﻿
function init_KeyPressEvent()
{
    if (document.addEventListener)
    {
	   document.addEventListener("keydown",keydown,false);
	   document.addEventListener("keyup",keyup,false);
       //document.addEventListener("keypress",keypress,false);
    }
    else if (document.attachEvent)
    {
       document.attachEvent("onkeydown", keydown);
       document.attachEvent("onkeyup", keyup);
       //document.attachEvent("onkeypress", keypress);
    }
    else
    {
       document.onkeydown= keydown;
       document.onkeyup= keyup;
       //document.onkeypress= keypress;
    }
}

var isShiftKeyHoldDown = false;
function keydown(e)
{
   if (!e) e= event;
   if (e.charCode != null) {
     if (e.charCode == 0)
       isShiftKeyHoldDown = true;  // morzilla and opera use e.charCode
   } else {
     if (e.keyCode == 16)
       isShiftKeyHoldDown = true;
   }
}

function keyup(e)
{
   if (!e) e= event;
   if (e.charCode != null) {
     if (e.charCode == 0)
       isShiftKeyHoldDown = false;  // morzilla and opera use e.charCode
   } else {
     if (e.keyCode == 16)
       isShiftKeyHoldDown = false;
   }
}

function performShiftClick(chkBox) {
   if(isShiftKeyHoldDown) {
     //var chkBox = _getElement(chkBoxID);
     var inputs = document.getElementsByTagName('input');
     var startCheckBox;
     var endCheckBox;
     if(inputs.length > 0) {
       for(var i=inputs.length-1; i>0; i--) {
         if(inputs[i].type == 'checkbox') {
           if(inputs[i].checked && inputs[i].getAttribute('rowcount') == chkBox.getAttribute('rowcount')) {
             endCheckBox = i;
           } else if(inputs[i].checked) {
             startCheckBox = i;
             break;
           }
         }
       }
       
       if(startCheckBox < endCheckBox) {
         for(var j=startCheckBox; j<=endCheckBox; j++) {
           if(inputs[j].type == 'checkbox') {
             if(!inputs[j].checked) 
               inputs[j].click();
           }
         }
       }
     }
   }
}


function _getElement(eName) {
        if (document.all) return(eval("document.all." + eName));
	    else return(document.getElementById(eName));
    }
    
    function hide(id) {
        var label = _getElement(id);
        if (label != null && isCheckBoxChecked()) {
            label.innerHTML = "";
            label.style.display = "none";
        }
    }
    
    function isCheckBoxChecked() {
        for (var i=0; i < document.forms[0].elements.length; i++) 
            {
                if ((document.forms[0].elements[i].type == 'checkbox') && 
                (document.forms[0].elements[i].name.indexOf('Gridrpt') > -1)) 
                {
                    if (document.forms[0].elements[i].checked)
                        return true;
                }
            }
        return false;
    }
    
  
//       function DisableButton(b)
//       {
//            b.form.submit();
//            b.disabled = true;
//          //b.value = 'Submitting';
//          
//       }
       
       function DisableButton() {
                document.forms[0].submit();
                window.setTimeout("disableButton('" + 
                   window.event.srcElement.id + "')", 0);
            }

            function disableButton(buttonID) {
                document.getElementById(buttonID).disabled=true;
            }


    
//    function checkValid() {
//        var emailfield = _getElement('ctl00_ContentPlaceHolder1_txtRespondentEmailAddress');
//        var phonefield = _getElement('ctl00_ContentPlaceHolder1_txtRespondentPhone');
//        
//        var req = eval(ctl00_ContentPlaceHolder1_bothPhoneEmailRequired);
//        
//        if (emailfield != null && phonefield != null) {
//            if (emailfield.value.length <= 0 && phonefield.value.length <= 0) {
//                req.enabled = true;
//                Page_ClientValidate();
//                alert("Please fill in either 'phone' or 'email' field.");
//            }
//            else {
//                req.enabled = false;
//                Page_ClientValidate();
//            }
//        }
//        else {
//            req.enabled = false;
//            Page_ClientValidate();
//        }
//    }

// Following function is for calling fucntionToExec only if Frozen row is prezent on the page
// because masterpage has the fucntion called RunFrozenRow(), other pages that doesn't contain FrozenRow gives error. 
// 'needFrozenRow' element is added on ForUser.aspx page where FrozenRow control is and so this need.
function RunFrozenRow() {
  var t = document.getElementById('needFrozenRow');
  if (t != null && typeof(functionToExec) != "undefined") {
    eval(functionToExec);
  }
}
