// JScript File
var obj;
function ShiftTime(InvalidBreakTime) {
    var Shiftin, Shiftout, BStartTime1, BStartTime2, BStartTime3, BEndTime1, BEndTime2, BEndTime3, ckbStaightShift, Breakhrs;
    var FHStart, SHStart, FHEnd, SHEnd;
    Shiftin = document.getElementById('ctl00_BodyContentPH_txt_ShiftInTime').value;
    Shiftout = document.getElementById('ctl00_BodyContentPH_txt_ShiftOuttime').value;
    BStartTime1 = document.getElementById('ctl00_BodyContentPH_txt_BreakStratTime1').value;
    BEndTime1 = document.getElementById('ctl00_BodyContentPH_txt_BreakEndTime1').value;
    BStartTime2 = document.getElementById('ctl00_BodyContentPH_txt_BreakStartTime2').value;
    BEndTime2 = document.getElementById('ctl00_BodyContentPH_txt_BreakEndTime2').value;
    BStartTime3 = document.getElementById('ctl00_BodyContentPH_txt_BreakStartTime3').value;
    BEndTime3 = document.getElementById('ctl00_BodyContentPH_txt_BreakEndTime3').value;
    FHStart = document.getElementById('ctl00_BodyContentPH_txt_FirstHalfStartTime').value;
    FHEnd = document.getElementById('ctl00_BodyContentPH_txt_FirstHalfEndTime').value;
    SHStart = document.getElementById('ctl00_BodyContentPH_txt_SecondHalfStartTime').value;
    SHEnd = document.getElementById('ctl00_BodyContentPH_txt_SecondHalfEndTime').value;
    ckbStaightShift = document.getElementById('ctl00_BodyContentPH_ckbStaightShift').checked;
    Breakhrs = document.getElementById('ctl00_BodyContentPH_txtboxBreak').value;
    //alert(ckbStaightShift);
    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 (obj != null) {
        var link = "ShiftRemote.aspx?";
        link = link + "Shiftin=" + Shiftin + "&";
        link = link + "Shiftout=" + Shiftout + "&";
        link = link + "BStartTime1=" + BStartTime1 + "&";
        link = link + "BEndTime1=" + BEndTime1 + "&";
        link = link + "BStartTime2=" + BStartTime2 + "&";
        link = link + "BEndTime2=" + BEndTime2 + "&";
        link = link + "BStartTime3=" + BStartTime3 + "&";
        link = link + "BEndTime3=" + BEndTime3 + "&";
        link = link + "FHStart=" + FHStart + "&";
        link = link + "FHEnd=" + FHEnd + "&";
        link = link + "SHStart=" + SHStart + "&";
        link = link + "SHEnd=" + SHEnd + "&";
        link = link + "BreakHrs=" + Breakhrs + "&";
        link = link + "ckbStaightShift=" + ckbStaightShift;
        if (window.ActiveXObject) {
            obj.onreadystatechange = ProcessTheResponse;
            obj.open("POST", link, true);
            obj.send(null);
        }
        else if (window.XMLHttpRequest) {
            obj.open("POST", link, false);
            obj.send(null);
            obj.onreadystatechange = ProcessTheResponse();
        }
    }
    return false;
}
function ProcessTheResponse() {
    if (obj.readyState == 4) {
        if (obj.status == 200) {
            var response = obj.responseText;
            if (response != '' && response != 'InvalidBreakTime' && response != 'InvalidShiftTime') {
                var arr_List = new Array();
                arr_List = response.split("*");
                if (arr_List[0] != '') {
                    document.getElementById('ctl00_BodyContentPH_txtFirstHalfWorkHrs').value = '';
                    document.getElementById('ctl00_BodyContentPH_txtFirstHalfWorkHrs').value = arr_List[0];
                }
                if (arr_List[1] != '') {
                    document.getElementById('ctl00_BodyContentPH_txtSecondHalfWorkHrs').value = '';
                    document.getElementById('ctl00_BodyContentPH_txtSecondHalfWorkHrs').value = arr_List[1];
                }
                if (arr_List[2] != '') {
                    document.getElementById('ctl00_BodyContentPH_txt_TotalWorkingHourrs').value = '';
                    document.getElementById('ctl00_BodyContentPH_txt_TotalWorkingHourrs').value = arr_List[2];
                }
            }
            else if (response == 'InvalidShiftTime') {
                alert("Total work hours should less than 23:59 hrs");
            }
            else {
                alert(InvalidBreakTime);
            }
        }
    }
}
//Function to validate shift time
function validateShiftTimes(Shiftin, Shiftout, BStartTime1, BStartTime2, BStartTime3, BEndTime1, BEndTime2, BEndTime3) {
    var reExHoursMinitues = /^([0-1][0-9]|[2][0-3]):([0-5][0-9]) (a|p|A|P)(m|M)$/;
    var IsValid = new Boolean();
    IsValid = false;
    if (Shiftin.value != '' && Shiftin.length != 0) {
        if (Shiftin.length == 8) {
            if (Shiftin.search(reExHoursMinitues) == -1) {
                alert("Enter valid Shift In Time");
                return false;
            }
            else {
                IsValid = true;
            }
        }
        else {
            return false;
        }
    }
    if (Shiftout.value != '' && Shiftout.length != 0) {
        if (Shiftout.length == 8) {
            if (Shiftout.search(reExHoursMinitues) == -1) {
                alert("Enter valid Shift Out Time");
                return false;
            }
            else {
                IsValid = true;
            }
        }
        else {
            return false;
        }
    }
    if (BStartTime1.value != '' && BStartTime1.length != 0) {
        if (BStartTime1.length == 8) {
            if (BStartTime1.search(reExHoursMinitues) == -1) {
                alert("Enter valid Break 1 Start Time");
                return false;
            }
            else {
                IsValid = true;
            }
        }
        else {
            return false;
        }
    }
    if (BEndTime1.value != '' && BEndTime1.length != 0) {
        if (BEndTime1.length == 8) {
            if (BEndTime1.search(reExHoursMinitues) == -1) {
                alert("Enter valid Break 1 End Time");
                return false;
            }
            else {
                IsValid = true;
            }
        }
        else {
            return false;
        }
    }
    if (BStartTime2.value != '' && BStartTime2.length != 0) {
        if (BStartTime2.length == 8) {
            if (BStartTime2.search(reExHoursMinitues) == -1) {
                alert("Enter valid Break 2 Start Time");
                return false;
            }
            else {
                IsValid = true;
            }
        }
        else {
            return false;
        }
    }
    if (BEndTime2.value != '' && BEndTime2.length != 0) {
        if (BEndTime2.length == 8) {
            if (BEndTime2.search(reExHoursMinitues) == -1) {
                alert("Enter valid Break 2 End Time");
                return false;
            }
            else {
                IsValid = true;
            }
        }
        else {
            return false;
        }
    }
    if (BStartTime3.value != '' && BStartTime3.length != 0) {
        if (BStartTime3.length == 8) {
            if (BStartTime3.search(reExHoursMinitues) == -1) {
                alert("Enter valid Break 3 Start Time");
                return false;
            }
            else {
                IsValid = true;
            }
        }
        else {
            return false;
        }
    }
    if (BEndTime3.value != '' && BEndTime3.length != 0) {
        if (BEndTime3.length == 8) {
            if (BEndTime3.search(reExHoursMinitues) == -1) {
                alert("Enter valid Break 3 End Time");
                return false;
            }
            else {
                IsValid = true;
            }
        }
        else {
            return false;
        }
    }
    return IsValid;
}
