if (document.images) { //preload images
	var preImage1 = new Image(); preImage1.src = "../images/img_border_lg.gif";
}

function submitform(){
	if (document.forms['frmMain'].xmaxqty){	//Indicates check for maximum quantity
		xmax = document.forms['frmMain'].xmaxqty.value;
	}else{
		xmax = "0";
	}
	iMaxQty = parseInt(xmax);

	if (document.forms['frmMain'].xminqty){	//Indicates check for minimum quantity
		xmin = document.forms['frmMain'].xminqty.value;
	}else{
		xmin = "0";
	}
	iMinQty = parseInt(xmin);
	
	//Must be ordered in multiples of X
	if (document.forms['frmMain'].xmultiple){
		xmultiple = document.forms['frmMain'].xmultiple.value;
		if (xmultiple == "" || isNaN(xmultiple)){
			imultiple = 1;
		}else{
			imultiple = parseInt(xmultiple);
		}
	}else{
		imultiple = 1;
	}
	
	xreorderpolicy = document.forms['frmMain'].xreorderpolicy.value;
	if (document.forms['frmMain'].xquantity){	//Single quantity to check
		xvalue = document.forms['frmMain'].xquantity.value;
		if (isNaN(xvalue) || xvalue == ""){
			alert(Astring[0]);
			document.forms['frmMain'].xquantity.focus();
			document.forms['frmMain'].xquantity.select();
			return;
		}
		
		iqty = parseInt(xvalue);
		if (iqty < 0){
			alert(Astring[1]);
			document.forms['frmMain'].xquantity.focus();
			document.forms['frmMain'].xquantity.select();
			return;
		}
		if (iMinQty > 1){
			if (iqty < iMinQty){
				alert(Astring[2] + xmin + ".\r\r" + Astring[3]);
				document.forms['frmMain'].xquantity.focus();
				document.forms['frmMain'].xquantity.select();
				return;
			}
		}
		if (iMaxQty > 0){
			if (iqty > iMaxQty){
				alert(Astring[12] + iMaxQty + ".\r\r" + Astring[3]);
				document.forms['frmMain'].xquantity.focus();
				document.forms['frmMain'].xquantity.select();
				return;
			}
		}
		//Check ordered in correct multiples
		if (iqty % imultiple != 0){
			alert(Astring[4] + imultiple + ".");
			document.forms['frmMain'].xquantity.focus();
			document.forms['frmMain'].xquantity.select();
			return;
		}
		
		if (document.forms['frmMain'].xinventory){
			xinventory = document.forms['frmMain'].xinventory.value;
		}else{
			xinventory = "0";
		}
		if (parseInt(xvalue) > parseInt(xinventory)){
			switch(xreorderpolicy){
				case "2":
					alert(Astring[5] + "\r\r" + Astring[6] + xinventory + ".\r\r" + Astring[3]);
					document.forms['frmMain'].xquantity.focus();
					document.forms['frmMain'].xquantity.select();
					return;
				case "3":
					alert(Astring[7] + "\r\r" + Astring[6] + xinventory + ".\r\r" + Astring[3]);
					document.forms['frmMain'].xquantity.focus();
					document.forms['frmMain'].xquantity.select();
					return;
				case "4":
					//if (parseInt(xinventory) == 0){
					//	alert("The minimum quantity for this LEADTIME product is " + xmin + ".\r\rYou have only ordered " + xvalue + ".\r\rPlease adjust your order quantity accordingly.");
					//	document.forms['frmMain'].xquantity.focus();
					//	document.forms['frmMain'].xquantity.select();
					//	return;
					//}else{
						if (parseInt(xvalue) < parseInt(xmin)){
							alert(Astring[8] + "\r\r" + Astring[6] + xinventory + ". " + Astring[2] + xmin + ".\r\r" + Astring[3]);
							document.forms['frmMain'].xquantity.focus();
							document.forms['frmMain'].xquantity.select();
							return;
						}
					//}
				case "7":
					if (parseInt(xvalue) < parseInt(xmin)){
						alert(Astring[9] + xmin + ".\r\r" + Astring[10] + xvalue + ".\r\r" + Astring[3]);
						document.forms['frmMain'].xquantity.focus();
						document.forms['frmMain'].xquantity.select();
						return;
					}
				default:
				    var sAllowBO = document.forms['frmMain'].xAllowBO.value;
				    if (sAllowBO == "true"){
				    
				    }else{
					    alert(Astring[6] + xinventory + ".\r\r" + Astring[3]);
					    document.forms['frmMain'].xquantity.focus();
					    document.forms['frmMain'].xquantity.select();
					    return;
					}
			}
		}
	}else{
		itotal = 0
		
		for (i=1;i<17;i++){
			xref = eval("document.forms['frmMain'].xqty" + i);
			if (xref){
				xvalue = xref.value;
				if (isNaN(xvalue) || xvalue == ""){
					alert(Astring[0]);
					xref = eval("document.forms['frmMain'].xqty" + i);
					xref.focus();
					xref.select();
					return;
				}
				
				iqty = parseInt(xvalue);
				if (iqty < 0){
					alert(Astring[1]);
					xref = eval("document.forms['frmMain'].xqty" + i);
					xref.focus();
					xref.select();
					return;
				}
				
				//Check ordered in correct multiples
				if (iqty % imultiple != 0){
					alert(Astring[4] + imultiple + ".");
					xref = eval("document.forms['frmMain'].xqty" + i);
					xref.focus();
					xref.select();
					return;
				}
				
				itotal = itotal + parseInt(xvalue);
			}
		}
		
		if (iMinQty > 1){
			if (itotal < iMinQty){
				alert(Astring[11] + xmin + ".\r\r" + Astring[3]);
				
				for (i=1;i<17;i++){
					xref = eval("document.forms['frmMain'].xqty" + i);
					if (xref){
						xref.focus();
						xref.select();
						break;
					}
				}
				return;
			}
		}
		if (iMaxQty > 0){
			if (itotal >iMaxQty){
				alert(Astring[12] + iMaxQty + ".\r\r" + Astring[3]);
				
				for (i=1;i<17;i++){
					xref = eval("document.forms['frmMain'].xqty" + i);
					if (xref){
						xref.focus();
						xref.select();
						break;
					}
				}
				return;
			}
		}

		
		for (i=1;i<17;i++){
			xref = eval("document.forms['frmMain'].xqty" + i);
			if (xref){
				xvalue = xref.value;
				
				xref2 = eval("document.forms['frmMain'].xinv" + i);
				if (xref2){
					xinventory = xref2.value;

					if (parseInt(xvalue) > parseInt(xinventory)){
						switch(xreorderpolicy){
							case "2":
								alert(Astring[5] + "\r\r" + Astring[3]);
								xref = eval("document.forms['frmMain'].xqty" + i);
								xref.focus();
								xref.select();
								return;
							case "3":
								alert(Astring[7] + "\r\r" + Astring[3]);
								xref = eval("document.forms['frmMain'].xqty" + i);
								xref.focus();
								xref.select();
								return;
							case "4":
								if (itotal < parseInt(xmin)){
									alert(Astring[8] + "\r\r" + Astring[11] + xmin + ".");
									xref = eval("document.forms['frmMain'].xqty" + i);
									xref.focus();
									xref.select();
									return;
								}
							case "7":
								if (itotal < parseInt(xmin)){
									alert(Astring[9] + xmin + ".\r\r" + Astring[10] + itotal + ".\r\r" + Astring[3]);
									xref = eval("document.forms['frmMain'].xqty" + i);
									xref.focus();
									xref.select();
									return;
								}
							default:
								alert(Astring[6] + xinventory + ".\r\r" + Astring[3]);
								xref = eval("document.forms['frmMain'].xqty" + i);
								xref.focus();
								xref.select();
								return;
						}
					}
				}
			}
		}
	}
	document.forms['frmMain'].submit();
}

function selproduct(xid){
	document.location.href = "product.asp?lang=" + sLang00 + "&id=" + xid;
}

function showsizing(xpage){
	sURL = "http://www.marketingisland.com/mi/tmm/en/sizing/" + xpage + ".asp";
	showwin(sURL,640,500);
}

function showzoom(sID,sLang){
	sURL = "image_zoom.asp?id=" + sID + "&lang=" + sLang;
	showwin(sURL,720,560);
}

function showstatushelp(sLang){
	sURL = "status_help.asp?lang=" + sLang;
	showwin(sURL,640,540);
}

function showwin(sURL0,iW,iH){
	xpos = (screen.availWidth - iW)/2;
	ypos = ((screen.availHeight - iH)/2) - 40;

	swin = open(sURL0,"swindow","toolbar=no,location=no,directories=no,dependent=yes," + 
		"status=no,menubar=yes,scrollbars=yes,resizable=yes,width=" + iW + ",height=" + iH + ",top=" + ypos + ",left=" + xpos);
	swin.focus()
}

function addwishlist(xid,xst){
	sURL = "xt_product_wishlist.asp?lang=" + sLang00 + "&id=" + xid + "&st=" + xst;
	document.location.href = sURL;
}

function sendInfo(xid,xlang){
	sURL = "product_email_info.asp?id=" + xid + "&lang=" + xlang;
	showwin(sURL,620,560);
}

function sPDF(sURL){
	if (sURL != ""){
		iwin = open(sURL,"IWindow","toolbar=no,location=no,directories=no,dependent=yes," + 
			"status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=760,height=560,top=10,left=20");
		iwin.focus();
	}
}
