
MM_preloadImages('/images/navro_r1_c1.jpg','/images/navro_r2_c1.jpg','/images/navro_r3_c1.jpg','/images/navro_r4_c1.jpg','/images/lcro_r37_c7.jpg','/images/lcro_r39_c7.jpg','/images/lcro_r41_c7.jpg','/images/lcro_r43_c7.jpg','/images/lcro_r1_c23.jpg','/images/lcro_r4_c21.jpg','/images/lcro_r6_c22.jpg','/images/lcro_r8_c24.jpg','/images/lcro_r10_c22.jpg');

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.01
  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 && d.getElementById) x=d.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 setCookie(name, value, expires) {
   document.cookie = name + "=" + escape(value) + "; 
   path=/" + ((expires == null) ? "" : "; expires=" + expires.toGMTString());

   var exp = new Date();     //set new date object
   exp.setTime(exp.getTime() + (1000 * 60 * 60 * 24 * 30));     //set it 30 days ahead 
}

function getCookie (name) {
    var dc = document.cookie;
    var cname = name + "=";

    if (dc.length > 0) {
      begin = dc.indexOf(cname);
      if (begin != -1) {
        begin += cname.length;
        end = dc.indexOf("", begin);
        if (end == -1) end = dc.length;
           return unescape(dc.substring(begin, end));
        }
      }
    }
    return null;
} */

function prodPopup(w,h,img,$caption,$imglist,$caplist) {

   // width and height are the image size so we need to add
   // some padding to these numbers to get the full window size.

   w = w + 200;
   h = h + 180;

   day = new Date();
   id = day.getTime();
   URL = "/prodimg_popup.html?img=" + img + "&cap=" + $caption + "&list=" + $imglist + "&caps=" + $caplist;
   eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=" + w + ",height=" + h + ",left = 40,top = 40');");
}

function viewOrder($ordnum) {

   w = 650;
   h = 800;

   day = new Date();
   id = day.getTime();
   URL = "/print_order.html?on=" + $ordnum ;
   eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=" + w + ",height=" + h + ",left = 40,top = 40');");
}



function replaceMainImg($fname, $caption) {

   document.getElementById('mainImg').src = $fname;
   document.getElementById('mainCap').innerHTML = $caption;

}

function checkCartData($value) {

   pattern = /\d+/;
   if ($value == "") {
      alert("Please enter a number in the quanty field before continuing.");
      return("failed");
   }
   if ($value == "0") {
      alert("0 is not a valid quantity. To remove this item, select the corrisponding Remove checkbox and click update cart.");
      return("failed");
   }
   if (pattern.exec($value)) {
      return("ok");
   }
   else {
      alert("A non-numeric value was detected, please correct this error before continuing.");
   }
}
function itemRemovalConfirm($title, ckboxid) {

}

function copyShipToBill() {

   document.ckout.billing_address1.value = document.ckout.shipping_address1.value;
   document.ckout.billing_address2.value = document.ckout.shipping_address2.value;
   document.ckout.billing_city.value = document.ckout.shipping_city.value;
   document.ckout.billing_state.value = document.ckout.shipping_state.value;
   document.ckout.billing_zip.value = document.ckout.shipping_zip.value;
   document.ckout.billing_phone.value = document.ckout.shipping_phone.value;
   document.ckout.billing_email.value = document.ckout.shipping_email.value;

   document.ckout.billing_country.value = document.ckout.shipping_country.value;


   document.ckout.cc_owner.value = document.ckout.shipping_first_name.value + " " + document.ckout.shipping_last_name.value;
}

function validateForm() {

   $msg = "";
   if (document.ckout.shipping_first_name.value == "") {
      $msg = "Shipping First Name\n";
   }
   if (document.ckout.shipping_last_name.value == "") {
      $msg += "Shipping Last Name\n";
   }
   if (document.ckout.shipping_address1.value == "") {
      $msg += "Shipping Address\n";
   }
   if (document.ckout.shipping_city.value == "") {
      $msg += "Shipping City\n";
   }
   if (document.ckout.shipping_state.value == "") {
      $msg += "Shipping State\n";
   }
   if (document.ckout.shipping_country.value == "") {
      $msg += "Shipping Country\n";
   }
   if (document.ckout.shipping_phone.value == "") {
      $msg += "Shipping Phone\n";
   }
   if (document.ckout.shipping_email.value == "") {
      $msg += "Shipping Email\n";
   }


   if (document.ckout.billing_address1.value == "") {
      $msg += "Billing Address\n";
   }
   if (document.ckout.billing_city.value == "") {
      $msg += "Billing City\n";
   }
   if (document.ckout.billing_state.value == "") {
      $msg += "Billing State\n";
   }
   if (document.ckout.billing_country.value == "") {
      $msg += "Billing Country\n";
   }
   if (document.ckout.billing_phone.value == "") {
      $msg += "Billing Phone\n";
   }
   if (document.ckout.billing_email.value == "") {
      $msg += "Billing Email\n";
   }

   if (document.ckout.cc_type.value == "") {
      $msg += "Credit Card Type\n";
   }
   if (document.ckout.cc_owner.value == "") {
      $msg += "Credit Card Owner\n";
   }
   if (document.ckout.cc_number.value == "") {
      $msg += "Credit Card Number\n";
   }
   if (document.ckout.ccexp_month.value == "") {
      $msg += "Expiration Month\n";
   }
   if (document.ckout.ccexp_year.value == "") {
      $msg += "Expireation Year\n";
   }
   if (document.ckout.cnp_security.value == "") {
      $msg += "Security Number\n";
   }


   if ($msg != "") {
      $msg = "Please enter data in the following fields:\n" + $msg;
      alert($msg);
      return false;
   }

}

// JavaScript for the form field hint boxes

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function prepareInputsForHints() {
        var inputs = document.getElementsByTagName("input");
        for (var i=0; i<inputs.length; i++){
                // test to see if the hint span exists first
                if (inputs[i].parentNode.getElementsByTagName("span")[0]) {
                        // the span exists!  on focus, show the hint
                        inputs[i].onfocus = function () {
                                this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
                        }
                        // when the cursor moves away from the field, hide the hint
                        inputs[i].onblur = function () {
                                this.parentNode.getElementsByTagName("span")[0].style.display = "none";
                        }
                }
        }
        // repeat the same tests as above for selects
        var selects = document.getElementsByTagName("select");
        for (var k=0; k<selects.length; k++){
                if (selects[k].parentNode.getElementsByTagName("span")[0]) {
                        selects[k].onfocus = function () {
                                this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
                        }
                        selects[k].onblur = function () {
                                this.parentNode.getElementsByTagName("span")[0].style.display = "none";
                        }
                }
        }
}

function reCalcShipping($shipMethod) {

   if ($shipMethod == "overnight") {
      $shipping_cost = document.review.overnight_price.value;
   }
   else if ($shipMethod == "twoday") {
      $shipping_cost = document.review.twoday_price.value;
   }
   else if ($shipMethod == "ground") {
      $shipping_cost = document.review.ground_price.value;
   }
   document.getElementById('shipping_price').innerHTML = $shipping_cost;
   document.review.shipping_price.value = $shipping_cost;

   $product_total = parseFloat(document.review.product_total.value);
   $tax_total = parseFloat(document.review.tax_total.value);
   $shipping_cost = parseFloat($shipping_cost);

   $grand_total = ($product_total+$shipping_cost)+$tax_total;

   $grand_total = roundToPennies($grand_total);

   document.getElementById('grand_total').innerHTML = $grand_total;
   document.review.total_amount.value = $grand_total;

}

function roundToPennies(n) {

 pennies = n * 100;
 pennies = Math.round(pennies);

 strPennies = "" + pennies;
 len = strPennies.length;

 return strPennies.substring(0, len - 2) + "." + strPennies.substring(len - 2, len);

}

function tellUs(box) {
 if(box.value==box.defaultValue) {
    box.value = "";
 }
 document.getElementById('contactInfo').style.display='block';
 document.getElementById('contactInfo').style.visibility='visible';
}
function clearForm(box) {
 if(box.value==box.defaultValue) {
    box.value = "";
 }
}
function validateTellUs() {

   $msg = "";
   if (document.getElementById('need').value == "Tell us what you need.") {
      $msg = "Enter some data before submitting this form.\n";
   }
   if ($msg != "") {
      alert($msg);
      return false;
   }
}
