
window.history.forward(1);
function ShowHideElementByID(id) {
	if (document.getElementById) { // DOM3 = IE5, NS6
		if(document.getElementById(id).style.display == "none"){
		document.getElementById(id).style.display = 'block';
		}else document.getElementById(id).style.display = 'none';
	}else{
		if(document.layers){
			if(document.id.display == "none"){ document.id.display = 'block'; }else document.id.display = 'none';
		}else{
			if(document.all.id.style.visibility == "none"){document.all.id.style.visibility = 'block';} else document.all.id.style.visibility = 'none';
		}
	}
}


function validateStepOne(PurchaseForm) {    

	var email = PurchaseForm.EmailAddress.value;
	var at = email.indexOf("@");		
	var space = email.indexOf(" ");
	var comma = email.indexOf(",");
	var dot = email.indexOf(".");
	var two_dots = email.indexOf("..");
	var length = email.length -1;

	if (PurchaseForm.LicenceeName.value == "") {
		alert("Please enter a name for this licence (person or organisation)");
		PurchaseForm.LicenceeName.focus();
		return false;
		}
	
	 if ((at == -1)||(at == 0)||(at == length)||(space != -1)||(comma != -1)||(two_dots != -1)||(dot == -1)||(dot == length)||(dot == 0)) {
		alert("Please enter a valid email address.");
		PurchaseForm.EmailAddress.focus();
		return false;	
		}
	
	if (PurchaseForm.cd.checked == true)
	    {
		if (PurchaseForm.Address1.value == "") {
			alert("Address1 field cannot be empty");
			PurchaseForm.Address1.focus();
			return false;
			}
		if (PurchaseForm.Address2.value == "") {
			alert("Address2 field cannot be empty");
			PurchaseForm.Address2.focus();
			return false;
		}
		if (PurchaseForm.City.value == "") {
			alert("City field cannot be empty");
			PurchaseForm.City.focus();
			return false;
		}
	} return true;
	return true;
}


function validateStepTwo(PurchaseForm) { 

	if (PurchaseForm.CCNumber.value == "") {
		alert("You must enter your card number.");
		PurchaseForm.CCNumber.focus();
		return false; } 
	else if (PurchaseForm.CCName.value == "") {
		alert("You must enter the name on the card.");
		PurchaseForm.CCName.focus();
		return false; } 
	hideSubmit();
	return true;
}

function showParentAndClose(givenURL) {
    window.opener.document.location = givenURL;
	self.close();
}


	function validate(LicenceeForm) {    
		listFind();
		}
	
	function checkproducts(FinishForm) {    
		if (FinishForm.ProductCount.value == "0") {
		alert("You must enter a at least one product.");
		return;
		}
	
		else {
		FinishForm.submit(); //submit form
		}			
	}
	function listFind() {
		list= document.AddLicenceForm.currentProds.value;
		delimiter = ",";
		searchFor = document.AddLicenceForm.ProductID.value ;
		
		// build an array from the product list to search through below.
		aryList = list.split(delimiter);

		for( i=0; i < aryList.length; i++ ){
			if( aryList[i] == searchFor ) {
				var existingProduct=1;
			}
		}
		if (existingProduct) {
			var confrimation = confirm('You already added a product of this type for this order. \n Are you sure you want to add another?'); 
			if (confrimation){
			        AddLicenceForm.submit();
			     }
			     else{
				return false;
			     }
			}
			else{
				AddLicenceForm.submit();
			
		}
	}

function textCounter( field, countfield, maxlimit ) {
  if ( field.value.length > maxlimit )
  {
    field.value = field.value.substring( 0, maxlimit );
    alert( 'Please restrict your notes to 50 characters' );
    return false;
  }
  else
  {
    countfield.value = maxlimit - field.value.length;
  }
}

function popitup(url) {
var newwindow = '';
	if (!newwindow.closed && newwindow.location) {
		newwindow.location.href = url;
	}
	else {
		newwindow=window.open(url,'remoteWin','width=930,height=880,top=20,left=20,resizable=1,menubar=0,status=1,scrollbars=1,panel=0,addressbar=0');
		if (!newwindow.opener) newwindow.opener = self;
	}
	if (window.focus) {newwindow.focus()}
	return false;
}


	function validate(OrganisationForm) {    
	

	if (OrganisationForm.OrganisationName.value == "") {
		alert("You must enter an Organisation Name.");
		OrganisationForm.OrganisationName.focus();
		return;
		}
					
	else {
		OrganisationForm.submit(); //submit form
		}		
	}

	function delLicencee (id) {
		if (confirm('Warning: this will remove the licencee from the system')) window.location = 'act_delete_licencee.cfm?LicenceeID='+id;
	}


	function ConfirmDelete(Logon) {
	
		if (confirm("Are you sure you want to delete this licence?")) {
			return true;
		}
		else {
			return false;
		}
	}



	function ValidateAdd(AddLicenceForm) {
	
	if (AddLicenceForm.Quantity.value <= 0) {
		alert("You must enter a logon Name.");
		AddLicenceForm.Name.focus();
		return;
		} 
		
	else {
		AddLicenceForm.submit(); //submit form
		//AddLicenceForm.AddLicence.value="Edit" 
		}
	}



	function validate(ContactForm) {    

		var email = ContactForm.EmailAddress.value;
		var at = email.indexOf("@");		
		var space = email.indexOf(" ");
		var comma = email.indexOf(",");
		var dot = email.indexOf(".");
		var two_dots = email.indexOf("..");
		var length = email.length -1;
		
	if (ContactForm.Name.value == "") {
		alert("You must enter a logon Name.");
		ContactForm.Name.focus();
		return;
		} 
	
	else if ((at == -1)||(at == 0)||(at == length)||(space != -1)||(comma != -1)||(two_dots != -1)||(dot == -1)||(dot == length)||(dot == 0)||(length < 1)) {
		alert("Please enter a valid email address.");
		ContactForm.EmailAddress.focus();
		return;	
		} 
		
	else {
		ContactForm.submit(); //submit form
		ContactForm.EditLicence.value="Edit"
		}
	}







	function ConfirmDelete(Logon) {
	
		if (confirm("Are you sure you want to delete the Logon for "+Logon+"?")) {
			return true;
		}
		else {
			return false;
		}
	}



	function validate(OrganisationForm) {    
			
	if (OrganisationForm.OrganisationName.value == "") {
		alert("You must enter an Organisation Name.");
		OrganisationForm.OrganisationName.focus();
		return;
		}
		
	else if (OrganisationForm.AccountCode.value == "") {
		alert("You must enter a Reseller Code.");
		OrganisationForm.AccountCode.focus();
		return;
		}
		
	else {
		OrganisationForm.submit(); //submit form
		}
	}

function checkDivertBox()
{
    // look at the current state of the checkbox 
    if (ResellerForm.renewalDivert.checked)
{}
else
    {
        alert("Unchecking 'Renwals to Licencee' will disassociate all past 'diverted' records with this reseller. Please be sure this is what you want to do before updating this record.");
    }
}


function validateRenewalOrderNumber(tid) {
   switch(tid) {
      case "pay":
      	if (document.renewalForm.OrderNo.value=='') 
      		{alert('Please enter order number'); return false;}
      	else { ShowHideElementByID('pay'); return true;}
         break;
      case "invoice":
      	if (renewalForm.OrderNo.value=='') 
      		{alert('Please enter order number'); return false;}
      	else { ShowHideElementByID('invoice'); return true;}
         break;
      }
   }
   
   
   
   
   function validateEshopOrder() {  
   
PurchaseForm=document.purchase;


	if (PurchaseForm.cd.value != 0)
	    {
		if (PurchaseForm.Address1.value == "") {
			alert("Address1 field cannot be empty");
			PurchaseForm.Address1.focus();
			return false;
			}
		if (PurchaseForm.Address2.value == "") {
			alert("Address2 field cannot be empty");
			PurchaseForm.Address2.focus();
			return false;
		}
		if (PurchaseForm.City.value == "") {
			alert("City field cannot be empty");
			PurchaseForm.City.focus();
			return false;
		}
	} 
	
	if (PurchaseForm.CCNumber.value == "") {
		alert("You must enter your card number.");
		PurchaseForm.CCNumber.focus();
		return false; 
			
	} 
	if (PurchaseForm.CCName.value == "") {
		alert("You must enter the name on the card.");
		PurchaseForm.CCName.focus();
		return false; } 
		
	if (PurchaseForm.cvc2.value == "") {
		alert("You must enter the verification number found on the back of your credit card.");
		PurchaseForm.cvc2.focus();
		return false; } 
	hideSubmit();
	return true;
}



function hideSubmit() {
	if (document.getElementById) {
		this.document.getElementById('submit_button').style.visibility = "hidden";
	} else {
		document.all[submit_button].visibility="hidden";
	}
}



		function confirmSubmit(msg)
		{
		return confirm(msg);
		}



    function submitLoadIcon(button1,button2,icon_div1,icon_div2)
	{
		
		var ieVer=getInternetExplorerVersion();
			
		
		
		if (ieVer ==-1) {
			document.getElementById(button1).style.display="none";
			document.getElementById(button1).style.visibility="hidden";
			document.getElementById(icon_div1).style.display="block"; 
			document.getElementById(icon_div1).style.visibility="visible";
			
			document.getElementById(button2).style.display="none";
			document.getElementById(button2).style.visibility="hidden";
			document.getElementById(icon_div2).style.display="block"; 
			document.getElementById(icon_div2).style.visibility="visible";		
		} else {
			document.getElementById(button1).style.display="none";
			document.getElementById(icon_div1).style.display="block"; 
			document.getElementById(icon_div1).innerHTML ="<img src='/images/loading.gif'>"; 
			
			document.getElementById(button2).style.display="none";
			document.getElementById(icon_div2).style.display="block"; 
			document.getElementById(icon_div2).innerHTML ="<img src='/images/loading.gif'>"; 
		}
	}




function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }

  return rv;
}
