
function checkrequired(which) {
	var elementIndex=0, elements=which.length;
	var pass=true;

    for (elementIndex=0; elementIndex < elements; elementIndex++) {
		var tempobj=which.elements[elementIndex];

	try {
		if ((tempobj.name && tempobj.name.toLowerCase().indexOf('req') >=0) ||
		    (tempobj.id && tempobj.id.toLowerCase().indexOf('req') >=0)) {
			if (tempobj.type. toLowerCase().indexOf('checkbox') >= 0 && !tempobj.checked) {
				if (pass)
		   			alert("Please accept the agreement.");
		   		pass = false;
				tempobj.style.backgroundColor = '#FF9999';
				//break;
			}
			else if (tempobj.value == '') {			
				if (pass)
		   			alert("Please be sure that all required fields are properly completed.");
		   		pass = false;
				tempobj.style.backgroundColor = '#FF9999';
				//break;
			}
			else {
				tempobj.style.backgroundColor = '#FFFFFF';
			}
		}
		if (tempobj.name && tempobj.name.toLowerCase().indexOf('state') >=0) {
			var countryField = document.getElementById('country_req');
			if (tempobj.value == '' && countryField && countryField.value == 'US') {
				if (pass)
		   			alert("Please provide your US State.");
	   			pass = false;
				tempobj.style.backgroundColor = '#FF9999';
				//break;
			}
			else {
				tempobj.style.backgroundColor = '#FFFFFF';
			}
		}
		if (tempobj.name &&
			tempobj.name.toLowerCase().indexOf('email') >=0 && 
		    tempobj.name.toLowerCase().indexOf('optout') == -1) {
			if (!isValidEmail(tempobj.value)) {
				if (pass)
		   			alert("Please be sure to provide a valid email address.");
	   			pass = false;
				tempobj.style.backgroundColor = '#FF9999';
	   			//break;
			}
			else {
				tempobj.style.backgroundColor = '#FFFFFF';
			}
		}
		if (tempobj.id && tempobj.id.toLowerCase().indexOf('corpemail') >=0) {
			if (!isValidCorporateEmail(tempobj.value)) {
				if (pass)
		   			alert("Please provide a valid business email address.\nWe can not accept addresses from public email servers (eg: Yahoo, Hotmail");
	   			pass = false;
				tempobj.style.backgroundColor = '#FF9999';
	   			//break;
			}
			else {
				tempobj.style.backgroundColor = '#FFFFFF';
			}
		}
		if (tempobj.name && tempobj.name.toLowerCase().indexOf('ccnum') >=0) {
			if (!isValidCreditCard(tempobj.value)) {
				if (pass)
		   			alert("Invalid Credit Card Number.");
	   			pass = false;
				tempobj.style.backgroundColor = '#FF9999';
	   			//break;
			}
			else {
				tempobj.style.backgroundColor = '#FFFFFF';
			}
		}
		if (tempobj.name && tempobj.name.toLowerCase().indexOf('hostid') >=0) {
			if (!isValidHostID(tempobj.value)) {
				if (pass) {
		   			alert("Invalid Host ID -- Please click 'OK' to get instructions on retrieving your Host ID.");
		   			pass = false;
					hostIDInstructions();
				}
				tempobj.style.backgroundColor = '#FF9999';
	   			//break;
			}
			else {
				tempobj.style.backgroundColor = '#FFFFFF';
			}
		}
	}
	catch (err) {
		alert (err);
	}
	}
	return pass;
}

function isValidEmail ( email ) {
	return (email.search("@") >= 1 && 
			(email.lastIndexOf(".") > email.indexOf("@")) && 
			(email.lastIndexOf(".") != email.length - 1));
}

function isValidCorporateEmail ( email ) {
	return (email.search("@") >= 1 && 
			(email.lastIndexOf(".") > email.indexOf("@")) && 
			(email.lastIndexOf(".") != email.length - 1) &&
			(email.search("yahoo") < 0) &&
			(email.search("hotmail") < 0) &&
			(email.search("msn") < 0) && 
			(email.search("gmail") < 0));
}

function isValidHostID( hostid )   {
	return ((hostid.length == 10 && hostid.indexOf("0x") == 0) ||
		(hostid.length == 17 && hostid.indexOf(':') == 2 && hostid.lastIndexOf(':') == 14) ||
		(hostid.length == 23 && hostid.indexOf(':') == 2 && hostid.lastIndexOf(':') == 20));
}

function isValidCreditCard( CC )   {
	var digitIndex=0;
	
	CC = CC.replace(/ /g, "");
	CC = CC.replace(/-/g, "");
	if (CC.length > 17)
		return false;
	sum = 0;
	mul = 1;
	for (digitIndex = CC.length - 1; digitIndex >= 0; digitIndex--) {
		digit = CC.charAt(digitIndex);
		tproduct = parseInt(digit,10)*mul;
		if (tproduct > 9)
			tproduct -= 9;
		sum += tproduct;
		if (mul == 1)
			mul++;
		else
			mul--;
	}
	return ((sum % 10) == 0);
} 

function disableResubmit(form) {
	var resubmitIndex=0;

	for (resubmitIndex=0; resubmitIndex < form.elements.length; resubmitIndex++) {
		if (form.elements[resubmitIndex].type == 'submit') {
			//form.elements[resubmitIndex].disabled = true;
			form.elements[resubmitIndex].value = "Thank you!";
		}
	}
	//disableResubmit=noOp;
	return true;
}

function noOp(form) {
	return false;
}	

function hostIDInstructions(page) {
	if (!page)
		page = '/support_old/faq/hostIDInstructions.html';
	window.open(page,'','height=400,width=400,location=no,resizable=yes,status=no,toolbar=no,directories=no,menubar=no');
}

function popupWindow5x4(page,title) {
	window.open(page,'','height=400,width=600,location=no,resizable=yes,status=no,toolbar=no,directories=no,menubar=no,scrollbars=yes,titlebar=no');
}

function popupWindow3x3(page,title) {
	window.open(page,'','height=350,width=350,location=no,resizable=yes,status=no,toolbar=no,directories=no,menubar=no,scrollbars=yes,titlebar=no');
}
