// Support Script (642)
function PopulateWith(TheList, Items)
{
  var iCount = TheList.getCount();
  for (var i=0; i<iCount; i++)
    if (TheList.elementID)
      TheList.elementID.options[0] = null;
    else
      alert("bad or wrong DE for state population");

  i = 0;
  iCount = Items.length;
 	for (i=0; i<iCount; i++)
    TheList.addOption(Items[i], i, "");

  TheList.setSelectedByPosition(0);
}
// Support Script (776)
function AddToValidateArray(strElementName)
{
    var strName = strElementName

    if (!document.ValidateArray) 
    {
        document.ValidateArray = new Array
    }

    document.ValidateArray[document.ValidateArray.length] = strName
}

// Support Script (800)
function StripChars(theFilter,theString)
{
	var strOut,i,curChar

	strOut = ""
	for (i=0;i < theString.length; i++)
	{		
		curChar = theString.charAt(i)
		if (theFilter.indexOf(curChar) < 0)	// if it's not in the filter, send it thru
			strOut += curChar		
	}	
	return strOut
}

function AllInRange(x,y,theString)
{
	var i, curChar
	
	for (i=0; i < theString.length; i++)
	{
		curChar = theString.charAt(i)
		if (curChar < x || curChar > y) //the char is not in range
			return false
	}
	return true
}


function reformat (s)
{
    var arg;
    var sPos = 0;
    var resultString = "";

    for (var i = 1; i < reformat.arguments.length; i++) {
       arg = reformat.arguments[i];
       if (i % 2 == 1) 
           resultString += arg;
       else 
       {
           resultString += s.substring(sPos, sPos + arg);
           sPos += arg;
       }
    }
    return resultString;
}

function Trim(theString)
{
 var i,firstNonWhite

 if (StripChars(" \n\r\t",theString).length == 0 ) return ""

	i = -1
	while (1)
	{
		i++
		if (theString.charAt(i) != " ")
			break	
	}
	firstNonWhite = i
	//Count the spaces at the end
	i = theString.length
	while (1)
	{
		i--
		if (theString.charAt(i) != " ")
			break	
	}	

	return theString.substring(firstNonWhite,i + 1)

}
// Support Script (661)

function ValidateZipCode()
{
	var msg = ""
	var theString = this.getText()
 var msgInvalid = "Please enter a valid Zip Code.\nSuch as 92008 or 92008-1337"

	var theLen = StripChars(" \n\t\r",theString).length
	if (theLen == 0)	
		if (!this.Required) return ""		
		else return "Required field.  " + msgInvalid

	theString = StripChars("- \n\r",theString)		

	if (!AllInRange("0","9",theString))
	{
		msg = msgInvalid
	}
	else if (theString.length != 5 && theString.length != 9)
	{
		msg = msgInvalid
	}

	if (msg == "")
	{
		if (theString.length == 9)		
			this.setText(reformat(theString,"",5,"-",4))
		else
   this.setText(theString)
   
	}
	return msg	
}
// Support Script (650)
function ValidateEMail()
{
   var msg = "";
   var val = this.getText();
   var msgInvalid = "Please enter a valid e-mail address\n(a valid e-mail address contains the @ character)";

  	var theLen = StripChars(" ",val).length
	  if (theLen == 0)	
		  if (!this.Required) return ""		
		  else return "Required field.  " + msgInvalid

   if (val.indexOf("@",0) < 0) 
   {
      msg = msgInvalid 
   }
   return msg;
}

// Support Script (659)
function ValidateUSPhone()
{
	var msg = ""
	var theString = this.getText()
 var msgInvalid = "Please enter a valid U.S. phone number.\nSuch as (760) 555-1212"

	var theLen = StripChars(" \n\t\r",theString).length
	if (theLen == 0)	
		if (!this.Required) return ""		
		else return "Required field.  " + msgInvalid

	theString = StripChars("*() -./_\n\r",theString)		

	if (!AllInRange("0","9",theString))
	{
		msg = msgInvalid
	}
	else if (theString.length == 11)
	{
		 if (theString.charAt(0) != "1")	
			msg = msgInvalid
	}
	else if (theString.length != 10 && theString.length != 7)
	{
		msg = msgInvalid
	}

	if (msg == "")
	{
		if (theString.length == 10)
			this.setText(reformat(theString,"(",3,") ",3,"-",4))
		else if (theString.length == 7)
			this.setText(reformat(theString,"",3,"-",4))
		else //len == 11
			this.setText(reformat(theString,"",1,"(",3,") ",3,"-",4))
	}
	return msg		
}


function document_onLoad() {
var i = 0;
s = new Array(51);
s[i++] = "--"
s[i++] = "AK"
s[i++] = "AL"
s[i++] = "AZ"
s[i++] = "AR"
s[i++] = "CA"
s[i++] = "CO"
s[i++] = "CT"
s[i++] = "DE"
s[i++] = "FL"
s[i++] = "GA"
s[i++] = "HI"
s[i++] = "ID"
s[i++] = "IL"
s[i++] = "IN"
s[i++] = "IA"
s[i++] = "KS"
s[i++] = "KY"
s[i++] = "LA"
s[i++] = "ME"
s[i++] = "MD"
s[i++] = "MA"
s[i++] = "MI"
s[i++] = "MN"
s[i++] = "MS"
s[i++] = "MO"
s[i++] = "MT"
s[i++] = "NE"
s[i++] = "NV"
s[i++] = "NH"
s[i++] = "NJ"
s[i++] = "NM"
s[i++] = "NY"
s[i++] = "NC"
s[i++] = "ND"
s[i++] = "OH"
s[i++] = "OK"
s[i++] = "OR"
s[i++] = "PA"
s[i++] = "RI"
s[i++] = "SC"
s[i++] = "SD"
s[i++] = "TN"
s[i++] = "TX"
s[i++] = "UT"
s[i++] = "VT"
s[i++] = "VA"
s[i++] = "WA"
s[i++] = "WV"
s[i++] = "WI"
s[i++] = "WY"

PopulateWith(State, s);
ZipCode.Validate = ValidateZipCode;
ZipCode.Required = Number("1");
AddToValidateArray("ZipCode")
EMail.Validate = ValidateEMail;
EMail.Required = Number("1");
AddToValidateArray("EMail")
telephone.Validate = ValidateUSPhone;
telephone.Required = Number("1");
AddToValidateArray("telephone")
 }


