
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		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.all.' + frm + '.qty' + index + '.value';
	qty = eval(element);
	retval=IsNumeric(qty)
	if(retval == 1)
	{
		alert('Enter valid quantity');
		eval('document.all.' + frm + '.qty' + index + '.value=1');
		eval('document.all.' + 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.all.' + frm + '.qty' + index + '.value=1');
			//eval('document.all.' + frm + '.qty' + index + '.focus()');
			return;
		}
	}
	document.all.frmAdditem.qty.value = qty;
	document.all.frmAdditem.ic.value = code;
	document.all.frmAdditem.type.value=type;
	document.all.frmAdditem.submit();
}
// End of the function preproc(frm,index,code,type)

//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		Description			: This function gets the selected matrix attributes from the select box
//  @                      and checks whether the particular combination is present or not.
//  @   Pages Affected  : Items
//  @		Function Name		: getattribute(frm,index,code,type)									
//	@		Input Parameters: frm = Form Name, index = Index value, code = Item Code, type = Item Type
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

function getattribute(frm,index,code,type)
{ 
	var iIndex,matrix,arrTemp,strselected,len;
	iItemCount=index
	matrix = false;
	arrTemp = eval('arrSelItems' + iItemCount)
	strselected = eval('document.all.frmAdd.SelMatrixAtt1' + iItemCount + '.options[document.all.frmAdd.SelMatrixAtt1' + iItemCount + '.selectedIndex].value'); 
	strselected = strselected + eval('document.all.frmAdd.SelMatrixAtt2' + iItemCount + '.options[document.all.frmAdd.SelMatrixAtt2' + iItemCount + '.selectedIndex].value'); 
	
	len = document.all.frmAdd.elements.length;
	for(iCount=0;iCount<=parseInt(len)-1;iCount++){
		if((document.all.frmAdd.elements[iCount].name.substring(0,13) == 'SelMatrixAtt3') && (document.all.frmAdd.elements[iCount].name.substring(13,14) == iItemCount))
			strselected = strselected + eval('document.all.frmAdd.SelMatrixAtt3' + iItemCount + '.options[document.all.frmAdd.SelMatrixAtt3' + iItemCount + '.selectedIndex].value'); 
	}		
	for(iIndex=0;iIndex<=arrTemp.length-1;iIndex++){
		if(arrTemp[iIndex][1]==strselected){
			code = arrTemp[iIndex][0];
			matrix = true;
			break;
		}
	}
	if(matrix){
		preproc(frm,index,code,type)
		return;
	}
	else{
		alert('The selected matrix combination is not present');
		return;
	}
}
// End of the function getattribute(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.all.' + 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 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()
{
	var value;
	value=document.all.frmList.lstSubCategory.options[document.all.frmList.lstSubCategory.selectedIndex].value;
	if(value != '0')
	{
		document.all.frmList.submit();
	}
}
// End of the function submitlist()
