//Standard site functions
function fnChangeImage(Obj, Img){
	Obj.src = '/images/'+Img;
}

function fnSubmitForm(Obj1, IPValue){
		Obj1.mode.value = IPValue;
		Obj1.submit();
}

function fnSimpleFormSubmit(Obj1){
		Obj1.submit();
}

function fnClose(obj){
	if (obj == 1){
		document.getElementById("AddToCart").style.display = 'none';
	}else{
		document.getElementById("OutofStock").style.display = 'none';
	}
}

function fnSubmitItem(obj){
	var i
	for (i=0; i<document.all.item(obj).options.length; i++){
			document.all.item(obj).options[i].selected = true
	}
	
	return true;
}

function fnCartAlert(){
	document.getElementById("AddToCart").style.display = "block";
}

function fnOutofStock(){
	document.getElementById("OutofStock").style.display = "block";
}

function fnEnableDisable(obj){
	var method;
	
	if (document.getElementById('chkConfirm').disabled == true || document.getElementById('gcheckout').disabled == true){
		method = ""
		
		if (obj == "$"){
			if (document.getElementById('chkAgree').checked == true){
				for (i=0;i<document.all.item('method').length;i++){
					if (document.all.item('method')[i].checked == true){
						method = document.all.item('method')[i].value;
						break;
					}
				}
					
				if (method == 'cc'){
					document.getElementById('gcheckout').disabled = false;
				}else if (method == 'eft'){
					document.getElementById('chkConfirm').disabled = false;
				}else{
					alert("Please select a payment method")
					document.getElementById('chkAgree').checked = false;
				}
			}else{
				document.getElementById('chkConfirm').disabled = true;
				document.getElementById('gcheckout').disabled = true;
			}
		}else{
			
			document.getElementById('chkConfirm').disabled = false;
		}
	}else{
		document.getElementById('chkConfirm').disabled = true;
		document.getElementById('gcheckout').disabled = true;
	}
}

function showStatus(sMsg) {
    window.status = sMsg ;
    return true ;
}

function fnLogin(){
	if (document.getElementById('signin').style.display == 'none'){
		document.getElementById('signin').style.display = 'block';
		document.getElementById('txtUID').focus();
	}else{
		document.getElementById('signin').style.display = 'none';
	}
}

function fnBrandRedirect(brandid){
	document.location="/perfect/"+brandid+"/form.html"
}

function fnCategoryRedirect(catid){
	document.location="/perfect/"+catid+"/form.html"
}

function fnCloseAssignment(){
	window.opener.location = '/ZW/14/Checkout.html';
	window.close();
}

function fnDetectBrowser(){
	document.getElementById("browser").value = navigator.appName;
}

function fnLoadRecipientWindow(obj){
	window.open("/assignment.asp?pid="+obj,"Assignmnet","width=500,height=300,resizable=1,toolbars=0,menubar=0");
}

function fnProfileSubmitForm(IPValue){
		document.frmProfile.mode.value = IPValue;
		document.frmProfile.submit();
}

function fnCheckKeyPress(Obj, Obj1, IPValue){
	if (Obj == 13){
		Obj1.mode.value = IPValue;
		Obj1.submit();
	}
}

function fnStatusChange(Obj){
	window.status = Obj
}

function fbreakout(obj){
	if (window.top!=window.self) 
	{
		window.top.location=obj
	}
}

function fnShowCheckout(obj){
	if (obj == 'cc'){
		document.getElementById('cccheckout').style.display = 'block';
		document.getElementById('directcheckout').style.display = 'none';
		document.getElementById('confirmcheckout').style.display = 'none';
	}else{
		document.getElementById('directcheckout').style.display = 'block';
		document.getElementById('cccheckout').style.display = 'none';
		document.getElementById('confirmcheckout').style.display = 'block';
	}
}

function addCatItem(obj, obj1, obj2, obj3){
	var i
	
	for (i=0; i<document.all.item(obj1).options.length; i++){
		if (document.all.item(obj1).options[i].selected==true){
			addNewItem(obj, obj3, obj2, document.all.item(obj1).options[i].value, document.all.item(obj1).options[i].text)
		}
	}	
}

function addNewItem(obj, obj1, obj2, id, name){
	var i
	addOption = true
	for (i=0; i<document.all.item(obj2).options.length; i++){
		if(document.all.item(obj2).options[i].value == id){
			addOption = false
		}
	}
	
	if (addOption == true){
		document.all.item(obj2).options[document.all.item(obj2).options.length] = new Option(name, id)

		if (obj == 'event' || obj == 'categories'){
			if (document.all.item(obj2).options.length == 1){
				document.all.item(obj1).value = id
			}else{
				document.all.item(obj1).value = document.all.item(obj1).value +','+id
			}
		}
	}
}

function removeCatItem(obj, obj1, obj2){
	var i
	var oElements
	var CatID
	var SelCat
	for (i=0; i<document.all.item(obj2).options.length; i++){
		if (document.all.item(obj2).options[i].selected==true){
			CatID = document.all.item(obj2).options[i].value
			document.all.item(obj2).options.remove(i)
		}
	}
	
	if (obj == 'event' || obj == 'categories'){
		for (i=0; i<document.all.item(obj2).options.length; i++){
			document.all.item(obj2).options[i].selected = true
		}
		
		oElements = document.all.item(obj2).value.split(",");
		document.all.item(obj1).value = "";
		for (i=0;i<oElements.length;i++){
			if (oElements.length == 1){
				document.all.item(obj1).value = oElements[i]
			}else{
				document.all.item(obj1).value = document.all.item(obj1).value +','+oElements[i]
			}
		}
	}
	
	if (obj == 'request'){
		document.location.replace("default.asp?cid=7&rid="+CatID)
	}
}

function fnValidateDepotRequest(){
	if (document.getElementById('txtDepot').value == ""){
		alert("Please select your desired depots.");
		document.getElementById('txtDepot').focus();
		return false;
	}
	
	fnSubmitItem('txtDepot');

	return true;
}

function fnLoadRequest(obj){
	var i
	addOption = true
	for (i=0; i<document.getElementById('txtDepots').options.length; i++){
		if(document.getElementById('txtDepots').options[i].value == obj){
			addOption = false
		}
	}
	
	if (addOption == true){
		document.getElementById('txtDepots').options[document.getElementById('txtDepots').options.length] = new Option(obj, obj)
	}
}

function fnRemoveRequest(obj){
	for (i=0; i<document.getElementById('txtDepots').options.length; i++){
		if (document.getElementById('txtDepots').options[i].selected==true){
			document.getElementById('txtDepots').options.remove(i)
		}
	}
}

function fnValidateRequest(){
	if (document.getElementById('txtContact').value == ""){
		alert("Please provide a contact person");
		document.getElementById('txtContact').focus();
		return false;
	}
	
	if (document.getElementById('txtOrganisation').value == ""){
		alert("Please provide your organisations name.");
		document.getElementById('txtOrganisation').focus();
		return false;
	}
	
	if (document.getElementById('txtEmail').value == ""){
		alert("Please provide a contact email address");
		document.getElementById('txtEmail').focus();
		return false;
	}
	
	if (document.getElementById('txtContact').value == ""){
		alert("Please provide a contact number");
		document.getElementById('txtContact').focus();
		return false;
	}
	
	var addr = document.getElementById('txtEmail').value
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
	   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
		  alert('The email address contains invalid characters');
		  return false;
	   }
	}
	
	for (i=0; i<addr.length; i++) {
	   if (addr.charCodeAt(i)>127) {
		  alert("The email address contains non ascii characters.");
		  return false;
	   }
	}
	
	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
	   alert('The email address must contain an @');
	   return false;
	}
	if (atPos == 0) {
	   alert('The email address must not start with @');
	   return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
	   alert('The email address must contain only one @');
	   return false;
	}
	if (addr.indexOf('.', atPos) == -1) {
	   alert('The email address must contain a period in the domain name');
	   return false;
	}
	if (addr.indexOf('@.',0) != -1) {
	   alert('The period must not immediately follow @ in email address');
	   return false;
	}
	if (addr.indexOf('.@',0) != -1){
	   alert('The period must not immediately precede @ in email address');
	   return false;
	}
	if (addr.indexOf('..',0) != -1) {
	  alert('The two periods must not be adjacent in email address');
	   return false;
	}
	
	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
	   alert('The primary domain in email address is invalid');
	   return false;
	}
	
	return true;
}

function fnFPwdValidate(obj){
	if (document.getElementById('txtContactEmail').value == ""){
		alert("Please provide a contact email address");
		document.getElementById('txtContactEmail').focus();
		return false;
	}
	
	var addr = document.getElementById('txtContactEmail').value
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
	   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
		  alert('The email address contains invalid characters');
		  return false;
	   }
	}
	
	for (i=0; i<addr.length; i++) {
	   if (addr.charCodeAt(i)>127) {
		  alert("The email address contains non ascii characters.");
		  return false;
	   }
	}
	
	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
	   alert('The email address must contain an @');
	   return false;
	}
	if (atPos == 0) {
	   alert('The email address must not start with @');
	   return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
	   alert('The email address must contain only one @');
	   return false;
	}
	if (addr.indexOf('.', atPos) == -1) {
	   alert('The email address must contain a period in the domain name');
	   return false;
	}
	if (addr.indexOf('@.',0) != -1) {
	   alert('The period must not immediately follow @ in email address');
	   return false;
	}
	if (addr.indexOf('.@',0) != -1){
	   alert('The period must not immediately precede @ in email address');
	   return false;
	}
	if (addr.indexOf('..',0) != -1) {
	  alert('The two periods must not be adjacent in email address');
	   return false;
	}
	
	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
	   alert('The primary domain in email address is invalid');
	   return false;
	}
}

function fnValidatePayment(){
	if (document.getElementById('txtTitle').value == ""){
		alert("Please provide your salutation.");
		ClickPaymentB('basket','pdetail','payment','baskettab','pdetailtab','paymenttab');
		document.getElementById('txtTitle').focus();
		return false;
	}
	
	if (document.getElementById('txtFirstName').value == ""){
		alert("Please provide your first name.");
		ClickPaymentB('basket','pdetail','payment','baskettab','pdetailtab','paymenttab')
		document.getElementById('txtFirstName').focus();
		return false;
	}
	
	if (document.getElementById('txtLastName').value == ""){
		alert("Please provide your last name.");
		ClickPaymentB('basket','pdetail','payment','baskettab','pdetailtab','paymenttab')
		document.getElementById('txtLastName').focus();
		return false;
	}
	
	if (document.getElementById('txtEmail').value == ""){
		alert("Please provide your email address.");
		ClickPaymentB('basket','pdetail','payment','baskettab','pdetailtab','paymenttab')
		document.getElementById('txtEmail').focus();
		return false;
	}
	
	var addr = document.getElementById('txtEmail').value
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
	   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
		  alert('The email address contains invalid characters');
		  return false;
	   }
	}
	
	for (i=0; i<addr.length; i++) {
	   if (addr.charCodeAt(i)>127) {
		  alert("The email address contains non ascii characters.");
		  return false;
	   }
	}
	
	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
	   alert('The email address must contain an @');
	   return false;
	}
	if (atPos == 0) {
	   alert('The email address must not start with @');
	   return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
	   alert('The email address must contain only one @');
	   return false;
	}
	if (addr.indexOf('.', atPos) == -1) {
	   alert('The email address must contain a period in the domain name');
	   return false;
	}
	if (addr.indexOf('@.',0) != -1) {
	   alert('The period must not immediately follow @ in email address');
	   return false;
	}
	if (addr.indexOf('.@',0) != -1){
	   alert('The period must not immediately precede @ in email address');
	   return false;
	}
	if (addr.indexOf('..',0) != -1) {
	  alert('The two periods must not be adjacent in email address');
	   return false;
	}
	
	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
	   alert('The primary domain in email address is invalid');
	   return false;
	}
	
	if (document.getElementById('txtContactNo').value == ""){
		alert("Please provide your contact number.");
		ClickPaymentB('basket','pdetail','payment','baskettab','pdetailtab','paymenttab')
		document.getElementById('txtContactNo').focus();
		return false;
	}
	
	if (document.getElementById('txtAddress1').value == "" || document.getElementById('txtAddress2').value == "" || document.getElementById('txtAddress3').value == "" || document.getElementById('txtAddress4').value == ""){
		alert("Please provide all the relevant delivery details.");
		ClickPaymentB('basket','pdetail','payment','baskettab','pdetailtab','paymenttab')
		document.getElementById('txtAddress1').focus();
		return false;
	}
	
	return true;
}

function fnValidateDetails(){
	if (document.getElementById('txtTitle').value == ""){
		alert("Please provide your salutation.");
		ClickPaymentA('pdetail','delivery','history','pdetailtab','deliverytab','historytab');
		document.getElementById('txtTitle').focus();
		return false;
	}
	
	if (document.getElementById('txtFirstName').value == ""){
		alert("Please provide your first name.");
		ClickPaymentA('pdetail','delivery','history','pdetailtab','deliverytab','historytab')
		document.getElementById('txtFirstName').focus();
		return false;
	}
	
	if (document.getElementById('txtLastName').value == ""){
		alert("Please provide your last name.");
		ClickPaymentA('pdetail','delivery','history','pdetailtab','deliverytab','historytab')
		document.getElementById('txtLastName').focus();
		return false;
	}
	
	if (document.getElementById('txtEmail').value == ""){
		alert("Please provide your email address.");
		ClickPaymentA('pdetail','delivery','history','pdetailtab','deliverytab','historytab')
		document.getElementById('txtEmail').focus();
		return false;
	}
	
	var addr = document.getElementById('txtEmail').value
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
	   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
		  alert('The email address contains invalid characters');
		  return false;
	   }
	}
	
	for (i=0; i<addr.length; i++) {
	   if (addr.charCodeAt(i)>127) {
		  alert("The email address contains non ascii characters.");
		  return false;
	   }
	}
	
	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
	   alert('The email address must contain an @');
	   return false;
	}
	if (atPos == 0) {
	   alert('The email address must not start with @');
	   return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
	   alert('The email address must contain only one @');
	   return false;
	}
	if (addr.indexOf('.', atPos) == -1) {
	   alert('The email address must contain a period in the domain name');
	   return false;
	}
	if (addr.indexOf('@.',0) != -1) {
	   alert('The period must not immediately follow @ in email address');
	   return false;
	}
	if (addr.indexOf('.@',0) != -1){
	   alert('The period must not immediately precede @ in email address');
	   return false;
	}
	if (addr.indexOf('..',0) != -1) {
	  alert('The two periods must not be adjacent in email address');
	   return false;
	}
	
	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
	   alert('The primary domain in email address is invalid');
	   return false;
	}
	
	if (document.getElementById('txtContactNo').value == ""){
		alert("Please provide your contact number.");
		ClickPaymentA('pdetail','delivery','history','pdetailtab','deliverytab','historytab')
		document.getElementById('txtContactNo').focus();
		return false;
	}
	
	if (document.getElementById('txtAddress1').value == "" || document.getElementById('txtAddress2').value == "" || document.getElementById('txtAddress3').value == "" || document.getElementById('txtAddress4').value == ""){
		alert("Please provide all the relevant delivery details.");
		ClickPaymentB('pdetail','delivery','history','pdetailtab','deliverytab','historytab')
		document.getElementById('txtAddress1').focus();
		return false;
	}
	
	return true;
}

function fnRegValidate(obj){
	if (document.getElementById('txtCompanyName').value == ""){
		alert("Please provide your company name");
		document.getElementById('txtCompanyName').focus();
		return false;
	}
	
	if (document.getElementById('txtContactPerson').value == ""){
		alert("Please provide a contact persons name");
		document.getElementById('txtContactPerson').focus();
		return false;
	}
	
	if (document.getElementById('txtContactNo').value == ""){
		alert("Please provide a contact persons number");
		document.getElementById('txtContactNo').focus();
		return false;
	}
	
	if (document.getElementById('txtContactEmail').value == ""){
		alert("Please provide a contact email address");
		document.getElementById('txtContactEmail').focus();
		return false;
	}
	
	var addr = document.getElementById('txtContactEmail').value
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
	   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
		  alert('The email address contains invalid characters');
		  return false;
	   }
	}
	
	for (i=0; i<addr.length; i++) {
	   if (addr.charCodeAt(i)>127) {
		  alert("The email address contains non ascii characters.");
		  return false;
	   }
	}
	
	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
	   alert('The email address must contain an @');
	   return false;
	}
	if (atPos == 0) {
	   alert('The email address must not start with @');
	   return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
	   alert('The email address must contain only one @');
	   return false;
	}
	if (addr.indexOf('.', atPos) == -1) {
	   alert('The email address must contain a period in the domain name');
	   return false;
	}
	if (addr.indexOf('@.',0) != -1) {
	   alert('The period must not immediately follow @ in email address');
	   return false;
	}
	if (addr.indexOf('.@',0) != -1){
	   alert('The period must not immediately precede @ in email address');
	   return false;
	}
	if (addr.indexOf('..',0) != -1) {
	  alert('The two periods must not be adjacent in email address');
	   return false;
	}
	
	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
	   alert('The primary domain in email address is invalid');
	   return false;
	}	
}

function fnLoadAccount(currency, rate){
	var iTotal

	document.getElementById('bsktinfo').style.display = 'block'
	
	rspText = document.getElementById('account').value;
	if (rspText != ""){
		sDetail = '<table width="200px" border="0" cellpadding="2" cellspacing="0" class="prodtable">'
		sDetail = sDetail + '<tr><td class="prodheading" width="50%" align="left">Product</td><td class="prodheading" width="25%" align="left">Qty</td></tr>'
		iTotal = 0
		oProducts = rspText.split("|");
		for (i=0;i<oProducts.length;i++){
			oDetail = oProducts[i].split(":");
			sFunction = "makeRequest('/process.asp?id="+oDetail[0]+"&action=sum&amt='+this.value)"
			sDetail = sDetail + '<tr><td class="account-body" valign="absbottom">&nbsp;'+oDetail[5]+'</td><td valign="bottom" class="account-body"><select name="qty" id="qty" style="width: 85%;" onChange="'+sFunction+'">'
			iCount = (oDetail[3]>10) ? 10 : oDetail[3]
			for (j=0;j<=iCount;j++){
					if (j == oDetail[1]){
						sDetail = sDetail + '<option value='+j+' selected>'+j+'</option>'
					}else{
						sDetail = sDetail + '<option value='+j+'>'+j+'</option>'
					}
			}
			iSubTotal = (oDetail[1]*oDetail[4])
								
			iTotal = iTotal + iSubTotal
			sDetail = sDetail + '</select></td></tr>'
			sDetail = sDetail + '<tr><td align="center" colspan="2"><hr size="1" width="100%"></td></tr>'
		}
		sTotal = iTotal.toString();
		oAmount = sTotal.split(".");
		if (oAmount.length > 1){
			if (oAmount[1].length == 1){sTotal = sTotal+'0'};
		}else{
			sTotal = sTotal+'.00'
		}
		
		sDetail = sDetail + '<tr><td class="account-body"><b>Total</b></td><td class="account-body"><b>'+currency+'&nbsp;'+RoundDec((sTotal*rate),2)+'</b></td></tr>'
		sDetail = sDetail + '</table>'
		sDetail = sDetail + '<br style="line-height:10px"><table width="200px" cellpadding="0" cellspacing="0"><tr><td align="left">'
		sDetail = sDetail + '<input type="button" name="checkout" value="Checkout" class="plainbutton" onClick="fnLoadCheckOut();" style="width:170px;">'
		sDetail = sDetail + '</td></tr></table>'

		document.getElementById('bsktaccount').innerHTML = sDetail
	}else{
		sTotal = '0.00'
		sDetail = '<table width="200px" cellpadding="2" cellspacing="0" class="prodtable" border="0">'
		sDetail = sDetail + '<tr><td class="prodheading" colspan="2" align="center">Your basket is empty.</td></tr>'
		sDetail = sDetail + '<tr><td class="account-body">&nbsp;<b>Total</b></td><td class="account-body" align="left">&nbsp;&nbsp;<b>'+currency+'&nbsp;'+RoundDec(sTotal,2)+'</b></td></tr>'
		sDetail = sDetail + '</table>'
		sDetail = sDetail + '</table>'
		
		document.getElementById('bsktaccount').innerHTML = sDetail
	}
}

function fnLoadCheckOut(){
	document.location="/ZW/14/Checkout.html";
}

function fnAddfavourite(){
   if (document.all){
      window.external.AddFavorite
      ("http://wireddev","Perfectform - Nutritional Supplementation")
   }
}

function fnPreload(){ 
  var args = fnPreload.arguments;
  document.imageArray = new Array(args.length);
  for(var i=0; i<args.length; i++)
  {
    document.imageArray[i] = new Image;
    document.imageArray[i].src = args[i];
  }
}

// onMouseOver="javascript:ShowAdBox('+oDetail[0]+',event.clientX,event.clientY)" onMouseOut="HideAdBox()"

function ClickA(ele1,ele2,ele3,tab1,tab2,tab3){	
	document.all.item(ele1).style.display = 'block';
	document.all.item(ele2).style.display = 'none';
	document.all.item(ele3).style.display = 'none';
	document.all.item(tab1).style.display = 'block';
	document.all.item(tab2).style.display = 'none';
	document.all.item(tab3).style.display = 'none';
}

function ClickPaymentA(ele1,ele2,ele3,tab1,tab2,tab3){	
	document.all.item(ele1).style.display = 'block';
	document.all.item(ele2).style.display = 'none';
	document.all.item(ele3).style.display = 'none';
	document.all.item(tab1).style.display = 'block';
	document.all.item(tab2).style.display = 'none';
	document.all.item(tab3).style.display = 'none';
	document.getElementById('buttonB').style.display = 'none';
	document.getElementById('buttonA').style.display = 'block';
	document.getElementById('buttonC').style.display = 'none';
}


function ClickB(ele1,ele2,ele3,tab1,tab2,tab3){
	document.all.item(ele1).style.display = 'none';
	document.all.item(ele2).style.display = 'block';
	document.all.item(ele3).style.display = 'none';
	document.all.item(tab1).style.display = 'none';
	document.all.item(tab2).style.display = 'block';
	document.all.item(tab3).style.display = 'none';
}

function ClickPaymentB(ele1,ele2,ele3,tab1,tab2,tab3){
	document.all.item(ele1).style.display = 'none';
	document.all.item(ele2).style.display = 'block';
	document.all.item(ele3).style.display = 'none';
	document.all.item(tab1).style.display = 'none';
	document.all.item(tab2).style.display = 'block';
	document.all.item(tab3).style.display = 'none';
	document.getElementById('buttonB').style.display = 'block';
	document.getElementById('buttonA').style.display = 'none';
	document.getElementById('buttonC').style.display = 'none';
}

function ClickC(ele1,ele2,ele3,tab1,tab2,tab3){
	document.all.item(ele1).style.display = 'none';
	document.all.item(ele2).style.display = 'none';
	document.all.item(ele3).style.display = 'block';
	document.all.item(tab1).style.display = 'none';
	document.all.item(tab2).style.display = 'none';
	document.all.item(tab3).style.display = 'block';
}

function ClickPaymentC(ele1,ele2,ele3,tab1,tab2,tab3){
	document.all.item(ele1).style.display = 'none';
	document.all.item(ele2).style.display = 'none';
	document.all.item(ele3).style.display = 'block';
	document.all.item(tab1).style.display = 'none';
	document.all.item(tab2).style.display = 'none';
	document.all.item(tab3).style.display = 'block';
	document.getElementById('buttonB').style.display = 'none';
	document.getElementById('buttonA').style.display = 'none';
	document.getElementById('buttonC').style.display = 'block';
}

function fnShowLogin(){
	if (document.getElementById('txtAccount').checked == true){
		document.getElementById('login').style.display = 'block';
		document.getElementById('txtUserName').value = document.getElementById('txtEmail').value;
	}else{
		document.getElementById('login').style.display = 'none';
		document.getElementById('txtUserName').value = "";
	}
}

function fnLoadTitle(obj){
	document.getElementById('TitleText').value = obj
}

function fnShowProduct(obj){
	if (document.getElementById('prodvis'+obj).style.display == 'none'){
		document.getElementById('prodvis'+obj).style.display = 'block';
	}else{
		document.getElementById('prodvis'+obj).style.display = 'none';
	}
}

function HideAdBox()
{
	document.getElementById("myAdBox").style.display="none";
	document.getElementById("myAdBox").innerHTML="";
}

function ShowAdBox(pid, xx, yy)
{	
	var HTML;
	
	HTML = "<span class='prodheading' align='center'>Product Information</span><br><br>"
	
	if (document.getElementById("myAdBox").style.display=="none")
	{
		if (HTML!='')
		{	
			if(HTML==null){HTML="Perfectform - Nutritional Supplementation"}		
			HTML = HTML + "Product Info: "+ document.getElementById('info'+pid).value
			document.getElementById("myAdBox").innerHTML = HTML;
			
			if (xx < 460){
				document.getElementById("myAdBox").style.left=xx - 5;	
			}else{
				document.getElementById("myAdBox").style.left=460
			}
			
			document.getElementById("myAdBox").style.top=yy+5 + document.body.scrollTop;
			document.getElementById("myAdBox").style.display="";
		}
	}
}

function fnLoadDepot(){
	if (document.getElementById('txtDepot').value == ""){
		document.getElementById('txtProvince').value = ""
		document.getElementById('collection').style.display = 'none';
	}else{
		document.getElementById('collection').style.display = 'block';
		
		sAddress = document.getElementById('txtDepot').value 
		oAddress = sAddress.split("|");
		
		document.getElementById('txtProvince').value = oAddress[0]
		if (oAddress[1] != ""){
			oDetail = oAddress[1].split(",");
			document.getElementById('txtStreet').value = oDetail[0]
			document.getElementById('txtSuburb').value = oDetail[1]
			document.getElementById('txtState').value = oDetail[2]
			document.getElementById('txtCode').value = oDetail[3]
		}else{
			document.getElementById('txtStreet').value = ""
			document.getElementById('txtSuburb').value = ""
			document.getElementById('txtStatue').value = ""
			document.getElementById('txtCode').value = ""
		}
	}
}

function fnValidateLocalRegistration(formVal){
	var ReqVar, VarLabel
	var ReqArray, FieldArray
	var bReq
	
	bReq = false;
	if (formVal == 1){
		ReqVar = "txtFirstname,txtLastname,txtContact1,txtVerify";
		FieldVar = "* First name,* Last name,* Your mobile no.,* Verification text";
	}else if (formVal == 2){
		ReqVar = "txtUserName,txtPassword,txtPassword2";
		FieldVar = "User name,Password,Retype password";
	}else if (formVal == 3){
		ReqVar = "txtName,txtSurname,txtDialCountry,txtContact1,txtIDNumber,txtDepot";
		FieldVar = "* Name,* Surname,* Dial code country,* Contact cell no.,* ID/Passport number,* Depot";
	}else {
		ReqVar = "txtFirstname,txtLastname,txtDialCountry,txtContact1";
		FieldVar = "* First name,* Last name,* Dial code country,* Your mobile no.";
	}
	ReqArray = ReqVar.split(",");
	FieldArray = FieldVar.split(",");
	
	for (j=0;j<FieldArray.length;j++){
		for (i=0;i<ReqArray.length;i++){
			if (j == i){
					document.getElementById("label-"+ReqArray[i]).innerHTML = FieldArray[j];
					break;
			}
		}
	}
	
	for (i=0;i<ReqArray.length;i++){
		if (document.getElementById(ReqArray[i]).value == ""){
			VarLabel = document.getElementById("label-"+ReqArray[i]).innerHTML;
			document.getElementById("label-"+ReqArray[i]).innerHTML = "<span style='color: #f20000; font-weight: bold; text-decoration: none;'>"+VarLabel+"</span>";
			bReq = true;
		}
	}
	
	if (bReq){
		alert("Please note -\r\n  The label(s) highlighted in red are mandatory fields.");
		
		for (i=0;i<=ReqArray.length;i++){
			if (document.getElementById(ReqArray[i]).value == ""){
				document.getElementById(ReqArray[i]).focus();
				break;
			}
		}
		return false;
	}
	
	if (formVal == 2){
		var pwdLen = 6;
		var pwdString = document.getElementById('txtPassword').value
		
		if (pwdString.length < pwdLen) {
			alert("Please enter a password that is 6 characters in length or more.");
			document.getElementById('txtPassword').focus();
			return false;
		}

		if (!alphaNumericCheck(pwdString)){
			alert("Please enter an alphanumeric password of 6 characters or more.")
			document.getElementById('txtPassword').focus();
			return false;
		}
		
		var pwdString = document.getElementById('txtPassword2').value
		
		if (!alphaNumericCheck(pwdString)){
			alert("Please enter an alphanumeric password of 6 characters or more in your retyped password.")
			document.getElementById('txtPassword2').focus();
			return false;
		}
		
		if (document.getElementById('txtPassword').value != document.getElementById('txtPassword2').value){
			alert("Please ensure that the passwords are an exact match.")
			return false;
		}
	}

	return true;
}


function fnValidateRegistration(formVal){
	var ReqVar, VarLabel
	var ReqArray, FieldArray
	var bReq
	
	bReq = false;
	if (formVal == 1){
		ReqVar = "txtFirstname,txtLastname,txtContact5,txtContact1,txtVerify";
		FieldVar = "* First name,* Last name,* Contact email,* Your mobile no.,* Verification text";
	}else if (formVal == 2){
		ReqVar = "txtUserName,txtPassword,txtPassword2";
		FieldVar = "User name,Password,Retype password";
	}else if (formVal == 3){
		ReqVar = "txtName,txtSurname,txtDialCountry,txtContact1,txtIDNumber,txtDepot";
		FieldVar = "* Name,* Surname,* Dial code country,* Contact cell no.,* ID/Passport number,* Depot";
	}else {
		ReqVar = "txtFirstname,txtLastname,txtContact5,txtDialCountry,txtContact1";
		FieldVar = "* First name,* Last name,* Contact email,* Dial code country,* Your mobile no.";
	}
	ReqArray = ReqVar.split(",");
	FieldArray = FieldVar.split(",");
	
	for (j=0;j<FieldArray.length;j++){
		for (i=0;i<ReqArray.length;i++){
			if (j == i){
					document.getElementById("label-"+ReqArray[i]).innerHTML = FieldArray[j];
					break;
			}
		}
	}
	
	for (i=0;i<ReqArray.length;i++){
		if (document.getElementById(ReqArray[i]).value == ""){
			VarLabel = document.getElementById("label-"+ReqArray[i]).innerHTML;
			document.getElementById("label-"+ReqArray[i]).innerHTML = "<span style='color: #f20000; font-weight: bold; text-decoration: none;'>"+VarLabel+"</span>";
			bReq = true;
		}
	}
	
	if (bReq){
		alert("Please note -\r\n  The label(s) highlighted in red are mandatory fields.");
		
		for (i=0;i<=ReqArray.length;i++){
			if (document.getElementById(ReqArray[i]).value == ""){
				document.getElementById(ReqArray[i]).focus();
				break;
			}
		}
		return false;
	}
	
	if (formVal == 1){
		if (document.getElementById('txtContact5').value == ""){
			alert("Please provide a contact email address");
			document.getElementById('txtContact5').focus();
			return false;
		}
		
		var addr = document.getElementById('txtContact5').value
		var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
		for (i=0; i<invalidChars.length; i++) {
		   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
			  alert('The email address contains invalid characters');
			  return false;
		   }
		}
		
		for (i=0; i<addr.length; i++) {
		   if (addr.charCodeAt(i)>127) {
			  alert("The email address contains non ascii characters.");
			  return false;
		   }
		}
		
		var atPos = addr.indexOf('@',0);
		if (atPos == -1) {
		   alert('The email address must contain an @');
		   return false;
		}
		if (atPos == 0) {
		   alert('The email address must not start with @');
		   return false;
		}
		if (addr.indexOf('@', atPos + 1) > - 1) {
		   alert('The email address must contain only one @');
		   return false;
		}
		if (addr.indexOf('.', atPos) == -1) {
		   alert('The email address must contain a period in the domain name');
		   return false;
		}
		if (addr.indexOf('@.',0) != -1) {
		   alert('The period must not immediately follow @ in email address');
		   return false;
		}
		if (addr.indexOf('.@',0) != -1){
		   alert('The period must not immediately precede @ in email address');
		   return false;
		}
		if (addr.indexOf('..',0) != -1) {
		  alert('The two periods must not be adjacent in email address');
		   return false;
		}
		
		var suffix = addr.substring(addr.lastIndexOf('.')+1);
		if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
		   alert('The primary domain in email address is invalid');
		   return false;
		}	
	
	}else if (formVal == 2){
		var pwdLen = 6;
		var pwdString = document.getElementById('txtPassword').value
		
		if (pwdString.length < pwdLen) {
			alert("Please enter a password that is 6 characters in length or more.");
			document.getElementById('txtPassword').focus();
			return false;
		}

		if (!alphaNumericCheck(pwdString)){
			alert("Please enter an alphanumeric password of 6 characters or more.")
			document.getElementById('txtPassword').focus();
			return false;
		}
		
		var pwdString = document.getElementById('txtPassword2').value
		
		if (!alphaNumericCheck(pwdString)){
			alert("Please enter an alphanumeric password of 6 characters or more in your retyped password.")
			document.getElementById('txtPassword2').focus();
			return false;
		}
		
		if (document.getElementById('txtPassword').value != document.getElementById('txtPassword2').value){
			alert("Please ensure that the passwords are an exact match.")
			return false;
		}
	}

	return true;
}

function alphaNumericCheck(textString){
	var num_valid="1234567890"
	var bNum = false
    for (var i=0; i<textString.length; i++) {
		if (num_valid.indexOf(textString.charAt(i)) >= 0) {
			bNum = true
			break;
        }
    }
	
	if (!bNum){
		return false
	}
		
	var alph_valid="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@"
	var bAlpha = false
    for (var i=0; i<textString.length; i++) {
        if (alph_valid.indexOf(textString.charAt(i)) >= 0) {
            bAlpha = true;
			break;
        }
    }
	
	if (!bAlpha){
		return false
	}

	return true;
}

function RoundDec(Original, Decimals) {
    var result1 = Original * Math.pow(10, Decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, Decimals)
    return pad_with_zeros(result3, Decimals)
}

function pad_with_zeros(rounded_value, decimal_places) {

    // Convert the number to a string
    var value_string = rounded_value.toString()
    
    // Locate the decimal point
    var decimal_location = value_string.indexOf(".")

    // Is there a decimal point?
    if (decimal_location == -1) {
        
        // If no, then all decimal places will be padded with 0s
        decimal_part_length = 0
        
        // If decimal_places is greater than zero, tack on a decimal point
        value_string += decimal_places > 0 ? "." : ""
    }
    else {

        // If yes, then only the extra decimal places will be padded with 0s
        decimal_part_length = value_string.length - decimal_location - 1
    }
    
    // Calculate the number of decimal places that need to be padded with 0s
    var pad_total = decimal_places - decimal_part_length
    
    if (pad_total > 0) {
        
        // Pad the string with 0s
        for (var counter = 1; counter <= pad_total; counter++) 
            value_string += "0"
        }
    return value_string
}

function fnPrintWindow(obj){
	window.open("/invoice/print-account.asp?contentid=26&est="+obj,"Checkout","width=600,height=600,toolbar=1");
}

function fnRecipientPrint(){
	window.open("/recipient-card.asp","Recipient","width=350,height=200,toolbar=0,scrollbars=1,menubar=0");
}


