var submitcount=0;

function validateLogin() 
{                       
	if (document.login.userName.value=="")    
	{
		alert("Please enter a USERNAME then re-submit this form.");
		document.login.userName.focus();
		document.login.userName.select();
		return false;
	}
	if (document.login.password.value=="")     
	{
		alert("Please enter a PASSWORD then re-submit this form.");
		document.login.password.focus();
		document.login.password.select();
		return false;
	}
	else 
	{
		if (submitcount == 0)
		{
			submitcount++;
			return true;
		}
		else 
		{
			alert("This form has already been submitted.  Thanks!");
			return false;
		}
	}
}

function validateStudentInfo() 
{
	if (document.accountInfo.firstname.value=="")     
	{
		alert("Please enter your FIRST NAME then re-submit this form.");
		document.accountInfo.firstname.focus();
		document.accountInfo.firstname.select();
		return false;
	} 
	if (document.accountInfo.lastname.value=="")     
	{
		alert("Please enter your LAST NAME then re-submit this form.");
		document.accountInfo.lastname.focus();
		document.accountInfo.lastname.select();
		return false;
	} 
	if (document.accountInfo.address1.value=="")     
	{
		alert("Please enter your ADDRESS or P.O. BOX then re-submit this form.");
		document.accountInfo.address1.focus();
		document.accountInfo.address1.select();
		return false;
	} 
	if (document.accountInfo.city.value=="")     
	{
		alert("Please enter your CITY then re-submit this form.");
		document.accountInfo.city.focus();
		document.accountInfo.city.select();
		return false;
	} 
	if (document.accountInfo.zip.value=="")    
	{
		alert("Please enter your Zip then re-submit this form.");
		document.accountInfo.zip.focus();
		document.accountInfo.zip.select();
		return false;
	}
	if (document.accountInfo.dayPhone.value=="")     
	{
		alert("Please enter your DAYTIME PHONE NUMBER then re-submit this form.");
		document.accountInfo.dayPhone.focus();
		document.accountInfo.dayPhone.select();
		return false;
	} 
	if ((document.accountInfo.email.value=="") || 
		(document.accountInfo.email.value.indexOf('@') == -1) || 
		(document.accountInfo.email.value.indexOf('.') == -1))     
		{
		alert("Please enter your EMAIL ADDRESS then re-submit this form. Example: yourname@yourisp.com");
		document.accountInfo.email.focus();
		document.accountInfo.email.select();
		return false;
	}
	else 
	{
		if (submitcount == 0)
		{
			submitcount++;
			return true;
		}
		else 
		{
			alert("This form has already been submitted.  Thanks!");
			return false;
		}
	}
}

function validateCustomer() 
{
	if (document.customer.firstname.value=="")     
	{
		alert("Please enter your FIRST NAME then re-submit this form.");
		document.customer.firstname.focus();
		document.customer.firstname.select();
		return false;
	} 
	if (document.customer.lastname.value=="")     
	{
		alert("Please enter your LAST NAME then re-submit this form.");
		document.customer.lastname.focus();
		document.customer.lastname.select();
		return false;
	} 
	if (document.customer.address1.value=="")     
	{
		alert("Please enter your ADDRESS or P.O. BOX then re-submit this form.");
		document.customer.address1.focus();
		document.customer.address1.select();
		return false;
	} 
	if (document.customer.city.value=="")     
	{
		alert("Please enter your CITY then re-submit this form.");
		document.customer.city.focus();
		document.customer.city.select();
		return false;
	} 
	if (document.customer.zip.value=="")    
	{
		alert("Please enter your Zip then re-submit this form.");
		document.customer.zip.focus();
		document.customer.zip.select();
		return false;
	}
	if (document.customer.dayPhone.value=="")     
	{
		alert("Please enter your DAYTIME PHONE NUMBER then re-submit this form.");
		document.customer.dayPhone.focus();
		document.customer.dayPhone.select();
		return false;
	} 
	if ((document.customer.email.value=="") || 
		(document.customer.email.value.indexOf('@') == -1) || 
		(document.customer.email.value.indexOf('.') == -1))     
		{
		alert("Please enter your EMAIL ADDRESS then re-submit this form. Example: yourname@yourisp.com");
		document.customer.email.focus();
		document.customer.email.select();
		return false;
	}
	if (!document.customer.acceptTC.checked)   
	{
		alert("You have to read and accept the Terms & Conditions and Privacy Policy.");
		document.customer.acceptTC.focus();
		return false;
	}
	else 
	{
		if (submitcount == 0)
		{
			submitcount++;
			return true;
		}
		else 
		{
			alert("This form has already been submitted.  Thanks!");
			return false;
		}
	}
}

function validatePayment() 
{

	if (document.customer.ccNumber.value=="")    
	{
		alert("Please enter your CREDIT CARD NUMBER then re-submit this form.");
		document.customer.ccNumber.focus();
		document.customer.ccNumber.select();
		return false;
	} 
	if (document.customer.ccNameOnCard.value=="")   
	{
		alert("Please enter the NAME ON CARD then re-submit this form.");
		document.customer.ccNameOnCard.focus();
		document.customer.ccNameOnCard.select();
		return false;
	}
	else 
	{
		if (submitcount == 0)
		{
			submitcount++;
			return true;
		}
		else 
		{
			alert("This form has already been submitted.  Thanks!");
			return false;
		}
	}
}



function validateCDCustomer() 
{
	if (document.customer.quantity.value=="")     
	{
		alert("Please enter a QUANTITY then re-submit this form.");
		document.customer.quantity.focus();
		document.customer.quantity.select();
		return false;
	} 
	if (!(isNumber(document.customer.quantity.value)))     // checks if password field is blank
		{
			alert("Please enter an number for QUANTITY then re-submit this form.");
			document.customer.quantity.focus();
			document.customer.quantity.select();
			return false;
		}
	if (document.customer.firstName.value=="")     
	{
		alert("Please enter your FIRST NAME then re-submit this form.");
		document.customer.firstName.focus();
		document.customer.firstName.select();
		return false;
	} 
	if (document.customer.lastName.value=="")     
	{
		alert("Please enter your LAST NAME then re-submit this form.");
		document.customer.lastName.focus();
		document.customer.lastName.select();
		return false;
	} 
	if (document.customer.billingAddress1.value=="")     
	{
		alert("Please enter your BILLING ADDRESS or P.O. BOX then re-submit this form.");
		document.customer.billingAddress1.focus();
		document.customer.billingAddress1.select();
		return false;
	} 
	if (document.customer.billingCity.value=="")     
	{
		alert("Please enter your BILLING CITY then re-submit this form.");
		document.customer.billingCity.focus();
		document.customer.billingCity.select();
		return false;
	} 
	if (document.customer.billingZip.value=="")    
	{
		alert("Please enter your BILLING ZIP then re-submit this form.");
		document.customer.billingZip.focus();
		document.customer.billingZip.select();
		return false;
	}
	if (document.customer.billingDayPhone.value=="")     
	{
		alert("Please enter your BILLING DAYTIME PHONE NUMBER then re-submit this form.");
		document.customer.billingDayPhone.focus();
		document.customer.billingDayPhone.select();
		return false;
	} 
	if ((document.customer.email.value=="") || 
		(document.customer.email.value.indexOf('@') == -1) || 
		(document.customer.email.value.indexOf('.') == -1))     
		{
		alert("Please enter your EMAIL ADDRESS then re-submit this form. Example: yourname@yourisp.com");
		document.customer.email.focus();
		document.customer.email.select();
		return false;
	}
	if (!document.customer.shippingSameAsBilling.checked)
	{
		if (document.customer.shippingAddress1.value=="")     
		{
			alert("Please enter your SHIPPIING ADDRESS or P.O. BOX then re-submit this form.");
			document.customer.shippingAddress1.focus();
			document.customer.shippingAddress1.select();
			return false;
		} 
		if (document.customer.shippingCity.value=="")     
		{
			alert("Please enter your SHIPPIING CITY then re-submit this form.");
			document.customer.shippingCity.focus();
			document.customer.shippingCity.select();
			return false;
		} 
		if (document.customer.shippingZip.value=="")    
		{
			alert("Please enter your SHIPPIING ZIP then re-submit this form.");
			document.customer.shippingZip.focus();
			document.customer.shippingZip.select();
			return false;
		}
		if (document.customer.shippingDayPhone.value=="")     
		{
			alert("Please enter your SHIPPIING DAYTIME PHONE NUMBER then re-submit this form.");
			document.customer.shippingDayPhone.focus();
			document.customer.shippingDayPhone.select();
			return false;
		} 
	}
	if (!document.customer.acceptTC.checked)   
	{
		alert("You have to read and accept the Terms & Conditions and Privacy Policy.");
		document.customer.acceptTC.focus();
		return false;
	}
	else 
	{
		if (submitcount == 0)
		{
			submitcount++;
			return true;
		}
		else 
		{
			alert("This form has already been submitted.");
			return true;
			//return false;
		}
	}
}

function clearshipto(){
	if (document.customer.shippingSameAsBilling.checked) {
	document.customer.shippingAddress1.value='';
	document.customer.shippingAddress2.value='';
	document.customer.shippingCity.value='';
	document.customer.shippingState.selectedIndex=0;
	document.customer.shippingZip.value='';
	document.customer.shippingDayPhone.value='';
	document.customer.shippingEveningPhone.value='';
	}
}


function isNumber(objValue)
	{
		var number_format = " .0123456789";
		for (var i = 0; i < objValue.length; i++)
		{
			char = number_format.indexOf(objValue.charAt(i));
			if (char < 0)
			{	
				return false;
			}	
		}
		return true;
	}
function validateCertRequest() 
{
	if (document.certificateRequest.reason.value=="")     
	{
		alert("Please enter your REASON FOR NEEDING ANOTHER CERTIFICATE then re-submit this form.");
		document.certificateRequest.reason.focus();
		return false;
	} 
	else 
	{
		if (submitcount == 0)
		{
			submitcount++;
			return true;
		}
		else 
		{
			alert("This form has already been submitted.  Thanks!");
			return false;
		}
	}
}




// validate other amount
function validatePhone(field) 
{
	var valid = " 0123456789-"
	var ok = "yes";
	var temp;

	for (var i=0; i<field.value.length; i++) 
	{
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") 
		{
			ok = "no";
		}
	}

	if (ok == "no") 
	{
		alert("Invalid character entry!  Only numbers and dashes (-) are accepted for this field!");
		field.focus();
		field.select();
	}
}


function OpenWindow(location,win_name,stuff) 
{ 
	window.open(location,win_name,stuff);
}
	
function populate()
{
	d = new Date();
	document.customer.title.selectedIndex = "2";
	document.customer.firstname.value = "Bubba";
	document.customer.middleInitial.value = "P";
	document.customer.lastname.value = "Kalchbrenner";
	document.customer.address1.value = "192 Main St.";
	document.customer.address2.value = "Court 5";
	document.customer.city.value = "Cordova";
	document.customer.state.selectedIndex = "48";
	document.customer.zip.value = "98019";
	document.customer.dayPhone.value = "909 123-4567";
	document.customer.email.value = "hosting@flyingmountain.co";
	document.customer.ccNumber.value = "4111111111111111";
	document.customer.ccExpMonth.selectedIndex = "3";
	document.customer.ccExpYear.selectedIndex = "3";
	document.customer.ccNameOnCard.value = "TEST";
}

function populateCD()
{
	document.customer.quantity.value = "1";
	document.customer.title.selectedIndex = "1";
	document.customer.firstName.value = "Mim";
	document.customer.middleInitial.value = "P";
	document.customer.lastName.value = "Wallach";
	document.customer.suffix.selectedIndex = "2";
	document.customer.billingAddress1.value = "192 Main St.";
	document.customer.billingAddress2.value = "Court 5";
	document.customer.billingCity.value = "Cordova";
	document.customer.billingState.selectedIndex = "48";
	document.customer.billingZip.value = "98019";
	document.customer.billingDayPhone.value = "909 123-4567";
	document.customer.billingEveningPhone.value = "909 123-4567";
	document.customer.email.value = "hosting@flyingmountain.com";
	document.customer.buisnessTitle.value = "Bigdaddy";
	document.customer.companyName.value = "House of Cards";
	document.customer.shippingAddress1.value = "192 Main St.";
	document.customer.shippingAddress2.value = "Court 5";
	document.customer.shippingCity.value = "Cordova";
	document.customer.shippingState.selectedIndex = "48";
	document.customer.shippingZip.value = "98019";
	document.customer.shippingDayPhone.value = "909 123-4567";
	document.customer.shippingEveningPhone.value = "909 123-4567";
}

function populateCDpay()
{
	
	document.customer.ccNumber.value = "4111111111111111";
	document.customer.ccExpMonth.selectedIndex = "3";
	document.customer.ccExpYear.selectedIndex = "3";
	document.customer.ccNameOnCard.value = "TEST";
}