﻿function EncryptPassword(txtBox) {
    var pwd = document.getElementById(txtBox);
    if (pwd != null && pwd.value != '') {
        var enc = hex_md5(pwd.value);
        pwd.value = enc;
    }
}

function makecenter(id) {

    var brSize = getBRSize();

    var WWidth = '';
    WWidth = id.style.width;
    WWidth = parseInt(WWidth.substring(0, WWidth.length - 2));

    var Wheight = '';
    Wheight = id.style.height;
    Wheight = parseInt(Wheight.substring(0, Wheight.length - 2));
}
function getBRSize() {
    var bodyWidth = document.documentElement.clientWidth;
    var bodyHeight = document.documentElement.clientHeight;

    var bodyWidth, bodyHeight;
    if (self.innerHeight) { // all except Explorer 
        bodyWidth = self.innerWidth;
        bodyHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) {
        // Explorer 6 Strict Mode 		 
        bodyWidth = document.documentElement.clientWidth;
        bodyHeight = document.documentElement.clientHeight;
    } else if (document.body) {// other Explorers 		 
        bodyWidth = document.body.clientWidth;
        bodyHeight = document.body.clientHeight;
    }
    var nav4 = window.event ? true : false;
    if (nav4) {
        x = document.documentElement.scrollLeft + document.body.scrollLeft;
        y = document.documentElement.scrollTop + document.body.scrollTop;
    }
    else {
        x = window.scrollX;
        y = window.scrollY;
    }
    if (x == 'undefined' || x == null) x = 0;
    if (y == 'undefined' || y == null) y = 0;

    bodyWidth = bodyWidth + x;
    bodyHeight = bodyHeight + y

    return [bodyWidth, bodyHeight];

}


/* Registration Page Scripts  - Start */
function RegPageShowActiveUserPanel(ddlUserStatusEdit, trActiveStatus, ddlUserType, ddlRole, lblRegistrationId, GetApproveStatusId) {
    if (document.getElementById(ddlUserStatusEdit).value == GetApproveStatusId)
        document.getElementById(trActiveStatus).style.display = '';
    else {
        document.getElementById(trActiveStatus).style.display = 'none';
        //document.getElementById(ddlUserType).selectedIndex = 0;
        //document.getElementById(ddlRole).selectedIndex = 0;
        document.getElementById(lblRegistrationId).innerHTML = "";
    }
}

function RegPageIsValidRegPage(ddlUserStatusEdit, GetApproveStatusId, ddlUserType, ddlRole, lblRegistrationId) {
    if (document.getElementById(ddlUserStatusEdit).value == GetApproveStatusId) {
        if (document.getElementById(ddlUserType).value == "-1") {
            alert("Please select User Type");
            document.getElementById(ddlUserType).focus();
            return false;
        }
        else if (document.getElementById(ddlRole).value == "-1") {
            alert("Please select Role");
            document.getElementById(ddlRole).focus();
            return false;
        }
        else if (document.getElementById(lblRegistrationId).innerHTML == "") {
            alert("Please generate registrationId for this user.");
            document.getElementById(lblRegistrationId).focus();
            return false;
        }
    }
    return true;
}

/* Registration Page Scripts  - End */

/* Print Functiona  - Start */
function getPrint(print_area, applicationpath) {

    if (print_area == null) return;
    if (document.getElementById('PrintHeader') != null)
        document.getElementById('PrintHeader').style["display"] = '';

    if (document.getElementById('PrintLogo') != null)
        document.getElementById('PrintLogo').style["display"] = '';

    if (document.getElementById('PrintFooter') != null)
        document.getElementById('PrintFooter').style["display"] = '';

    if (document.getElementById('tblPrint') != null)
        document.getElementById('tblPrint').style["width"] = '95%';
    

    //Creating new page
    var pp = window.open();

    var strHtml = '<html><head><title></title>'
                  + '<link href="' + applicationpath + '/Portal/Design_CSS/1.css"  type="text/css" rel="stylesheet">'
                  + '<link href="' + applicationpath + '/Portal/Design_CSS/2.css"  type="text/css" rel="stylesheet">'
                  + '<link href="' + applicationpath + '/App_Themes/Admin/Print.css"  type="text/css" rel="stylesheet">'
    //+ '<LINK href="App_Themes/User/User.css"  type="text/css" rel="stylesheet">'
    //+ '<LINK href="App_Themes/User/thickbox.css"  type="text/css" rel="stylesheet">'
                  + '<base target="_self"></head>'
                  + '<body onload="window.print(); window.close();" ms_positioning="gridlayout" bottommargin="0" leftmargin="0" topmargin="0" rightmargin="0">'
                //+ '<body onload="window.print();" ms_positioning="gridlayout" bottommargin="0" leftmargin="0" topmargin="0" rightmargin="0">'
                  + '<form method="post" id="form1">'
                  + '<table width=100%><tr><td></td></tr><tr><td align=right>'
                  + '<input id="print" type="button" value="print" style="display:none" '
                  + 'onclick="javascript:location.reload(true);window.print();">'
                  + '<input id="close" type="button" style="display:none" value="close" onclick="window.close();">'
                  + '</td></tr><tr><td></td></tr></table>'
    
    pp.document.clear();
    pp.document.writeln(strHtml);

   

    // Replace Print word to Blank in Print Window
    var content = document.getElementById(print_area).innerHTML;

    content = content.toString().replace("Print</A>", "</A>");  //For IE
    content = content.toString().replace("Print</a>", "</a>");  //For Mozilla
    content = content.toString().replace("Imprimer</A>", "</A>");  //For IE
    content = content.toString().replace("Imprimer</a>", "</a>");  //For Mozilla
    content = content.toString().replace("طباعة</A>", "</A>");  //For IE
    content = content.toString().replace("طباعة</a>", "</a>");  //For Mozilla

    //Writing print area of the calling page    
    pp.document.writeln(content);
    //Ending Tag of </form>, </body> and </HTML>
    pp.document.writeln('</form></body>');

    var strDisableScript = '<script type="text/javascript">'
                + 'window.unload = disableForm(document.forms[0]);'
                + 'function disableForm(theform) {'
                + 'for (i = 0; i < theform.length; i++) {'
                + 'var tempobj = theform.elements[i];'
                + 'if(tempobj.id == "PRINT" || tempobj.id == "CLOSE") continue;'
                + 'tempobj.disabled = "disabled";'
                + '}return false;}'
                + '</script>'

    pp.document.writeln(strDisableScript);

    pp.document.writeln('</html>');
    pp.document.close();

    if (document.getElementById('PrintHeader') != null)
        document.getElementById('PrintHeader').style["display"] = 'none';
    if (document.getElementById('PrintLogo') != null)
        document.getElementById('PrintLogo').style["display"] = 'none';
    if (document.getElementById('PrintFooter') != null)
        document.getElementById('PrintFooter').style["display"] = 'none';
    if (document.getElementById('tblPrint') != null)
        document.getElementById('tblPrint').style["width"] = '100%';
}
/* Print Functiona  - End */

/* Start - Added By Anish Patel on 07/17/2010 - For Job Application Page */

function RequiredLangugaeSelection(Speaking1, Reading1, Writing1, Speaking2, Reading2, Writing2, Speaking3, Reading3, Writing3, Otherlanguage, Speaking4, Reading4, Writing4, source, arguments) {
    if ((Speaking1.options[Speaking1.selectedIndex].value != "0" &&
            Reading1.options[Reading1.selectedIndex].value != "0" &&
            Writing1.options[Writing1.selectedIndex].value != "0") ||
             (Speaking2.options[Speaking2.selectedIndex].value != "0" &&
            Reading2.options[Reading2.selectedIndex].value != "0" &&
            Writing2.options[Writing2.selectedIndex].value != "0") ||
            (Speaking3.options[Speaking3.selectedIndex].value != "0" &&
            Reading3.options[Reading3.selectedIndex].value != "0" &&
            Writing3.options[Writing3.selectedIndex].value != "0") ||
            (Speaking4.options[Speaking4.selectedIndex].value != "0" &&
            Reading4.options[Reading4.selectedIndex].value != "0" &&
            Writing4.options[Writing4.selectedIndex].value != "0" &&
            Otherlanguage.value != "")) {
        arguments.IsValid = true;
    }
    else
        arguments.IsValid = false;
}

function CheckisNumberKey(evt) {
    var charCode = (evt.which) ? evt.which : evt.keyCode
    if ((charCode > 47 && charCode < 58) || charCode == 44 || charCode == 46 || charCode == 8)
        return true;

    return false;
}


/* Used in HR Form added by Anish Patel on 08/18/2010*/
function CheckInputdate(DD, MM, YYYY, source, arguments, CheckBlank) {
    FieldAttrib = "Yes";
    Format = "dd/mm/yyyy";
    strValue = DD + "/" + MM + "/" + YYYY;
    if (strValue == "DD/MM/YYYY") {
        if (CheckBlank)
            arguments.IsValid = false;
        else arguments.IsValid = true;
    }
    else {
        if (FieldAttrib) {
            if (FieldAttrib == "Yes") {
                var objRegExp = /^\d{1,2}(\/)\d{1,2}(\/)\d{1,4}$/;
            } else {
                var objRegExp = /^\d{1,2}(\/)\d{1,2}(\/)\d{1,2}$/;
            }
        }
        else {

            var objRegExp = /^\d{1,2}(\/)\d{1,2}(\/)\d{1,2}$/;
        }
        if (!objRegExp.test(strValue)) {
            ErrMsg += "- Please enter a valid date for " + FieldAttrib["Alias"] + "\n";
            ok = false;
            arguments.IsValid = false;
        }
        else {
            var arrayDate = strValue.split("\/"); //split date into month, day, year
            if (Format == "mm/dd/yy" || Format == "mm/dd/yyyy") {
                var intDay = parseInt(arrayDate[1], 10);
                var intYear = parseInt(arrayDate[2], 10);
                var intMonth = parseInt(arrayDate[0], 10);
            }
            else if (Format == "dd/mm/yy" || Format == "dd/mm/yyyy") {
                var intDay = parseInt(arrayDate[0], 10);
                var intYear = parseInt(arrayDate[2], 10);
                var intMonth = parseInt(arrayDate[1], 10);
            }
            if ((intMonth > 12 || intMonth < 1) || (intYear >= 9999 || intYear <= 1753)) {
                ErrMsg += "- Please enter a valid date for " + FieldAttrib["Alias"] + "\n";
                ok = false;
                arguments.IsValid = false;
            }
            else {
                var arrayLookup = { '1': 31, '3': 31, '4': 30, '5': 31, '6': 30, '7': 31,
                    '8': 31, '9': 30, '10': 31, '11': 30, '12': 31
                }
                if (intMonth != 2) {
                    if (intDay <= arrayLookup[intMonth] && intDay != 0) {
                        arguments.IsValid = true;
                    }

                }
                else {
                    if (FieldAttrib == "Yes") {
                        var booLeapYear = (intYear % 4 == 0 && (intYear % 100 != 0 || intYear % 400 == 0));
                        if ((booLeapYear && intDay <= 29) && intDay != 0) {
                            arguments.IsValid = true;
                        }
                        else if ((!booLeapYear && intDay <= 28) && intDay != 0) {
                            arguments.IsValid = true;
                        }
                        else
                        { arguments.IsValid = false; }
                    }
                    else {
                        arguments.IsValid = true;
                    }
                }
            }
        }
    }
}

function ClearTextBox(obj, Value) {
    if (obj.value == Value)
        obj.value = '';
}
function FillTextBox(obj, Value) {
    if (obj.value == '')
        obj.value = Value;
}

/* End */


function ConfirmMessage() {
    if (Page_ClientValidate("Submit")) {
        var check = confirm("Before save information have you seen the print preview?");
        if (check == true) {
            var res = confirm("Are you sure, you want to save information?");
            if (res == true) {
                return true;
            }
            else {
                return false;
            }
        }
    }
    else {
        return false;
    }
}
