function openWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function addtocart(itemid, price) {
	parent.frtop.location = "/cgi-bin/addtocart.pl?" + itemid;
var mystr = "The item with the price of " + price + "\nhas been added to your shopping cart\.";
	alert(mystr);
}

function removeitem(itemid) {
	document.location = "/cgi-bin/removefromcart.pl?" + itemid;
}

function textFocus(form, index) {
	form.elements[index * 9 -7 ].focus();
}

function recalculate(itemno) {
var subtotal = 0;
var shipping = 0;
var shipindex = 0;
var i;
	for (i=1; i<=itemno; i++ ) {
		subtotal += parseFloat(document.chkout.elements[i*9 - 1].value);
	}
	document.chkout.txtsubtotal.value = round_off(subtotal);
	if (document.chkout.shiptype.value == 'upsground') {
		shipindex = 0;
	} else if (document.chkout.shiptype.value == 'ups3day') {
		shipindex = 1;
	} else if (document.chkout.shiptype.value == 'ups2day') {
		shipindex = 2;
	} else if (document.chkout.shiptype.value == 'ups1day') {
		shipindex = 3;
	}
	for (i=1; i<=itemno; i++ ) {
		shipping += parseFloat(document.chkout.elements[i*9 - 7].value * document.chkout.elements[i*9 - 5 + shipindex].value);
	}
	document.chkout.txtshipping.value = round_off(shipping);
	document.chkout.txttotal.value = round_off(shipping+subtotal);
}

function updatevalue(price, txtqty, txtamount, itemno, itemid)  {
	if (txtqty.value == 0) {
		var answer;
		answer=confirm("Do you want to remove this item?");
		if (answer) {
			document.location = "/cgi-bin/removefromcart.pl?" + itemid;
			document.location = "/viewcart.html";
		} else {
			txtqty.value = 1;
		}
	}
	var quantity;
	quantity = txtqty.value;
	txtamount.value = round_off(price * quantity); //update amount
	recalculate(itemno);
}

function payonline() {
	if (document.chkout.txtsubtotal.value == 0 ) {
		alert("At least one product must be choosen!");
		return false;
	} else {
		document.chkout.action = "https://secure.vnisoft.net/cgi-bin/ndfsoft/ccard.pl";
		document.chkout.submit();
		return true;
	}
}

function paybyphone() {
	if (document.chkout.txtsubtotal.value == 0 ) {
		alert("At least one product must be choosen!");
		return false;
	} else {
		document.chkout.action = "/cgi-bin/paybyphone.pl";
		return true;
	}
}

function paybymail() {
	if (document.chkout.txtsubtotal.value == 0 ) {
		alert("At least one product must be choosen!");
		return false;
	} else {
	document.chkout.action = "/cgi-bin/paybymail.pl";
		return true;
	}
}

function round_off(n) {
	return Math.round(n*100) / 100;
}

