﻿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 chkNumeric(rowNumber)
{
   
    var tmpQuantity
    eval("tmpQuantity=document.basket.basket_" + rowNumber + "_quantity.value")
    document.basket.basket_action.value="3"
    //alert(tmpQuantity.length)
    
    if (IsNumeric(tmpQuantity) == true ) {
        document.basket.submit()
    }
    else
    {
       alert("The quantity you entered is not valid.")
   }


}

function chkAllNumeric() {
    var Count
    var tmpQuantity
    Count = document.basket.basket_count.value
    var check
    check = true
    var i = 0
    for (i = 1; i <= Count; i++) {

        eval("tmpQuantity=document.basket.basket_" + i + "_quantity.value")

        //alert(tmpQuantity.length)
        if (IsNumeric(tmpQuantity) == false)  {
            check = false
        }
    }

    if (check == true) {
        document.basket.submit()
    }
    else {
        alert("The quantity you entered is not valid.")
    }
}

var popUpWin=0;

function popUpWindow(URLStr, left, top, width, height) {

    if (popUpWin) {

        if (!popUpWin.closed) popUpWin.close();

    }

    popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto,resizable=yes,copyhistory=yes,width=' + width + ',height=' + height + ',left=' + left + ', top=' + top + ',screenX=' + left + ',screenY=' + top + '');

}
function addBasket(prodID, catID, count) {
    /*
    alert("xxx")
    alert(prodID)
    alert(catID)
    alert(count)
    */
    var qty    
    var qtylen
    eval("qty=document.frm_prodlisting.basket_" + count + "_quantity.value")
    
    if ((qty == "Qty...") || (qty == "Qty.") || (qty == "")) {
        qty = 1
        qtylen = 1
    }
    else {
        qtylen = qty.length
    }
    
    //alert(qtylen)
    
    if (IsNumeric(qty) == true) {
        if (qtylen <= 6) {
            //alert("/Basket.aspx?basket_action=1&amp;basket_product=" + prodID + "&amp;basket_category=" + catID + "&amp;basket_quantity=" + qty )        
            document.frm_product.basket_product.value = prodID
            document.frm_product.basket_category.value = catID
            document.frm_product.basket_quantity.value = qty

            //alert(prodID + "/" + catID + "/" + qty)
            document.frm_product.submit()
            //window.location="/Basket.aspx?basket_action=1&basket_product=" + prodID + "&basket_category=" + catID + "&basket_quantity=" + qty
        }
        else {
            alert("Please enter a quantity number have lower than 6 digits.");
        }
    } 
    else 
    {
        alert("The quantity you entered is not valid.");
    }
}

function isValid()
//  check for valid numeric strings	
{
    var strValidChars = "0123456789";
    var strChar;
    var blnResult = true;
    var strString;
    strString = document.frmDetails.basket_quantity.value;

    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) {
            alert("The quantity you entered is not valid.");
            blnResult = false;
        }
    }
    return blnResult;
}
