// JScript File
var objExchange;
var type;
function EmpName_Exchange(type1,SelectCompany,Shiftnotallocated)
{
type=type1;
       if(window.ActiveXObject)
        {    
	        try
	        {
		        objExchange = new ActiveXObject("Msxml2.XMLHTTP");
	        }
	        catch(e)
	        {
		        try
		        {
			        objExchange = new ActiveXObject("Microsoft.XMLHTTP");
		        }
		        catch(e1)
		        {
			        objExchange = null;
		        }
	        }
        }  
         else if(window.XMLHttpRequest)
         {
	        try
	        {
		        objExchange = new XMLHttpRequest("Msxml2.XMLHTTP");
	        }
	        catch(e)
	        {
		        try
		        {
			        objExchange = new XMLHttpRequest("Microsoft.XMLHTTP");
		        }
		        catch(e1)
		        {
			        objExchange = null;
		        }
	        }
        }
//	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_BodyContentPH_txt_Ecode1').value;
	document.getElementById('ctl00_BodyContentPH_txt_E1ActualShift').value="";
    //document.getElementById('ctl00_BodyContentPH_txt_E1Date').value="";
	if(EmpId == "")
		{
		    var empty="";
		    document.getElementById('ctl00_BodyContentPH_txt_Emp1Name').value=empty;
		    return false;
		    //document.getElementById('ctl00_BodyContentPH_txt_Ecode1').focus();
		} 
	else
		{
		    var LevelId;
	        if(document.getElementById('ctl00_BodyContentPH_ddlCompany').value!="0")
	        {
	            LevelId=document.getElementById('ctl00_BodyContentPH_ddlCompany').value;
	        }
	        else
	        {
	           //alert("Select Company"); 
	           alert(SelectCompany); 
	            return;
	        }
		    var k=Math.floor(Math.random()*111);
		    if(window.ActiveXObject)
            {
		        objExchange.onreadystatechange = ProcessTheResponseShiftExchange_EmpName;		
		        objExchange.open("GET","EmployeeName.aspx?EmpId=" + EmpId + "&LevelId="  + LevelId + "&k="  + k,true)
		        objExchange.send(null);
		    }
		    else if(window.XMLHttpRequest)
            {
		         objExchange.open("GET","EmployeeName.aspx?EmpId=" + EmpId + "&LevelId="  + LevelId + "&k="  + k,false)
		         objExchange.send(null);
		         objExchange.onreadystatechange = ProcessTheResponseShiftExchange_EmpName();		
            }
		}
	}
	if (type=='2')
	{
	var EmpId=document.getElementById('ctl00_BodyContentPH_txt_Ecode2').value;
	document.getElementById('ctl00_BodyContentPH_txt_E2ActualShift').value="";
	//document.getElementById('ctl00_BodyContentPH_txt_E1Date').value="";
	if(EmpId == "")
		{
		    var empty="";
		    document.getElementById('ctl00_BodyContentPH_txt_Emp2Name').value=empty;
		    return false;
		    //document.getElementById('ctl00_BodyContentPH_txt_Ecode2').focus();
		} 
	else
		{
		    var LevelId;
	        if(document.getElementById('ctl00_BodyContentPH_ddlCompany').value!="0")
	        {
	            LevelId=document.getElementById('ctl00_BodyContentPH_ddlCompany').value;
	        }
	        else
	        {
	            //alert("Select Company");
	            alert(SelectCompany);
	            return;
	        }
		    var k=Math.floor(Math.random()*111);
		    if(window.ActiveXObject)
		    {
		        objExchange.onreadystatechange = ProcessTheResponseShiftExchange_EmpName;		
		        objExchange.open("GET","EmployeeName.aspx?EmpId=" + EmpId + "&LevelId="  + LevelId + "&k="  + k,true)
		        objExchange.send(null);
		    }
		    else if(window.XMLHttpRequest)
		    {
		        objExchange.open("GET","EmployeeName.aspx?EmpId=" + EmpId + "&LevelId="  + LevelId + "&k="  + k,false)
		        objExchange.send(null);
		        objExchange.onreadystatechange = ProcessTheResponseShiftExchange_EmpName();		
		    }
		}
	}
	}
	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_BodyContentPH_txt_Emp1Name').value=response;
                     document.getElementById('ctl00_BodyContentPH_txt_Ecode1').value=emp;
                     document.getElementById('ctl00_BodyContentPH_txt_Ecode1').focus();
                     }
              else
              { 
               //Added by MAnjula.P on 13-Mar-2014 for getting employee name only in shift exchange
                var empDetails = response.split(',');
                document.getElementById('ctl00_BodyContentPH_txt_Emp1Name').value=empDetails[0];
                 //*************************
                ShiftExchange1(Shiftnotallocated);
              }
          }
          if (type=='2')
          {
              if(response=="Invalid EmployeeCode")
              {
                var emp="";
                document.getElementById('ctl00_BodyContentPH_txt_Emp2Name').value=response;
                document.getElementById('ctl00_BodyContentPH_txt_Ecode2').value=emp;
                document.getElementById('ctl00_BodyContentPH_txt_Ecode2').focus();
              }
              else
              { 
                //Added by MAnjula.P on 13-Mar-2014 for getting employee name only in shift exchange
                var empDetails = response.split(',');
                document.getElementById('ctl00_BodyContentPH_txt_Emp2Name').value=empDetails[0];
                //*************************
                ShiftExchange2(Shiftnotallocated);
              }
          }
		}
	}
}
