//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		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)
{ var element, retval, qty, iItemqty, iTotalqty;

	element = "document." + frm + ".qty" + index + ".value";
	qty = eval(element);
	retval=IsNumeric(qty)
	if(retval == 1)
	{
		alert("Enter valid quantity");
		eval("document." + frm + ".qty" + index + ".value=1");
		eval("document." + frm + ".qty" + index + ".focus()");
		return;
	}
	iItemqty = qty*1
	if ((iMaxCount != "") && (bMaxItem.toLowerCase()=="true")){
		iTotalqty = parseInt(sCartItems)
		if((iItemqty + iTotalqty)>parseInt(iMaxCount)){
			alert("Total quantity in the cart can not exceed " + iMaxCount);
			eval("document." + frm + ".qty" + index + ".value=1");
			//eval("document." + frm + ".qty" + index + ".focus()");
			return;
		}
	}
	document.frmAdditem.qty.value = qty;
	document.frmAdditem.ic.value = code;
	document.frmAdditem.type.value=type;
	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)

//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		Description			: This function used to format the contents in the field.
//	@		                	If value is 100.0 , this funciton will change it to 100.00.
//	@		Pages Affected  : Shipcalculator.asp
//  @		Function Name		: setFormat(field)									
//	@		Input Parameters: field = name of the form and fieldto be formatted
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

function setFormat(field){
		var i, idiff,strval;
		var m_Field = eval("document." + field);
  	if(m_Field.value.indexOf(".") < 0)
			m_Field.value = m_Field.value + ".00";
		if(m_Field.value.length-m_Field.value.indexOf(".") == 2)
			m_Field.value = m_Field.value + "0";
		else if(m_Field.value.length-m_Field.value.indexOf(".") > 3){
			m_Field.value=m_Field.value.substring(0,m_Field.value.indexOf(".") +3)		
		}
		
	  idiff=10-m_Field.value.length	
		strval=""
		for(i=0;i< 10;i++)	{
			strval=strval+ " "  
			if (i==idiff-1){
				strval=strval+m_Field.value;
				break;
			}
		}
}
// End of the function setFormat(field)

//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		Description			: This function used to format numbers.
//	@		                	If we pass 100 , this funciton will return 100.00.
//	@	  Pages Affected  : Shipcalculator.asp
//  @		Function Name		: formatValue(value)									
//	@		Input Parameters: value = then number to be formatted
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
function formatValue(value){
	return Math.round(value*100)/100;
}
// End of the function formatValue(value)




	
	
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		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.asp (All items except Music itmes)
//  @		Function Name		: preprocess()									
//	@		Input Parameters: Value to be tested									
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@


function preprocess(){ 
	var retval, iItemqty, iTotalqty, qty;
	qty=document.frmAdd.qty.value
	retval=IsNumeric(qty)
	if(retval == 1)	{
		alert("Enter valid quantity");
		document.frmAdd.qty.value=1;
		document.frmAdd.qty.focus();
		return;
	}
	iItemqty = qty*1
	if ((iMaxCount != "") && (bMaxItem.toLowerCase()=="true")){
		iTotalqty = parseInt(sCartItems)
		if((iItemqty + iTotalqty)>parseInt(iMaxCount)){
			alert("Total quantity in the cart can not exceed " + iMaxCount);
			document.frmAdd.qty.value=1;
			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();
	
}
// End of the function preprocess()


//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		Description			: (this function is used by only music items in itemdesc.asp. At item.asp preprocess() is used
//	@                                     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.asp (Music Items)
//  @		Function Name		: preprocessKaset()									
//	@		Input Parameters: Value to be tested									
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@


function preprocessKaset(){ 
	var retval, iItemqty, iTotalqty, qty;
	qty=document.frmAdd.qty.value
	retval=IsNumeric(qty)
	if(retval == 1)	{
		alert("Enter valid quantity");
		document.frmAdd.qty.value=1;
		document.frmAdd.qty.focus();
		return;
	}
	iItemqty = qty*1
	if ((iMaxCount != "") && (bMaxItem.toLowerCase()=="true")){
		iTotalqty = parseInt(sCartItems)
		if((iItemqty + iTotalqty)>parseInt(iMaxCount)){
			alert("Total quantity in the cart can not exceed " + iMaxCount);
			document.frmAdd.qty.value=1;
			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.Ic.value= document.frmAdd.Ic.value + "H"
	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)
{
	//iTotalqty = parseInt(sCartItems)
	iTotalqty = 100;
	if ((iMaxCount != "") && (bMaxItem.toLowerCase()=="true")){
		if(iTotalqty >= parseInt(iMaxCount)){
			alert("Total quantity in the cart can not exceed " + iMaxCount);
			return;
		}
	}
	document.frmUpgrade.ic.value = itemcode;
	document.frmUpgrade.submit();
}
// End of the function UpgradeBuy(itemcode)

function doModifyProduct(itemNo)
{
	thisForm = document.forms['frmdocumentdItems'];
	thisForm.action = 'icy_modifyItem.asp';
	doSingleSell(null,null,itemNo);
}