
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		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(getMessage("iUniqueAttributes"));
				return false;
			}
			if(iAttrib3=="1"){
				sAttrib3=document.frmMatrix.Attrib3.options[document.frmMatrix.Attrib3.selectedIndex].value;
				if((sAttrib3==sAttrib1)||(sAttrib3==sAttrib2)){
					alert(getMessage("iUniqueAttributes"));
					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(getMessage("iValidQuantity"));
					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(getMessage("iSelectItems"));
		return;
	}

	if ((iMaxCount != "") && (bMaxItem.toLowerCase()=="true")){
		iTotalqty = parseInt(sCartItems)
		if((iItemqty + iTotalqty)>parseInt(iMaxCount)){
			alert(getMessage("iTotalQtyExceed") + " " + 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 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()

