// calculate price
function Total() {
        var q, i, ordertotal, sh, total, total_quant;
		total_quant = 0;
        ordertotal = 0;
        nitems = 5
        for (i=1; i<nitems+1; i++) {
                eval("document.order.subtotal" + i + ".value = '';");
                eval("q = document.order.quantity" + i + ".value;");
                if (q) {
						eval("total_quant = total_quant + (document.order.quantity" + i + ".value * 1);");
                        eval("total=document.order.price" + i + ".value * document.order.quantity" + i + ".value;");
                        eval("document.order.subtotal" + i + ".value=Currency(total)");
                        eval("ordertotal = ordertotal + total;");
                }
        }
		updateShipping();
        document.order.OrderGst.value = Currency(ordertotal * 0.06);
        document.order.OrderPst.value = Currency(ordertotal * 0.08);
        document.order.OrderTotal.value = Currency(ordertotal);
        sh = document.order.shipping.value * total_quant
		tax = document.order.OrderGst.value * 1 + document.order.OrderPst.value * 1
        document.order.shipping.value = Currency(sh);
        document.order.charge_total.value = Currency(ordertotal + sh + tax);
}

// calculate price
function TotalUs() {
        var q, i, ordertotal, sh, total, total_quant;
		total_quant = 0;
        ordertotal = 0;
        nitems = 5
        for (i=1; i<nitems+1; i++) {
                eval("document.order.subtotal" + i + ".value = '';");
                eval("q = document.order.quantity" + i + ".value;");
                if (q) {
						eval("total_quant = total_quant + (document.order.quantity" + i + ".value * 1);");
                        eval("total=document.order.price" + i + ".value * document.order.quantity" + i + ".value;");
                        eval("document.order.subtotal" + i + ".value=Currency(total)");
                        eval("ordertotal = ordertotal + total;");
                }
        }
		updateShipping();
        document.order.OrderTotal.value = Currency(ordertotal);
        sh = document.order.shipping.value * total_quant
        document.order.shipping.value = Currency(sh);
        document.order.charge_total.value = Currency(ordertotal + sh);
}

// format price to round up
function Currency(anynum) {
        //returns number as string in $xxx,xxx.xx format.
        anynum = "" + eval(anynum)  //evaluate (in case an expression sent)
        intnum = parseInt(anynum)  //isolate integer portion
        intnum = Math.abs(intnum)
        intstr = ""+intnum
        //add comma in thousands place.
        if (intnum >= 1000) {
                intlen = intstr.length
                temp1=parseInt(""+(intnum/1000))
                temp2=intstr.substring(intlen-3,intlen)
                intstr = temp1+","+temp2

        }
        if (intnum >= 1000000) {
                intlen = intstr.length
                temp1=parseInt(""+(intnum/1000000))
                temp2=intstr.substring(intlen-7,intlen)
                intstr = temp1+","+temp2

        }

        decnum = Math.abs(parseFloat(anynum)-parseInt(anynum)) //isolate decimal portion
        decnum = decnum * 100 // multiply decimal portion by 100.
        decstr = "" + Math.abs(Math.round(decnum))
        if (decstr.length>2) {decstr=decstr.substring(0,2)}
        while (decstr.length < 2) {decstr="0"+decstr}
        retval = intstr + "." + decstr 
        if (anynum < 0) {
                retval="("+retval+")"
        }
        return retval
}

function updateShipping(){
// shipping values
for (i = 0; i < 3; i++){
if (document.order.cost[i].checked == true){document.order.shipping.value = document.order.cost[i].value;}	
}// ends shipping values


// Item2Quantity

}// ends function

// Shipping information is the same as billing information
function CopyBillingInfo()
{
	if (document.order.samebilling.checked == false)
	{ 
	   document.order.samebilling.value = "0";
	   document.order.ship_first_name.value = "";
	   document.order.ship_last_name.value = "";
	   document.order.ship_address_one.value = "";
	   document.order.ship_city.value = "";
	   document.order.ship_state_or_province.value = "";
	   document.order.ship_postal_code.value = "";
	   document.order.ship_phone.value = "";
	   document.order.email2.value = "";
	}	else  { 
	   document.order.samebilling.checked == true;
	   document.order.samebilling.value = document.order.bill_first_name.value;
	   document.order.ship_first_name.value = document.order.bill_first_name.value;
	   document.order.ship_last_name.value = document.order.bill_last_name.value;
	   document.order.ship_address_one.value = document.order.bill_address_one.value;
	   document.order.ship_city.value = document.order.bill_city.value;
	   document.order.ship_state_or_province.value = document.order.bill_state_or_province.value;
	   document.order.ship_postal_code.value = document.order.bill_postal_code.value;
	   document.order.ship_phone.value = document.order.bill_phone.value;
	   document.order.email2.value = document.order.email.value;
	}		
}

// Update Shipping Information
function UpdateBillingInfo()
{
	if (document.order.samebilling.checked == true)
	{ 
	   document.order.samebilling.checked == true;
	   document.order.samebilling.value = document.order.bill_first_name.value;
	   document.order.ship_first_name.value = document.order.bill_first_name.value;
	   document.order.ship_last_name.value = document.order.bill_last_name.value;
	   document.order.ship_address_one.value = document.order.bill_address_one.value;
	   document.order.ship_city.value = document.order.bill_city.value;
	   document.order.ship_state_or_province.value = document.order.bill_state_or_province.value;
	   document.order.ship_postal_code.value = document.order.bill_postal_code.value;
	   document.order.ship_phone.value = document.order.bill_phone.value;
	   document.order.email2.value = document.order.email.value;
	}		
}

//checkboxes
function checkboxes(formname,checkname,thestate){
var el_collection=eval("document.forms."+formname+"."+checkname)
for (c=0;c<el_collection.length;c++)
el_collection[c].checked=thestate
}

//dynamic divs
function writeIt(text,id){
	if (document.getElementById)
	{
		x = document.getElementById(id);
		x.innerHTML = '';
		x.innerHTML = text;
	}
	else if (document.all)
	{
		x = document.all[id];
		x.innerHTML = text;
	}
	else if (document.layers)
	{
		x = document.layers[id];
		text2 = text;
		x.document.open();
		x.document.write(text2);
		x.document.close();
	}
}

// pop-up window control
var imageWin = "";
function launchPage(url,theWidth,theHeight) {

 if(imageWin && !imageWin.closed) {
 imageWin.close();
 }

 imageWin = window.open(url,'imageWindow','width=' + theWidth + ',height=' + theHeight + ',resizable=no,scrollbars=auto,menubar=no,toolbar=no,directories=no,location=no,status=no');
 setTimeout("imageWin.focus()",250);
      
}

// close menus
var x = 0;
function SuspendLayerTimer(){ 
 x = 0;   // turn off timer
}  

function ResetLayerTimer(){
 x = 5;  // set timeout in 1/10 of seconds (10 = 1 second)
}  

function LayerTimeOut(){
 window.setTimeout( "LayerTimeOut()", 100); // 100 milliseconds delay
 if (x == 1){
	x = 0;
	// function to timeout
	MM_showHideLayers('snav01','','hide','snav02','','hide','snav03','','hide','snav04','','hide','snav05','','hide','snav06','','hide','snav07','','hide');
}
 if (x > 1) x = x - 1;
}

// global functions
function MM_displayStatusMsg(msgStr)  { //v3.0
	status=msgStr; document.MM_returnValue = true;
}

function MM_findObj(n, d) { //v3.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); 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 MM_nbGroup(event, grpName) { //v3.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : args[i+1];
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    if ((nbArr = document[grpName]) != null)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = args[i+1];
      nbArr[nbArr.length] = img;
  } }
}

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_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i< (args.length-2); i+=3) if ((obj=document.getElementById(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}