function showanother(flap) {
//show next
  document.getElementById(flap).style.display= '';
}

/*var thinky;

window.onload = startrup;

function startrup() {
 for (var i=1; i< 5; i++) {
  thinky = "meet"+i;
 document.getElementById(thinky).style.display= 'none';
 }
}
function showanother(flap) {
//show next
  var flapPlus = "meet"+(flap+1);
  document.getElementById(flapPlus).style.display= '';
//hide prior
 document.getElementById("meet_add_"+flap).style.visibility= 'hidden';
 document.getElementById("meet_add_"+flap).style.display= 'none';
}
*/
function validateForm(f) {
 var today_dt = new Date();
 f = eval(f);
with(f) { 
  if (Empty(fname,"First Name is required","text, numbers, and other",1,30)) return false; 
  if (Empty(lname,"Last Name is required","text, numbers, and other",1,30)) return false; 
  if (Empty(fname2,"Please enter a title","text, numbers, and other",1,30)) return false; 
  if (Empty(hphone,"Please enter your phone number","numbers and other",10,12)) return false; 
  if (Empty(email,"Email Address is required","text, numbers, and other",6,256)) return false; 
  if (!ValidEmail(email)) return false;
 if (!(travel_agent[0].checked || travel_agent[1].checked)) {
	alert("Please specify if you are a travel agent or not");
	return false;
 } 
 if (travel_agent[0].checked) {
     if (Empty(agency_num,"Please enter your agency ARC number","numbers",7,7)) return false; 
 }
 if (Empty(company_name,"Please enter your company name","text, numbers, and other",1,30)) return false; 
  if (Empty(address1,"Please enter your address","text, numbers, and other",1,38)) return false;
  if (Empty(city,"Please enter your city","text, numbers, and other",1,30)) return false;
  if (state.value == null || state.value == "" ) { alert("Please enter your state/province");return false }
  if (Empty(zip,"Please enter your zip/postal code","text, numbers, and other",5,12)) return false;
  if (Empty(meeting_name,"Please enter a meeting name","text, numbers, and other",1,30)) return false;
  if (meeting1_FM_MM.selectedIndex==0) {alert("Please enter meeting start date MONTH"); meeting1_FM_MM.focus();return false;}
  if (meeting1_FM_DD.selectedIndex==0) {alert("Please enter meeting start date DAY"); meeting1_FM_DD.focus();return false;}
  if (meeting1_FM_YY.selectedIndex==0) {alert("Please enter meeting start date YEAR"); meeting1_FM_YY.focus();return false;}
  if (meeting1_TO_MM.selectedIndex==0) {alert("Please enter meeting end date MONTH"); meeting1_TO_MM.focus();return false;}
  if (meeting1_TO_DD.selectedIndex==0) {alert("Please enter meeting end date DAY"); meeting1_TO_DD.focus();return false;}
  if (meeting1_TO_YY.selectedIndex==0) {alert("Please enter meeting end date YEAR"); meeting1_TO_YY.focus();return false;}

//build 2 dates, check start is older than end

 var meeting1_start_dt = new Date(meeting1_FM_YY[meeting1_FM_YY.selectedIndex].value, meeting1_FM_MM[meeting1_FM_MM.selectedIndex].value-1, meeting1_FM_DD[meeting1_FM_DD.selectedIndex].value);
 var meeting1_end_dt = new Date(meeting1_TO_YY[meeting1_TO_YY.selectedIndex].value, meeting1_TO_MM[meeting1_TO_MM.selectedIndex].value-1, meeting1_TO_DD[meeting1_TO_DD.selectedIndex].value);
 if (meeting1_end_dt < meeting1_start_dt) {alert("Meeting end date must be later than meeting start date");meeting1_FM_MM.focus();return false;}
 if (meeting1_start_dt < today_dt) {alert("Please enter only future dates.");meeting1_FM_MM.focus();return false;}
 if (dest_city1.value=="") {alert("Please enter the destination airport");dest_city1.focus();return false; }
 if (meeting1_attend.value==0) {alert("Please enter the estimated attendance");	meeting1_attend.focus();return false; }
  if (Empty(meeting1_attend,"Please enter the estimated attendance","numbers",1,4)) return false; 
  var multiMeeting = "N";
/*
//meeting 2
if (meeting2_FM_YY.selectedIndex != 0 ||  meeting2_FM_MM.selectedIndex != 0 || meeting2_FM_DD.selectedIndex != 0 || meeting2_TO_YY.selectedIndex != 0 || meeting2_TO_MM.selectedIndex != 0 || meeting2_TO_DD.selectedIndex != 0) {
  multiMeeting = "Y";
  if (meeting2_FM_MM.selectedIndex==0) {alert("Please enter meeting start date MONTH"); meeting2_FM_MM.focus();return false;}
  if (meeting2_FM_DD.selectedIndex==0) {alert("Please enter meeting start date DAY"); meeting2_FM_DD.focus();return false;}
  if (meeting2_FM_YY.selectedIndex==0) {alert("Please enter meeting start date YEAR"); meeting2_FM_YY.focus();return false;}
  if (meeting2_TO_MM.selectedIndex==0) {alert("Please enter meeting end date MONTH"); meeting2_TO_MM.focus();return false;}
  if (meeting2_TO_DD.selectedIndex==0) {alert("Please enter meeting end date DAY"); meeting2_TO_DD.focus();return false;}
  if (meeting2_TO_YY.selectedIndex==0) {alert("Please enter meeting end date YEAR"); meeting2_TO_YY.focus();return false;}
  if (dest_city2.value=="") {alert("Please enter the destination airport");dest_city2.focus();return false; }
  if (meeting2_attend.value==0) {alert("Please enter the estimated attendance");meeting2_attend.focus();return false; }
  var meeting2_start_dt = new Date(meeting2_FM_YY[meeting2_FM_YY.selectedIndex].value, meeting2_FM_MM[meeting2_FM_MM.selectedIndex].value-1, meeting2_FM_DD[meeting2_FM_DD.selectedIndex].value);
  var meeting2_end_dt = new Date(meeting2_TO_YY[meeting2_TO_YY.selectedIndex].value, meeting2_TO_MM[meeting2_TO_MM.selectedIndex].value-1, meeting2_TO_DD[meeting2_TO_DD.selectedIndex].value);
  if (meeting2_end_dt < meeting2_start_dt) {alert("Meeting end date must be later than meeting start date");meeting2_FM_MM.focus();return false;}
  if (meeting2_start_dt < today_dt) {alert("Although we're working on it, United cannot yet deliver you to meetings in the past. Please enter only future meetings.");meeting2_FM_MM.focus();return false;}
}
//meeting3
if (meeting3_FM_YY.selectedIndex != 0 ||  meeting3_FM_MM.selectedIndex != 0 || meeting3_FM_DD.selectedIndex != 0 || meeting3_TO_YY.selectedIndex != 0 || meeting3_TO_MM.selectedIndex != 0 || meeting3_TO_DD.selectedIndex != 0) {
  multiMeeting = "Y";
  if (meeting3_FM_MM.selectedIndex==0) {alert("Please enter meeting start date MONTH"); meeting3_FM_MM.focus();return false;}
  if (meeting3_FM_DD.selectedIndex==0) {alert("Please enter meeting start date DAY"); meeting3_FM_DD.focus();return false;}
  if (meeting3_FM_YY.selectedIndex==0) {alert("Please enter meeting start date YEAR"); meeting3_FM_YY.focus();return false;}
  if (meeting3_TO_MM.selectedIndex==0) {alert("Please enter meeting end date MONTH"); meeting3_TO_MM.focus();return false;}
  if (meeting3_TO_DD.selectedIndex==0) {alert("Please enter meeting end date DAY"); meeting3_TO_DD.focus();return false;}
  if (meeting3_TO_YY.selectedIndex==0) {alert("Please enter meeting end date YEAR"); meeting3_TO_YY.focus();return false;}
  if (dest_city3.value=="") {alert("Please enter the destination airport");dest_city3.focus();return false; }
  if (meeting3_attend.value==0) {alert("Please enter the estimated attendance");meeting3_attend.focus();return false; }
  var meeting3_start_dt = new Date(meeting3_FM_YY[meeting3_FM_YY.selectedIndex].value, meeting3_FM_MM[meeting3_FM_MM.selectedIndex].value-1, meeting3_FM_DD[meeting3_FM_DD.selectedIndex].value);
  var meeting3_end_dt = new Date(meeting3_TO_YY[meeting3_TO_YY.selectedIndex].value, meeting3_TO_MM[meeting3_TO_MM.selectedIndex].value-1, meeting3_TO_DD[meeting3_TO_DD.selectedIndex].value);
  if (meeting3_end_dt < meeting3_start_dt) {alert("Meeting end date must be later than meeting start date");meeting3_FM_MM.focus();return false;}
  if (meeting3_start_dt < today_dt) {alert("Although we're working on it, United cannot yet deliver you to meetings in the past. Please enter only future meetings.");meeting3_FM_MM.focus();return false;}
}

//meeting4
if (meeting4_FM_YY.selectedIndex != 0 ||  meeting4_FM_MM.selectedIndex != 0 || meeting4_FM_DD.selectedIndex != 0 || meeting4_TO_YY.selectedIndex != 0 || meeting4_TO_MM.selectedIndex != 0 || meeting4_TO_DD.selectedIndex != 0) {
  multiMeeting = "Y";
  if (meeting4_FM_MM.selectedIndex==0) {alert("Please enter meeting start date MONTH"); meeting4_FM_MM.focus();return false;}
  if (meeting4_FM_DD.selectedIndex==0) {alert("Please enter meeting start date DAY"); meeting4_FM_DD.focus();return false;}
  if (meeting4_FM_YY.selectedIndex==0) {alert("Please enter meeting start date YEAR"); meeting4_FM_YY.focus();return false;}
  if (meeting4_TO_MM.selectedIndex==0) {alert("Please enter meeting end date MONTH"); meeting4_TO_MM.focus();return false;}
  if (meeting4_TO_DD.selectedIndex==0) {alert("Please enter meeting end date DAY"); meeting4_TO_DD.focus();return false;}
  if (meeting4_TO_YY.selectedIndex==0) {alert("Please enter meeting end date YEAR"); meeting4_TO_YY.focus();return false;}
  if (dest_city4.value=="") {alert("Please enter the destination airport");dest_city4.focus();return false; }
  if (meeting4_attend.value==0) {alert("Please enter the estimated attendance");meeting4_attend.focus();return false; }
  var meeting4_start_dt = new Date(meeting4_FM_YY[meeting4_FM_YY.selectedIndex].value, meeting4_FM_MM[meeting4_FM_MM.selectedIndex].value-1, meeting4_FM_DD[meeting4_FM_DD.selectedIndex].value);
  var meeting4_end_dt = new Date(meeting4_TO_YY[meeting4_TO_YY.selectedIndex].value, meeting4_TO_MM[meeting4_TO_MM.selectedIndex].value-1, meeting4_TO_DD[meeting4_TO_DD.selectedIndex].value);
  if (meeting4_end_dt < meeting4_start_dt) {alert("Meeting end date must be later than meeting start date");meeting4_FM_MM.focus();return false;}
  if (meeting4_start_dt < today_dt) {alert("Although we're working on it, United cannot yet deliver you to meetings in the past. Please enter only future meetings.");meeting4_FM_MM.focus();return false;}
}
//meeting5
if (meeting5_FM_YY.selectedIndex != 0 ||  meeting5_FM_MM.selectedIndex != 0 || meeting5_FM_DD.selectedIndex != 0 || meeting5_TO_YY.selectedIndex != 0 || meeting5_TO_MM.selectedIndex != 0 || meeting5_TO_DD.selectedIndex != 0) {
  multiMeeting = "Y";
  if (meeting5_FM_MM.selectedIndex==0) {alert("Please enter meeting start date MONTH"); meeting5_FM_MM.focus();return false;}
  if (meeting5_FM_DD.selectedIndex==0) {alert("Please enter meeting start date DAY"); meeting5_FM_DD.focus();return false;}
  if (meeting5_FM_YY.selectedIndex==0) {alert("Please enter meeting start date YEAR"); meeting5_FM_YY.focus();return false;}
  if (meeting5_TO_MM.selectedIndex==0) {alert("Please enter meeting end date MONTH"); meeting5_TO_MM.focus();return false;}
  if (meeting5_TO_DD.selectedIndex==0) {alert("Please enter meeting end date DAY"); meeting5_TO_DD.focus();return false;}
  if (meeting5_TO_YY.selectedIndex==0) {alert("Please enter meeting end date YEAR"); meeting5_TO_YY.focus();return false;}
  if (dest_city5.value=="") {alert("Please enter the destination airport");dest_city5.focus();return false; }
  if (meeting5_attend.value==0) {alert("Please enter the estimated attendance");meeting5_attend.focus();return false; }
  var meeting5_start_dt = new Date(meeting5_FM_YY[meeting5_FM_YY.selectedIndex].value, meeting5_FM_MM[meeting5_FM_MM.selectedIndex].value-1, meeting5_FM_DD[meeting5_FM_DD.selectedIndex].value);
  var meeting5_end_dt = new Date(meeting5_TO_YY[meeting5_TO_YY.selectedIndex].value, meeting5_TO_MM[meeting5_TO_MM.selectedIndex].value-1, meeting5_TO_DD[meeting5_TO_DD.selectedIndex].value);
  if (meeting5_end_dt < meeting5_start_dt) {alert("Meeting end date must be later than meeting start date");meeting5_FM_MM.focus();return false;}
  if (meeting5_start_dt < today_dt) {alert("Although we're working on it, United cannot yet deliver you to meetings in the past. Please enter only future meetings.");meeting5_FM_MM.focus();return false;}
}
//test to see if multiple cities or single city
if (multiMeeting == "Y" && (meeting1_attend.value*1 + meeting2_attend.value*1 + meeting3_attend.value*1 + meeting4_attend.value*1 + meeting5_attend.value*1) < 125) {
  alert("In order to qualify for MeetingsPlus pricing, your total attendance of all meetings must be 125 or more. Please reenter the number of attendees");
  meeting1_attend.focus();
  return false; 
} else --recombine with next statement if multiple meetings reimplemented.
*/
if (meeting1_attend.value<25) {
 alert("In order to qualify for MeetingsPlus pricing, your attendance must be 25 or more. Please reenter the number of attendees");
 meeting1_attend.focus();
 return false; 
}

 if (!(version[0].checked || version[1].checked)) {
	alert("Please choose an agreement type");
	return false;
 }
 //Build up the URL for coReg string submit
 // JavaScript Document
 // assemble dynamic destination 
 var urlString = "http://www.unitedoffers.com/el/coReg.p_Process?";
// if () {f.hphone.value+= "x"+f.ext.value};
 for (i=0; i< f.length-1; i++) {
    var g = f.elements[i];
    if (g.name.charAt(0) != "x" && g.value != null && g.value != "") { 
      if (g.name == "access_type" 
		   || g.name == "vendor_id"
		   || g.name == "campaign_id" 
		   || g.name == "banner_id"  
		   || g.name == "env_id" 
		   || g.name == "user_status" 
           || g.name == "targetURL"
           || g.name == "failureURL"
           || g.name == "fname"
//           || g.name == "fname2"
           || g.name == "lname"
           || g.name == "hphone"
//           || g.name == "aphone"
           || g.name == "email"
           || g.name == "address1"
           || g.name == "address2"
           || g.name == "city"
           || g.name == "state"
           || g.name == "country"
           || g.name == "zip"
           || g.name == "email") 
        {
          urlString += g.name+ "=" + escape(g.value) + "&";
        }
     }
  }//end forloop
//build up vuser from company name and meeting name for uniqueness
 urlString += "vuser=" + escape(company_name.value)+ "|" + escape(meeting_name.value)
     + "|" + (Math.round((Math.random()*9999999)+1)); 

//build up event string
 var event_string =  meeting1_FM_MM[meeting1_FM_MM.selectedIndex].value+"/"+meeting1_FM_DD[meeting1_FM_DD.selectedIndex].value+"/"+meeting1_FM_YY[meeting1_FM_YY.selectedIndex].value;
event_string += "|"+meeting1_TO_MM[meeting1_TO_MM.selectedIndex].value+"/"+meeting1_TO_DD[meeting1_TO_DD.selectedIndex].value+"/"+meeting1_TO_YY[meeting1_TO_YY.selectedIndex].value;
event_string += "|"+dest_city1.value+"|"+meeting1_attend.value;
/*
event_string += (meeting2_FM_MM.selectedIndex > 0) ? "|"+meeting2_FM_MM[meeting2_FM_MM.selectedIndex].value+"/"+meeting2_FM_DD[meeting2_FM_DD.selectedIndex].value+"/"+meeting2_FM_YY[meeting2_FM_YY.selectedIndex].value : "|null";
event_string += (meeting2_FM_MM.selectedIndex > 0) ? "|"+meeting2_TO_MM[meeting2_TO_MM.selectedIndex].value+"/"+meeting2_TO_DD[meeting2_TO_DD.selectedIndex].value+"/"+meeting2_TO_YY[meeting2_TO_YY.selectedIndex].value : "|null";
event_string += (meeting2_FM_MM.selectedIndex > 0) ? "|"+dest_city2.value+"|"+meeting2_attend.value : "|null|null";

event_string += (meeting3_FM_MM.selectedIndex > 0) ? "|"+meeting3_FM_MM[meeting3_FM_MM.selectedIndex].value+"/"+meeting3_FM_DD[meeting3_FM_DD.selectedIndex].value+"/"+meeting3_FM_YY[meeting3_FM_YY.selectedIndex].value : "|null";
event_string += (meeting3_FM_MM.selectedIndex > 0) ? "|"+meeting3_TO_MM[meeting3_TO_MM.selectedIndex].value+"/"+meeting3_TO_DD[meeting3_TO_DD.selectedIndex].value+"/"+meeting3_TO_YY[meeting3_TO_YY.selectedIndex].value : "|null";
event_string += (meeting3_FM_MM.selectedIndex > 0) ? "|"+dest_city3.value+"|"+meeting3_attend.value : "|null|null";

event_string += (meeting4_FM_MM.selectedIndex > 0) ? "|"+meeting4_FM_MM[meeting4_FM_MM.selectedIndex].value+"/"+meeting4_FM_DD[meeting4_FM_DD.selectedIndex].value+"/"+meeting4_FM_YY[meeting4_FM_YY.selectedIndex].value : "|null";
event_string += (meeting4_FM_MM.selectedIndex > 0) ? "|"+meeting4_TO_MM[meeting4_TO_MM.selectedIndex].value+"/"+meeting4_TO_DD[meeting4_TO_DD.selectedIndex].value+"/"+meeting4_TO_YY[meeting4_TO_YY.selectedIndex].value : "|null";
event_string += (meeting4_FM_MM.selectedIndex > 0) ? "|"+dest_city4.value+"|"+meeting4_attend.value : "|null|null";

event_string += (meeting5_FM_MM.selectedIndex > 0) ? "|"+meeting5_FM_MM[meeting5_FM_MM.selectedIndex].value+"/"+meeting5_FM_DD[meeting5_FM_DD.selectedIndex].value+"/"+meeting5_FM_YY[meeting5_FM_YY.selectedIndex].value : "|null";
event_string += (meeting5_FM_MM.selectedIndex > 0) ? "|"+meeting5_TO_MM[meeting5_TO_MM.selectedIndex].value+"/"+meeting5_TO_DD[meeting5_TO_DD.selectedIndex].value+"/"+meeting5_TO_YY[meeting5_TO_YY.selectedIndex].value : "|null";
event_string += (meeting5_FM_MM.selectedIndex > 0) ? "|"+dest_city5.value+"|"+meeting5_attend.value : "|null|null";
*/
//build up canswer 
 urlString += "&canswer=" + event_string;
//urlString += (travel_agent[0].checked == true)? travel_agent[0].value : travel_agent[1].value;
urlString += (agency_num.value) ?  "|"+agency_num.value : "|null";

//version of contract
urlString +=  (version[0].checked==true) ? "|" + escape(version[0].value) : "|" + escape(version[1].value);
/*
//united offers opt-in
urlString +=  (united_signup[0].checked==true) ? "|" + united_signup[0].value : "|" + united_signup[1].value;
//partner opt in
urlString +=  (partner_signup[0].checked==true) ? "|" + partner_signup[0].value : "|" + partner_signup[1].value;
*/
//added title to the end of canswer string
urlString += "|" + fname2.value; 
//add fax to end of canswer string
urlString += (aphone.value) ?  "|"+aphone.value : "|null";
//add phone ext to canswer string
urlString += (ext.value) ? "|"+ext.value : "|null";


// submit window to destination
  
  top.location=urlString;
//	document.write(urlString); //test only
 
 return true;
}//end with f
} // end validate Form

function SelectMe(fld) {
  fld.focus();
  if (fld.type != "select-one") fld.select();
}

function Empty(fld,alertMsg,aType,minLen,maxLen) {

  // determine the Valid Characters
  var strValidChars = " ";
  if (aType.indexOf("text") != -1) {
    strValidChars += "abcdefghijklmnopqrstuvwxyz";
  } 
  if (aType.indexOf("numbers") != -1) {
    strValidChars += "1234567890";
  }
  if (aType.indexOf("other") != -1) {
    strValidChars += "@_().-/ ";
  }

  with(fld) {
    // test if we're just off really simply
    if (value.length != 0 && value != " ") { 
      // here, there's some characters and it's not a single space
      //let's test further...assuming all things start off good:
      var valid = true;
      // let's test for length first - there's special cases
      // ...for exact length (i.e. the ARC Number),
      if (minLen == maxLen && value.length != minLen) {
        valid = false;
        alertMsg +=". It should be a " + minLen + " digit number";
      }
      // ...for too short,
      if (value.length < minLen && valid == true) {
        valid = false;
        alertMsg +=". It should be at least " + minLen + " characters long";
      }
      // ...and too long.
      if (value.length > maxLen && valid == true) {
        valid = false;
        alertMsg +=". It should be at no more than " + maxLen + " characters long";
      }      
      // Now, set up a flag for looping
      var spaces = 0;      
      // now loop thru the string given and see what's there
      for(i=0; i < value.length && valid == true; i++) {
        aChar = value.charAt(i).toLowerCase();
        if (strValidChars.indexOf(aChar) == -1) {
          valid=false;
          alertMsg += ", and should contain only " + aType;
        }
        if (aChar == " ") {
          spaces++;
          if(spaces == value.length) {
              valid=false;
              alertMsg += ", and cannot consist of all spaces"
          } else {
           // Special case, text only fields can not have more than 2 spaces
            if (type == "text") {
              if(spaces > 5) {
                valid=false;
                alertMsg += ", and cannot contain extra spaces"
              }
            }
          }
        }  
      }      
      // we're done looping - are things good or not?
      if(!valid) {
        alert(alertMsg + ".");
        setTimeout("SelectMe(document.forms['" + 
  		    fld.form.name + "'].elements['" + fld.name + "'])", 0);
  	    return true;
      } else { 
        return false;
      }
  	} else { // we made a simple stupid error - give me basic messaging
      alert(alertMsg + ".");
      setTimeout("SelectMe(document.forms['" + 
  		  fld.form.name + "'].elements['" + fld.name + "'])", 0);
  	  return true;
    } 
  } 
}

function ValidEmail(address) {
  with (address)  {
    apos=value.indexOf("@"); 
    dotpos=value.lastIndexOf(".");
    lastpos=value.length-1;

    if (apos<1 || dotpos-apos<2 || lastpos-dotpos>256 || lastpos-dotpos<2) {
      alert('Email address requires the @ symbol, a . (dot), and at least two letters after the dot.');
      setTimeout("SelectMe(document.forms['" + 
  		address.form.name + "'].elements['" + address.name + "'])", 0);
      return false;
    } else {
      return true;
    }
  } 
}


function showDaBox(g) {
 if (g=="Y") {
  document.getElementById('home_arc_id').style.display='inline';
  } else if (g=="N") {
  document.getElementById('home_arc_id').style.display='none';
  document.coreg.agency_num.value='';
  }

}


/* This script Source :: http://javascript.internet.com
Created by: Down Home Consulting :: http://downhomeconsulting.com 

Country State Drop Downs v1.0.
(c) Copyright 2005 Down Home Consulting, Inc.
www.DownHomeConsulting.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. The software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, itness for a particular purpose and noninfringement. in no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.
*/

var postState = '';
var postCountry = '';

// State table
var statelst = '\
US::Select State|\
US:AK:Alaska|\
US:AL:Alabama|\
US:AR:Arkansas|\
US:AZ:Arizona|\
US:CA:California|\
US:CO:Colorado|\
US:CT:Connecticut|\
US:DC:D.C.|\
US:DE:Delaware|\
US:FL:Florida|\
US:GA:Georgia|\
US:HI:Hawaii|\
US:IA:Iowa|\
US:ID:Idaho|\
US:IL:Illinois|\
US:IN:Indiana|\
US:KS:Kansas|\
US:KY:Kentucky|\
US:LA:Louisiana|\
US:MA:Massachusetts|\
US:MD:Maryland|\
US:ME:Maine|\
US:MI:Michigan|\
US:MN:Minnesota|\
US:MO:Missouri|\
US:MP:Marianas|\
US:MS:Mississippi|\
US:MT:Montana|\
US:NC:North Carolina|\
US:ND:North Dakota|\
US:NE:Nebraska|\
US:NH:New Hampshire|\
US:NJ:New Jersey|\
US:NM:New Mexico|\
US:NV:Nevada|\
US:NY:New York|\
US:OH:Ohio|\
US:OK:Oklahoma|\
US:OR:Oregon|\
US:PA:Pennsylvania|\
US:PR:Puerto Rico|\
US:RI:Rhode Island|\
US:SC:South Carolina|\
US:SD:South Dakota|\
US:TN:Tennessee|\
US:TX:Texas|\
US:UT:Utah|\
US:VA:Virginia|\
US:VT:Vermont|\
US:WA:Washington|\
US:WI:Wisconsin|\
US:WV:West Virginia|\
US:WY:Wyoming|\
CA::Select Province|\
CA:AB:Alberta|\
CA:BC:British Columbia|\
CA:MB:Manitoba|\
CA:NB:New Brunswick|\
CA:NF:Newfoundland and Labrador|\
CA:NS:Nova Scotia|\
CA:NT:Northwest Territories|\
CA:ON:Ontario|\
CA:PE:Prince Edward Island|\
CA:QC:Quebec|\
CA:SK:Saskatchewan|\
CA:YT:Yukon Territory|\
';

// Country data table
var country = '\
CA:Canada|\
US:United States\
';

function TrimString(sInString) {
  if ( sInString ) {
    sInString = sInString.replace( /^\s+/g, "" );// strip leading
    return sInString.replace( /\s+$/g, "" );// strip trailing
  }
}

// Populates the country selected with the counties from the country list
function populateCountry(defaultCountry) {
  if ( postCountry != '' ) {
    defaultCountry = postCountry;
  }
  var countryLineArray = country.split('|');  // Split into lines
  var selObj = document.getElementById('countrySelect');
  selObj.options[0] = new Option('Select one','');
  selObj.selectedIndex = 0;
  for (var loop = 0; loop < countryLineArray.length; loop++) {
    lineArray = countryLineArray[loop].split(':');
    countryCode  = TrimString(lineArray[0]);
    countryName  = TrimString(lineArray[1]);
    if ( countryCode != '' ) {
      selObj.options[loop + 1] = new Option(countryName, countryCode);
    }
    if ( defaultCountry == countryCode ) {
      selObj.selectedIndex = loop + 1;
    }
  }
}

function populateState() {
  var selObj = document.getElementById('stateSelect');
  var foundState = false;
  // Empty options just in case new drop down is shorter
  if ( selObj.type == 'select-one' ) {
    for (var i = 0; i < selObj.options.length; i++) {
      selObj.options[i] = null;
    }
    selObj.options.length=null;
//    selObj.options[0] = new Option('Select State',''); //this is now dynamic, included in list
    selObj.selectedIndex = 0;
  }
  // Populate the drop down with states from the selected country
  var stateLineArray = statelst.split("|");  // Split into lines
//  var optionCntr = 1; since including option 0, start with 0
  var optionCntr = 0;
  for (var loop = 0; loop < stateLineArray.length; loop++) {
    lineArray = stateLineArray[loop].split(":");
    countryCode  = TrimString(lineArray[0]);
    stateCode    = TrimString(lineArray[1]);
    stateName    = TrimString(lineArray[2]);
  if (document.getElementById('countrySelect').value == countryCode && countryCode != '' ) {
      if ( stateCode != '' ) {
        selObj.options[optionCntr] = new Option(stateName, stateCode);
      }
      // See if it's selected from a previous post
      if ( stateCode == postState && countryCode == postCountry ) {
        selObj.selectedIndex = optionCntr;
      }
      foundState = true;
      optionCntr++
    }
  }

}

function initCountry(country) {
  populateCountry(country);
}


