function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function _hbxStrip(a){
   a = a.split("|").join("");
   a = a.split("&").join("");
   a = a.split("'").join("");
   a = a.split("#").join("");
   a = a.split("$").join("");
   a = a.split("%").join("");
   a = a.split("^").join("");
   a = a.split("*").join("");
   a = a.split(":").join("");
   a = a.split("!").join("");
   a = a.split("<").join("");
   a = a.split(">").join("");
   a = a.split("~").join("");
   a = a.split(";").join("");
   a = a.split(" ").join("+");
   return a;
}

function copyfields()
{
    var myform = document.forms['billship'];
    var i;
    var fromstr = "billing_";
    var tostr = "shipping_";
    var names = new Array("first","last","company","address1","address2",
    					  "city","zip","phone");
    
    var cnames = new Array("country");
    
    var snames = new Array("state");

    for (i = 0; i < names.length; i++) {
      eval( "myform." + tostr + names[i] + ".value = myform." + fromstr + names[i] + ".value");
    }
    
    // for (i = 0; i < cnames.length; i++) {
    //   eval( "myform." + tostr + cnames[i] + ".selectedIndex = myform." + fromstr + cnames[i] + ".selectedIndex");
    // }
		
    //populateStateListShipping();
    
    var list = document.billship.billing_country;
    if (document.billship.billing_country.options[list.selectedIndex].value == document.billship.shipping_country.value) {
       //document.write(document.billship.billing_country.options[list.selectedIndex].value);
       for (i = 0; i < snames.length; i++) {
         eval( "myform." + tostr + snames[i] + ".selectedIndex = myform." + fromstr + snames[i] + ".selectedIndex");
       }
    } 

}


function poboxcheck()
{
 //This will check if the phrase pobox exists in either address1 or address2 values
 //It do the check by:
 //1. Convert values to lower case
 //2. Check the value using function checkpo()
 //3. Check any pobox abbreviation exceptions

 var add1=document.billship.shipping_address1.value.toLowerCase();
 var add2=document.billship.shipping_address2.value.toLowerCase();
 var address = add1 + ' ' + add2;
 //Other weird pobox abbreviations
 var index1 = address.indexOf("pobox");
 var index2 = address.indexOf("p.o.box");
 var index3 = address.indexOf("post office box");
 var sum = index1 + index2 + index3;

 if(sum > -3)
 {
  alert("We are unable to offer 2nd Day or Next Day delivery to PO Box.  Please enter a different shipping address or change shipping method to Ground.");
  return false;
 } 
 else if(checkpo(add1) && checkpo(add2))
 {
  return true;
 }
 else if(!checkpo(add1))
 {
  document.billship.shipping_address1.focus();
  document.billship.shipping_address1.select();
  alert("We are unable to offer 2nd Day or Next Day delivery to PO Box.  Please enter a different shipping address or change shipping method to Ground.");
  return false;
 }
 else if(!checkpo(add2))
 {
  document.billship.shipping_address2.focus();
  document.billship.shipping_address2.select();
  alert("We are unable to offer 2nd Day or Next Day delivery to PO Box.  Please enter a different shipping address or change shipping method to Ground.");
  return false;
 }
}

function checkpo(str)
{
 //This checks whether a string contains the word pobox. It does so by:
 //1. Scan through each character
 //2. Remove any . and spaces
 //3. Form the new string under a new variable
 //4. Check if the new string var contains pobox word.

 var newstr="";
 var junkstr="";
 var chr;
 var inputstring= str;
 for(i=0;i<inputstring.length;i++)
 {
  chr=inputstring.charAt(i);
  if((chr == ".") || (chr == " "))
  {
   junkstr=junkstr + chr;
  }
  else
  {
   newstr=newstr + chr;
  }
  if(newstr.indexOf("pobox")>-1)
  {
   return false;
  }
 }
  return true;
}





var stateValueList = new Array();

stateValueList['US']='AL,AK,AZ,AR,CA,CO,CT,DE,DC,FL,GA,HI,ID,IL,IN,IA,KS,KY,LA,ME,MD,MA,MI,AA,AE,AP,MN,MS,MO,MT,NE,NV,NH,NJ,NM,NY,NC,ND,OH,OK,OR,PA,RI,SC,SD,TN,TX,UT,VT,VA,WA,WV,WI,WY';
stateValueList['CA']='AB,BC,MB,NB,NF,NS,NU,NT,ON,PE,QC,SK,YT';

var stateNames = new Array();

stateNames["AA"]="Military - AA (Americas)";
stateNames["AE"]="Military - AE (Europe)";
stateNames["AP"]="Military - AP (Pacific)";
stateNames["AL"]="Alabama";
stateNames["AK"]="Alaska";
stateNames["AZ"]="Arizona";
stateNames["AR"]="Arkansas";
stateNames["CA"]="California";
stateNames["CO"]="Colorado";
stateNames["CT"]="Connecticut";
stateNames["DE"]="Delaware";
stateNames["DC"]="District of Columbia";
stateNames["FL"]="Florida";
stateNames["GA"]="Georgia";
stateNames["HI"]="Hawaii";
stateNames["ID"]="Idaho";
stateNames["IL"]="Illinois";
stateNames["IN"]="Indiana";
stateNames["IA"]="Iowa";
stateNames["KS"]="Kansas";
stateNames["KY"]="Kentucky";
stateNames["LA"]="Louisiana";
stateNames["ME"]="Maine";
stateNames["MD"]="Maryland";
stateNames["MA"]="Massachusetts";
stateNames["MI"]="Michigan";
stateNames["MN"]="Minnesota";
stateNames["MS"]="Mississippi";
stateNames["MO"]="Missouri";
stateNames["MT"]="Montana";
stateNames["NE"]="Nebraska";
stateNames["NV"]="Nevada";
stateNames["NH"]="New Hampshire";
stateNames["NJ"]="New Jersey";
stateNames["NM"]="New Mexico";
stateNames["NY"]="New York";
stateNames["NC"]="North Carolina";
stateNames["ND"]="North Dakota";
stateNames["OH"]="Ohio";
stateNames["OK"]="Oklahoma";
stateNames["OR"]="Oregon";
stateNames["PA"]="Pennsylvania";
stateNames["RI"]="Rhode Island";
stateNames["SC"]="South Carolina";
stateNames["SD"]="South Dakota";
stateNames["TN"]="Tennessee";
stateNames["TX"]="Texas";
stateNames["UT"]="Utah";
stateNames["VT"]="Vermont";
stateNames["VA"]="Virginia";
stateNames["WA"]="Washington";
stateNames["WV"]="West Virginia";
stateNames["WI"]="Wisconsin";
stateNames["WY"]="Wyoming";
stateNames["AB"]="Alberta";
stateNames["BC"]="British Columbia";
stateNames["MB"]="Manitoba";
stateNames["NB"]="New Brunswick";
stateNames["NF"]="Newfoundland";
stateNames["NT"]="NW Territories";
stateNames["NU"]="Nunavut";
stateNames["NS"]="Nova Scotia";
stateNames["ON"]="Ontario";
stateNames["PE"]="Pr. Edward Island";
stateNames["QC"]="Quebec";
stateNames["SK"]="Saskatchewan";
stateNames["YT"]="Yukon";


function clearList(optionList, titleName)
{		
  optionList.length =	0;
  optionList.options[0] = new Option(titleName, 'null', true, true);
}


function loadStates(index)
{	    
    //document.write(index);

  if (index == "CA" || index == "US") {
        //var stateNames = stateNameList[index].split(',');
        var stateValues = stateValueList[index].split(',');
        for (var i=0; i<stateValues.length; i++) {
            document.billship.billing_state.options[i+1] = new Option(stateNames[stateValues[i]], stateValues[i], false, false);
        }
  } 
}

function populateStateList()
{
  var list = document.billship.billing_country;
  var listValue = document.billship.billing_country.options[list.selectedIndex].value;
  
  if (listValue == 'US') {  
     clearList( document.billship.billing_state, "Select State" );
  } else if (listValue == 'CA') {
     clearList( document.billship.billing_state, "Select Province" );
  } else {
     document.billship.billing_state.length = 0;
     document.billship.billing_state.options[0] = new Option("------------", 'FN', true, true);
  }

  loadStates( listValue );
}


function loadStatesShipping(index)
{	    
    //document.write(index);

  if (index == "CA" || index == "US") {
        //var stateNames = stateNameList[index].split(',');
        var stateValues = stateValueList[index].split(',');
        for (var i=0; i<stateValues.length; i++) {
            document.billship.shipping_state.options[i+1] = new Option(stateNames[stateValues[i]], stateValues[i], false, false);
        }
  } 
}

function populateStateListShipping()
{
  var list = document.billship.shipping_country;
  var listValue = document.billship.shipping_country.value;

  if (listValue == 'US') {  
     clearList( document.billship.shipping_state, "Select State" );
  } else if (listValue == 'CA') {
     clearList( document.billship.shipping_state, "Select Province" );
  } else {
     clearList( document.billship.shipping_state, "------------" );
  }

  loadStatesShipping( listValue );
}












//function loadStates(index)
//{	    
//    //document.write(index);
//
//  if (index != "null" && index != "") {
//
//    var stateNames = stateNameList[index].split(',');
//    var	stateValues = stateValueList[index].split(',');
//    for	(var i=0; i<stateNames.length; i++)
//      document.billship.billing_state.options[i+1] = new Option(stateNames[i], stateValues[i], false, false);
//
//  }    
//}
//
//function populateStateList()
//{
//  var list = document.billship.billing_country;
//  var listValue = list.options[list.selectedIndex].value;
//
//  //if ( listValue == "null" ) listValue = "null";
//
//  clearList( document.billship.billing_state, "Select State" );
//
//  loadStates( listValue );
//}







//function loadStatesShipping(index)
//{	    
//    //document.write(index);
//  if (index != "null" && index != "") {
//    var stateNames = stateNameList[index].split(',');
//    var	stateValues = stateValueList[index].split(',');
//    for	(var i=0; i<stateNames.length; i++)
//      document.billship.shipping_state.options[i+1] = new Option(stateNames[i], stateValues[i], false, false);
//
//    document.billship.shipping_state.options[0].selected = true;
//  }        
//}

//function populateStateListShipping()
//{
//  var list = document.billship.shipping_country;
//  var listValue = list.options[list.selectedIndex].value;
//  
//  //if ( listValue == "null" ) listValue = "null";
//
//  clearList( document.billship.shipping_state, "Select State" );
//
//  loadStatesShipping( listValue );
//}






















