// JScript File
var flg = null;
var objLeave = null;
    function ajaxEmpLeave(FillLeavePolicy,Leavepolicydurationshouldnotbeempty,SelectDate,InvalidDate,PolicyStartDateshouldbegreaterthantheDOJ,PolicyDatealreadyExists,FillStartDateandEndDate,NoDetailsfoundinEmpLeave,Errorinretrivingdetails,LeavePolicyNoDetailsfoundinEmpLeave,LeavePolicyErrorinretrivingdetails,PolicyDateContinutyMissing)
    {
       if(window.ActiveXObject)
        {    
	        try
	        {
		        objLeave = new ActiveXObject("Msxml2.XMLHTTP");
	        }
	        catch(e)
	        {
		        try
		        {
			        objLeave = new ActiveXObject("Microsoft.XMLHTTP");
		        }
		        catch(e1)
		        {
			        objLeave = null;
		        }
	        }
        }  
         else if(window.XMLHttpRequest)
         {
	        try
	        {
		        objLeave = new XMLHttpRequest("Msxml2.XMLHTTP");
	        }
	        catch(e)
	        {
		        try
		        {
			        objLeave = new XMLHttpRequest("Microsoft.XMLHTTP");
		        }
		        catch(e1)
		        {
			        objLeave = null;
		        }
	        }
        }
//        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);
                if(window.ActiveXObject)
                {
                    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(window.XMLHttpRequest)
                {
                    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,false);
                    objLeave.send(null);
                    objLeave.onreadystatechange=Process_Response_EmpLeave();
                }
           }
         }
         else if(document.getElementById("ctl00_BodyContentPH_hdf_Policy").value!="")
            {
                if(document.aspnetForm.ctl00_BodyContentPH_ddl_LeavePolicy.selectedIndex==0)
                {
                    //alert("Fill Leave Policy");
                     alert(FillLeavePolicy);
                    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");
                    alert(Leavepolicydurationshouldnotbeempty);
                    //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");
				            alert(SelectDate);
				            return false;
				        }
				     else
				        {
				        }
				//VALIDATING FROM/TO DATE VS LEAVE POLICY DURATION
				    if(retval=="Fail")
				        {
				            document.getElementById("ctl00_BodyContentPH_hidLeaveFlag").value = 'F';
				            //alert("Invalid Date");	
				            alert(InvalidDate);				            
				            //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");
				            alert(PolicyStartDateshouldbegreaterthantheDOJ);
				            //return false;
				        }
				    else if(retval=="Interven")
				        {				        
				            document.getElementById("ctl00_BodyContentPH_hidLeaveFlag").value = 'F';
				            alert(PolicyDatealreadyExists);
				            //return false;
				        }
				    else if(retval=="EmptyFail")
				        {
				            document.getElementById("ctl00_BodyContentPH_hidLeaveFlag").value = 'F';
				            //alert("Fill Start Date and End Date");
				            alert(FillStartDateandEndDate);
				            //return false;
				        }
				    else
				        {
				            document.getElementById("ctl00_BodyContentPH_hidLeaveFlag").value = 'T';
				            if(document.getElementById('div_LeavePolicydetails')!=null)
				                {
				                  document.getElementById('div_LeavePolicydetails').style.display="none";
				                }
				           document.getElementById('ctl00_BodyContentPH_div_EmpLeave').innerHTML=retval;
				           //return true;
				        }
				        //return chumma();
				}
				else
				{
				    //alert("No Details found  in Emp Leave!");
				    alert(NoDetailsfoundinEmpLeave);
				}
			}
			else
			{
				//alert("Error in retriving details");
				alert(Errorinretrivingdetails);
			}
		}
	}
	function ajaxEmpLeave_saveButton(FillLeavePolicy,Leavepolicydurationshouldnotbeempty,SelectDate,InvalidDate,PolicyStartDateshouldbegreaterthantheDOJ,PolicyDatealreadyExists,FillStartDateandEndDate,NoDetailsfoundinEmpLeave,Errorinretrivingdetails,LeavePolicyNoDetailsfoundinEmpLeave,LeavePolicyErrorinretrivingdetails,PolicyDateContinutyMissing)
    {
       if(window.ActiveXObject)
        {    
	        try
	        {
		        objLeave = new ActiveXObject("Msxml2.XMLHTTP");
	        }
	        catch(e)
	        {
		        try
		        {
			        objLeave = new ActiveXObject("Microsoft.XMLHTTP");
		        }
		        catch(e1)
		        {
			        objLeave = null;
		        }
	        }
        }  
         else if(window.XMLHttpRequest)
         {
	        try
	        {
		        objLeave = new XMLHttpRequest("Msxml2.XMLHTTP");
	        }
	        catch(e)
	        {
		        try
		        {
			        objLeave = new XMLHttpRequest("Microsoft.XMLHTTP");
		        }
		        catch(e1)
		        {
			        objLeave = null;
		        }
	        }
        }
//        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);
            if(window.ActiveXObject)
            {
                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 if(window.XMLHttpRequest)
           {
                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,false);
                objLeave.send(null);
                objLeave.onreadystatechange=Process_Response_EmpLeave_saveButton();
           }
         }
         else
         {
          //  alert("Fill Leave Policy");
           // document.getElementById('ctl00_BodyContentPH_div_EmpLeave').innerHTML="";
            __doPostBack(document.getElementById('ctl00_BodyContentPH_ButSave').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(SelectDate);
				            return false;
				        }
				     else
				        {
				        }
				//VALIDATING FROM/TO DATE VS LEAVE POLICY DURATION
				    if(retval=="Fail")
				        {
				        ShowTab();
				            document.getElementById("ctl00_BodyContentPH_hidLeaveFlag").value = 'F';
				            alert(InvalidDate);
//				            return  false;
				        }
				     else if(retval=="DOJFail")
				        {
				        ShowTab();
				            document.getElementById("ctl00_BodyContentPH_hidLeaveFlag").value = 'F';
				            alert(PolicyStartDateshouldbegreaterthantheDOJ);
//				            return false;
				        }
				    else if(retval=="Interven")
				        {	
				        ShowTab();			        
				            document.getElementById("ctl00_BodyContentPH_hidLeaveFlag").value = 'F';
				            alert(PolicyDatealreadyExists);
//				            return false;
				        }
				    else if(retval=="EmptyFail")
				        {
				        ShowTab();
				            document.getElementById("ctl00_BodyContentPH_hidLeaveFlag").value = 'F';
				            alert(FillStartDateandEndDate);
//				            return false;
				        }
				    else
				        {
				            document.getElementById("ctl00_BodyContentPH_hidLeaveFlag").value = 'T';
				            if(document.getElementById('div_LeavePolicydetails')!=null)
				                {
				                  document.getElementById('div_LeavePolicydetails').style.display="none";
				                }
				           //document.getElementById('ctl00_BodyContentPH_div_EmpLeave').innerHTML=retval;			           
				           flg="success";
				        }
				        //return chumma();
				}
				else
				{
				    //alert("Leave Policy - No Details found  in Emp Leave!");
				    alert(LeavePolicyNoDetailsfoundinEmpLeave);
				}
				if (flg=="success")
				{
                     __doPostBack(document.getElementById('ctl00_BodyContentPH_ButSave').name,'');
				}
			}
			else
			{
				//alert("Leave Policy - Error in retriving details");
				alert(LeavePolicyErrorinretrivingdetails);
			}
		}
    }
function CheckPolicyTab()
  {
    if(window.ActiveXObject)
        {    
	        try
	        {
		        objLeave = new ActiveXObject("Msxml2.XMLHTTP");
	        }
	        catch(e)
	        {
		        try
		        {
			        objLeave = new ActiveXObject("Microsoft.XMLHTTP");
		        }
		        catch(e1)
		        {
			        objLeave = null;
		        }
	        }
        }  
         else if(window.XMLHttpRequest)
         {
	        try
	        {
		        objLeave = new XMLHttpRequest("Msxml2.XMLHTTP");
	        }
	        catch(e)
	        {
		        try
		        {
			        objLeave = new XMLHttpRequest("Microsoft.XMLHTTP");
		        }
		        catch(e1)
		        {
			        objLeave = null;
		        }
	        }
        }
//        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);
            if(window.ActiveXObject)
            {
                objLeave.onreadystatechange=CheckPolicyResponse;
                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(window.XMLHttpRequest)
            {
                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,false);
                objLeave.send(null);
                objLeave.onreadystatechange=CheckPolicyResponse();
            }
         }
         else
         {
          //  alert("Fill Leave Policy");
           // document.getElementById('ctl00_BodyContentPH_div_EmpLeave').innerHTML="";
           //__doPostBack(document.getElementById('ctl00_BodyContentPH_ImageButton2').name,'');
         }
        }
        return false;
}
function CheckPolicyResponse()
	{
		if(objLeave.readyState == 4)
		{
			if(objLeave.status == 200)
			{
				var retval=objLeave.responseText;
				if (retval.length > 0)
				{
				    if(retval=="Failure")
				        {
				            alert(SelectDate);
				            return false;
				        }
				     else
				        {
				        }
				//VALIDATING FROM/TO DATE VS LEAVE POLICY DURATION
				    if(retval=="Fail")
				        {
				            test();
				            document.getElementById("ctl00_BodyContentPH_hidLeaveFlag").value = 'F';
				            alert(InvalidDate);				            
				            //return  false;
				        }
				     else if(retval=="DOJFail")
				        {
				        test();
				            document.getElementById("ctl00_BodyContentPH_hidLeaveFlag").value = 'F';
				            alert(PolicyStartDateshouldbegreaterthantheDOJ);
				            //return false;
				        }
				    else if(retval=="Interven")
				        {				        
				        test();
				            document.getElementById("ctl00_BodyContentPH_hidLeaveFlag").value = 'F';
				            alert(PolicyDatealreadyExists);
				            //return false;
				        }
				    else if(retval=="EmptyFail")
				        {
				        test();
				            document.getElementById("ctl00_BodyContentPH_hidLeaveFlag").value = 'F';
				            alert(FillStartDateandEndDate);
				            //return false;
				        }
				    else
				        {
				            document.getElementById("ctl00_BodyContentPH_hidLeaveFlag").value = 'T';
				            if(document.getElementById('div_LeavePolicydetails')!=null)
				                {
				                  document.getElementById('div_LeavePolicydetails').style.display="none";
				                }
				           //document.getElementById('ctl00_BodyContentPH_div_EmpLeave').innerHTML=retval;			           
				           flg="success";
				        }
				        //return chumma();
				}
				else
				{
				    test();
				    alert(NoDetailsfoundinEmpLeave);
				}
				if (flg=="success")
				{
				    document.getElementById("txtSuccess").value="true";
				    //__doPostBack(document.getElementById('ctl00_BodyContentPH_ImageButton2').name,'');
				}
				else
				{
    				document.getElementById("txtSuccess").value="false";
				}
			}
			else
			{
				alert(Errorinretrivingdetails);
			}
		}
}
function ShowTab()
{
    document.getElementById('ctl00_BodyContentPH_PH_Personal').style.display="none";
    document.getElementById('ctl00_BodyContentPH_PH_Official').style.display="none";
    document.getElementById('ctl00_BodyContentPH_PH_LeavePolicy').style.display = "block";
    document.getElementById('ctl00_BodyContentPH_PH_Payroll').style.display = "none";
    document.getElementById('ctl00_BodyContentPH_PH_Others').style.display="none";
      $('#tablist a[href="#LeavePolicy"]').tab('show');
      $('#ctl00_BodyContentPH_lblMandat').text("NIL");
}
function ajaxEmpLeaveQuota(FillLeavePolicy,Leavepolicydurationshouldnotbeempty,SelectDate,InvalidDate,PolicyStartDateshouldbegreaterthantheDOJ,PolicyDatealreadyExists,FillStartDateandEndDate,NoDetailsfoundinEmpLeave,Errorinretrivingdetails,LeavePolicyNoDetailsfoundinEmpLeave,LeavePolicyErrorinretrivingdetails,PolicyDateContinutyMissing)
    {
    if(window.ActiveXObject)
        {    
	        try
	        {
		        objLeave = new ActiveXObject("Msxml2.XMLHTTP");
	        }
	        catch(e)
	        {
		        try
		        {
			        objLeave = new ActiveXObject("Microsoft.XMLHTTP");
		        }
		        catch(e1)
		        {
			        objLeave = null;
		        }
	        }
        }  
         else if(window.XMLHttpRequest)
         {
	        try
	        {
		        objLeave = new XMLHttpRequest("Msxml2.XMLHTTP");
	        }
	        catch(e)
	        {
		        try
		        {
			        objLeave = new XMLHttpRequest("Microsoft.XMLHTTP");
		        }
		        catch(e1)
		        {
			        objLeave = null;
		        }
	        }
        }
//        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);
            if(window.ActiveXObject)
            {
                objLeave.onreadystatechange=Process_Response_EmpLeaveQuota;
                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 + "&Qo=1" ,true);
                objLeave.send(null);
            }
            else if(window.XMLHttpRequest)
            {
                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 + "&Qo=1" ,false);
                objLeave.send(null);
                objLeave.onreadystatechange=Process_Response_EmpLeaveQuota();
            }
           }
         }
         else if(document.getElementById("ctl00_BodyContentPH_hdf_Policy").value!="")
            {
                if(document.aspnetForm.ctl00_BodyContentPH_ddl_LeavePolicy.selectedIndex==0)
                {
                    //alert("Fill Leave Policy");
                    alert(FillLeavePolicy);
                    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");
                    alert(Leavepolicydurationshouldnotbeempty);
                    //document.getElementById('ctl00_BodyContentPH_div_EmpLeave').innerHTML="";
                    return false;
                }
         }
        }
        return false;
    }
    function Process_Response_EmpLeaveQuota()
	{
		if(objLeave.readyState == 4)
		{
			if(objLeave.status == 200)
			{
				var retval=objLeave.responseText;
				if (retval.length > 0)
				{
				    if(retval=="Failure")
				        {
				            alert(SelectDate);
				            return false;
				        }
				     else
				        {
				        }
				//VALIDATING FROM/TO DATE VS LEAVE POLICY DURATION
				    if(retval=="Fail")
				        {
				            document.getElementById("ctl00_BodyContentPH_hidLeaveFlag").value = 'F';
				            alert(InvalidDate);				            
				            //return  false;
				        }
				     else if(retval=="DOJFail")
				        {
				            document.getElementById("ctl00_BodyContentPH_hidLeaveFlag").value = 'F';
				            alert(PolicyStartDateshouldbegreaterthantheDOJ);
				            //return false;
				        }
				    else if(retval=="Interven")
				        {				        
				            document.getElementById("ctl00_BodyContentPH_hidLeaveFlag").value = 'F';
				            alert(PolicyDatealreadyExists);
				            //return false;
				        }
				         else if(retval=="DisConnect")
				        {				        
				            document.getElementById("ctl00_BodyContentPH_hidLeaveFlag").value = 'F';
				            //alert("Policy Date Continuty Missing");
				            alert(PolicyDateContinutyMissing);
				            //return false;
				        } 
				    else if(retval=="EmptyFail")
				        {
				            document.getElementById("ctl00_BodyContentPH_hidLeaveFlag").value = 'F';
				            alert(FillStartDateandEndDate);
				            //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_dvCurrrentQuota').innerHTML=retval;
				          //return true;
				        }
				        //return chumma();
				}
				else
				{
				    alert(NoDetailsfoundinEmpLeave);
				}
			}
			else
			{
				alert(Errorinretrivingdetails);
			}
		}
	}
