﻿// JScript File
/* Form Validation Script for Confirm Deletion
Developed By	: Ashok Kumar Mandial
Date			: October 09, 2007 
Message			: Create an array of form elements and apply validation rules on them.
*/
//Function used to confirm deletion
 function CfmDelete(lblgrid,mode)
 {
    var confirmMsg;
    var alertMsg;
    if(mode=='remove')
    {
        confirmMsg='remove item(s)';
        alertMsg='remove';
    }
    else
    {
        confirmMsg='update item(s)';
        alertMsg='update';
    } 
        
    var selectedBoxes = ""; 
    var inputTags = lblgrid.getElementsByTagName("input"); 
    var tagsLength = inputTags.length; 
    
    for(var i=0;i<tagsLength ;i++)
    { 
       if(inputTags[i].checked==true)
           selectedBoxes ="1"; 
    } 
    
    if(mode=='update' && selectedBoxes.length>0)
    {
        var LIntQty;
	    var LStrFormElementName;
	    var LIntAvalQty;
	    var LIntInnerCtr;
	    var LIntSelectedCheckBoxes=0;

	    var LIntCtr;
	    var LIntSelectedCheckBoxes=0;
        for (LIntCtr=0; LIntCtr < document.aspnetForm.elements.length; LIntCtr++) 
        {
            if ((document.aspnetForm.elements[LIntCtr].type == 'text') && (document.aspnetForm.elements[LIntCtr].name.indexOf('txtQuantity') > -1)) 
            {
                LIntQty = document.aspnetForm.elements[LIntCtr].value;
                document.aspnetForm.ctl00_GeneralContent_hdnProductQuantity.value = LIntQty;
                if(document.aspnetForm.ctl00_GeneralContent_hdnProductQuantity.value=='')
                {
                    alert("Quantity must be entered !");
                    return false;
                }
                else
                {
                    var prdQty = document.aspnetForm.ctl00_GeneralContent_hdnProductQuantity.value;
                    reg = new RegExp("^[0-9]*$");
                    if ( !reg.test(prdQty) || parseInt(prdQty)==0 ) 
		            {
                        alert("Quantity must be numeric and greater than 0")
                        return false;
                    }
                }       
            }
        }
    }    
    
    if(selectedBoxes.length>0)
    {
        return window.confirm("Are you sure you want to " + confirmMsg + "?");
    }
    else
    {
        alert("Please select the item(s) you want to " + alertMsg + "!");
        return false;
    }
 }
 
 //function used to select/unselect child checkboxes
 function CheckAll(objChk,lblgrid)
 {
    var selectedBoxes = ""; 
    if(lblgrid.getElementsByTagName("input"))
    {
        var inputTags = lblgrid.getElementsByTagName("input");
        var tagsLength = inputTags.length; 
        for(var i=0;i<tagsLength ;i++)
        { 
            if(objChk.checked==true)
            {
              inputTags[i].checked=true;
            }
            else
            {
               inputTags[i].checked=false;
            }
                 
        }
    }
    return true;
 }

