/**
* Google : Page tracking for flash.
*/
function googleTracker(url)
{
	//alert("PageTracker: "+url);
	pageTracker._trackPageview(url);
}



//function to pop contact form (result of change order in June 2009)
function showContact(){
	
	var _url="http://contact.americancrew.com/contact-form.aspx?ref=ac&uid="+readCookie("acuid"); 
	var leftVal = (screen.availWidth-755)/2;
	var topVal = (screen.availHeight-850)/2;
	var thedest=window.open(_url,null,"height=850,width=755,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,left=" +leftVal+",top="+topVal);
}

function footerClick(str,fromXHTML){
	/* ------Footer links are no longer in the popup. They will slide out from the Right.

	var url;
	if (str=="privacy"){
		url = "privacypolicy.aspx";
	}else{
		url = "noanimaltesting.aspx";
	}
	var leftVal = (screen.availWidth-550)/2;
	var topVal = (screen.availHeight-450)/2;
	var thedest=window.open(url,null,"height=450,width=550,status=no,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,left=" +leftVal+",top="+topVal);
	
	*/
	
	//slide form out and load policy
	if (str=="privacy"){
	
		document.getElementById('Forgotfrm').style.display = "none";
		document.getElementById('Registerfrm').style.display="none";
		document.getElementById('Loginfrm').style.display="none";
		document.getElementById('animalpolicy').style.display="none";
		document.getElementById('privacypolicy').style.display="block";
		if (fromXHTML=='1'){
			animateOut('0') //animate div out
			document.location="#pp";
		}else{
			animateOut('1') //animate div out
		}
	}else{
		document.getElementById('Forgotfrm').style.display = "none";
		document.getElementById('Registerfrm').style.display="none";
		document.getElementById('Loginfrm').style.display="none";
		document.getElementById('privacypolicy').style.display="none";
		document.getElementById('animalpolicy').style.display="block";
		if (fromXHTML=='1'){
			animateOut('0') //animate div out
			document.location="#ap";
		}else{
			animateOut('1') //animate div out
		}
	}
	
}

function shopCategoryChange(){

	if (document.getElementById('category').value!=""){
		if (document.getElementById('category').value!='All'){
			if (location.href.indexOf("/shop/category/")>0){
				document.location=document.getElementById('category').value;
			}else{
				document.location= "shop/category/"+document.getElementById('category').value;
			}
		}else{
			if (location.href.indexOf("/shop/category/")>0){
				document.location= "../../shop";
			}
		}
	}
}

function shopDetailCategoryChange(){
	if (document.getElementById('category').value!=""){
		if (document.getElementById('category').value!='All'){
			document.location= "../shop/category/"+document.getElementById('category').value;
		}else{
			document.location= "../../shop"
			
		}
	}

}

function checkOut(){
	
	var ProductIdList = document.getElementById('ProductIdList').value;
	var prodarr = ProductIdList.split(",")
	var x=0;
	for (var i=0;i<prodarr.length;i++){
		x++;
		if (document.getElementById('quantity_'+x).value=="0"){
			alert('Please remove all products with a zero quantity.');
			return
		}
	}	
	
	
	var url = "https://www.paypal.com/cgi-bin/webscr?cmd=_cart&upload=1&business=salonloyalties@americancrew.com"
	//TEST ENV
	//var url = "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_cart&upload=1&business=salonloyalties@americancrew.com"
	
	var ProductIdList = document.getElementById('ProductIdList').value;
	var prodarr = ProductIdList.split(",")
	var x=0;
	var SKUs='';
	var Amounts='';
	if(ProductIdList.length > 0){
		for (var i=0;i<prodarr.length;i++)
		{
			x++;
			url+="&item_name_"+x+"="+convert_chars_forPP(document.getElementById('item_name_'+x).value);
			url+="&amount_"+x+"="+document.getElementById('amount_'+x).value;
			url+="&quantity_"+x+"="+document.getElementById('quantity_'+x).value;
			SKUs+="&sku_"+x+"="+document.getElementById('sku_'+x).value.split("#").join("[pnd]");
			Amounts+="&quantity_"+x+"="+document.getElementById('quantity_'+x).value;
			url+="&weight_"+x+"="+document.getElementById('weight_'+x).value;
		}
		
		url+="&first_name="+document.getElementById('first_name').value;
		url+="&last_name="+document.getElementById('last_name').value;
		url+="&rm=1";
		url+="&cancel_return="+document.getElementById('cancel_return').value;
		//url+="&weight_cart=10";
		url+="&weight_unit=lbs";

		//update the DB and set CONFIRMED to inactive
		var Confirmedurl = slcnt + "data/includes/updatecart.aspx?confirmed=false&" + document.getElementById('userInformation').value+"&productCount=" + document.getElementById('productCount').value+SKUs+Amounts; 
		xml = new JKL.ParseXML( Confirmedurl );   
		data = xml.parse();
		//now go to paypal
		document.location=url;
		//alert(url)
	}else{
		alert("You must have at least one item in your cart to check out.")
	}
}
function convert_chars_forPP(str){
	var ret;
	ret = str.split("&").join("and");
	ret = ret.split("™").join("");
	ret = ret.split("®").join("");
	var tmp = escape(ret)
	ret = unescape(tmp.split("%u2122").join("")) //This was added to get rid of the trademark sysmbol//
	return ret
}
function UpdateCart(){
	
	var ProductIdList = document.getElementById('ProductIdList').value;
	var prodarr = ProductIdList.split(",")
	var x=0;
	for (var i=0;i<prodarr.length;i++){
		x++;
		if (document.getElementById('quantity_'+x).value=="0"){
			alert('Please remove all products with a zero quantity.');
			return
		}
	}	

	CartformObj.submit()
	//update quantity in cart
	var tmpCnt = document.getElementById('_shopquantity').innerHTML;
	//var ProductIdList = document.getElementById('ProductIdList').value;
	//var prodarr = ProductIdList.split(",")
	var tmpCnt = 0;
	var x=0;
	for (var i=0;i<prodarr.length;i++)
	{
		x++;
		if (document.getElementById('quantity_'+x).value!="0" && isInt(document.getElementById('quantity_'+x).value)){
			tmpCnt+=parseInt(document.getElementById('quantity_'+x).value); //add all items in textboxes together
		}
	}
	
	
	document.getElementById('_shopquantity').innerHTML = tmpCnt;
	document.getElementById('serverMessage').innerHTML = "Your shopping cart has been updated";

}
function checkNAN(divID){
	if (isInt(document.getElementById(divID).value)==false){
		alert('Please enter a valid quantity');
		return
	}
	//alert(document.getElementById(divID).value)
	if (document.getElementById(divID).value=="0"){
		alert('Please remove all products with a zero quantity.');
		return
	}
}
function isInt(x) {
   var y=parseInt(x);
   if (isNaN(y)) return false;
   return x==y && x.toString()==y.toString();
 } 
function remove_cart_item(itemID,userID,itemDivId,slashCount,quantityInputBox){

	var url = (slashCount+"data/includes/updateCart.aspx");
	var poststr = "rem=" + itemID + "&userid=" + userID;
	makePOSTRequest(url, poststr)
	
	document.location="http://www.americancrew.com/shop/cart";
   // $("#"+itemDivId).fadeOut("slow");
	
	//update quantity in cart
	var tmpCnt = document.getElementById('_shopquantity').innerHTML;
	var tmpQ = document.getElementById(quantityInputBox).value;
	var productCount = document.getElementById('productCount').value;
	var ProductIdList = document.getElementById('ProductIdList').value;
	
	var pcnt = parseInt(tmpCnt)-1;
	var shqnt = parseInt(tmpCnt)-parseInt(tmpQ);
	
	document.getElementById('productCount').value = pcnt; //update hidden field. remove one product type.
	document.getElementById('_shopquantity').innerHTML = shqnt;  //update label to user
	
	var prodarr = ProductIdList.split(",")
	var tmpHolderForNonRemovedIds=''
	for (var i=0;i<prodarr.length;i++)
	{
		if (prodarr[i]==itemID){
		//	alert('remove id='+prodarr[i])
		}else{ //add to list
			if (tmpHolderForNonRemovedIds==''){
				tmpHolderForNonRemovedIds = prodarr[i];
			}else{
				tmpHolderForNonRemovedIds = tmpHolderForNonRemovedIds + "," + prodarr[i];
			}
		}
	}

	document.getElementById('ProductIdList').value = tmpHolderForNonRemovedIds; //set value back in temp hidden field
	location.href="../../shop/cart"; //forget it. I tried to remove items but there are issues with removing items from cart. So I will just refresh.
}
var flashForgot = 0;
function forgotFlashPassword(){
	document.getElementById('Forgotfrm').style.display = "block";
	document.getElementById('Registerfrm').style.display="none";
	document.getElementById('Loginfrm').style.display="none";
	document.getElementById('privacypolicy').style.display="none";
	document.getElementById('animalpolicy').style.display="none";
	flashForgot = 1;
	animateOut('1') //animate div out

}

function forgotPassword(){
	document.getElementById('Forgotfrm').style.display = "block";
	document.getElementById('Registerfrm').style.display="none";
	document.getElementById('Loginfrm').style.display="none";
	document.getElementById('privacypolicy').style.display="none";
	document.getElementById('animalpolicy').style.display="none";
	animateOut('0') //animate div out
}
function checkForgotForm(){
	if (document.getElementById('forgot_email').value == ''){
		alert("You must enter a valid email address.")
	}else{
		//submit
		var url = slcnt + "data/includes/RegisterInterface.aspx?forgot=true&forgot_email="+document.getElementById('forgot_email').value; 
		xml = new JKL.ParseXML( url );   
		data = xml.parse();
		if (data["complete"]!=undefined){
			if (data["complete"]=="error"){ //email not found
				alert("This email address is not registered with American Crew. Please enter a registered email addresss.");
				document.getElementById('forgot_email').value = "";
				return
			}else{
				//IF THERE IS AN ERROR OR NOT SHOW THEM THIS
				//wrap up.
				document.getElementById('forgot_email').value = "";
				if (flashForgot==1){
					//flash requires this
					document.getElementById('Forgotmessage').innerHTML = "<h1>Forgot Password</h1><p>We have emailed you a password to access our system.</p><p>To close this form please <a href=\"javascript:closeDom();\">click here</a>.</p>";
					//document.getElementById('Forgotmessage').innerHTML = "<h1>Forgot Password</h1><p>We have emailed you a password to access our system. Please <a href=\"javascript:toggle_forms('login');\">click here</a> to login.</p>";
					
				}else{
					document.getElementById('Forgotmessage').innerHTML = "<h1>Forgot Password</h1><p>We have emailed you a password to access our system. Please <a href=\"javascript:toggle_forms('login');\">click here</a> to login.</p>";

				}
				return
			}	
			
		}
		
	}


}
// -----------------------   FORM INFORMATION
function animateOut(isFlash){
	
	if (flashForgot==1){
		document.getElementById('Forgotmessage').innerHTML = "<h1>Forgot Password</h1><p>To have your password emailed to your account please fill out the information below. If you already have an account <a href=\"javascript:closeDom();\">click here</a> to login.</p>";
	}

	if (isFlash=="0"){
		document.getElementById('opquelayer').style.display="block";
	}else{
		closeDomFlash=1;
	}
	$('#formwrapper').animate({
		left:"0px"
	}, 1000);
	$('#wrapper').animate({
		left:"365px"
	}, 1000);

	
	document.body.style.overflow = "hidden";

	//alert(document.body.style.overflowY)
}
var closeDomFlash=0;
var isFlashRegistration=0;
function toggle_forms(item,flash){
	
	
	if (flash!=undefined){
		if (flash=="1"){
			animateOut('1') //animate div out
			isFlashRegistration = 1; //in case a person uses flash registration form
			document.getElementById('registermessage').innerHTML = "<h1>Please Register</h1><p>Please fill out the following information to register with American Crew.</p><p>To cancel the registration process, please <a href=\"javascript:closeDom();\">click here</a>.</p>"
			document.getElementById('registerFieldset').style.display="block";
		}
	}else{
		animateOut('0') //animate div out
		document.getElementById('registerFieldset').style.display="block";
	}
	if (item=="register"){
		document.getElementById('Loginfrm').style.display="none";
		document.getElementById('Registerfrm').style.display="block";
		document.getElementById('Forgotfrm').style.display = "none";
		document.getElementById('privacypolicy').style.display="none";
		document.getElementById('animalpolicy').style.display="none";
		
	}else if (item=="login"){
		document.getElementById('Loginfrm').style.display="block";
		document.getElementById('Registerfrm').style.display="none";
		document.getElementById('Forgotfrm').style.display = "none";
		document.getElementById('privacypolicy').style.display="none";
		document.getElementById('animalpolicy').style.display="none";
	}

}
function closeDom(){
	//alert("CLOSE" + closeDomFlash)
	if (closeDomFlash=="0"){
		document.getElementById('opquelayer').style.display="none";
	}
	
	if (document.getElementById('formwrapper').style.left=="0" || document.getElementById('formwrapper').style.left=="0px"){
		$('#formwrapper').animate({
			left:"-365px"
		}, 1000);
		$('#wrapper').animate({
			left:"0px"
		}, 1000);
		
		document.body.style.overflow = "";
	}
}
function showLogin(){
	toggle_forms("login");
}
function isValidUSZip(sZip) {
   return /^\d{5}(-\d{4})?$/.test(sZip);
}
function isValidCanadianZip(sZip) {
	reg_exp_pcode = new RegExp(/(^s*([a-z](\s)?\d(\s)?){3}$)s*/i);
    if(!reg_exp_pcode.test(sZip)){
		return(false);
    }
    return(true);
}
function is_valid_email(email){
	return /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email);
}
function IsNumeric(sText){
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;
   if (sText!=undefined){
	   for (i = 0; i < sText.length && IsNumber == true; i++){ 
			Char = sText.charAt(i); 
			if (ValidChars.indexOf(Char) == -1){
				IsNumber = false;
			}
	    }
	}
   return IsNumber;
}

function RegisterForm(){

	if (document.getElementById('referredFrom').value=="editinfo"){ 
			//this array is required field array
			var FieldArr=new Array("firstname","lastname","email","ima","salonName","salonType","salonAddress1","salonCity","state","salonZipCode","Country","chairnumber","homeOrBusiness","phoneNumber","clientele","loyaltiesMember","communications");
			var FieldTitleArr=new Array("Stylist First Name","Stylist Last Name","Stylist Email","I am a","Salon / Barbershop Name","Which best describes the salon/barbershop where you work?","Mailing Address","City","State / Province","Zip","Country","Salon/Barbershop Size","Is the mailing address you entered your home or salon? This information is used to ensure proper shipping and timely delivery.","Phone Number","Weekly Average Male Clientele","Are you currently a Crew Salon Loyalties Member?","Would you like to receive future communication from American Crew?");
			//check required fields
			for (var i=0;i<FieldArr.length;i++){
				if (document.getElementById(FieldArr[i]).value==""){
					alert("Some required form information is missing. Please check the field titled '"+FieldTitleArr[i]+"'.");
					return
				}
				
				if (FieldArr[i]=="ima"){
					if (document.getElementById(FieldArr[i]).value=="Other"){
						if (document.getElementById('imaother').value==""){
							alert("You have selected the option \"other\" for the question \"I am a\" but have not specified an answer in the \"other\" text field. Please complete this field and resubmit the form.")
							return
						}
					}
				}
				
				if (FieldArr[i]=="salonZipCode"){
					if (document.getElementById("Country").value=="Canada"){
						//CHECK for Canadian Postal Code match
						var canadianCodes = "AB,BC,MB,NB,NF,NT,NS,ON,PI,PQ,SA,YT";
						canadianCodes = canadianCodes.split(",")
						for (var c=0;c<canadianCodes.length;c++){
							if (canadianCodes[c]==document.getElementById("state").value){ //is canadian
								if (isValidCanadianZip(document.getElementById(FieldArr[i]).value)==false){
									alert("please enter a valid Canadian Postal code with no spaces.");
									return
								}
							}
						}
					}
					
					if (document.getElementById("Country").value=="United States"){
						//CHECK for US Postal Code match
						var UsCodes = "WY,WI,WV,DC,WA,VA,VT,UT,TX,TN,SD,SC,RI,PA,OR,OK,OH,ND,NC,NY,NM,NJ,NH,NV,NE,MT,MO,MS,MN,MI,MA,MD,ME,LA,KY,KS,IA,IN,IL,ID,HI,GA,FL,DC,DE,CT,CO,CA,AR,AZ,AK,AL";
						UsCodes = UsCodes.split(",")
						for (var c=0;c<UsCodes.length;c++){
							if (UsCodes[c]==document.getElementById("state").value){ //is US
								if (isValidUSZip(document.getElementById(FieldArr[i]).value)==false){
									alert("Please enter a valid US postal code.");
									return
								}
							}
						}
					}
				}

				if (FieldArr[i]=="phoneNumber" && (document.getElementById("Country").value=="United States" || document.getElementById("Country").value=="Canada")  ){
					var tmpCntStr = document.getElementById('phoneNumber').value;
					var cnt=0;
					for (var x=0;x<tmpCntStr.length;x++){
						if (IsNumeric(tmpCntStr[x])==true){
							cnt++;
						}
					}
					
					if (cnt<10){
						alert("Please enter a valid 10 digit telephone number for United States and Canadian countries.");
						return;
					}
				}
				
			}
			if (is_valid_email(document.getElementById('email').value)!=false){
				//regformObj.submit()
				
				//for some reason ddl info is not posted in some cases. Copy information to hidden fields and then post information
				
				document.getElementById('imahidden').value = removeAmp(document.getElementById('ima').value);
				document.getElementById('salonTypehidden').value = removeAmp(document.getElementById('salonType').value);
				document.getElementById('statehidden').value = removeAmp(document.getElementById('state').value);
				document.getElementById('Countryhidden').value = removeAmp(document.getElementById('Country').value);
				document.getElementById('chairnumberhidden').value = removeAmp(document.getElementById('chairnumber').value);
				document.getElementById('homeOrBusinesshidden').value = removeAmp(document.getElementById('homeOrBusiness').value);
				document.getElementById('loyaltiesMemberhidden').value = removeAmp(document.getElementById('loyaltiesMember').value);
				if(document.getElementById('communicationschecked').checked){
					document.getElementById('communicationshidden').value = "Yes";
				}else{
					document.getElementById('communicationshidden').value = "No";
				}
				
				//submit form
				//regformObj.submit()
				
				//-------------redo the way this submission works. DDL info is not being captured in some instances. Create a form submission method using a non-post of information.
				
				
				var subURL = "";
				subURL += "firstname="+removeAmp(document.getElementById('firstname').value); 
				subURL += "&lastname="+removeAmp(document.getElementById('lastname').value); 
				subURL += "&email="+removeAmp(document.getElementById('email').value); 
				subURL += "&ima="+removeAmp(document.getElementById('imahidden').value); 
				subURL += "&imaother="+removeAmp(document.getElementById('imaother').value); 
				subURL += "&salonName="+removeAmp(document.getElementById('salonName').value); 
				subURL += "&salonType="+removeAmp(document.getElementById('salonTypehidden').value); 
				subURL += "&salonAddress1="+removeAmp(document.getElementById('salonAddress1').value); 
				subURL += "&salonAddress2="+removeAmp(document.getElementById('salonAddress2').value); 
				subURL += "&salonCity="+removeAmp(document.getElementById('salonCity').value); 
				subURL += "&state="+removeAmp(document.getElementById('statehidden').value); 
				subURL += "&salonZipCode="+removeAmp(document.getElementById('salonZipCode').value);
				subURL += "&Country="+removeAmp(document.getElementById('Countryhidden').value); 
				subURL += "&chairnumber="+removeAmp(document.getElementById('chairnumberhidden').value); 
				subURL += "&homeOrBusiness="+removeAmp(document.getElementById('homeOrBusinesshidden').value); 
				subURL += "&phoneNumber="+removeAmp(document.getElementById('phoneNumber').value); 
				subURL += "&AmericanCrewCheck="+document.getElementById('AmericanCrew').checked; 
				subURL += "&RedkenforMen="+document.getElementById('RedkenforMen').checked; 
				subURL += "&MatrixforMen="+document.getElementById('MatrixforMen').checked; 
				subURL += "&PaulMitchell="+document.getElementById('PaulMitchell').checked; 
				subURL += "&otherMensBrandCarried="+document.getElementById('otherMensBrandCarried').value; 
				subURL += "&clientele="+document.getElementById('clientele').value; 
				subURL += "&loyaltiesMember="+document.getElementById('loyaltiesMemberhidden').value; 
				subURL += "&communications="+document.getElementById('communicationshidden').value; 
				subURL += "&referredFrom=editinfo"; 
				subURL += "&uid="+readCookie("acuid"); 
				subURL = "../data/includes/RegisterInterface.aspx?" + subURL;
				xml = new JKL.ParseXML( subURL );   
				data = xml.parse();
				
				
				document.getElementById('registermessage').innerHTML="<h1>Your profile information has been updated.</h1><p>Please <a href=\"javascript:closeDom();\">click here</a>.</p>"
				document.getElementById('registerFieldset').style.display="none";
				
			}else{
				alert("You must enter a valid email address.")
			}
					
	}else{
			//this array is required field array
			var FieldArr=new Array("firstname","lastname","email","ima","salonName","salonType","salonAddress1","salonCity","state","salonZipCode","Country","chairnumber","homeOrBusiness","phoneNumber","clientele","loyaltiesMember","communications");
			var FieldTitleArr=new Array("Stylist First Name","Stylist Last Name","Stylist Email","I am a","Salon / Barbershop Name","Which best describes the salon/barbershop where you work?","Mailing Address","City","State / Province","Zip","Country","Salon/Barbershop Size","Is the mailing address you entered your home or salon? This information is used to ensure proper shipping and timely delivery.","Phone Number","Weekly Average Male Clientele","Are you currently a Crew Salon Loyalties Member?","Would you like to receive future communication from American Crew?");
			
			//check required fields
			for (var i=0;i<FieldArr.length;i++){
				if (document.getElementById(FieldArr[i]).value==""){
					
					alert("Some required form information is missing. Please check the field titled '"+FieldTitleArr[i]+"'.");
					return
				}
				
				if (FieldArr[i]=="ima"){
					if (document.getElementById(FieldArr[i]).value=="Other"){
						if (document.getElementById('imaother').value==""){
							alert("You have selected the option \"other\" for the question \"I am a\" but have not specified an answer in the \"other\" text field. Please complete this field and resubmit the form.")
							return
						}
					}
				}
				
				if (FieldArr[i]=="salonZipCode"){
					if (document.getElementById("Country").value=="Canada"){
						//CHECK for Canadian Postal Code match
						var canadianCodes = "AB,BC,MB,NB,NF,NT,NS,ON,PI,PQ,SA,YT";
						canadianCodes = canadianCodes.split(",")
						for (var c=0;c<canadianCodes.length;c++){
							if (canadianCodes[c]==document.getElementById("state").value){ //is canadian
								if (isValidCanadianZip(document.getElementById(FieldArr[i]).value)==false){
									alert("please enter a valid Canadian Postal code with no spaces.");
									return
								}
							}
						}
					}
					
					if (document.getElementById("Country").value=="United States"){
						//CHECK for US Postal Code match
						var UsCodes = "WY,WI,WV,DC,WA,VA,VT,UT,TX,TN,SD,SC,RI,PA,OR,OK,OH,ND,NC,NY,NM,NJ,NH,NV,NE,MT,MO,MS,MN,MI,MA,MD,ME,LA,KY,KS,IA,IN,IL,ID,HI,GA,FL,DC,DE,CT,CO,CA,AR,AZ,AK,AL";
						UsCodes = UsCodes.split(",")
						for (var c=0;c<UsCodes.length;c++){
							if (UsCodes[c]==document.getElementById("state").value){ //is US
								if (isValidUSZip(document.getElementById(FieldArr[i]).value)==false){
									alert("Please enter a valid US postal code.");
									return
								}
							}
						}
					}
				}

				if (FieldArr[i]=="phoneNumber" && (document.getElementById("Country").value=="United States" || document.getElementById("Country").value=="Canada")  ){
					var tmpCntStr = document.getElementById('phoneNumber').value;
					var cnt=0;
					for (var x=0;x<tmpCntStr.length;x++){
						if (IsNumeric(tmpCntStr[x])==true){
							cnt++;
						}
					}
					
					if (cnt<10){
						alert("Please enter a valid 10 digit telephone number for United States and Canadian countries.");
						return;
					}
				}
				
					
			}
			
			//All Product checkboxes are required as well
			if (document.getElementById('Other').checked==false && document.getElementById('AmericanCrewCheck').checked==false && document.getElementById('RedkenforMen').checked==false && document.getElementById('MatrixforMen').checked==false && document.getElementById('PaulMitchell').checked==false){
				alert("You must make a selection for the question: Which, if any, of the following men's grooming brands do you currently carry in your salon.");
				return
			}
			
			
			//check the checkbox information
			if (document.getElementById('Other').checked==true && document.getElementById('otherMensBrandCarried').value==''){
				alert("You have selected 'other' brands that are carried in your salon but not specified product names. Please deselect this checkbox if you do not want to specify these products.") 
				return
			}
			
			if (is_valid_email(document.getElementById('email').value)!=false){
			
				//check for duplicates
				var url = slcnt + "data/includes/RegisterInterface.aspx?dup=true&email="+document.getElementById('email').value; 
				xml = new JKL.ParseXML( url );   
				data = xml.parse();
				if (data["complete"]!=undefined){
					if (data["complete"].toString()=="error"){
						alert("The email address you are registering with already exists in our system. Please login.");
						return
					}
				}
				
				//for some reason ddl info is not posted in some cases. Copy information to hidden fields and then post information
				
				document.getElementById('imahidden').value = removeAmp(document.getElementById('ima').value);
				document.getElementById('salonTypehidden').value = removeAmp(document.getElementById('salonType').value);
				document.getElementById('statehidden').value = removeAmp(document.getElementById('state').value);
				document.getElementById('Countryhidden').value = removeAmp(document.getElementById('Country').value);
				document.getElementById('chairnumberhidden').value = removeAmp(document.getElementById('chairnumber').value);
				document.getElementById('homeOrBusinesshidden').value = removeAmp(document.getElementById('homeOrBusiness').value);
				document.getElementById('loyaltiesMemberhidden').value = removeAmp(document.getElementById('loyaltiesMember').value);
				if(document.getElementById('communicationschecked').checked){
					document.getElementById('communicationshidden').value = "Yes";
				}else{
					document.getElementById('communicationshidden').value = "No";
				}
				
				//submit form
				//regformObj.submit()
				
				//-------------redo the way this submission works. DDL info is not being captured in some instances. Create a form submission method using a non-post of information.
				
				
				var subURL = "";
				subURL += "firstname="+removeAmp(document.getElementById('firstname').value); 
				subURL += "&lastname="+removeAmp(document.getElementById('lastname').value); 
				subURL += "&email="+removeAmp(document.getElementById('email').value); 
				subURL += "&ima="+removeAmp(document.getElementById('imahidden').value); 
				subURL += "&imaother="+removeAmp(document.getElementById('imaother').value); 
				subURL += "&salonName="+removeAmp(document.getElementById('salonName').value); 
				subURL += "&salonType="+removeAmp(document.getElementById('salonTypehidden').value); 
				subURL += "&salonAddress1="+removeAmp(document.getElementById('salonAddress1').value); 
				subURL += "&salonAddress2="+removeAmp(document.getElementById('salonAddress2').value); 
				subURL += "&salonCity="+removeAmp(document.getElementById('salonCity').value); 
				subURL += "&state="+removeAmp(document.getElementById('statehidden').value); 
				subURL += "&salonZipCode="+removeAmp(document.getElementById('salonZipCode').value);
				subURL += "&Country="+removeAmp(document.getElementById('Countryhidden').value); 
				subURL += "&chairnumber="+removeAmp(document.getElementById('chairnumberhidden').value); 
				subURL += "&homeOrBusiness="+removeAmp(document.getElementById('homeOrBusinesshidden').value); 
				subURL += "&phoneNumber="+removeAmp(document.getElementById('phoneNumber').value); 
				subURL += "&AmericanCrewCheck="+document.getElementById('AmericanCrewCheck').checked; 
				subURL += "&RedkenforMen="+document.getElementById('RedkenforMen').checked; 
				subURL += "&MatrixforMen="+document.getElementById('MatrixforMen').checked; 
				subURL += "&PaulMitchell="+document.getElementById('PaulMitchell').checked; 
				subURL += "&Other="+document.getElementById('Other').checked; 
				subURL += "&otherMensBrandCarried="+document.getElementById('otherMensBrandCarried').checked;
				subURL += "&clientele="+document.getElementById('clientele').value;				
				subURL += "&loyaltiesMember="+document.getElementById('loyaltiesMemberhidden').value; 
				subURL += "&communications="+document.getElementById('communicationshidden').value; 
				subURL = "../data/includes/RegisterInterface.aspx?" + subURL;
				xml = new JKL.ParseXML( subURL );   
				data = xml.parse();
				
				
		
				if (isFlashRegistration==1){
					document.getElementById('registermessage').innerHTML="<h1>Thanks for becoming a member of the American Crew Professional Network.</h1><p>To complete your registration, you will need to check for a verification email (delivered to your registered email address). This email will contain your password and the link to return and login to the site.</p><p>If you haven't received your password, please be sure to check your \"spam\" or \"junk\" mail folder for the email. To ensure any future email deliveries from American Crew to your inbox, please add <a href=\"mailto:noreply@americancrew.com\">noreply@americancrew.com</a> to your Email Address Book or Safe List.</p><p>Please <a href=\"javascript:closeDom();\">click here</a> to login.</p>"
				}else{
					document.getElementById('registermessage').innerHTML="<h1>Thanks for becoming a member of the American Crew Professional Network.</h1><p>To complete your registration, you will need to check for a verification email (delivered to your registered email address). This email will contain your password and the link to return and login to the site.</p><p>If you haven't received your password, please be sure to check your \"spam\" or \"junk\" mail folder for the email. To ensure any future email deliveries from American Crew to your inbox, please add <a href=\"mailto:noreply@americancrew.com\">noreply@americancrew.com</a> to your Email Address Book or Safe List.</p><p>Please <a href=\"javascript:toggle_forms('login');\">click here</a> to login.</p>"
				}
				
				var url = "../data/includes/RegisterInterface.aspx?q=last_id"; 
				xml = new JKL.ParseXML( url );   
				data = xml.parse();
				
				//location.href="#anch";
				
				//this would auto login a person
				//createCookie("acuid",data["id"],"999")
				
				document.getElementById('registerFieldset').style.display="none";
			}else{
				alert("You must enter a valid email address.")
			}
	}
	
}
function removeAmp(str){
	var ret;
	ret = str.split("&").join("[amp]");
	ret = ret.split("#").join("[pnd]");
	ret = ret.split("?").join("[ques]");
	return ret
}
function LoginForm(promo){
	if (document.getElementById('eml').value=='' || document.getElementById('pw').value==''){
		alert("Please fill in the email address and password to login");
	}else{
		var url = slcnt + "data/includes/RegisterInterface.aspx?ln=true&pw="+document.getElementById('pw').value+"&eml="+document.getElementById('eml').value; 
		//alert(url)
		xml = new JKL.ParseXML( url );   
		dataID = xml.parse();
		if (dataID["id"].toString()=="error"){
			document.getElementById('loginmessage').innerHTML = "<h1>The email address and password combination supplied is not valid.</h1><p>Note:  Your Salon Loyalties username and password will not work with this site. Please \"Create an Account or Register\" to gain access for further stylist inspiration and education.</p><p>Please try again or <a href=\"javascript:toggle_forms('register');\">register</a> with American Crew.</p>"
		}else{
			if (promo!=undefined){
				if(document.getElementById('promoTitle').value.toLowerCase().indexOf("hair recovery quiz") > -1){
					createCookie("acuid",dataID["id"],"999");
					location.href= "/quiz/step1.aspx";
				}else{
				
					// -- idOfPromotionalItem -- this is a variable used fro Paid Promotions
					// -- promoInfo -- this is a variable used for Non paid Promotions
					var tmp;
					if (document.getElementById('forwardURL')==undefined){ //non Paid
						tmp = document.getElementById('promoInfo').value.toString().split("&").join("[amp]");
						tmp = tmp.split("?").join("[ques]");
						
						var url = slcnt + "data/includes/RegisterInterface.aspx?pp=true&pw="+document.getElementById('pw').value+"&eml="+document.getElementById('eml').value+"&promoInfo="+tmp+"&surveyID="+PromoCodeID; 
					
						xml = new JKL.ParseXML( url );   
						data = xml.parse();
						if (data["complete"].toString()=="true"){
							document.getElementById('loginmessage').innerHTML="<h1>Thank you!</h1><p>Your code was successfully entered. If your promotional offer included a product, it's on its way. You can find estimated shipping times in our What's Hot section. <a href='http://www.americancrew.com/#/home'>Click here</a> to head back to our homepage.</p>"
							createCookie("acuid",dataID["id"],"999")
						}
					}else{
						//at this point we need to redirect.
						
						var url = slcnt + "data/includes/RegisterInterface.aspx?pp=true&pw="+document.getElementById('pw').value+"&eml="+document.getElementById('eml').value+"&promoInfo="+tmp+"&surveyID="+PromoCodeID; ; 
						
						xml = new JKL.ParseXML( url );   
						data = xml.parse();
						if (data["complete"].toString()=="true"){
							document.getElementById('loginmessage').innerHTML="<h1>Thank you.</h1><p>You are now being directed to redeem this product.</p>"
							
							createCookie("acuid",dataID["id"],"999")
							var theURL = document.getElementById('forwardURL').value;
							location.href=theURL;
						}

					}
				}
				
			}else{
				document.getElementById('loginmessage').innerHTML="<h1>You are now logged in </h1><p><a href='javascript:closeDomAndReloadPage();'>Please click here</a></p>"
				createCookie("acuid",dataID["id"],"999")
			}
			
			document.getElementById('eml').value="";
			document.getElementById('pw').value="";
			document.getElementById('loginFieldset').style.display="none";
			
		}
	}
}
//FLASH METHODS
function FlashLogin(usr,pw){
	var url = slcnt + "data/includes/RegisterInterface.aspx?ln=true&pw="+pw+"&eml="+usr; 
	xml = new JKL.ParseXML( url );   
	dataID = xml.parse();
	if (dataID["id"].toString()=="error"){
		return "The email address and password combination supplied is not valid.<br />Note:  Your Salon Loyalties username and password will not work with this site. Please \"Create an Account\" to gain access for further stylist inspiration and education."
	}else{
		createCookie("acuid",dataID["id"],"999")
		checkUserID(dataID["id"], "flash");
		return ""
	}
}

function checkFlashLoggedIn(){
	if (readCookie("acuid")==null || readCookie("acuid")==undefined){
		return false
	}else{
		checkUserID(readCookie("acuid"), "flash");
		return true
	}
}
//END FLASH METHODS

function closeDomAndReloadPage(){
	location.reload(true);
}
function clearOutFields(){
	document.getElementById('firstname').value='';
	document.getElementById('lastname').value='';
	document.getElementById('email').value=''
}
function FlashObtainRegistration(){
	var url = "data/includes/RegisterInterface.aspx?editprofile=true&uid="+readCookie("acuid"); 
	xml = new JKL.ParseXML( url );   
	var dataFull = xml.parse();
	
	if (dataFull["results"]["firstname"]!=undefined){
		document.getElementById('firstname').value = dataFull["results"]["firstname"];
		document.getElementById('lastname').value = dataFull["results"]["lastname"];
		document.getElementById('email').value = dataFull["results"]["email"];
			setInputValue(document.getElementById("ima"), dataFull["results"]["contact_type"]);//ddl
		document.getElementById('imaother').value = replaceundefined(dataFull["results"]["contact_type_other"]);
		document.getElementById("salonName").value = dataFull["results"]["salon_shop_name"];
			setInputValue(document.getElementById("salonType"), dataFull["results"]["salon_type"]);//ddl
		document.getElementById('salonAddress1').value = dataFull["results"]["Salon_address_1"];
		document.getElementById('salonAddress2').value = replaceundefined(dataFull["results"]["Salon_address_2"]);
		document.getElementById('salonCity').value = dataFull["results"]["Salon_city"];
			setInputValue(document.getElementById("state"), dataFull["results"]["Salon_state_province"]);//ddl
		document.getElementById('salonZipCode').value = dataFull["results"]["salon_zip_postal_code"];
			setInputValue(document.getElementById("Country"), dataFull["results"]["salon_country"]);//ddl
			setInputValue(document.getElementById("chairnumber"), dataFull["results"]["salon_chair_number"]);//ddl
		document.getElementById('otherMensBrandCarried').value = replaceundefined(dataFull["results"]["other_mens_brands_carried"]);	
			setInputValue(document.getElementById("loyaltiesMember"), dataFull["results"]["salon_loyalties_member"]);//ddl
			setInputValue(document.getElementById("communications"), dataFull["results"]["recieve_further_communication"]); //ddl

		setCheckbox(document.getElementById("RedkenforMen"), dataFull["results"]["redken_for_men_carried"]); //checkbox
		setCheckbox(document.getElementById("MatrixforMen"), dataFull["results"]["matrix_for_men_carried"]); //checkbox
		setCheckbox(document.getElementById("PaulMitchell"), dataFull["results"]["Paul_mitchell_carried"]); //checkbox
		setCheckbox(document.getElementById("AmericanCrewCheck"), dataFull["results"]["american_crew_carried"]); //checkbox

	}
}
function replaceundefined(str){
		var ret
		if (str==undefined){
			return ""
		}else{ 
			return str
		}
}
function setCheckbox(obj,value){
	if (value=="on"){
		obj.checked = true;
	}
}
function setInputValue(obj,passedVal){
	for(var i=0;i<obj.length;i++){
		if (obj[i].value==passedVal){
			obj[i].selected = true;
		}		
	}
}
function editProfile(isFlash){

	if (isFlash=="1"){
		//the issue here is that the page has not refreshed yet. The data may not be on the form because flash doesnt refresh until an XHTML page is visited OR the flash is reloaded or revisited.
		FlashObtainRegistration()
		toggle_forms("register","1");
		isFlashCancel=1;
		isFlashCancel=1;
	}else{
		toggle_forms("register");
	}
	
	document.getElementById('referredFrom').value="editinfo";
	document.getElementById('uid').value=readCookie("acuid");
	document.getElementById('submitRegister').value="update";
	document.getElementById('registermessage').innerHTML="<h1>Edit Your Profile</h1><p>Edit your account profile and click the update button. To exit without saving changes <a href=\"javascript:cancelForm();\">click here</a>.</p>";
	
	
	
}
function forgotKeyPress(event){
 if (event && event.which == 13){
   checkForgotForm();
  }
}
function LoginSubmitTest(event) {
  if (event && event.which == 13)
   LoginForm('promo');
  else
    return true;}

function LoginSubmitNonPromo(event) {
  if (event && event.which == 13)
   LoginForm();
  else
    return true;}
	
function PromoCodeEnter(event) {
	//alert(event.which)
  if (event && event.which == 13){
	answerSurvey('paidItem');
}
 // }else{
	//return false;
  
//	}
}
function cancelForm(){
	closeDom()
	//always show bg and the main dom
	//document.getElementById('lightbox-bg').style.display="none";
	//document.getElementById('lightbox-wrapper').style.display="none";
	
	
}
//PAID PROMOTION ITEM
function redeemPaiditem(){
	animateOut('0');
	document.getElementById('Surveyfrm').style.display = "none";
	document.getElementById('Surveyfrm').style.display = "block";
	document.getElementById('Loginfrm').style.display="none";
	document.getElementById('Forgotfrm').style.display = "none";
}
//NONPAID PROMOTION FORM INFORMATION
function redeemNonPaiditem(title,id){


	//animateOut('0');
	
	if (document.getElementById('hasSurvey').value=="0"){
			
			if (readCookie("acuid")==null || readCookie("acuid")==undefined){
				
				animateOut('0');
				document.getElementById('loginmessage').innerHTML="<h1>Please login below to redeem this promotional item.</h1><p>If you don't already have an account <a href=\"javascript:toggle_forms('register');\">please register</a> with American Crew.</p><p>To cancel please <a href=\"javascript:cancelForm();\">click here</a>.</p>";
				document.getElementById('Surveyfrm').style.display="none";
				document.getElementById('Loginfrm').style.display="block";
			}else{
				if(title.toLowerCase().indexOf("hair_recovery_quiz") > -1){
					location.href= "/quiz/step1.aspx";
				}else{
					
					animateOut('0');
					var tmp = document.getElementById('promoInfo').value.toString().split("&").join("[amp]")
					tmp = document.getElementById('promoInfo').value.toString().split("?").join("[ques]")
					var url = slcnt + "data/includes/RegisterInterface.aspx?pp=true&userID="+readCookie("acuid")+"&pw=&eml=&promoInfo="+tmp; 
					xml = new JKL.ParseXML( url );   
					data = xml.parse();
					if (data["complete"].toString()=="true"){
						document.getElementById('Surveyfrm').style.display="none";
						document.getElementById('loginFieldset').style.display="none";
						document.getElementById('Loginfrm').style.display="block";
						
						//document.getElementById('loginmessage').innerHTML="<h1>Thank you!</h1><p>Your code was successfully entered. If your promotional offer included a product, it's on its way. You can find estimated shipping times in our What's Hot section. <a href='http://www.americancrew.com/#/home'>Click here</a> to head back to our homepage.</p>"
						document.getElementById('loginmessage').innerHTML="<h1>Thank you!</h1><p>If your promotional offer included a product, it's on its way. You can find estimated shipping times in our What's Hot section. <a href='http://www.americancrew.com/#/home'>Click here</a> to head back to our homepage.</p>"
					}
				}
			}	
	
	}else{
		animateOut('0');
	}
}

var PromoCodeID;
function answerSurvey(isPaidItem){

	//alert(isPaidItem)
	//-------CHECK TO SEE IF IT IS A  PAID ITEM. TOTALLY DIFFERENT HANDLING OF PROCESS
	if (isPaidItem=='paidItem'){
		if (document.getElementById('PromoCode').value==""){
			alert("You must enter a promotional code to proceed.");
			return
		}
		var tmp2 = document.getElementById('PromoCode').value.split("&").join("[amp]");
		tmp2 = tmp2.split("?").join("[ques]");
		tmp2 = tmp2.split("#").join("[pnd]");
		
		var url = "../data/includes/surveyInterface.aspx?isPaid=true&idOfPromotionalItem="+document.getElementById('idOfPromotionalItem').value+'&promoCode='+tmp2;
	
		xml = new JKL.ParseXML( url );   
		data = xml.parse();
		
		if (data["error"]==undefined){
			if (data["results"]["complete"]=="true"){
				PromoCodeID = data["results"]["id"];
				
				//determine if user is logged in
				if (readCookie("acuid")==null || readCookie("acuid")==undefined){
					
					document.getElementById('loginmessage').innerHTML="<h1>Thank you for entering your code.</h1><p>Please login below to complete your entry for this promotional offer.</p><p>If you don't already have an account <a href=\"javascript:toggle_forms('register');\">please register</a> with American Crew.</p><p>To cancel please <a href=\"javascript:cancelForm();\">click here</a>.</p>";
					document.getElementById('Surveyfrm').style.display="none";
					document.getElementById('Surveyfrm').style.display="none";
					document.getElementById('Loginfrm').style.display="block";
				}else{ //auto login
					
					var tmp = document.getElementById('PromoCode').value.toString().split("&").join("[amp]")
					tmp = document.getElementById('PromoCode').value.toString().split("?").join("[ques]")
					var url = slcnt + "data/includes/RegisterInterface.aspx?pp=true&userID="+readCookie("acuid")+"&pw=&eml=&promoInfo="+tmp+"&surveyID="+PromoCodeID; 
					xml = new JKL.ParseXML( url );   
					data = xml.parse();
					if (data["complete"]=="true"){
						document.getElementById('Surveyfrm').style.display="none";
						document.getElementById('loginFieldset').style.display="none";
						document.getElementById('Loginfrm').style.display="block";
						document.getElementById('Surveyfrm').style.display="none";
						
						document.getElementById('loginmessage').innerHTML="<h1>Thank you.</h1><p>You are now being directed to redeem this product.</p>"
						var theURL = document.getElementById('forwardURL').value;
						location.href=theURL;
					}
				}	
			}
		}else if (data["error"]=="promo"){
			alert("The promotional code entered is invalid. You must have a valid promotional code to redeem the promotion.");
			return
		}
		return //just exit everything since paid item functions are compelte
	}
	
	
	//-------OTHERWISE HANDLE ALL NON PAID PROMOTIONS
		//check required Fields and field information
		var js_requiredFieldStr = document.getElementById('js_requiredFieldStr').value;
		// FORMAT:  question | questionDivID | ActualquestionID | questionTypeID | IsRequired Boolean value , NEXT ITEM
		
		var finalQString='';
		if (js_requiredFieldStr!=""){
			var questInfo = js_requiredFieldStr.split(",");
			
			for (var i=0;i<questInfo.length;i++){
				var individualQuestInfo = questInfo[i].split("|");
				//alert(individualQuestInfo[1])
				if (document.getElementById(individualQuestInfo[1]).value == "" && individualQuestInfo[4]=="1"){
					alert("The question \""+individualQuestInfo[0]+"\" is required. Please answer this question.")
					return
				}else{ //create string to pass to update database
					if (document.getElementById('PromoCode').value==""){
						alert("You must enter a promotional code to proceed.");
						return
					}
					var tmp = individualQuestInfo[0].split("&").join("[amp]");
					tmp = tmp.split("?").join("[ques]");
					tmp = tmp.split("#").join("[pnd]");
					finalQString+= tmp + '|' + document.getElementById(individualQuestInfo[1]).value +  '|' + individualQuestInfo[2] + "^";
				}
			}
		}else{ //just promo code required. no survey questions are present
			if (document.getElementById('PromoCode').value==""){
				alert("You must enter a promotional code to proceed.");
				return
			}
		}
		
		var tmp = document.getElementById('promoTitle').value.split("&").join("[amp]");
		tmp = tmp.split("?").join("[ques]");
		tmp = tmp.split("#").join("[pnd]");
		
		var tmp2 = document.getElementById('PromoCode').value.split("&").join("[amp]");
		tmp2 = tmp2.split("?").join("[ques]");
		tmp2 = tmp2.split("#").join("[pnd]");
		
		
		var url = "../data/includes/surveyInterface.aspx?answers="+finalQString+'&idOfPromotionalItem='+document.getElementById('idOfPromotionalItem').value+'&promoTitle='+tmp+'&promoCode='+tmp2;
		//alert(url)
		xml = new JKL.ParseXML( url );   
		data = xml.parse();
		
		if (data["error"]==undefined){
		
			if (data["results"]["complete"]=="true"){
				PromoCodeID = data["results"]["id"];
				//determine if user is logged in
				if (readCookie("acuid")==null || readCookie("acuid")==undefined){
					document.getElementById('loginmessage').innerHTML="<h1>Thank you for entering your code.</h1><p>Please login below to complete your entry for this promotional offer.</p><p>If you don't already have an account <a href=\"javascript:toggle_forms('register');\">please register</a> with American Crew.</p><p>To cancel please <a href=\"javascript:cancelForm();\">click here</a>.</p>";
					document.getElementById('Surveyfrm').style.display="none";
					document.getElementById('Loginfrm').style.display="block";
				}else{ //auto login
					var tmp = document.getElementById('promoInfo').value.toString().split("&").join("[amp]")
					tmp = document.getElementById('promoInfo').value.toString().split("?").join("[ques]")
					var url = slcnt + "data/includes/RegisterInterface.aspx?pp=true&userID="+readCookie("acuid")+"&pw=&eml=&promoInfo="+tmp+"&surveyID="+PromoCodeID; 
					xml = new JKL.ParseXML( url );   
					data = xml.parse();
					if (data["complete"]=="true"){
						document.getElementById('Surveyfrm').style.display="none";
						document.getElementById('loginFieldset').style.display="none";
						document.getElementById('Loginfrm').style.display="block";
						//document.getElementById('loginmessage').innerHTML="<h1>Thank you for your participation.</h1><p>We have captured your entry for this promotional offer. If this was a product offering, please plan for up to 8-10 weeks for delivery of the product.</p><p>Please <a href='javascript:closeDomAndReloadPage();'>click here</a> to return to the offer.</p>"
						document.getElementById('loginmessage').innerHTML="<h1>Thank you!</h1><p>Your code was successfully entered. If your promotional offer included a product, it's on its way. You can find estimated shipping times in our What's Hot section. <a href='http://www.americancrew.com/#/home'>Click here</a> to head back to our homepage.</p>"
					}
				}	
			}
		}else if (data["error"]=="promo"){
			alert("The promotional code entered is invalid. You must have a valid promotional code to redeem the promotion.");
			return
		}
	//-end non paid item
}
//END SURVEY

//UNUSED
function initJs(){
	//checkNavLoggedIn();
	
	//by default everything is setup for the flash page. So change the messages for the forms to have the appropriate link for XHTML sites.
	//document.getElementById('loginmessage').innerHTML = "<h1>Please Login</h1><p>You are not logged in and this portion of the website requires you to be logged in. Please enter the proper account cridentials. Otherwise <a href=\"javascript:toggle_forms('register');\">please register</a> with American Crew. If you forgot your password, please <a href=\"javascript:forgotPassword();\">click here</a>.</p>"
	
	document.getElementById('loginmessage').innerHTML = "<h1>Please Login</h1><p>You need to log in to see the full website.</p><p>Please enter your email address and password below.</p><p>If you forgot your password, please <a href='javascript:forgotPassword();'>click here</a>.</p><p>If this is your first visit, <a href=\"javascript:toggle_forms(\'register\');\">please register here</a>.</p>"
	
	
	document.getElementById('registermessage').innerHTML = "<h1>Please Register</h1><p>Please fill out the following information to register with American Crew. If you already have an account <a href=\"javascript:toggle_forms('login');\">please login</a> to American Crew. If you forgot your password, please <a href=\"javascript:forgotPassword();\">click here</a>.</p>"

	//***NK Addition to get existing users to answer the new question***//
	var userID = readCookie("acuid");
	if (userID !=null && userID !=undefined){
		checkUserID(userID, "html");
	}
	
}
function checkNavLoggedIn(){
	if (readCookie("acuid")==null || readCookie("acuid")==undefined){
		document.getElementById('login_edit_navItem').innerHTML = "<a href=\"http://americancrew.com/register/login\"><em>Login</em></a>";
	}else{
		document.getElementById('login_edit_navItem').innerHTML = "<a href=\"http://americancrew.com/register/edit\"><em>Edit Profile</em></a>";
	}
}
//END UNUSED

//Additional Form Question Functions//

function checkUserID(id, type){
	var url = slcnt + "data/includes/CheckUserStatus.aspx?id="+id; 
	//alert(url)
	var xml = new JKL.ParseXML( url );   
	var dataID = xml.parse();
	//alert(dataID["result"]);
	if (dataID["result"].toString()=="false"){
		displayQuestionDom(type);
	}
}

function displayQuestionDom(type){
	if(type == "flash"){
		$('#swfContent').fadeOut('slow');
		$('#wrapper').append('<div id="newFormWrapper"></div>');
	}else{
		$('#master').append('<div id="newFormWrapper"></div>');
	}
	$('#newFormWrapper').append('<div id="newFormBG" class="darkOverlay></div>');
	var newFormContent = '<div class="newForm"><h1>Hello!</h1><p> We are updating out records, please complete the question below and we will get you on your way.</p>'
	newFormContent += '<p>&nbsp;</p><p> What is your weekly average Male Clientele?</p>'
	newFormContent += '<select id="existing_clientele" name="existing_clientele">'
	newFormContent += '<option value="1-5 Men">1-5 Men</option>'
	newFormContent += '<option value="5-10 Men">5-10 Men</option>'
	newFormContent += '<option value="10-20 Men">10-20 Men</option>'
	newFormContent += '<option value="20+ Men">20+ Men</option>'
	newFormContent += '</select>'
	newFormContent += '<p></p>' 
	newFormContent += '<input id="submitLogin" name="submitLogin" type="button" onclick="javscript:submitClientele(\'' + type + '\');" class="submit" value="Submit" />'
	newFormContent += '</div>'
	
	$('#newFormWrapper').append(newFormContent);
	$('#newFormWrapper').fadeIn('slow');
	
}
function submitClientele(type){
	var userID = readCookie("acuid");
	var newValue = document.getElementById('existing_clientele').value;
	if (newValue != null && newValue.length > 0){
		var url = slcnt + "data/includes/UpdateUser.aspx?id="+userID+"&val="+newValue; 
		var xml = new JKL.ParseXML( url ); 
		var dataID = xml.parse();
		//alert(dataID["result"].toString());
		$('.newForm').html('<h1>Thank You!</h1>');
		setTimeout(function() { $('#newFormWrapper').fadeOut('slow') }, 1000);
		if(type == "flash"){
			$('#swfContent').fadeIn('slow')
		}
	}
}
//END ADDITIONAL FORM QUESTION//

//CALENDAR
function CalendarSortChange(){
	
	var month = document.getElementById('Month').value;
	var category = document.getElementById('Category').value;
	var location = document.getElementById('Location').value;
	
	if ((month=="" || month=="none") && (category=="" || category=="none") && (location=="" || location=="none")){
		if (slCnt=="../"){
			document.location= "../calendar"
		}else{
			document.location= "../../calendar"
		}
	}else{
		if (slCnt=="../"){
			
			document.location= "../calendar/sort/"+month.split("none").join("")+"|"+category.split("none").join("")+"|"+location.split("none").join("");
		}else{
			document.location= "../../calendar/sort/"+month.split("none").join("")+"|"+category.split("none").join("")+"|"+location.split("none").join("");
		}
	
	}
	
}


function makePOSTRequest(url, parameters) {
  http_request = false;
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
	 http_request = new XMLHttpRequest();
	 if (http_request.overrideMimeType) {
		// set type accordingly to anticipated content type
		//http_request.overrideMimeType('text/xml');
		http_request.overrideMimeType('text/html');
	 }
  } else if (window.ActiveXObject) { // IE
	 try {
		http_request = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
		try {
		   http_request = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {}
	 }
  }
  if (!http_request) {
	// alert('Cannot create XMLHTTP instance');
	 return false;
  }
  
  //http_request.onreadystatechange = alertContents;
  http_request.open('POST', url, true);
  http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http_request.setRequestHeader("Content-length", parameters.length);
  http_request.setRequestHeader("Connection", "close");
  http_request.send(parameters);
}
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	//var domain = "fl-2.com";
	var domain = "americancrew.com";
	//var domain = "fl-2.com";
	//var domain = "agentsolid.com";
	document.cookie = name+"="+value+expires+"; domain=" + domain +"; path=/";
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
/*
function thisMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
}
*/
/*
function setVideo(value) {
	//alert("thisMovie: " + thisMovie);
	thisMovie("videoPlayer").setVideo(value);
}
*/
function toggleLayer( whichLayer ){
	//alert("toggleLayer");
	var elem, vis;
	if( document.getElementById ) // this is the way the standards work
		elem = document.getElementById( whichLayer );
	else if( document.all ) // this is the way old msie versions work
		elem = document.all[whichLayer];
	else if( document.layers ) // this is the way nn4 works
		elem = document.layers[whichLayer];
		vis = elem.style;
	// if the style.display value is blank we try to figure it out here
	if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
		vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
		vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}