
var counter = 0;
var items = 0;
function hideRoundedBox() {
  var divs;
  var box;
  divs = document.getElementsByTagName("div");
  for (var i = 0; i < divs.length; i++) {
    d = divs[i];
    if (d.className == "boxRound") {
      v = findDiv(d.innerHTML, "<DIV");
      f = findDiv(d.innerHTML, "<FORM");
      if ((v > -1) || (f > -1)) {
        c = d.parentNode.className.replace("hiddenBox", "");
        d.parentNode.className = c;
      }
    }
  }
}
function trim(stringToTrim) {
  return stringToTrim.replace(/^\s+|\s+$/g, "");
}
function findDiv(stringToSearch, el) {
  source = stringToSearch.toUpperCase();
  return source.indexOf(el, 0);
}
function showPopupByUrl(w, h, url, winName) {
  x = screen.availWidth / 2 - w / 2;
  y = screen.availHeight / 2 - h / 2;
  var vWin = window.open("", winName, "width=" + w + ",height=" + h + ",left=" + x + ",top=" + y + ",screenX=" + x + ",screenY=" + y + ",scrollbars=yes,resizable=yes,dependent=yes,status=yes");
  vWin.location.href = url;
  vWin.window.focus();
}


var log="Log:\n";
var image;
function imageSave(i){
  image=i;
}

function imageLoaded() {
  var w=0;//surrounding box width
  var h=0;//surrounding box height
  var nW=101;//image native width
  var nH=101;//image native height
  var endW=0;//image computed width
  var endH=0;//image computed height
  if (image.parentNode.parentNode.currentStyle) {
    w = parseInt(image.parentNode.parentNode.currentStyle["width"]);
      nW = parseInt(image.width);
      nH = parseInt(image.height);
  } else {
    if (window.getComputedStyle) {
      w = parseInt(document.defaultView.getComputedStyle(image.parentNode.parentNode, null).getPropertyValue("width"));
      nW = image.naturalWidth;
      nH = image.naturalHeight;
    }
  }
  h=w;
  endW = nW;
  endH = nH;

  if (nH >= h) {
    endH = h;
    endW = nW * h / nH;
    if (endW >= w) {
      endH = endH * w / endW;
      endW = w;
    }
  }
  if (endW >= w) {
    endW = w;
    endH = nH * w / nW;
    if (endH >= h) {
      endW = endW * h / endH;
      endH = h;
    }
  }
  if (nW <= w && nW >= nH) {
    endH = endH * w / nW;
    endW = w;
  }
  if (nH <= h && nH >= nW) {
    endW = endW * h / nH;
    endH = h;
  }
  image.width = endW;
  image.height = endH;
  log = log + " w:" + w + " h:" + h + " natW:" + nW + " natH:" + nH + " endW:" + endW + " endH:" + endH + "\n";
  return true;
}

function disableEndDate() {

  if (document.subscriptionSubscribe.subscriptionEnd.disabled==false) {
  	document.subscriptionSubscribe.subscriptionEnd.value='';
    document.subscriptionSubscribe.subscriptionEnd.disabled=true;
    document.getElementById("unlimitted").value='0';
  } else {
  	document.subscriptionSubscribe.subscriptionEnd.disabled=false;
    document.getElementById("unlimitted").value='1';
  }
}

function disableEndDateSubscription(date) {
  if (document.subscriptionSubscribe.subscriptionEnd.disabled==false) {
    document.subscriptionSubscribe.subscriptionEnd.value='';
    document.subscriptionSubscribe.subscriptionEnd.disabled=true;
    document.getElementById("unlimitted").value='0';
  } else {
    document.subscriptionSubscribe.subscriptionEnd.disabled=false;
    document.getElementById("unlimitted").value='1';
    document.subscriptionSubscribe.subscriptionEnd.value=date;
  }
}

function switchEditFrequencies() {
 
  if (document.getElementById("frequency").disabled) {
    document.getElementById("frequency").disabled=false;
    document.getElementById("frequencyHours").disabled=false;
    document.getElementById("frequencyMinutes").disabled=false;
  } else {
  	document.getElementById("frequency").disabled=true;
    document.getElementById("frequencyHours").disabled=true;
    document.getElementById("frequencyMinutes").disabled=true;
    
  }
}

function submitOneTimeRequest(loggedIn){
	if(loggedIn){
		document.getElementById("subscriptionSubscribe").action='oneTimeRequest.do';
	}
	else{
		document.getElementById("subscriptionSubscribe").action='oneTimeRequestLogin.do';
	}
	document.getElementById("subscriptionSubscribe").submit();
}

/*function subscribeWithParameters(max){
	var origId;
	var copyId;
	for (i=0; i < max; i++) {
  		origId = "orig_"+i;
  		copyId = "copy_"+i;
  		document.getElementById(copyId).value = document.getElementById(origId).value;
	}
	document.subscriptionSubscribe.submit();
	
}*/