var http = getHTTPObject();
var xmlDoc;
//var url="http://localhost/consult/php/checuname.php";
var url="http://localhost/consult/php/checuname.php?uname=";
var firstNode;

function handleResponse() {
  if (http.readyState == 4) { // done
//	  document.getElementById("stLoading").style.display = 'none';
	  results = http.responseText;
	  loadXML(results);
	  handleResult();
  }
}

function clientAdd(frm) {
	if(echeck(frm.email.value)) {
		url_ = url + frm.email.value;
		http.open("GET", url_, true);
		if(http.readyState == 1) { // loading scheme
		//	document.getElementById("stLoading").innerHTML = "LOADING";
		//	document.getElementById("stLoading").style.display = 'block';
		}
		http.onreadystatechange = handleResponse;
		http.send(null);
	}
	else
		alert("Adresa Email nu este valida.");
	return false;
}

function programsAdd() {


	
	if(t == 2) {
		return true;
	}
	return false;
}
function handleResult() {
	//document.getElementById("uNameErr").innerHTML = firstNode.childNodes[1].childNodes[0].nodeValue;
	if(firstNode.childNodes[0].childNodes[0].nodeValue == 1) {
		var t = 0;
		t+=checkItem(document.forms[1].password, 'password');
		if(document.forms[1].password.value != document.forms[1].cpassword.value) {			
			setDVstyle("cpassword", "stFormCellTextError");
		}
		else {
			setDVstyle("cpassword", "stFormCellText");
			t++;
		}			
		t+=checkItem(document.forms[1].nume,'nume');
		t+=checkItem(document.forms[1].prenume,'prenume');
		if(t == 4)
			document.forms[1].submit();
		else
			return false;
		
	}
	else if(firstNode.childNodes[0].childNodes[0].nodeValue == 2) {
		document.getElementById("uNameErr").innerHTML = firstNode.childNodes[1].childNodes[0].nodeValue;
		document.forms[1].email.focus();
	}
//	val = firstNode.childNodes[0].childNodes[0].nodeValue;
//	document.getElementById("vacancyLink").href = "vacanciesfrm.html?vid=" + val;
}

function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}

function loadXML(str) {
	if (window.ActiveXObject) {
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async=false;
		xmlDoc.loadXML(str);
	//	getmessage();
	}
	else {
	  var parser=new DOMParser();
	  var xmlDoc=parser.parseFromString(str,"text/xml");
	}
	firstNode=xmlDoc.documentElement;
}