
var iMaxCount = "";
var bMaxItem = "false";


function buy(sForm,todo,bWish)
{
	top.status = sForm + "|gorko|" + bWish;
	var oForm = eval("document." + sForm + ";");
	var qty= eval("document." + sForm + ".qty.value;");

	var retval=IsNumeric(qty);
	if(retval == 1)	
	{
		alert("Enter valid quantity, please.");
		oForm.qty.value=1;
		oForm.qty.focus();
		return;
	}
	iItemqty = qty*1;
	//top.status = iItemqty;

	var bAccs = false;
	var sItemList="";
	for (count=0;count<document.forms.length;count++)	{
		top.status += document.forms[count].name;
		if (document.forms[count].name=="frmSpecial")	
		{	
			for(var ix=0;ix<(document.frmSpecial.elements.length);ix++) 
			{
			
				if(document.frmSpecial.elements[ix].checked)
				{
					sItemList+=String(document.frmSpecial.elements[ix].value) + ",1,0,";
					//sItemList=document.frmSpecial.elements[ix].value + ",0,0,";
					//iItemqty++;				
					//top.status = "*" + sItemList;
					//alert(document.frmSpecial.elements[ix].value + ",0,0");
				}
			
			}

		}
		//alert(sItemList);
		if (document.forms[count].name=="frmRelated")	{	
			try
			{
			for(index=1;index<(document.frmRelated.elements.length);index+=2) 
			{
				if(document.frmRelated.elements[index].checked){
					sItemList+=document.frmRelated.elements[index].value + ","
					//	+document.frmRelated.elements[index-2].value+ "," // qty
						+document.frmRelated.elements[index-1].value  // price
						+ "|";
				
					iItemqty++;				
				}
			}
			sItemList = sItemList.substring(0,sItemList.length-1)
			//ert(sItemList);
			//top.status = sItemList;
			document.frmAdd.chkItems.value = sItemList;
/*
			if(document.frmRelated.elements.length > 0 && sItemList == "")
			{
				if(!confirm("You haven't added any accessories! Continue to checkout anyway?"))
				{
					return(false);
				}
			}
		*/
			}
			catch(ex)
			{
				top.status = ex.message;
			}

		}
	}

//top.status = 'kit check on ' + sForm;
//top.status += document.frmAdd.Ic.value;
//alert("sForm:" + sForm);
	if(sForm != 'frmAdd' && sForm != 'frmKitInfo')
	{
			
		if(sForm == "frmMatrix")
		{
			if(oForm.selOpts.selectedIndex==0)
			{
				alert("Please select an option.");
				return(false);
			}
			var opts = oForm.selOpts[oForm.selOpts.selectedIndex].value;
			//alert("opts:" + opts);
			if(opts.indexOf("#") > 0)
			{
				var parts = opts.split("#");
				document.frmAdd.Ic.value = parts[0];
				document.frmKitInfo.ic.value = parts[0];
				document.frmAdd.qty.value = oForm.qty.value;
		
				//depItem  = parts[1];
				document.frmAdd.price.value = parts[2];
				//oSub.sku + "#" + this.parentItem.sku + "#" + oSub.optno;
				var configArr = document.frmKitInfo.configArr.value;
			
				document.frmKitInfo.configArr.value =  "" + parts[2]
					+ configArr.substring(1,configArr.length);
				
			}
		}	
		else
		{
			document.frmAdd.Ic.value = oForm.Ic.value;
			document.frmAdd.qty.value = oForm.qty.value;
			var configArr = document.frmKitInfo.configArr.value;
			document.frmKitInfo.ic.value = oForm.Ic.value;
			document.frmKitInfo.configArr.value = 
			
			oForm.idx.value + configArr.substring(1,configArr.length);

		}		
		
	}
	else
	{
		document.frmKitInfo.ic.value = document.frmAdd.Ic.value;
	}

	//p.status = bWish.toString();
	
	if(bWish)
	{
		//document.frmAdd.action = "/MB/includes/AddWishitem.asp?CartId=" + sCartId + "&Tp=";
		//document.frmAdd.action = "/MB/includes/AddWishitem.asp?Tp=";
		document.frmAdd.action = "/MB/includes/add_itemjs.asp?wish=T&Tp=";
		document.frmKitInfo.action = "/MB/includes/add_itemjs.asp?wish=T&Tp=";
		//alert(document.frmAdd.action);
		document.frmAdd.submit();
	}
	
	//top.status = todo;	
	
	if(todo == "add")
	{
		document.frmKitInfo.chkItems.value = document.frmAdd.chkItems.value;
		document.frmKitInfo.qty.value = document.frmAdd.qty.value;
		document.frmKitInfo.todo.value = todo;	
		document.frmKitInfo.submit();
	}
	else
	{
		document.frmAdd.submit();
	}
		

}


//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		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									
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		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; 
}


function ack()
{
	alert("Present!");
}

