// JScript File

var objec = null;

    function ajaxfunction()
    {
        try
        {
             objec = new XMLHttpRequest();
        }
        catch(ex)
        {
            try
            {
                objec=new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch(e)
            {
                try
                {
                    objec=new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch(e1)
                {
                    objec=null;
                }
            }
        }
        if(objec!=null)
        {
         if(document.getElementById("ctl00_BodyContentPH_txt_ChildrenNo").value > 0)
         {
            objec.onreadystatechange=Process_Response;
            objec.open("GET","Employee_Children.aspx?No="+document.getElementById("ctl00_BodyContentPH_txt_ChildrenNo").value,true);
            objec.send(null);
         }
         else
         {
            document.getElementById("div_children").innerHTML="";
         }
        }
        return false;
    }
    
    function Process_Response()
	{
		if(objec.readyState == 4)
		{
			if(objec.status == 200)
			{
				var retval=objec.responseText;
				if (retval.length > 0)
				{
				   document.getElementById("div_children").innerHTML=retval;
				}
				else
				{
				    alert("No Details found in Child!");
				}
			}
			else
			{
				alert("Error in retriving details");
			}
		}
	}
	
	//assign the children details to hidden field
	
	function assign_hidden(child)
    {
        if(child != 1)
        {  
                   //current date
               var Curdate=new Date();
               var CurYear=Curdate.getFullYear();
               var CurMonth=Curdate.getMonth();
               CurMonth=CurMonth+1;
               var cdate=Curdate.getDate();
               
               //DOB child validation
                        var dob;
               if(document.getElementById(child.id) != null)
               {
                  dob=document.getElementById(child.id).value;
               }
               else
               {    
                 dob = document.getElementById(child).value;               
               }
               //dob = document.getElementById(child.id).value;  
               
               //validation for MM/dd/YYYY format
              if(document.getElementById('Hidden1').value=='%m/%d/%Y')
              {             
               var dobMonth=dob.substring(0,2);
               var dobDate=dob.substring(3,5);
               var dobYear=dob.substring(6,dob.length);
              }
               
               //validation for dd/MM/YYYY format
              if(document.getElementById('Hidden1').value=='%d/%m/%Y')
                {
                var dobMonth=dob.substring(3,5);
                var dobDate=dob.substring(0,2);
                var dobYear=dob.substring(6,dob.length);
                }
                
                //validation for dd-MMM-YYYY format
                if(document.getElementById('Hidden1').value=='%d-%b-%Y')
                {
                   var mon = dob.substring(3,6);
                   var dobMonth = Month(mon);
                   
                   var dobDate=dob.substring(0,2);
                   var dobYear=dob.substring(7,dob.length);
                }
                
                if (dobYear >= CurYear)
                {
                    if (dobYear > CurYear)
                    {
                        alert("Invalid Child DOB");
                        return false;
                    }
                    if (dobYear == CurYear)
                    {
                        if (dobMonth >= CurMonth)
                        {
                            if (dobMonth > CurMonth)
                            {
                                alert("Invalid Child DOB");
                                return false;
                            }
                            if (dobMonth == CurMonth)
                            {
                                if (dobDate >= cdate)
                                {
                                    alert("Invalid Child DOB");
                                    return false;
                                }
                                else
                                {
                                }
                            }
                        }
                        else
                        {
                        }
                    }        
                }
                else
                {
                }
        
        }                      
        var no_of_rows=document.getElementById("ctl00_BodyContentPH_txt_ChildrenNo").value;
        var data="";
        
        for(var i=1; i<= no_of_rows; i++)
            {
            var txt = "txt_ChName" + i;
            var dat = "txt_ChildDOB" + i;
                if(data == "")
                {
                    data = document.getElementById(txt).value + "," + document.getElementById(dat).value;
                }
                else
                {
                   data = data + "*" + document.getElementById(txt).value + "," + document.getElementById(dat).value;
                }
            }
            document.getElementById("ctl00_BodyContentPH_hid_Children").value=data;
            
     return true;
    } 
	 
	
//Employee Children Details Modify

function ajaxfunctionModify(EmpID)
{
        try
        {
             objec = new XMLHttpRequest();
        }
        catch(ex)
        {
            try
            {
                objec=new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch(e)
            {
                try
                {
                    objec=new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch(e1)
                {
                    objec=null;
                }
            }
        }
        if(objec!=null)
        {  
            if (document.getElementById("ctl00_BodyContentPH_txt_ChildrenNo").value !="")
            {          
                objec.open("POST","Emp_ChildrenModify.aspx?No=" + document.getElementById("ctl00_BodyContentPH_txt_ChildrenNo").value + "&EmpID="+EmpID+"",true);
                objec.onreadystatechange=ProcessResponseModify;
                objec.send(null);
            }
                return false
        }               
        return false;
    }
    
    function ProcessResponseModify()
	{
		if(objec.readyState == 4)
		{
			if(objec.status == 200)
			{
			    document.getElementById('div_children').innerHTML = objec.responseText;
			}
		}
	}
	
	//assign the children details to hidden field
	
	function assign_hiddenModify(child)
    {
            if(child != 1)
            {  
                   //current date
               var Curdate=new Date();
               var CurYear=Curdate.getFullYear();
               var CurMonth=Curdate.getMonth();
               CurMonth=CurMonth+1;
               var cdate=Curdate.getDate();
               
               //DOB child validation
                var dob;
               if(document.getElementById(child.id) != null)
               {
                  dob=document.getElementById(child.id).value;
               }
               else
               {    
                 dob = document.getElementById(child).value;   
               }
               //dob = document.getElementById(child.id).value;   
                           
               //validation for MM/dd/YYYY format
              if(document.getElementById('Hidden1').value=='%m/%d/%Y')
              {             
               var dobMonth=dob.substring(0,2);
               var dobDate=dob.substring(3,5);
               var dobYear=dob.substring(6,dob.length);
              }
               
               //validation for dd/MM/YYYY format
              if(document.getElementById('Hidden1').value=='%d/%m/%Y')
                {
                var dobMonth=dob.substring(3,5);
                var dobDate=dob.substring(0,2);
                var dobYear=dob.substring(6,dob.length);
                }
                
                //validation for dd-MMM-YYYY format
                if(document.getElementById('Hidden1').value=='%d-%b-%Y')
                {
                   var mon = dob.substring(3,6);
                   var dobMonth = Month(mon);
                   
                   var dobDate=dob.substring(0,2);
                   var dobYear=dob.substring(7,dob.length);
                }
    
                if (dobYear >= CurYear)
                {
                    if (dobYear > CurYear)
                    {
                        alert("Invalid Child DOB");
                        return false;
                    }
                    if (dobYear == CurYear)
                    {
                        if (dobMonth >= CurMonth)
                        {
                            if (dobMonth > CurMonth)
                            {
                                alert("Invalid Child DOB");
                                return false;
                            }
                            if (dobMonth == CurMonth)
                            {
                                if (dobDate >= cdate)
                                {
                                    alert("Invalid Child DOB");
                                    return false;
                                }
                                else
                                {
                                }
                            }
                        }
                        else
                        {
                        }
                    }        
                }
                else
                {
                }
        
            }  
        
        var no_of_rows=document.getElementById("ctl00_BodyContentPH_txt_ChildrenNo").value;
        var data="";
        
        for(var i=0; i< no_of_rows; i++)
            {
            var txt = "txt_ChName" + i;
            var dat = "txt_ChildDOB" + i;
                if(data == "")
                {
                    data = document.getElementById(txt).value + "," + document.getElementById(dat).value;
                }
                else
                {
                   data = data + "*" + document.getElementById(txt).value + "," + document.getElementById(dat).value;
                }
            }
            document.getElementById("ctl00_BodyContentPH_hid_Children").value=data;
            
            return true;
    } 
	
	//Employee Children Details View

function ajaxfunctionView(EmpID)
{
        try
        {
             objec = new XMLHttpRequest();
        }
        catch(ex)
        {
            try
            {
                objec=new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch(e)
            {
                try
                {
                    objec=new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch(e1)
                {
                    objec=null;
                }
            }
        }
        if(objec!=null)
        {            
            objec.open("POST","Emp_ChildrenView.aspx?EmpID="+EmpID+"",true);
            objec.onreadystatechange=ProcessResponseView;
            objec.send(null);
         }               
        return false;
    }
    
    function ProcessResponseView()
	{
		if(objec.readyState == 4)
		{
			if(objec.status == 200)
			{
			    document.getElementById('div_children').innerHTML = objec.responseText;
			}
		}
	}