﻿function calcTotal(aspqty,asptotname,aspidx) {

	var qtyvalueidx = asptotname.substring(asptotname.length-1,asptotname.length);
	var autoshipPrice = new Array(13);
	var autoshipCV = new Array(13);
	
	var autoshipItems = new Array(13);

                 //modification 0 - 040506 - Craig Janson
                 var ctrlName = asptotname+'_hidden';
                 var ctrlName1 = 'cv' + qtyvalueidx + '_hidden';
                 var ctrlName2 = 'qtyasp' + qtyvalueidx;
      	 var hCtrlName = asptotname+'_hiddenQtyRequest';
                 var hCtrlName1 = asptotname+'_hiddenItemRequest';
                 // end modification 0 - 040506

 	
	autoshipItems[0]="EA410";
	autoshipItems[1]="DR440";
	autoshipItems[2]="SN460";
	autoshipItems[3]="KT150";
	autoshipItems[4]="LC820";
	autoshipItems[5]="LC840";
	autoshipItems[6]="BF044";
	autoshipItems[7]="BF042";
	autoshipItems[8]="HY047";
	autoshipItems[9]="HY046";
	autoshipItems[10]="SP001";
	autoshipItems[11]="KT156";
	autoshipItems[12]="KT155";

	autoshipPrice[0]="49.95";
	autoshipPrice[1]="39.95";
	autoshipPrice[2]="29.95";
	autoshipPrice[3]="119.85";
	autoshipPrice[4]="80";
	autoshipPrice[5]="150";
	autoshipPrice[6]="49.95";
	autoshipPrice[7]="49.95 ";
	autoshipPrice[8]="29.95 ";
	autoshipPrice[9]="29.95 ";
	autoshipPrice[10]="59.95 ";
	autoshipPrice[11]="139.85 ";
	autoshipPrice[12]="139.85 ";
	
	autoshipCV[0]="40";
	autoshipCV[1]="35";
	autoshipCV[2]="25";
	autoshipCV[3]="43";
	autoshipCV[4]="0";
	autoshipCV[5]="0";
	autoshipCV[6]="43";
	autoshipCV[7]="43";
	autoshipCV[8]="25";
	autoshipCV[9]="25";
	autoshipCV[10]="50";
	autoshipCV[11]="118";
	autoshipCV[12]="118";
	
	if (aspidx >= 0 && aspidx != null && aspidx != "") {
	
	    var qty         = aspqty;
	    var ItemCode    = autoshipItems[aspidx]

	    
		var price = autoshipPrice[aspidx] * aspqty;
		displayprice = formatCurrency(price);
		var cv = autoshipCV[aspidx] * aspqty;

 		if (price != 0) {
			/* modification 1 - 040506 - Craig Janson */
			document.getElementById(asptotname).innerHTML = displayprice;
			document.frmMain[ctrlName].value = price;
			document.frmMain[ctrlName1].value = cv;
			
			document.frmMain[hCtrlName].value = qty;
			document.frmMain[hCtrlName1].value = ItemCode;
			/* end modification 1 - 040506 */
		}
		else {
			document.getElementById(asptotname).innerHTML = "$0.00";
			document.frmMain[ctrlName].value = 0;
			document.frmMain[ctrlName1].value = 0;

			document.frmMain[hCtrlName].value = 0;
			document.frmMain[hCtrlName1].value = "";

		}
	}
	else  {
		document.frmMain[ctrlName].value = 0;
		document.frmMain[ctrlName2].value = 0;
		document.frmMain[ctrlName1].value = 0;

			            document.frmMain[hCtrlName].value = 0;
			document.frmMain[hCtrlName1].value = "";
	}

	// modification 2 - 040506 - Craig Janson 
	var totprice = (1*document.frmMain.total0_hidden.value) + (1*document.frmMain.total4_hidden.value) + (1*document.frmMain.total5_hidden.value) + (1*document.frmMain.astotal1_hidden.value) + (1*document.frmMain.astotal2_hidden.value) + (1*document.frmMain.astotal3_hidden.value);
	var totqty = (1*document.frmMain.qtyasp0.value) + (1*document.frmMain.qtyasp1.value) + (1*document.frmMain.qtyasp2.value) + (1*document.frmMain.qtyasp3.value) + (1*document.frmMain.qtyasp4.value) + (1*document.frmMain.qtyasp5.value);
	var totcv = (1*document.frmMain.cv0_hidden.value) + (1*document.frmMain.cv1_hidden.value) + (1*document.frmMain.cv2_hidden.value) + (1*document.frmMain.cv3_hidden.value) + (1*document.frmMain.cv4_hidden.value) + (1*document.frmMain.cv5_hidden.value);
	// end modification 2 - 040506 

	displaytotprice = formatCurrency(totprice);
	document.getElementById('astotal_all').innerHTML = displaytotprice;
	document.getElementById('aspqty_all').innerHTML = totqty;
	document.getElementById('cvqty_all').innerHTML = totcv;

                  if (asptotname == "astotal1")
                  {
                        document.frmMain.dropdown1.value = aspidx;
                  }
                  if (asptotname == "astotal2")
                  {
                        document.frmMain.dropdown2.value = aspidx;
                  }
                  if (asptotname == "astotal3")
                  {
                        document.frmMain.dropdown3.value = aspidx;
                  }

}
function billisship() {
	document.getElementById("_ctl0_ShippingAddress1").value     = document.getElementById("_ctl0_BillingAddress1").value;
	document.getElementById("_ctl0_ShippingCity").value         = document.getElementById("_ctl0_BillingCity").value;
	document.getElementById("_ctl0_ShippingState").value        = document.getElementById("_ctl0_BillingState").value;
	document.getElementById("_ctl0_ShippingZip").value          = document.getElementById("_ctl0_BillingZip").value;
}
function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}
function openWindow2(url, height, width, resize, sbars)
{
	var h=height;
	var w=width;
	
	if (h==null) h=300;
	if (w==null) w=500;
	
	if (resize!=null){
		var r = (resize==true) ? "yes" : "no"}
	else{
		r = "yes";
	}

	if (sbars!=null){
		if (sbars=="yes") {
                                var s = "yes"
                                } else if (sbars=="no") {
                                var s = "no"
                                }
	}else{
		s = "no";
	}
	var l = Math.ceil( (window.screen.width  - w) / 2 );
	var t = Math.ceil( (window.screen.height - h) / 2 );
	
	var val= window.open(url, "_blank", "top="+t+", left="+l+", width="+w+", height="+h+", status=no, toolbar=no, titlebar=no, menubar=no, location=no, resizable="+r+", border=0, scrollbars=yes);

}
	function NewWindow(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function winpop(winname) {
SmallWin=window.open(winname,"SmallWin","toolbar=no,directories=no,status=no,scrollbars=yes,menubar=no,width=400,height=400,resizable=no"); SmallWin.window.focus() }
