
var basicunitsTotal = 0;
var advunitsTotal = 0;
var wbunitsTotal = 0;
var trendnetTotal = 0;
var ud100Total = 0;
var aircableTotal = 0;
var ccraneTotal = 0;
var upsTotal = 0;
var casesTotal = 0;
var wbTimer = null;
var trendnetTimer = null;
var ud100Timer = null;
var aircableTimer = null;
var ccraneTimer = null;
var upsTimer = null;
var casesTimer = null;
var bName = navigator.appName;
var bVer = parseInt(navigator.appVersion);
var NS4 = (bName == "Netscape" && bVer >= 4);
var IE4 = (bName == "Microsoft Internet Explorer" && bVer >= 4);
var fields1 = "";
var fields2 = "";

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function updateSubtotal()
{
   var subtotal = basicunitsTotal + advunitsTotal + wbunitsTotal + aircableTotal + ud100Total + trendnetTotal + ccraneTotal + upsTotal + casesTotal;
   var elementRef = document.getElementById('subtotal');
   if (elementRef != null) {
      elementRef.innerHTML = '<p class=white>$' + subtotal;
   }

   var elementRef = document.getElementById('subtotalText');
   if (elementRef != null) {
      elementRef.innerHTML = '<p class=white><b>Subtotal</b>';
   }
}

function resetBasicUnits()
{
   if (document.orderform.basicunits.value == "") {
     document.orderform.basicunits.value = 0;
     checkBasicUnits();
   }
   return true;
}

function checkBasicUnits()
{
   if (document.orderform.basicunits.value == "") return;
   
   var count = parseInt(document.orderform.basicunits.value);
   if (isNaN(count)) count = 0;
   if (count < 0) count = 0;
   if (count > 100) count = 100;
   
   document.orderform.basicunits.value = count;
   var elementRef = document.getElementById('basicunitCost');
   var total = document.getElementById('basicunitsTotalText');

     // buy
     basicunitsTotal = 0;
     if (elementRef != null && total != null) {
        if (count >= 30) {
           elementRef.innerHTML = '<p class=white>$' + basicLargeQuantityPrice;
           basicunitsTotal = basicLargeQuantityPrice*count;
        }
        else if (count >= 15) {
           elementRef.innerHTML = '<p class=white>$' + basicMidQuantityPrice;
           basicunitsTotal = basicMidQuantityPrice*count;
        }
        else {
           elementRef.innerHTML = '<p class=white>$' + basicLowQuantityPrice;
           basicunitsTotal = basicLowQuantityPrice*count;
        }
        total.innerHTML = '<p class=white>$' + basicunitsTotal;
     }

//   clearTimeout(aircableTimer);
//   clearTimeout(ccraneTimer);
//   clearTimeout(upsTimer);
//   clearTimeout(casesTimer);
//   aircableTimer = setTimeout("checkAircable()",2000);
//   ccraneTimer = setTimeout("checkCCrane()",2000);
//   upsTimer = setTimeout("checkUPS()",2000);
//   casesTimer = setTimeout("checkCases()",2000);

   updateSubtotal();
}

function resetAdvUnits()
{
   if (document.orderform.advunits.value == "") {
     document.orderform.advunits.value = 0;
     checkAdvUnits();
   }
   return true;
}

function checkAdvUnits()
{
   if (document.orderform.advunits.value == "") return;
   
   var count = parseInt(document.orderform.advunits.value);
   if (isNaN(count)) count = 0;
   if (count < 0) count = 0;
   if (count > 100) count = 100;
   
   document.orderform.advunits.value = count;
   var elementRef = document.getElementById('advunitCost');
   var total = document.getElementById('advunitsTotalText');

     // buy
     if (elementRef != null && total != null) {
        if (count >= 30) {
           elementRef.innerHTML = '<p class=white>$' + advancedLargeQuantityPrice;
           advunitsTotal = advancedLargeQuantityPrice*count;
        }
        else if (count >= 15) {
           elementRef.innerHTML = '<p class=white>$' + advancedMidQuantityPrice;
           advunitsTotal = advancedMidQuantityPrice*count;
        }
        else {
           elementRef.innerHTML = '<p class=white>$' + advancedLowQuantityPrice;
           advunitsTotal = advancedLowQuantityPrice*count;
        }
        total.innerHTML = '<p class=white>$' + advunitsTotal;
     }

//   clearTimeout(aircableTimer);
//   clearTimeout(ccraneTimer);
//   clearTimeout(upsTimer);
//   clearTimeout(casesTimer);
//   aircableTimer = setTimeout("checkAircable()",2000);
//   ccraneTimer = setTimeout("checkCCrane()",2000);
//   upsTimer = setTimeout("checkUPS()",2000);
//   casesTimer = setTimeout("checkCases()",2000);

   updateSubtotal();
}

function resetWBUnits()
{
   if (document.orderform.wbunits.value == "") {
     document.orderform.wbunits.value = 0;
     checkWBUnits();
   }
   return true;
}

function checkWBUnits()
{
   clearTimeout(wbTimer);
   wbTimer = setTimeout("checkWBUnitsDelayed()",750);
}

function checkWBUnitsDelayed()
{
   if (document.orderform.wbunits.value == "") return;
   
   var count = parseInt(document.orderform.wbunits.value);
   if (isNaN(count)) count = 0;
   if (count < 0) count = 0;
   if (count > 0 && count < 5) count = 5;
   if (count > 100) count = 100;
   
   document.orderform.wbunits.value = count;
   var elementRef = document.getElementById('wbunitCost');
   var total = document.getElementById('wbunitsTotalText');

   
     document.orderform.wbunits.disabled = false;
     
     // buy
     if (elementRef != null && total != null) {
        if (count >= 30) {
           elementRef.innerHTML = '<p class=white>$' + advancedLargeQuantityPrice;
           wbunitsTotal = advancedLargeQuantityPrice*count;
        }
        else if (count >= 15) {
           elementRef.innerHTML = '<p class=white>$' + advancedMidQuantityPrice;
           wbunitsTotal = advancedMidQuantityPrice*count;
        }
        else {
           elementRef.innerHTML = '<p class=white>$' + advancedLowQuantityPrice;
           wbunitsTotal = advancedLowQuantityPrice*count;
        }
        total.innerHTML = '<p class=white>$' + wbunitsTotal;
     }

//   clearTimeout(aircableTimer);
//   clearTimeout(ccraneTimer);
//   clearTimeout(upsTimer);
//   clearTimeout(casesTimer);
//   aircableTimer = setTimeout("checkAircable()",2000);
//   ccraneTimer = setTimeout("checkCCrane()",2000);
//   upsTimer = setTimeout("checkUPS()",2000);
//   casesTimer = setTimeout("checkCases()",2000);

   updateSubtotal();
}


function resetAircable()
{
   if (document.orderform.aircable.value == "") {
     document.orderform.aircable.value = 0;
     checkAircable();
   }
   return true;
}

function checkAircable()
{
   if (document.orderform.aircable.value == "") return;
   
   var count = parseInt(document.orderform.aircable.value);
   if (isNaN(count)) count = 0;
   if (count < 0) count = 0;
   if (count > 100) count = 100;
   
   // out of stock
//   if (count != 0) {
//      alert("AirCable transmitters are currently out of stock and cannot be ordered.");
//   }
//   count = 0;
   
   document.orderform.aircable.value = count;

   var elementRef = document.getElementById('aircableCost');
   var total = document.getElementById('aircableTotalText');

   if (elementRef != null && total != null) {
         elementRef.innerHTML = '<p class=white>$' + aircablePrice;
         aircableTotal = aircablePrice*count;
         total.innerHTML = '<p class=white>$' + aircableTotal;
   }

   updateSubtotal();
}

function resetTrendnet()
{
   if (document.orderform.trendnet.value == "") {
     document.orderform.trendnet.value = 0;
     checkTrendnet();
   }
   return true;
}

function checkTrendnet()
{
   if (document.orderform.trendnet.value == "") return;
   
   var count = parseInt(document.orderform.trendnet.value);
   if (isNaN(count)) count = 0;
   if (count < 0) count = 0;
   if (count > 100) count = 100;

   // out of stock   
   count = 0;
   
   document.orderform.trendnet.value = count;

   var elementRef = document.getElementById('trendnetCost');
   var total = document.getElementById('trendnetTotalText');

   if (elementRef != null && total != null) {
         elementRef.innerHTML = '<p class=white>$' + trendnetPrice;
         trendnetTotal = trendnetPrice*count;
         total.innerHTML = '<p class=white>$' + trendnetTotal;
   }

   updateSubtotal();
}

function resetUD100()
{
   if (document.orderform.ud100.value == "") {
     document.orderform.ud100.value = 0;
     checkUD100();
   }
   return true;
}

function checkUD100()
{
   if (document.orderform.ud100.value == "") return;
   
   var count = parseInt(document.orderform.ud100.value);
   if (isNaN(count)) count = 0;
   if (count < 0) count = 0;
//   if (count > 100) count = 100;
   
   document.orderform.ud100.value = count;

   var elementRef = document.getElementById('ud100Cost');
   var total = document.getElementById('ud100TotalText');

   if (elementRef != null && total != null) {
         elementRef.innerHTML = '<p class=white>$' + ud100Price;
         ud100Total = ud100Price*count;
         total.innerHTML = '<p class=white>$' + ud100Total;
   }

   updateSubtotal();
}

function resetCCrane()
{
   if (document.orderform.ccranetransmitters.value == "") {
     document.orderform.ccranetransmitters.value = 0;
     checkCCrane();
   }
   return true;
}

function checkCCrane()
{
   if (document.orderform.ccranetransmitters.value == "") return;

   var count = parseInt(document.orderform.ccranetransmitters.value);
   if (isNaN(count)) count = 0;
   if (count < 0) count = 0;
   if (count > 100) count = 100;
   
   document.orderform.ccranetransmitters.value = count;

   var elementRef = document.getElementById('ccranetransmittersCost');
   var total = document.getElementById('ccranetransmittersTotalText');

   if (elementRef != null && total != null) {
         elementRef.innerHTML = '<p class=white>$' + ccranePrice;
         ccraneTotal = ccranePrice*count;
         total.innerHTML = '<p class=white>$' + ccraneTotal;
   }

   updateSubtotal();
}

function resetUPS()
{
   if (document.orderform.ups.value == "") {
     document.orderform.ups.value = 0;
     checkUPS();
   }
   return true;
}

function checkUPS()
{
   if (document.orderform.ups.value == "") return;
   
   var count = parseInt(document.orderform.ups.value);
   if (isNaN(count)) count = 0;
   if (count < 0) count = 0;
   if (count > 100) count = 100;
   
   // out of stock
   if (count != 0) {
      alert("Xantrex power supplies are currently available only by special ordered.  Please contact us to place your order.");
   }
   count = 0;
   
   document.orderform.ups.value = count;
// out of stock
return;

   var elementRef = document.getElementById('upsCost');
   var total = document.getElementById('upsTotalText');

   if (elementRef != null && total != null) {
        elementRef.innerHTML = '<p class=white>$' + xantrexPrice;
        document.orderform.ups.disabled = false;
        upsTotal = xantrexPrice*count;
        total.innerHTML = '<p class=white>$' + upsTotal;
   }

   updateSubtotal();
}


function resetCases()
{
   if (document.orderform.cases.value == "") {
     document.orderform.cases.value = 0;
     checkCases();
   }
   return true;
}

function checkCases()
{
   if (document.orderform.cases.value == "") return;
   
   var count = parseInt(document.orderform.cases.value);
   if (isNaN(count)) count = 0;
   if (count < 0) count = 0;
   if (count > 100) count = 100;
   
   document.orderform.cases.value = count;

   var elementRef = document.getElementById('casesCost');
   var total = document.getElementById('casesTotalText');

   if (elementRef != null && total != null) {
        elementRef.innerHTML = '<p class=white>$' + casePrice;
        document.orderform.cases.disabled = false;
        casesTotal = casePrice*count;
        total.innerHTML = '<p class=white>$' + casesTotal;
   }

   updateSubtotal();
}

function clearFirstName()
{
   if (document.orderform.firstname.value == "First Name") {
//     document.orderform.firstname.value = "";
     document.orderform.firstname.select();
   }
   return true;
}

function resetFirstName()
{
   if (document.orderform.firstname.value == "") {
     document.orderform.firstname.value = "First Name";
   }
   return true;
}

function clearLastName()
{
   if (document.orderform.lastname.value == "Last Name") {
      //document.orderform.lastname.value = "";
      document.orderform.lastname.select();
   }
   return true;
}

function resetLastName()
{
   if (document.orderform.lastname.value == "") {
     document.orderform.lastname.value = "Last Name";
   }
   return true;
}

function clearCompany()
{
   if (document.orderform.firstname.value == "Company") {
//     document.orderform.firstname.value = "";
     document.orderform.company.select();
   }
   return true;
}

function resetCompany()
{
   if (document.orderform.company.value == "") {
     document.orderform.company.value = "Company";
   }
   return true;
}

function clearAddress1()
{
   if (document.orderform.address1.value == "Address") {
//     document.orderform.address1.value = "";
     document.orderform.address1.select();
   }
   return true;
}

function resetAddress1()
{
   if (document.orderform.address1.value == "") {
     document.orderform.address1.value = "Address";
   }
   return true;
}

function clearAddress2()
{
   if (document.orderform.address2.value == "Address") {
//     document.orderform.address2.value = "";
     document.orderform.address2.select();
   }
   return true;
}

function resetAddress2()
{
   if (document.orderform.address2.value == "") {
     document.orderform.address2.value = "Address";
   }
   return true;
}

function clearCity()
{
   if (document.orderform.city.value == "City") {
//     document.orderform.city.value = "";
     document.orderform.city.select();
   }
   return true;
}

function resetCity()
{
   if (document.orderform.city.value == "") {
     document.orderform.city.value = "City";
   }
   return true;
}


function selectState(county)
{
   var firstname = document.orderform.firstname.value;                   
   var lastname = document.orderform.lastname.value;                   
   var address1 = document.orderform.address1.value;                   
   var address2 = document.orderform.address2.value;                   
   var city = document.orderform.city.value;                   
   var state = document.orderform.state.value;                   
   var zip = document.orderform.postcode.value;                   
   var phone = document.orderform.phone.value;                   
   var comments = document.orderform.comments.value;                   
         
   if (state == "FL") {
      var elementRef = document.getElementById('Fields');
      if (elementRef != null) {
         if (elementRef.innerHTML.indexOf ("county", 0) != -1) return;

         var countyHTML = '<select name="county"  style="width: 430px">';
         if (county != "" && county != "(Select County)") {
            countyHTML += '<option value="' + county + '" selected>' + county + '</option>';
         }
         
         countyHTML += '<option value="">(Select County)</option>'
                   + '<option value="Alachua">Alachua</option>'
                   + '<option value="Baker">Baker</option>'
                   + '<option value="Bay">Bay</option>'
                   + '<option value="Bradford">Bradford</option>'
                   + '<option value="Brevard">Brevard</option>'
                   + '<option value="Broward">Broward</option>'
                   + '<option value="Calhoun">Calhoun</option>'
                   + '<option value="Charlotte">Charlotte</option>'
                   + '<option value="Citrus">Citrus</option>'
                   + '<option value="Clay">Clay</option>'
                   + '<option value="Collier">Collier</option>'
                   + '<option value="Columbia">Columbia</option>'
                   + '<option value="DeSoto">DeSoto</option>'
                   + '<option value="Dixie">Dixie</option>'
                   + '<option value="Duval">Duval</option>'
                   + '<option value="Escambia">Escambia</option>'
                   + '<option value="Flagler">Flagler</option>'
                   + '<option value="Franklin">Franklin</option>'
                   + '<option value="Gadsden">Gadsden</option>'
                   + '<option value="Gilchrist">Gilchrist</option>'
                   + '<option value="Glades">Glades</option>'
                   + '<option value="Gulf">Gulf</option>'
                   + '<option value="Hamilton">Hamilton</option>'
                   + '<option value="Hardee">Hardee</option>'
                   + '<option value="Hendry">Hendry</option>'
                   + '<option value="Hernando">Hernando</option>'
                   + '<option value="Highlands">Highlands</option>'
                   + '<option value="Hillsborough">Hillsborough</option>'
                   + '<option value="Holmes">Holmes</option>'
                   + '<option value="Indian River">Indian River</option>'
                   + '<option value="Jackson">Jackson</option>'
                   + '<option value="Jefferson">Jefferson</option>'
                   + '<option value="Lafayette">Lafayette</option>'
                   + '<option value="Lake">Lake</option>'
                   + '<option value="Lee">Lee</option>'
                   + '<option value="Leon">Leon</option>'
                   + '<option value="Levy">Levy</option>'
                   + '<option value="Liberty">Liberty</option>'
                   + '<option value="Madison">Madison</option>'
                   + '<option value="Manatee">Manatee</option>'
                   + '<option value="Marion">Marion</option>'
                   + '<option value="Martin">Martin</option>'
                   + '<option value="Miami-Dade">Miami-Dade</option>'
                   + '<option value="Monroe">Monroe</option>'
                   + '<option value="Nassau">Nassau</option>'
                   + '<option value="Okaloosa">Okaloosa</option>'
                   + '<option value="Okeechobee">Okeechobee</option>'
                   + '<option value="Orange">Orange</option>'
                   + '<option value="Osceola">Osceola</option>'
                   + '<option value="Palm Beach">Palm Beach</option>'
                   + '<option value="Pasco">Pasco</option>'
                   + '<option value="Pinellas">Pinellas</option>'
                   + '<option value="Polk">Polk</option>'
                   + '<option value="Putnam">Putnam</option>'
                   + '<option value="Santa Rosa">Santa Rosa</option>'
                   + '<option value="Sarasota">Sarasota</option>'
                   + '<option value="Seminole">Seminole</option>'
                   + '<option value="St. Johns">St. Johns</option>'
                   + '<option value="St. Lucie">St. Lucie</option>'
                   + '<option value="Sumter">Sumter</option>'
                   + '<option value="Suwannee">Suwannee</option>'
                   + '<option value="Taylor">Taylor</option>'
                   + '<option value="Union">Union</option>'
                   + '<option value="Volusia">Volusia</option>'
                   + '<option value="Wakulla">Wakulla</option>'
                   + '<option value="Walton">Walton</option>'
                   + '<option value="Washington">Washington</option>'
                   + '</select> <br>';
         
         elementRef.innerHTML = fields1 + countyHTML + fields2;
         setTimeout("document.orderform.state.focus();", 100);
      }
   }

   else {
      var elementRef = document.getElementById('Fields');
      if (elementRef != null) {
         elementRef.innerHTML = fields1 + fields2;
         setTimeout("document.orderform.state.focus();", 100);
     }
   }

   document.orderform.firstname.value = firstname;             
   document.orderform.lastname.value = lastname;                   
   document.orderform.address1.value = address1;                   
   document.orderform.address2.value = address2;                   
   document.orderform.city.value = city;                   
   document.orderform.state.value = state;                   
   document.orderform.postcode.value = zip;                   
   document.orderform.phone.value = phone;                   
   document.orderform.comments.value = comments;                   
   return true;
}

function clearZip()
{
   if (document.orderform.postcode.value == "Zip Code") {
//     document.orderform.postcode.value = "";
     document.orderform.postcode.select();
   }
   return true;
}

function resetZip()
{
   if (document.orderform.postcode.value == "") {
     document.orderform.postcode.value = "Zip Code";
   }
   return true;
}
function clearPostcode()
{
   if (document.orderform.postcode.value == "Postal Code") {
//     document.orderform.postcode.value = "";
     document.orderform.postcode.select();
   }
   return true;
}

function resetPostcode()
{
   if (document.orderform.postcode.value == "") {
     document.orderform.postcode.value = "Postal Code";
   }
   return true;
}

function clearEmail()
{
   if (document.orderform.email.value == "E-Mail Address") {
//     document.orderform.email.value = "";
     document.orderform.email.select();
   }
   return true;
}

function resetEmail()
{
   if (document.orderform.email.value == "") {
     document.orderform.email.value = "E-Mail Address";
   }
   return true;
}

function clearPhone()
{
   if (document.orderform.phone.value == "Phone Number (xxx-xxx-xxxx format)") {
//     document.orderform.phone.value = "";
     document.orderform.phone.select();
   }
   return true;
}

function resetPhone()
{
   if (document.orderform.phone.value == "") {
     document.orderform.phone.value = "Phone Number (xxx-xxx-xxxx format)";
   }
   return true;
}

function clearComments()
{
   if (document.orderform.comments.value == "Comments") {
//     document.orderform.comments.value = "";
     document.orderform.comments.select();
   }
   return true;
}

function resetComments()
{
   if (document.orderform.comments.value == "") {
     document.orderform.comments.value = "Comments";
   }
   return true;
}

function selectCountry(address1, address2, city, state, county, postcode, phone)
{
   if (document.orderform.country.value == "United States" ||
       document.orderform.country.value.indexOf("U.S. Domestic") != -1) {
      var elementRef = document.getElementById('Fields');
      if (elementRef != null) {

        var stateHTML = '<select name="state"  style="width: 430px" onChange="selectState(\'' + county + '\')">';
        if (document.orderform.country.value.indexOf("U.S. Domestic") != -1) {
           stateHTML += '<option value="XX" selected>U.S. Territory or Possession</option>';
        }
        else if (state != "" && state != "(Select State)") {
           stateHTML += '<option value="' + state + '" selected>' + state + '</option>';
        }
        
        stateHTML += '<option value="">(Select State)</option>'
                   + '<option value="XX">U.S. Territory or Possession</option>'
                   + '<option value="AL">AL</option>'
                   + '<option value="AK">AK</option>'
                   + '<option value="AZ">AZ</option>'
                   + '<option value="AR">AR</option>'
                   + '<option value="CA">CA</option>'
                   + '<option value="CO">CO</option>'
                   + '<option value="CT">CT</option>'
                   + '<option value="DE">DE</option>'
                   + '<option value="DC">DC</option>'
                   + '<option value="FL">FL</option>'
                   + '<option value="GA">GA</option>'
                   + '<option value="HI">HI</option>'
                   + '<option value="ID">ID</option>'
                   + '<option value="IL">IL</option>'
                   + '<option value="IN">IN</option>'
                   + '<option value="IA">IA</option>'
                   + '<option value="KS">KS</option>'
                   + '<option value="KY">KY</option>'
                   + '<option value="LA">LA</option>'
                   + '<option value="ME">ME</option>'
                   + '<option value="MD">MD</option>'
                   + '<option value="MA">MA</option>'
                   + '<option value="MI">MI</option>'
                   + '<option value="MN">MN</option>'
                   + '<option value="MS">MS</option>'
                   + '<option value="MO">MO</option>'
                   + '<option value="MT">MT</option>'
                   + '<option value="NE">NE</option>'
                   + '<option value="NV">NV</option>'
                   + '<option value="NH">NH</option>'
                   + '<option value="NJ">NJ</option>'
                   + '<option value="NM">NM</option>'
                   + '<option value="NY">NY</option>'
                   + '<option value="NC">NC</option>'
                   + '<option value="ND">ND</option>'
                   + '<option value="OH">OH</option>'
                   + '<option value="OK">OK</option>'
                   + '<option value="OR">OR</option>'
                   + '<option value="PA">PA</option>'
                   + '<option value="RI">RI</option>'
                   + '<option value="SC">SC</option>'
                   + '<option value="SD">SD</option>'
                   + '<option value="TN">TN</option>'
                   + '<option value="TX">TX</option>'
                   + '<option value="UT">UT</option>'
                   + '<option value="VT">VT</option>'
                   + '<option value="VA">VA</option>'
                   + '<option value="WA">WA</option>'
                   + '<option value="WV">WV</option>'
                   + '<option value="WI">WI</option>'
                   + '<option value="WY">WY</option>'
                   + '</select> <br>';

        fields1 = '<font size=5><input type=text name="address1" onFocus="clearAddress1();" onBlur="resetAddress1();" value="' + address1 + '" style="width: 430px"> <br>'
                + '<input type=text name="address2" onFocus="clearAddress2();" onBlur="resetAddress2();" value="' + address2 + '" style="width: 430px"> <br>'
                + '<input type=text name="city" onFocus="clearCity();" onBlur="resetCity();" value="' + city +'" style="width: 430px"> <br>'
                + stateHTML + '</font>';

        if (postcode == "Postal Code") postcode = "Zip Code";
        fields2 = '<input type=text name="postcode" onFocus="clearZip();" onBlur="resetZip();" value="' + postcode + '" style="width: 430px"> <br>'
                + '<input type=text name="phone" onFocus="clearPhone();" onBlur="resetPhone();" value="' + phone + '" style="width: 430px"> <br>';

        elementRef.innerHTML = fields1 + fields2;

        if (state != "" && state != "(Select State)") selectState(county);
      }

   }
   else if (document.orderform.country.value != "") {
      
      var elementRef = document.getElementById('Fields');
      if (elementRef != null) {
        if (postcode == "Zip Code") postcode = "Postal Code";

        elementRef.innerHTML = '<font size=5>'
                             + '<input type=text name="address1" onFocus="clearAddress1();" onBlur="resetAddress1();" value="' + address1 + '" style="width: 430px"> <br>'
                             + '<input type=text name="address2" onFocus="clearAddress2();" onBlur="resetAddress2();" value="' + address2 + '" style="width: 430px"> <br>'
                             + '<input type=text name="city" onFocus="clearCity();" onBlur="resetCity();" value="' + city +'" style="width: 430px"> <br>'
                             + '<input type=text name="postcode" onFocus="clearPostcode();" onBlur="resetPostcode();" value="' + postcode +'" style="width: 430px"> <br></font>';
      }
   }
}

function checkform()
{
  document.orderform.firstname.value = trim(document.orderform.firstname.value.replace(/First Name/gi,""));

  if (document.orderform.firstname.value == "") {
    alert( "Please enter your first name." );
    document.orderform.firstname.select();
    return false;
  }

  document.orderform.lastname.value = trim(document.orderform.lastname.value.replace(/Last Name/gi,""));

  if (document.orderform.lastname.value == "") {
    alert( "Please enter your last name." );
    document.orderform.lastname.select();
    return false;
  }

  if (document.orderform.country.value == "") {
    alert( "Please select a country." );
    document.orderform.country.focus();
    return false;
  }

  document.orderform.address1.value = trim(document.orderform.address1.value.replace(/Address/gi,""));
  document.orderform.address2.value = trim(document.orderform.address2.value.replace(/Address/gi,""));

  if (document.orderform.address1.value == "") {
    alert( "Please enter an address." );
    document.orderform.address1.select();
    return false;
  }

  document.orderform.city.value = trim(document.orderform.city.value);

  if (document.orderform.city.value == "City") {
    alert( "Please enter a city." );
    document.orderform.city.select();
    return false;
  }

  if (document.orderform.country.value == "United States" && document.orderform.state.value == "") {
    alert( "Please select a state." );
    document.orderform.state.focus();
    return false;
  }

  if (document.orderform.country.value == "United States" && document.orderform.state.value == "FL" && document.orderform.county.value == "") {
    alert( "Florida residents need to select a county." );
    document.orderform.county.focus();
    return false;
  }

  if ((document.orderform.country.value == "United States" || document.orderform.country.value.indexOf("U.S. Domestic") != -1)) {
    document.orderform.postcode.value = trim(document.orderform.postcode.value.replace(/Zip Code/gi,""));

    if (document.orderform.postcode.value == "") {
      alert( "Please enter a zip code." );
      document.orderform.postcode.select();
      return false;
    }

    if (!CheckZip()) {
      document.orderform.postcode.select();
      return false;
    }

    document.orderform.phone.value = trim(document.orderform.phone.value);

    document.orderform.phone.value = trim(document.orderform.phone.value.replace(/Phone Number \(xxx-xxx-xxxx format\)/gi,""));

    if (document.orderform.phone.value == "") {
      alert( "Please enter a phone number." );
      document.orderform.phone.select();
      return false;
    }
  
    // check number if provided
    if (!CheckPhone()) {
       document.orderform.phone.select();
       return false;
    }
  }
//  else {
//    document.orderform.postcode.value = trim(document.orderform.postcode.value.replace(/Postal Code/gi,""));

//    if (document.orderform.postcode.value == "") {
//      alert( "Please enter a postal code." );
//      document.orderform.postcode.select();
//      return false;
//    }
//  }

//  if (document.orderform.country.value != "United States") {
//     var count = parseInt(document.orderform.ups.value);
//     if (count != 0) {
//        alert("Xantrex Power Supplies are only available for shipping in the US.");
//        document.orderform.ups.select();
//        return false;
//     }
//  }

  document.orderform.email.value = trim(document.orderform.email.value.replace(/E-Mail Address/gi,""));

  if (document.orderform.email.value == "") {
    alert( "Please enter an e-mail address." );
    document.orderform.email.select();
    return false;
  }
  
  if (!CheckEmail()) {
    document.orderform.email.select();
    return false;
  }
  
  if (document.orderform.aircable.value + document.orderform.ud100.value + document.orderform.trendnet.value < 1)
  {
     var answer = confirm("There are no Bluetooth transmitters included in this order.  Do you want to proceed with checkout?")
     if (!answer){
        document.orderform.trendnet.select();
	return false;
     }
  }

  if (document.orderform.basicunits.value + document.orderform.advunits.value + document.orderform.wbunits.value + document.orderform.ups.value + document.orderform.ccranetransmitters.value < 1) {
     var answer = confirm("There are no BlueFlyers units included in this order.  Do you want to proceed with checkout?")
     if (!answer){
        document.orderform.basicunits.select();
       return false;
     }
  }

  return true ;
}

function CheckZip()
{
   var s_zip = document.orderform.postcode.value;

   var i = s_zip.indexOf(' ',0);
   while(i > -1)
   {
      s_zip = s_zip.substring(0,i) + 
         s_zip.substring((i + 1),s_zip.length);
      i = s_zip.indexOf(' ',0);
   }

   document.orderform.postcode.value = s_zip.substring(0,5);
   if((s_zip.length < 5) ||
      (s_zip.charAt(0) < '0' || s_zip.charAt(0) > '9') ||
      (s_zip.charAt(1) < '0' || s_zip.charAt(1) > '9') ||
      (s_zip.charAt(2) < '0' || s_zip.charAt(2) > '9') ||
      (s_zip.charAt(3) < '0' || s_zip.charAt(3) > '9') ||
      (s_zip.charAt(4) < '0' || s_zip.charAt(4) > '9'))
   {
      alert('The zip code "' + s_zip + '" is not a valid 5 digit zip code.');
      return false;
   }
   return true;
}

function CheckPhone() 
{
   var thisnumber = document.orderform.phone.value;

   if(thisnumber.length == 0)
   {
      return false;
   }

   OK = /\(?\d{3}\)?([-\/\.])\d{3}\1\d{4}/.exec(thisnumber)
   if (!OK)		
   {
      alert('The phone number "' + thisnumber + '" is not a valid number in the format xxx-xxx-xxxx.');
      return false;
   }

   return true;
}

function CheckEmail()
{
   var s_email = document.orderform.email.value;

   // developed by willmaster.com
   var i = s_email.indexOf(' ',0);
   while(i > -1)
   {
      s_email = s_email.substring(0,i) + 
         s_email.substring((i + 1),s_email.length);
      i = s_email.indexOf(' ',0);
   }

   document.orderform.email.value = s_email;
   if((s_email.length < 6) ||
      (s_email.indexOf('@',0) < 1) ||
      (s_email.lastIndexOf('@') != s_email.indexOf('@',0)) ||
      (s_email.lastIndexOf('@') > (s_email.length - 5)) ||
      (s_email.lastIndexOf('.') > (s_email.length - 3)) ||
      (s_email.lastIndexOf('.') < (s_email.length - 4)) ||
      (s_email.indexOf('..',0) > -1) ||
      (s_email.indexOf('@.',0) > -1) ||
      (s_email.indexOf('.@',0) > -1) ||
      (s_email.indexOf(',',0) > -1))
   {
      alert('The email address "' + s_email + '" is not valid.');
      return false;
   }
   return true;
}

