/****************************************************************/
/* validateData function										*/
/* used to validate contact/request_info.asp form				*/
/****************************************************************/
function validateData(f){
	errorMsg = "Please enter the following required fields\n";
	isError = false;
	isBrochure = document.pageForm.sendBrochure.checked;
	isNewsletter = document.pageForm.joinNewsletter.checked
	strFname = f.firstName.value;
	strLname = f.lastName.value;
	strCompany = f.company.value;
	strTitle = f.title.value;
	strStreet = f.street.value;
	strCity	= f.city.value;
	strState = f.state.value;
	strZip		= f.zip.value;
	strPhone1 = f.phone.value;
	strPhone2 = f.phone2.value;
	strPhone3 = f.phone3.value;
	strEmail = f.email.value;

	if(isStringWhitespace(strFname)){
		errorMsg += "First Name\n";
		isError = true;	}	
	if(isStringWhitespace(strLname)){
		errorMsg += "Last Name\n";
		isError = true;	}
	if(isStringWhitespace(strCompany)){
		errorMsg += "Company\n";
		isError = true;	}

	if(!isBrochure || !isNewsletter || (isBrochure || isNewletter)){
		if(isBrochure || !isNewsletter){
			if(isStringWhitespace(strTitle)){
				errorMsg += "Title\n";
				isError = true;	}
			if(isStringWhitespace(strStreet)){
				errorMsg += "Street\n";
				isError = true;	}
			if(isStringWhitespace(strCity)){
				errorMsg += "City\n";
				isError = true;	}
			if(isStringWhitespace(strState)){
				errorMsg += "State\n";
				isError = true;	}
			if(isStringWhitespace(strZip) || !isNumeric(strZip)){
				errorMsg += "Zip\n";
				isError = true;	}
		}
	}

	if(isStringWhitespace(strPhone1) || !isNumeric(strPhone1)){
		errorMsg += "Area Code\n";
		isError = true;	}
	if(isStringWhitespace(strPhone2) || !isNumeric(strPhone2)){
		errorMsg += "Phone Prefix\n";
		isError = true;	}
	if(isStringWhitespace(strPhone3) || !isNumeric(strPhone3)){
		errorMsg += "Phone Suffix\n";
		isError = true;	}
	if(!checkEmail(strEmail)){
		errorMsg += "Email\n";
		isError = true;	}	
	if(isError){
		alert(errorMsg);
		return false; }
}// end function
/****************************************************************/
/* validateNewletter function									*/
/* used to validate newsletter signup form on top of all pages	*/
/****************************************************************/
function validateNewsletter(f){
	errorMsg = "Please enter the following required fields\n";
	isError = false;
	strName = f.nl_name.value;
	strEmail = f.nl_email.value;

	if(isStringWhitespace(strName)){
		errorMsg += "Name\n";
		isError = true;	}
	if(!checkEmail(strEmail)){
		errorMsg += "Email";
		isError = true;	}
	if(isError){
		alert(errorMsg);
		return false; }
}// end function

/****************************************************************/
/* validateBid Form function									*/
/* used to validate bid signup form								*/
/****************************************************************/
function validateBidForm(f){
	errorMsg = "Please enter the following required fields:\n";
	isError = false;
	strCompany = f.companyName.value;
	strAddress = f.address.value;
	strCity = f.city.value;
	strState = f.state.value;
	strZip = f.zip.value;
	strPhone = f.phone.value;
	strPhone2 = f.phone2.value;
	strPhone3 = f.phone3.value;
	strContactName = f.contact.value;
	strTrade = f.trade.value;

	if(isStringWhitespace(strCompany)){
		errorMsg += "Company Name\n";
		isError = true; }
	if(isStringWhitespace(strAddress)){
		errorMsg += "Address\n";
		isError = true; }
	if(isStringWhitespace(strCity)){
		errorMsg += "City\n";
		isError = true; }
	if(isStringWhitespace(strState)){
		errorMsg += "State\n";
		isError = true; }
	if(isStringWhitespace(strZip) || !isNumeric(strZip)){
		errorMsg += "Zip\n";
		isError = true;	}
	if(isStringWhitespace(strPhone) || !isNumeric(strPhone)){
		errorMsg += "Area Code\n";
		isError = true; }
	if(isStringWhitespace(strPhone2) || !isNumeric(strPhone2)){
		errorMsg += "Phone Prefix\n";
		isError = true; }
	if(isStringWhitespace(strPhone3) || !isNumeric(strPhone3)){
		errorMsg += "Phone Suffix\n";
		isError = true; }
	if(isStringWhitespace(strContactName)){
		errorMsg += "Contact Name\n";
		isError = true; }
	if(isStringWhitespace(strTrade)){
		errorMsg += "Trades of Work\n";
		isError = true; }

	if(isError){
		alert(errorMsg);
		return false; }
}// end function
/****************************************************************/
/* common functions												*/
/* used to in multiple page validation funcitons				*/
/****************************************************************/
function checkEmail(pEmail) 
{	
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(pEmail)){
	alert('success');
		return true;
		}else
		{
		alert('sorry');
	return false;
	}
}// end function


function emailCheck(strValue)				
{
	if (strValue.indexOf("@") == -1 && strValue != "") 
	{
		return false;
	}
	if (strValue.indexOf(".") == -1 && strValue != "") 
	{
		return false;
	}
	if ((strValue.lastIndexOf("@") > strValue.lastIndexOf(".")) && (strValue != "")) 
	{
		return false;
	}
	return true;
}


function isNumeric(pText)
{
	var ValidChars = "0123456789";
	var isNumber = true;
	var Char;

		for (i = 0; i < pText.length && isNumber == true; i++) 
		{ 
			Char = pText.charAt(i); 
			if (ValidChars.indexOf(Char) == -1) 
			{
				isNumber = false;
			}
		}
	return isNumber;
}// end function

var whitespace = " \t\n\r";
function isEmpty(s){   
	return ((s == null) || (s.length == 0));
}// end function
function isStringWhitespace(str){   
	var i;
	if (isEmpty(str)) return true;
	for (i = 0; i < str.length; i++){
		var c = str.charAt(i);
		if (whitespace.indexOf(c) == -1) return false;
	}
	return true;
}// end function