



function emailfilterblur()
{
	// this function is referenced all over, but didn't exist;
	// added 2006-10-05 -- HS
	return true;
}

function getCookie(c_name){
	if (document.cookie.length>0){
		c_start=document.cookie.indexOf(c_name + "=")
		if (c_start!=-1){ 
			c_start=c_start + c_name.length+1 
			c_end=document.cookie.indexOf(";",c_start)
		if (c_end==-1) 
			c_end=document.cookie.length
			return unescape(document.cookie.substring(c_start,c_end))
		} 
	}
	return null
}

function isNumeric(objName){
	var numberfield = objName;
	if (fnChkNumeric(objName) == false) {
		numberfield.select();
		numberfield.focus();
		return false;
	}
	else{
	return true;
	}
}//end of isNumeric

	function fnChkNumeric(objName){
		var checkOK = "0123456789.-()+ ";
	    var checkStr = objName;
	    var allValid = true;
	    var decPoints = 0;
	    var allNum = "";
	    for (i = 0;  i < checkStr.value.length;  i++)
	    {
	        ch = checkStr.value.charAt(i);
			for (j = 0;  j < checkOK.length;  j++)
	        {
	            if (ch == checkOK.charAt(j))
	            {
	                break;
	            }
	        }
	        if (j == checkOK.length)
	        {
	            allValid = false;
		   break;
	        }
	    }
	    if(checkStr.value.length == 1)
	    {
	        if('.' == checkStr.value.charAt(0))
	        {
	            allValid = false;
	        }
	    }
	    if (!allValid)
	    {
	       	return (false);
	    }
	    else
	    {
	      /*  if(isNaN(objName.value))
			{
			   return false;
			}else{
			   return true;
			}*/
			return true;
	
	    }
	}//end of fnChkNumeric
	function validate_email(field,alerttxt){
		with (field){
			apos =value.indexOf("@")
			dotpos=value.lastIndexOf(".")
			if (apos<1||dotpos-apos<2){
				alert(alerttxt);
				return false; 
			}
			else{
				return true;
			}
		}
	}
	function validate_required(field,alerttxt){
		with (field){
			if (value==null||value==""){
				alert(alerttxt);
				return false;
			}
			else {
				return true;
			}
		}
	}
	function validate_select(field,alerttxt){
		with (field){
			if (value==null||value==""||value=="Choose one"||value=="Choose One:"){
				alert(alerttxt);
				return false;
			}
			else {
			   return true;
			}
		}
	}
	function validate_radio(radio){
        var radioVal = '';
        if(radio.length > 1) {
            for (var i = 0; i < radio.length; i++){
                if (radio[i].checked){
                    return true;
                }
            }
            return true;
        }else{
            if (radio.checked){
                return true;
            }else{
                return false;
            }
        }
    }
	function validate_form(thisform){
		with (thisform){
			// to check FirstName for non blank 
			if (validate_required(fname,"Please enter your first name.")==false){
				thisform.fname.focus();
				return false;
			}
			// to check LastName for non blank 
			if (validate_required(lname,"Please enter your last name.")==false){
				thisform.lname.focus();
				return false;
			}
			// to check email for non blank 
			if (validate_required(email,"Please enter your corporate email address.")==false){
				email.focus();
				return false;
			}
			
			if(!validate_email(thisform.email, "Please enter a valid email address.")){
				email.focus();
				return false;
			}
			
			// to check phonenumber for non blank 
			if (validate_required(phone,"Please enter your phone number.")==false){
				phone.focus();
				return false;
			}
			// to check phonenumber for numeric value
			if(!isNumeric(phone)){
                        alert("Please re-enter a valid phone number.")
				phone.focus();
				return false;
			}
			// to check company for non blank 
			if (validate_required(company,"Please enter your company's name")==false){
				company.focus();
				return false;
			}
			// to check jobtitle for non blank 
			if (validate_required(title,"Please enter your job title.")==false){
				title.focus();
				return false;
			}
			// to check jobrole for non blank 
			if (validate_select(select,"Please select your job role.")==false){
				//alert("Job Role "+select.value);
				select.focus();
				return false;
			}
			// to check purchasingtimeframe for non blank 
			if (validate_select(select2,"Please select a purchasing time frame.")==false){
				select2.focus();
				return false;
			}
			// to check address1 for non blank 
			if (validate_required(address,"Please enter your street address.")==false){
				address.focus();
				return false;
			}
			// to check city for non blank 
			if (validate_required(city,"Please enter your city.")==false){
				city.focus();
				return false;
			}
			// to check state for non blank 
			/* deactivated per esupport ticket #1647
			if (validate_select(state1,"Please enter your state (US, Canada, Australia only).")==false){
				state1.focus();
				return false;
			}
			*/
			// to check country for non blank 
			if (validate_select(country,"Please select your country.")==false){
				country.focus();
				return false;
			}

			// to check zip for numeric value 
			/* deactivated per support ticket #1682
			if (!isNumeric(zip)){
				alert("Zip/Postal Code is Numeric");
				zip.focus();
				return false;
			}
			*/
			
			// to check Receive Information Info selected ?
			if (validate_radio(EmailFlag,"please check Receive Information Update ?")==false){
				EmailFlag.focus();
				return false;
			}
		return true;	
		}
	}
function Set_Cookie(name,value,expires,path,domain,secure) { 
    var cookieString = name + "=" +escape(value) + 
       ( (expires) ? ";expires=" + expires.toGMTString() : "") + 
       ( (path) ? ";path=" + path : "") + 
       ( (domain) ? ";domain=" + domain : "") + 
       ( (secure) ? ";secure" : ""); 
    document.cookie = cookieString; 
} 


function frmCenterLogin_valid()
{
	//variable array to hold all input fields values
	if(!validate_form(document.frmCenterLogin)){
		return false;
	}
	var strFormInputs = new Array();
	var strCookieInputs;
	var strSplitter="$##$";
    var strValSplitter="~##~";
	strFormInputs[0] = document.frmCenterLogin.per_title.value;
	strCookieInputs = "per_title"+strValSplitter+strFormInputs[0]+strSplitter;
	strFormInputs[1] = document.frmCenterLogin.fname.value;
	strCookieInputs = strCookieInputs+"fname"+strValSplitter+strFormInputs[1]+strSplitter;
	strFormInputs[2] = document.frmCenterLogin.lname.value;
	strCookieInputs = strCookieInputs+"lname"+strValSplitter+strFormInputs[2]+strSplitter;
	strFormInputs[3] = document.frmCenterLogin.email.value;
	strCookieInputs = strCookieInputs+"email"+strValSplitter+strFormInputs[3]+strSplitter;
	strFormInputs[4] = document.frmCenterLogin.phone.value;
	strCookieInputs = strCookieInputs+"phone"+strValSplitter+strFormInputs[4]+strSplitter;
	strFormInputs[5] = document.frmCenterLogin.company.value;
	strCookieInputs = strCookieInputs+"company"+strValSplitter+strFormInputs[5]+strSplitter;
	strFormInputs[6] = document.frmCenterLogin.title.value;
	strCookieInputs = strCookieInputs+"title"+strValSplitter+strFormInputs[6]+strSplitter;
	strFormInputs[7] = document.frmCenterLogin.select.value;
	strCookieInputs = strCookieInputs+"select"+strValSplitter+strFormInputs[7]+strSplitter;
	strFormInputs[8] = document.frmCenterLogin.select2.value;
	strCookieInputs = strCookieInputs+"select2"+strValSplitter+strFormInputs[8]+strSplitter;
	strFormInputs[9] = document.frmCenterLogin.address.value;
	strCookieInputs = strCookieInputs+"address"+strValSplitter+strFormInputs[9]+strSplitter;
	strFormInputs[10] = document.frmCenterLogin.address2.value;
	strCookieInputs = strCookieInputs+"address2"+strValSplitter+strFormInputs[10]+strSplitter;
	strFormInputs[11] = document.frmCenterLogin.city.value;
	strCookieInputs = strCookieInputs+"city"+strValSplitter+strFormInputs[11]+strSplitter;
	strFormInputs[12] = document.frmCenterLogin.state1.value;
	strCookieInputs = strCookieInputs+"state1"+strValSplitter+strFormInputs[12]+strSplitter;
	strFormInputs[13] = document.frmCenterLogin.country.value;	
	strCookieInputs = strCookieInputs+"country"+strValSplitter+strFormInputs[13]+strSplitter;
	if(document.frmCenterLogin.zip.value==null){
	strFormInputs[14] = "";
	}
	else{
 	 strFormInputs[14] = document.frmCenterLogin.zip.value;
	}
	strCookieInputs = strCookieInputs+"zip"+strValSplitter+strFormInputs[14]+strSplitter;
	strFormInputs[15] = fnGetRCRadioValue(document.frmCenterLogin.EmailFlag);
    strCookieInputs = strCookieInputs+"EmailFlag"+strValSplitter+strFormInputs[15]+strSplitter;
	strFormInputs[16] = document.frmCenterLogin.saveme.checked;
	strCookieInputs = strCookieInputs+"saveme"+strValSplitter+strFormInputs[16]+strSplitter;
	strFormInputs[17] = document.frmCenterLogin.receive_call.checked;
	strCookieInputs = strCookieInputs+"receive_call"+strValSplitter+strFormInputs[17]+strSplitter;
	strFormInputs[18] = document.frmCenterLogin.txtA1.value;
	strCookieInputs = strCookieInputs+"txtA1"+strValSplitter+strFormInputs[18]+strSplitter;
    strFormInputs[19] = document.frmCenterLogin.txtA2.value;
	strCookieInputs = strCookieInputs+"txtA2"+strValSplitter+strFormInputs[19]+strSplitter;
	strFormInputs[20] = document.frmCenterLogin.txtA3.value;
	strCookieInputs = strCookieInputs+"txtA3"+strValSplitter+strFormInputs[20]+strSplitter;
	strFormInputs[20] = document.frmCenterLogin.txtA3.value;
	strFormInputs[21] = document.frmCenterLogin.txtA4.value;
	strCookieInputs = strCookieInputs+"txtA4"+strValSplitter+strFormInputs[21]+strSplitter;
	strFormInputs[22] = document.frmCenterLogin.txtA5.value;
	strCookieInputs = strCookieInputs+"txtA5"+strValSplitter+strFormInputs[22]+strSplitter;
	strFormInputs[23] = document.frmCenterLogin.txtA6.value;
	strCookieInputs = strCookieInputs+"txtA6"+strValSplitter+strFormInputs[23]+strSplitter;
	strFormInputs[24] = document.frmCenterLogin.txtA7.value;
	strCookieInputs = strCookieInputs+"txtA7"+strValSplitter+strFormInputs[24]+strSplitter;
	strFormInputs[25] = document.frmCenterLogin.txtA8.value;
	strCookieInputs = strCookieInputs+"txtA8"+strValSplitter+strFormInputs[25]+strSplitter;
	strFormInputs[26] = document.frmCenterLogin.txtA9.value;
	strCookieInputs = strCookieInputs+"txtA9"+strValSplitter+strFormInputs[26]+strSplitter;
	strFormInputs[27] = document.frmCenterLogin.txtA10.value;
	strCookieInputs = strCookieInputs+"txtA10"+strValSplitter+strFormInputs[27]+strSplitter;
	strFormInputs[28] = document.frmCenterLogin.txtA11.value;
	strCookieInputs = strCookieInputs+"txtA11"+strValSplitter+strFormInputs[28]+strSplitter;
	strFormInputs[29] = document.frmCenterLogin.txtA12.value;
	strCookieInputs = strCookieInputs+"txtA12"+strValSplitter+strFormInputs[29]+strSplitter;
	strFormInputs[30] = document.frmCenterLogin.txtA13.value;
	strCookieInputs = strCookieInputs+"txtA13"+strValSplitter+strFormInputs[30]+strSplitter;
	strFormInputs[31] = document.frmCenterLogin.txtA14.value;
	strCookieInputs = strCookieInputs+"txtA14"+strValSplitter+strFormInputs[31]+strSplitter;
	strFormInputs[32] = document.frmCenterLogin.txtA15.value;
	strCookieInputs = strCookieInputs+"txtA15"+strValSplitter+strFormInputs[32]+strSplitter;
	strFormInputs[33] = document.frmCenterLogin.txtA16.value;
	strCookieInputs = strCookieInputs+"txtA16"+strValSplitter+strFormInputs[33]+strSplitter;
	strFormInputs[34] = document.frmCenterLogin.txtA17.value;
	strCookieInputs = strCookieInputs+"txtA17"+strValSplitter+strFormInputs[34]+strSplitter;
	strFormInputs[35] = document.frmCenterLogin.txtA18.value;
	strCookieInputs = strCookieInputs+"txtA18"+strValSplitter+strFormInputs[35]+strSplitter;
	strFormInputs[36] = document.frmCenterLogin.txtA19.value;
	strCookieInputs = strCookieInputs+"txtA19"+strValSplitter+strFormInputs[36]+strSplitter;
	strFormInputs[37] = document.frmCenterLogin.txtA20.value;
	strCookieInputs = strCookieInputs+"txtA20"+strValSplitter+strFormInputs[37]+strSplitter;
	strFormInputs[38] = document.frmCenterLogin.txtA21.value;
	strCookieInputs = strCookieInputs+"txtA21"+strValSplitter+strFormInputs[38]+strSplitter;
	strFormInputs[39] = document.frmCenterLogin.txtA22.value;
	strCookieInputs = strCookieInputs+"txtA22"+strValSplitter+strFormInputs[39]+strSplitter;
	strFormInputs[40] = document.frmCenterLogin.txtA23.value;
	strCookieInputs = strCookieInputs+"txtA23"+strValSplitter+strFormInputs[40]+strSplitter;
	strFormInputs[41] = document.frmCenterLogin.txtA24.value;
	strCookieInputs = strCookieInputs+"txtA24"+strValSplitter+strFormInputs[41]+strSplitter;
	strFormInputs[42] = document.frmCenterLogin.txtA25.value;
	strCookieInputs = strCookieInputs+"txtA25"+strValSplitter+strFormInputs[42]+strSplitter;
	
	var today = new Date(); 
	var zero_date = new Date(0,0,0); 
	today.setTime(today.getTime() - zero_date.getTime()); 
	var cookie_expire_date = new Date(today.getTime() + (8 * 365 * 86400000));
	var cookie_expire_zero = new Date(today.getTime() + (8 * 0 * 86400000));
	if( document.frmCenterLogin.saveme.checked == true ){
		Set_Cookie("askindex",strCookieInputs,cookie_expire_date,"/");
	}
	else {
		Set_Cookie("askindex","",cookie_expire_zero,"/");
	}
	
	return true;
}

function fnGetRCRadioValue(radio)
{
        var radioVal = '';
        if(radio.length > 1) {
            for (var i = 0; i < radio.length; i++){
                if (radio[i].checked){
                    return radio[i].value;
                }
            }
            return radioVal;
        }else{
            if (radio.checked){
                return radio.value;
            }else{
                return radioVal;
            }
        }
} //End of fnGetRCRadioValue

function checkCookie()
{       
		var cookieExists = getCookie("askindex");
		if (cookieExists!=null){
			populateForm();
		}
		else {
			//document.frmCenterLogin.saveme.checked=true;
			//document.frmCenterLogin.EmailFlag.checked=true;
		}
}
     
// this function populates all the input controls in the form
function populateForm()
{
    	// variable to hold the cookie value
		var strCookieValue = getCookie("askindex");
if (strCookieValue!=null){
		// Array to hold the splited values from cookie
		var arrCookieValue = new Array();
		arrCookieValue = strCookieValue.split("$##$");
		var obj;
		var field;
        var val;
		// this loop will sets values of the input controls
		for(x=0; x < arrCookieValue.length; x++){
			var arrFormFields = new Array();
			arrFormFields = arrCookieValue[x].split("~##~");
			
			//populating the individual fields present in form
			if(arrFormFields[0] =="per_title" ){
                document.frmCenterLogin.per_title.value=arrFormFields[1];
            }
			else if(arrFormFields[0] == "fname"){
			    document.frmCenterLogin.fname.value=arrFormFields[1];
            }
            else if(arrFormFields[0] == "lname"){
			    document.frmCenterLogin.lname.value=arrFormFields[1];
            }
			else if(arrFormFields[0] == "email"){
			    document.frmCenterLogin.email.value=arrFormFields[1];
            }
            else if(arrFormFields[0] == "phone"){
			    document.frmCenterLogin.phone.value=arrFormFields[1];
            }
			else if(arrFormFields[0] == "company"){
			    document.frmCenterLogin.company.value=arrFormFields[1];
            }
            else if(arrFormFields[0] == "title"){
			    document.frmCenterLogin.title.value=arrFormFields[1];
            }
			else if(arrFormFields[0] == "select"){
			    document.frmCenterLogin.select.value=arrFormFields[1];
            }
            else if(arrFormFields[0] == "select2"){
			    document.frmCenterLogin.select2.value=arrFormFields[1];
            }
			else if(arrFormFields[0] == "address"){
			    document.frmCenterLogin.address.value=arrFormFields[1];
            }
            else if(arrFormFields[0] == "address2"){
			    document.frmCenterLogin.address2.value=arrFormFields[1];
            }
			else if(arrFormFields[0] == "city"){
			    document.frmCenterLogin.city.value=arrFormFields[1];
            }
            else if(arrFormFields[0] == "state1"){
			    document.frmCenterLogin.state1.value=arrFormFields[1];
            }
			else if(arrFormFields[0] == "country"){
			    document.frmCenterLogin.country.value=arrFormFields[1];
            }
            else if(arrFormFields[0] == "zip"){
			    document.frmCenterLogin.zip.value=arrFormFields[1];
            }
            else if(arrFormFields[0] == "saveme"){
			    document.frmCenterLogin.saveme.checked=arrFormFields[1];
            }
            else if(arrFormFields[0] == "receive_call" ){
			    if(arrFormFields[1]=="true"){
                document.frmCenterLogin.receive_call.checked="true"
				}
            }
            else if(arrFormFields[0] == "EmailFlag"){
               	document.frmCenterLogin.EmailFlag.value =  arrFormFields[1];
            	if(arrFormFields[1] == "Y"){
                    document.frmCenterLogin.EmailFlag[0].checked =  true;      
            	}else if(arrFormFields[1] == "N"){
					document.frmCenterLogin.EmailFlag[1].checked =  true;   
            	}
            }
			else if(arrFormFields[0] == "txtA1"){
			    document.frmCenterLogin.txtA1.value=arrFormFields[1];
            }
            else if(arrFormFields[0] == "txtA2"){
			    document.frmCenterLogin.txtA2.value=arrFormFields[1];
            }
			else if(arrFormFields[0] == "txtA3"){
			    document.frmCenterLogin.txtA3.value=arrFormFields[1];
            }
            else if(arrFormFields[0] == "txtA4"){
			    document.frmCenterLogin.txtA4.value=arrFormFields[1];
            }
			else if(arrFormFields[0] == "txtA5"){
			    document.frmCenterLogin.txtA5.value=arrFormFields[1];
            }
            else if(arrFormFields[0] == "txtA6"){
			    document.frmCenterLogin.txtA6.value=arrFormFields[1];
            }
			else if(arrFormFields[0] == "txtA7"){
			    document.frmCenterLogin.txtA7.value=arrFormFields[1];
            }
            else if(arrFormFields[0] == "txtA8"){
			    document.frmCenterLogin.txtA8.value=arrFormFields[1];
            }
			else if(arrFormFields[0] == "txtA9"){
			    document.frmCenterLogin.txtA9.value=arrFormFields[1];
            }
            else if(arrFormFields[0] == "txtA10"){
			    document.frmCenterLogin.txtA10.value=arrFormFields[1];
            }
			else if(arrFormFields[0] == "txtA11"){
			    document.frmCenterLogin.txtA11.value=arrFormFields[1];
            }
			else if(arrFormFields[0] == "txtA12"){
			    document.frmCenterLogin.txtA12.value=arrFormFields[1];
            }
            else if(arrFormFields[0] == "txtA13"){
			    document.frmCenterLogin.txtA13.value=arrFormFields[1];
            }
			else if(arrFormFields[0] == "txtA14"){
			    document.frmCenterLogin.txtA14.value=arrFormFields[1];
            }
            else if(arrFormFields[0] == "txtA15"){
			    document.frmCenterLogin.txtA15.value=arrFormFields[1];
            }
			else if(arrFormFields[0] == "txtA16"){
			    document.frmCenterLogin.txtA16.value=arrFormFields[1];
            }
            else if(arrFormFields[0] == "txtA17"){
			    document.frmCenterLogin.txtA17.value=arrFormFields[1];
            }
			else if(arrFormFields[0] == "txtA18"){
			    document.frmCenterLogin.txtA18.value=arrFormFields[1];
            }
			else if(arrFormFields[0] == "txtA19"){
			    document.frmCenterLogin.txtA19.value=arrFormFields[1];
            }
			else if(arrFormFields[0] == "txtA20"){
			    document.frmCenterLogin.txtA20.value=arrFormFields[1];
            }
            else if(arrFormFields[0] == "txtA21"){
			    document.frmCenterLogin.txtA21.value=arrFormFields[1];
            }
			else if(arrFormFields[0] == "txtA22"){
			    document.frmCenterLogin.txtA22.value=arrFormFields[1];
            }
            else if(arrFormFields[0] == "txtA23"){
			    document.frmCenterLogin.txtA23.value=arrFormFields[1];
            }
			else if(arrFormFields[0] == "txtA24"){
			    document.frmCenterLogin.txtA24.value=arrFormFields[1];
            }
            else if(arrFormFields[0] == "txtA25"){
			    document.frmCenterLogin.txtA25.value=arrFormFields[1];
	       }
         }
    }			
}  
 
