// JavaScript Document

/* validation for the "Get A Quote" form
	Jonathan Villatoro for eBlue Networks, LLC */
function ValidateContactForm() {
	valid = true;

    if (document.quoteReqForm.name.value == "") /* check name */
    {	document.quoteReqForm.name.style.backgroundColor='#FF0000';
		document.quoteReqForm.name.style.color='#FFFFFF';
		document.quoteReqForm.name.value="Please fill in your name";
        valid = false;
    }
	phone_regex=/^\d{10}?$/; /* check phone */
	if (!(phone_regex.test(document.quoteReqForm.phone.value)))
	{	document.quoteReqForm.phone.style.backgroundColor='#FF0000';
		document.quoteReqForm.phone.style.color='#FFFFFF';
		document.quoteReqForm.phone.value="Please enter your phone number";
		valid=false;
	}
	email_regex=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/;  /* check email address */
	if (!(email_regex.test(document.quoteReqForm.email.value)))
	{	document.quoteReqForm.email.style.backgroundColor='#FF0000';
		document.quoteReqForm.email.style.color='#FFFFFF';
		document.quoteReqForm.email.value="Please enter your email address";
		valid=false;
	}
	zip_code_regex=/^\d{5}?$/; /* check zip code */
	if (!(zip_code_regex.test(document.quoteReqForm.zip_code.value)))
	{	document.quoteReqForm.zip_code.style.backgroundColor='#FF0000';
		document.quoteReqForm.zip_code.style.color='#FFFFFF';
		document.quoteReqForm.zip_code.value="Please enter a valid Zip Code";
		valid=false;
	}
	/*if (valid) {
		document.write('Thanks for you request.<br />One of our representatives should contact you shortly.<br><a href="javascript:history.go(-1)">back to page</a>');
		//setTimeout('javascript:history.go(0)',10000);
	}*/
    return valid;
}

// Radio Button Validation
// copyright Stephen Chapman, 15th Nov 2004,14th Sep 2005
// you may copy this function but please keep the copyright notice with it
function valButton(btn) {
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
}

/* validation for the "Order Now" form
	Jonathan Villatoro for eBlue Networks, LLC */
function ValidateOrderForm() {
	valid = true;

    if (document.orderForm.name.value == "") /* check name */
    {	document.orderForm.name.style.backgroundColor='#FF0000';
		document.orderForm.name.style.color='#FFFFFF';
		document.orderForm.name.value="Please fill in your name";
        valid = false;
    }
	phone_regex=/^[0-9\\-\\.]+$/; /* check phone */
	if (!(phone_regex.test(document.orderForm.phone.value)))
	{	document.orderForm.phone.style.backgroundColor='#FF0000';
		document.orderForm.phone.style.color='#FFFFFF';
		document.orderForm.phone.value="Please enter your phone number";
		valid=false;
	}
	email_regex=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/;  /* check email address */
	if (!(email_regex.test(document.orderForm.email.value)))
	{	document.orderForm.email.style.backgroundColor='#FF0000';
		document.orderForm.email.style.color='#FFFFFF';
		document.orderForm.email.value="Please enter your email address";
		valid=false;
	}
	zip_code_regex=/^\d{5}(-\d{4})?$/; /* check zip code */
	if (!(zip_code_regex.test(document.orderForm.zip_code.value)))
	{	document.orderForm.zip_code.style.backgroundColor='#FF0000';
		document.orderForm.zip_code.style.color='#FFFFFF';
		document.orderForm.zip_code.value="Please enter a valid Zip Code";
		valid=false;
	}
	alertText="";
	if (valButton(document.orderForm.plan) == null) /* check plan selection */
	{	alertText=alertText+"\r\nPlease select a Plan";
		valid=false;
	}
	if (valButton(document.orderForm.leaseOrBuy) == null) /* check lease or buy selection */
	{	alertText=alertText+"\r\nPlease select whether to Lease or Purchase your system";
		valid=false;
	}
	if (!document.orderForm.agree_terms.checked) /* check lease or buy selection */
	{	alertText=alertText+"\r\nPlease check the Terms of Use";
		valid=false;
	}
	if (alertText!="")
	{	alert(alertText);
	}
	/*if (valid) {
		document.write('Thanks for you request.<br />One of our representatives should contact you shortly.<br><a href="javascript:history.go(-1)">back to page</a>');
		//setTimeout('javascript:history.go(0)',10000);
	}*/
    return valid;
}
