﻿// JScript File
    function CheckNemericValue(e)
    {
        key = e.which ? e.which : e.keyCode;
        if((key>=48 && key<=57) || key == 46 || key == 8 || key == 9)
        {  
           return true;
        }
        else
         {  
            return false;
         }
    }
        
    function CheckQty(txt)
    {
        var obj = document.getElementById(txt);
        if(obj != null)
        {
            if(obj.value.length < 1)
            {
                alert('Enter Quantity');
                return false;
            }
        }
    }
    
    function CheckCBList(cblid)
    {
        var cbl = document.getElementById(cblid);
        var isChkd = false;
        var node;
        
        for (var i = 0 ; i < cbl.rows.length ; i++)
        {   
            for (var j = 0 ; j < cbl.rows[i].cells.length ; j++)
            {   
                node = cbl.rows[i].cells[j].childNodes[0];
                   
                if(node != null && node.type == "checkbox")
                {   
                    if(node.checked)
                    {
                        isChkd = true;
                        break;
                    }
                }
            }
            
            if(isChkd)
                break;
                             
        }
        
        if(!isChkd)
        {
            alert('Plase select atleast one category.');
            return false;
        }
    }
    
    function  CheckGrid(gridId)
    {   
        var grid = document.getElementById(gridId);
        //variable to contain the cell of the grid
        var cell;
        var isChkd = false;
        
        if (grid.rows.length > 0)
        {
            //loop starts from 1. rows[0] points to the header.
            for (i=1; i<grid.rows.length; i++)
            {
                //get the reference of first column
                cell = grid.rows[i].cells[0];
                
                //loop according to the number of childNodes in the cell
                for (j=0; j<cell.childNodes.length; j++)
                {           
                    //if childNode type is CheckBox                 
                    if (cell.childNodes[j].type =="checkbox")
                    {
                       if(cell.childNodes[j].checked)
                       {
                            isChkd = true;
                            break;
                       }
                    }
                }
                
                if(isChkd)
                    break;           
            }
            
            if(!isChkd)
            {
                alert('Please Select Atleast One Row');
                return false;
            }
            else 
            {
                return confirm('Are you sure to want to delete ?');
            }
        }
    }
    
    function SelectDeselectAll(gridid,cb)
    {
        var grid = document.getElementById(gridid);
        var head_cb = document.getElementById(cb);
        var status;
        var cell;
        
        status = head_cb.checked
        
        if(grid.rows.length > 0)
        {
            for (var i = 0; i < grid.rows.length ; i++)
            {
                cell = grid.rows[i].cells[0];
                
                for(var j = 0; j < cell.childNodes.length; j++)
                {
                    if(cell.childNodes[j].type == "checkbox")
                    {
                        cell.childNodes[j].checked = status;
                        break;
                    }
                }
            }
        }
    }
    
    function FillShippingAddress()
    {
        var parent_ctrl = "ctl00_ContentPlaceHolder1_";
        
        document.getElementById(parent_ctrl + "txtShippingAddress").value = 
                                document.getElementById(parent_ctrl + "txtBillingAddress").value;
        
        document.getElementById(parent_ctrl + "txtShippingCity").value = 
                                document.getElementById(parent_ctrl + "txtCity").value;
                                
       document.getElementById(parent_ctrl + "txtShippingState").value = 
                                document.getElementById(parent_ctrl + "txtState").value;
                                
       
       var opt = document.getElementById(parent_ctrl + "ddlCountry").options;
       
       for(var i = 0 ; i < opt.length ; i++)
       {
            if (opt[i].selected)
            {   
                document.getElementById(parent_ctrl + "ddlShippingCountry").options[i].selected = true;
                break;
            }
       }
       
    }
    
    function showPopup(popupId)
    {
        var obj = $find(popupId);
        if(obj != null)
        {
            obj.showPopup();
        }
        
    }
    
    function hidePopup(popupId)
    {
        var obj = $find(popupId);
        if(obj != null)
        {
            obj.hidePopup();
        }
    }

