
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		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)


//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		Description			: This function is for submitting the form automatically when user  
//	@											selects a subcategory from list-box.
//  @   Pages Affected  : items, itemdesc
//  @		Function Name		: submitlist()									
//	@		Input Parameters: null
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

function submitlist(sBc)
{
	var value,sCatText;
	value=document.frmList.lstSubCategory.options[document.frmList.lstSubCategory.selectedIndex].value;
	sCatText=document.frmList.lstSubCategory.options[document.frmList.lstSubCategory.selectedIndex].text;
	if(value != "0")
	{
		document.frmList.action = sNonSecurePath + "items.asp?Cc=" + value + "&CatName=" + sCatText + "&Bc="+sBc+"&BrandName="+sBrandName+"&Tp="+sTpCatalog+"&iTpStatus=1";
		document.frmList.submit();
	}
}
// End of the function submitlist()

	
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		Description			: This function checks	whether the entered qty is correct or not.
//  @                   : If any related items is checked then it is passed thru hidden 
//  @                   : field called chkitems with ',' as seperator
//  @   Pages Affected  : Itemdesc
//  @		Function Name		: preprocess()									
//	@		Input Parameters: Value to be tested									
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@


function preprocess(iWishList, iUnits){ 
	var retval, iItemqty, iTotalqty, qty, iIndex, iRelatedQty;
	qty=document.frmAdd.qty.value;
	retval=IsNumeric(qty);
	iRelatedQty = 0;
	if(retval == 1)	{
		alert(getMessage("iValidQuantity"));
		document.frmAdd.qty.value=iUnits;
		document.frmAdd.qty.focus();
		return;
	}
	
	if (iWishList == 0){
		iItemqty = qty*1
		if ((iMaxCount != "") && (bMaxItem.toLowerCase()=="true")){
			iTotalqty = parseInt(sCartItems)
			if (document.frmRelated){
				if(document.frmRelated.chkItems.length > 1){
					for (iIndex = 0; iIndex < document.frmRelated.chkItems.length; iIndex++){
						if (document.frmRelated.chkItems[iIndex].checked){
							iRelatedQty =  iRelatedQty + parseInt(document.frmRelated.chkItems[iIndex].value.split(",")[1]);
						}
					}
				}
				else{
					if (document.frmRelated.chkItems.checked){
						iRelatedQty =  parseInt(document.frmRelated.chkItems.value.split(",")[1]);
					}
				}
			}
			if((iItemqty + iTotalqty + iRelatedQty)>parseInt(iMaxCount)){
				alert(getMessage("iTotalQtyExceed") + " " + iMaxCount);
				document.frmAdd.qty.value=iUnits;
				document.frmAdd.qty.focus();
				return;
			}
		}
		for (count=0;count<document.forms.length;count++){
				if (document.forms[count].name=="frmRelated"){	
					var sItemList="";
					for(index=0;index<(document.frmRelated.elements.length);index++) {
						if(document.frmRelated.elements[index].checked){
							sItemList+=document.frmRelated.elements[index].value + "," ;
							iItemqty++;				
						}
					}
					sItemList = sItemList.substring(0,sItemList.length-1)
					document.frmAdd.chkItems.value = sItemList;
				}
		}
		document.frmAdd.submit();
	}
	else{
		document.frmAdd.action = sNonSecurePath + "includes/AddWishitem.asp?Tp=" + sTpCatalog
		document.frmAdd.submit();
	}
}
// End of the function preprocess()


//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		Description			: This function is used to submit the upgrade items form.
//  @   Pages Affected  : Itemdesc
//  @		Function Name		: UpgradeBuy(itemcode)									
//	@		Input Parameters: itemcode = Item Code									
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

function UpgradeBuy(itemcode,iUnits)
{
	iTotalqty = parseInt(sCartItems)
	if ((iMaxCount != "") && (bMaxItem.toLowerCase()=="true")){
		if(iTotalqty >= parseInt(iMaxCount)){
			alert(getMessage("iTotalQtyExceed") + " " + iMaxCount);
			return;
		}
	}
	document.frmUpgrade.ic.value = itemcode;
	document.frmUpgrade.qty.value = iUnits;
	document.frmUpgrade.submit();
}
// End of the function UpgradeBuy(itemcode)

