function GetXmlHttpObject()
{ var xmlHttp=null;
  try
    { xmlHttp=new XMLHttpRequest(); }
  catch (e)
    { try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
    	catch (e) 
    		{ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
    }
  return xmlHttp;
};


/*
var xmlHttp = GetXmlHttpObject()

function stateChanged() { 
		if (xmlHttp.readyState==4)
			{
				#de facut 
			}
	};
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",link,true);
    xmlHttp.send(null);
  
*/


function Save(id) {
	
	var nume = document.getElementById("nume").value;
	var prenume = document.getElementById("prenume").value;
	var email = document.getElementById("email").value;

	var link = "includes/edit.account.php?id=" + id + "&nume=" + nume + "&prenume=" + prenume + "&email=" + email + "&x=" + Math.random();
	//alert (link);
	var xmlHttp = GetXmlHttpObject()

	function stateChanged() { 
		if (xmlHttp.readyState==4)
			{
				document.location.reload(); 
			}
	};
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",link,true);
    xmlHttp.send(null);


};

function Undo() {
	document.location.reload(); 

};




function popup(type, content) {
	wnd=window.open('','name','height=600,width=600');
	var tmp = wnd.document;
	tmp.write('<html><head><title>TITLU</title><head>');
	tmp.write('<body>');
	if (type == 1) {
		tmp.write('<img src=\"' + content + '\"');
	};
	
	if (type == 2) {
		tmp.write('<p>' + content + '</p>');
	};

	
	tmp.write('<br /><a href="javascript:self.close()">close</a> the popup.</p>');
	tmp.write('</body></html>');
	tmp.close();
};


function change_pass(id) {
//alert(id);
var raspuns=confirm("Are you sure you  want to change your password?");
if (raspuns==true)
  {
  
  	var parola_veche=prompt("Please enter your current password","Type here...");
  	//alert (parola_veche);
	if (parola_veche!=null  && parola_veche!="Type here...")
  		{
  			var link = "includes/check.pass.php?pass=" + parola_veche + "&id=" + id + "&x=" + Math.random();
  			//alert(link);
  			var xmlHttp = GetXmlHttpObject();
  			function stateChanged() { 
				if (xmlHttp.readyState==4)
					{
						q = xmlHttp.responseText;
						//alert (q);
						if (q == "OK") {
							var parola_noua = prompt("Please enter the new password","Type here...");
							if (parola_noua!=null && parola_noua!="" && parola_noua!="Type here...")
							{
								schimba_parola(id, parola_noua);
							}
							else
							{
								alert("Invalid input!");
							};
						}
						else
							{
								alert("Sorry, the password you entered is not valid!");
							}; 
					};
			};
			xmlHttp.onreadystatechange=stateChanged;
			xmlHttp.open("GET",link,true);
    		xmlHttp.send(null);
  		}
  	else
  		{
  			
  			alert("Invalid/incorrect input. Try again!");
  		};
  
  };
};

function schimba_parola(id, pass) {
	//alert("parola:" + pass);
	var xmlHttp = GetXmlHttpObject();
	var link = "includes/usr.change.pass.php?key=" + pass + "&id=" + id + "&x=" + Math.random();
	function stateChanged() { 
		if (xmlHttp.readyState==4)
			{
				var answ = xmlHttp.responseText;
				switch (answ) {
					case "OK": alert("The password has been changed.");break;
					case "NOTOK":alert("Pasword could not be saved. Try again later. if the problem persists, contact the webmaster");break;
				}; 
			}
	};
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",link,true);
    xmlHttp.send(null);


};








