function IsNumeric(strString)
   //  check for valid numeric strings
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }

function trimAll(sString)
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}


function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true
	}

function checkProductDetail(a)
{
	if(trimAll(a.productname.value)=='')
	{
		alert('Please Enter Product Name!');
		a.productname.value="";
		a.productname.focus();
		return false;
	}
	if(trimAll(a.sellprice.value)=='')
	{
		alert('Please Enter selling price!');
		a.sellprice.value="";
		a.sellprice.focus();
		return false;
	}

	if(IsNumeric(a.sellprice.value) == false)
    {
    	alert("Please check - non numeric value!");
    	a.sellprice.focus();
		return false;
    }

	if(trimAll(a.qtyavailable.value)=='')
	{
		alert('Please Enter quantity available!');
		a.qtyavailable.value="";
		a.qtyavailable.focus();
		return false;
	}
	if(IsNumeric(a.qtyavailable.value) == false)
    {
    	alert("Please check - non numeric value!");
    	a.qtyavailable.focus();
		return false;
    }
}

function delProductDetail(product_id)
{
	if(confirm('Do you want to delete this record?'))
	{
		window.location="../shoppingCart/addProducts.php?hmode=D&product_id="+product_id;
	}
}

function showSelectedRecords(a,productname,shcategoryname,subCategoryValue)
{
	window.location="showProducts.php?recShow1="+a.value+"&productname="+productname+"&shcategoryname="+shcategoryname+"&subCategoryValue="+subCategoryValue;
}

function updateQtyValue(a,qty)
{
	window.location="finalCheckOut.php?product_val="+a.id+"&qty="+qty.value;
}

function checkCartInformation(a)
{
	if (echeck(a.emailid.value)==false)
	{
		a.emailid.value="";
		a.emailid.focus();
		return false;
	}
	if (trimAll(a.address.value)=='')
	{
		alert('Please enter your address!');
		a.address.value="";
		a.address.focus();
		return false;
	}
}

function showOriginalProductImage(product_id)

{

	window.open("../shoppingCart/originalProductImage.php?product_id="+product_id+"&",

                "DescriptiveWindowName","resizable=no,scrollbars=yes,status=yes,height=400,width=600,left=50,top=40");

}