	var requiredFields = new Array("txtMsgHeadline", "txtMessage", "txtEmail");
    var fieldNames = new Array("Message Headline", "Message", "Contact Email");   
	var FormOK = MsgHeadOK = MsgOK = EmailOK = true;

function checkFields(input) {

	MsgType = (document.AForm.MsgType.selectedIndex)-0;
	if (MsgType == 0){
		if (document.AForm.MsgType.value == "") { alert("The Message Type field requires valid input"); return false;  }
	}
	
	Coun = (document.AForm.Country.selectedIndex)-0;
	if (Coun == 0){
		if (document.AForm.Country.value == "") { alert("The Country field requires valid input"); return false;  }
	}

	//StateProv = (document.AForm.State.selectedIndex)-0;
	//if (StateProv == 0){
	//	if (document.AForm.State.value == "") { 
	//		if (document.AForm.Country.value == "United States") {
	//			alert("The State / Province field requires valid input"); return false;  
	//		}
	//		if (document.AForm.Country.value == "Canada") {
	//			alert("The State / Province field requires valid input"); return false;  
	//		}
	//	}
	//}
		
	if (document.AForm.txtMessage.value.length > 500){
		alert ("Your message can not exceed 500 characters."); return false;
	}
	
	if (!(checkRequiredFieldsBC(input))) {return false;}	
	if (!(MsgHeadOK)) { alert("The First Name field requires valid input"); return false; }
	if (!(MsgOK)) { alert("The Last Name field requires valid input"); return false; }
	if (!(EmailOK)) { alert("The Email Address 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 changeStateProv() {
	
	Coun = document.AForm.Country
	StateProv = document.AForm.State
	
	with (Coun) {
		switch (selectedIndex){
			//Canada
			case 2:
				for (var i = StateProv.options.length; i > 0; i--) {
					StateProv.options[i] = null;
				}
				StateProv.options[0] = new Option("Please Select","")
				StateProv.options[1] = new Option("--All Provinces--","")
				StateProv.options[2] = new Option("Alberta","Alberta")
				StateProv.options[3] = new Option("British Columbia","British Columbia")
				StateProv.options[4] = new Option("Manitoba","Manitoba")
				StateProv.options[5] = new Option("New Brunswick","New Brunswick")
				StateProv.options[6] = new Option("Newfoundland","Newfoundland")
				StateProv.options[7] = new Option("Northwest Territories","Northwest Territories")
				StateProv.options[8] = new Option("Nova Scotia","Nova Scotia")
				StateProv.options[9] = new Option("Nunavut","Nunavut")
				StateProv.options[10] = new Option("Ontario","Ontario")
				StateProv.options[11] = new Option("Prince Edward Island","Prince Edward Island")
				StateProv.options[12] = new Option("Quebec","Quebec")
				StateProv.options[13] = new Option("Saskatchewan","Saskatchewan")
				StateProv.options[14] = new Option("Yukon Territory","Yukon Territory")
				StateProv.options[0].selected = true;
				break
			//United States	
			case 1:
				for (var i = StateProv.options.length; i > 0; i--) {
					StateProv.options[i] = null;
				}
				StateProv.options[0] = new Option("Please Select","")
				StateProv.options[1] = new Option("--All States--","")
				StateProv.options[2] = new Option("Alabama","Alabama")
				StateProv.options[3] = new Option("Alaska","Alaska")
				StateProv.options[4] = new Option("Arizona","Arizona")
				StateProv.options[5] = new Option("Arkansas","Arkansas")
				StateProv.options[6] = new Option("California","California")
				StateProv.options[7] = new Option("Colorado","Colorado")
				StateProv.options[8] = new Option("Connecticut","Connecticut")
				StateProv.options[9] = new Option("Delaware","Delaware")
				StateProv.options[10] = new Option("Dist. of Columbia","Dist. of Columbia")
				StateProv.options[11] = new Option("Florida","Florida")
				StateProv.options[12] = new Option("Georgia","Georgia")
				StateProv.options[13] = new Option("Hawaii","Hawaii")
				StateProv.options[14] = new Option("Idaho","Idaho")
				StateProv.options[15] = new Option("Illinois","Illinois")
				StateProv.options[16] = new Option("Indiana","Indiana")
				StateProv.options[17] = new Option("Iowa","Iowa")
				StateProv.options[18] = new Option("Kansas","Kansas")
				StateProv.options[19] = new Option("Kentucky","Kentucky")
				StateProv.options[20] = new Option("Louisiana","Louisiana")
				StateProv.options[21] = new Option("Maine","Maine")
				StateProv.options[22] = new Option("Maryland","Maryland")
				StateProv.options[23] = new Option("Massachusetts","Massachusetts")
				StateProv.options[24] = new Option("Michigan","Michigan")
				StateProv.options[25] = new Option("Minnesota","Minnesota")
				StateProv.options[26] = new Option("Mississippi","Mississippi")
				StateProv.options[27] = new Option("Missouri","Missouri")
				StateProv.options[28] = new Option("Montana","Montana")
				StateProv.options[29] = new Option("Nebraska","Nebraska")
				StateProv.options[30] = new Option("Nevada","Nevada")
				StateProv.options[31] = new Option("New Hampshire","New Hampshire")
				StateProv.options[32] = new Option("New Jersey","New Jersey")
				StateProv.options[33] = new Option("New Mexico","New Mexico")
				StateProv.options[34] = new Option("New York","New York")
				StateProv.options[35] = new Option("North Carolina","North Carolina")
				StateProv.options[36] = new Option("North Dakota","North Dakota")
				StateProv.options[37] = new Option("Ohio","Ohio")
				StateProv.options[38] = new Option("Oklahoma","Oklahoma")
				StateProv.options[39] = new Option("Oregon","Oregon")
				StateProv.options[40] = new Option("Pennsylvania","Pennsylvania")
				StateProv.options[41] = new Option("Rhode Island","Rhode Island")
				StateProv.options[42] = new Option("South Carolina","South Carolina")
				StateProv.options[43] = new Option("South Dakota","South Dakota")
				StateProv.options[44] = new Option("Tennessee","Tennessee")
				StateProv.options[45] = new Option("Texas","Texas")
				StateProv.options[46] = new Option("Utah","Utah")
				StateProv.options[47] = new Option("Vermont","Vermont")
				StateProv.options[48] = new Option("Virginia","Virginia")
				StateProv.options[49] = new Option("Washington","Washington")
				StateProv.options[50] = new Option("West Virginia","West Virginia")
				StateProv.options[51] = new Option("Wisconsin","Wisconsin")
				StateProv.options[52] = new Option("Wyoming","Wyoming")
				StateProv.options[0].selected = true;
				break		
			default:
				for (var i = StateProv.options.length; i >= 0; i--) {
					StateProv.options[i] = null;
				}
				StateProv.options[0] = new Option("-----","")				
				break
		}
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/*
==================================================================
LTrim(string) : Returns a copy of a string without leading spaces.
==================================================================
*/
function LTrim(str)
/*
   PURPOSE: Remove leading blanks from our string.
   IN: str - the string we want to LTrim
*/
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      // We have a string with leading blank(s)...

      var j=0, i = s.length;

      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
   }
   return s;
}

/*
==================================================================
RTrim(string) : Returns a copy of a string without trailing spaces.
==================================================================
*/
function RTrim(str)
/*
   PURPOSE: Remove trailing blanks from our string.
   IN: str - the string we want to RTrim

*/
{
   // We don't want to trip JUST spaces, but also tabs,
   // line feeds, etc.  Add anything else you want to
   // "trim" here in Whitespace
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      // We have a string with trailing blank(s)...

      var i = s.length - 1;       // Get length of string

      // Iterate from the far right of string until we
      // don't have any more whitespace...
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;


      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
   }

   return s;
}

/*
=============================================================
Trim(string) : Returns a copy of a string without leading or trailing spaces
=============================================================
*/
function Trim(str)
/*
   PURPOSE: Remove trailing and leading blanks from our string.
   IN: str - the string we want to Trim

   RETVAL: A Trimmed string!
*/
{
   return RTrim(LTrim(str));
}


//to trim spaces in Biz Desc field
function TrimMessage(str)
{
   document.AForm.txtMessage.value = RTrim(LTrim(str));
}

