﻿// JScript File


var $ = function(i){
    return document.getElementById(i);
}
var p$ = function(i){
    return window.parent.document.getElementById(i)
}

var isIE = function(){
    if((navigator.appName).indexOf("Micro") == -1){
        return false;
    }else{
        return true;
    }
}

var netTranslate = {
        label:"span",
        panel:"div",
        textbox:"input",
        dropdownlist:"select"
    }

var getchildIDof = function(e,nNode,indexID){
     var returnval = "";
     for(var n = 0; n < $(e).childNodes.length ;n++){
        if(nNode!=""){
            if(($(e).childNodes[n].nodeName+"").indexOf(nNode) > -1){
                try{
                    var returnval = $(e).childNodes[n].id + "";
                }catch(i){
                    var returnval = "";
                }
            }
        }else if(indexID){
            if(($(e).childNodes[n].id + "").indexOf(indexID) > -1){
                try{
                    var returnval = $(e).childNodes[n].id + "";
                }catch(i){
                    var returnval = "";
                }
            }
        }
     }
     return returnval;
}


/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Abraham Joffe :: http://www.abrahamjoffe.com.au/ */

/***** CUSTOMIZE THESE VARIABLES *****/

  // width to resize large images to
var maxWidth=100;
  // height to resize large images to
var maxHeight=100;
  // valid file types
var fileTypes=["bmp","gif","png","jpg","jpeg"];
var importfileTypes=["xls","xlsx"];

  // what to display when the image is not valid
var defaultPic="~/Common/Images/LogoPlayNetwork.gif";

/***** DO NOT EDIT BELOW *****/

function clickas(what)
{
   
    what.form.reset();
    what.focus();
}

function ValidateUploadedFile(fuControl)
{ //debugger;
    //alert('hi');
}


function preview(what)
{//debugger;
  var source=what.value;
  var ext=source.substring(source.lastIndexOf(".")+1,source.length).toLowerCase();
  for (var i=0; i<fileTypes.length; i++) if (fileTypes[i]==ext) break;
  globalPic=new Image();
  if (i<fileTypes.length) 
  {
     globalPic.src=source;
  }
  else
  {
    globalPic.src=defaultPic;
    alert("THAT IS NOT A VALID IMAGE\nPlease load an image with an extention of one of the following:\n\n"+fileTypes.join(", "));
    what.form.reset();
    what.focus();
    return;
  }
  setTimeout("applyChanges()",200);
}
var globalPic;
function applyChanges(){
    // the id of the preview image tag
var outImage= getchildIDof("spanUploadLogo", "", "imgLogoPreview");
  var field=document.getElementById(outImage);
  var x=parseInt(globalPic.width);
  var y=parseInt(globalPic.height);
  if (x>maxWidth) {
    y*=maxWidth/x;
    x=maxWidth;
  }
  if (y>maxHeight) {
    x*=maxHeight/y;
    y=maxHeight;
  }
//  if (x==0) {
//    x=maxWidth;
//  }
//  if (y==0) {
//    y=maxHeight;
//  }
  //field.style.display= "inline";
  field=globalPic;
  field.width=x;
  field.height=y;
}
// End -->

function switchIMG(id,img){
    try{
        var thisSCR = $(id).src;
        //alert(thisSCR);
        if(thisSCR.indexOf("_mo")== -1){
            thisSCR = thisSCR.replace(".gif","_mo.gif");
        }else{
            thisSCR = thisSCR.replace("_mo","");
        }
        
        $(id).src = thisSCR;
    }catch(e){
    
    } 
}

var Xbuttons = {
    hide:function(){
        try{
            var links = parent.document.getElementsByTagName("A");

            for(var i = 0; i < links.length; i++){
                
                if((links[i].id+"").indexOf("imgDelete") >-1){
                    links[i].style.visibility = "hidden";
                }
            }
            //var _inputs = document.getElementsByTagName("INPUT");
            
            
        }catch(e){
        }
    },
    show:function(){
        try{
            var inputs = parent.document.getElementsByTagName("A");

            for(var i = 0; i < inputs.length; i++){
                
                if((inputs[i].id+"").indexOf("imgDelete") >-1){
                    inputs[i].style.visibility = "visible";
                }
            }
        }catch(e){
        }
    }  
}

function closeFframe(){
    window.parent.window.history.back()
}

function hidePopIn(targetUrl)
{
    window.parent.parent.location.href = targetUrl;
}

function showStaticIPControls(source)
{
    if(source.children[2].checked)
    {
        $("divStaticIPControls").style.visibility = 'visible';
    }
    else
    {
         $("divStaticIPControls").style.visibility = 'hidden';
    }
}

function showStaticDateControls(source)
{
    if(source.children[2].checked)
    {
        $("divStaticDateControls").style.visibility = 'visible';
    }
    else
    {
         $("divStaticDateControls").style.visibility = 'hidden';
    }
}

function showDailyControls(source)
{
    if(source.children[2].checked)
    {
        $("divDailyControls").style.visibility = 'visible';
        $("divWeekly").style.visibility = 'hidden';
    }
    else
    {
         $("divDailyControls").style.visibility = 'hidden';
          $("divWeekly").style.visibility = 'visible';
    }
}

function fnMoveItems(lboxAvailable,lboxSelected)
{
 var varFromBox = document.getElementById(getchildIDof("spn"+lboxAvailable, "", lboxAvailable));
 var varToBox = document.getElementById(getchildIDof("spn"+lboxSelected, "", lboxSelected));
 if ((varFromBox != null) && (varToBox != null)) 
 { 
  if(varFromBox.length < 1) 
  {
   alert('There are no items in the source ListBox');
   return false;
  }
  if(varFromBox.options.selectedIndex == -1) // when no Item is selected the index will be -1
  {
   alert('Please select an Item to move');
   return false;
  }
  while ( varFromBox.options.selectedIndex >= 0 ) 
  { 
   var newOption = new Option(); // Create a new instance of ListItem 
   newOption.text = varFromBox.options[varFromBox.options.selectedIndex].text; 
   newOption.value = varFromBox.options[varFromBox.options.selectedIndex].value; 
   varToBox.options[varToBox.length] = newOption; //Append the item in Target Listbox
   varFromBox.remove(varFromBox.options.selectedIndex); //Remove the item from Source Listbox 
  } 
 }
 return false; 
}


function changethis(){
        switchIMG(this.vtval,"");
       
}

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
var _maxLength = 20;



function AddNewRow(valueField, textField)
{//divMyTable
    var tbodyElem = document.getElementById(getchildIDof("divMyTable","","myTable"));
    var trElem, tdElem;
    trElem = tbodyElem.insertRow(tbodyElem.rows.length);
    var cssClass = "tr" + (tbodyElem.rows.length%2);
    trElem.className = cssClass;
    
    trElem.onmouseover = function ChangeColor(){trElem.className = "mouseOverRow";};
    trElem.onmouseout = function ReverseColor(){//debugger;
    if(trElem.cells[1].children[0].checked == false)
    {
        trElem.className = cssClass;
    }
    else
    {   
        trElem.className = "selectedTR";
    }
    };
    // first column
    tdElem = trElem.insertCell(trElem.cells.length);
    tdElem.className = "col0";
    if(valueField != '')
    {
        tdElem.innerHTML = valueField;
    }
    else
    {
        tdElem.innerHTML = tbodyElem.rows.length;
    }
    tdElem.style.visibility = "hidden";
    tdElem = trElem.insertCell(trElem.cells.length);
    tdElem.className = "col2";
    var checkbox = document.createElement('input');
    checkbox.type = 'checkbox';
    checkbox.name = 'checkboxName';
    checkbox.defaultChecked = false;
    tdElem.appendChild(checkbox);
    tdElem.style.visibility = "hidden";
    trElem.onclick = function SelectedItem(){
    trElem.className = "selectedTR";
    DeSelectRows();
    checkbox.checked = true;
    };
    // third column
    tdElem = trElem.insertCell(trElem.cells.length);
    tdElem.className = "col1";
    if(textField == '')
    {
        var textId = "newRow" + tbodyElem.rows.length;
        var el = document.createElement('input');
        el.type = 'text'; 
        el.name = 'txt' + textId;
        el.id = 'txt' + textId; 
        el.size = 20;
        el.maxLength = _maxLength;
        el.onblur = function ChangeToLable(){//debugger;
        var txtValue = el.value;
        tdElem.innerHTML = txtValue;
        el.style.visibility = "hidden";};
        tdElem.appendChild(el);
        el.focus();
    }
    else
    {
        tdElem.innerHTML = textField;
    }
    tdElem.ondblclick = function MakeEditable(){
    DeSelectRows();
    var isInEditMode = false;
    var totalChildElements = tdElem.children.length;
    for(var i=0; i < totalChildElements; i++)
    {
        if(tdElem.children[i].tagName == "INPUT")
        {
            isInEditMode = true;
        }
    }
    if(!isInEditMode)
    {
        var txtEditValue = tdElem.innerHTML;
        tdElem.innerHTML = "";
        var textId = "editRow" + tbodyElem.rows.length;
        var el = document.createElement('input');   
        el.type = 'text'; 
        el.name = 'txt' + textId;
        el.id = 'txt' + textId; 
        el.size = 20;
        el.value = txtEditValue;
        el.maxLength = _maxLength;
        el.onblur = function ChangeToLable(){
        var txtValue = el.value;
        tdElem.innerHTML = txtValue;
        el.style.visibility = "hidden";};
        tdElem.appendChild(el);
        el.focus();
        };
    }
}

function EditValue()
{
    //var tbodyElem = document.getElementById("myTable");
    var tbodyElem = document.getElementById(getchildIDof("divMyTable","","myTable"));
    var totalNumberOfRows = tbodyElem.rows.length;
    var cellText = "";
    for(var currentRowIndex = 0; currentRowIndex < totalNumberOfRows; currentRowIndex++)
    {
        var currentRow = tbodyElem.rows[currentRowIndex];
        if(currentRow.cells[1].children[0].checked == true)
        {
            tdElem = currentRow.cells[2];
            //alert(currentRow.cells[2].innerHTML);  
            var txtEditValue = tdElem.innerHTML;
            tdElem.innerHTML = "";
            var textId = "editRow" + tbodyElem.rows.length;
            var el = document.createElement('input');   
            el.type = 'text'; 
            el.name = 'txt' + textId;
            el.id = 'txt' + textId; 
            el.size = 20;
            el.value = txtEditValue;
            el.maxLength = _maxLength;
            el.onblur = function ChangeToLable(){
            var txtValue = el.value;
            tdElem.innerHTML = txtValue;
            el.style.visibility = "hidden";};
            tdElem.appendChild(el);
            el.focus();
         }
    }
}

function DeSelectRows()
{
    var tbodyElem = document.getElementById(getchildIDof("divMyTable","","myTable"));
    var totalNumberOfRows = tbodyElem.rows.length;
    var cellText = "";
    for(var currentRowIndex = 0; currentRowIndex < totalNumberOfRows; currentRowIndex++)
    {
        var currentRow = tbodyElem.rows[currentRowIndex];
        currentRow.className = "tr" + (currentRowIndex+1)%2;
        currentRow.cells[1].children[0].checked = false;
    }
}

function DeleteRows()
{
    var tbodyElem = document.getElementById(getchildIDof("divMyTable","","myTable"));
    var totalNumberOfRows = tbodyElem.rows.length;
    var cellText = "";
    for(var currentRowIndex = 0; currentRowIndex < totalNumberOfRows; currentRowIndex++)
    {
        var currentRow = tbodyElem.rows[currentRowIndex];
        if(currentRow.cells[1].children[0].checked == true)
        {
            tbodyElem.deleteRow(currentRowIndex); 
            totalNumberOfRows--;
        }
    }
}

function PaasValues()
{//debugger;
    var tbodyElem = document.getElementById(getchildIDof("divMyTable","","myTable"));
    var totalNumberOfRows = tbodyElem.rows.length;
    var cellText = "";
    for(var currentRowIndex = 0; currentRowIndex < totalNumberOfRows; currentRowIndex++)
    {
        var currentRow = tbodyElem.rows[currentRowIndex];
        if(currentRow.cells[2].innerHTML != '')
        {
            if(cellText != "")
            {
                cellText = cellText + "_" + currentRow.cells[0].innerHTML+ "_" + currentRow.cells[2].innerHTML;
            }
            else
            {
                cellText = currentRow.cells[0].innerHTML+ "_" + currentRow.cells[2].innerHTML;
            }
        }
    }
    var txtValues = document.getElementById(getchildIDof("divMyTable","","hdnListText"));
    txtValues.value = cellText;
}

function keyPressTest(e, obj)
{
  var validateChkb = document.getElementById('chkValidateOnKeyPress');
  if (validateChkb.checked) {
    var displayObj = document.getElementById('spanOutput');
    var key;
    if(window.event) {
      key = window.event.keyCode; 
    }
    else if(e.which) {
      key = e.which;
    }
    var objId;
    if (obj != null) {
      objId = obj.id;
    } else {
      objId = this.id;
    }
    displayObj.innerHTML = objId + ' : ' + String.fromCharCode(key);
  }
}


function BindData()
{
    var txtValues = document.getElementById(getchildIDof("divMyTable","","hdnListText"));
    if(txtValues.value != "")
    {
        var tableData = txtValues.value.split("_");
        for (var j = 0; j < tableData.length; j++) 
        {
            var valueField = tableData[j];
            j++;
            var textField = tableData[j];
            AddNewRow(valueField, textField);
        }
    }
}
////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////


function validateUploadLogo()
{
    var uploadControl = document.getElementById(getchildIDof("spanUploadLogo","","fuUploadLogo"));
    if(uploadControl!=null && uploadControl.value != "")
    {
        var source = uploadControl.value;
        var ext=source.substring(source.lastIndexOf(".")+1,source.length).toLowerCase();
        for (var i=0; i<fileTypes.length; i++) 
        {
            if (fileTypes[i]==ext)
            {
                break;
            }
         }
        if (i<fileTypes.length)
        {
        }
        else 
        {
            alert("THAT IS NOT A VALID IMAGE\nPlease load an image with an extention of one of the following:\n\n"+fileTypes.join(", "));
            window.Page_BlockSubmit = true;
        }
    }
}


// valid message file types
var validMessageFileTypes=["mp2","mp3","wma","wav","flac"];
function validateUploadedMessageFile(div, fuSourceFile)
{//debugger;
    var uploadControl = document.getElementById(getchildIDof(div,"",fuSourceFile));
    if(uploadControl.value == "")
    {
        alert('browse a file to upload.');
        window.Page_BlockSubmit = true;
        return;
    }
    var source = uploadControl.value;
    var ext=source.substring(source.lastIndexOf(".")+1,source.length).toLowerCase();
    for (var i=0; i<validMessageFileTypes.length; i++) 
    {
        if (validMessageFileTypes[i]==ext)
        {
            break;
        }
     }
    if (i<validMessageFileTypes.length)
    {
        window.Page_BlockSubmit = false;
        //return true;
    }
    else 
    {
        alert("Not a valid message format\nPlease load a file with an extention, one of the following:\n\n"+validMessageFileTypes.join(", "));
        window.Page_BlockSubmit = true;
        return false;
    }
}

function validateUploadVarLogo()
{
    var uploadControl = document.getElementById(getchildIDof("spanUploadLogo","","fuUploadLogo"));
    
    if(uploadControl!=null && uploadControl.value != "")
    {
        var source = uploadControl.value;
        var ext=source.substring(source.lastIndexOf(".")+1,source.length).toLowerCase();
        for (var i=0; i<fileTypes.length; i++) 
        {
            if (fileTypes[i]==ext)
            {
                break;
            }
         }
        if (i<fileTypes.length)
        {
        }
        else 
        {
            alert("THAT IS NOT A VALID IMAGE\nPlease load an image with an extention of one of the following:\n\n"+fileTypes.join(", "));
            window.Page_BlockSubmit = true;
        }
    }
}


function moveOne(div, Pro, Postfix)
{//debugger;
    var availableListItems;
    var selectedListItems;
    if(Pro=="Add" || Pro=="AddAll")
    {
         availableListItems = document.getElementById(getchildIDof(div, "", "lbAvailableList"+Postfix));
         selectedListItems = document.getElementById(getchildIDof(div, "", "lbSelectedList"+Postfix));
    }
    if(Pro=="Remove" || Pro=="RemoveAll")
    {
         availableListItems = document.getElementById(getchildIDof(div, "", "lbSelectedList"+Postfix));
         selectedListItems = document.getElementById(getchildIDof(div, "", "lbAvailableList"+Postfix));
    }
    var hdnSelectedValues = document.getElementById(getchildIDof('DivHidden', "", "hdnSelectedValues"));
    var totaloptionsInAvailableList = availableListItems.options.length;
    
    if(totaloptionsInAvailableList > 0)
    {
        var isAnyItemseleted = false;
        for(var currentChildIndex=0; currentChildIndex < totaloptionsInAvailableList; currentChildIndex++)
        {
            var currentChild = availableListItems.options[currentChildIndex];
            if(Pro=="Add" || Pro=="Remove")
            {
                if(currentChild.selected)
                {
                    // add option to selected list
                    var elOptNew = document.createElement('option');
                    elOptNew.text = currentChild.text;
                    elOptNew.value = currentChild.value;
                    selectedListItems.options.add(elOptNew);
                    // remove from available list
                    availableListItems.options[currentChildIndex] = null;
                    totaloptionsInAvailableList--;
                    currentChildIndex--;
                    isAnyItemseleted = true;
                }
            }
            if(Pro=="AddAll" || Pro=="RemoveAll")
            {
                // add option to selected list
                var elOptNew = document.createElement('option');
                elOptNew.text = currentChild.text;
                elOptNew.value = currentChild.value;
                selectedListItems.options.add(elOptNew);
                // remove from available list
                availableListItems.options[currentChildIndex] = null;
                totaloptionsInAvailableList--;
                currentChildIndex--;
                isAnyItemseleted = true;
            }
        }
        var finalListOfSelectedItems = document.getElementById(getchildIDof(div, "", "lbSelectedList"+Postfix));
        var totalOptionsInSelectedList = finalListOfSelectedItems.options.length;
        var arraySelectedValues = new Array();
        if(totalOptionsInSelectedList > 0)
        {
            for(var currentChildIndex=0; currentChildIndex < totalOptionsInSelectedList; currentChildIndex++)
            {
                var currentChild = finalListOfSelectedItems.options[currentChildIndex];
                arraySelectedValues.push(currentChild.value);
            }
        }
        if(arraySelectedValues.length > 0)
        {
            hdnSelectedValues.value = arraySelectedValues.toString();
        }
        //alert(hdnSelectedValues.value);
        if(!isAnyItemseleted)
        {
            alert('Select at list one item');
        }
    }
    else
    {
        alert('There is no item.');
    }
}

function bindDataToSelectedList()
{
    var availableListItems = $(getchildIDof("divListBuilderMessage", "", "lbAvailableList"));
    var selectedListItems = $(getchildIDof("divListBuilderMessage", "", "lbSelectedList"));
    var hdnSelectedValues = $(getchildIDof("DivHidden", "", "hdnSelectedValues"));
    if(hdnSelectedValues.value != "")
    {
        var selectedValues = new Array();
        selectedValues = hdnSelectedValues.value.split(",");
        if(selectedValues.length > 0)
        {
            for(var currentIndex = 0; currentIndex < selectedValues.length; currentIndex++)
            {
                var totalChildrenInAvailableList = availableListItems.children.length;
                if(totalChildrenInAvailableList > 0)
                {
                    for(var currentChildIndex=0; currentChildIndex < totalChildrenInAvailableList; currentChildIndex++)
                    {
                        var currentChild = availableListItems.children[currentChildIndex];
                        if(currentChild.value == selectedValues[currentIndex])
                        {
                            // add option to selected list
                            var elOptNew = document.createElement('option');
                            elOptNew.text = currentChild.text;
                            elOptNew.value = currentChild.value;
                            selectedListItems.add(elOptNew);
                            // remove from available list
                            availableListItems.remove(currentChildIndex);
                            totalChildrenInAvailableList--;
                        }
                    }
                }
            }
        }
    }
    
}

function ValidateForUserPermissions()
{//debugger;
    var isAnyCheckboxChecked = false;
    // get the check box list control to validate it
    if(document.getElementById(getchildIDof("divUserPermissions", "", "chkReadOnlyUser")).checked == false)
    {
        if(document.getElementById(getchildIDof("divUserPermissions", "", "chkAdministrator")).checked == false)
        {
            var theForm = $(getchildIDof("divchklUserPermissions", "", "chklUserPermissions"));
            for(var i = 0; i < theForm.rows.length ;i++)
            {
                for(var j = 0; j < theForm.rows[i].cells.length ;j++)
                {
                    for(var z = 0; z < theForm.rows[i].cells[j].childNodes.length ;z++)
                    {
                        if((theForm.rows[i].cells[j].childNodes[z].name+"").indexOf("chklUserPermissions") > -1)
                        {
                            if(theForm.rows[i].cells[j].childNodes[z].type == 'checkbox')
                            {
                                if(theForm.rows[i].cells[j].childNodes[z].checked == true)
                                {
                                    // come out of the loop if any of the check box is being checked
                                    isAnyCheckboxChecked = true;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
        else
            isAnyCheckboxChecked = true;
    }
    else
        isAnyCheckboxChecked = true;
    if(!isAnyCheckboxChecked)
    {
        // show a message that user permissions have not been granted and ask user to provide user permissions
        alert('Select at least one user permission');
        window.Page_BlockSubmit = true;
        return;
    }
    else
        window.Page_BlockSubmit = false;
}
function UncheckAll(theElement)
{//debugger;
    //on chkReadOnlyUser.checked = true  
    var typeOfEmployeeControlId = $(getchildIDof("divTypeOfEmployee", "", theElement));
    var CorporateEmployeeControl;
    for(var i = 0; i < typeOfEmployeeControlId.rows.length ;i++)
    {
        for(var j = 0; j < typeOfEmployeeControlId.rows[i].cells.length ;j++)
        {
            for(var z = 0; z < typeOfEmployeeControlId.rows[i].cells[j].childNodes.length ;z++)
            {
                if((typeOfEmployeeControlId.rows[i].cells[j].childNodes[z].name+"").indexOf(theElement) > -1)
                {
                    if(typeOfEmployeeControlId.rows[i].cells[j].childNodes[z].type == 'radio' && typeOfEmployeeControlId.rows[i].cells[j].childNodes[z].value == '3')
                    {
                        CorporateEmployeeControl=typeOfEmployeeControlId.rows[i].cells[j].childNodes[z];
                    }
                }
            }
        }
    }
    if(document.getElementById(getchildIDof("divUserPermissions", "", "chkReadOnlyUser")).checked == true
        || document.getElementById(getchildIDof("divUserPermissions", "", "chkAdministrator")).checked == false)
    {
        var theForm = $(getchildIDof("divchklUserPermissions", "", "chklUserPermissions"));
        for(var i = 0; i < theForm.rows.length ;i++)
        {
            for(var j = 0; j < theForm.rows[i].cells.length ;j++)
            {
                for(var z = 0; z < theForm.rows[i].cells[j].childNodes.length ;z++)
                {
                    if((theForm.rows[i].cells[j].childNodes[z].name+"").indexOf("chklUserPermissions") > -1)
                    {
                        if(theForm.rows[i].cells[j].childNodes[z].type == 'checkbox')
                        {
                            theForm.rows[i].cells[j].childNodes[z].checked = false;
                        }
                        if((theForm.rows[i].cells[j].childNodes[z].nextSibling.innerHTML).indexOf("Run Report") > -1 && CorporateEmployeeControl.checked == true)
                        {
                            theForm.rows[i].cells[j].childNodes[z].checked = true;
                        }
                    }
                }
            }
        }
        document.getElementById(getchildIDof("divUserPermissions", "", "chkAdministrator")).checked = false;
    }
}
function checkAll(theElement)
{//debugger;
    //on chkAdministrator.checked = true
    if(document.getElementById(getchildIDof("divUserPermissions", "", "chkAdministrator")).checked == true)
    {
        var theForm = $(getchildIDof("divchklUserPermissions", "", "chklUserPermissions"));
        for(var i = 0; i < theForm.rows.length ;i++)
        {
            for(var j = 0; j < theForm.rows[i].cells.length ;j++)
            {
                for(var z = 0; z < theForm.rows[i].cells[j].childNodes.length ;z++)
                {
                    if((theForm.rows[i].cells[j].childNodes[z].name+"").indexOf("chklUserPermissions") > -1)
                    {
                        if(theForm.rows[i].cells[j].childNodes[z].type == 'checkbox')
                        {
                            theForm.rows[i].cells[j].childNodes[z].checked = true;
                        }
                    }
                }
            }
        }
        document.getElementById(getchildIDof("divUserPermissions", "", "chkReadOnlyUser")).checked = false;
    }
    else
    {
        UncheckAll('rdlTypeOfEmployee');
    }
}
function change(theElement)
{
    var isAnyCheckboxChecked = false;
    var isAnyCheckboxUnChecked = false;
    var varchkReadOnlyUser = document.getElementById(getchildIDof("divUserPermissions", "", "chkReadOnlyUser"));
    var varchkAdministrator = document.getElementById(getchildIDof("divUserPermissions", "", "chkAdministrator"));
    var theForm = $(getchildIDof("divchklUserPermissions", "", "chklUserPermissions"));
    var typeOfEmployeeControlId = $(getchildIDof("divTypeOfEmployee", "", theElement));
    var CorporateEmployeeControl;
    var RunReportControl;
    for(var i = 0; i < typeOfEmployeeControlId.rows.length ;i++)
    {
        for(var j = 0; j < typeOfEmployeeControlId.rows[i].cells.length ;j++)
        {
            for(var z = 0; z < typeOfEmployeeControlId.rows[i].cells[j].childNodes.length ;z++)
            {
                if((typeOfEmployeeControlId.rows[i].cells[j].childNodes[z].name+"").indexOf(theElement) > -1)
                {
                    if(typeOfEmployeeControlId.rows[i].cells[j].childNodes[z].type == 'radio' && typeOfEmployeeControlId.rows[i].cells[j].childNodes[z].value == '3')
                    {
                        CorporateEmployeeControl=typeOfEmployeeControlId.rows[i].cells[j].childNodes[z];
                    }
                }
            }
        }
    }
    for(var i = 0; i < theForm.rows.length ;i++)
    {
        for(var j = 0; j < theForm.rows[i].cells.length ;j++)
        {
            for(var z = 0; z < theForm.rows[i].cells[j].childNodes.length ;z++)
            {
                if((theForm.rows[i].cells[j].childNodes[z].name+"").indexOf("chklUserPermissions") > -1)
                {
                    if(theForm.rows[i].cells[j].childNodes[z].type == 'checkbox')
                    {
                        if(theForm.rows[i].cells[j].childNodes[z].checked == true)
                        {
                            // come out of the loop if any of the check box is being checked
                            if((theForm.rows[i].cells[j].childNodes[z].nextSibling.innerHTML).indexOf("Run Report") > -1 && CorporateEmployeeControl.checked == true)
                            {
                                isAnyCheckboxUnChecked = true;
                            }
                            else
                                isAnyCheckboxChecked = true;                            
                        }
                        else
                            isAnyCheckboxUnChecked = true;
                        if((theForm.rows[i].cells[j].childNodes[z].nextSibling.innerHTML).indexOf("Run Report") > -1 && CorporateEmployeeControl.checked == true)
                        {
                         RunReportControl = theForm.rows[i].cells[j].childNodes[z];
                        }
                    }
                }
            }
        }
    }
    if(!isAnyCheckboxChecked)
    {
    //to make chkReadOnlyUser.checked = true
        
        varchkReadOnlyUser.checked = true;
        varchkAdministrator.checked = false;
        if(CorporateEmployeeControl.checked == true)
        {
            RunReportControl.checked = true;
        }
    }
    if(!isAnyCheckboxUnChecked)
    {
    
    //to make chkAdministrator.checked = true
        varchkAdministrator.checked = true;
        varchkReadOnlyUser.checked = false;
    }
    if(isAnyCheckboxChecked && isAnyCheckboxUnChecked)
    {
        varchkReadOnlyUser.checked = false;
        varchkAdministrator.checked = false;
    }
}
function changeVisibility(Div, theElement)
{
// on rdlTypeOfEmployee change
    var theForm = document.forms[0], z = 0;
    for(z=0; z<theForm.length;z++)
    {
        if(theForm[z].type == 'radio' && theForm[z].name.indexOf(theElement) > 0)
        {
            if(theForm[z].checked == true)
            {
                if(theForm[z].value==1)
                {
                    document.getElementById(getchildIDof(Div, "", "ddlLocations")).style.visibility="visible";
                    document.getElementById(getchildIDof(Div, "", "lblHeadingLocation")).style.visibility="visible";
                    document.getElementById(getchildIDof(Div, "", "lblHeadingGroup")).style.visibility="hidden";
                    document.getElementById(getchildIDof(Div, "", "ddlLocationGroups")).style.visibility="hidden";
                }
                else if(theForm[z].value==2)
                {
                    document.getElementById(getchildIDof(Div, "", "ddlLocations")).style.visibility="hidden"; 
                    document.getElementById(getchildIDof(Div, "", "lblHeadingLocation")).style.visibility="hidden";
                    document.getElementById(getchildIDof(Div, "", "lblHeadingGroup")).style.visibility="visible";
                    document.getElementById(getchildIDof(Div, "", "ddlLocationGroups")).style.visibility="visible";          
                }
                else if(theForm[z].value==3)
                {
                    document.getElementById(getchildIDof(Div, "", "ddlLocations")).style.visibility="hidden"; 
                    document.getElementById(getchildIDof(Div, "", "lblHeadingLocation")).style.visibility="hidden";
                    document.getElementById(getchildIDof(Div, "", "lblHeadingGroup")).style.visibility="hidden";  
                    document.getElementById(getchildIDof(Div, "", "ddlLocationGroups")).style.visibility="hidden";
                }
            }
        }
    }        
    change(theElement);
}

function CheckPermissions(themeDropDownId, permissionsCheckboxListId, administratorCheckBoxId, employeeTypeCheckboxId)
{
    var themeDropDown = document.getElementById(themeDropDownId);    
    if (themeDropDown == null)
        return;
    var corporateEmployeeChecked = document.getElementById(employeeTypeCheckboxId + '_2').checked;
    var singleLocationEmployeeChecked = document.getElementById(employeeTypeCheckboxId + '_0').checked;
    
    var disabled = false;
    
    if ((themeDropDown.value != '00000000-0000-0000-0000-000000000000' && corporateEmployeeChecked) || singleLocationEmployeeChecked)
    {   disabled = true;}
    
    if(document.getElementById(permissionsCheckboxListId + '_1') != null)
        document.getElementById(permissionsCheckboxListId + '_1').disabled = disabled;
    if(document.getElementById(permissionsCheckboxListId + '_7') != null)
        document.getElementById(permissionsCheckboxListId + '_7').disabled = disabled;
    if(document.getElementById(permissionsCheckboxListId + '_11') != null)
        document.getElementById(permissionsCheckboxListId + '_11').disabled = disabled;
    if(document.getElementById(permissionsCheckboxListId + '_12') != null)
        document.getElementById(permissionsCheckboxListId + '_12').disabled = disabled;
    if(document.getElementById(permissionsCheckboxListId + '_13') != null)
        document.getElementById(permissionsCheckboxListId + '_13').disabled = disabled;
    if(document.getElementById(administratorCheckBoxId) != null)
        document.getElementById(administratorCheckBoxId).disabled = disabled;

    if(disabled)
    {
        if(document.getElementById(permissionsCheckboxListId + '_1') != null)
            document.getElementById(permissionsCheckboxListId + '_1').checked = false;
        if(document.getElementById(permissionsCheckboxListId + '_7') != null)
            document.getElementById(permissionsCheckboxListId + '_7').checked = false;
        if(document.getElementById(permissionsCheckboxListId + '_11') != null)
            document.getElementById(permissionsCheckboxListId + '_11').checked = false;
        if(document.getElementById(permissionsCheckboxListId + '_12') != null)
            document.getElementById(permissionsCheckboxListId + '_12').checked = false;
        if(document.getElementById(permissionsCheckboxListId + '_13') != null)
            document.getElementById(permissionsCheckboxListId + '_13').checked = false;
        if(document.getElementById(administratorCheckBoxId) != null)
            document.getElementById(administratorCheckBoxId).checked = false;
    }
}

function addNewRecord(currentControl)
{//debugger;
    var tblControl = currentControl.parentElement.previousSibling.children[0];
    var tbody = tblControl.getElementsByTagName("TBODY")[0];
    var row = document.createElement("TR")
    row = tblControl.rows[1];
    tbody.appendChild(row);
}

//Validates deleted record to prevent it from editing when user selects the record from the grid.
function ValidateDeletedRecordLinkClick(control, gridView, msg)
{
    var varGridControl = $(control.parentNode.offsetParent.id.substring(0, control.parentNode.offsetParent.id.lastIndexOf('_'))+"_"+gridView);
    var RowIndex = control.id.substring(control.id.lastIndexOf('_')-1, control.id.lastIndexOf('_')) - 1;
    
    if(varGridControl != null)
    {
        var totalNumberCellsInGridControl = varGridControl.rows.length;
        var isAnyRecordSelected = false;
        var cellNo = 0;
        
        for(var CellIndex = 0; CellIndex < varGridControl.rows[0].cells.length; CellIndex++)
        {
            if(navigator.appName=="Netscape")
            {
                if( varGridControl.rows[0].cells[CellIndex].textContent == "Status")
                {
                    cellNo = CellIndex;
                    break;
                }
            }
            else
            {
                if( varGridControl.rows[0].cells[CellIndex].innerText == "Status")
                {
                    cellNo = CellIndex;
                    break;
                }
            }
        }
        
        if(varGridControl.rows[RowIndex].cells[cellNo].innerHTML == "Deleted")
        {
            alert(msg);
            return false;
        }
        
    }
}

function ValidateDeletedRecord(control, gridView, msg)
{//debugger;
    var varGridControl = $(control.id.substring(0, control.id.lastIndexOf('_'))+"_"+gridView);
    if(varGridControl != null)
    {
        var totalNumberCellsInGridControl = varGridControl.rows.length;
        var isAnyRecordSelected = false;
        var cellNo = 0;
        
        for(var CellIndex = 0; CellIndex < varGridControl.rows[0].cells.length; CellIndex++)
        {
            if(navigator.appName=="Netscape")
            {
                if( varGridControl.rows[0].cells[CellIndex].textContent == "Status")
                {
                    cellNo = CellIndex;
                    break;
                }
            }    
            else
            {
                if( varGridControl.rows[0].cells[CellIndex].innerText == "Status")
                {
                    cellNo = CellIndex;
                    break;
                }
            } 
        }
        for(var currentCellIndex = 0; currentCellIndex < totalNumberCellsInGridControl; currentCellIndex++)
        {
            if(varGridControl.rows[currentCellIndex].cells.length > 0 && varGridControl.rows[currentCellIndex].cells[0].childNodes[0].type == "checkbox")
            {
                if(varGridControl.rows[currentCellIndex].cells[0].childNodes[0].checked == true)
                {
                    if(varGridControl.rows[currentCellIndex].cells[cellNo].innerHTML == "Deleted")
                    {
                        alert(msg);
                        isAnyRecordSelected = true;
                        break;
                    }
                }
            }
        }
        if(isAnyRecordSelected)
        {
            window.Page_BlockSubmit = true;
            return false;
        }
    }
}

function ValidateEditCSUser(control, gridView, errorMessage)
{
//debugger;
    var varGridControl = $(control.id.substring(0, control.id.lastIndexOf('_'))+"_"+gridView);
    if(varGridControl != null)
    {
        var totalNumberCellsInGridControl = varGridControl.rows.length;
        var isAnyRecordSelected = false;
        for(var currentCellIndex = 1; currentCellIndex < totalNumberCellsInGridControl; currentCellIndex++)
        {
            if(varGridControl.rows[currentCellIndex].cells.length > 0 && varGridControl.rows[currentCellIndex].cells[0].childNodes[0].type == "checkbox")
            {
                if(varGridControl.rows[currentCellIndex].cells[0].childNodes[0].checked == true)
                {
                    isAnyRecordSelected = true;
                    break;
                }
            }
        }
        if(!isAnyRecordSelected)
        {
            window.Page_BlockSubmit = true;
            alert(errorMessage);
            return false;
        }
        else
        {
            window.Page_BlockSubmit = false;
            return;
        }
    }
    else
    {
        window.Page_BlockSubmit = true;
        return false;
    }
}
function HtmlCheck()
{
/*
            debugger;
    var regex = /^[^\<\>\%\'\"]{0,200}$/;
    for(z=0; z<theForm.length; z++)
    {
        if(theForm[z].type == 'text')
        {
            if (!(regex.test(theForm[z].value)))
            {
                theForm[z].value = "";
//                window.Page_BlockSubmit = true;
            }
        }
    }
    */
}

//------Funtion for Move Button List Box --LocatioHomePage.aspx---Starts Here---Vardan
function showlistmove ()
{
    document.getElementById("moveitems").style.display="inline";
    document.getElementById("moveitems").style.visibility="visible";
}

function hidelistmove ()
{
    setTimeout ( "hidelbox()", 3000 );
    //set delay time
}

function hidelbox()
{  
 document.getElementById("moveitems").style.display="none";
 document.getElementById("moveitems").style.visibility="hidden";
}
         
//------Funtion for Move Button List Box --LocatioHomePage.aspx---Ends Here         


function ChangeCountry(ddlState)
{
 var countrycode = document.getElementById(getchildIDof("tdcountry", "","InvisCountryCode"));
 var ddlCountry = document.getElementById(getchildIDof("tdcountry", "", "ddlCountryCode"));

    var index= ddlState.selectedIndex;
    if(index>0 && index <=52)
    {
      ddlCountry.selectedIndex=2;
      countrycode.value='2';
    }
    if(index > 52)
    {
    ddlCountry.selectedIndex=1;
    countrycode.value='1';
    }

}

function ChangeCountryMozilla(ddlState,InvisCountryCode,ddlCountryCode)
{
var countrycode = document.getElementById(InvisCountryCode);
 var ddlCountry = document.getElementById(ddlCountryCode);

    var index= ddlState.selectedIndex;
    if(index>0 && index <=52)
    {
      ddlCountry.selectedIndex=2;
      countrycode.value='2';
    }
    if(index > 52)
    {
    ddlCountry.selectedIndex=1;
    countrycode.value='1';
    }

}


function ChangeCountryForLocation(ddlState)
{
 var countrycode = document.getElementById(getchildIDof("tdLocCountry", "","InvisCountryCode"));
 var ddlCountry = document.getElementById(getchildIDof("tdLocCountry", "", "ddlCountryCode"));

    var index= ddlState.selectedIndex;
    if(index>0 && index <=52)
    {
      ddlCountry.selectedIndex=2;
      countrycode.value='2';
    }
    if(index > 52)
    {
    ddlCountry.selectedIndex=1;
    countrycode.value='1';
    }

}

function validateSpecialCharacters(source, args)
{
    var iChars = '<>%;+"';
    for (var i = 0; i < args.Value.length; i++) 
    {
        if (iChars.indexOf(args.Value.charAt(i)) != -1) 
        {  	           
            args.IsValid = false;
            return;
        }
    }
    args.IsValid = true;
}  