function PopUpWindow(url,title,xwidth,xheight,features) {
  if(screen.width){
  var winl = (screen.width-xwidth)/2;
  var wint = (screen.height-xheight)/2;
  }else{winl = 0;wint =0;}
  if (winl < 0) winl = 0;
  if (wint < 0) wint = 0;
  var settings = 'height=' + xheight + ',';
  settings += 'width=' + xwidth + ',';
  settings += 'top=' + wint + ',';
  settings += 'left=' + winl;
  settings += features;
  win = window.open(url,title,settings);
  win.window.focus();
}

function buyNow(strISACode,strMenu) { 
	location.href="Purchase.aspx?ISA_ID="+strISACode+"&Menu="+strMenu;
}

function ResellerDetails(srid)
{
  var url = "Common/resellerdetails.aspx?Reseller=" + srid;
  PopUpWindow(url,"Details",600,298,'toolbar=no,resizable=no,scrollbars=no,status=no');
}

// randy's stuff for header
kDDMLayName = "DDMSubmenu";
fwDDMLayCount = 2;
fwLoad = new Object;
function FWLoad(image)
{
	if (!document.images)
		return null;
	if (!fwLoad[image])
	{
		fwLoad[image]=new Image;
		fwLoad[image].src=image;
	}
	return fwLoad[image].src;
}
function FWPreload(){FWLoad("../images/bg5.gif");FWLoad("../images/arrow5.png");}

function checkMouseLeave(element, evt) {
  if (element.contains && evt.toElement) {
    return !element.contains(evt.toElement);
  }
  else if (evt.relatedTarget) {
    return !containsDOM(element, evt.relatedTarget);
  }
}

function containsDOM (container, containee) {
  var isParent = false;
  do {
    if ((isParent = container == containee))
      break;
    containee = containee.parentNode;
  }
  while (containee != null);
  return isParent;
}

function checkMouseEnter (element, evt) {
  if (element.contains && evt.fromElement) {
    return !element.contains(evt.fromElement);
  }
  else if (evt.relatedTarget) {
    return !containsDOM(element, evt.relatedTarget);
  }
}

function setButtonState(element, bValue){
  eval(element).disabled = !bValue;
}

function setStateAddSubBttn(element1,element2){
  eval(element2).disabled = !eval(element1).checked;
}
function setButtonState2(element){
//  FafYN = document.getElementById("selFaF");
//  var selAns = FafYN.selectedIndex;
//  if (selAns == "1") eval(element).disabled = false;
  
    eval(element).disabled = true;
    if (document.getElementById("selFaFY").checked == true) eval(element).disabled = false;
}

//function selStateChanged(State, Country){
//	var strValue = eval(State).value;
//	eval(Country).value = strValue.substring(3,strValue.strlen);
//}

function setCDShipButtons() {

	 	document.purchase.radShip1.disabled = true;
	  document.purchase.radShip2.disabled = true;
    document.purchase.radShip3.disabled = true; 
    document.purchase.radCDShipN.checked = true;

//	eval(document.purchase.radShip1).disabled = true;
//	eval(document.purchase.radShip2).disabled = true;
//  eval(document.purchase.radShip3).disabled = true;
  
//  eval(document.purchase.radCDShipY).checked = false;
//  eval(document.purchase.radCDShipN).checked = true;
  
//  eval(document.purchase.radShip2).checked = true;
}

function selStateChanged(objectFired, State, Country, SalesTaxLabel, SalesTaxAmt, SignupLabel, SignupAmt){
	var strValue = "";
	var BSKAmt;
	var SalesTaxApplied = 0;
	var numLic;
	var newLic;
	var shipMeth;
	var ShipAmt;
	var TotalAmt = 0;
	
	// ***************  ISASignup.aspx  *************
	if (document.update) {
		// country change based on state selection
		strValue = eval(State).value;
		eval(Country).value = strValue.substring(3,50);
	}
	
	if (document.join) {
		// country change based on state selection
		strValue = eval(State).value;
		eval(Country).value = strValue.substring(3,50);
	
		// registration, business kit
		BSKAmt = document.join.txtRegisFee.value;

		// sales tax if Utah
		eval(SalesTaxLabel).value = "0.00";
		if (strValue.substring(0,2) == "UT") {
			eval(SalesTaxLabel).value = SalesTaxAmt;
			SalesTaxApplied = SalesTaxAmt;
		}
	
		// number of licenses selected
		// check to see if subscription check box is checked
		numLic = 0;
		eval(SignupLabel).value = "  0.00";
		
		if (document.join.chkPersSub) {
			if (document.join.chkPersSub.checked) {
				document.join.lblSubscriptionQuantity.value = 1;
				numLic = document.join.lblSubscriptionQuantity.value;
				eval(SignupLabel).value = round(SignupAmt * numLic, 2);
//			eval(document.join.txtFirstNameITIR1).disabled = false;
//			eval(document.join.txtLastNameITIR1).disabled = false;
//			eval(document.join.txtFirstNameITIR2).disabled = false;
//			eval(document.join.txtLastNameITIR2).disabled = false;
			}
			else if (objectFired == "chkPersSub" ) {
				eval(SignupLabel).value = "  0.00";
				numLic = 0;
				document.join.lblSubscriptionQuantity.value = 0;
//			eval(document.join.txtFirstNameITIR1).disabled = true;
//			eval(document.join.txtLastNameITIR1).disabled = true;
//			eval(document.join.txtFirstNameITIR2).disabled = true;
//			eval(document.join.txtLastNameITIR2).disabled = true;
				alert("ATTENTION!  You are removing your PC Security subscription to INVISUS that is included with your ISA signup.  \n\nDon't forget to protect your personal computer(s) first!  Remember, when you sign up as an ISA, your personal \nINVISUS subscription for your own PC is considered a sale for your sponsor.  If you choose not to get your \npersonal subscription now, your first sale as an ISA will be credited to your sponsor.");
			}
		}
	
		// shipping method
		for (i=0; i < document.join.shipMethod.length; i++) {
			if (document.join.shipMethod[i].checked==true)
				shipMeth=i
		}

		if (shipMeth == 2) ShipAmt = "23.99";
		if (shipMeth == 1) ShipAmt = "0.00";
		if (shipMeth == 0) ShipAmt = "0.00";
	
		document.join.txtShip.value = ShipAmt; 
	
		// Total cost to CC
		TotalAmt = round(((BSKAmt * 1) + (SignupAmt * numLic * 1) + (SalesTaxApplied * 1) + (ShipAmt * 1)),2);
		document.join.txtTotal.value = TotalAmt; 
	}
	
	// ***************  Purchase.aspx  *************
				
		if (document.purchase) {
		
		eval(document.purchase.radShip1).disabled = true;
		eval(document.purchase.radShip2).disabled = true;
		eval(document.purchase.radShip3).disabled = true;
		  
		// country change based on state selection
		strValue = eval(State).value;	
//		alert (strValue);	
//		alert ("country= " + Country);				
		eval(Country).value = strValue.substring(3,50);
		
//		alert (strValue.substring(3,50));
		
		//grey out state box if not US or Canada
		if (objectFired == "selCountry") {
			document.purchase.selState.disabled = false
			if (document.purchase.selCountry.value != "US" && document.purchase.selCountry.value != "CA") {
				document.purchase.selState.disabled = true;
				document.purchase.selState.selectedIndex = 0;
			}
		}
		if (objectFired == "selState") {
//			alert (document.purchase.selCountry.value);
			if (strValue.substring(3,50) == "United States") {
				strCountryIndex = "0";
			}
			if (strValue.substring(3,50) == "Canada") {
				strCountryIndex = "1";
			}
			document.purchase.selCountry.selectedIndex = strCountryIndex;
		}
		
//		alert (strValue.substring(3,50));		
//		alert (document.purchase.selCountry.value);
//		alert (strValue.substring(0,3));
		
		// number of licenses selected
		numLic = document.purchase.selNumLic.selectedIndex + 1;
		eval(SignupLabel).value = round(SignupAmt * numLic, 2);
			
		// price per subscription
		var subCost;
		subCost = 14.99;
		if (numLic > 1 && numLic <= 5) {
			subCost = subCost + (numLic - 1) * 9.99;
		}
		if (numLic > 5) {
			subCost = subCost + (4) * 9.99;
			subCost = subCost + (numLic - 5) * 8.99;
		}
		subCost = round(subCost, 2);
		
		// shipping method
		// check to see if they want the cd shipped
		if (objectFired == "radCDShipY") {
      eval(document.purchase.radShip2).checked = true;
    }
    
     ShipAmt = "0.00";
		if (document.purchase.radCDShipY.checked==true) {
		
			eval(document.purchase.radShip1).disabled = false;
		  eval(document.purchase.radShip2).disabled = false;
		  eval(document.purchase.radShip3).disabled = false;   
	  
		  for (i=0; i < document.purchase.shipMethod.length; i++) {
			  if (document.purchase.shipMethod[i].checked==true)
			  	shipMeth=i
		  }
	  	if (shipMeth == 0) ShipAmt = "23.99";
	  	if (shipMeth == 1) ShipAmt = "9.99";
	  	if (shipMeth == 2) ShipAmt = "3.99";

		  document.purchase.txtShip.value = ShipAmt; 

		}
		else if (document.purchase.radCDShipN.checked==true){
//		else if (objectFired == "radCDShipN") {

		    eval(document.purchase.radShip1).disabled = true;
		    eval(document.purchase.radShip2).disabled = true;
		    eval(document.purchase.radShip3).disabled = true;
        ShipAmt = "0.00";
        document.purchase.txtShip.value = ShipAmt; 
		}  
		document.purchase.lblTotalSecondMonth.value = subCost;
		document.purchase.lblSecondMonthSubNum.value = numLic;
	
		// Total cost to CC
		TotalAmt = round(((SignupAmt * numLic * 1) + (ShipAmt * 1)),2);
		document.purchase.txtTotal.value = TotalAmt; 
	}
	
	//****************  MySubscriptions.aspx ************
	if (document.MySubs) {
	
	
		eval(document.MySubs.radShip1).disabled = true;
		eval(document.MySubs.radShip2).disabled = true;
		eval(document.MySubs.radShip3).disabled = true;
		  
		// country change based on state selection
//		strValue = eval(State).value;						
//		eval(Country).value = strValue.substring(3,50);
		
		// number of licenses selected
		numLic = document.MySubs.selNumLic.selectedIndex + 1;
		eval(SignupLabel).value = round(SignupAmt * numLic, 2);
			
		// price per subscription
		newLic = numLic + Number(document.MySubs.idNumSubs.value);
		var subCost;
		subCost = 14.99;
		if (newLic > 1 && newLic <= 5) {
			subCost = subCost + (newLic - 1) * 9.99;
		}
		if (newLic > 5) {
			subCost = subCost + (4) * 9.99;
			subCost = subCost + (newLic - 5) * 8.99;
		}
		subCost = round(subCost, 2);
		
		// shipping method
		// check to see if they want the cd shipped
		if (objectFired == "radCDShipY") {
      eval(document.MySubs.radShip2).checked = true;
    }
    
     ShipAmt = "0.00";
		if (document.MySubs.radCDShipY.checked==true) {
		
			eval(document.MySubs.radShip1).disabled = false;
		  eval(document.MySubs.radShip2).disabled = false;
		  eval(document.MySubs.radShip3).disabled = false;   
	  
		  for (i=0; i < document.MySubs.shipMethod.length; i++) {
			  if (document.MySubs.shipMethod[i].checked==true)
			  	shipMeth=i
		  }
	  	if (shipMeth == 0) ShipAmt = "23.99";
	  	if (shipMeth == 1) ShipAmt = "9.99";
	  	if (shipMeth == 2) ShipAmt = "3.99";

		  document.MySubs.txtShip.value = ShipAmt; 

		}
		else if (document.MySubs.radCDShipN.checked==true){
//		else if (objectFired == "radCDShipN") {

		    eval(document.MySubs.radShip1).disabled = true;
		    eval(document.MySubs.radShip2).disabled = true;
		    eval(document.MySubs.radShip3).disabled = true;
        ShipAmt = "0.00";
        document.MySubs.txtShip.value = ShipAmt; 
		}  
		document.MySubs.lblTotalSecondMonth.value = subCost;
		document.MySubs.lblSecondMonthSubNum.value = newLic;
	
		// Total cost to CC
		TotalAmt = round(((SignupAmt * numLic * 1) + (ShipAmt * 1)),2);
		document.MySubs.txtTotal.value = TotalAmt; 
	}

	
	// ***************  ISASalesTools.aspx  *************
	if (document.salestools) {
	
		// country change based on state selection
		strValue = eval(State).value;
		eval(Country).value = strValue.substring(3,50);
		
		// number of licenses selected
		numLic = document.salestools.selNumDemoCD.selectedIndex + 1;
		if (numLic > 1 && numLic < 4) SignupAmt = 25.00;
		if (numLic > 3 && numLic < 8) SignupAmt = 23.75;
		if (numLic > 7 && numLic < 11) SignupAmt = 22.50;
		eval(SignupLabel).value = round(SignupAmt * numLic, 2);
		
		document.salestools.lblLicCostPer.value = round(SignupAmt, 2);
		
		// sales tax if Utah
		eval(SalesTaxLabel).value = "0.00";
		if (strValue.substring(0,2) == "UT") {
			eval(SalesTaxLabel).value = round(numLic * SignupAmt * 0.0625, 2);
			SalesTaxApplied = round(numLic * SignupAmt * 0.0625, 2);
		}
	
		// shipping method
		for (i=0; i < document.salestools.shipMethod.length; i++) {
			if (document.salestools.shipMethod[i].checked==true)
				shipMeth=i
		}

		if (shipMeth == 0) ShipAmt = "25.99";
		if (shipMeth == 1) ShipAmt = "9.99";
		if (shipMeth == 2) ShipAmt = "3.99";
	
		document.salestools.txtShip.value = ShipAmt; 
	
		// Total cost to CC
		TotalAmt = round(((SignupAmt * numLic * 1) + (SalesTaxApplied * 1) + (ShipAmt * 1)),2);
		document.salestools.txtTotal.value = TotalAmt; 
	}
	
	// ***************  CustomerISASignup.aspx  *************
	if (document.CustJoin) {
		
		// state value
		strValue = eval(State).value;
	
		// registration, business kit
		BSKAmt = document.CustJoin.txtRegisFee.value;
		
		// shipping method
		for (i=0; i < document.CustJoin.shipMethod.length; i++) {
			if (document.CustJoin.shipMethod[i].checked==true)
				shipMeth=i
		}

		if (shipMeth == 2) ShipAmt = "23.99";
		if (shipMeth == 0) ShipAmt = "0.00";
		if (shipMeth == 1) ShipAmt = "0.00";
	
		// sales tax if Utah
		if (strValue.substring(0,4) == "Utah") {
			SalesTaxApplied = SalesTaxAmt;
		}
		
		document.CustJoin.txtShip.value = ShipAmt; 
	
		// Total cost to CC
		TotalAmt = round(((BSKAmt * 1) + (SalesTaxApplied * 1) + (ShipAmt * 1)),2);
		document.CustJoin.txtTotal.value = TotalAmt; 
	}
}

function format10 (n, d) {
  n = round (n, d);
  for (var i = n.indexOf('.') - 3; i > 0; i -= 3)
    n = n.substring(0, i) + ',' + n.substring(i);
  return n;
}

function round (n, d) {
  n = n - 0;
  d = d || 2;
  var f = Math.pow(10, d);
  n = Math.round(n * f) / f;
  n += Math.pow(10, - (d + 1));
  n += '';
  return d == 0 ? n.substring(0, n.indexOf('.')) :
      n.substring(0, n.indexOf('.') + d + 1);
}

function selWebNameChanged(objectFired, formName){

  var objNameFired = "document." + formName + "." + objectFired + ".value";
  var objTextbox = "document." + formName + ".txtPersonalWS";
  var objFirstName = "document." + formName + ".txtFirstName.value";
  var objFI = "document." + formName + ".txtFirstName.value";
  var objFIPrint = eval(objFI);
  objFIPrint = objFIPrint.substring(0,1);
  var objLastName = "document." + formName + ".txtLastName.value";
  var objMI = "document." + formName + ".txtMI.value";
  var objWebNameOther = "document." + formName + ".txtWebNameOther.value";

  var objOtherTextBox = "document." + formName + ".txtWebNameOther";
  var objRadWebName = "document." + formName + ".radWebName";
//  var objDivOtherTextBox = "divOther";
//  var objDivOtherTextBoxNS = "document.getElementById('divOther')";
  
  //  if (document.layers) { //  are we in dhtml ns4? 
  var agt=navigator.userAgent.toLowerCase();

  // *** BROWSER VERSION ***
  var is_major = parseInt(navigator.appVersion);
  var is_minor = parseFloat(navigator.appVersion);

  var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
              && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
              && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
  var is_nav4up = (is_nav && (is_major >= 4));
  var is_gecko = (agt.indexOf('gecko') != -1);
  
//  if (is_nav4up || is_gecko) {
//    eval(objDivOtherTextBoxNS).style.visibility = "hidden";
//	}
//	else {
//	  eval(objDivOtherTextBox).style.visibility = "hidden";
//  }
  
  if (objectFired == "unknown") {
    for (counter = 0; counter < eval(objRadWebName).length; counter++) {
      cntr = counter + 1;
      if (eval(objRadWebName)[counter].checked) {
        objectFired = "radWebName" + cntr;
      }
    }
  }

  if (objectFired == "radWebName1") {
    eval(objTextbox).value = objFIPrint + eval(objLastName);
  }
  if (objectFired == "radWebName2") {
    eval(objTextbox).value = eval(objLastName) + objFIPrint;
  }
  if (objectFired == "radWebName3") {
    eval(objTextbox).value = eval(objFirstName);
  }
  if (objectFired == "radWebName4") {
    eval(objTextbox).value = eval(objLastName);
  }  
//  if (objectFired == "radWebName5") {
//    if (is_nav4up || is_gecko) {
//      eval(objDivOtherTextBoxNS).style.visibility = "visible";
//    }
 //   else {
 //     eval(objDivOtherTextBox).style.visibility = "visible";
 //   }
 //   eval(objTextbox).value = eval(objWebNameOther);
  }
  
function browserType() {
  // convert all characters to lowercase 
  var agt=navigator.userAgent.toLowerCase();

  // *** BROWSER VERSION ***
  var is_major = parseInt(navigator.appVersion);
  var is_minor = parseFloat(navigator.appVersion);

  // Note: Opera and WebTV spoof Navigator.  We do strict client detection.
  // If you want to allow spoofing, take out the tests for opera and webtv.
  var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
              && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
              && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
  var is_nav4up = (is_nav && (is_major >= 4));
  var is_gecko = (agt.indexOf('gecko') != -1);
}

function populateWindow(url)
{
  document.getElementById('frameISAInfo').src = url; 
}