function IsPositiveInteger(val)
{
	var strValidChars = "0123456789";
	var strChar;
	var blnResult = true;
	var strString=val;	
	if (strString.length == 0) return false;
	for (i = 0; i < strString.length && blnResult == true; i++)
    {
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1)
		{
			blnResult = false;
		}
	}
	return blnResult;
}

function validatecart()
{
	if(document.getElementById("imgsubmit"))
	{
		//if(document.frmcart.packtype.value!="")
//		{
//			if(document.frmcart.nonprepack.value=="")
//			{
//				alert("Please Select Type of Pack !!");
//				document.frmcart.nonprepack.focus();
//				return false;
//			}
//		}
//		
		fieldchecked=false;
		if(document.frmcart.purchaseqty.length)
		{
			for(k=0; k<(document.frmcart.purchaseqty.length); k++)
			{
				if (document.frmcart.purchaseqty[k].value != "Qty")
				{
					if ((document.frmcart.purchaseqty[k].value) != "" )
					{
						if(isNaN(document.frmcart.purchaseqty[k].value) || document.frmcart.purchaseqty[k].value<=0)
						{ 
							alert("Please enter valid quantity!!");
							document.frmcart.purchaseqty[k].value ="";
							document.frmcart.purchaseqty[k].focus();
							return(false);
						}
						else
						{
							if(document.frmcart.purchasemodel)
							{
								if((document.frmcart.purchasemodel[k].value == "") && (document.frmcart.purchaseqty[k].value != "Qty") && (document.frmcart.purchaseqty[k].value != ""))
								{				
									alert("Please Select Model !!");
									document.frmcart.purchasemodel[k].focus();
									return(false);
								}
							}
						}
						if((document.frmcart.purchaseqty[k].value).indexOf('.')>=0)
						{
							alert("Please enter valid quantity!!");
							document.frmcart.purchaseqty[k].value ="";
							document.frmcart.purchaseqty[k].focus();
							return(false);
						}
						fieldchecked=true;
					}
				}
				else
				{	
					if (document.frmcart.purchaseqty[k].value != "Qty")
					{		
						if((document.frmcart.purchaseqty[k].value != "") && (document.frmcart.purchasemodel[k].value != ""))
						{				
							fieldchecked=true;
							if(isNaN(document.frmcart.purchaseqty[k].value) || document.frmcart.purchaseqty[k].value<=0)
							{ 
								alert("Please enter valid quantity!!");
								document.frmcart.purchaseqty[k].value ="";
								document.frmcart.purchaseqty[k].focus();
								return(false);	
							}	
							if((document.frmcart.purchaseqty[k].value).indexOf('.')>=0)
							{
								alert("Please enter valid quantity!!");
								document.frmcart.purchaseqty[k].value ="";
								document.frmcart.purchaseqty[k].focus();
								return(false);}   	
							}
							if((document.frmcart.purchasemodel[k].value == "") && (document.frmcart.purchaseqty[k].value != "Qty") && (document.frmcart.purchaseqty[k].value != ""))
							{				
								alert("Please Select Model !!");
								document.frmcart.purchasemodel[k].focus();
								return(false);
							}
						}
					}
				}
				if (fieldchecked == false)
				{
					alert('You must enter atleast one item before submit!!');
					document.frmcart.purchaseqty[0].value=""; 
					document.frmcart.purchaseqty[0].focus(); 
					return(false);
				}
			}
			else
			{
				if (document.frmcart.purchaseqty.value != "Qty")
				{	
					if(!(IsPositiveInteger(document.frmcart.purchaseqty.value)) || document.frmcart.purchaseqty.value==0)
					{
						alert("Please enter valid quantity!!");
						document.frmcart.purchaseqty.value="";
						document.frmcart.purchaseqty.focus();
						return false;
					}
					else
					{
						if(document.frmcart.purchasemodel)
						{
							if(document.frmcart.purchasemodel.value=="")
							{
								alert("Please Select Model !!");
								document.frmcart.purchasemodel.focus();
								return false;
							}
						}
					}
					fieldchecked=true;
				}
				
				if (fieldchecked == false)
				{
					alert('You must enter atleast one item before submit!!');
					document.frmcart.purchaseqty.value=""; 
					document.frmcart.purchaseqty.focus(); 
					return(false);
				}
				
			}
	document.frmcart.submit();		
	}
	else
	{
		return false;
	}
	
}
