var xmlHttp

function gravar(cartao)
{ 
 if(cartao!='')
 {
  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null)
  {
   alert ("Seu browser não tem suporte para AJAX!");
   return;
  } 
  var url="gravarPonto.php";
  url=url+"?cartao="+cartao;
  url=url+"&sid="+Math.random();
  xmlHttp.onreadystatechange=stateChanged;
  xmlHttp.open("GET",url,true);
  //xmlhttp.setrequestheader "ContentType","text/xml";
  xmlHttp.send(null);
 }
}

function stateChanged() 
{ 
 //if (xmlHttp.readyState==4)
 document.getElementById("txtStatus").innerHTML = "<font size='2' face='verdana' color='blue'>Aguarde, buscando informações do Funcionário...</font>";
 if(checkReadyState(xmlHttp))
 { 
   var response = xmlHttp.responseText;
   temp1 = response.replace("ï»¿","",response);
   //alert(temp1);
   eval(temp1);
   if(Funcionario.length > 0)
   {
    if(Funcionario[0].tipo=='S')
    {
     var tipo = "Saída";
    }
    else
    {
     var tipo = "Entrada";
    }
    //document.getElementById("txtStatus").style.font.color ='green';
    document.getElementById("txtStatus").innerHTML= "<font size='2' face='verdana' color='blue'>Ponto Marcado - </font><font size='3' face='verdana' color='green'>"+tipo+"</font>";
    document.getElementById("digitado").value    = "";
    document.getElementById("numero").innerHTML  = "<font size='2' face='verdana' color='blue'>"+Funcionario[0].cartao+"</font>";
    document.getElementById("nome").innerHTML    = "<font size='2' face='verdana' color='blue'>"+Funcionario[0].nome+"</font>";
    document.getElementById("data").innerHTML    = "<font size='2' face='verdana' color='blue'>"+Funcionario[0].data+"</font>";
    document.getElementById("hora").innerHTML    = "<font size='2' face='verdana' color='blue'>"+Funcionario[0].hora+"</font>";
    habilitar(true);
   }
   else
   {
    document.getElementById("txtStatus").innerHTML = "<font size='2' face='verdana' color='red'>Funcionário não Cadastrado !</font>";
    habilitar(false);     
   }
 }
}

function habilitar(bSim)
{
   document.getElementById("digitado").value = "";
   document.getElementById("digitado").focus();
   document.getElementById("digitado").select();
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function checkReadyState(obj)
{
  if(obj.readyState == 4)
  {
    if(obj.status == 200)
    {
      return true;
    }
    else
    {
      alert("Problem retrieving XML data");
    }
  }
}

