// JavaScript Document
// Author: Tonia M. White of Affluent Concepts
// www.affluentconcepts.com
// Date: January 12, 2009


//Short Form Validation Script.
function validateContactForm() {
    var msgString = "";
	document.getElementById("nameFirst");
	document.getElementById("nameLast");
	document.getElementById("addressLine1");
	document.getElementById("addressCity");
	document.getElementById("addressState");
	document.getElementById("addressZip");
	document.getElementById("email");
	document.getElementById("primaryPhone");
	document.getElementById("fanClub");
	if( !isTwoLetters( trim(document.BillStricklandContactForm.nameFirst.value) ) ) { 
		msgString += "* Your first name must contain at least 2 letters.<br>"; 
		document.getElementById("nameFirst").className='errorStyle';
	}
	if( !isTwoLetters( trim(document.BillStricklandContactForm.nameLast.value) ) ) { 
		msgString += "* Your last name must contain at least 2 letters.<br>"; 
		document.getElementById("nameLast").className='errorStyle';
	}
	if( document.getElementById("addressLine1").value == ""){
			msgString += "* Enter your street address.<br>";
			document.getElementById("addressLine1").className='errorStyle';
	}
	if( document.getElementById("addressCity").value == ""){
			msgString += "* Enter your city.<br>";
			document.getElementById("addressCity").className='errorStyle';
	}
	if( document.getElementById("addressState").value == ""){
			msgString += "* Enter your state.<br>";
			document.getElementById("addressState").className='errorStyle';
	}
	if(!isPostalCode( document.BillStricklandContactForm.addressZip.value ) && !isZip( document.BillStricklandContactForm.addressZip.value ) ) {
		msgString += "* Enter your zip code.<br>"; 
		document.getElementById("addressZip").className='errorStyle';
	}
	if( document.BillStricklandContactForm.primaryPhone.value == "" || !isPhoneNumber( document.BillStricklandContactForm.primaryPhone.value ) ) {
			msgString += "* Enter a valid phone number.<br>"; 
			document.getElementById("primaryPhone").className='errorStyle';
    }
	if( document.BillStricklandContactForm.email.value == "" || !isEmail( document.BillStricklandContactForm.email.value ) ) {
    		msgString += "* Enter your valid email.<br>";
			document.getElementById("email").className='errorStyle';
    }
	if ( ( document.BillStricklandContactForm.fanClub[0].checked == false ) && ( document.BillStricklandContactForm.fanClub[1].checked == false ) ){
			msgString += "* Bill Strickland Fan Club - Select Yes or No.<br>";
			document.getElementById("fanClub").className='errorStyle';
	}
	if( msgString.length > 0 ) { 
		document.getElementById('error').innerHTML = msgString;  
		return false; 
	} //else {
		//document.BillStricklandContactForm.primaryPhone.value = correctPhoneNumber(document.BillStricklandContactForm.primaryPhone.value);
	//}
    return true;
}


//Validation Functions//
function isEmail(string) {
    if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
}
function isPhone(string) {
    if (string.search(/^\d{10}/) != -1)
        return true;
    else
        return false;
}
function isPhoneNumber(string) {
    if (string.search(/^(1\s*[-\/\.]?)?(\((\d{3})\)|(\d{3}))\s*[-\/\.]?\s*(\d{3})\s*[-\/\.]?\s*(\d{4})\s*(([xX]|[eE][xX][tT])\.?\s*(\d+))*$/) != -1)
        return true;
    else
        return false;
}
function isZip(string) {
    if (string.search(/^\d{5}/) != -1)
        return true;
    else
        return false;
}
function isTwoLetters(string) {
    if (string.length > 1)
        return true;
    else
        return false;
}
function isPhoneSeven(string) {
    if (string.search(/^(\((\d{3})\)|(\d{3}))\s*[-\/\.]?\s*(\d{4})\s*(([xX]|[eE][xX][tT])\.?\s*(\d+))*$/) != -1)
        return true;
    else
        return false;
}
function isPostalCode(string) {
    if (string.search(/^\s*[a-ceghj-npr-tvxy]\d[a-ceghj-npr-tv-z](\s)?\d[a-ceghj-npr-tv-z]\d\s*$/i) != -1) {
        return true;
	} else {
        return false;
	}
}
//function correctPhoneNumber (string) {
//	 phoneNumber = string.replace(/ /g,"-");
//	 phoneNumber = phoneNumber.replace(/\(/g,"-");
//	 phoneNumber = phoneNumber.replace(/\)/g,"-");
//	 phoneNumber = phoneNumber.replace(/-/g,"-");
//	 phoneNumber = phoneNumber.replace(/\./g,"-");
//	 return phoneNumber;
//}
function trim(str){
	while(''+str.charAt(0)==' ')
	str=str.substring(1,str.length);
	while(''+str.charAt(str.length-1)==' ')
	str=str.substring(0,str.length-1);
	return str;
}