﻿// JScript File

    function AddQty(txtId)
    {
        var ctrl;
        ctrl = document.getElementById(txtId);
        if (ctrl.value != "")
        {
            if (!isNaN(ctrl.value))
                ctrl.value = parseInt(ctrl.value) + 1;
            else 
                ctrl.value  = 1;
        }
        else
            ctrl.value  = 1;
    }

    function RemoveQty(txtId)
    {
        var ctrl;
        ctrl = document.getElementById(txtId);
        if (ctrl.value != "")
        {
            if (!isNaN(ctrl.value))
            {
                if(parseInt(ctrl.value) > 1)            
                    ctrl.value = parseInt(ctrl.value) - 1;
            }
            else
                ctrl.value  = 1;            
        }
    }

    function ValidateQty(txtId)
    {
        var ctrl;
        ctrl = document.getElementById(txtId);
        if (ctrl.value != "")
        {
            if (isNaN(ctrl.value))
            {
                alert("Quantity should be numeric.");
                ctrl.focus();
                return false
            }
            else if (parseInt(ctrl.value) <= 0)
            {
                alert("Quantity should be greater than zero");
                ctrl.focus();
                return false
            }              
        }
        
        return true;
    }

    function ValidateQtyForAll()
    {
        var arrCtrl = document.getElementsByTagName("input");
        var flag = false;
        for(var i=0;i < arrCtrl.length;i++)
        {
            if(arrCtrl[i].type=="text")
            {
                if(arrCtrl[i].id.indexOf("txtQty") > 0)
                {
                    if (isNaN(arrCtrl[i].value))
                    {
                        alert("Quantity should be numeric.");
                        arrCtrl[i].focus();
                        return false;
                    }
                    else if (parseInt(arrCtrl[i].value) < 0)
                    {
                        alert("Quantity should be greater than zero");
                        arrCtrl[i].focus();
                        return false;
                    }
                    else if (parseInt(arrCtrl[i].value) > 0)
                    {
                        flag = true;
                    }   
                }
            }
        }
        if (flag)
            return true;
        else
        {
            alert("Please specify quantity for at least one product") 
            return false;
        }
    }    
        
    var width = 600
    var height = 300
    
//    function OpenPopUpWindow(CatId, StockCode)
//    {
//        var url = "mailtofriend.aspx?CatId=" + CatId + "&StockCode=" + StockCode
//        window.open(url,"mailtofriend","height=" + height + ", width=" + width)
//    }

    function OpenPopUpWindow(url, width, height)
    {
        window.open(url,"popUpWindow","height=" + height + ", width=" + width)
    }

