// JScript File
var obj;
function ShiftTime()
{

            var Shiftin,Shiftout,BStartTime1,BStartTime2,BStartTime3,BEndTime1,BEndTime2,BEndTime3;
		    
		    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;


         //Time validation
//            var CheckVal=new Boolean(); 
//            CheckVal=validateShiftTimes(Shiftin,Shiftout,BStartTime1,BStartTime2,  BStartTime3, BEndTime1, BEndTime2, BEndTime3);
//            if(CheckVal==false)
//            {
//            document.getElementById('ctl00_BodyContentPH_txt_TotalWorkingHourrs').value="0.0";
//            return false;
//            }
            
                      
	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;
		   
		    obj.onreadystatechange = ProcessTheResponse;		
		    obj.open("POST", link, true);
		    obj.send(null);
		
	}
	return false;
}
function ProcessTheResponse()
{
	if (obj.readyState == 4)
	{
		if(obj.status == 200)
		{
		  
          var response=obj.responseText;
          
          document.getElementById('ctl00_BodyContentPH_txt_TotalWorkingHourrs').value=response;
         
		}
	}
}


//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;
   }
