// JScript File

// Created by Kumuthini.L

var objInPunchTypes;
var objOutPunchTypes;

function ManualTimeEntry_InPunchTypes()
{
    try
	{
		objInPunchTypes = new XmlHttpRequest();
	}
	catch(e)
	{
		try
		{
			objInPunchTypes = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e1)
		{
			objInPunchTypes = new ActiveXObject("Msxml2.XMLHTTP");
		}
	}
	
	if(objInPunchTypes != null)
	{
		var EntranceId=document.getElementById('ctl00_CP_Transaction_ddlInTerminals').value;
	    
	    if(EntranceId == "-Select-")
	    {
	       alert("Select In Terminal");
	       
	       //Clears In PunchTypes dropdown
	       if (document.getElementById('ctl00_CP_Transaction_ddlInPunchTypes').options.length != null)
            {				
	            for (var count = document.getElementById('ctl00_CP_Transaction_ddlInPunchTypes').options.length-1;count >-1; count--)
	            {
	                document.getElementById('ctl00_CP_Transaction_ddlInPunchTypes').options[count] = null;
	            }	
            }
             //Fill In punchtypes drop down with 'Select'
             var newOptSelect = new Option('-Select-','-Select-',  false, false);
             document.getElementById('ctl00_CP_Transaction_ddlInPunchTypes').options[0]=newOptSelect;
             
            
	       return false;
	    }
		if(EntranceId != "")
		{
		    objInPunchTypes.onreadystatechange =  Process_Response_InPunchTypes;		
		    objInPunchTypes.open("GET","AjaxManualTimeEntry.aspx?EntranceId=" + EntranceId + "&TerminalType=I" + "&strType=PunchTypes" + "&RanId=" + Math.random(),true)
		    objInPunchTypes.send(null);
		} 
		
		FillInTerminalHidden();
		
	}
	return false;
}

function Process_Response_InPunchTypes()
{
   if (document.getElementById('ctl00_CP_Transaction_ddlInPunchTypes').options.length != null)
   {				
	  for (var count = document.getElementById('ctl00_CP_Transaction_ddlInPunchTypes').options.length-1;count >-1; count--)
	  {
	     document.getElementById('ctl00_CP_Transaction_ddlInPunchTypes').options[count] = null;
	  }	
   }
   
   if(objInPunchTypes.readyState == 4)
   {
	   if(objInPunchTypes.status == 200)
	   {
		  if(objInPunchTypes.responseText=="Fail" || objInPunchTypes.responseText=="")
		  {
			 var newOptSelect = new Option('-Select-','-Select-',  false, false);
             document.getElementById('ctl00_CP_Transaction_ddlInPunchTypes').options[0]=newOptSelect;
		     alert("No Records");
			 return;
		  }
		  else
		  {
			 var xml=objInPunchTypes.responseXML;
			 var dsRoot=xml.documentElement.getElementsByTagName("InPunchTypes");  
			 var totalRec = dsRoot.length;
             var newOptSelect = new Option('-Select-','-Select-',  false, false);
             document.getElementById('ctl00_CP_Transaction_ddlInPunchTypes').options[0]=newOptSelect;
                        
             for(i=0; i<totalRec; i++)
             {
                var Value = xml.getElementsByTagName("Value")[i];
                var PunchTypeId=xml.getElementsByTagName("PunchType_Id")[i];
                var newOpt=new Option(Value.text,Value.text);
                        
                document.getElementById('ctl00_CP_Transaction_ddlInPunchTypes').options[i+1]=newOpt;
             }
             document.getElementById('ctl00_CP_Transaction_ddlInPunchTypes').focus();
           }
      }
      else
      {
	    alert("Error in retriving details");
      }
   }
}

function ManualTimeEntry_OutPunchTypes()
{
    try
	{
		objOutPunchTypes = new XmlHttpRequest();
	}
	catch(e)
	{
		try
		{
			objOutPunchTypes = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e1)
		{
			objOutPunchTypes = new ActiveXObject("Msxml2.XMLHTTP");
		}
	}
	
	if(objOutPunchTypes != null)
	{
		var EntranceId=document.getElementById('ctl00_CP_Transaction_ddlOutTerminals').value;
		
		if(EntranceId == "-Select-")
	    {
	       alert("Select Out Terminal");
	       
	       //Clears Out PunchTypes dropdown
	       if (document.getElementById('ctl00_CP_Transaction_ddlOutPunchTypes').options.length != null)
            {				
	            for (var count = document.getElementById('ctl00_CP_Transaction_ddlOutPunchTypes').options.length-1;count >-1; count--)
	            {
	                document.getElementById('ctl00_CP_Transaction_ddlOutPunchTypes').options[count] = null;
	            }	
            }
             //Fill Out punchtypes drop down with 'Select'
             var newOptSelect = new Option('-Select-','-Select-',  false, false);
             document.getElementById('ctl00_CP_Transaction_ddlOutPunchTypes').options[0]=newOptSelect;
             
            
	       return false;
	    }
	    
		if(EntranceId != "")
		{
		    objOutPunchTypes.onreadystatechange = Process_Response_OutPunchTypes;		
		    objOutPunchTypes.open("GET","AjaxManualTimeEntry.aspx?EntranceId=" + EntranceId + "&TerminalType=O" + "&strType=PunchTypes" + "&RanId=" + Math.random(),true)
		    objOutPunchTypes.send(null);
		} 
		
		 FillOutTerminalHidden();
 
	}
	return false;
}

function Process_Response_OutPunchTypes()
{
   if (document.getElementById('ctl00_CP_Transaction_ddlOutPunchTypes').options.length != null)
   {				
	  for (var count = document.getElementById('ctl00_CP_Transaction_ddlOutPunchTypes').options.length-1;count >-1; count--)
	  {
	     document.getElementById('ctl00_CP_Transaction_ddlOutPunchTypes').options[count] = null;
	  }	
   }
   
   if(objOutPunchTypes.readyState == 4)
   {
	   if(objOutPunchTypes.status == 200)
	   {
		  if(objOutPunchTypes.responseText=="Fail" || objOutPunchTypes.responseText=="")
		  {
			 var newOptSelect = new Option('-Select-','-Select-',  false, false);
             document.getElementById('ctl00_CP_Transaction_ddlOutPunchTypes').options[0]=newOptSelect;
		     alert("No Records");
			 return;
		  }
		  else
		  {
			 var xml=objOutPunchTypes.responseXML;
			 var dsRoot=xml.documentElement.getElementsByTagName("OutPunchTypes");  
			 var totalRec = dsRoot.length;
             var newOptSelect = new Option('-Select-','-Select-',  false, false);
             document.getElementById('ctl00_CP_Transaction_ddlOutPunchTypes').options[0]=newOptSelect;
                        
             for(i=0; i<totalRec; i++)
             {
                var Value = xml.getElementsByTagName("Value")[i];
                var PunchTypeId=xml.getElementsByTagName("PunchType_Id")[i];
                var newOpt=new Option(Value.text,Value.text);
                        
                document.getElementById('ctl00_CP_Transaction_ddlOutPunchTypes').options[i+1]=newOpt;
             }
             document.getElementById('ctl00_CP_Transaction_ddlOutPunchTypes').focus();
           }
      }
      else
      {
	    alert("Error in retriving details");
      }
   }
}


//Manual Time Entry fill In and Out Terminals in Dropdown Based on the Entrance

var objInTerminals;
var objOutTerminals;

function ManualTimeEntryTerminals()
{
	ManualTimeEntry_InTerminals();
	ManualTimeEntry_OutTerminals();
}

function ManualTimeEntry_InTerminals()
{
    try
	{
		objInTerminals = new XmlHttpRequest();
	}
	catch(e)
	{
		try
		{
			objInTerminals = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e1)
		{
			objInTerminals = new ActiveXObject("Msxml2.XMLHTTP");
		}
	}
	
	if(objInTerminals != null)
	{
		var EntranceId=document.getElementById('ctl00_CP_Transaction_ddlEntranceName').value
	    
	    if(EntranceId == "-Select-")
	    {
	       
	        
            //Clear Drop down OutTerminals
            if (document.getElementById('ctl00_CP_Transaction_ddlInTerminals').options.length != null)
            {				
	            for (var count = document.getElementById('ctl00_CP_Transaction_ddlInTerminals').options.length-1;count >-1; count--)
	            {
	                document.getElementById('ctl00_CP_Transaction_ddlInTerminals').options[count] = null;
	            }	
            }
   
            //Clear Drop down OutTerminals
	       if (document.getElementById('ctl00_CP_Transaction_ddlOutTerminals').options.length != null)
            {				
	            for (var count = document.getElementById('ctl00_CP_Transaction_ddlOutTerminals').options.length-1;count >-1; count--)
	            {
	                document.getElementById('ctl00_CP_Transaction_ddlOutTerminals').options[count] = null;
	            }	
            }
            //Fill Select for InTerminals and OutTerminals Drop downs
                var newOptSelect = new Option('-Select-','-Select-',  false, false);
                var newOptSelectOut = new Option('-Select-','-Select-',  false, false);
                document.getElementById('ctl00_CP_Transaction_ddlInTerminals').options[0]=newOptSelect;
                document.getElementById('ctl00_CP_Transaction_ddlOutTerminals').options[0]=newOptSelectOut;
                
                
             //Clears In PunchTypes dropdown
	        if (document.getElementById('ctl00_CP_Transaction_ddlInPunchTypes').options.length != null)
            {				
	            for (var count = document.getElementById('ctl00_CP_Transaction_ddlInPunchTypes').options.length-1;count >-1; count--)
	            {
	                document.getElementById('ctl00_CP_Transaction_ddlInPunchTypes').options[count] = null;
	            }	
            }
             //Fill In punchtypes drop down with 'Select'
             var newOptSelectInPunchTypes = new Option('-Select-','-Select-',  false, false);
              document.getElementById('ctl00_CP_Transaction_ddlInPunchTypes').options[0]=newOptSelectInPunchTypes;
              
              //Clears Out PunchTypes dropdown
	       if (document.getElementById('ctl00_CP_Transaction_ddlOutPunchTypes').options.length != null)
            {				
	            for (var count = document.getElementById('ctl00_CP_Transaction_ddlOutPunchTypes').options.length-1;count >-1; count--)
	            {
	                document.getElementById('ctl00_CP_Transaction_ddlOutPunchTypes').options[count] = null;
	            }	
            }
             //Fill Out punchtypes drop down with 'Select'
             var newOptSelectOutPunchTypes = new Option('-Select-','-Select-',  false, false);
             document.getElementById('ctl00_CP_Transaction_ddlOutPunchTypes').options[0]=newOptSelectOutPunchTypes;
             
             
             
               alert("Select Entrance ID"); 
	       return false;
	    }
		if(EntranceId != "")
		{
		    objInTerminals.onreadystatechange =  Process_Response_InTerminals;		
		    objInTerminals.open("GET","AjaxManualTimeEntry.aspx?EntranceId=" + EntranceId + "&TerminalType=I" + "&strType=Terminals" + "&RanId=" + Math.random(),true)
		    objInTerminals.send(null);
		} 
	}
	return false;
}

function Process_Response_InTerminals()
{
   if (document.getElementById('ctl00_CP_Transaction_ddlInTerminals').options.length != null)
   {				
	  for (var count = document.getElementById('ctl00_CP_Transaction_ddlInTerminals').options.length-1;count >-1; count--)
	  {
	     document.getElementById('ctl00_CP_Transaction_ddlInTerminals').options[count] = null;
	  }	
   }
   
   if(objInTerminals.readyState == 4)
   {
	   if(objInTerminals.status == 200)
	   {
		  if(objInTerminals.responseText=="Fail" || objInTerminals.responseText=="")
		  {
			 var newOptSelect = new Option('-Select-','-Select-',  false, false);
             document.getElementById('ctl00_CP_Transaction_ddlInTerminals').options[0]=newOptSelect;
		     alert("No Records");
			 return;
		  }
		  else
		  {
			 var xml=objInTerminals.responseXML;
			 var dsRoot=xml.documentElement.getElementsByTagName("InTerminals");  
			 var totalRec = dsRoot.length;
             var newOptSelect = new Option('-Select-','-Select-',  false, false);
             document.getElementById('ctl00_CP_Transaction_ddlInTerminals').options[0]=newOptSelect;
                        
             for(i=0; i<totalRec; i++)
             {
                var Value = xml.getElementsByTagName("Reader_Id")[i];
                var TerminalId=xml.getElementsByTagName("Terminal_ReaderID")[i];
                var newOpt=new Option(TerminalId.text,Value.text);
                        
                document.getElementById('ctl00_CP_Transaction_ddlInTerminals').options[i+1]=newOpt;
             }
             document.getElementById('ctl00_CP_Transaction_ddlInTerminals').focus();
           }
      }
      else
      {
	    alert("Error in retriving details");
      }
   }
}

function ManualTimeEntry_OutTerminals()
{
    try
	{
		objOutTerminals = new XmlHttpRequest();
	}
	catch(e)
	{
		try
		{
			objOutTerminals = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e1)
		{
			objOutTerminals = new ActiveXObject("Msxml2.XMLHTTP");
		}
	}
	
	if(objOutTerminals != null)
	{
		var EntranceId=document.getElementById('ctl00_CP_Transaction_ddlEntranceName').value
	 
	    if(EntranceId == "-Select-")
	    {
	    return false;
	    }
		if(EntranceId != "")
		{
		    objOutTerminals.onreadystatechange = Process_Response_OutTerminals;		
		    objOutTerminals.open("GET","AjaxManualTimeEntry.aspx?EntranceId=" + EntranceId + "&TerminalType=O" + "&strType=Terminals" + "&RanId=" + Math.random(),true)
		    objOutTerminals.send(null);
		} 
	}
	return false;
}

function Process_Response_OutTerminals()
{
   if (document.getElementById('ctl00_CP_Transaction_ddlOutTerminals').options.length != null)
   {				
	  for (var count = document.getElementById('ctl00_CP_Transaction_ddlOutTerminals').options.length-1;count >-1; count--)
	  {
	     document.getElementById('ctl00_CP_Transaction_ddlOutTerminals').options[count] = null;
	  }	
   }
   
   if(objOutTerminals.readyState == 4)
   {
	   if(objOutTerminals.status == 200)
	   {
		  if(objOutTerminals.responseText=="Fail" || objOutTerminals.responseText=="")
		  {
			 var newOptSelect = new Option('-Select-','-Select-',  false, false);
             document.getElementById('ctl00_CP_Transaction_ddlOutTerminals').options[0]=newOptSelect;
		     alert("No Records");
			 return;
		  }
		  else
		  {
			 var xml=objOutTerminals.responseXML;
			 var dsRoot=xml.documentElement.getElementsByTagName("OutTerminals");  
			 var totalRec = dsRoot.length;
             var newOptSelect = new Option('-Select-','-Select-',  false, false);
             document.getElementById('ctl00_CP_Transaction_ddlOutTerminals').options[0]=newOptSelect;
                        
             for(i=0; i<totalRec; i++)
             {
                var Value = xml.getElementsByTagName("Reader_Id")[i];
                var TerminalId=xml.getElementsByTagName("Terminal_ReaderID")[i];
                var newOpt=new Option(TerminalId.text,Value.text);
                        
                document.getElementById('ctl00_CP_Transaction_ddlOutTerminals').options[i+1]=newOpt;
             }
             document.getElementById('ctl00_CP_Transaction_ddlOutTerminals').focus();
           }
      }
      else
      {
	    alert("Error in retriving details");
      }
   }
}


 function FillInTerminalHidden()
 {
    var InTerminal;
    
    var InTerminalSelectedIndex = document.aspnetForm.ctl00_CP_Transaction_ddlInTerminals.selectedIndex;
    InTerminal = document.aspnetForm.ctl00_CP_Transaction_ddlInTerminals.options[InTerminalSelectedIndex].value;
    document.aspnetForm.ctl00_CP_Transaction_hdn_InTerminal.value = InTerminal;  
 }
 
 
  function FillOutTerminalHidden()
 {
    var OutTerminal;
    
    var OutTerminalSelectedIndex = document.aspnetForm.ctl00_CP_Transaction_ddlOutTerminals.selectedIndex;
    OutTerminal = document.aspnetForm.ctl00_CP_Transaction_ddlOutTerminals.options[OutTerminalSelectedIndex].value;
    document.aspnetForm.ctl00_CP_Transaction_hdn_OutTerminal.value = OutTerminal;  
 }