﻿//disablowanie przyciskow na czas wykonywania akcji
 function disableButtons(){
    var input = document.getElementsByTagName("input");
    var count = input.length;
    for(var i =0; i < count; i++){
        document.getElementsByTagName("input")[i].disabled = true;
        document.getElementsByTagName("input")[i].style.cursor='wait';
    }
    return true;
}

function SetChechUnCheck_New(chkType, con, gvId, hfId)
{
    //get the table element
    var tbl = document.getElementById(gvId);
    var hid_Text = "";
    //check whether the selected check box is header or body
    if(chkType == 'All')
    {
        document.getElementById(hfId).value = "";
        //assign check box .....
        var tbl_Header_Chk =  con;
        //loop through the table rows
        for(var i = 1; i< tbl.rows.length;i++)
        {
             var tbl_row = tbl.rows[i];
            //find the table cell in chich check box is available
             var tbl_Cell = tbl_row.cells[0]; // we can change 0 to any cell
             var tbl_Cell_Chk;
             //loop through the cell's controls and find the checkbox
             for(var x = 0; x<tbl_Cell.childNodes.length;x++)
             {
                if(tbl_Cell.childNodes[x].type == "checkbox")
                {
                    tbl_Cell_Chk = tbl_Cell.childNodes[x];  
                }
             }
             //set the check boxes checked state is true
             tbl_Cell_Chk.checked = tbl_Header_Chk.checked;
            
             if(tbl_Header_Chk.checked == true)
             {
                var tbl_cell_Id = tbl.rows[i].cells[2];
                if(hid_Text != "")
                {
                    hid_Text = hid_Text + "," + tbl_cell_Id.innerHTML;
                } 
                else
                {
                    hid_Text = tbl_cell_Id.innerHTML;
                }
             }
        } 
        document.getElementById(hfId).value = hid_Text; 
    }
    //if the selected check box is body check box
    else
    {
        //get the header cell
        var tbl_HeaderRow = tbl.rows[0];
        var tbl_HeaderCell = tbl_HeaderRow.cells[0];
        var tbl_Header_chk;
        //loop thorugh the header cell and get header checkbox control
         for(var x = 0; x<tbl_HeaderCell.childNodes.length;x++)
         {
            var temp = tbl_HeaderCell.childNodes[x];
            if(tbl_HeaderCell.childNodes[x].type == "checkbox")
            {
                tbl_Header_chk = tbl_HeaderCell.childNodes[x];  
            }
         }
       var chk_Cell = con.parentElement.parentElement.cells[2];
       var Id = chk_Cell.innerHTML;
        //check whether the selected check box is checked or not....
        if(con.checked == false)
        {
            //if unchecked set the header check box to false straigtaway
            tbl_Header_chk.checked = false;
            var arrIds = Array();
            arrIds = document.getElementById(hfId).value.split(",");
            for(var i = 0;i<arrIds.length;i++)
            {
                if(arrIds[i] == Id)
                {
                    arrIds[i] = null;
                    break;
                }
            }
           
            for(var i = 0;i<arrIds.length;i++)
            {
                if(arrIds[i] != null)
                {
                    if(hid_Text != "")
                    {
                        hid_Text = hid_Text + "," + arrIds[i];
                    } 
                    else
                    {
                        hid_Text = arrIds[i];
                    }
                }
            }
        }
        //the selected checkbox is checked
        else
        {
            var IsChecked = false;
            //this is temp variable is used to
            var tempCount = 0;
            //loop through the table rows and check whether all the check boxes are checked....
            for(var i = 1; i< tbl.rows.length;i++)
            {
                 var tbl_row = tbl.rows[i];
                 var tbl_Cell = tbl_row.cells[0];
                 var tbl_Cell_Chk;
                 //loop through the controls in cells and set the check box control
                 for(var x = 0; x<tbl_Cell.childNodes.length;x++)
                 {
                    if(tbl_Cell.childNodes[x].type == "checkbox")
                    {
                        tbl_Cell_Chk = tbl_Cell.childNodes[x];  
                    }
                 }
                
                 //if checkbox  is checked increase the count by 1....
                 if(tbl_Cell_Chk.checked == true)
                 {
                    tempCount = tempCount + 1;
                 }
            } 
            if(tempCount ==  tbl.rows.length - 1)
            {
                tbl_Header_chk.checked = true;
            }
            else
            {
                tbl_Header_chk.chekced = false;
            }
            hid_Text = document.getElementById(hfId).value;
            if(hid_Text != "")
            {
                hid_Text = hid_Text + "," + Id;
            } 
            else
            {
                hid_Text = Id;
            }
        }
         document.getElementById(hfId).value = hid_Text;  
       }
}



/* Alert nie zaznaczone checkboxy*/

function alertUserNoCheckBoxesChecked(hfId)
{
    
   var hf_text = document.getElementById(hfId).value;
   
   if(hf_text == null || hf_text == ""){
        alert('Proszę dokonać wyboru');
        return false;   
     }

}

/*Alert nie zaznaczone checkboxy 2*/

function alertUserNoCheckBoxesChecked2(gvId)
{
     //get the table element
    var tbl = document.getElementById(gvId);
    var hid_Text = "";
    var showAllert = true;
    //check whether the selected check box is header or body
   
    //if the selected check box is body check box
    
        //get the header cell
        var tbl_HeaderRow = tbl.rows[0];
        var tbl_HeaderCell = tbl_HeaderRow.cells[0];
        var tbl_Header_chk;
        //loop thorugh the header cell and get header checkbox control
       
         
         for(var i = 1; i< tbl.rows.length;i++)
         {
             var tbl_row = tbl.rows[i];
            //find the table cell in chich check box is available
             var tbl_Cell = tbl_row.cells[0]; // we can change 0 to any cell
             var tbl_Cell_Chk;
             //loop through the cell's controls and find the checkbox
             for(var x = 0; x<tbl_Cell.childNodes.length;x++)
             {
                if(tbl_Cell.childNodes[x].type == "checkbox" && tbl_Cell.childNodes[x].checked)
                {
                  
                    showAllert = false;
                }
             }
             //set the check boxes checked state is true
             
            
        } 
         
      
       
       if(showAllert){
        alert('Proszę dokonać zaznaczenia'); 
        return false;
        }
        
}



function CountSigns(id1,id2)
{
  
  
  if(document.all){
     document.getElementById(id1).innerText = document.getElementById(id2).value.length;
    } else{
    document.getElementById(id1).textContent  = document.getElementById(id2).value.length;
    }

}

//wpisywanie daty urodzenia i plci po peselu


         