//var requiredFields = new Array("txtName", "txtTitle", "txtCompany", "txtAddress", "txtCity", "txtState", "txtZIP", "txtEmail", "txtPhone1", "txtWebsite");
//var fieldNames = new Array("Name", "Title", "Company", "Address", "City", "State / Province / Region", "ZIP / Postal Code", "Email", "Phone 1", "Web Site");   
//var FormOK = NameOK = TitleOK = CompanyOK = AddressOK = CityOK = StateOK = ZIPOK = EmailOK = PhoneOK = WebsiteOK = true;
var requiredFields = new Array("txtName", "txtTitle", "txtCompany", "txtAddress", "txtCity", "txtZIP", "txtEmail", "txtPhone1", "txtWebsite");
var fieldNames = new Array("Name", "Title", "Company", "Address", "City", "ZIP / Postal Code", "Email", "Phone 1", "Web Site");   
var FormOK = NameOK = TitleOK = CompanyOK = AddressOK = CityOK = ZIPOK = EmailOK = PhoneOK = WebsiteOK = true;

function checkFields(input) {

	Country = (document.AForm.Country.selectedIndex)-0;
	if (Country == 0){
		if (document.AForm.Country.value == "") { alert("The Country field requires valid input"); return false;  }
	}
	
	//if (Country == 1) {  //|| (Country == 2){
	////if ((Country == 1) || (Country == 2)){
		//alert ("US or Canada!!");
		//to get state drop down value into txtState
		////document.AForm.txtState.value = document.AForm.State.value;
	////}

	//commented out txtState as required field, so need to ck txtState value if 
	//User changes and selects US or Can in Country dropdown
	if ((Country == 1) || (Country == 2)){
		if (document.AForm.State.value == "") { alert("The State / Province / Region field requires valid input"); return false; }
		else{
			document.AForm.txtState.value = document.AForm.State.value;
		}
	}

	//check txtState is not empty if not US or Canada
	if (!(Country == 1 || Country == 2)){
		if (document.AForm.State.value == "") { 
			if (document.AForm.txtState.value == "" || document.AForm.txtState.value == " "){
				alert("The State / Province / Region field requires valid input"); return false; 
			}
		}	
		else{
			document.AForm.txtState.value = document.AForm.State.value;
		}
	}
	
	//get State value into txtState if user leaves drop downs unchanged
	////MyStateDropDownValue = (document.AForm.State.selectedIndex)-0;
	////if ((Country == 0) && (MyStateDropDownValue == 0)){
	////	document.AForm.txtState.value = document.AForm.State.value;
	////}
			
	Source = (document.AForm.Source.selectedIndex)-0;
	if (Source == 0){
		if (document.AForm.Source.value == "") { alert("The 'Where did you hear about us?' field requires valid input"); return false;  }
	}

	if (!(checkRequiredFieldsBC(input))) {return false;}	
	if (!(NameOK)) { alert("The Name field requires valid input"); return false; }
	if (!(TitleOK)) { alert("The Title field requires valid input"); return false; }
	if (!(CompanyOK)) { alert("The Company field requires valid input"); return false; }
	if (!(AddressOK)) { alert("The Address field requires valid input"); return false; }
	if (!(CityOK)) { alert("The City field requires valid input"); return false; }
	//if (!(StateOK)) { alert("The State / Province / Region field requires valid input"); return false; }
	if (!(ZIPOK)) { alert("The ZIP / Postal Code field requires valid input"); return false; }
	if (!(EmailOK)) { alert("The Email field requires valid input"); return false; }
	if (!(PhoneOK)) { alert("The Phone 1 field requires valid input"); return false; }
	if (!(WebsiteOK)) { alert("The Web Site field requires valid input"); return false; }
	else {
	return true; 
	}
}	
		
function checkRequiredFieldsBC(input)
{             
   
    var fieldCheck   = true;
    var fieldsNeeded = "\nA value must be entered in the following field(s):\n\n\t";

    for(var fieldNum=0; fieldNum < requiredFields.length; fieldNum++) {
        if ((input.elements[requiredFields[fieldNum]].value == "") ||
            (input.elements[requiredFields[fieldNum]].value == " ")) {

            fieldsNeeded += fieldNames[fieldNum] + "\n\t";
            fieldCheck = false;
        }
    }
  
    if (fieldCheck == true)
    {
		FormOK = true
        return true;
    }

    else
    {
		FormOK = false
        alert(fieldsNeeded);
        return false;
    }
}

// Check whether string s is empty.
function ifEmpty(s)
{   
	return ((s == null) || (s.length == 0))
}

// Returns true if string s is empty or 
// whitespace characters only.

function isWhitespace (s)
{   
	var i;
	var whitespace = " \t\n\r";
	
    // Is s empty?
    if (ifEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
	// Check that current character isn't whitespace.
	var c = s.charAt(i);

	if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}

// isEmail (STRING s [, BOOLEAN emptyOK])
// 
// Email address must be of form a@b.c ... in other words:
// * there must be at least one character before the @
// * there must be at least one character before and after the .
// * the characters @ and . are both required
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isEmail (s)
{   
	if (ifEmpty(s)) 
       if (isEmail.arguments.length == 1) return alert('Please Enter Email Address');
       else return (isEmail.arguments[1] == true);
   
    // is s whitespace?
    if (isWhitespace(s)) return alert('invalid email1'); //false;
    
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return alert('Invalid Email Address without  "@" '); //false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return alert('Invalid Email Address without  "." '); //false;
    else return true;
}		

function toNumber(checkString)
		{
			newString = ""; 	  //if not, then massage the numbers
			// LOOP THROUGH STRING CHARACTER BY CHARACTER
			for (i = 0; i < checkString.length; i++) {
				ch = checkString.substring(i, i+1);

			 // CHECKS TO SEE IF A NUMBER IS BETWEEN 0 AND 9, or - 
				if ((ch >="0"  && ch <= "9"))
				{
				 newString += ch;
				 }
				}
	
				return newString;
		}

/*  checking for valid Phone or Fax*/
function isPhoneFax(checkString) {
	//	check for incompatable characters
    for (i = 0; i < checkString.length; i++) {
        ch = checkString.substring(i, i+1);
		//if (!((ch >="0"  && ch <= "9") || (ch==" ") || (ch=="-") || (ch=="(") || (ch==")") || (ch=="x") ))
		if (!((ch >="0"  && ch <= "9") || (ch==" ") || (ch=="-") || (ch=="(") || (ch==")") || (ch=="x") ))
			{
				alert('This Phone number contains incompatable characters');
				document.AForm.txtPhone.clear;
				return(false);
			}
	}
	if (checkString.length >= 10 && checkString.length <=25)
		{
		return (true);
		}
	else 
		{ 
		alert('This Phone number is invalid'); 
		document.AForm.txtPhone.clear;
		return (false);
		}
}		


function changeRegionStProv() {
	
	BizCoun = document.AForm.Country
	BizRSP = document.AForm.State
	
	with (BizCoun) {
		switch (selectedIndex){
			//if --SELECT--
			//case 0:
			//	document.AForm.txtState.style.visibility='hidden';
			//	document.AForm.State.style.visibility='hidden';
			//	break
			//United States	
			case 1:
				document.AForm.txtState.style.visibility='hidden';
				document.AForm.State.style.visibility='visible';
				for (var i = BizRSP.options.length; i > 0; i--) {
					BizRSP.options[i] = null;
				}
				BizRSP.options[0] = new Option("Select a State","")
				BizRSP.options[1] = new Option("Alabama","AL")
				BizRSP.options[2] = new Option("Alaska","AK")
				BizRSP.options[3] = new Option("Arizona","AZ")
				BizRSP.options[4] = new Option("Arkansas","AR")
				BizRSP.options[5] = new Option("California","CA")
				BizRSP.options[6] = new Option("Colorado","CO")
				BizRSP.options[7] = new Option("Connecticut","CT")
				BizRSP.options[8] = new Option("Delaware","DE")
				BizRSP.options[9] = new Option("Dist. of Columbia","DC")
				BizRSP.options[10] = new Option("Florida","FL")
				BizRSP.options[11] = new Option("Georgia","GA")
				BizRSP.options[12] = new Option("Hawaii","HI")
				BizRSP.options[13] = new Option("Idaho","ID")
				BizRSP.options[14] = new Option("Illinois","IL")
				BizRSP.options[15] = new Option("Indiana","IN")
				BizRSP.options[16] = new Option("Iowa","IA")
				BizRSP.options[17] = new Option("Kansas","KS")
				BizRSP.options[18] = new Option("Kentucky","KY")
				BizRSP.options[19] = new Option("Louisiana","LA")
				BizRSP.options[20] = new Option("Maine","ME")
				BizRSP.options[21] = new Option("Maryland","MD")
				BizRSP.options[22] = new Option("Massachusetts","MA")
				BizRSP.options[23] = new Option("Michigan","MI")
				BizRSP.options[24] = new Option("Minnesota","MN")
				BizRSP.options[25] = new Option("Mississippi","MS")
				BizRSP.options[26] = new Option("Missouri","MO")
				BizRSP.options[27] = new Option("Montana","MT")
				BizRSP.options[28] = new Option("Nebraska","NE")
				BizRSP.options[29] = new Option("Nevada","NV")
				BizRSP.options[30] = new Option("New Hampshire","NH")
				BizRSP.options[31] = new Option("New Jersey","NJ")
				BizRSP.options[32] = new Option("New Mexico","NM")
				BizRSP.options[33] = new Option("New York","NY")
				BizRSP.options[34] = new Option("North Carolina","NC")
				BizRSP.options[35] = new Option("North Dakota","ND")
				BizRSP.options[36] = new Option("Ohio","OH")
				BizRSP.options[37] = new Option("Oklahoma","OK")
				BizRSP.options[38] = new Option("Oregon","OR")
				BizRSP.options[39] = new Option("Pennsylvania","PA")
				BizRSP.options[40] = new Option("Rhode Island","RI")
				BizRSP.options[41] = new Option("South Carolina","SC")
				BizRSP.options[42] = new Option("South Dakota","SD")
				BizRSP.options[43] = new Option("Tennessee","TN")
				BizRSP.options[44] = new Option("Texas","TX")
				BizRSP.options[45] = new Option("Utah","UT")
				BizRSP.options[46] = new Option("Vermont","VT")
				BizRSP.options[47] = new Option("Virginia","VA")
				BizRSP.options[48] = new Option("Washington","WA")
				BizRSP.options[49] = new Option("West Virginia","WV")
				BizRSP.options[50] = new Option("Wisconsin","WI")
				BizRSP.options[51] = new Option("Wyoming","WY")
				BizRSP.options[0].selected = true;
				break	
			//Canada
			case 2:
				document.AForm.txtState.style.visibility='hidden';
				document.AForm.State.style.visibility='visible';
				for (var i = BizRSP.options.length; i > 0; i--) {
					BizRSP.options[i] = null;
				}
				BizRSP.options[0] = new Option("Select a Province","")
				BizRSP.options[1] = new Option("Alberta","AL")
				BizRSP.options[2] = new Option("British Columbia","BC")
				BizRSP.options[3] = new Option("Manitoba","MB")
				BizRSP.options[4] = new Option("New Brunswick","NB")
				BizRSP.options[5] = new Option("Newfoundland","NL")
				BizRSP.options[6] = new Option("Northwest Territories","NT")
				BizRSP.options[7] = new Option("Nova Scotia","NS")
				BizRSP.options[8] = new Option("Nunavut","NU")
				BizRSP.options[9] = new Option("Ontario","ON")
				BizRSP.options[10] = new Option("Prince Edward Island","PE")
				BizRSP.options[11] = new Option("Quebec","QC")
				BizRSP.options[12] = new Option("Saskatchewan","SK")
				BizRSP.options[13] = new Option("Yukon Territory","YT")
				BizRSP.options[0].selected = true;
				break					
			default:
				//document.frm.txt.style.visibility='visible'
				//document.AForm.txtState.style.visibility='hidden';
				//document.AForm.State.style.visibility='hidden';
				document.AForm.txtState.style.visibility='visible';
				for (var i = BizRSP.options.length; i >= 0; i--) {
					BizRSP.options[i] = null;
				}
				BizRSP.options[0] = new Option("-----","")				
				break
		}
	}
}