﻿function OpenCenteredWindow(url, parms, height, width) {
    // var parms = 'toolbar=0,status=0,menubar=0,scrollbars=1,resizable=0';
    //var height=200;
    //var width=300;
    var name = null;
    var left = Math.floor((screen.width - width) / 2);
    var top =
	 Math.floor((screen.height - height) / 2);
    var winParms = "top=" + top + ",left=" + left + ",height=" + height + ",width=" + width;
    if (parms) {
        winParms += "," + parms;
    }
   
    var win = window.open(url, name, winParms);

    if (parseInt(navigator.appVersion) >= 4 && win != null) {
//        win.location.reload(true);
        win.window.focus();
    }
}
function FullScreenPopup(url) {

    var left = 0;
    var top = 0;
    var popUpsBlocked = false;
    var mine = window.open('', '', 'width=1,height=1,left=0,top=0,scrollbars=no');
    if (mine != null) {
        popUpsBlocked = false;
        mine.close()
    }
    else {
        popUpsBlocked = true;
    }
    if (popUpsBlocked) {
        //alert("We wish to open the page in a popup window but we detect that you have blocked popups\n To show the page please allow popups");
        $find('PopupBlockerPopup').show();
        return;
    }  

    var params = 'width=' + screen.width + ', height=' + screen.height;
    params += ', top=' + top + ', left=' + left;
    params += ', directories=no';
    params += ', location=no';
    params += ', menubar=no';
    params += ', resizable=yes';
    params += ', scrollbars=yes';
    params += ', status=yes';
    params += ', toolbar=no';

    var newwin = window.open(url, 'windowname4', params);
    if (newwin != null) {
        if (newwin.focus) { newwin.focus() }
    }
    return false;
}

function FullScreenModalPopup(url) {

    var left = 0;
    var top = 0;
    var newwin;
    var params = 'width=' + screen.width + ', height=' + screen.height;
    params += ', top=' + top + ', left=' + left;
    params += ', directories=no';
    params += ', location=no';
    params += ', menubar=no';
    params += ', resizable=yes';
    params += ', scrollbars=yes';
    params += ', status=no';
    params += ', toolbar=no';

    // to handle in IE 7.0           
    if (window.showModalDialog) {

        newwin = window.showModalDialog(url, 'fullScreenPopupWindow', "dialogHeight:" + screen.height + "px,dialogWidth:" + screen.width + "px,resizable:yes,center:yes,");

    }
    // to handle in Firefox
    else {
        //newwin = window.open("PopupWin.aspx?Control1="+fname + "&ControlVal=" + val,'Show Popup Window','height=90,width=250,resizable=yes,modal=yes');


        newwin = window.open(url, 'windowname4', params + ",resizable=yes,modal=yes");
        //retVal.focus();            
    }

    if (newwin.focus) { newwin.focus() }
    return false;
}
var currPrefs = new Array()
function getPrefsData(url) {
    var prefs = showModalDialog(url, currPrefs,
        "dialogWidth:400px; dialogHeight:300px")
    //        if (prefs) {
    //            if (prefs["name"]) {
    //                document.all.firstName.innerText = prefs["name"]
    //                currPrefs["name"] = prefs["name"]
    //            }
    //            if (prefs["bgColor"]) {
    //                document.body.style.backgroundColor = prefs["bgColor"]
    //                currPrefs["bgColor"] = prefs["bgColor"]
    //            }
    //            if (prefs["textColor"]) {
    //                document.body.style.color = prefs["textColor"]
    //                currPrefs["textColor"] = prefs["textColor"]
    //            }
    //            if (prefs["h1Size"]) {
    //                document.all.welcomeHeader.style.fontSize = prefs["h1Size"]
    //                currPrefs["h1Size"] = prefs["h1Size"]
    //            }
    //        }
}
function ValidateEmail(email) {
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    if (reg.test(email) == false)
        return false;

    return true;
}

function OpenPopup(url) {

    OpenCenteredWindow(url, 'toolbar=0,status=0,menubar=0,scrollbars=1,resizable=0', 560, 800); return false;
}
function OpenPopupOfSpecificWidthHeight(url) {

    OpenCenteredWindow(url, 'toolbar=0,status=0,menubar=0,scrollbars=1,resizable=0', 700, 900); return false;
}
function Checknumeric() /* function start to validate emp id  (html controle) onkeypess event */
{
    var e = window.event;

    if ((e.keyCode >= 48 && e.keyCode <= 57)) {

    }
    else {

        return false;
    }
}

function LimitInput(control) {
    if (control.value.length > control.attributes["maxLength"].value) {
        control.value = control.value.substring(0, control.attributes["maxLength"].value);
    }
};

function CheckAlphanumeric1(text) {

    var reg = /^[a-zA-Z0-9]+$/;
    if (reg.test(text) == false)
        return false;

    return true;
}
function CheckNumeric(text) {
    var reg = /^[0-9]+$/
    if (reg.test(text) == false)
        return false;

    return true;
}

function CheckAlpha(text) {
    var reg = /^[A-Z]+$/
    if (reg.test(text) == false)
        return false;

    return true;
}


//gridview checkbox column state change mgmt methods

//call when we need to change state of specific checkbox
function ChangeCheckBoxState(id, checkState) {
    var cb = document.getElementById(id);
    if (cb != null)
        cb.checked = checkState;
}

//call when we need to change state of all checkboxes
function ChangeAllCheckBoxStates(CheckBoxIDs, checkState) {
    // Toggles through all of the checkboxes defined in the CheckBoxIDs array
    // and updates their value to the checkState input parameter     
    if (CheckBoxIDs != null) {
        for (var i = 0; i < CheckBoxIDs.length; i++)
            ChangeCheckBoxState(CheckBoxIDs[i], checkState);
        //enable/disable the add to list button

    }
}

//call when state changes of any checkbox (except header checkbox)
function ChangeHeaderAsNeeded(CheckBoxIDs) {
    // Whenever a checkbox in the GridView is toggled, we need to
    // check the Header checkbox if ALL of the GridView checkboxes are
    // checked, and uncheck it otherwise
    if (CheckBoxIDs != null) {
        // check to see if all other checkboxes are checked
        if (CheckBoxIDs.length > 1) {
            for (var i = 1; i < CheckBoxIDs.length; i++) {
                var cb = document.getElementById(CheckBoxIDs[i]);
                if (!cb.checked) {
                    // Whoops, there is an unchecked checkbox, make sure
                    // that the header checkbox is unchecked
                    ChangeCheckBoxState(CheckBoxIDs[0], false);
                    return;
                }
            }
            // If we reach here, ALL GridView checkboxes are checked
            ChangeCheckBoxState(CheckBoxIDs[0], true);
        }
        else {
            ChangeCheckBoxState(CheckBoxIDs[0], false);        
        }
    }
}

function ThousandSeparator(decimalDigits, Value) {
    // Separator Length. Here this is thousand separator
    var separatorLength = 3;
    var OriginalValue = Value;
    var TempValue = "" + OriginalValue;
    var NewValue = "";
    // Store digits after decimal
    var pStr;
    // store digits before decimal
    var dStr;
    // Add decimal point if it is not there
    if (TempValue.indexOf(".") == -1) { TempValue += "." }
    dStr = TempValue.substr(0, TempValue.indexOf("."));
    pStr = TempValue.substr(TempValue.indexOf("."))
    // Add "0" for remaining digits after decimal point
    while (pStr.length - 1 < decimalDigits) { pStr += "0" }
    if (pStr == '.') pStr = '';
    if (dStr.length > separatorLength) {
        // Logic of separation                
        while (dStr.length > separatorLength) {
            NewValue = "," + dStr.substr(dStr.length - separatorLength) + NewValue;
            dStr = dStr.substr(0, dStr.length - separatorLength);
        }
        NewValue = dStr + NewValue;
    }
    else {
        NewValue = dStr;
    }
    //  Add decimal part
    NewValue = NewValue + pStr;
    // Show Final value
    return NewValue;

}
function addCommas(sValue) {
    var sRegExp = new RegExp('(-?[0-9]+)([0-9]{3})');

    while (sRegExp.test(sValue)) {
        sValue = sValue.replace(sRegExp, '$1,$2');
    }
    return sValue;
}



