/*
'<!--$$Revision: 15 $-->
'<!--$$Author: Errol $-->
'<!--$$Date: 10/08/09 3:53p $-->
'<!--$$Logfile: /4.0 Arts Hub/shared/js/ajax/subscribe.js $-->
'<!--$$NoKeywords: $-->
*/
var emailIsDupe=null;
var tGlobalPathToCommonASP = "/shared/js/ajax/common.asp";

	//Firstly the renewal js functions
	
	function renewLater(url) {
		window.location=url;
	}
			
	function renewNever(url) {
		//set cookie
		document.cookie = "renew=never;expires=01/01/3000 00:00:00";
		//send Nathan an email
		window.location=url;
	}
	function renewNowCard() {
		if(checkTheFormCardRenew()==false) {
			return (false);
		} else {
		if (document.getElementById("btnPayNowCard")) {	document.getElementById("btnPayNowCard").disabled = true}
			document.Form1.submit();
		}
	}
	function renewNowCheque() {
		if(checkTheFormChequeRenew()==false) {
			return (false);
		} else {
			if (document.getElementById("btnPayNowCheque")) {	document.getElementById("btnPayNowCheque").disabled = true}
			document.Form1.submit();
		}
	}	
	
	function updateForm(panchor) {
		//submit form - but no validation etc
		//alert("update called");
		if (panchor != "") {
			document.Form1.action = "subscribe2.asp#" + panchor;
			//alert(panchor);
		}
		document.Form1.action.value="";
		document.Form1.doCheck.value="no";
		document.Form1.submit();
	}

	function updateSubscribeForm(panchor) {
		//submit form - but no validation etc
		//alert("update called");
		if (typeof(document.Form1.promoCode) != "undefined") {
			if (document.Form1.promoCode.value!= " ") {
				if (panchor != "") {
					document.Form1.action = "subscribe2.asp#" + panchor;
					//alert(panchor);
				}
				
				document.Form1.saction.value="";
				document.Form1.doCheck.value="no";
				document.Form1.submit();
			}
		}
	}
	
	function updateRenewForm(panchor) {
		//submit form - but no validation etc
		//alert("update called");
		if (panchor != "") {
			document.Form1.action = "renew2.asp#" + panchor;
			//alert(panchor);
		}
		
		document.Form1.saction.value="";
		document.Form1.doCheck.value="no";
		document.Form1.submit();
	}
	
	function checkNameTabSet() {
		if (document.userCheckForm) {
			
			if (document.userCheckForm.userEmail.value !="") {
				
				document.userCheckForm.userPassword.focus();
			}
			else {
				
				document.userCheckForm.userEmail.focus();
			}	
		}
	}
	
	function checkUserCheckForm() {
		if (document.userCheckForm.userEmail.value == "") {
			alert('Please fill in your email');
			return false;
		}
		else if (document.userCheckForm.userPassword.value == "") {
			alert('Please fill in your password');
			return false;
		}
		else {
			return true;
		}
	}
	
	
	
	
	// Now the subscribe functions
		
	function processWorldPay() {
		
		document.frmWorldPayPost.submit();
		
	}
	
	function processNoCharge() {
		
		document.frmNoChargePost.submit();
		
	}
	
	function payNowCard() {
	
		document.Form1.doCheck.value = "yes";
	
		if(checkTheFormCardSubscribe()==false) {
			return (false);
		} else {
		if (document.getElementById("btnPayNowCard")) {	document.getElementById("btnPayNowCard").disabled = true}
		document.Form1.submit();
		}
	}
	
	function payNowCheque() {
	
		document.Form1.doCheck.value = "yes";
	
		if(checkTheFormChequeSubscribe()==false) {
			return (false);
		} else {
		if (document.getElementById("btnPayNowCheque")) {	document.getElementById("btnPayNowCheque").disabled = true}
		document.Form1.submit();
		}
	}

	function FrmValidCheque(theForm) {
		if(checkTheFormChequeSubscribe()==false) {
			return (false);
		}
	}
	function FrmValidCard(theForm) {
		if(checkTheFormCardSubscribe()==false) {
			return (false);
		}
	}
	
	function dedupeMatesRates(emailAddress) {
		getDoc('/shared/js/ajax/common.asp?action=dedupematesrates&emailAddress='+encodeURI(emailAddress),'divResponseMatesEmail','');
	}
	
	
function dedupeEmail(emailAddress,memId,tWhereFrom) {
	var msg = "";
	var uri = "";
	var uriCancel = "default.asp";
	var bDoNothing  = false;
	var imgBad = "<img src=\"../shared/images/icons/exclamation.gif\" align=\"absmiddle\" border=\"0\" />";
	var imgGood = "<img src=\"../shared/images/icons/heart.gif\" align=\"absmiddle\" border=\"0\" />";
	document.getElementById("divDeDupe").innerHTML="";
	if(emailAddress=='') {
		document.getElementById("divDeDupe").innerHTML="";
	} else {
		if(emailCheck(emailAddress,false))	{
			
				//If hidden field value is same as text field when we get to renew/upgrade
				//then dont perform check! Stop redirecting again.
				if(typeof(document.forms[0].eEmailOriginal) != "undefined") {
					if (document.forms[0].eEmailOriginal.value!="" && document.forms[0].eEmailOriginal.value == emailAddress){
						bDoNothing = true;
					}	
				}
			
				if(!bDoNothing) {
					//document.getElementById("working").innerHTML=loadstatustext;
					var theString ="../shared/js/ajax/common.asp?action=dedupeemail&emailAddress="+encodeURI(emailAddress)+"&memId="+memId+"&tWhereFrom="+tWhereFrom;
					//alert(theString)
					var aObj=new Array(); 
					var aIndx = aObj.length;
					aObj[aIndx] = new sack();
					aObj[aIndx].requestFile = theString;
					aObj[aIndx].onCompletion = function(){ 
						//This is a good way to debug..
						//window.alert("Response:"+aObj[aIndx].response+"\nFrom:"+tWhereFrom);
						if (aObj[aIndx].response=="true" && tWhereFrom != "recbyemail" && tWhereFrom != "registerforumah") {
							
							if (tWhereFrom != "registerforumah") {
								emailIsDupe=true;
								document.getElementById("divDeDupe").innerHTML=imgBad + " Not Available";
							}
							
							//alert("The email address you have entered is already subscribed. Please choose another.");
							tWhereFrom = tWhereFrom.toLowerCase();
							switch (tWhereFrom) {
								case "subscribe":
									msg = "\"Welcome back to Arts Hub\".\n\nIt appears you have subscribed before!\n\n* Click OK to Renew/Upgrade your membership\n* or Cancel to return to the Homepage.";
									uri = "renew2.asp?sdd=1&fspr=1&email="+emailAddress;// (-_-) Dont go direct to renew-upgrade even if you need to 'trust me'
									break;
								case "subscribe-mini":
									msg = "\"Welcome back to Arts Hub\".\n\nIt appears you have subscribed as a Mini member before!\n\n* Click OK to Renew your membership for FREE!\n* or Cancel to return to the Homepage.";
									uri = "renew2.asp?sdd=1&ofa=1&email="+emailAddress; // (-_-) Dont go direct to renew-upgrade even if you need to 'trust me'
									break;
								case "renew":
									msg = "\"Welcome back to Arts Hub\".\n\nThe email address you have entered is subscribed!\n\n* Click OK to go and subscribe with another email address\n* or Cancel to return to the Homepage.";
									uri = "subscribe1.asp";
									break;
								case "convert":
									msg = "\"Welcome back to Arts Hub\".\n\nThe email address you have entered is already subscribed!\n\n* Click OK to Renew your subscription\n* or Cancel to return to the Homepage.";
									uri = "renew1.asp";
									break;
								case "trial":
									msg = "\"Welcome back to Arts Hub\".\n\nIt appears you may have already taken a trial with us!\n\n* Click OK to Convert to a full subscription\n* or Cancel to return to the Homepage.";
									uri = "renew2.asp?email="+emailAddress;
									break;
								case "orguseradd":
									msg = "\"Email already in use\".\n\nYou need to enter a unique new user email.\n\n* Click OK to check your users for this email\n* or Cancel to return to the page.";
									uri = "javascript: fnGetDashboardTab('userdetails',0);";
									uriCancel = "";
									break;
							}
							temp = window.confirm(msg);
							//Explicitly boolean..
							if (temp==true) {
								MM_goToURL('parent',uri);
							} else if (temp==false) {
								MM_goToURL('parent',uriCancel);
							}
						} else if (aObj[aIndx].response=="true" && tWhereFrom == "recbyemail") {
							document.getElementById("divResponse").innerHTML=imgGood + " Accepted";
						} else if (aObj[aIndx].response=="false" && tWhereFrom == "recbyemail") {
							document.getElementById("divResponse").innerHTML=imgBad + " Email not listed";
							window.alert("Sorry, your friends email appears to be incorrect\nThe email "+emailAddress+" is not in our system\n\nPlease try again!");
						} else if (aObj[aIndx].response=="true" && tWhereFrom == "registerforumah") {
							document.getElementById("divResponse").innerHTML=imgGood + " Registered on Arts Hub";
							document.Form1.btnSubmit.disabled = false;
						} else if (aObj[aIndx].response=="false" && tWhereFrom == "registerforumah") {
							document.getElementById("divResponse").innerHTML=imgBad + " Not a registered email";
							window.alert("Sorry, you cannot proceed\nThe email "+emailAddress+" is not in our system\n\nYou need to join Arts Hub or register as a Forum only member to gain access!");
							history.back();
						} else if (aObj[aIndx].response=="alreadyforum" && tWhereFrom == "subscribe") {
							document.getElementById("divDeDupe").innerHTML=imgBad + " Already registered via ArtsForum";
							msg ="It appears you are already subscribed as a Forum member with the email "+emailAddress+"\n\nYou simply need to upgrade/convert to an Arts Hub subscription to gain access!\n\n* Click OK to Convert to a full subscription\n* or Cancel to return to the Homepage.";
							uri = "convert1.asp";
							temp = window.confirm(msg);
							//Explicitly boolean..
							if (temp==true) {
								MM_goToURL('parent',uri);
							} else if (temp==false) {
								MM_goToURL('parent',uriCancel);
							}
						//Forum member upgrading to a trial
						} else if (aObj[aIndx].response=="gimmeatrial" && tWhereFrom == "trial") {
							document.getElementById("divDeDupe").innerHTML=imgGood + " Upgrading from ArtsForum";
							msg ="It appears you are already subscribed as a Forum member with the email "+emailAddress+"\n\nYou simply need to upgrade/convert to an Arts Hub subscription to gain access!\n\n* Click OK to Convert to a full subscription\n* or Cancel to return to the Homepage.";
						} else {
						emailIsDupe=false;
						//document.getElementById("divDeDupe").innerHTML="<img src='images/icons/tick.gif' align='absmiddle' />";
						};
						//document.getElementById("working").innerHTML=""; 
					};  
					aObj[aIndx].runAJAX();
				}
		} else {
			document.getElementById("divDeDupe").innerHTML=imgBad + " Invalid Email";
			if (tWhereFrom != "registerforumah") {
				if (typeof(document.getElementById("divResponse"))!="undefined") {
					document.getElementById("divResponse").innerHTML="";
					//document.Form1.btnSubmit.disabled = true;
				}
			}
		}	
	}	
}

function fnGetOrgMemberDiscountJoinRedirect(emailAddress) {
	var msg = "";
	var uri = "";
	var uriCancel = "default.asp";
	var imgBad = "<img src=\"../shared/images/icons/exclamation.gif\" align=\"absmiddle\" border=\"0\" />";
	var imgGood = "<img src=\"../shared/images/icons/heart.gif\" align=\"absmiddle\" border=\"0\" />";

	if(emailAddress!='') {
		//document.getElementById("working").innerHTML=loadstatustext;
		var theString ="../shared/js/ajax/common.asp?action=getorgmemdiscjoinredir&eEmail="+encodeURI(emailAddress);
		//alert(theString)
		var aObj=new Array(); 
		var aIndx = aObj.length;
		aObj[aIndx] = new sack();
		aObj[aIndx].requestFile = theString;
		aObj[aIndx].onCompletion = function(){ 
			//This is a good way to debug..
			//window.alert("Response:"+aObj[aIndx].response+"\nFrom:"+tWhereFrom);
			if (aObj[aIndx].response != "") {
				window.alert("It appears you are part of an organisation that gets\ndiscounted subscription rates for members joining Arts Hub\n\nThis page will reload and you will be offered a discount subscription rate!");
				MM_goToURL('parent',aObj[aIndx].response);
			};
		};  
		aObj[aIndx].runAJAX();
	}	
}
/* ________________________________________________ */
//	Name 		- fnUpdateProductCostInPage --------------------------
//  Purpose		- 
//	Args 		- 
//	Returns		- 
/* _______________________________________________ */
	function fnUpdateProductCostInPage(tmpCost, strDiv) {
		var theString = tGlobalPathToCommonASP+"?action=updateprodcostinform&tmpCost="+tmpCost;
		//alert(theString)
		getDoc(theString,strDiv,'');
	}
/* ________________________________________________ */
//	Name 		- fnUpdateTempTermsAndConditions --------------------------
//  Purpose		- 
//	Args 		- 
//	Returns		- 
/* _______________________________________________ */
	function fnUpdateTempTermsAndConditions(pId, nShowHide, strDiv) {
		var theString = tGlobalPathToCommonASP+"?action=updatetermsandconditionsinform&pId="+pId+"&nShowHide="+nShowHide;
		//alert(theString)
		getDoc(theString,strDiv,'');
	}

//(^_^) Just centralising form validation as a temp measure
//		Soon will implement bubbanoosh form validation code library


/* _________________________________________________________________________________________________________________________________ */
/* _________________________________________________________________________________________________________________________________ */
/* _________________________________________________________________________________________________________________________________ */
	
//Renew functions
	function checkTheFormChequeRenew(theForm,getDemographics) {
		theForm=document.Form1
		if (theForm.productid.value =="") {
			alert("Please select Membership Amount.");
			theForm.productId.focus();
			return (false);
		}
		if (theForm.chequeName.value =="") {
			alert("Please enter the name we would expect to see on the cheque.");
			theForm.chequeName.focus();
			return (false);
		}
		if (theForm.FirstName.value=="") 	{
			alert("Please enter your First Name")
			theForm.FirstName.focus()
			return false
		}
		if (theForm.LastName.value=="") 	{
			alert("Please enter your Last Name")
			theForm.LastName.focus()
			return false
		}
		if (theForm.address1.value == "") {
			alert('Please fill in your street address');
			theForm.address1.focus();
			return (false);
		}
		if (theForm.suburb.value == "") {
			alert('Please fill in your Suburb');
			theForm.suburb.focus();
			return (false);
		}
		if (theForm.regionId.value == 0) {
			alert('Please choose your State');
			theForm.regionId.focus();
			return (false);
		}
		if (theForm.postcode.value == "") {
			alert('Please type your Postcode');
			theForm.postcode.focus();
			return (false);
		}
		
		if (theForm.iagree.checked == false) {
			alert("You must agree to the terms and conditions.");
			theForm.iagree.focus();
			return (false);
		}
		if (typeof(theForm.iagree12) != "undefined") {
			if (theForm.iagree12.checked == false) {
				alert("You must agree to the terms of the 12 month agreement.");
				theForm.iagree12.focus();
				return (false);
			}
		}
		if (emailIsDupe) {
			alert("Email address has already been used.");
			theForm.email.focus();
			return (false);
		}	
		if (theForm.email.value =="")  {
			alert("Please enter an Email Address.");
			theForm.email.focus();
			return (false);
		} else {
			if(emailCheck(theForm.email.value))	{
			} else {
				theForm.email.focus();
				return (false);
			}
		}
		/*if (getDemographics=="yes") {
		if (theForm.gender.value=="0") 	{
			alert("Please select Gender")
			theForm.gender.focus()
			return false
		}
		if (theForm.yob.value=="0") 	{
			alert("Please select Year of Birth")
			theForm.yob.focus()
			return false
		}	
		if (theForm.pathwayId.value=="0") 	{
			alert("Please select Sector")
			theForm.pathwayId.focus()
			return false
		}
		if (theForm.classificationId.value=="0") 	{
			alert("Please select Classification")
			theForm.classificationId.focus()
			return false
		}	
		}*/
	}
	
	function checkTheFormCardRenew(theForm) {
		theForm=document.Form1
		//alert(document.Form1.productid.value);
			
		if (theForm.productid.value == "") {
			alert("Please select Subscription type.");
			theForm.productid.focus();
			return (false);
		}
		if (theForm.address1.value == "") {
			alert('Please fill in your street address');
			theForm.address1.focus();
			return (false);
		}
		if (theForm.suburb.value == "") {
			alert('Please fill in your Suburb');
			theForm.suburb.focus();
			return (false);
		}
		if (theForm.regionId.value == 0) {
			alert('Please choose your State');
			theForm.regionId.focus();
			return (false);
		}
		if (theForm.postcode.value == "") {
			alert('Please type your Postcode');
			theForm.postcode.focus();
			return (false);
		}		
	
		
		if (theForm.iagree.checked == false) {
			alert("You must agree to the terms and conditions.");
			theForm.iagree.focus();
			return (false);
		}
		if (typeof(theForm.iagree12) != "undefined") {
			if (theForm.iagree12.checked == false) {
				alert("You must agree to the terms of the 12 month agreement.");
				theForm.iagree12.focus();
				return (false);
			}
		}
		if (theForm.FirstName.value=="") 	{
		alert("Please enter your First Name")
		theForm.FirstName.focus()
		return false
		}
		if (theForm.LastName.value=="") 	{
			alert("Please enter your Last Name")
			theForm.LastName.focus()
			return false
		}
		if (emailIsDupe) {
			alert("Email address has already been used.");
			theForm.email.focus();
			return (false);
		}	
		if (theForm.email.value =="")  {
			alert("Please enter an Email Address.");
			theForm.email.focus();
			return (false);
		} else {
			if(emailCheck(theForm.email.value))	{
			} else {
				theForm.email.focus();
				return (false);
			}
		}
	}

	
//Subscribe stuff
	function checkTheFormChequeSubscribe(theForm) {
		theForm=document.Form1
		if (theForm.productid.value =="") {
			alert("Please select Membership Amount.");
			theForm.productid.focus();
			return (false);
		}
		if (theForm.chequeName.value =="") {
			alert("Please enter the name we would expect to see on the cheque.");
			theForm.chequeName.focus();
			return (false);
		}
		if (theForm.FirstName.value=="") 	{
			alert("Please enter your First Name")
			theForm.FirstName.focus()
			return false
		}
		if (theForm.LastName.value=="") 	{
			alert("Please enter your Last Name")
			theForm.LastName.focus()
			return false
		}
		if (emailIsDupe) {
			alert("Email address has already been used.");
			theForm.email.focus();
			return (false);
		}	
		if (theForm.email.value =="")  {
			alert("Please enter an Email Address.");
			theForm.email.focus();
			return (false);
		} else {
			if(emailCheck(theForm.email.value))	{
			} else {
				theForm.email.focus();
				return (false);
			}
		}
		if (theForm.emailconfirm.value == "")  {
			alert("Please confirm your Email Address.");
			theForm.emailconfirm.focus();
			return (false);
		} else {
			if (theForm.emailconfirm.value != theForm.email.value) {
				alert("Email address do not match");
				theForm.emailconfirm.focus();
				return (false);
			}
		}
		if (validatePW(theForm.password.value) || (theForm.password.value.length<5 || theForm.password.value.length>10)){
			alert("Passwords must be between 5 and 10 characters long, and can only contain letters, numbers, and underscores");
			theForm.password.focus();
			return (false);
		}
		if(isNaN(theForm.password.value))	{
		} else {
			alert("For security reasons Passwords cannot be all numbers.");
			theForm.password.focus();
			return (false);
		}
		if (theForm.password.value != theForm.password2.value) {
			alert("Confirmation Password is not the same as Password.");
			theForm.password2.focus();
			return (false);
		}
		//Users have been adding nil or N/A etc for friends email..
		if (typeof(theForm.recByEmail)!="undefined") {
			if (theForm.recByEmail.value != "") {
				if(!emailCheck(theForm.recByEmail.value))	{
					theForm.recByEmail.focus();
					return (false);
				}
			}
		}
		if (theForm.regionId.value == 0) {
			alert('Please choose your State');
			theForm.regionId.focus();
			return (false);
		}
		/*if (theForm.heardabout.value == 0) {
		alert('Please choose how you heard about us');
		theForm.heardabout.focus();
		return (false);
		}*/
		if (theForm.address1.value == "") {
			alert('Please fill in your street address');
			theForm.address1.focus();
			return (false);
		}
		if (theForm.suburb.value == "") {
			alert('Please fill in your Suburb');
			theForm.suburb.focus();
			return (false);
		}
		if (theForm.postcode.value == "") {
			alert('Please fill in your Postcode');
			theForm.postcode.focus();
			return (false);
		}
		if (theForm.iagree.checked == false) {
			alert("You must agree to the terms and conditions of subscription.");
			theForm.iagree.focus();
			return (false);
		}
		if (typeof(theForm.iagree12) != "undefined") {
			if (theForm.iagree12.checked == false) {
				alert("You must agree to the terms of the 12 month agreement.");
				theForm.iagree12.focus();
				return (false);
			}
		}
		
	}
	
	function checkTheFormCardSubscribe(theForm) {
		theForm=document.Form1
		window.alert("ey");
		return false;
		if (theForm.productid.value =="") {
			alert("Please select Membership Amount.");
			theForm.productid.focus();
			return (false);
		}		
		if (theForm.FirstName.value=="") 	{
			alert("Please enter your First Name")
			theForm.FirstName.focus()
			return false
		}
		if (theForm.LastName.value=="") 	{
			alert("Please enter your Last Name")
			theForm.LastName.focus()
			return false
		}
		if (emailIsDupe) {
			alert("Email address has already been used.");
			theForm.email.focus();
			return (false);
		}	
		if (theForm.email.value == "")  {
			alert("Please enter an Email Address.");
			theForm.email.focus();
			return (false);
		} else {
			if(emailCheck(theForm.email.value))	{
			} else {
				theForm.email.focus();
				return (false);
			}
		}
		if (theForm.emailconfirm.value == "")  {
			alert("Please confirm your Email Address.");
			theForm.emailconfirm.focus();
			return (false);
		} else {
			if (theForm.emailconfirm.value != theForm.email.value) {
				alert("Email address do not match");
				theForm.emailconfirm.focus();
				return (false);
			}
		}
		if (validatePW(theForm.password.value) || (theForm.password.value.length<5 || theForm.password.value.length>8)){
			alert("Passwords must be between 5 and 8 characters long, and can only contain letters, numbers, and underscores");
			theForm.password.focus();
			return (false);
		}
		if(isNaN(theForm.password.value))	{
		} else {
			alert("For security reasons Passwords cannot be all numbers.");
			theForm.password.focus();
			return (false);
		}
		if (theForm.password.value != theForm.password2.value) {
			alert("Confirmation Password is not the same as Password.");
			theForm.password2.focus();
			return (false);
		}
		//Users have been adding nil or N/A etc for friends email..
		if (typeof(theForm.recByEmail)!="undefined") {
			if (theForm.recByEmail.value != "") {
				if(!emailCheck(theForm.recByEmail.value))	{
					theForm.recByEmail.focus();
					return (false);
				}
			}
		}
		if (theForm.regionId.value == 0) {
			alert('Please choose your State');
			theForm.regionId.focus();
			return (false);
		}
		/*if (theForm.heardabout.value == 0) {
		alert('Please choose how you heard about us');
		theForm.heardabout.focus();
		return (false);
		}*/
		if (theForm.address1.value == "") {
			alert('Please fill in your street address');
			theForm.address1.focus();
			return (false);
		}
		if (theForm.suburb.value == "") {
			alert('Please fill in your Suburb');
			theForm.suburb.focus();
			return (false);
		}
		if (theForm.postcode.value == "") {
			alert('Please fill in your Postcode');
			theForm.postcode.focus();
			return (false);
		}
		if (theForm.iagree.checked == false) {
			alert("You must agree to the terms and conditions of subscription.");
			theForm.iagree.focus();
			return (false);
		}
		if (typeof(theForm.iagree12) != "undefined") {
			if (theForm.iagree12.checked == false) {
				alert("You must agree to the terms of the 12 month agreement.");
				theForm.iagree12.focus();
				return (false);
			}
		}
	}

