
var countries = new Array();
var states = new Array();

function validateCybersource(phoneHome, phoneBiz, zip, countryCode) {
	errMsg = "";
	retVal = true;
	//check the business phone number function returns true for success, false for failure

	if (phoneBiz != '' && phoneBiz != null && phoneBiz.value != '') { 	
		retVal = checkPhone(phoneBiz, countryCode);
		if (retVal == false) {
				errMsg += " - Phone (daytime) - appears to be invalid, please check.\n\r";
		}
	}
	
	if (phoneHome != '' && phoneHome != null && phoneHome.value != '') { 
		retVal = checkPhone(phoneHome, countryCode);
		if (retVal == false) {
				errMsg += " - Phone (Evening) - appears to be invalid, please check.\n\r";
		}
	}
	
	//check the zip code base on which country is selected.  Function returns 0 for success, 1 for failure for US, 2 for failure for Canada.
	if ( ( countryCode != null) && (zip != null)) {
		retVal = checkZip(countryCode, zip);
		switch (retVal) {
			case 0  : break;	//everything was peachy
			case 1  : errMsg += " - US Zipcode was invalid.\n\r"; break;
			case 2  : errMsg += " - Canadian postal code was invalid.\n\r"; break;
			default : errMsg += " - Unknown Error.";
		}
	}
	if (errMsg.length > 0) {
		alert ( "Your address had errors.  Please check these fields : \n\r" + errMsg);
		return false;
	} else {
		return true;
	}
	//<a href="javascript:void(validateCybersource(document.forms['formMask'].PhoneHome , document.forms['formMask'].PhoneBusiness, document.forms['formMask'].PostalCode, document.forms['formMask'].country));">click here</a>
}

function ShipBillAddressCheck(form){
	if (form.UseForInvoiceTo.checked  == false && form.UseForShipTo.checked ==false){
		alert("Please select whether this is a Billing or Recipient address");
		return false;
	}
	else
		return true;
	
}
//KWR: added this new function to do additional checking for non-domestic orders and name fields
function moreChecks(form) {
	
	//countryCode = form.country.options[ form.country.selectedIndex].value;
	countryCode = form.country.value
	if (countryCode != "US") {
		city=form.city.value;
		zipCode=form.zipCode.value;
		if (city.length>13) {
			alert("City must be less than 13 characters or less");
			form.city.focus();
			return false;
		}
		if (zipCode.length > 8) {
			alert("Zip/postal code must be less than 8 characters or less");
			form.zipCode.focus();
			return false;
		}
	}
	
	fullName = form.firstName.value + form.lastName.value;;
	if (fullName.length > 25) {
		// i don't think we should check for this one.
		alert("First name and last name cannot exceed 25 characters");
		form.firstName.focus();
		return false;
	}
	
	//added to check email format
	if (form.email1.value !=null && form.email1.value!="")
		return(emailCheck(form.email1.value)); 
	else
		return true;s
			
	
}// end of moreChecks()

function checkPhone(phoneFieldName, country) {
	
	//remove possible common phone delimiters: ._()- +ext#
	//var phoneFieldNumericOnly = phoneFieldName.value.replace(/[^\d]/g,'');		
	var phoneFieldNumericOnly = phoneFieldName.value.replace(/[\.\_\(\)\-\ \+extEXT#]/g,'');
	//question: should we include room for ext, # and under those conditions, shouldn't require and equality of 10
	
	if (phoneFieldNumericOnly == null || !IsNumeric(phoneFieldNumericOnly))
		return false;
	else if (country.value == 'US' || country.value.toLowerCase().indexOf("united states")>-1){
		
		if (phoneFieldNumericOnly.length >=10  && phoneFieldNumericOnly.length<=20 ){
		    //phoneFieldName.value = phoneFieldNumericOnly.substring(0,3) + "-" +
		   	//phoneFieldNumericOnly.substring(3, 6) + "-" + phoneFieldNumericOnly.substring(6);
			return true;	
		}	
		else {
			return false;	
		}
	}
	else{
		if (phoneFieldNumericOnly.length >=8 && phoneFieldNumericOnly.length<=20 )
			return true;
		else
			return false;	
	}	
}

function IsNumeric(sText){
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++) {       
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) {    
         IsNumber = false;
      }
   }
   return IsNumber;   
}





function emailCheck (emailStr) {
/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailPat=/^(.+)@(.+)$/
/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address. 
   These characters include ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* The following string represents the range of characters allowed in a 
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+'
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


/* Finally, let's start trying to figure out if the supplied address is
   valid. */

/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
	alert("Email address seems incorrect (check @ and .'s)")
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
    alert("The username doesn't seem to be valid.")
    return false
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("Destination IP address is invalid!")
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("The domain name doesn't seem to be valid.")
    return false
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding 
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>4) {
   // the address must end in a two letter or three letter word.
   alert("The address must end in a three-letter domain, four-letter domain, or two letter country.")
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This address is missing a hostname!"
   alert(errStr)
   return false
}

// If we've gotten this far, everything's valid!
return true;

}


function checkZip(countryCodeFieldName, zipFieldName) {
		rVal = 0;			//assume that we are correct before going in, as countries other tahn US, CA are automatically correct (no check)
		regexZipUSLong = /^\d{5}-\d{4}$/;
		regexZipUSShort = /^\d{5}$/;

		regexZipCAGreaterThanThree = /^[a-zA-Z]\d[a-zA-Z]/;
		regexZipCASeven = /.*\d[a-zA-Z]\d$/;

		countryCodeField = countryCodeFieldName.value;		
		zipField = zipFieldName.value;
	
		if (countryCodeField == "US") {
			if ( !(zipField.match(regexZipUSLong)) && !(zipField.match(regexZipUSShort)) ) 	{
				rVal = 1;
			}
		} else if (countryCodeField == "CA") {
			if ((zipField.length == 7) && (!zipField.match(regexZipCASeven))){
				rVal = 2;
			}else if ((zipField.length > 3) && (!zipField.match(regexZipCAGreaterThanThree))){
				rVal = 2;
			}
		}

		return rVal;
}


//*********************************************************************
// Function: initializeStatesArray
// Purpose : initialize select fields for state
//
// 
//*********************************************************************
function initializeStatesArray(orderOnlyShipUS){
		//states[states.length] = new jsState('US', '-- Select --', '-- Select --');
		states[states.length] = new jsState('US', '-- Select --', '');
		if (orderOnlyShipUS ==null || orderOnlyShipUS == ''){
			states[states.length] = new jsState('US', 'APO/FPO AA', 'AA');
			states[states.length] = new jsState('US', 'APO/FPO AE', 'AE');
			states[states.length] = new jsState('US', 'APO/FPO AP', 'AP');
		}
		states[states.length] = new jsState('US', 'Alabama', 'AL');
		if (orderOnlyShipUS ==null || orderOnlyShipUS == ''){
			states[states.length] = new jsState('US', 'Alaska', 'AK');
		}
		states[states.length] = new jsState('CA', 'Alberta', 'AB');
		if (orderOnlyShipUS ==null || orderOnlyShipUS == ''){
			states[states.length] = new jsState('US', 'American Samoa', 'AS');
		}
		states[states.length] = new jsState('US', 'Arizona', 'AZ');
		states[states.length] = new jsState('US', 'Arkansas', 'AR');
		states[states.length] = new jsState('CA', 'British Columbia', 'BC');
		states[states.length] = new jsState('US', 'California', 'CA');
		states[states.length] = new jsState('US', 'Colorado', 'CO');
		states[states.length] = new jsState('US', 'Connecticut', 'CT');
		states[states.length] = new jsState('US', 'Delaware', 'DE');
		states[states.length] = new jsState('US', 'District of Columbia', 'DC');
		if (orderOnlyShipUS ==null || orderOnlyShipUS == ''){
		states[states.length] = new jsState('US', 'Fed. St. of Micronesia', 'FM');
		}
		states[states.length] = new jsState('US', 'Florida', 'FL');
		states[states.length] = new jsState('US', 'Georgia', 'GA');
		if (orderOnlyShipUS ==null || orderOnlyShipUS == ''){
			states[states.length] = new jsState('US', 'Guam', 'GU');
			states[states.length] = new jsState('US', 'Hawaii', 'HI');
		}
		states[states.length] = new jsState('US', 'Idaho', 'ID');
		states[states.length] = new jsState('US', 'Illinois', 'IL');
		states[states.length] = new jsState('US', 'Indiana', 'IN');
		states[states.length] = new jsState('US', 'Iowa', 'IA');
		states[states.length] = new jsState('US', 'Kansas', 'KS');
		states[states.length] = new jsState('US', 'Kentucky', 'KY');
		states[states.length] = new jsState('US', 'Louisiana', 'LA');
		states[states.length] = new jsState('US', 'Maine', 'ME');
		states[states.length] = new jsState('CA', 'Manitoba', 'MB');
		if (orderOnlyShipUS ==null || orderOnlyShipUS == ''){
			states[states.length] = new jsState('US', 'Marshall Islands', 'MH');
		}
		states[states.length] = new jsState('US', 'Maryland', 'MD');
		states[states.length] = new jsState('US', 'Massachusetts', 'MA');
		states[states.length] = new jsState('US', 'Michigan', 'MI');
		states[states.length] = new jsState('US', 'Minnesota', 'MN');
		states[states.length] = new jsState('US', 'Mississippi', 'MS');
		states[states.length] = new jsState('US', 'Missouri', 'MO');
		states[states.length] = new jsState('US', 'Montana', 'MT');
		states[states.length] = new jsState('US', 'Nebraska', 'NE');
		states[states.length] = new jsState('US', 'Nevada', 'NV');
		states[states.length] = new jsState('CA', 'New Brunswick', 'NB');
		states[states.length] = new jsState('US', 'New Hampshire', 'NH');
		states[states.length] = new jsState('US', 'New Jersey', 'NJ');
		states[states.length] = new jsState('US', 'New Mexico', 'NM');
		states[states.length] = new jsState('US', 'New York', 'NY');
		states[states.length] = new jsState('CA', 'Newfoundland', 'NF');
		states[states.length] = new jsState('US', 'North Carolina', 'NC');
		states[states.length] = new jsState('US', 'North Dakota', 'ND');
		if (orderOnlyShipUS ==null || orderOnlyShipUS == ''){
			states[states.length] = new jsState('US', 'Northern Mariana Iss.', 'MP');
		}
		states[states.length] = new jsState('CA', 'Northwest Territories', 'NT');
		states[states.length] = new jsState('CA', 'Nova Scotia', 'NS');
		states[states.length] = new jsState('CA', 'Nunavut', 'NU');
		states[states.length] = new jsState('US', 'Ohio', 'OH');
		states[states.length] = new jsState('US', 'Oklahoma', 'OK');
		states[states.length] = new jsState('CA', 'Ontario', 'ON');
		states[states.length] = new jsState('US', 'Oregon', 'OR');
		if (orderOnlyShipUS ==null || orderOnlyShipUS == ''){
			states[states.length] = new jsState('US', 'Palau', 'PW');
		}
		states[states.length] = new jsState('US', 'Pennsylvania', 'PA');
		states[states.length] = new jsState('CA', 'Prince Edward Island', 'PE');
		if (orderOnlyShipUS ==null || orderOnlyShipUS == ''){
			states[states.length] = new jsState('US', 'Puerto Rico', 'PR');
		}
		states[states.length] = new jsState('CA', 'Quebec', 'QC');
		states[states.length] = new jsState('US', 'Rhode Island', 'RI');
		states[states.length] = new jsState('CA', 'Saskatchewan', 'SK');
		states[states.length] = new jsState('US', 'South Carolina', 'SC');
		states[states.length] = new jsState('US', 'South Dakota', 'SD');
		states[states.length] = new jsState('US', 'Tennessee', 'TN');
		states[states.length] = new jsState('US', 'Texas', 'TX');
		states[states.length] = new jsState('US', 'Utah', 'UT');
		states[states.length] = new jsState('US', 'Vermont', 'VT');
		if (orderOnlyShipUS ==null || orderOnlyShipUS == ''){
			states[states.length] = new jsState('US', 'Virgin Islands', 'VI');
		}
		states[states.length] = new jsState('US', 'Virginia', 'VA');
		states[states.length] = new jsState('US', 'Washington', 'WA');
		states[states.length] = new jsState('US', 'West Virginia', 'WV');
		states[states.length] = new jsState('US', 'Wisconsin', 'WI');
		states[states.length] = new jsState('US', 'Wyoming', 'WY');
		states[states.length] = new jsState('CA', 'Yukon', 'YK');
}


function jsState(countryID, name, abbreviation){
	this.countryID = countryID;
	this.name = name;
	this.abbreviation = abbreviation;
	return true;
}

function initializeStates(stateField, countryCodeField, currentState, orderOnlyShipUS){
	
	if (states.length ==0){
			initializeStatesArray(orderOnlyShipUS);
	}
	var countryCode = 'US'
	if(countryCodeField != null){
		countryCode = countryCodeField.options[countryCodeField.selectedIndex].value;
	}
	var i = 0;
	while (i < states.length){
   		if (states[i].countryID == countryCode){			 
	   		
			document.write('<option value="' + states[i].name + '"');			
			if (states[i].name == currentState){
				document.write(' selected');									
			}	
		document.write('>' + states[i].name + '</option>');
		}
	i++;
	}
}

function updateStates(stateField, countryCodeField, currentState){
    countryCode = countryCodeField.options[countryCodeField.selectedIndex].value;
    //countryCode = countryCodeField.options[countryCodeField.selectedIndex].value;
    // remove all states
    for (var i=stateField.options.length-1; i >=0 ; i--){
            stateField.options[i] = null;
    }
    var i = 0;
    var j = 0;
   // stateField.options[j++] = (new Option(" --Select--",""));
    
    while (i < states.length){
		if (states[i].countryID == countryCode){
			stateField.options[j++] = (new Option(states[i].name,states[i].name));
			if (states[i].value == ""){
				stateField.options[j-1].selected = true;
			}
		}
	i++;
	}
	if(stateField.options.length < 2){
		// no known states for the country
		stateField.options[0] = new Option("N/A","N/A",true,true);
	}
	if (stateField.selectedIndex < 2){
		// set the first state as selected, so that it cannot be blank
		stateField.options[0].selected = true;
	}
	if (document.layers){
		for (pause=0; pause < 1000; pause++){}
			//window.history.go(0);
	}
	return true;
}
function windowOpener(windowHeight, windowWidth, windowName, windowUri)
{
    var centerWidth = (window.screen.width - windowWidth) / 2;
    var centerHeight = (window.screen.height - windowHeight) / 2;

    newWindow = window.open(windowUri, windowName, 'resizable=0,width=' + windowWidth + 
        ',height=' + windowHeight + ',left=' + centerWidth + ',top=' + centerHeight+' scrollbars=0,status=0,location=0,toolbar=0,menubar=0,resizable=0');

    newWindow.focus();
    return newWindow.name;
}


function showWarning(country){
	if(country.value !="US"){
		//windowOpener("120","400", "newWin", "/CustomsAndDuties.html");
		alert("Please be aware Recipients are responsible for all applicable customs duties or taxes in that country, which are collected by the carrier upon delivery.");
		//mywindow = window.open ('/CustomsAndDuties.html', 'newWin', 'scrollbars=no,status=no,width=300,height=200')
	    //mywindow.moveTo(0,0);
	}
}
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}


function setUPSAddressFields(form, selectedAddress, cityField, stateField, zipCodeField, countryCodeField){
	//alert("selectedAddress:"+selectedAddress);
	selectedAddress = selectedAddress.split(",");
	//alert("selectedAddress[0]="+selectedAddress[0]+"selectedAddress[1]="+selectedAddress[1]+"selectedAddress[2]="+selectedAddress[2]);	
	countryCode = countryCodeField.options[countryCodeField.selectedIndex].value;
	form.city.value=	selectedAddress[0];
	currentState = selectedAddress[1];
	 var i = 0;
	  if(countryCode=="US"){
		  while (i < stateField.length){
		  		//alert("stateField[i].value:"+stateField[i].value+" AND currentState="+currentState);
				if (stateField[i].value == currentState){
					stateField.options[i].selected = true;
				}
				i++;
			}
		}
		var zipCode = trim(selectedAddress[2]);
		zipCode = ltrim(zipCode);
		zipCode = rtrim(zipCode);
		zipCodeField.value=zipCode;
		return true;
}


//this doesn't seem to be used but left in just in case
function addressInitialize(stateField, countryCodeField, currentState){  
		states.length = 0;
		initializeStatesArray();
		if (stateField.options.length < 1){			
				return updateStates(stateField, countryCodeField, currentState);
		}
		return true;
}

function initializeCountriesArray(){
				
		countries[countries.length] = new jsCountry('Albania', 'AL'); 
		countries[countries.length] = new jsCountry('Algeria', 'DZ');
		countries[countries.length] = new jsCountry('Andorra', 'AD');
		countries[countries.length] = new jsCountry('Angola', 'AO'); 
		countries[countries.length] = new jsCountry('Anguilla', 'AI'); 
		countries[countries.length] = new jsCountry('Antigua &amp; Barbuda', 'AG');
		countries[countries.length] = new jsCountry('Argentina', 'AR'); 
		countries[countries.length] = new jsCountry('Aruba', 'AW');
		countries[countries.length] = new jsCountry('Australia', 'AU'); 
		countries[countries.length] = new jsCountry('Austria', 'AT'); 
		countries[countries.length] = new jsCountry('Bahamas', 'BS');
		countries[countries.length] = new jsCountry('Bahrain', 'BH'); 
		countries[countries.length] = new jsCountry('Bangladesh', 'BD'); 
		countries[countries.length] = new jsCountry('Barbados', 'BB'); 
		countries[countries.length] = new jsCountry('Belarus', 'BY');
		countries[countries.length] = new jsCountry('Belgium', 'BE'); 
		countries[countries.length] = new jsCountry('Belize', 'BZ'); 
		countries[countries.length] = new jsCountry('Benin', 'BJ'); 
		countries[countries.length] = new jsCountry('Bermuda', 'BM'); 
		countries[countries.length] = new jsCountry('Bolivia', 'BO');
		countries[countries.length] = new jsCountry('Botswana', 'BW');
		countries[countries.length] = new jsCountry('Brazil', 'BR');
		countries[countries.length] = new jsCountry('Brunei', 'BN'); 
		countries[countries.length] = new jsCountry('Bulgaria', 'BG');
		countries[countries.length] = new jsCountry('Burkina Faso', 'BF'); 
		countries[countries.length] = new jsCountry('Burundi', 'BI');
		countries[countries.length] = new jsCountry('Cambodia', 'KH');
		countries[countries.length] = new jsCountry('Cameroon', 'CM');
		countries[countries.length] = new jsCountry('Canada', 'CA'); 
		countries[countries.length] = new jsCountry('Cape Verde', 'CV');
		countries[countries.length] = new jsCountry('Cayman Islands', 'KY'); 
		countries[countries.length] = new jsCountry('Central African Republic', 'CF');
		countries[countries.length] = new jsCountry('Chad', 'TD'); 
		countries[countries.length] = new jsCountry('Chile', 'CL'); 
		countries[countries.length] = new jsCountry('China, Peoples Republic of', 'CN'); 
		countries[countries.length] = new jsCountry('Colombia', 'CO');
		countries[countries.length] = new jsCountry('Congo', 'CG'); 
		countries[countries.length] = new jsCountry('Cook Islands', 'CK');
		countries[countries.length] = new jsCountry('Costa Rica', 'CR');
		countries[countries.length] = new jsCountry("Cote d'Ivoire", 'CI');
		countries[countries.length] = new jsCountry('Croatia', 'HR');
		countries[countries.length] = new jsCountry('Cuba', 'CU'); 
		countries[countries.length] = new jsCountry('Cyprus', 'CY'); 
		countries[countries.length] = new jsCountry('Czech Republic', 'CZ'); 
		countries[countries.length] = new jsCountry('Denmark', 'DK'); 
		countries[countries.length] = new jsCountry('Djibouti', 'DJ'); 
		countries[countries.length] = new jsCountry('Dominica', 'DM'); 
		countries[countries.length] = new jsCountry('Dominican Republic', 'DO');
		countries[countries.length] = new jsCountry('Ecuador', 'EC'); 
		countries[countries.length] = new jsCountry('Egypt', 'EG');
		countries[countries.length] = new jsCountry('El Salvador', 'SV'); 
		countries[countries.length] = new jsCountry('Equatorial Guinea', 'GQ'); 
		countries[countries.length] = new jsCountry('Eritrea', 'ER'); 
		countries[countries.length] = new jsCountry('Estonia', 'EE'); 
		countries[countries.length] = new jsCountry('Ethiopia', 'ET');
		countries[countries.length] = new jsCountry('Faroe Islands', 'FO');
		countries[countries.length] = new jsCountry('Fiji', 'FJ'); 
		countries[countries.length] = new jsCountry('Finland', 'FI');
		countries[countries.length] = new jsCountry('France', 'FR'); 
		countries[countries.length] = new jsCountry('French Guiana', 'GF'); 
		countries[countries.length] = new jsCountry('French Polynesia', 'PF');
		countries[countries.length] = new jsCountry('Gabon', 'GA'); 
		countries[countries.length] = new jsCountry('Gambia', 'GM'); 
		countries[countries.length] = new jsCountry('Georgia', 'GE'); 
		countries[countries.length] = new jsCountry('Germany', 'DE');
		countries[countries.length] = new jsCountry('Ghana', 'GH'); 
		countries[countries.length] = new jsCountry('Gibraltar', 'GI'); 
		countries[countries.length] = new jsCountry('Greece', 'GR');
		countries[countries.length] = new jsCountry('Greenland', 'GL'); 
		countries[countries.length] = new jsCountry('Grenada', 'GD');
		countries[countries.length] = new jsCountry('Guadeloupe', 'GP'); 
		countries[countries.length] = new jsCountry('Guatemala', 'GT'); 
		countries[countries.length] = new jsCountry('Guinea', 'GN'); 
		countries[countries.length] = new jsCountry('Guinea-Bissau', 'GW'); 
		countries[countries.length] = new jsCountry('Guyana', 'GY'); 
		countries[countries.length] = new jsCountry('Haiti', 'HT'); 
		countries[countries.length] = new jsCountry('Honduras', 'HN'); 
		countries[countries.length] = new jsCountry('Hong Kong', 'HK'); 
		countries[countries.length] = new jsCountry('Hungary', 'HU');
		countries[countries.length] = new jsCountry('Iceland', 'IS'); 
		countries[countries.length] = new jsCountry('India', 'IN');
		countries[countries.length] = new jsCountry('Ireland, Republic of', 'IE'); 
		countries[countries.length] = new jsCountry('Israel', 'IL'); 
		countries[countries.length] = new jsCountry('Italy', 'IT');
		countries[countries.length] = new jsCountry('Jamaica', 'JM'); 
		countries[countries.length] = new jsCountry('Japan', 'JP');
		countries[countries.length] = new jsCountry('Jordan', 'JO');
		countries[countries.length] = new jsCountry('Kazakhstan', 'KZ');
		countries[countries.length] = new jsCountry('Kenya', 'KE');
		countries[countries.length] = new jsCountry('Kiribati', 'KI');
		countries[countries.length] = new jsCountry('Korea, South', 'KR');
		countries[countries.length] = new jsCountry('Kuwait', 'KW');
		countries[countries.length] = new jsCountry('Kyrgyzstan', 'KG');
		countries[countries.length] = new jsCountry('Laos', 'LA');
		countries[countries.length] = new jsCountry('Latvia', 'LV');
		countries[countries.length] = new jsCountry('Lebanon', 'LB');
		countries[countries.length] = new jsCountry('Lesotho', 'LS');
		countries[countries.length] = new jsCountry('Liberia', 'LR');
		countries[countries.length] = new jsCountry('Liechtenstein', 'LI');
		countries[countries.length] = new jsCountry('Lithuania', 'LT');
		countries[countries.length] = new jsCountry('Luxembourg', 'LU');
		countries[countries.length] = new jsCountry('Macau', 'MO');
		countries[countries.length] = new jsCountry('Macedonia', 'MK');
		countries[countries.length] = new jsCountry('Madagascar', 'MG');
		countries[countries.length] = new jsCountry('Malawi', 'MW');
		countries[countries.length] = new jsCountry('Malaysia', 'MY');
		countries[countries.length] = new jsCountry('Maldives', 'MV');
		countries[countries.length] = new jsCountry('Mali', 'ML');
		countries[countries.length] = new jsCountry('Malta', 'MT');
		countries[countries.length] = new jsCountry('Martinique', 'MQ');
		countries[countries.length] = new jsCountry('Mauritania', 'MR');
		countries[countries.length] = new jsCountry('Mauritius', 'MU');
		countries[countries.length] = new jsCountry('Mexico', 'MX');
		countries[countries.length] = new jsCountry('Moldova', 'FM');
		countries[countries.length] = new jsCountry('Monaco', 'MC');
		countries[countries.length] = new jsCountry('Montserrat', 'MS');
		countries[countries.length] = new jsCountry('Morocco', 'MA');
		countries[countries.length] = new jsCountry('Mozambique', 'MZ');
		countries[countries.length] = new jsCountry('Myanmar', 'MM');
		countries[countries.length] = new jsCountry('Namibia', 'NA');
		countries[countries.length] = new jsCountry('Nepal', 'NP');
		countries[countries.length] = new jsCountry('Netherlands (Holland)', 'NL');
		countries[countries.length] = new jsCountry('Netherlands Antilles', 'AN');
		countries[countries.length] = new jsCountry('New Caledonia', 'NC');
		countries[countries.length] = new jsCountry('New Zealand', 'NZ');
		countries[countries.length] = new jsCountry('Nicaragua', 'NI');
		countries[countries.length] = new jsCountry('Niger', 'NE');
		countries[countries.length] = new jsCountry('Norfolk Island', 'NF');
		countries[countries.length] = new jsCountry('Norway', 'NO');
		countries[countries.length] = new jsCountry('Oman', 'OM');
		countries[countries.length] = new jsCountry('Pakistan', 'PK');
		countries[countries.length] = new jsCountry('Panama', 'PA');
		countries[countries.length] = new jsCountry('Papua New Guinea', 'PG');
		countries[countries.length] = new jsCountry('Paraguay', 'PY');
		countries[countries.length] = new jsCountry('Peru', 'PE');
		countries[countries.length] = new jsCountry('Philippines', 'PH');
		countries[countries.length] = new jsCountry('Poland', 'PL');
		countries[countries.length] = new jsCountry('Portugal', 'PT');
		countries[countries.length] = new jsCountry('Qatar', 'QA');
		countries[countries.length] = new jsCountry('Reunion', 'RE');
		countries[countries.length] = new jsCountry('Romania', 'RO');
		countries[countries.length] = new jsCountry('Russia', 'RU');
		countries[countries.length] = new jsCountry('Rwanda', 'RW');
		countries[countries.length] = new jsCountry('Saint Kitts &amp; Nevis', 'KN');
		countries[countries.length] = new jsCountry('Saint Lucia', 'LC');
		countries[countries.length] = new jsCountry('Saint Vincent &amp; the Grenadines', 'VC');
		countries[countries.length] = new jsCountry('Saudi Arabia', 'SA');
		countries[countries.length] = new jsCountry('Senegal', 'SN');
		countries[countries.length] = new jsCountry('Seychelles', 'SC');
		countries[countries.length] = new jsCountry('Sierra Leone', 'SL');
		countries[countries.length] = new jsCountry('Singapore', 'SG');
		countries[countries.length] = new jsCountry('Slovakia', 'SK');
		countries[countries.length] = new jsCountry('Slovenia', 'SI');
		countries[countries.length] = new jsCountry('Solomon Islands', 'SB');
		countries[countries.length] = new jsCountry('South Africa', 'ZA');
		countries[countries.length] = new jsCountry('Spain', 'ES');
		countries[countries.length] = new jsCountry('Sri Lanka', 'LK');
		countries[countries.length] = new jsCountry('Sudan', 'SD');
		countries[countries.length] = new jsCountry('Suriname', 'SR');
		countries[countries.length] = new jsCountry('Swaziland', 'SZ');
		countries[countries.length] = new jsCountry('Sweden', 'SE');
		countries[countries.length] = new jsCountry('Switzerland', 'CH');
		countries[countries.length] = new jsCountry('Syria', 'SY');
		countries[countries.length] = new jsCountry('Taiwan', 'TW');
		countries[countries.length] = new jsCountry('Tajikistan', 'TJ');
		countries[countries.length] = new jsCountry('Tanzania', 'TZ');
		countries[countries.length] = new jsCountry('Thailand', 'TH');
		countries[countries.length] = new jsCountry('Togo', 'TG');
		countries[countries.length] = new jsCountry('Tonga', 'TO');
		countries[countries.length] = new jsCountry('Trinidad &amp; Tobago', 'TT');
		countries[countries.length] = new jsCountry('Tunisia', 'TN');
		countries[countries.length] = new jsCountry('Turkey', 'TR');
		countries[countries.length] = new jsCountry('Turks &amp; Caicos Islands', 'TM');
		countries[countries.length] = new jsCountry('Tuvalu', 'TV');
		countries[countries.length] = new jsCountry('Uganda', 'UG');
		countries[countries.length] = new jsCountry('Ukraine', 'UA');
		countries[countries.length] = new jsCountry('United Arab Emirates', 'AE');
		countries[countries.length] = new jsCountry('United Kingdom', 'GB');
		countries[countries.length] = new jsCountry('United States of America', 'US');
		countries[countries.length] = new jsCountry('Uruguay', 'UY');
		countries[countries.length] = new jsCountry('Uzbekistan', 'UZ');
		countries[countries.length] = new jsCountry('Vanuatu', 'VU');
		countries[countries.length] = new jsCountry('Venezuela', 'VE');
		countries[countries.length] = new jsCountry('Vietnam', 'VN');
		countries[countries.length] = new jsCountry('Virgin Islands (British)', 'VG');
		countries[countries.length] = new jsCountry('Wake Island', 'VI');
		countries[countries.length] = new jsCountry('Wallis &amp; Futuna Islands', 'WF');
		countries[countries.length] = new jsCountry('Western Samoa', 'EH');
		countries[countries.length] = new jsCountry('Yemen, Republic of', 'YE');
		countries[countries.length] = new jsCountry('Zaire', 'YU');
		countries[countries.length] = new jsCountry('Zambia', 'ZM');
		countries[countries.length] = new jsCountry('Zimbabwe', 'ZW');
}

function setCountry(country, state, form ){

	for(var i=0; i < form.country.length; i++)
	{
		if(form.country[i].value == country)		
			form.country[i].selected=true;		
	}
	//note: since this was inconsistent in the past, need to check both forms
	if(country != "US" &&  country.toLowerCase().indexOf("united states") < 0 )	
		updateStates(form.state, form.country,'');	
	for(var i=0; i < form.state.length; i++)
	{
		if(form.state[i].value == state)		
			form.state[i].selected=true;		
	}
}



function initializeCountries(countryCodeField, currentCountry){

	if (countries.length ==0){
		initializeCountriesArray();
	}
	if (currentCountry == '')
		currentCountry = 'US';
	var i = 0;
    while (i < countries.length){
		document.write('<option value="' + countries[i].abbreviation + '"');
		if (countries[i].name.indexOf(currentCountry)>-1 || countries[i].abbreviation == currentCountry){
			document.write(' selected ');
		}
		
		document.write('>' + countries[i].name + '</option>');
		i++;
	}
}

function jsCountry(name, abbreviation) {
	this.name = name;
	this.abbreviation = abbreviation;
	return true;
}

function stateCode(stateString){
	if (stateString == "Alabama") return "AL";
	else if (stateString =="Alaska" ) return "AK";
	else if (stateString =="Arizona" ) return "AZ";
	else if (stateString =="Arkansas" ) return "AR";
	else if (stateString =="California" ) return "CA";
	else if (stateString =="Colorado" ) return "CO";
	else if (stateString =="Connecticut" ) return "CT";
	else if (stateString =="Delaware" ) return "DE";
	else if (stateString =="District of Columbia" ) return "DC";
	else if (stateString =="Florida" ) return "FL";
	else if (stateString =="Georgia" ) return "GA";
	else if (stateString =="Hawaii" ) return "HI";
	else if (stateString =="Idaho" ) return "ID";
	else if (stateString =="Illinois" ) return "IL";
	else if (stateString =="Indiana" ) return "IN";
	else if (stateString =="Iowa" ) return "IA";
	else if (stateString =="Kansas" ) return "KS";
	else if (stateString =="Kentucky" ) return "KY";
	else if (stateString =="Louisiana" ) return "LA";
	else if (stateString =="Maine" ) return "ME";
	else if (stateString =="Maryland" ) return "MD";
	else if (stateString =="Massachusetts" ) return "MA";
	else if (stateString =="Michigan" ) return "MI";
	else if (stateString =="Minnesota" ) return "MN";
	else if (stateString =="Mississippi" ) return "MS";
	else if (stateString =="Missouri" ) return "MO";
	else if (stateString =="Montana" ) return "MT";
	else if (stateString =="Nebraska" ) return "NE";
	else if (stateString =="Nevada" ) return "NV";
	else if (stateString =="New Hampshire" ) return "NH";
	else if (stateString =="New Jersey" ) return "NJ";
	else if (stateString =="New Mexico" ) return "NM";
	else if (stateString =="New York" ) return "NY";
	else if (stateString =="North Carolina" ) return "NC";
	else if (stateString =="North Dakota" ) return "ND";
	else if (stateString =="Ohio" ) return "OH";
	else if (stateString =="Oklahoma" ) return "OK";
	else if (stateString =="Oregon" ) return "OR";
	else if (stateString =="Pennsylvania" ) return "PA";
	else if (stateString =="Rhode Island" ) return "RI";
	else if (stateString =="South Carolina" ) return "SC";
	else if (stateString =="South Dakota" ) return "SD";
	else if (stateString =="Tennessee" ) return "TN";
	else if (stateString =="Texas" ) return "TX";
	else if (stateString =="Utah" ) return "UT";
	else if (stateString =="Vermont" ) return "VT";
	else if (stateString =="Virginia" ) return "VA";
	else if (stateString =="Washington" ) return "WA";
	else if (stateString =="West Virginia" ) return "WV";
	else if (stateString =="Wisconsin" ) return "WI";
	else if (stateString =="Wyoming" ) return "WY";


}