﻿// JScript File
////For MS DataGrid
function ChangeBackGroundColor(checkBox, selectColor, unSelectColor) {

    //      //changing row style accordingly
   
        if (checkBox.checked)
        //checkbox.Cell.Row ( this is the target row where checkbox is added
            checkBox.parentNode.parentNode.style.backgroundColor = selectColor;
        else
            checkBox.parentNode.parentNode.style.backgroundColor = unSelectColor;
    
    return true;
}

    function HighLightRow(checkboxref,rowId,selectColor,unSelectColor)
    {
        
                 //check     .TableCell .TableRow  .Table
        var oGrid = checkboxref.parentNode.parentNode.parentNode;
        var obj=checkboxref.parentNode;
        var rowIndex=0;
        var columnIndex=0;
        var columnName;
       
        ChangeBackGroundColor(checkboxref,selectColor,unSelectColor);   
               
        columnIndex=getClickedCheckBoxIndex(obj);
        //alert(oGrid.rows[3].children[4].innerText);

       // window.open(oGrid.rows[3].children[4].innerText);
        //after getting the right column 
        // needs to get Header Checkbox
                         //Table.THEAD      .TR     .TD                   .CheckBox   
        var HeaderCheckBox=oGrid.rows[0].children[columnIndex].firstChild;
        //Initilizating check box 
        HeaderCheckBox.checked=true;
        // start looping from TBODY
        for(rowIndex=1;rowIndex<oGrid.rows.length;rowIndex++)
        {
          // TABLE .TBODY      .TR(s)  .TD         .TARGET CHECK BOX                         
          var checkBox= oGrid.rows[rowIndex].children[columnIndex].firstChild;
          //will use circuit switching to uncheck Header Checkbox means when we find first 
          //unchecked checkbox in Tbody rows we will uncheck Header check box and break 
          //otherwise it is fine               
          if(checkBox.type="checkbox")
          {
                if(!checkBox.checked) 
                {
                  HeaderCheckBox.checked=false;
                  break;
                }
          }
        }   
       return true;
   }



   function MouseCellMove(checkboxref, rowId, selectColor, unSelectColor) {
       //check     .TableCell .TableRow  .Table
       
       if (checkboxref.parentNode.style.backgroundColor != "wheat" && checkboxref.parentNode.style.backgroundColor != "Wheat")
           checkboxref.parentNode.style.backgroundColor = selectColor;
       var oGrid = checkboxref.parentNode.parentNode.parentNode;
      
       return true;
   }
   function MouseCellLeave(checkboxref, rowId, selectColor, unSelectColor) {
       //check     .TableCell .TableRow  .Table

       if (checkboxref.parentNode.style.backgroundColor != "wheat" && checkboxref.parentNode.style.backgroundColor != "Wheat")
           checkboxref.parentNode.style.backgroundColor = selectColor;
       return true;
   }

   function MouseCtrlMove(checkboxref, rowId, selectColor, unSelectColor) {
       //check     .TableCell .TableRow  .Table
       if (checkboxref.parentNode.style.backgroundColor != "wheat" && checkboxref.parentNode.style.backgroundColor != "Wheat")
           checkboxref.parentNode.parentNode.style.backgroundColor = selectColor
       var oGrid = checkboxref.parentNode.parentNode.parentNode;

       return true;
   }
   function MouseCtrlLeave(checkboxref, rowId, selectColor, unSelectColor) {
       //check     .TableCell .TableRow  .Table
       if (checkboxref.parentNode.style.backgroundColor != "wheat" && checkboxref.parentNode.style.backgroundColor != "Wheat")
           checkboxref.parentNode.parentNode.style.backgroundColor = selectColor
       return true;
   }

   
    
    function ChangeSelection(HeaderCheckBox,selectColor,unSelectColor)
    {
        var rowIndex=0;
        var obj=HeaderCheckBox.parentNode;
                 //check        .TableCell .TableRow  .TableHead .Table
        
        //oGrid.children[0].childNodes[0].children.length
        var columnIndex=0;
        var columnName;
        var pos = -1;
        
        var oGrid = HeaderCheckBox.parentNode.parentNode.parentNode.parentNode;
		columnIndex=getClickedCheckBoxIndex(obj);
        // start looping in Table excluding First Row
        // that contain Header CheckBox
        for(rowIndex=1;rowIndex<oGrid.rows.length;rowIndex++)
        {
          // TABLE .TBODY      .TR(s)  .TD         .TARGET CHECK BOX                         
           var checkBox= oGrid.rows[rowIndex].children[columnIndex].firstChild;      
          if(checkBox.type="checkbox")
          {
          
                checkBox.checked=HeaderCheckBox.checked;
                ChangeBackGroundColor(checkBox,selectColor,unSelectColor);
            }

        }
        HeaderCheckBox.parentNode.parentNode.parentNode.style.backgroundColor = "#6699bb";
        return true;
    }
    function getClickedCheckBoxIndex(obj)
    {
        var columnIndex=0;
        while(obj.previousSibling){
			obj = obj.previousSibling;
			if(obj.tagName=='TD')columnIndex++;		
		}
		return columnIndex;
}

function OnButtonFieldMouseMove(refButton) {
   
    refButton.style.backgroundImage = 'url(../ApplicationLayer/NYO_Icons/TabIcon/hover_tab_bg.gif)';
    refButton.style.backgroundRepeat = 'repeat-x';

}
function OnButtonFieldMouseOut(refButton) {
    refButton.style.backgroundImage = 'url(../ApplicationLayer/NYO_Icons/AllIcons24/grid_bg.gif)';
    refButton.style.backgroundRepeat = 'repeat-x';

}


/* use uppermost modal*/
function OnClickOpenModal(refUrl) {
    var modal = window.parent.window.$find('programmaticModalPopupBehavior');
    var modalPopupBehavior = modal;
    modalPopupBehavior.show();
    var el = window.parent.window.document.getElementById('iframeId');
   
    if (el == null) {

        el = window.parent.window.document.all('iframeId').contentWindow;
        if (el == null) { alert("Pleaes switch to IE"); return; }
        el.location = refUrl;
        
    }
    else {
        el.src = refUrl;
    }
      
    
   // var el = document.all('iframeId2').contentWindow;
   // el.location = refUrl;

}
/*

function OnClickOpenModal(refUrl) {

    var modalPopupBehavior = $find('programmaticModalPopupBehavior');
    alert(window.document.title);
    modalPopupBehavior.show();
    var el = document.getElementById('iframeId');
   
    if (el == null) {
    
        el = document.all('iframeId').contentWindow;
        if (el == null) { alert("Pleaes switch to IE"); return; }
        el.location = refUrl;
        
    }
    else {
        el.src = refUrl;
    }
      
    
   // var el = document.all('iframeId2').contentWindow;
   // el.location = refUrl;

}
*/
function OnClickOpenUsual(refUrl) {
    var sFeatures = "center: yes;";
    sFeatures += "edge: sunken;";
    sFeatures += "scroll: yes;";
    sFeatures += "status: yes;";
    sFeatures += "resizeable: yes;";

    window.open(refUrl, '', '');
}

function OnDialogButtonClick(refUrl) {
   
    var sFeatures = "height: 1500px;";
    sFeatures += "width: 1500px;";
    sFeatures += "center: yes;";
    sFeatures += "edge: sunken;";
    sFeatures += "scroll: yes;";
    sFeatures += "status: yes;";
    sFeatures += "resizeable: yes;";

    window.open(refUrl, '', sFeatures);
}

function getKeyCode(e)// v1.0
{
    if (window.event)
        return window.event.keyCode;
    else if (e)
        return e.which;
    else
        return null;
}
function keyRestrict(e, validchars) { // v3.0
    var key = '', keychar = '';
    key = getKeyCode(e);
    if (key == null) return true;
    keychar = String.fromCharCode(key);
    keychar = keychar.toLowerCase();
    validchars = validchars.toLowerCase();
    if (validchars.indexOf(keychar) != -1)
        return true;
    if (key == null || key == 0 || key == 8 || key == 9 || key == 13 || key == 27)
        return true;
    return false;
}


var styleToSelect;
function onOk() {
    $get('Paragraph1').className = styleToSelect;
}

// Add click handlers for buttons to show and hide modal popup on pageLoad
function pageLoad() {
    
    $addHandler($get("hideModalPopupViaClientButton"), 'click', hideModalPopupViaClient);
}

function showModalPopupViaClient(ev) {
   
    ev.preventDefault();
    var modalPopupBehavior = $find('programmaticModalPopupBehavior');
    modalPopupBehavior.show();
}

function hideModalPopupViaClient(ev) {
    ev.preventDefault();
    var modalPopupBehavior = $find('programmaticModalPopupBehavior');
    modalPopupBehavior.hide();
}

function OnCloseClick() {

    alert('close');
}
