// JScript File

var objExchange;
var type;

function EmpName_Exchange(type1)
{

type=type1;

	try
	{
		objExchange = new XmlHttpRequest();
	}
	catch(e)
	{
		try
		{
			objExchange = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e1)
		{
			objExchange = new ActiveXObject("Msxml2.XMLHTTP");
		}
	}
	
	if(objExchange != null)
	{
	
	if (type=='1')
	{
	var EmpId=document.getElementById('ctl00_CP_Transaction_txt_Ecode1').value;
	
	document.getElementById('ctl00_CP_Transaction_txt_E1ActualShift').value="";
    document.getElementById('ctl00_CP_Transaction_txt_E1Date').value="";
	
	if(EmpId == "")
		{
		    var empty="";
		    document.getElementById('ctl00_CP_Transaction_txt_Emp1Name').value=empty;
		    return false;
		    //document.getElementById('ctl00_CP_Transaction_txt_Ecode1').focus();
		} 
	else
		{
		    var k=Math.floor(Math.random()*111);
		  
		    objExchange.onreadystatechange = ProcessTheResponseShiftExchange_EmpName;		
		    objExchange.open("GET","EmployeeName.aspx?EmpId=" + EmpId + "&k"  + k,true)
		    objExchange.send(null);
		}
	
	}
	if (type=='2')
	{
	var EmpId=document.getElementById('ctl00_CP_Transaction_txt_Ecode2').value;
	document.getElementById('ctl00_CP_Transaction_txt_E2ActualShift').value="";
	document.getElementById('ctl00_CP_Transaction_txt_E2Date2').value="";
	if(EmpId == "")
		{
		    var empty="";
		    document.getElementById('ctl00_CP_Transaction_txt_Emp2Name').value=empty;
		    return false;
		    //document.getElementById('ctl00_CP_Transaction_txt_Ecode2').focus();
		} 
	else
		{
		    var k=Math.floor(Math.random()*111);
		  
		    objExchange.onreadystatechange = ProcessTheResponseShiftExchange_EmpName;		
		    objExchange.open("GET","EmployeeName.aspx?EmpId=" + EmpId + "&k"  + k,true)
		    objExchange.send(null);
		}
	}
		
		
		
		
	}
	return false;
}


function ProcessTheResponseShiftExchange_EmpName()
{ 
	if (objExchange.readyState == 4)
	{
		if(objExchange.status == 200)
		{
          var response=objExchange.responseText;
          
          if (type=='1')
          {
              if(response=="Invalid EmployeeCode")
              {
                var emp="";
                
                document.getElementById('ctl00_CP_Transaction_txt_Emp1Name').value=response;
                document.getElementById('ctl00_CP_Transaction_txt_Ecode1').value=emp;
                document.getElementById('ctl00_CP_Transaction_txt_Ecode1').focus();
              }
              else
              { 
                document.getElementById('ctl00_CP_Transaction_txt_Emp1Name').value=response;
              }
          }
          
          if (type=='2')
          {
              if(response=="Invalid EmployeeCode")
              {
                var emp="";
                
                document.getElementById('ctl00_CP_Transaction_txt_Emp2Name').value=response;
                document.getElementById('ctl00_CP_Transaction_txt_Ecode2').value=emp;
                document.getElementById('ctl00_CP_Transaction_txt_Ecode2').focus();
              }
              else
              { 
                document.getElementById('ctl00_CP_Transaction_txt_Emp2Name').value=response;
              }
          }
          
		}
	}
}

