// JavaScript Document

function getloclist(str)
{

var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
      document.getElementById("loclist").innerHTML=xmlHttp.responseText;
      }
	 if(xmlHttp.readyState==1||xmlHttp.readyState==2||xmlHttp.readyState==3)
	 {
		 document.getElementById("loclist").innerHTML="<img src='images/icon_circle.gif' alt='' hspace='40'/>";
	 }
    }
	var url="location.php?cid="+str
	
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
  }
  
//get location list for user  
function getlocationlist(str)
{

var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
      document.getElementById("loclist").innerHTML=xmlHttp.responseText;
      }
	 if(xmlHttp.readyState==1||xmlHttp.readyState==2||xmlHttp.readyState==3)
	 {
		 document.getElementById("loclist").innerHTML="<img src='images/icon_circle.gif' alt='' hspace='40'/>";
	 }
    }
	var url="user.php?cid="+str+"&type=loc";
	
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
  }
  
  //get location list for user  
function getlocationlist_with_id(str,divid)
{

var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
      document.getElementById(divid).innerHTML=xmlHttp.responseText;
      }
	 if(xmlHttp.readyState==1||xmlHttp.readyState==2||xmlHttp.readyState==3)
	 {
		 document.getElementById(divid).innerHTML="<img src='images/icon_circle.gif' alt='' hspace='40'/>";
	 }
    }
	var url="user-2.php?cid="+str+"&type=loc&did="+divid;
	
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}
  
//get building list  
function getbuildlist(str)
{

var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
      document.getElementById("buildlist").innerHTML=xmlHttp.responseText;
      }
	 if(xmlHttp.readyState==1||xmlHttp.readyState==2||xmlHttp.readyState==3)
	 {
		 document.getElementById("buildlist").innerHTML="<div align='center'>Loading...<div>";
	 }
    }
	var url="user.php?lid="+str+"&type=build";

  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
  }
  
//get building list  
function getbuildlist_with_id(str,divid)
{

var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
      document.getElementById(divid).innerHTML=xmlHttp.responseText;
      }
	 if(xmlHttp.readyState==1||xmlHttp.readyState==2||xmlHttp.readyState==3)
	 {
		 document.getElementById(divid).innerHTML="<div align='center'>Loading...<div>";
	 }
    }
	var url="user-2.php?lid="+str+"&type=build&did="+divid;

  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function add_company_new(str)
{

var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
      //document.getElementById('comp_list').innerHTML = xmlHttp.responseText;
	  //sttt = xmlHttp.responseText;
	  document.getElementById('comp_list').insertAdjacentHTML('beforeEnd',xmlHttp.responseText);
      }
	 if(xmlHttp.readyState==1||xmlHttp.readyState==2||xmlHttp.readyState==3)
	 {
		 //document.getElementById('comp_list').innerHTML+="<div align='center'>Loading...<div>";
	 }
    }
	var url="user-mnus.php?id="+str;

  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function delete_company_from_user(uid,cid)
{

var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
      document.getElementById('comp_list').innerHTML = xmlHttp.responseText;
	  //sttt = xmlHttp.responseText;
	  //document.getElementById('comp_list').insertAdjacentHTML('beforeEnd',xmlHttp.responseText);
      }
	 if(xmlHttp.readyState==1||xmlHttp.readyState==2||xmlHttp.readyState==3)
	 {
		 document.getElementById('comp_list').innerHTML+="<div align='center'>Loading...<div>";
	 }
    }
	var url="user-mnus-del.php?uid="+uid+"&cid="+cid;

  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}
  
 //check validity of username 
  function chkuser(str)
{

var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
      document.getElementById("chkusername").innerHTML=xmlHttp.responseText;
      }
	 if(xmlHttp.readyState==1||xmlHttp.readyState==2||xmlHttp.readyState==3)
	 {
		 document.getElementById("chkusername").innerHTML="<img src='images/icon_circle.gif' alt='' hspace='40'/>";
	 }
    }
	var url="brand.php?action=chkuser&cid="+str
	
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
  }
   //check validity of companyref,locationref,buildingref 
  function chkcmnyref(str,reftype,id,lid)
{

var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
      document.getElementById("chkusername").innerHTML=xmlHttp.responseText;
      }
	 if(xmlHttp.readyState==1||xmlHttp.readyState==2||xmlHttp.readyState==3)
	 {
		 document.getElementById("chkusername").innerHTML="<img src='images/icon_circle.gif' alt='' hspace='10'/>";
	 }
    }
	var url="refno.php?reftype="+reftype+"&id="+id+"&lid="+lid+"&cid="+str
	
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
  }
 //hide error lable. 
   function hidetag(name)
{

var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
      document.getElementById('errormsg').innerHTML=xmlHttp.responseText;
      }
	 if(xmlHttp.readyState==1||xmlHttp.readyState==2||xmlHttp.readyState==3)
	 {
		 document.getElementById('errormsg').innerHTML="";
	 }
    }
		var url="login.php?action=hide&name="+name;
	
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
  }

