//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		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			: 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.frmAdd.SelMatrixAtt1" + iItemCount + ".options[document.frmAdd.SelMatrixAtt1" + iItemCount + ".selectedIndex].value"); 
	strselected = strselected + eval("document.frmAdd.SelMatrixAtt2" + iItemCount + ".options[document.frmAdd.SelMatrixAtt2" + iItemCount + ".selectedIndex].value"); 
	
	len = document.frmAdd.elements.length;
	for(iCount=0;iCount<=parseInt(len)-1;iCount++){
		if((document.frmAdd.elements[iCount].name.substring(0,13) == "SelMatrixAtt3") && (document.frmAdd.elements[iCount].name.substring(13,14) == iItemCount))
			strselected = strselected + eval("document.frmAdd.SelMatrixAtt3" + iItemCount + ".options[document.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			: This function checks whether the attributes are unique 
//  @   Pages Affected  : Itemmatrix
//  @		Function Name		: attribCheck()
//	@		Input Parameters: iAttrib3 = (returns 1 if 3rd attribute is present, else returns 0)
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

		function attribCheck(iAttrib3){
			var sAttrib1,sAttrib2,sAttrib3;
			sAttrib1=document.frmMatrix.Attrib1.options[document.frmMatrix.Attrib1.selectedIndex].value;
			sAttrib2=document.frmMatrix.Attrib2.options[document.frmMatrix.Attrib2.selectedIndex].value;
			if(sAttrib1==sAttrib2){
				alert("Attributes are same. Please select unique attributes");
				return false;
			}
			if(iAttrib3=="1"){
				sAttrib3=document.frmMatrix.Attrib3.options[document.frmMatrix.Attrib3.selectedIndex].value;
				if((sAttrib3==sAttrib1)||(sAttrib3==sAttrib2)){
					alert("Attributes are same. Please select unique attributes");
					return false;
				}
			}
			document.frmMatrix.submit();
		}
// End of the function attribCheck(iAttrib3)

//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		Description			: This function gets the selected matrix Items 
//  @   Pages Affected  : Itemmatrix
//  @		Function Name		: multiselect()
//	@		Input Parameters: type = Item type(matrix Item),attribcode3=attribcode3
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

function multiselect(type,attribcode3)
{ 
	var len, iIndex, attributes, qty, code, quantity, retval, attribute_codes,iTotalqty,iItemqty;

	iTotalqty=0;
	iItemqty=0;
	qty = "";
	code = "";
	attributes = "";
	attribute_codes = "";
		
	len = document.frmAdd.elements.length;
	for(iIndex=0;iIndex<=parseInt(len)-1;iIndex++){	
		if(document.frmAdd.elements[iIndex].type == "checkbox"){
			if(document.frmAdd.elements[iIndex].checked){
				arr = document.frmAdd.elements[iIndex].value.split("*");
				quantity = eval("document.frmAdd.qty" + arr[0] + ".value")
				retval=IsNumeric(quantity)
				if(retval == 1){
					alert("Enter valid quantity");
					eval("document.frmAdd.qty" + arr[0] + ".value=1");
					eval("document.frmAdd.qty" + arr[0] + ".focus()");
					return;
				}
				qty = qty + quantity + "*";
				code = arr[1];
				attributes = attributes + arr[2] + "*";
				iItemqty=iItemqty+parseInt(quantity);
							
			}	  
		}	
	}
	if(code == ""){
		alert("Please select one or more Items");
		return;
	}

	if ((iMaxCount != "") && (bMaxItem.toLowerCase()=="true")){
		iTotalqty = parseInt(sCartItems)
		if((iItemqty + iTotalqty)>parseInt(iMaxCount)){
			alert("Total quantity in the cart can not exceed " + iMaxCount);
			return;
		}
	}
	attribute_codes = attribute_codes + (document.frmMatrix.Attrib1.selectedIndex + 1) + "*";
	attribute_codes = attribute_codes + (document.frmMatrix.Attrib2.selectedIndex + 1) + "*";
	if(attribcode3 != "") 
		attribute_codes = attribute_codes + (document.frmMatrix.Attrib3.selectedIndex + 1);
	else
		attribute_codes = attribute_codes + "";
		
	document.frmAdditem.qty.value = qty;
	document.frmAdditem.ic.value = code;
  document.frmAdditem.type.value=type;
  document.frmAdditem.attributes.value = attributes;
  document.frmAdditem.attribute_codes.value = attribute_codes;
  document.frmAdditem.submit();
}
// End of the function multiselect(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 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.frmList.lstSubCategory.options[document.frmList.lstSubCategory.selectedIndex].value;
	if(value != "0")
	{
		document.frmList.action = "/items.asp?Cc=" + value;
		document.frmList.submit();
	}
}
// End of the function submitlist()

//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		Description			: This function is called to choose the Catalog from the list.
//  @   Pages Affected  : PowerSearch
//  @		Function Name		: ChangeCatalog()									
//	@		Input Parameters: null							
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

function ChangeCatalog()
{
  strURL = "/powersearch.asp?Tp=" + document.frmPSearch.shop.options[document.frmPSearch.shop.selectedIndex].value;
  window.location.href = strURL;
}
// End of the function ChangeCatalog()
	
	
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		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)
	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)

	
	
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		Description			: This function is used to delete a particular item from cart.
//  @   Pages Affected  : Viewcart
//  @		Function Name		: DeleteFromCart(itemcode, itemtype, tpcode)									
//	@		Input Parameters: itemcode = Item Code, itemtype = Item Type, tpcode = TpCode									
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

function DeleteFromCart(itemcode, itemtype, tpcode)
{
	if(confirm("Are you sure you want to remove this item from your shopping cart."))
	{
		var docForm = document.forms["frmDelete"];
		docForm.elements["itemcode"].value = itemcode;
		docForm.elements["itemtype"].value = itemtype;
		docForm.elements["tpcode"].value = tpcode;
		docForm.submit();
		return false;
		//document.frmDelete.itemcode.value = itemcode;
		//document.frmDelete.itemtype.value = itemtype;
		//document.frmDelete.tpcode.value = tpcode;
		//document.frmDelete.submit();
	}
}
// End of the function DeleteFromCart(itemcode, itemtype, tpcode)



//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		Description			: This function is used to empty the cart.
//  @   Pages Affected  : Viewcart
//  @		Function Name		: EmptyCart()									
//	@		Input Parameters: Null									
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

function EmptyCart()
{
	if(confirm("Are you sure you want to empty your shopping cart."))
	{
	var docForm = document.forms["frmDelete"];
	docForm.elements["todo"].value = "empty";
	docForm.submit();
	//document.forms.frmDelete.todo.value = "empty";
	//document.frmDelete.submit();
	}
}
// End of the function EmptyCart()


//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		Description			: This function is used to update the cart contents, as changed 
//	@											by the user.
//  @   Pages Affected  : Viewcart
//  @		Function Name		: UpdateCart(Index)									
//	@		Input Parameters: Index = Total no. of items									
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

function UpdateCart(Index)
{
	var count,qty,retval,iItemqty;
	iItemqty=0
	for(count = 1;count<=Index;count++)
	{		
		qty = eval("document.frmCartContents.qty" + count + ".value")
		var validate=/(^\d+$)/
		if (validate.test(qty) == false)
		{
			alert("Enter valid quantity");
			//eval("document.frmCartContents.qty" + count + ".value=1");
			eval("document.frmCartContents.qty" + count + ".focus()");
			return;
		}
		qty=qty*1
		iItemqty=iItemqty+qty
	}
	if ((iMaxCount != "") && (bMaxItem.toLowerCase()=="true")){
		if(iItemqty > parseInt(iMaxCount)){
			alert("Total quantity in the cart can not exceed " + iMaxCount);
			return;
		}
	}
	document.frmCartContents.submit();
}
// End of the function UpdateCart(Index)


//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		Description			: This function is called whenever user clicks prev or next navigation.
//  @   Pages Affected  : pSearchresult
//  @		Function Name		: submitSearch(iPageNo)									
//	@		Input Parameters: iPageNo	= PageNo								
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

function submitSearch(iPageNo){	
	document.frmPSearch.PageNo.value= iPageNo;
	document.frmPSearch.submit();
}
// End of the function submitSearch(iPageNo)






//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		Description			: This function is called whenever user clicks prev or next navigation.
//  @   Pages Affected  : pSearchresult
//  @		Function Name		: submitSearchMini(iPageNo)									
//	@		Input Parameters: miPageNo	= mPageNo								
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

function submitNextMini(miPageNo){	
	document.frmMini.mPageNo.value= miPageNo;
	document.frmMini.submit();
}
// End of the function submitSearch(miPageNo)


//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		Description			: This function is called before submiting page, to validate
//	@											the min & max price.
//  @   Pages Affected  : PowerSearch
//  @		Function Name		: PowerSearchVal()									
//	@		Input Parameters: null							
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

function PowerSearchVal(sCustTypeInt, sCustTypeDate){
	var len,iIndex,bCriteria,fMinval,fMaxval,value ;
	
	var validate=/(^\d+$)/
	if(sCustTypeInt!=""){
		sCustTypeInt = sCustTypeInt.substring(0,sCustTypeInt.length-1) 
		arr = sCustTypeInt.split(",");
		for(iIndex=0;iIndex<=arr.length-1;iIndex++){
			objField=eval("document.frmPSearch." + arr[iIndex]) 
			if(objField.value!=""){
				if(!(validate.test(objField.value)))  {
						alert("Please enter a valid integer.");
						objField.focus();
						objField.select();
						return false;
				}
			}	
		}	
	}
	if(sCustTypeDate!=""){
		sCustTypeDate = sCustTypeDate.substring(0,sCustTypeDate.length-1) 
		arr = sCustTypeDate.split(",");
		for(iIndex=0;iIndex<=arr.length-1;iIndex++){
			smonth=eval("document.frmPSearch." + arr[iIndex]+ "month.options[document.frmPSearch." + arr[iIndex]+ "month.selectedIndex].value")
			sday=eval("document.frmPSearch." + arr[iIndex]+ "day.options[document.frmPSearch." + arr[iIndex]+ "day.selectedIndex].value")
			syear=eval("document.frmPSearch." + arr[iIndex]+ "year.options[document.frmPSearch." + arr[iIndex]+ "year.selectedIndex].value")
			var sdate=new Date(syear, smonth ,sday)
			var sDefaultDate=new Date(1995,1,1)
			if((sdate-sDefaultDate)!=0)
				eval("document.frmPSearch.Txt" + arr[iIndex] + ".value=smonth+'/'+sday+'/'+syear")
			else
				eval("document.frmPSearch.Txt" + arr[iIndex] + ".value=''")
		}
	}
	
	bCriteria=false;
	len = document.frmPSearch.elements.length;
	for(iIndex=0;iIndex<=parseInt(len)-1;iIndex++){	
		if(document.frmPSearch.elements[iIndex].type == "text"){
			if(document.frmPSearch.elements[iIndex].value != ""){
				if(document.frmPSearch.elements[iIndex].value.charAt(0)==" "){
					alert("Search field should not start with spaces.");
					document.frmPSearch.elements[iIndex].focus();
					return false;
				}
				bCriteria = true;
			}
		}
		
		if(document.frmPSearch.elements[iIndex].type == "hidden"){
			if(document.frmPSearch.elements[iIndex].value != "")
				bCriteria = true;
		}
		if(document.frmPSearch.elements[iIndex].type == "checkbox"){
			if(document.frmPSearch.elements[iIndex].checked)
				bCriteria = true;
		}
		sFldname=document.frmPSearch.elements[iIndex].name
		if((sFldname == "selCategory")||(sFldname == "selBrand")||(sFldname == "selManufacturer")){
			if(document.frmPSearch.elements[iIndex].options[document.frmPSearch.elements[iIndex].selectedIndex].value != "")
				bCriteria = true;
		}
		if(bCriteria) break;
	}
	
	if(! bCriteria)	{
		alert("Please enter a text to be searched.");
		document.frmPSearch.txtKey.focus();
		return false;
	}
	
	fMinval=document.frmPSearch.txtMin.value
	fMaxval=document.frmPSearch.txtMax.value
	
	if(document.frmPSearch.txtMin.value.length > 0)
	{ 
		 retval=IsFloat(fMinval);
		
		if(! retval)
		{
				alert("Please enter a valid price.");
				document.frmPSearch.txtMin.focus();
				document.frmPSearch.txtMin.select();
				return false;
		}
		
			fMinval=parseFloat(fMinval);
		
		
	}
	if(document.frmPSearch.txtMax.value.length > 0)
	{   
	  
		 retval=IsFloat(fMaxval);
		if(! retval)
		{
			alert("Please enter a valid price.");
			document.frmPSearch.txtMax.focus();
			document.frmPSearch.txtMax.select();
			return false;
		}
		
			fMaxval=parseFloat(fMaxval);
	
		
	}
	if(fMaxval < fMinval)
	{
		alert("Maximum Price should be greater than Minimum Price");
		document.frmPSearch.txtMax.focus();
		document.frmPSearch.txtMax.select();
		return false;
		
	}
	document.frmPSearch.sManDesc.value  = document.frmPSearch.selManufacturer.options[document.frmPSearch.selManufacturer.selectedIndex].text;
	document.frmPSearch.sBrandDesc.value = document.frmPSearch.selBrand.options[document.frmPSearch.selBrand.selectedIndex].text;
	document.frmPSearch.sCatDesc.value  =  document.frmPSearch.selCategory.options[document.frmPSearch.selCategory.selectedIndex].text;
	document.frmPSearch.submit();
	
}

// End of the function powersearchval()

//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		Description			: This function is called before submiting page, to validate
//	@											float value.
//  @   Pages Affected  : PowerSearch
//  @		Function Name		: IsFloat()									
//	@		Input Parameters: price value(Minimum or Maximum)							
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@


function IsFloat(value)
{
		pattern = /^(\d+)(\.){0,1}(\d*)$/
		return pattern.test(value) ;
}

// End of the function IsFloat()


//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		Description			: This function is called when Delete or Retrieve link is clicked.
//	@											It is used to change the action depending on the link clicked.
//  @   Pages Affected  : Retreivecart
//  @		Function Name		: RetrieveCart(getcart,todo)									
//	@		Input Parameters: getcart = cartid,todo = 1(Delete) or 0(Retrieve)							
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

function RetrieveCart(getcart,todo)
{
	if(todo=="1")
		if(confirm("Are you sure you want to delete this saved cart."))
			document.frmRetrieveCart.action = "/retrievecart.asp?action=DEL";
		else
			return;
	else
		document.frmRetrieveCart.action = "/retrievecart.asp?action=RET";
	document.frmRetrieveCart.PrevCartID.value =  getcart;
	document.frmRetrieveCart.submit();
}
// End of the function RetrieveCart(getcart,todo)


//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		Description			: This function is called when New cart name and Email id is entered.
//	@											It validates the Name and the Email id.
//  @   Pages Affected  : SaveCart
//  @		Function Name		: SaveCart()									
//	@		Input Parameters: null							
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

function SaveCart(){
	if (document.frmSaveCart.CARTNAME.value == ""){
    alert ("Please enter Cart Name");
		document.frmSaveCart.CARTNAME.focus();
		return;
	}
	if (document.frmSaveCart.CARTNAME.value.charAt(0)==" "){
		alert("Cart name should not start with spaces.");
		document.frmSaveCart.CARTNAME.focus();
		return;
	}
	// ### Validating email.
	ret_val = IsEmail(document.frmSaveCart.EMAIL.value);
	if (ret_val == 1){
		document.frmSaveCart.EMAIL.focus();
		document.frmSaveCart.EMAIL.select();
		return;
	}
	document.frmSaveCart.action = "/savecart.asp?action=SN&saved=1"
	document.frmSaveCart.submit();
}
// End of the function SaveCart()



//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		Description			: This function is called when when existing cart name is selected.
//  @   Pages Affected  : SaveCart
//  @		Function Name		: RestoreCart()									
//	@		Input Parameters: null							
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

function RestoreCart()
{
	if (document.frmSaveCart.CARTLIST.options[document.frmSaveCart.CARTLIST.selectedIndex].value == 0 )	{
		alert ("Please choose the Cart Name");
		document.frmSaveCart.CARTLIST.focus();
	}	
	else	{	
		document.frmSaveCart.action = "/savecart.asp?action=SE&saved=1"
		document.frmSaveCart.submit();
	}
}
// End of the function SaveCart()


//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		Description			: This function is called to validate the zipcode.
//  @   Pages Affected  : ShipCalculator
//  @		Function Name		: ZipCode_validate()									
//	@		Input Parameters: null							
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

function ZipCode_validate(bUseDestZone)
{	
	var retval;
	// ### Validating address type
	if (document.frmShip.RESI.options[document.frmShip.RESI.selectedIndex].value == 0)
	{
		alert("Please select address type.")
		document.frmShip.RESI.focus();
		return false;
	}
	if(document.frmShip.zipcode.value != ""){	
		if(bUseDestZone.toUpperCase() !="TRUE") {
			retval=IsNumeric(document.frmShip.zipcode.value)
			if(retval == 1)	{
				alert("Please enter valid zipcode");
				document.frmShip.zipcode.focus();
				document.frmShip.zipcode.select();
				return false;
			}
		}
	}
	if((bUseDestZone.toUpperCase()=="FALSE") && (document.frmShip.zipcode.value == ""))	
		alert("Please enter the zipcode");
			
	if(bUseDestZone.toUpperCase()=="TRUE"){
		// ### Validating City
		if(document.frmShip.City.value != "" && (!( isAlphanumeric(document.frmShip.City.value,"1"))) ){
				document.frmShip.City.focus();
				document.frmShip.City.select();
				return false;
		}
		// ### Validating State/ Province
		if(document.frmShip.State.value != "" && (!( isAlphanumeric(document.frmShip.State.value,"1"))) ){	
				document.frmShip.State.focus();
				document.frmShip.State.select();
				return false;
		}
	}	
	document.frmShip.submit();
}
// End of the function ZipCode_validate()


//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		Description			: This function is called when a shipping method is selected.
//  @		Pages Affected  : ShipCalculator
//  @		Function Name		: ShipCharge_Calculate()									
//	@		Input Parameters: null							
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

function ShipCharge_Calculate()
{	
	var total, i
	for(i=0;i<=document.frmCost.radsel.length-1;i++){
		if(document.frmCost.radsel[i].checked)
		{
			tVal = parseFloat(document.frmCost.radsel[i].value);
			document.frmCost.shipprice.value = formatValue(tVal);
			setFormat("frmCost.shipprice");
			total = parseFloat(tVal) + parseFloat(sCartTotal);
			document.frmCost.total.value = formatValue(total);
			setFormat("frmCost.total");
			break;
		}
	}
}
// End of the function ShipCharge_Calculate()

//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		Description			: Function is to validate the alphanumeric characters and  string.  
//  @  		Pages Affected 		: Shipcalculator
//  @		Function Name		: isAlphanumeric(str,cSpace)
//	@		Input Parameters	: formname = name of the form
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

function isAlphanumeric(str,cSpace){
    var sSpacepat = /^(((\w+)[\s,\-*\.]*)+)$/
     var sPat = /^(((\w+)[*,\-\.]*)+)$/
     if (cSpace=="1"){
		if(!(sSpacepat.test(str)))
		   {
			 alert("Please enter a valid text.")
			 return false;
	       }	
		}
	  else{
		
		if(!(sPat.test(str)))  
			{
				alert("Please enter a valid text.")
				return false;
	        }
	        }
     return true;
}
// End of the function isAlphanumeric(str,cSpace)

//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		Description			: This function changes the no. of days dynamically according to  
//  @											the month and the year.
//	@	  Pages Affected  : powersearch.asp
//  @		Function Name		: DateValidate(which)									
//	@		Input Parameters: which = field
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

function DateValidate(which)
{
	var sel = eval("document.frmPSearch." + which + "day.selectedIndex");
	var i=eval("document.frmPSearch." + which + "month.options[document.frmPSearch." + which + "month.selectedIndex].value");
	var j=eval("document.frmPSearch." + which + "year.options[document.frmPSearch." + which + "year.selectedIndex].value");
	var k;
	if(i=="1" || i=="3" || i=="5" || i=="7" || i=="8" || i=="10" || i=="12")
	{
		eval("document.frmPSearch." + which + "day.length=31");
		for(k=28;k<=30;k++)
		{
			eval("document.frmPSearch." + which + "day.options[" + k + "].value=" + parseInt(k+1));
			eval("document.frmPSearch." + which + "day.options[" + k + "].text=" + parseInt(k+1));
		}
	}
	if(i=="4" || i=="6" || i=="9" || i=="11")
	{
		eval("document.frmPSearch." + which + "day.length=30");
		for(k=28;k<=29;k++)
		{
			eval("document.frmPSearch." + which + "day.options[" + k + "].value=" + parseInt(k+1));
			eval("document.frmPSearch." + which + "day.options[" + k + "].text=" + parseInt(k+1));
		}
	}
	var mydate = new Date();
	if(i==2)
	{
		mydate.setDate(1);
		mydate.setYear(j);
		mydate.setMonth(1);
		mydate.setDate(31);
		var k=31-mydate.getDate();
		eval("document.frmPSearch." + which + "day.length=" + k);
		if((k==29) || (k==28))
		{
			eval("document.frmPSearch." + which + "day.options[" + (k-1) + "].value=" + k);
			eval("document.frmPSearch." + which + "day.options[" + (k-1) + "].text=" + k);
		}
	}
	
	if((sel+1) > eval("document.frmPSearch." + which + "day.length"))
	{
		eval("document.frmPSearch." + which + "day.selectedIndex=document.frmPSearch." + which + "day.length-1");
	}
}
// End of the function DateValidate(which)


//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		Description			: Validation for EMail									@
//  @		Function Name		: IsEmail()												@
//	@		Input Parameters	: Value to be tested									@
//	@		Return Value		: 0 - Success											@
//	@							  1 - Failure											@
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
function IsEmail(strEmail)
{
var intReturn =1;
var emailPat=/^(.+)@(.+)$/
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
var validChars="\[^\\s" + specialChars + "\]"
var quotedUser="(\"[^\"]*\")"
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
var atom=validChars + '+'
var word="(" + atom + "|" + quotedUser + ")"
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var matchArray=strEmail.match(emailPat)
	if (matchArray==null) {
		alert("Please enter a valid Email address.");
		return intReturn;
	}
var user=matchArray[1]
var domain=matchArray[2]
if (user.match(userPat)==null) {
    alert("Please enter a valid Email address.");
    return intReturn;
}
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		// this is an IP address
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				alert("Please enter a valid Email address.");
			return intReturn;
			}
		}
		intReturn=0;
		return intReturn;
	}
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("Please enter a valid Email address.");
    return intReturn;
}
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	if (domArr[domArr.length-1].length<2 || 
		domArr[domArr.length-1].length>3) {
	alert("Please enter a valid Email address.");
	return intReturn;
	}
var len=domArr.length	
if (len<2) {
   var errStr="Please enter a valid Email address."
   alert(errStr)
   return intReturn;
}
intReturn=0;
return intReturn;
}
//	End of the function IsEmail(strEmail)
