

var IE4 = (document.all && !document.getElementById) ? true : false;
var NS4 = (document.layers) ? true : false;
var IE5 = (document.all && document.getElementById) ? true : false;
var N6 = (document.getElementById && !document.all) ? true : false;
var MAC = (window.navigator.userAgent.indexOf("Mac") >= 0) ? true : false;

if(NS4){
    document.bgColor = "#E5E5E5";
}


function viewCart(command){

var scriptName = "quikstore.cgi";
var linkURL = "http://keystone-labs.com/cgi-bin/quikstore.cgi";
var task = "?view_cart=yes"
if(command == "checkout"){
     task = "?checkout=yes"
}
linkURL += task;

	var myLocation = unescape(document.location);
	myLocation = myLocation.substring(1).split('/');

     if(myLocation[myLocation.length - 1].substring(0,scriptName.length) == scriptName){

          // GET Requests
		var qsQuery = unescape(document.location.search.replace(/\+/g,' '));
        qsQuery = qsQuery.replace('?','&');
        qsQuery = qsQuery.replace("checkout=yes&",'');
        qsQuery = qsQuery.replace("view_cart=yes&",'');

          if(qsQuery.length > 1){
     		linkURL += qsQuery;
          }
          else{
               for(i = 0; i < document.forms[0].elements.length; i++){
                    var inType = document.forms[0].elements[i].type;
                    if(inType == "hidden"){
                         var fieldName = document.forms[0].elements[i].name;
                         var fieldValue = document.forms[0].elements[i].value;
                         if(fieldName == "view_cart"){
                            continue;
                         }
                         if(fieldName == "checkout"){
                            continue;
                         }
                         if(fieldValue != "shipping.html"){
                              qsQuery += "&" + fieldName + "=" + fieldValue;
                         }
                    }
               }
               linkURL += qsQuery;
          }
     }
     else{
          var PAGE = myLocation[myLocation.length - 1];
          linkURL += "&page=" + PAGE + "&store_type=html";
     }

document.location = linkURL;
}


// -------------------------------------------------------------------
function GoTo(thisURL) {
     self.location = thisURL;
}
// -------------------------------------------------------------------
function OpenWindow(thisURL,wdt,hgt) {
	var myWin = window.open(thisURL,"pics",
     "toolbar=no,scrollbars=yes,resizable=yes,width=" + wdt + ",height=" + hgt);
}

// -------------------------------------------------------------------
function fillTrackingNumber(form){

     var STDIN = unescape(location.search.replace(/\+/g,' '));
     STDIN = STDIN.substring(1).split('&');
     for(i=0; i < STDIN.length; i++){
          STDIN[i] = STDIN[i].split('=');
     }
     var trackingNum = STDIN[0][1];
     if(trackingNum != null){
          form.TrackID.value = trackingNum;
          form.submit();
     }
}


// -------------------------------------------------------------------
// SHIPPING PAGE
// -------------------------------------------------------------------

function checkCountry(form){

     // This function tests the selected country and resets
     // the values in the <select> boxes for the appropriate
     // State/Province values and also the shipping rates
     // based on the values in the shipping.data file.

     var CountryIndex = form.Mailing_Country.selectedIndex;
     var CountryValue = form.Mailing_Country.options[CountryIndex].value;

     if(CountryValue == "CA"){
          clearStates(form);
          addProvinces(form);
     }
     else if(CountryValue == "US"){
          clearStates(form);
          addStates(form);
     }
     else{
          clearStates(form);
          var noState = new Option("None","None",false,false);
          form.Mailing_State.options[0] = noState;
     }

loadShippingMethods(form);

}

// -------------------------------------------------------------------
function checkState(form){

     // This function tests the country field and if US is selected,
     // Makes sure that a state value was also selected.

     // If your store is in Canada, You will want to change the countryName
     // variable below so it tests for provences.

var countryName = "US";
var taxField = "Mailing_State";
var orderFormStateField = "Mailing_State";

var CountryIndex = form.Mailing_Country.selectedIndex;
var CountryValue = form.Mailing_Country.options[CountryIndex].value;
var CountryText = form.Mailing_Country.options[CountryIndex].text;
var taxFieldValue = "";
var taxFieldType = form.elements[taxField].type;
var fieldValues = new Array();

    if(taxFieldType == "select-one"){
          var taxIndex = form.elements[taxField].selectedIndex;
          fieldValues = form.elements[taxField].options[taxIndex].value.split('|');
          taxFieldValue = fieldValues[0];
    }
    else{
          fieldValues = form.elements[taxField].value.split('|');
          taxFieldValue = fieldValues[0];
    }

    if((CountryValue == countryName)&&
        ((taxFieldValue == "")||(taxFieldValue == "INVALID"))){
         if(countryName == "US"){
              alert("\nSince you selected " + CountryText + " for your country, you" +
                    "\nmust enter your state abbreviation before going to checkout.\n");
         }
         else{
              alert("\nSince you selected " + CountryText + " for your country, you" +
                    "\nmust select your province before going to checkout.\n");
         }
          form.elements[taxField].focus();
     return false;
     }

     if(taxFieldValue != "NA"){
          document.cookie = "Mailing_State=" + escape(taxFieldValue) + "; path=/";
     }
     document.cookie = "Mailing_Country=" + escape(CountryValue) + "; path=/";

return true;
}

// -------------------------------------------------------------------
function clearStates(form){

     // Simply clears the states so we can reload them.

    selectLen = form.Mailing_State.length;
    for ( i = (selectLen -1); i>=0; i--){
        document.forms[0].Mailing_State.options[i] = null;
    }
}


// -------------------------------------------------------------------

function addProvinces(form){

     // Loads the provinces when CA (Canada) is selected

var Provinces = new Array();

     // Entries are "TAX_COD|ABBREVIATION|PROVINCE";

Provinces[0]  = "Alberta|Alberta";
Provinces[1]  = "British Columbia|British Columbia";
Provinces[2]  = "Manitoba|Manitoba";
Provinces[3]  = "Native Reservations|Native Reservations";
Provinces[4]  = "New Brunswick|New Brunswick";
Provinces[5]  = "Newfoundland|Newfoundland";
Provinces[6]  = "North West Territories|North West Territories";
Provinces[7]  = "Nova Scotia|Nova Scotia";
Provinces[8]  = "Ontario|Ontario";
Provinces[9]  = "Prince Edward Island|Prince Edward Island";
Provinces[10] = "Quebec|Quebec";
Provinces[11] = "Saskatchewan|Saskatchewan";
Provinces[12] = "Yukon|Yukon";

     for(i=0;i<=Provinces.length -1;i++){
        if(Provinces[i] != null){
          var pro = Provinces[i].split('|');
          var newProvince = new Option(pro[1],pro[0],false,false);
          form.Mailing_State.options[i] = newProvince;
        }
     }
}

// -------------------------------------------------------------------
function addStates(form){

     // Reset the country

form.Mailing_Country.options[0].selected = true;

     // Loads the States when US is selected

var States = new Array();

// Entries are "ABBREVIATION|STATE";

States[0]  = "INVALID|Select State";
States[1]  = "AL|Alabama";
States[2]  = "AK|Alaska";
States[3]  = "AZ|Arizona";
States[4]  = "AR|Arkansas";
States[5]  = "CA|California";
States[6]  = "CO|Colorado";
States[7]  = "CT|Connecticut";
States[8]  = "DE|Delaware";
States[9]  = "DC|District of Columbia";
States[10] = "FL|Florida";
States[11] = "GA|Georgia";
States[12] = "GU|Guam";
States[13] = "HI|Hawaii";
States[14] = "ID|Idaho";
States[15] = "IL|Illinois";
States[16] = "IN|Indiana";
States[17] = "IA|Iowa";
States[18] = "KS|Kansas";
States[19] = "KY|Kentucky";
States[20] = "LA|Louisiana";
States[21] = "ME|Maine";
States[22] = "MD|Maryland";
States[23] = "MA|Massachusetts";
States[24] = "MI|Michigan";
States[25] = "MN|Minnesota";
States[26] = "MS|Mississippi";
States[27] = "MO|Missouri";
States[28] = "MT|Montana";
States[29] = "NE|Nebraska";
States[30] = "NV|Nevada";
States[31] = "NH|New Hampshire";
States[32] = "NJ|New Jersey";
States[33] = "NM|New Mexico";
States[34] = "NY|New York";
States[35] = "NC|North Carolina";
States[36] = "ND|North Dakota";
States[37] = "OH|Ohio";
States[38] = "OK|Oklahoma";
States[39] = "OR|Oregon";
States[40] = "PA|Pennsylvania";
States[41] = "PR|Puerto Rico";
States[42] = "RI|Rhode Island";
States[43] = "SC|South Carolina";
States[44] = "SD|South Dakota";
States[45] = "TN|Tennessee";
States[46] = "TX|Texas";
States[47] = "UT|Utah";
States[48] = "VT|Vermont";
States[49] = "VA|Virginia";
States[50] = "VI|Virgin Islands";
States[51] = "WA|Washington";
States[52] = "WV|West Virginia";
States[53] = "WI|Wisconsin";
States[54] = "WY|Wyoming";

     for(i=0;i<=States.length -1;i++){
        if(States[i] != null){
          var values = States[i].split('|');
          var newState = new Option(values[1],values[0],false,false);
          form.Mailing_State.options[i] = newState;
        }
     }
}

// -------------------------------------------------------------------
function clearMethods(form){

     // Clears the Shipping Methods when the form is loaded

    selectLen = form.Shipping_Method.length;
    for ( i = (selectLen -1); i>=0; i--){
        document.forms[0].Shipping_Method.options[i] = null;
    }
}

// -------------------------------------------------------------------
function loadShippingMethods(form){

     // This loads the values for the shipping rates
     // as defined in the shipping.data file

var weight = form.cart_weight.value;

     // This next variable (TAG) gets substituted when
     // the page is loaded. DO NOT REMOVE IT.

 var domCarriers = new Array();

     if(weight > 0){
          domCarriers[0] = "Standard Postal Service - 6.95";
          domCarriers[1] = "Priority Mail - 8.95";
      	domCarriers[2] = "UPS 2nd Day - 13.50";
     }
     else{
          domCarriers[0] = "Download Only";
     }

 var intCarriers = new Array();

     if(weight > 0){
      	intCarriers[0] = "International Airmail - 20.95";
     }
     else{
          intCarriers[0] = "Download Only";
     }

 var caCarriers = new Array();

     if(weight > 0){
          caCarriers[0] = "Canada Airmail - 20.95";
     }
     else{
          caCarriers[0] = "Download Only";
     }


clearMethods(form);
var CountryIndex = form.Mailing_Country.selectedIndex;
var CountryValue = form.Mailing_Country.options[CountryIndex].value;

     if(CountryValue == "US"){
          for(i=0;i<=domCarriers.length -1;i++){
             if(domCarriers[i] != null){
               var sText  = domCarriers[i];
               var values = domCarriers[i].split(' - ');
               var sValue = values[0];
               var newMethod = new Option(sText,sValue,false,false);
               form.Shipping_Method.options[i] = newMethod;
             }
          }
     }
     else if(CountryValue == "CA"){
          for(i=0;i<=caCarriers.length -1;i++){
             if(caCarriers[i] != null){
               var sText  = caCarriers[i];
               var values = caCarriers[i].split(' - ');
               var sValue = values[0];
               var newMethod = new Option(sText,sValue,false,false);
               form.Shipping_Method.options[i] = newMethod;
             }
          }
     }
     else{
          for(i=0;i<=intCarriers.length -1;i++){
             if(intCarriers[i] != null){
               var sText  = intCarriers[i];
               var values = intCarriers[i].split(' - ');
               var sValue = values[0];
               var newMethod = new Option(sText,sValue,false,false);
               form.Shipping_Method.options[i] = newMethod;
             }
          }
     }
}






