function GetSoftAdCookie() {

	var sCurrentCookie = GetCookie("ASP.NET_SessionId");
	
	return sCurrentCookie;

}

function GetCookie(name) { // use: getCookie("name");
	var bikky = document.cookie;
	var index = bikky.indexOf(name + "=");
	if (index == -1) return null;
	index = bikky.indexOf("=", index) + 1; // first character

	var endstr = bikky.indexOf(";", index);
	if (endstr == -1) endstr = bikky.length; // last character
	return unescape(bikky.substring(index, endstr));
	
}

function SetCookie(name, value) {
         var argv = SetCookie.arguments;
         var argc = SetCookie.arguments.length;
         var expires = (argc > 2) ? argv[2] : null;
         var path = (argc > 3) ? argv[3] : null;
         var domain = (argc > 4) ? argv[4] : null;
         var secure = (argc > 5) ? argv[5] : false;
         document.cookie = name + "=" + escape (value) +
         ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
         ((path == null) ? "" : ("; path=" + path)) +
         ((domain == null) ? "" : ("; domain=" + domain)) +
         ((secure == true) ? "; secure" : "");
}

function DeleteCookie(name) { 
	var exp = new Date(); 
	exp.setTime (exp.getTime() - 1); 
	// This cookie is history 
	var cval = GetCookie (name); 
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString(); 
} 

function preloadquizform() { 
	
	var ContactUsForm = document.forms.quizform;
	
	var HunterDouglasContactUsCookie = GetCookie("HunterDouglasContactUs");

	var sCurrentSoftADCookie = GetSoftAdCookie();	
	
	
	if (HunterDouglasContactUsCookie == sCurrentSoftADCookie) {
		
		ContactUsForm.firstname.value = (GetCookie("FirstName") == "") ? "" : GetCookie("FirstName");
		ContactUsForm.lastname.value = (GetCookie("LastName") == "") ? "" : GetCookie("LastName");

		
		ContactUsForm.address.value = (GetCookie("Address") == "" || GetCookie("Address") == null ) ? "" : GetCookie("Address");
		ContactUsForm.city.value = (GetCookie("City") == "" || GetCookie("City") == null) ? "" : GetCookie("City");
		if (GetCookie("State") != "" && GetCookie("State") != null) {
			for (var i = 0; i < ContactUsForm.state.length; i++) {
				if (ContactUsForm.state.options[i].value == GetCookie("State")) {
					ContactUsForm.state.options[i].selected = true;
					break;
				} 
			}		
		}
		
		ContactUsForm.zip.value = (GetCookie("Zip") == "" || GetCookie("Zip") == null) ? "" : GetCookie("Zip");
		ContactUsForm.email.value = (GetCookie("Email") == "" || GetCookie("Email") == null) ? "" : GetCookie("Email");
		ContactUsForm.phone.value = (GetCookie("Phone") == "" || GetCookie("Phone") == null) ? "" : GetCookie("Phone");
		ContactUsForm.mobilephone.value = (GetCookie("Mobile") == "" || GetCookie("Mobile") == null) ? "" : GetCookie("Mobile");
	}

}

function Open360quiz(vanity,sitekey,pagekey) {

	var URL;
	
	if (vanity != "") {
		URL = "/" + vanity + "/sb.cn?crt=pagekey=" + pagekey + "&pageid=sitebuilder.360quiz";
	
	} else {
		URL = "/channelnet.aspx?cn=sitebuilder&act=view&crt=sitekey=" + sitekey + "%26pagekey=" + pagekey + "&pageid=sitebuilder.360quiz";
	
	}

	var popup = window.open(URL,"360Quiz","width=800,height=650,scrollbars=no,location=no,menubar=no,resizable=yes,toolbar=no,status=no");

}

function handleOver() { 
 if (document.images) document.images["360quiz"].src=img_on.src;
}

function handleOut() {
 if (document.images) document.images["360quiz"].src=img_off.src;
}

function SubmitQuizForm()
{
  var oForm = document.forms.quizform;
   if (document.getElementById('firstname').value.length < 1)
   {
       alert("First Name is required.");
       return false;
   } else if (document.getElementById('lastname').value.length < 1) {
       alert("Last Name is required.");
       return false;
    } else if  (isEmail(document.getElementById('email').value) == false) {
	alert("Email Address is invalid.");
       return false;
    } else if  (document.getElementById('contact').checked == true & document.getElementById('contact_phone').checked == true & document.getElementById('contact_phone_type').value == 'phone' & document.getElementById('phone').value.length < 1) {
       alert("Phone number is required because you've selected phone as your prefered contact method.");
       return false;
    } else if  (document.getElementById('contact').checked == true & document.getElementById('contact_phone').checked == true & document.getElementById('contact_phone_type').value == 'mobilephone' & document.getElementById('mobilephone').value.length < 1) {
       alert("Mobile phone number is required because you've selected mobile phone as your prefered contact method.");
       return false;
   } else {
	var a1;
	var a1_1;
	oForm.hdnetsession.value = GetSoftAdCookie();
	if (document.getElementById('contact').checked == true) {		           		
		a1 = "Yes";
	} else {		           		
		a1 = "No";
	}

	for (var i = 0; i < oForm.contact_by.length; i++) {
		if (oForm.contact_by[i].checked) {
			if (oForm.contact_by[i].value == "email") {
				a1_1 = "Contact me by email";
			} else {

				if (oForm.contact_phone_type.options[oForm.contact_phone_type.selectedIndex].value == "phone") {

					a1_1 = "Call my home phone";

				} else {

					a1_1 = "Call my mobile phone";
				}
			}
		}            
	}		           		
	oForm.a1.value = a1;
	oForm.a1_1.value = a1_1;
	
	var expDays = 30; 
	var exp = new Date(); 	

	exp.setTime(exp.getTime() + (expDays*24*60*60*1000));		
	sSoftAdCookie = GetSoftAdCookie();
	SetCookie('HunterDouglasContactUs', sSoftAdCookie, exp);
	SetCookie('FirstName', oForm.firstname.value, exp); 
	SetCookie('LastName', oForm.lastname.value, exp); 
	SetCookie('Email', oForm.email.value, exp);
	SetCookie('Phone', oForm.phone.value, exp);
	SetCookie('Mobile', oForm.mobilephone.value, exp);
	SetCookie('Address', oForm.address.value, exp);
	SetCookie('City', oForm.city.value, exp);
	SetCookie('State', oForm.state.value, exp);
	SetCookie('Zip', oForm.zip.value, exp);		
	return true;
   }
}

function redircttoquiz() {
	
	document.forms.LifeTraitsQuiz.submit();

}