// JScript File
var flg = null;
var objLeave = null;

    function ajaxEmpLeave()
    {
        try
        {
             objLeave = new XMLHttpRequest();
        }
        catch(ex)
        {
            try
            {
                objLeave=new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch(e)
            {
                try
                {
                    objLeave=new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch(e1)
                {
                    objLeave=null;
                }
            }
        }
        
        if(objLeave!=null)
        {
         //alert(document.getElementById("ctl00_BodyContentPH_hdf_Policy").value)   
         if(document.getElementById("ctl00_BodyContentPH_hdf_Policy").value.length > 0)
         {
            //Year already closed
           if(document.getElementById("ctl00_BodyContentPH_hdf_Policy").value=="MappedPolicy@~%")
           {
           return true;
           }
           else
           {
            var rndValue=Math.floor(Math.random()*111);
            objLeave.onreadystatechange=Process_Response_EmpLeave;
            objLeave.open("GET","EmpLeave_Remote.aspx?Details=" + document.getElementById("ctl00_BodyContentPH_hdf_Policy").value+"&validationDate="+ document.getElementById("ctl00_BodyContentPH_hdf_PolVal").value+"&DOJDate="+ document.getElementById("ctl00_BodyContentPH_txt_doj").value +"&rndValue="+rndValue,true);
            objLeave.send(null);
           }
            
         }
         
         else if(document.getElementById("ctl00_BodyContentPH_hdf_Policy").value!="")
            {
                if(document.aspnetForm.ctl00_BodyContentPH_ddl_LeavePolicy.selectedIndex==0)
                {
                    alert("Fill Leave Policy");
                    document.getElementById('ctl00_BodyContentPH_div_EmpLeave').innerHTML="";
                    return false;
                }
            }
         else if(document.getElementById("ctl00_BodyContentPH_hdf_Policy").value=="")
         {
                if(document.aspnetForm.ctl00_BodyContentPH_ddl_LeavePolicy.selectedIndex!=0)
                {
                    alert("Leave policy duration should not be empty");
                    //document.getElementById('ctl00_BodyContentPH_div_EmpLeave').innerHTML="";
                    return false;
                }
         
         }
         
        }
        
        return false;
    }
    
    
    
    function Process_Response_EmpLeave()
	{
		if(objLeave.readyState == 4)
		{
		
			if(objLeave.status == 200)
			{
			   
				var retval=objLeave.responseText;
				if (retval.length > 0)
				{
				
				    if(retval=="Failure")
				        {
				            alert("Select Date");
				            return false;
				        }
				     else
				        {
				        
				        }
				           
				
				//VALIDATING FROM/TO DATE VS LEAVE POLICY DURATION
				
				
				    
				    if(retval=="Fail")
				        {
				            document.getElementById("ctl00_BodyContentPH_hidLeaveFlag").value = 'F';
				            alert("Invalid Date");				            
				            //return  false;
				        }
				     else if(retval=="DOJFail")
				        {
				            document.getElementById("ctl00_BodyContentPH_hidLeaveFlag").value = 'F';
				            alert("Policy Start Date should be greater than the Date Of Joining");
				            //return false;
				        }
				    else if(retval=="Interven")
				        {				        
				            document.getElementById("ctl00_BodyContentPH_hidLeaveFlag").value = 'F';
				            alert("Policy Date already Exists");
				            //return false;
				        }
				    else if(retval=="EmptyFail")
				        {
				            document.getElementById("ctl00_BodyContentPH_hidLeaveFlag").value = 'F';
				            alert("Fill Start Date and End Date");
				            //return false;
				        }
				    else
				        {
				        
				            document.getElementById("ctl00_BodyContentPH_hidLeaveFlag").value = 'T';
				            if(document.getElementById('tbl_LeavePolicydetails')!=null)
				                {
				                  document.getElementById('tbl_LeavePolicydetails').style.display="none";
				                }
        				
				           document.getElementById('ctl00_BodyContentPH_div_EmpLeave').innerHTML=retval;
				           return true;
				        }
				        //return chumma();
				}
				
				else
				{
				    alert("No Details found  in Emp Leave!");
				}
			}
			
			else
			{
				alert("Error in retriving details");
			}
			
		}
	}
	
	
	function ajaxEmpLeave_saveButton()
    {
        try
        {
             objLeave = new XMLHttpRequest();
        }
        catch(ex)
        {
            try
            {
                objLeave=new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch(e)
            {
                try
                {
                    objLeave=new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch(e1)
                {
                    objLeave=null;
                }
            }
        }
        
        if(objLeave!=null)
        {
         //alert(document.getElementById("ctl00_BodyContentPH_hdf_Policy").value)   
         if(document.getElementById("ctl00_BodyContentPH_hdf_Policy").value.length > 0)
         {
            var rndValue=Math.floor(Math.random()*111);
            objLeave.onreadystatechange=Process_Response_EmpLeave_saveButton;
            objLeave.open("GET","EmpLeave_Remote.aspx?Details=" + document.getElementById("ctl00_BodyContentPH_hdf_Policy").value+"&validationDate="+ document.getElementById("ctl00_BodyContentPH_hdf_PolVal").value+"&DOJDate="+ document.getElementById("ctl00_BodyContentPH_txt_doj").value+"&rndValue="+rndValue,true);
            objLeave.send(null);
            
         }
         
         else
         {
          //  alert("Fill Leave Policy");
           // document.getElementById('ctl00_BodyContentPH_div_EmpLeave').innerHTML="";
           __doPostBack(document.getElementById('ctl00_BodyContentPH_ImageButton2').name,'');
         }
         
        }
        
        return false;
    }
    function Process_Response_EmpLeave_saveButton()
	{
		if(objLeave.readyState == 4)
		{
		
			if(objLeave.status == 200)
			{
			   
				var retval=objLeave.responseText;
				if (retval.length > 0)
				{
				
				    if(retval=="Failure")
				        {
				            alert("Select Date");
				            return false;
				        }
				     else
				        {
				        
				        }
				           
				
				//VALIDATING FROM/TO DATE VS LEAVE POLICY DURATION
				
				
				    
				    if(retval=="Fail")
				        {
				            document.getElementById("ctl00_BodyContentPH_hidLeaveFlag").value = 'F';
				            alert("Invalid Date");				            
				            //return  false;
				        }
				     else if(retval=="DOJFail")
				        {
				            document.getElementById("ctl00_BodyContentPH_hidLeaveFlag").value = 'F';
				            alert("Policy Start Date should be greater than the Date Of Joining");
				            //return false;
				        }
				    else if(retval=="Interven")
				        {				        
				            document.getElementById("ctl00_BodyContentPH_hidLeaveFlag").value = 'F';
				            alert("Policy Date already Exists");
				            //return false;
				        }
				    else if(retval=="EmptyFail")
				        {
				            document.getElementById("ctl00_BodyContentPH_hidLeaveFlag").value = 'F';
				            alert("Fill Start Date and End Date");
				            //return false;
				        }
				    else
				        {
				        
				            document.getElementById("ctl00_BodyContentPH_hidLeaveFlag").value = 'T';
				            if(document.getElementById('tbl_LeavePolicydetails')!=null)
				                {
				                  document.getElementById('tbl_LeavePolicydetails').style.display="none";
				                }
        				
				           //document.getElementById('ctl00_BodyContentPH_div_EmpLeave').innerHTML=retval;			           
				           flg="success";
				        }
				        //return chumma();
				}
				
				else
				{
				    alert("No Details found  in Emp Leave!");
				}
				if (flg=="success")
				{
				    __doPostBack(document.getElementById('ctl00_BodyContentPH_ImageButton2').name,'');
				}
			}
			
			else
			{
				alert("Error in retriving details");
			}
			
		}
}