//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		Description			: This function checks whether the entered qty is correct or not.
//  @   Pages Affected  : Index,Items, searchresult,Psearchresult
//  @		Function Name		: preproc(frm,index,code,type)									
//	@		Input Parameters: frm = Form Name, index = Index value, code = Item Code, type = Item Type
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

function preproc(frm,index,code,type,eqCode,iWishList, iUnits)
{ var element, retval, qty, iItemqty, iTotalqty;

	element = "document." + frm + ".qty" + index + ".value";
	qty = eval(element);
	retval=IsNumeric(qty);
	
	if(retval == 1)
	{
		alert(getMessage("iValidQuantity"));
		eval("document." + frm + ".qty" + index + ".value=iUnits");
		eval("document." + frm + ".qty" + index + ".focus()");
		return;
	}
	
	
	if (iWishList == 0){
		iItemqty = qty*1;
		if ((iMaxCount != "") && (bMaxItem.toLowerCase()=="true")){
			iTotalqty = parseInt(sCartItems);
			if((iItemqty + iTotalqty)>parseInt(iMaxCount)){
				alert(getMessage("iTotalQtyExceed") +" "+ iMaxCount);
				eval("document." + frm + ".qty" + index + ".value=iUnits");
				//eval("document." + frm + ".qty" + index + ".focus()");
				return;
			}
		}
	document.frmAdditem.qty.value = qty;
	document.frmAdditem.ic.value = code;
	document.frmAdditem.type.value=type;
	document.frmAdditem.EqCode.value=eqCode;
	document.frmAdditem.action = sNonSecurePath+"includes/add_item.asp?Tp="+sTpCatalog;
	//document.frmAdditem.submit();

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
		  {
	document.frmAdditem.submit();
	}
	else
		{
		var request;
		var queryString; //will hold the POSTed data

		queryString="";
		var frm = document.frmAdditem;
		var numberElements = frm.elements.length;
		for(var i = 0; i < numberElements; i++) {
			if(i < numberElements-1) {
			queryString += frm.elements[i].name+"="+
			encodeURIComponent(frm.elements[i].value)+"&";
			} else {
			queryString += frm.elements[i].name+"="+
			encodeURIComponent(frm.elements[i].value);
			}

		}

		xmlHttp.open("GET","includes/add_item.asp?"+queryString ,true);
		xmlHttp.send(null);
		
		var cartnum=parseInt(document.getElementById("cartnum").innerHTML) + 1;
		document.getElementById("cartnum").innerHTML=cartnum;
		alert('The item has been added!');	
		}

	
	}
	else{
	document.frmAdditem.qty.value = qty;
	document.frmAdditem.ic.value = code;
	document.frmAdditem.EqCode.value=eqCode;
	document.frmAdditem.action = sNonSecurePath+"includes/AddWishitem.asp?Tp="+sTpCatalog;
	document.frmAdditem.submit();
	}
}
// End of the function preproc(frm,index,code,type)


//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		Description			: Function IsNumeric checks whether the entered value is a 
//	@											numeric and greater than Zero
//  @		Function Name		: IsNumeric(value)									
//	@		Input Parameters: value to be tested
//	@		Return Value		: 0 - Success	  1 - Failure			
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

function IsNumeric(value)
{
	var validate=/(^\d+$)/
	if ((validate.test(value)) && (value > 0))
		return 0; 
	else
		return 1; 
}
// End of the function IsNumeric(value)

