﻿// JScript File
var gctWindow = null;
var gctCallBack = null;
var gctIsCallBack = null;
var gctOverlay = null;
var GCTWindow = new GCTWINDOW();
var IsEffect = 'true';
var GCTAutoScroll = false;
function GCTWINDOW() {
    this.open = OpenWindow;
    this.close = closeGCTWindow;
    this.customOpen = OpenCustomWindow;
    this.noEffect = function() { IsEffect = 'false' };
    this.SetPosition = ReposGCTWindow;
    this.setBounds = setHeightWidth;
    this.fromScrollTop = false;
}

function setHeightWidth(height, width) {
    var gctwin = document.getElementById("GCTWINDOW");
    gctwin.style.height = height + "px";
    gctwin.style.width = width + "px";
    var Pagesize = getPageSize();
    var top = (Pagesize.height - height) / 2 + Pagesize.scrollTop;
    if (top >= 0) gctwin.style.top = top + 'px';
    else gctwin.style.top = '0px';
    gctwin.style.left = (Pagesize.width - width) / 2 + 'px';
    height -= 18;
    document.getElementById('GCTIFrame').style.height = height + 'px';
    document.getElementById('GCTIFrame').style.width = width + 'px';
}

function OpenWindow(url, title, width, height, modal) {
    var Pagesize = getPageSize();
    var gctOver = null;
    var gctwin = null;
    if (document.getElementById('GCTOVERLAY') == null) {
        gctOver = document.createElement('div');
        document.body.appendChild(gctOver);
        gctwin = document.createElement('div');
        document.body.appendChild(gctwin);

        gctOver.setAttribute('id', 'GCTOVERLAY');
        gctwin.setAttribute('id', 'GCTWINDOW');
        gctOver.style.position = 'absolute';
        gctOver.style.zindex = 3001;
        gctwin.style.position = 'absolute';
        gctwin.style.zindex = 3002;
        gctwin.style.opacity = 0;
        gctwin.style.MozOpacity = 0;
        gctwin.style.KhtmlOpacity = 0;
        gctwin.style.filter = "alpha(opacity=0)";
        gctOver.style.left = '0px';
        gctOver.style.top = '0px';
        gctOver.style.opacity = 0;
        gctOver.style.MozOpacity = 0;
        gctOver.style.KhtmlOpacity = 0;
        gctOver.style.filter = "alpha(opacity=0)";

    }
    else {
        gctOver = document.getElementById('GCTOVERLAY');
        gctwin = document.getElementById('GCTWINDOW');
    }
    gctOver.className = 'GctOverlay';
    gctwin.className = 'GctWindow';
    gctWindow = 'GCTWINDOW';
    gctOverlay = 'GCTOVERLAY';
    gctwin.style.width = width + 'px';
    gctwin.style.height = height + 'px';

    if (modal == 'True' || modal == 'true') {
        gctOver.style.display = '';

        opacity(gctOverlay, 0, 50, 0);
        if (document.body.offsetHeight > window.screen.height)
            gctOver.style.height = document.body.offsetHeight + 'px';
        else
            gctOver.style.height = window.screen.height + 'px';
        // gctOver.style.height = document.body.scrollHeight + "px";

        if (document.body.offsetWidth > window.screen.width)
            gctOver.style.width = document.body.offsetWidth + 'px';
        else
            gctOver.style.width = window.screen.width - 23 + 'px';
    }
    //gctOver.innerHTML += "<!--[if lte IE 6.5]><iframe class='GCTMask'></iframe><![endif]-->";
    gctwin.style.display = '';
    var top = (Pagesize.height - height) / 2 + Pagesize.scrollTop;
    if (GCTWindow.fromScrollTop) top = Pagesize.scrollTop;
    if (top >= 0)
        gctwin.style.top = top + 'px';
    else
        gctwin.style.top = '0px';
    gctwin.style.left = (Pagesize.width - width) / 2 + 'px';

    height -= 3;
    gctwin.innerHTML = " <iframe id='GCTIFrame' class='GctWindowFrame' height='" + height + "' width='" + width + "' frameborder='0'  />";
    //<div align='center' style='border: thin solid #000000' ><iframe id='GCTIFrame' class='GctWindowFrame' height='" + height + "' width='" + width + "' frameborder='0'  /></div>";
    opacity(gctWindow, 0, 100, 1000);
    document.getElementById('GCTIFrame').src = url;
    if (GCTAutoScroll) window.scrollTo(0, 0);
}
var fireFox = navigator.userAgent.indexOf("Firefox") > -1;
var LocFire = location.href;
function OpenCustomWindow(htm, title, width, height, modal) {

    var LocCal = LocFire.indexOf("EventCalender/scheduler.aspx?") > -1;
    var GctCalWin = htm.indexOf("GctCalenderWindow") > -1;
    var gctOver = null;
    var gctwin = null;
    if (document.getElementById('GCTOVERLAY') == null) {
        gctOver = document.createElement('div');
        document.body.appendChild(gctOver);
        gctwin = document.createElement('div');
        document.body.appendChild(gctwin);
        gctOver.setAttribute('id', 'GCTOVERLAY');
        gctwin.setAttribute('id', 'GCTWINDOW');
        gctOver.style.position = 'absolute';
        gctOver.style.zindex = 3001;
        gctwin.style.position = 'absolute';
        gctwin.style.zindex = 3002;
        gctwin.style.opacity = 0;
        gctwin.style.MozOpacity = 0;
        gctwin.style.KhtmlOpacity = 0;
        gctwin.style.filter = "alpha(opacity=0)";
        gctOver.style.left = '0px';
        gctOver.style.top = '0px';
        gctOver.style.opacity = 0;
        gctOver.style.MozOpacity = 0;
        gctOver.style.KhtmlOpacity = 0;
        gctOver.style.filter = "alpha(opacity=0)";
    }
    else {
        gctOver = document.getElementById('GCTOVERLAY');
        gctwin = document.getElementById('GCTWINDOW');
    }
    gctOver.className = 'GctOverlay';
    gctwin.className = 'GctWindow';
    gctWindow = 'GCTWINDOW';
    gctOverlay = 'GCTOVERLAY';
    if (modal == 'True' || modal == 'true') {
        gctOver.style.display = '';
        if (IsEffect == 'true')
            opacity(gctOverlay, 0, 70, 0);
        else {
            var object = document.getElementById(gctOverlay).style;
            object.opacity = (100 / 100);
            object.MozOpacity = (100 / 100);
            object.KhtmlOpacity = (100 / 100);
            object.filter = "alpha(opacity=" + 100 + ")";
        }
        if (document.body.offsetHeight > window.screen.height)
            gctOver.style.height = document.body.offsetHeight + 'px';
        else
            gctOver.style.height = window.screen.height + 'px';
        //  gctOver.style.height = document.body.scrollHeight + "px";

        if (document.body.offsetWidth > window.screen.width)
            gctOver.style.width = document.body.offsetWidth + 'px';
        else
            gctOver.style.width = window.screen.width - 23 + 'px';
    }
    gctOver.innerHTML += "<!--[if lte IE 6.5]><iframe class='GCTMask'></iframe><![endif]-->";
    gctwin.style.display = '';
    gctwin.innerHTML = "<div  class='GctTitleRow' align='center' ><span unselectable='on' class='GctTitle'>" + title + "</span></div>" + htm;
    gctwin.style.width = width + 'px';
    gctwin.style.height = height + 'px';
    if (fireFox && LocFire && GctCalWin) {
        window.scrollTo(0, 0);
        gctwin.style.top = ((window.screen.height - height) / 4) - 10 + 'px';
        gctwin.style.left = ((document.body.clientWidth - width) / 3) + 150 + 'px';
    }
    else {
        gctwin.style.top = (window.screen.height - height) / 3 + 'px';
        gctwin.style.left = (document.body.clientWidth - width) / 2 + 'px';
    }
    if (IsEffect == 'true')
        opacity(gctWindow, 0, 100, 1000);
    else {
        var object = document.getElementById(gctWindow).style;
        object.opacity = (100 / 100);
        object.MozOpacity = (100 / 100);
        object.KhtmlOpacity = (100 / 100);
        object.filter = "alpha(opacity=" + 100 + ")";
    }
    if (GCTAutoScroll) window.scrollTo(0, 0);
}

function ReposGCTWindow(left, top) {
    var gctwin = document.getElementById(gctWindow);
    gctwin.style.top = top + 'px';
    gctwin.style.left = left + 'px';
}

function closeGCTWindow(callbackfunction) {
    if (gctWindow != null) {
        if (IsEffect == 'true') {
            opacity(gctOverlay, 50, 0, 2000);
            opacity(gctWindow, 100, 0, 1000);
        }
        else {
            document.getElementById(gctOverlay).style.display = 'none';
            document.getElementById(gctWindow).style.display = 'none';
        }
    }
    if (callbackfunction != '')
        eval(callbackfunction + "();");
}

function closeWindow() {
    if (gctWindow != null) {
        if (IsEffect == 'true') {
            opacity(gctOverlay, 50, 0, 2000);
            opacity(gctWindow, 100, 0, 1000);
        }
        else {
            document.getElementById(gctOverlay).style.display = 'none';
            document.getElementById(gctWindow).style.display = 'none';
        }
        if (window.parent.buttonClick == true)
            window.parent.RefreshPage();
    }
}
var ie = navigator.userAgent.indexOf("MSIE") > -1;
var ie6 = navigator.userAgent.indexOf("MSIE 6") > -1;
var ie7 = navigator.userAgent.indexOf("MSIE 7") > -1;
var safari = navigator.userAgent.indexOf("Safari") > -1;
var macintosh = navigator.userAgent.indexOf("Macintosh") > -1;
var fireFox = navigator.userAgent.indexOf("Firefox") > -1;

function getPageSize() {
    var iebody = document.compatMode && document.compatMode != "BackCompat"
        ? document.documentElement : document.body;
    var b = document.body;
    var xScroll = (window.innerWidth && window.scrollMaxX)
            ? window.innerWidth + window.scrollMaxX :
                (b.scrollWidth > b.offsetWidth ? b.scrollWidth : b.offsetWidth),
        yScroll = (window.innerHeight && window.scrollMaxY)
            ? window.innerHeight + window.scrollMaxY :
                (b.scrollHeight > b.offsetHeight ? b.scrollHeight : b.offsetHeight),
        pageWidth = ie || ie6 || ie7 ? iebody.scrollWidth :
            (document.documentElement.clientWidth || self.innerWidth);
    pageHeight = ie || ie6 || ie7 ? iebody.clientHeight :
            (document.documentElement.clientHeight || self.innerHeight);

    var width = ie || ie6 || ie7 ? iebody.clientWidth :
            (document.documentElement.clientWidth || self.innerWidth),
        height = ie || ie6 || ie7 ? iebody.clientHeight : self.innerHeight;

    return {
        pageWidth: xScroll < pageWidth ? pageWidth : xScroll,
        pageHeight: yScroll < pageHeight ? pageHeight : yScroll,
        width: width,
        height: height,
        scrollLeft: ie || ie6 || ie7 ? iebody.scrollLeft : pageXOffset,
        scrollTop: ie || ie6 || ie7 ? iebody.scrollTop : pageYOffset
    }
}

function opacity(id, opacStart, opacEnd, millisec) {
    var speed = Math.round(millisec / 100);
    var timer = 0;

    if (opacStart > opacEnd) {
        for (i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')", (timer * speed));
            timer++;
        } 
    }
    else if (opacStart < opacEnd) {
        for (i = opacStart; i <= opacEnd; i++) {
            setTimeout("changeOpac(" + i + ",'" + id + "')", (timer * speed));
            timer++;
        } 
    }

}
var ov = 'false';
var op = 'false';
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";

    if (id == gctOverlay && ov == 'true' && opacity == 0) {
        document.getElementById(gctOverlay).style.display = 'none';
        ov = 'mid';
    }
    if (id == gctWindow && op == 'true' && opacity == 0) {
        document.getElementById(gctWindow).style.display = 'none';
        op = 'mid';
    }
    if (id == gctWindow && op != 'mid') { op = 'true'; }
    else if (id == gctWindow && op == 'mid') { op = 'false'; }
    if (id == gctOverlay && ov != 'mid') { ov = 'true'; }
    else if (id == gctOverlay && ov == 'mid') { ov = 'false'; }
}



function SubmitSearch() {
    window.parent.SubmitPage(window);
}

function CloseWind() {
    window.parent.GCTWindow.close('');
}
function validateLength(src, args) {
    var splchr = "~!@#$%^&*";
    var val = args.Value.replace(/^\s+/g, "");
    val = val.replace(/\s+$/g, "");
    if (val.length >= 6) {
        var flag = false;
        var isWithNumeric = false;
        for (var i = 0; i <= val.length; i++) {
            for (var j = 0; j <= 9; j++) {
                if (val.substr(i, 1) == j.toString()) {
                    isWithNumeric = true;
                }
            }
            for (var j = 0; j < splchr.length; j++)
                if (val.indexOf(splchr.substr(j, 1)) > -1 && isWithNumeric) flag = true;
        }
        args.IsValid = flag;
    }
    else {
        args.IsValid = false;
    }
}
function checkImage(imdId) {
    var imgVar = document.getElementById(imdId);
    if (imgVar != '') {
        imgVar.style.display = 'none';
    }
    else {
        imgVar.style.display = 'block';
    }
}


function SelectAll(id) {

    //get reference of GridView control
    var grid = document.getElementById("<%= GrdDesign.ClientID %>");

    //variable to contain the cell of the grid
    var cell;

    if (grid.rows.length > 0) {
        alert(grid.rows.length);
        //loop starts from 1. rows[0] points to the header.
        for (i = 1; i < grid.rows.length; i++) {

            //get the reference of first column
            cell = grid.rows[i].cells[0];
            // alert(cell.parentNode.parentNode.tagName);
            //loop according to the number of childNodes in the cell
            for (j = 0; j < cell.childNodes.length - 1; j++) {
                // alert(cell.childNodes[j].childNodes[j].tagName);      
                //if childNode type is CheckBox   type="checkbox"              
                if (cell.childNodes[j].childNodes[j].type == "checkbox") {
                    //alert(cell.childNodes[j].childNodes[j].type);

                    //assign the status of the Select All checkbox to the cell checkbox within the grid
                    cell.childNodes[j].childNodes[j].checked = document.getElementById(id).checked;
                }
            }
        }
    }
}

//Author: Subhash Saini
//Date: 27/06/2008
//this function checked all the checkboxes on checking the Select all checked box in header of grid View

function SelectAllCheckBox(id, grd) {
    //get reference of GridView control
    var grid = document.getElementById(grd);

    //variable to contain the cell of the grid
    var cell;
    if (grid.rows.length > 0) { //loop starts from 1. rows[0] points to the header.
        for (i = 1; i < grid.rows.length; i++) {
            //get the reference of first column
            cell = grid.rows[i].cells[0];

            // alert(cell.parentNode.parentNode.tagName);
            //loop according to the number of childNodes in the cell
            for (j = 0; j < cell.childNodes.length - 1; j++) {
                //alert(cell.childNodes[j].type); // alert(cell.childNodes[j].childNodes[j].tagName); //if childNode type is CheckBox   type="checkbox"
                // if (cell.childNodes[j].childNodes[j].type == "checkbox")
                if (cell.childNodes[j].type == "checkbox") {
                    //alert(cell.childNodes[j].childNodes[j].type);
                    //assign the status of the Select All checkbox to the cell checkbox within the grid
                    cell.childNodes[j].checked = document.getElementById(id).checked;
                }
            }
        }
    }

}
//Author:Subhash Saini
//Date: 09/07/2008
//This function validate the float values
function ValidateFloat(txtVal) {
    var valText = txtVal.value;
    var valLength = txtVal.value.length;
    if (valLength > 5) {
        var strDot = valText.indexOf('.');
        if (strDot != 5) {
            var fn1 = txtVal.value.substring(0, 4);
            txtVal.value = fn1;
        }
    }
}
function blockNonNumbers(obj, e, allowDecimal, allowNegative) {
    var key;
    var isCtrl = false;
    var keychar;
    var reg;
    if (window.event) {
        key = e.keyCode;
        isCtrl = window.event.ctrlKey
    }
    else if (e.which) {
        key = e.which;
        isCtrl = e.ctrlKey;
    }
    if (isNaN(key)) return true;
    keychar = String.fromCharCode(key);
    // check for backspace or delete, or if Ctrl was pressed
    if (key == 8 || isCtrl) {
        return true;
    }

    reg = /\d/;
    var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
    var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;
    return isFirstN || isFirstD || reg.test(keychar);
}

//Firoz : 24 Oct

function closeWindowFromInnerPage() {
    window.parent.GCTWindow.close('');
}

function checkMaxLen(txt, maxLen, inp) {
    var inpp = document.getElementById(inp);
    if (txt.value.length > (maxLen)) {
        var cont = txt.value;
        txt.value = cont.substring(0, (maxLen));
        return false;
    }
    else {
        if (inpp) {
            inpp.value = txt.value.length;
        }
    }
}


function EraseInvalidData(Id) {
    badkeys = new Array("<", ">", "<<", ">>");
    var val = document.getElementById(Id).value;
    for (i = 0; i < val.length; i++) {
        for (j = 0; j < badkeys.length; j++) {
            if (val.indexOf(badkeys[j], i) == -1) {
                // alert((parm.charAt(j),i));         
            }
            else {
                document.getElementById(Id).value = val.replace(badkeys[j], '');
            }
        }
    }
}

function EraseInvalidDataForBlur(Id) {
    badkeys = new Array("<", ">", "<<", ">>");
    var val = document.getElementById(Id).value;
    for (i = 0; i < val.length; i++) {
        for (j = 0; j < badkeys.length; j++) {
            val = val.replace(badkeys[j], '');
        }
        document.getElementById(Id).value = val;
    }
}



function extractNumber(obj, decimalPlaces, allowNegative) {
    var temp = obj.value;
    // avoid changing things if already formatted correctly
    var reg0Str = '[0-9]*';
    if (decimalPlaces > 0) {
        reg0Str += '\\.?[0-9]{0,' + decimalPlaces + '}';
    } else if (decimalPlaces < 0) {
        reg0Str += '\\.?[0-9]*';
    }
    reg0Str = allowNegative ? '^-?' + reg0Str : '^' + reg0Str;
    reg0Str = reg0Str + '$';
    var reg0 = new RegExp(reg0Str);
    if (reg0.test(temp)) return true;

    // first replace all non numbers
    var reg1Str = '[^0-9' + (decimalPlaces != 0 ? '.' : '') + (allowNegative ? '-' : '') + ']';
    var reg1 = new RegExp(reg1Str, 'g');
    temp = temp.replace(reg1, '');

    if (allowNegative) {
        // replace extra negative
        var hasNegative = temp.length > 0 && temp.charAt(0) == '-';
        var reg2 = /-/g;
        temp = temp.replace(reg2, '');
        if (hasNegative) temp = '-' + temp;
    }
    if (decimalPlaces != 0) {
        var reg3 = /\./g;
        var reg3Array = reg3.exec(temp);
        if (reg3Array != null) {
            // keep only first occurrence of .
            //  and the number of places specified by decimalPlaces or the entire string if decimalPlaces < 0
            var reg3Right = temp.substring(reg3Array.index + reg3Array[0].length);
            reg3Right = reg3Right.replace(reg3, '');
            reg3Right = decimalPlaces > 0 ? reg3Right.substring(0, decimalPlaces) : reg3Right;
            temp = temp.substring(0, reg3Array.index) + '.' + reg3Right;
        }
    }
    obj.value = temp;
} 
     