var xmlhttp;

function loadPage(){
  try{
    document.getElementById('waiting').style.display='none';
    getLastJob();
  }catch(e){}
  return true;
}

function fromFormToXML(frmToXML){
  try{
    var oDom = _DOMcreateDoc();
    var nRoot = oDom.createElement("root");
    var nodeTable = oDom.createElement("table");
    nodeTable.setAttribute("tablename", "account");
    nodeTable.setAttribute("statement", "select");

    nRoot.appendChild(nodeTable);
    oDom.appendChild(nRoot);
  }catch(e){}

//  var serialized;
//  serializer = new XMLSerializer();
//  serialized = serializer.serializeToString(oDom);
//  alert(serialized);

//  alert(oDom.xml);

  return oDom;
}

function checkForm(frmCheck){
  try{
    alert("CHECK");
  }catch(e){}
  return true;
}

function getLastJob(){
  try{
    var xmlIn = fromFormToXML('none');

    xmlhttp = _HTTPrequestId();
    if (xmlhttp!=null){
      SendAsync(xmlhttp,"POST","/lib/lavoro_small.aspx",xmlIn,getLoginDone,getLoginFault,getLoginWait);
    }
    else{
      alert("Your browser does not support XMLHTTP.");
    }
  }catch(e){}
  return true;
}

function getLoginDone(responseText){
// DONE
  try{
    document.getElementById('waiting').style.display='none';
//  responseText=responseText.replace('<?xml version=\"1.0\"?>','');
//  responseText='<?xml version=\"1.0\"?>'+responseText;
//  alert("Response HttpRequest - "+responseText);

  var xmlDocResp=_DOMparseDoc(responseText);
  var x=xmlDocResp.documentElement.childNodes;
  var lastJob;
  lastJob='';
  for (i=0;i<x.length;i++){
    if (x[i].nodeType==1){//Process only element nodes (type 1) 
//  document.write(x[i].nodeName);
      jJobID=xmlDocResp.getElementsByTagName("jobid")[i].childNodes[0];
      jTitle=xmlDocResp.getElementsByTagName("title")[i].childNodes[0];
      jDate=xmlDocResp.getElementsByTagName("date")[i].childNodes[0];
      lastJob=lastJob+'<p><a href="/lavoro/lavoro.aspx?id='+jJobID.nodeValue+'">'+jTitle.nodeValue+'</a></p>';
    }
  }
  document.getElementById("lastjob").innerHTML=lastJob;

//    if (xmlDocResp.documentElement.firstChild.firstChild.nodeValue=="0"){
//      self.location.href = "/aziende/pdc.aspx";
//    }else{
//      self.location.href = "/en/message.html?topic=contacts&issue=unsuccess";
//    }
  }catch(e){}
  return true;
}

function getLoginWait(readyState){
// WAIT
  try{
    document.getElementById('waiting').style.display='block';
  }catch(e){}
  return true;
}

function getLoginFault(statusText){
// FAULT
  try{
    document.getElementById('waiting').style.display='none';
    alert('Error HttpRequest - '+statusText);
  }catch(e){}
  return true;
}

