// JScript File


/// Count Number of Hours Remaining


function NumberOfHours()
{
	try
	{
		obj = new XmlHttpRequest();
	}
	catch(e)
	{
		try
		{
			obj = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e1)
		{
			obj = new ActiveXObject("Msxml2.XMLHTTP");
		}
	}
	
	if(obj != null)
	{
	  var FromTime=document.aspnetForm.ctl00_CP_Transaction_txt_StartTime.value;
	  if(FromTime=="")
	  {
	    return false;
	  }
	  
	  var EndTime=document.aspnetForm.ctl00_CP_Transaction_txt_EndTime.value;
	  if(EndTime=="")
	  {
	    return false;
	   
	  }
   
	 
		    var link = "NumberofHoursCount.aspx?";
		    link = link + "&" + "FromTime=" + FromTime;
		    link = link + "&" + "EndTime=" + EndTime;
		
		   
		    obj.onreadystatechange = ProcessResponseHours;		
		    obj.open("POST", link, true);
		    obj.send(null);
		
	}
	
}
function ProcessResponseHours()
{
	if (obj.readyState == 4)
	{
		if(obj.status == 200)
		{
	      var response=obj.responseText;
	      
	      var HoursMaxandRemain=response.split(",");
	      
	      if(response=="FillBothTime")
	      {
	      document.getElementById('ctl00_CP_Transaction_txt_NumberOfHours').value="";
	      return false;
	      }
	      else if(response=="SelectValidHours")
	      {
	        alert("Select Valid Permission Hours");
	        document.getElementById('ctl00_CP_Transaction_txt_NumberOfHours').value="";
	        return false;
	      
	      }
	       else if(response=="Fail")
	      {
	      
	      //alert(document.getElementById('ctl00_CP_Transaction_hdnNegativeValue').value)
	      if(document.getElementById('ctl00_CP_Transaction_hdnNegativeValue').value!="-1")
	      {
	        document.getElementById('ctl00_CP_Transaction_hdnNegativeValue').value="-1";
	        alert("Permission Hours Should Not In Negative Hours");
	        document.getElementById('ctl00_CP_Transaction_txt_NumberOfHours').value="";
	        return false;
	      }
	      else
	      {
	      return false;
	      }
	      }
	   
          document.getElementById('ctl00_CP_Transaction_txt_NumberOfHours').value=HoursMaxandRemain[0];
          document.getElementById('ctl00_CP_Transaction_hdnNegativeValue').value="";
    // document.getElementById('ctl00_CP_Transaction_lblRemainNoOfHours').innerText=HoursMaxandRemain[1];
    	}
	}
}

function assignEmployeeIdPermission(con)
{
  
	var EmpId=document.getElementById('ctl00_CP_Transaction_hdnEmployeeId').value;
	
	var permissionDate=document.getElementById('ctl00_CP_Transaction_TxtPermissionDate').value;
   // var permissionDate=con.value;
	
	if(EmpId=="-Select-" || EmpId=="" )
	{
	return false;
	}
	else
	{
	
	 EmpId=document.getElementById('ctl00_CP_Transaction_hdnEmployeeId').value;
	
	}
			
	try
	{
		objReMainHours = new XmlHttpRequest();
	}
	catch(e)
	{
		try
		{
			objReMainHours = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e1)
		{
			objReMainHours = new ActiveXObject("Msxml2.XMLHTTP");
		}
	}
	
	if(objReMainHours != null)
	{
	 	 
		    var link = "NumberofRemainingHoursCount.aspx?";
		     var k=Math.floor(Math.random()*111);
		    link = link + "&" + "EmpId=" + EmpId;
		    link = link + "&" + "permissionDate=" + permissionDate;
		    link = link + "&" + "k=" + k;
		    
		    objReMainHours.onreadystatechange = ProcessResponseRemainingHours;		
		    objReMainHours.open("POST", link, true);
		    objReMainHours.send(null);
		
	}
	
}
function ProcessResponseRemainingHours()
{
	if (objReMainHours.readyState == 4)
	{
		if(objReMainHours.status == 200)
		{
	     
	      var response=objReMainHours.responseText;
	      
	      if(response=="Fail")
	      {
	        alert("Permission Hours Not defined for this employee");
    	    document.getElementById('ctl00_CP_Transaction_hdnRemainNoOfHours').value="00:00";
	        document.getElementById('tdRemainNoOfHours').innerHTML="00:00";
	        return false;
	      }
	      else if(response=="MaxInstancesMonthExceed")
	      {
	        alert("Max Number of Instances per month Exceeds");
	        document.getElementById('ctl00_CP_Transaction_hdnRemainNoOfHours').value="00:00";
	        document.getElementById('tdRemainNoOfHours').innerHTML="00:00";
	        return false;
	      }
	      
	     
	      var HoursMaxandRemain=response.split(",");
	      
	     document.getElementById('ctl00_CP_Transaction_hdnRemainNoOfHours').value=HoursMaxandRemain[0];
          //document.getElementById('ctl00_CP_Transaction_txt_NumberOfHours').value=HoursMaxandRemain[0];
         
     document.getElementById('tdRemainNoOfHours').innerHTML=HoursMaxandRemain[0];
     //alert(document.getElementById('tdRemainNoOfHours').innerHTML);
    	}
	}
}