function testfunc(){
	alert(1);
}
function SetValue(frm,y){
	var j, props;
	j = 1;
	props = "";
	document.shopFrm.SKU.value = frm.SKU.value;
	document.shopFrm.Typereq.value = y;
	if(frm.elements.length>1){
		//alert(frm.elements.length);
		while(j != (frm.elements.length)){
			//alert(j)
			//alert(frm.elements[j].name)
			if(props != ""){
				props = props +"|"
			}
			 props = props + frm.elements[j].name + ":"+ frm.elements[j].value
			 document.shopFrm.Props.value = props
			//alert(document.shopFrm.Props.value);
			j = j+ 1;
		}
	}
	document.shopFrm.submit();
}
function opendetails(y){
	var URL;
	URL = "finaldet.asp?SKU=" + y
	window.open(URL, "Pop", "width=700,height=425,scrollbars=yes,status=No,resizeable=No", "no")
}
function SetVal(x){
	var res;
	res = false;
	document.scfrm.HidVal.value = x;
	if (x=="Buy") {
		n = document.scfrm.ItemId.length;
		if(isNaN(n)){
			if(document.scfrm.ItemId.checked){
				res = true;
			}
		}
		else{
			for (i=0;i <n;i++){
				if(document.scfrm.ItemId[i].checked){
					res = true;
				}
			}
		}
	}
	else if(x=="Update") {
		res =  CheckForNull();
	}
	if(document.scfrm.defadd.value != "yes" && res == true && x=="Buy" ){
			//alert("No Billing address");
			OpenBill();
			res = false;
			return;	
	}
	if (res==true){
		document.scfrm.submit();				
	}
	else if((res==false) && (x=="Buy")){
		alert("Please select the item(s) you want to buy.");
	}
}
function CheckForNull(){
	var res;
	res = true;
	for(i=0;i<document.scfrm.length; i++){
		if(document.scfrm.elements[i].value == ""){
			alert("You seem to have erroneously entered a blank in the quantity field for one or more of the items. The quantity for those items will be updated to 1. If you want to remove an item from the shopping cart, use the 'Remove from cart' link for that item.");
			document.scfrm.elements[i].focus();
			res = true;
		}
		else if(!isNaN(document.scfrm.elements[i].name)){
			if(isNaN(document.scfrm.elements[i].value)){
				alert("You seem to have erroneously entered a non-numerical value in the quantity field of one or more items. Please enter a numerical value in the quantity field.");
				document.scfrm.elements[i].focus();
				res = false;
			}
			if(document.scfrm.elements[i].value < 0 ){
				alert("You seem to have erroneously entered a negative value in the quantity field of one or more items. Please enter a positive value in the quantity field.");
				document.scfrm.elements[i].focus();
				res = false;
			}
			if(document.scfrm.elements[i].value == 0 ){
				alert("You seem to have erroneously entered a zero in the quantity field of one or more items. Please enter a positive value in the quantity field. If you want to remove an item from the shopping cart, use the 'Remove from cart' link for that item.");
				document.scfrm.elements[i].focus();
				res = false;
			}

		}
	}
	return res;
}
function checkVal(){
	var res;
	res = true;
	for(i=0;i<document.delfrm.length; i++){
		//alert(document.delfrm.elements[i].name.substring(0,3));
		if(document.delfrm.elements[i].name.substring(0,3) == "Add"){
			if(document.delfrm.elements[i][document.delfrm.elements[i].selectedIndex].value == "0"){
				alert("Please choose a delivery address for all items");
				res = false;
				document.delfrm.elements[i].focus();
				return;
			}
		}
	}
	for(i=0;i<document.delfrm.length; i++){
		//alert(document.delfrm.elements[i].name.substring(0,3));
		if(document.delfrm.elements[i].name.substring(0,3) == "sel"){
			if(document.delfrm.elements[i].value == "none"){
				alert("All items do not have shipping addresses. Please add a shipping address for those items.");
				res = false;
				return;
			}
		}
	}
	if(document.delfrm.defaddr.value == "no"){
		alert("Please add a Billing Address by clicking on the link at the top of the page.");
		res = false;
	}
	else if(document.delfrm.noad.value == "no"){
		alert("You have no delivery addresses associated with you. Please add your own delivery addresses and choose an appropriate address for each item.");
		res = false;
	}
	if (res == true){
		//alert(res);
		document.delfrm.submit();
	}
}
function callrefresh(){
	window.location.reload();
}

function SearchSubmit(){
	if(document.searchfrm.price[document.searchfrm.price.selectedIndex].value == "0" && document.searchfrm.brand[document.searchfrm.brand.selectedIndex].value == "0" && document.searchfrm.subcat[document.searchfrm.subcat.selectedIndex].value == "0" ){
		alert("Please select a price range and then click on 'Go' in order to view the items");
	}
	else{
		document.searchfrm.submit();		
	}
}
function ZeroSubmit(){
	if(document.pricefrm.price[document.pricefrm.price.selectedIndex].value!="0"){
		document.pricefrm.submit();		
	}
	else{
		alert("Please select a price range and then click on 'Go' in order to view the items");
	}
}

function rgSetValue(x, y, z){
	var j, props, qty;
	props = "";
	j = 1;
	document.shopFrm.Typereq.value = y;
	document.shopFrm.SKU.value = x.SKU.value;
	qty =x.qty.value;
	if(QtyCheck(qty) == true){
		document.shopFrm.qty.value = x.qty.value; 	
	}
	else{
		return;
	}
	
	if(z < x.Custtext.value.length){
		alert("The text you have entered has exceeded the maximum characters allowed in the personalized text for this product. Please reduce the length of the text.");
		return;
	}
	if(x.elements.length>2){
	//alert(x.elements.length);
		while(j != (x.elements.length - 1)){
			if(props != "" && x.elements[j].value != "" ){
				props = props +"|"
			}
			if (x.elements[j].value != "" && x.elements[j].name != "qty"){
				props = props + x.elements[j].name + ":"+ x.elements[j].value
			}
			j=j+1;
		}
		document.shopFrm.Props.value = props
	}
	//alert(document.shopFrm.Props.value);
	document.shopFrm.submit();
}
function QtyCheck(qty){
var res;
res = true;
if(qty == ""){
	alert("Please enter the quantity you want to buy.");
	res = false;
}
else if(isNaN(qty) == true){
	alert("Please enter a numerical value in the quantity field.");
	res = false;
}
else if (parseInt(qty) <= 0)  {
	alert("Please enter a positive numerical value in the quantity field.")  ;
	res = false;
}
return res;
}
function OpenNewadd(frm){
	z = "ViewAdd.asp?ARN=" + frm[frm.selectedIndex].value
	if(frm[frm.selectedIndex].value != "0"){
		window.open(z, "Arn", "width=350,height=375,status=No,resizeable=No", "no");
	}
}
function OpenBill(){
	z = "BillingAddress.asp"
	window.open(z, "bill", "width=400,height=450,status=No,resizeable=No", "no")
}
function consubmit(){
	var clp, maxclp;
	clp = document.confrm.REDCLP.value;
	maxclp = document.confrm.maxclp.value;
	//alert(maxclp);
	if(isNaN(clp) == true){
		alert("Please enter a numerical value in the field for the CLP points you want to redeem.");
	}
	else if(clp < 0){
		alert("Please enter a positive numerical value in the field for the customer loyality points you want to redeem.");
		document.confrm.REDCLP.focus();
	}
	else if(parseFloat(maxclp) < parseFloat(clp)){
		alert("You have " + maxclp + " CLP points. You cannot redeem more than that." );
	}
	else{
		document.confrm.submit();
	}
}
function openForm(x){
	x = "../ordfm/" + x
	//alert(x);
	window.open(x, "ordform", "width=700,height=650,scrollbars=yes,status=No,resizeable=no", "no")
}
function payopt(){
	if(document.chfrm.rad2.checked == true){
		document.chfrm.submit();
	}
	else if(document.crfrm.crex.value == "yes"){
		if(document.crfrm.rad1.checked == true){
			document.crfrm.submit();
		}
	}
	else{
		alert("Please choose a mode of payment.");
	}
}
function changecheck(x){
	//alert(x);
	if(x == "rad2"){
		if(document.crfrm.crex.value =="yes"){
			document.crfrm.rad1.checked = false;
		}
	}
	else if(x == "rad1"){
		document.chfrm.rad2.checked = false;
	}
}

function OpenPopUp(link){
	window.open(link, "popup", "width=650,height=450,scrollbars=yes,status=No,resizeable=yo", "no");
}
function subcatSubmit(){
	if(document.subcatfrm.subcat[document.subcatfrm.subcat.selectedIndex].value!="0"){
		document.subcatfrm.submit();		
	}
	else{
		alert("Please select a subcategory and then click on 'Go' in order to view the items");
	}
}

function callsub(){
	var res;
	res = true;
	if(document.frm.addname.value == ""){
		alert("Please specify a name for the address you are adding.")
		res = false;
		document.frm.addname.focus();
	}
	else if(document.frm.pername.value == ""){
		alert("Please specify the name of the addressee.")
		res = false;
		document.frm.pername.focus();
	}
	else if(document.frm.address.value== ""){
		alert("Please specify the address.")
		res = false;
		document.frm.address.focus();
	}
	else if(document.frm.pin.value == ""){
		alert("Please specify the pin/zip code.")
		res = false;
		document.frm.pin.focus();
	}
	if(document.frm.Cntry[document.frm.Cntry.selectedIndex].value != "India"){
		if(document.frm.fcity.value == ""){
			alert("Please specify the city.")
			res = false;
			document.frm.fcity.focus();
		}
		else if(document.frm.state.value == ""){
			alert("Please specify the state.")
			res = false;
			document.frm.state.focus();
		}
	}
	if(res == true){
		document.frm.submit();
	}
}
function callbilladd(){
	var res;
	res = true;
	if(document.Addfrm.AddName.value == ""){
		alert("Please specify a name for the address you are adding.")
		res = false;
		document.Addfrm.AddName.focus();
	}
	else if(document.Addfrm.PerName.value == ""){
		alert("Please specify the name of the addressee.")
		res = false;
		document.Addfrm.PerName.focus();
	}
	else if(document.Addfrm.Address.value == ""){
		alert("Please specify the address.")
		res = false;
		document.Addfrm.Address.focus();

	}
	else if(document.Addfrm.city.value == ""){
		alert("Please specify the city")
		res = false;
		document.Addfrm.city.focus();

	}
	else if(document.Addfrm.state.value == ""){
		alert("Please specify the state")
		res = false;
		document.Addfrm.state.focus();

	}
	else if(document.Addfrm.pin.value == ""){
		alert("Please specify the pin/zip code")
		res = false;
		document.Addfrm.pin.focus();
	}
	if(res == true){
		document.Addfrm.submit();
	}
}
function giftssubmit(){
	if(document.giftsfrm.cat[document.giftsfrm.cat.selectedIndex].value != "0" || document.giftsfrm.price[document.giftsfrm.price.selectedIndex].value != "0"){
		document.giftsfrm.submit();
	}
	else{
		alert("Select either a category or a price range and then click on submit to view the items.");
	}
}
function OpenCLP(link){
	window.open(link, "popup", "width=650,height=450,scrollbars=yes,status=No,resizeable=no", "no");
}
function OpenShipLoc(link){
	window.open(link, "popup", "width=500,height=450,scrollbars=yes,status=No,resizeable=no", "no");
}
