// JScript File
var formObject = "0";
var obj;
function EmpName(isFrom) {
    debugger;
    if (isFrom == "Onduty") {
        formObject = "1";
    }
    if (window.ActiveXObject) {
        try {
            obj = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            try {
                obj = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e1) {
                obj = null;
            }
        }
    }
    else if (window.XMLHttpRequest) {
        try {
            obj = new XMLHttpRequest("Msxml2.XMLHTTP");
        }
        catch (e) {
            try {
                obj = new XMLHttpRequest("Microsoft.XMLHTTP");
            }
            catch (e1) {
                obj = null;
            }
        }
    }
    //	try
    //	{
    //		obj = new XmlHttpRequest();
    //	}
    //	catch(e)
    //	{
    //		try
    //		{
    //			obj = new ActiveXObject("Microsoft.XMLHTTP");
    //		}
    //		catch(e1)
    //		{
    //			obj = new ActiveXObject("Msxml2.XMLHTTP");
    //		}
    //	}
    if (document.getElementById('ctl00_BodyContentPH_hdnEmployeeId') != null & formObject!="1") {
        document.getElementById('ctl00_BodyContentPH_hdnEmployeeId').value = "";
    }
    if (obj != null) {
        var EmpId;
        var txtEmployee = document.getElementById('ctl00_BodyContentPH_txt_EmployeeId');
        var EmployeeCode = document.getElementById('ctl00_BodyContentPH_hdnEmployeeCodeId').value;
        if (txtEmployee == null & EmployeeCode==null) {
            if (document.getElementById('ctl00_BodyContentPH_hfEmployeeCode') == null) {
                EmpId = document.getElementById('ctl00_BodyContentPH_lblEmployeeIdData').innerHTML;
            }
            else {
                EmpId = document.getElementById('ctl00_BodyContentPH_hfEmployeeCode').value;
            }
        }
        else {
            if (formObject == "1" & EmployeeCode!="")
            {
                EmpId = EmployeeCode;
            }
            else {
                EmpId = document.getElementById('ctl00_BodyContentPH_txt_EmployeeId').value;
            }
            
        }

        if (EmpId == "") {
            var empty = "";
            document.getElementById('ctl00_BodyContentPH_txt_Name').value = empty;
            //document.getElementById('ctl00_BodyContentPH_txt_Name').focus();
        }
        else {
            var k = Math.floor(Math.random() * 111);
            if (window.ActiveXObject) {
                obj.onreadystatechange = ProcessTheResponseManualEntry;
                obj.open("GET", "EmployeeName.aspx?EmpId=" + EmpId + "&k" + k + '&isFrom=' + isFrom, true)
                obj.send(null);
            }
            else if (window.XMLHttpRequest) {
                obj.open("GET", "EmployeeName.aspx?EmpId=" + EmpId + "&k" + k + '&isFrom=' + isFrom, false)
                obj.send(null);
                obj.onreadystatechange = ProcessTheResponseManualEntry();
            }
        }
    }
    return false;
}
function ProcessTheResponseManualEntry() {
    if (obj.readyState == 4) {
        if (obj.status == 200) {
            var response = obj.responseText;
            if (response == "Invalid EmployeeCode") {
                var emp = "";
                document.getElementById('ctl00_BodyContentPH_txt_Name').value = response;
                document.getElementById('ctl00_BodyContentPH_txt_EmployeeId').value = emp;
                document.getElementById('ctl00_BodyContentPH_txt_EmployeeId').focus();
                //Added by Manjula.P on 19-Nov-2013 for getting employeeid in that hiddenfield
                if (document.getElementById('ctl00_BodyContentPH_hdnEmployeeId') != null) {
                    document.getElementById('ctl00_BodyContentPH_hdnEmployeeId').value = emp;
                }
                //************************************************************
            }
            else {
                //Added below one line by MAnjula.P for gettign response array
                debugger;
                var empDetails = response.split(',');
                if (document.getElementById('ctl00_BodyContentPH_txt_Name') != null) {
                    document.getElementById('ctl00_BodyContentPH_txt_Name').value = empDetails[0];
                }
                //document.getElementById('ctl00_BodyContentPH_TextBox2').value = empDetails[2];
                //document.getElementById('ctl00_BodyContentPH_TextBox3').value = empDetails[3];
                //document.getElementById('ctl00_BodyContentPH_TextBox4').value = empDetails[4];
                //document.getElementById('ctl00_BodyContentPH_TextBox1').value = empDetails[5];
                //Added below if condition by Manjula.P on 19-Nov-2013 to assigning employeeid
                if (document.getElementById('ctl00_BodyContentPH_hdnEmployeeId') != null) {
                    document.getElementById('ctl00_BodyContentPH_hdnEmployeeId').value = empDetails[1];
                }
                debugger;
                if (formObject == "1") {
                    if (empDetails[6] == "Female") {
                        if (empDetails[10] == "Y") {
                            document.getElementById('ctl00_BodyContentPH_WFHType').style.display = 'block';
                            document.getElementById('ctl00_BodyContentPH_PMWFH').style.display = 'block';
                            document.getElementById('ctl00_BodyContentPH_PPWFH').style.display = 'none';
                        }
                        else {
                            document.getElementById('ctl00_BodyContentPH_WFHType').style.display = 'none';
                        }
                        
                    }
                    else {
                        if (empDetails[10] == "Y" & empDetails[12]==0) {
                            document.getElementById('ctl00_BodyContentPH_WFHType').style.display = 'block';
                            document.getElementById('ctl00_BodyContentPH_PMWFH').style.display = 'none';
                            document.getElementById('ctl00_BodyContentPH_PPWFH').style.display = 'block';
                            document.getElementById('ctl00_BodyContentPH_hdnPPValidateDate').value = empDetails[11];
                        }
                        else {
                            document.getElementById('ctl00_BodyContentPH_WFHType').style.display = 'none';
                        }
                    }
                    document.getElementById('ctl00_BodyContentPH_hdnYearStartDate').value = empDetails[7];
                    document.getElementById('ctl00_BodyContentPH_hdnYearToDate').value = empDetails[8];
                    document.getElementById('ctl00_BodyContentPH_hdnNumofWFHDays').value = empDetails[9];
                    
                }
            }
        }
    }
}
function EmpNameForCompensationEntry() {
    if (window.ActiveXObject) {
        try {
            obj = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            try {
                obj = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e1) {
                obj = null;
            }
        }
    }
    else if (window.XMLHttpRequest) {
        try {
            obj = new XMLHttpRequest("Msxml2.XMLHTTP");
        }
        catch (e) {
            try {
                obj = new XMLHttpRequest("Microsoft.XMLHTTP");
            }
            catch (e1) {
                obj = null;
            }
        }
    }
    if (obj != null) {
        var EmpId = document.getElementById('ctl00_BodyContentPH_txt_EmployeeId').value
        if (EmpId == "") {
            var empty = "";
            document.getElementById('ctl00_BodyContentPH_txt_Name').value = empty;
            //document.getElementById('ctl00_BodyContentPH_txt_Name').focus();
            if (document.getElementById('ctl00_BodyContentPH_txtCurrDepartment') != null) {
                document.getElementById('ctl00_BodyContentPH_txtCurrDepartment').value = "";
            }
        }
        else {
            var k = Math.floor(Math.random() * 111);
            if (window.ActiveXObject) {
                obj.onreadystatechange = ProcessTheResponseCompensationEntry;
                obj.open("GET", "EmployeeNameForCompensationEntry.aspx?EmpId=" + EmpId + "&k" + k, true)
                obj.send(null);
            }
            else if (window.XMLHttpRequest) {
                obj.open("GET", "EmployeeNameForCompensationEntry.aspx?EmpId=" + EmpId + "&k" + k, false)
                obj.send(null);
                obj.onreadystatechange = ProcessTheResponseCompensationEntry();
            }
        }
    }
    return false;
}
function ProcessTheResponseCompensationEntry() {
    if (obj.readyState == 4) {
        if (obj.status == 200) {
            var response = obj.responseText;
            if (response == "Invalid EmployeeCode") {
                var emp = "";
                document.getElementById('ctl00_BodyContentPH_txt_Name').value = response;
                document.getElementById('ctl00_BodyContentPH_txt_EmployeeId').value = emp;
                document.getElementById('ctl00_BodyContentPH_txt_EmployeeId').focus();
                if (document.getElementById('ctl00_BodyContentPH_txtCurrDepartment') != null) {
                    document.getElementById('ctl00_BodyContentPH_txtCurrDepartment').value = "";
                }
            }
            else {
                //alert(document.getElementById('ctl00_BodyContentPH_txt_Name'));
                var str = response.split(",");
                if (str.length > 1) {
                    document.getElementById('ctl00_BodyContentPH_txt_Name').value = str[0];
                    if (document.getElementById('ctl00_BodyContentPH_hdnEmployeeName') != null) {
                        document.getElementById('ctl00_BodyContentPH_hdnEmployeeName').value = str[0];
                    }
                    if (document.getElementById('ctl00_BodyContentPH_txtCurrDepartment') != null) {
                        document.getElementById('ctl00_BodyContentPH_txtCurrDepartment').value = str[1];
                    }
                    if (document.getElementById('ctl00_BodyContentPH_hidLvl') != null) {
                        document.getElementById('ctl00_BodyContentPH_hidLvl').value = str[2];
                    }
                    if (document.getElementById('ctl00_BodyContentPH_hdnEmployeeId') != null) {
                        document.getElementById('ctl00_BodyContentPH_hdnEmployeeId').value = str[3];
                    }

                }
                else {
                }
            }
        }
    }
}


function EmpNameForCompensationEntry(type, format) {
    if (window.ActiveXObject) {
        try {
            obj = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            try {
                obj = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e1) {
                obj = null;
            }
        }
    }
    else if (window.XMLHttpRequest) {
        try {
            obj = new XMLHttpRequest("Msxml2.XMLHTTP");
        }
        catch (e) {
            try {
                obj = new XMLHttpRequest("Microsoft.XMLHTTP");
            }
            catch (e1) {
                obj = null;
            }
        }
    }
    if (obj != null) {

        var EmpId = "";
        if (document.getElementById('ctl00_BodyContentPH_txt_EmployeeId') == null) {
            EmpId = document.getElementById('ctl00_BodyContentPH_lblEmployeeIdData').innerHTML;
        }
        else {
            EmpId = document.getElementById('ctl00_BodyContentPH_txt_EmployeeId').value;
        }
        if (EmpId == "") {
            document.getElementById('ctl00_BodyContentPH_txt_Name').value = empty;
            if (document.getElementById('ctl00_BodyContentPH_txtCurrDepartment') != null) {
                document.getElementById('ctl00_BodyContentPH_txtCurrDepartment').value = "";
            }
        }
        else {
            if (type == "empid") {
                document.getElementById('ctl00_BodyContentPH_hdfInPunchTime').value = "";
                document.getElementById('ctl00_BodyContentPH_hdfoutPunchTime').value = "";
                document.getElementById('ctl00_BodyContentPH_hdfTotalWorkedHrs').value = "";
                document.getElementById('ctl00_BodyContentPH_hdfDayWorked').value = "";
                document.getElementById('ctl00_BodyContentPH_hdnLeavePolicyStatus').value = "";
                document.getElementById('ctl00_BodyContentPH_txtFromDate').value = "";
                document.getElementById('ctl00_BodyContentPH_lbl_InPunchTime').value = "";
                document.getElementById('ctl00_BodyContentPH_lbl_outPunchTime').value = "";
                document.getElementById('ctl00_BodyContentPH_lbl_TotalWorkedHrs').value = "";
                document.getElementById('ctl00_BodyContentPH_Txt_OTType').value = "";

            }
            else {
                if (document.getElementById("ctl00_BodyContentPH_txtFromDate").value != '') {
                    if (checkDate(document.getElementById("ctl00_BodyContentPH_txtFromDate"), format, "Please enter valid date with correct format MM/dd/yyyy", "Please enter valid date with correct format dd/MM/yyyy", "Invalid year entry", "Invalid month entry", "Invalid date entry", "Please enter valid date with correct format dd-MMM-yyyy", "Enter time", "Invalid value for hours:", "Invalid value for minutes:", "Invalid time format:", "Please enter valid Date and Time", "Please enter valid Date and Time MM/dd/yyyy HH:mm", "Please enter valid Date and Time MM/dd/yyyy hh:mm tt", "Please enter valid Date and Time ", "Invalid value for hours:", "Invalid value for minutes:")) {
                    }
                    else {
                        document.getElementById('ctl00_BodyContentPH_hdfInPunchTime').value = "";
                        document.getElementById('ctl00_BodyContentPH_hdfoutPunchTime').value = "";
                        document.getElementById('ctl00_BodyContentPH_hdfTotalWorkedHrs').value = "";
                        document.getElementById('ctl00_BodyContentPH_hdfDayWorked').value = "";
                        document.getElementById('ctl00_BodyContentPH_hdnLeavePolicyStatus').value = "";
                        document.getElementById('ctl00_BodyContentPH_txtFromDate').value = "";
                        document.getElementById('ctl00_BodyContentPH_lbl_InPunchTime').value = "";
                        document.getElementById('ctl00_BodyContentPH_lbl_outPunchTime').value = "";
                        document.getElementById('ctl00_BodyContentPH_lbl_TotalWorkedHrs').value = "";
                        document.getElementById('ctl00_BodyContentPH_Txt_OTType').value = "";
                        return false;
                    }
                }
            }
            var k = Math.floor(Math.random() * 111);
            var EmpDate = document.getElementById('ctl00_BodyContentPH_txtFromDate').value
            if (window.ActiveXObject) {

                obj.onreadystatechange = ProcessTheResponseCompensationEntry;
                obj.open("GET", "EmployeeNameForCompensationEntry.aspx?EmpId=" + EmpId + "&EmpDate=" + EmpDate + "&k" + k, true)
                obj.send(null);
            }
            else if (window.XMLHttpRequest) {
                if (EmpId == "") {
                    EmpId = document.getElementById('ctl00_BodyContentPH_lblEmployeeIdData').value
                }
                obj.open("GET", "EmployeeNameForCompensationEntry.aspx?EmpId=" + EmpId + "&Type=" + type + "&EmpDate=" + EmpDate + "&k" + k, false)
                obj.send(null);
                if (type == "date") {
                    obj.onreadystatechange = ProcessTheResponseCompensationEntryShiftDate();
                }
                else {
                    obj.onreadystatechange = ProcessTheResponseCompensationEntry();
                }
            }
        }
    }
    return false;
}
function ProcessTheResponseCompensationEntryShiftDate() {
    if (obj.readyState == 4) {
        if (obj.status == 200) {
            var response = obj.responseText;
            var strName = response.split(",");
            if (strName[0] == "Invalid Date") {
                var emptyvalue = "";
                document.getElementById('ctl00_BodyContentPH_lbl_InPunchTime').value = emptyvalue;
                document.getElementById('ctl00_BodyContentPH_lbl_outPunchTime').value = emptyvalue;
                document.getElementById('ctl00_BodyContentPH_lbl_TotalWorkedHrs').value = emptyvalue;
                document.getElementById('ctl00_BodyContentPH_hdfInPunchTime').value = emptyvalue;
                document.getElementById('ctl00_BodyContentPH_hdfoutPunchTime').value = emptyvalue;
                document.getElementById('ctl00_BodyContentPH_hdfTotalWorkedHrs').value = emptyvalue;
                document.getElementById('ctl00_BodyContentPH_hdnLeavePolicyStatus').value = emptyvalue;
                document.getElementById('ctl00_BodyContentPH_hdfDayWorked').value = emptyvalue;
                document.getElementById('ctl00_BodyContentPH_Txt_OTType').value = emptyvalue;
                document.getElementById('ctl00_BodyContentPH_lblEmployeeNameData').value = strName[1];
                document.getElementById('ctl00_BodyContentPH_hdfProcess_Rec_ID').value = emptyvalue;
                document.getElementById('ctl00_BodyContentPH_hdfEmployee_Id').value = emptyvalue;
                document.getElementById('ctl00_BodyContentPH_hdfLevelName').value = emptyvalue;
                document.getElementById('ctl00_BodyContentPH_hdfOverTimeStatus').value = emptyvalue;
                document.getElementById('ctl00_BodyContentPH_hdfTopLevelID').value = emptyvalue;
                if (document.getElementById('ctl00_BodyContentPH_hdnDayCompStatus') != null) {
                    document.getElementById('ctl00_BodyContentPH_hdnDayCompStatus').value = emptyvalue;
                }
            }
            else {
                var str = response.split(",");
                if (str.length > 1) {

                    document.getElementById('ctl00_BodyContentPH_lbl_InPunchTime').value = str[1];
                    document.getElementById('ctl00_BodyContentPH_hdfInPunchTime').value = str[1];
                    document.getElementById('ctl00_BodyContentPH_lbl_outPunchTime').value = str[2];
                    document.getElementById('ctl00_BodyContentPH_hdfoutPunchTime').value = str[2];
                    document.getElementById('ctl00_BodyContentPH_lbl_TotalWorkedHrs').value = str[3];
                    document.getElementById('ctl00_BodyContentPH_hdfTotalWorkedHrs').value = str[3];
                    document.getElementById('ctl00_BodyContentPH_Txt_OTType').value = str[0];
                    document.getElementById('ctl00_BodyContentPH_hdfDayWorked').value = str[0];
                    //document.getElementById('ctl00_BodyContentPH_lblEmployeeNameData').value = str[4];
                    document.getElementById('ctl00_BodyContentPH_hdnEmployeeName').value = str[4];
                    document.getElementById('ctl00_BodyContentPH_hdfProcess_Rec_ID').value = str[5];
                    document.getElementById('ctl00_BodyContentPH_hdfEmployee_Id').value = str[6];
                    document.getElementById('ctl00_BodyContentPH_hdfLevelName').value = str[7];
                    document.getElementById('ctl00_BodyContentPH_hdfOverTimeStatus').value = str[8];
                    document.getElementById('ctl00_BodyContentPH_hdfTopLevelID').value = str[9];
                    document.getElementById('ctl00_BodyContentPH_hdfExtraMins').value = str[10];
                    if (document.getElementById('ctl00_BodyContentPH_hdnDayCompStatus') != null) {
                        document.getElementById('ctl00_BodyContentPH_hdnDayCompStatus').value = str[11];
                    }
                    document.getElementById('ctl00_BodyContentPH_hdnLeavePolicyStatus').value = str[13];
                    //if (str[11] == "Not Reached" && str[3] != '00:00') {
                    //    alert(str[12])
                    //}
                    return false;
                }
            }
        }
    }
}
function ProcessTheResponseCompensationEntry() {
    if (obj.readyState == 4) {
        if (obj.status == 200) {
            var response = obj.responseText;
            if (response == "Invalid EmployeeCode") {
                var emp = "";
                document.getElementById('ctl00_BodyContentPH_txt_Name').value = response;
                document.getElementById('ctl00_BodyContentPH_txt_EmployeeId').value = emp;
                document.getElementById('ctl00_BodyContentPH_txt_EmployeeId').focus();
                if (document.getElementById('ctl00_BodyContentPH_txtCurrDepartment') != null) {
                    document.getElementById('ctl00_BodyContentPH_txtCurrDepartment').value = "";
                }
            }
            else {
                var str = response.split(",");
                if (str.length > 1) {
                    document.getElementById('ctl00_BodyContentPH_txt_Name').value = str[0];
                    document.getElementById('ctl00_BodyContentPH_hdnEmployeeName').value = str[0];
                    if (document.getElementById('ctl00_BodyContentPH_hdnEmployeeName') != null) {
                        document.getElementById('ctl00_BodyContentPH_hdnEmployeeName').value = str[0];
                    }
                    if (document.getElementById('ctl00_BodyContentPH_txtCurrDepartment') != null) {
                        document.getElementById('ctl00_BodyContentPH_txtCurrDepartment').value = str[1];
                    }
                    if (document.getElementById('ctl00_BodyContentPH_hidLvl') != null) {
                        document.getElementById('ctl00_BodyContentPH_hidLvl').value = str[2];
                    }
                    if (document.getElementById('ctl00_BodyContentPH_hdnEmployeeId') != null) {
                        document.getElementById('ctl00_BodyContentPH_hdnEmployeeId').value = str[3];
                    }
                }
            }
        }
    }
}
