

//STORE FUNCTIONS

function validate_contacts() {
	fullname = document.getElementById("fullname").value;
	emailaddress = document.getElementById("emailaddress").value;
	phonenumber = document.getElementById("phonenumber").value;
	company = document.getElementById("company").value;
	contacttype = document.getElementById("contacttype").value;
	informationtype = document.getElementById("informationtype").value;
	region = document.getElementById("region").value;
	country = document.getElementById("country").value;
	source = document.getElementById("source").value;
	
	document.getElementById("fullname_Error").style.display = "none";
	document.getElementById("emailaddress_Error").style.display = "none";
	document.getElementById("contacttype_Error").style.display = "none";
	document.getElementById("informationtype_Error").style.display = "none";
	document.getElementById("region_Error").style.display = "none";
	document.getElementById("country_Error").style.display = "none";
	document.getElementById("source_Error").style.display = "none";
	document.getElementById("company_Error").style.display = "none";
	document.getElementById("phonenumber_Error").style.display = "none";


	try {
		var hascheck = false;
		var cbs = document.captchaForm.elements["download"];
		for (var i = 0; i < cbs.length; i++) {
			if (cbs[i].checked) 
			hascheck = true
		}
	}catch(err) {
		hascheck = true;
	}

	if (trim(fullname) == "")  {
		document.getElementById("fullname_Error").style.display = "inline";
		document.getElementById("fullname").select();
		document.getElementById("fullname").focus();
		document.getElementById("fullname").style.backgroundColor = 'eeeeee';
		return false;
	} 
	else if (trim(company)== "") {
		document.getElementById("company_Error").style.display = "inline";
		document.getElementById("company").select();
		document.getElementById("company").focus();
		document.getElementById("company").style.backgroundColor = 'eeeeee';
		return false;
	}
	else if (!echeck(emailaddress)) {
		document.getElementById("emailaddress_Error").style.display = "inline";
		document.getElementById("emailaddress").select();
		document.getElementById("emailaddress").focus();
		document.getElementById("emailaddress").style.backgroundColor = 'eeeeee';
		return false;
	}
	else if (trim(phonenumber) == "" && contacttype == "Phone") {
		document.getElementById("phonenumber_Error").style.display = "inline";
		document.getElementById("phonenumber").select();
		document.getElementById("phonenumber").focus();
		document.getElementById("phonenumber").style.backgroundColor = 'eeeeee';
		return false;
	}
	else if (trim(contacttype) == "") {
		document.getElementById("contacttype_Error").style.display = "inline";
		document.getElementById("contacttype").style.backgroundColor = 'eeeeee';
		return false;
	}
	else if (trim(informationtype) == "") {
		document.getElementById("informationtype_Error").style.display = "inline";
		document.getElementById("informationtype").style.backgroundColor = 'eeeeee';
		return false;
	}
	else if (trim(region) == "") {
		document.getElementById("region_Error").style.display = "inline";
		document.getElementById("region").style.backgroundColor = 'eeeeee';
		return false;
	}
		else if (trim(country) == "") {
		document.getElementById("country_Error").style.display = "inline";
		document.getElementById("country").style.backgroundColor = 'eeeeee';
		return false;
	}
	
	else if (trim(source) == "") {
		document.getElementById("source_Error").style.display = "inline";
		document.getElementById("source").style.backgroundColor = 'eeeeee';
		return false;
	}
	else if (!hascheck ) {
		document.getElementById("download_Error").style.display = "inline";
		return false;
	}
	
	return true;
}

function validate_checkout() {
	emailaddress 	 = trim(document.getElementById("emailaddress").value);
	password 		 = trim(document.getElementById("password").value);
	confirmpassword  = trim(document.getElementById("confirmpassword").value);
	firstname 		 = trim(document.getElementById("firstname").value);
	lastname 		 = trim(document.getElementById("lastname").value);
	billingaddress1  = trim(document.getElementById("billingaddress1").value);
	city 			 = trim(document.getElementById("city").value);
	countryid 			= trim(document.getElementById("countryid").value);
	zip 			 = trim(document.getElementById("zip").value);
	creditcardnumber = trim(document.getElementById("creditcardnumber").value);
	cvv2 			 = trim(document.getElementById("cvv2").value);
	
	document.getElementById("emailaddress_Error").style.display = "none";
	document.getElementById("password_Error").style.display = "none";
	document.getElementById("confirmpassword_Error").style.display = "none";
	document.getElementById("firstname_Error").style.display = "none";
	document.getElementById("lastname_Error").style.display = "none";
	document.getElementById("billingaddress1_Error").style.display = "none";
	document.getElementById("countryid_Error").style.display = "none";
	document.getElementById("city_Error").style.display = "none";
	document.getElementById("zip_Error").style.display = "none";
	document.getElementById("creditcardnumber_Error").style.display = "none";
	document.getElementById("cvv2_Error").style.display = "none";

	if (!echeck(emailaddress))  {		
		document.getElementById("emailaddress_Error").style.display = "inline";
		document.getElementById("emailaddress_Error").innerHTML = "Please enter a valid email address.";
		document.getElementById("emailaddress").select();
		document.getElementById("emailaddress").focus();
		
		return false;
	
	}
	else if (password == "" ) {
		document.getElementById("password_Error").style.display = "inline";
		document.getElementById("password_Error").innerHTML = "Password cannot be blank."; 
		document.getElementById("password").select();
		document.getElementById("password").focus();
		
		return false;
	}
	else if (confirmpassword != password ) {
		document.getElementById("confirmpassword_Error").style.display = "inline";
		document.getElementById("confirmpassword_Error").innerHTML = "Passwords do not match.";
		document.getElementById("confirmpassword").select();
		document.getElementById("confirmpassword").focus();
		
		return false;
	}	
	
	else if (firstname == "" ) {
		document.getElementById("firstname_Error").style.display = "inline";
		document.getElementById("firstname_Error").innerHTML = "Please enter a vaild firstname.";
		document.getElementById("firstname").select();
		document.getElementById("firstname").focus();
		
		return false;
	}
	else if (lastname == "" ) {
		document.getElementById("lastname_Error").style.display = "inline";
		document.getElementById("lastname_Error").innerHTML = "Please enter a vaild lastname.";
		document.getElementById("lastname").select();
		document.getElementById("lastname").focus();
		
		return false;
	}

	//String contains email address
	else if ( password.search(eval("/" + emailaddress + "|" + firstname + "|" + lastname  + "/i")) >= 0)  {
		document.getElementById("password_Error").style.display = "inline";
		document.getElementById("password_Error").innerHTML = "Password cannot contain significant portions of the user's email address or name.";
		document.getElementById("password").select();
		document.getElementById("password").focus();
		
		return false;
	}
	else if (password.length < 6) {
		document.getElementById("password_Error").style.display = "inline";
		document.getElementById("password_Error").innerHTML = "Password must be at least six characters in length.";
		document.getElementById("password").select();
		document.getElementById("password").focus();
		
		return false;
	}
	
	//Search for alphanumeric character
	else if (password.search("[A-Za-z!@#$%^&*]") == -1) {
		document.getElementById("password_Error").style.display = "inline";
		document.getElementById("password_Error").innerHTML = "Password must contain at least one alphanumeric character.";
		document.getElementById("password").select();
		document.getElementById("password").focus();
		
		return false;
	}
	
	//Search for non-alphanumeric  character
	else if (password.search("[0-9]") == -1) {
		document.getElementById("password_Error").style.display = "inline";
		document.getElementById("password_Error").innerHTML = "Password must contain at least one non-alphanumeric character.";
		document.getElementById("password").select();
		document.getElementById("password").focus();
		
		return false;
	}
	else if (billingaddress1 == "" ) {
		document.getElementById("billingaddress1_Error").style.display = "inline";
		document.getElementById("billingaddress1_Error").innerHTML = "Please enter a vaild billing address.";
		document.getElementById("billingaddress1").select();
		document.getElementById("billingaddress1").focus();
		
		return false;
	}
	else if (countryid == "-1" ) {
		document.getElementById("countryid_Error").style.display = "inline";
		document.getElementById("countryid_Error").innerHTML = "Please enter a vaild country.";
		return false;
	}
	
	else if (city == "" ) {
		document.getElementById("city_Error").style.display = "inline";
		document.getElementById("city_Error").innerHTML = "Please enter a vaild city.";
		document.getElementById("city").select();
		document.getElementById("city").focus();
		
		return false;
	}
	else if (zip == "" ) {
		document.getElementById("zip_Error").style.display = "inline";
		document.getElementById("zip_Error").innerHTML = "Please enter a vaild Zip/Postal Code.";
		document.getElementById("zip").select();
		document.getElementById("zip").focus();
		
		return false;
	}
	else if (creditcardnumber == "") {
		document.getElementById("creditcardnumber_Error").style.display = "inline";
		document.getElementById("creditcardnumber_Error").innerHTML = "Please enter a vaild Credit Card Number.";
		document.getElementById("creditcardnumber").select();
		document.getElementById("creditcardnumber").focus();
		
		return false;
	}
	
	else if (cvv2 == "") {
		document.getElementById("cvv2_Error").style.display = "inline";
		document.getElementById("cvv2_Error").innerHTML = "Please enter a vaild Credit Card Number.";
		document.getElementById("cvv2").select();
		document.getElementById("cvv2").focus();
		
		return false;
	}
	
	securecheckoutform.submit();
}

function validate_UpdateProfile() {
	currentpassword  = trim(document.getElementById("currentpassword").value);
	password 		 = trim(document.getElementById("password").value);
	username 		 = trim(document.getElementById("username").value);
	firstname 		 = trim(document.getElementById("firstname").value);
	lastname 		 = trim(document.getElementById("lastname").value); 
	billingaddress1  = trim(document.getElementById("billingaddress1").value);
	city 			 = trim(document.getElementById("city").value);
	
	alert
	document.getElementById("password_Error").style.display = "none";
	document.getElementById("currentpassword_Error").style.display = "none";
	
	// update password
	if (password != "" ) {
		if (password == currentpassword ) {
			document.getElementById("password_Error").style.display = "inline";
			document.getElementById("password_Error").innerHTML = "Password cannot be the same as the current password."; 
			document.getElementById("password").select();
			document.getElementById("password").focus();
			document.getElementById("password").style.backgroundColor = 'eeeeee';
			return false;
		
		}
		else if (password.length < 6) {
			document.getElementById("password_Error").style.display = "inline";
			document.getElementById("password_Error").innerHTML = "Password must be at least six characters in length.";
			document.getElementById("password").select();
			document.getElementById("password").focus();
			document.getElementById("password").style.backgroundColor = 'eeeeee';
			return false;	 
		}
		
		//Search for alphanumeric character
		else if (password.search("[A-Za-z!@#$%^&*]") == -1) {
			document.getElementById("password_Error").style.display = "inline";
			document.getElementById("password_Error").innerHTML = "Password must contain at least one alphanumeric character.";
			document.getElementById("password").select();
			document.getElementById("password").focus();
			document.getElementById("password").style.backgroundColor = 'eeeeee';
			return false;
		}
		
		//Search for non-alphanumeric  character
		else if (password.search("[0-9]") == -1) {
			document.getElementById("password_Error").style.display = "inline";
			document.getElementById("password_Error").innerHTML = "Password must contain at least one non-alphanumeric character.";
			document.getElementById("password").select();
			document.getElementById("password").focus();
			document.getElementById("password").style.backgroundColor = 'eeeeee';
			return false;
		}
	}
	if (firstname == "" ) {
		document.getElementById("firstname_Error").style.display = "inline";
		document.getElementById("firstname_Error").innerHTML = "Please enter a vaild firstname.";
		document.getElementById("firstname").select();
		document.getElementById("firstname").focus();
		document.getElementById("firstname").style.backgroundColor = 'eeeeee';
		return false;
	}
	else if (lastname == "" ) {
		document.getElementById("lastname_Error").style.display = "inline";
		document.getElementById("lastname_Error").innerHTML = "Please enter a vaild lastname.";
		document.getElementById("lastname").select();
		document.getElementById("lastname").focus();
		document.getElementById("lastname").style.backgroundColor = 'eeeeee';
		return false;
	}
	
	else if (billingaddress1 == "" ) {
		document.getElementById("billingaddress1_Error").style.display = "inline";
		document.getElementById("billingaddress1_Error").innerHTML = "Please enter a vaild billing address.";
		document.getElementById("billingaddress1").select();
		document.getElementById("billingaddress1").focus();
		document.getElementById("billingaddress1").style.backgroundColor = 'eeeeee';
		return false;
	}
	
	else if (city == "" ) {
		document.getElementById("city_Error").style.display = "inline";
		document.getElementById("city_Error").innerHTML = "Please enter a vaild city.";
		document.getElementById("city").select();
		document.getElementById("city").focus();
		document.getElementById("city").style.backgroundColor = 'eeeeee';
		return false;
	}
	else if (zip == "" ) {
		document.getElementById("zip_Error").style.display = "inline";
		document.getElementById("zip_Error").innerHTML = "Please enter a vaild Zip/Postal Code.";
		document.getElementById("zip").select();
		document.getElementById("zip").focus();
		document.getElementById("zip").style.backgroundColor = 'eeeeee';
		return false;
	}

	UpdateProfile.submit();
}

function updateRegion(){
	countryid = document.getElementById("countryid").value;
	
	var iCount = document.getElementById("state").options.length;
	while(iCount > 0) {
		iCount--;
		document.getElementById("state").options[iCount] = null;
	}
	
	if(countryid == 'UNITED STATES' ) {
		
            document.getElementById("state").options[0] = new Option( "ALABAMA", "AL");
            
            document.getElementById("state").options[1] = new Option( "ALASKA", "AK");
            
            document.getElementById("state").options[2] = new Option( "APO/FPO AA", "APO/FPO AA");
            
            document.getElementById("state").options[3] = new Option( "APO/FPO AE", "APO/FPO AE");
            
            document.getElementById("state").options[4] = new Option( "APO/FPO AP", "APO/FPO AP");
            
            document.getElementById("state").options[5] = new Option( "ARIZONA", "AZ");
            
            document.getElementById("state").options[6] = new Option( "ARKANSAS", "AR");
            
            document.getElementById("state").options[7] = new Option( "CALIFORNIA", "CA");
            
            document.getElementById("state").options[8] = new Option( "COLORADO", "CO");
            
            document.getElementById("state").options[9] = new Option( "CONNECTICUT", "CT");
            
            document.getElementById("state").options[10] = new Option( "DELAWARE", "DE");
            
            document.getElementById("state").options[11] = new Option( "DISTRICT OF COLUMBIA", "DC");
            
            document.getElementById("state").options[12] = new Option( "FLORIDA", "FL");
            
            document.getElementById("state").options[13] = new Option( "GEORGIA", "GA");
            
            document.getElementById("state").options[14] = new Option( "HAWAII", "HI");
            
            document.getElementById("state").options[15] = new Option( "IDAHO", "ID");
            
            document.getElementById("state").options[16] = new Option( "ILLINOIS", "IL");
            
            document.getElementById("state").options[17] = new Option( "INDIANA", "IN");
            
            document.getElementById("state").options[18] = new Option( "IOWA", "IA");
            
            document.getElementById("state").options[19] = new Option( "KANSAS", "KS");
            
            document.getElementById("state").options[20] = new Option( "KENTUCKY", "KY");
            
            document.getElementById("state").options[21] = new Option( "LOUISIANA", "LA");
            
            document.getElementById("state").options[22] = new Option( "MAINE", "ME");
            
            document.getElementById("state").options[23] = new Option( "MARYLAND", "MD");
            
            document.getElementById("state").options[24] = new Option( "MASSACHUSETTS", "MA");
            
            document.getElementById("state").options[25] = new Option( "MICHIGAN", "MI");
            
            document.getElementById("state").options[26] = new Option( "MINNESOTA", "MN");
            
            document.getElementById("state").options[27] = new Option( "MISSISSIPPI", "MS");
            
            document.getElementById("state").options[28] = new Option( "MISSOURI", "MO");
            
            document.getElementById("state").options[29] = new Option( "MONTANA", "MT");
            
            document.getElementById("state").options[30] = new Option( "NEBRASKA", "NE");
            
            document.getElementById("state").options[31] = new Option( "NEVADA", "NV");
            
            document.getElementById("state").options[32] = new Option( "NEW HAMPSHIRE", "NH");
            
            document.getElementById("state").options[33] = new Option( "NEW JERSEY", "NJ");
            
            document.getElementById("state").options[34] = new Option( "NEW MEXICO", "NM");
            
            document.getElementById("state").options[35] = new Option( "NEW YORK", "NY");
            
            document.getElementById("state").options[36] = new Option( "NORTH CAROLINA", "NC");
            
            document.getElementById("state").options[37] = new Option( "NORTH DAKOTA", "ND");
            
            document.getElementById("state").options[38] = new Option( "OHIO", "OH");
            
            document.getElementById("state").options[39] = new Option( "OKLAHOMA", "OK");
            
            document.getElementById("state").options[40] = new Option( "OREGON", "OR");
            
            document.getElementById("state").options[41] = new Option( "PENNSYLVANIA", "PA");
            
            document.getElementById("state").options[42] = new Option( "PUERTO RICO", "PR");
            
            document.getElementById("state").options[43] = new Option( "RHODE ISLAND", "RI");
            
            document.getElementById("state").options[44] = new Option( "SOUTH CAROLINA", "SC");
            
            document.getElementById("state").options[45] = new Option( "SOUTH DAKOTA", "SD");
            
            document.getElementById("state").options[46] = new Option( "TENNESSEE", "TN");
            
            document.getElementById("state").options[47] = new Option( "TEXAS", "TX");
            
            document.getElementById("state").options[48] = new Option( "UTAH", "UT");
            
            document.getElementById("state").options[49] = new Option( "VERMONT", "VT");
            
            document.getElementById("state").options[50] = new Option( "VIRGINIA", "VA");
            
            document.getElementById("state").options[51] = new Option( "WASHINGTON", "WA");
            
            document.getElementById("state").options[52] = new Option( "WEST VIRGINIA", "WV");
            
            document.getElementById("state").options[53] = new Option( "WISCONSIN", "WI");
            
            document.getElementById("state").options[54] = new Option( "WYOMING", "WY");
            
	}
	else if (countryid == 'CANADA' ) {
		
            document.getElementById("state").options[0] = new Option( "ALBERTA", "AB");
            
            document.getElementById("state").options[1] = new Option( "BRITISH COLUMBIA", "BC");
            
            document.getElementById("state").options[2] = new Option( "MANITOBA", "MB");
            
            document.getElementById("state").options[3] = new Option( "NEW BRUNSWICK", "NB");
            
            document.getElementById("state").options[4] = new Option( "NEWFOUNDLAND AND LABRADOR", "NL");
            
            document.getElementById("state").options[5] = new Option( "NORTHWEST TERRITORIES", "NT");
            
            document.getElementById("state").options[6] = new Option( "NOVA SCOTIA", "NS");
            
            document.getElementById("state").options[7] = new Option( "NUNAVUT", "NU");
            
            document.getElementById("state").options[8] = new Option( "ONTARIO", "ON");
            
            document.getElementById("state").options[9] = new Option( "PRINCE EDWARD ISLAND", "PE");
            
            document.getElementById("state").options[10] = new Option( "QUEBEC", "QC");
            
            document.getElementById("state").options[11] = new Option( "SASKATCHEWAN", "SK");
            
            document.getElementById("state").options[12] = new Option( "YUKON", "YT");
            
	}
	else {
		document.getElementById("state").options[0] = new Option( "(Not Applicable)", "none");
	}
}

//Called from Gateway
function load_displayTextWin(textcode) {
	url = '/index.cfm/evt/displayText/textcode/' + textcode;
	$('#MyWindow').jqmShow();
	$('#MyWindow_content').load(url);	
}

//Generic call
function load_ajax_win(url) {
	$('#MyWindow').jqmShow();
	$('#MyWindow_content').load(url);
}

