function creazaXmlHttp(){
	var xmlHttp;
	if(window.ActiveXObject){
		try{
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e){
			xmlHttp = false;
		}
	}
	else{
		try{
			xmlHttp = new XMLHttpRequest();
		}
		catch (e){
			xmlHttp = false;
		}
	}
	if (!xmlHttp) alert("Nu s-a putut crea obiectul XMLHttpRequest .");
	else return xmlHttp;
}

function $val(a){
	try{
		return document.getElementById(a).value;
	}
	catch(e){
		alert('Elementul '+a+' nu poate fi gasit reporniti browserul si incercati din nou');
		return false;
	}
}

function $v(a,v){
	try{
		document.getElementById(a).value=v;
		return true;
	}
	catch(e){
		alert('Elementul '+a+' nu poate fi gasit reporniti browserul si incercati din nou');
		return false;
	}
}
function $html(a,v){
	try{
		document.getElementById(a).innerHTML=v;
		return true;
	}
	catch(e){
		alert('Elementul '+a+' nu poate fi gasit reporniti browserul si incercati din nou');
		return false;
	}
}


function $id(a){
	var rez;
	try{
		rez=document.getElementById(a);
		return rez;
	}
	catch(e){
		alert('Elementul '+a+' nu poate fi gasit reporniti browserul si incercati din nou');
		return false;
	}
}


var xmainpath='images/';
var xmlHttp=creazaXmlHttp();
function Ejax(phpfile,params,divelem){
	if(divelem!=''){
		var xdiv=$id(divelem);
		var dispwait=true;
	}
	else {
		var xdiv='';
		var dispwait=false;
	}
	this.phppath=phpfile;
	var xphp=this.phppath;
	if(params!=''){
		var xparam='?'+params+"&sid="+Math.random();
	}
	else{
		var xparam="?sid="+Math.random();
	}
	this.cerere=function(){
		if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0){
			xmlHttp.open("GET", xphp+xparam, true);
				xmlHttp.onreadystatechange = xrez;
				xmlHttp.send(null);
				if(dispwait){
					xdiv.innerHTML= '<img src="'+xmainpath+'wait.gif'+'" width=25 height=25>'+'PLEASE WAIT!!!';
				}
		}
		else{
			if(dispwait){
				xdiv.innerHTML= '<img src="'+xmainpath+'wait.gif'+'" width=25 height=25>'+'PLEASE WAIT!!!';
			}
			
		}
	};
	var xcer=this.cerere;
	this.rezultat=function(){
		if (xmlHttp.readyState == 4){
			if (xmlHttp.status == 200){
				var raspuns = xmlHttp.responseText;
				if(xdiv==''){
					alert(raspuns);
				}
				else{
					xdiv.innerHTML =  raspuns;
				}
			}
			else{
				alert("Problema la accesare: " +xmlHttp.statusText);
			}
		}
		else{
			if(dispwait){
				//xdiv.innerHTML= '<img src="'+xmainpath+'wait.gif'+'" width=25 height=25>'+'PLEASE WAIT!!!';
			}
			
		}
	};
	var xrez=this.rezultat;
	xcer();
	
}
function Ejaxw(phpfile,params,titlu,overdiv){
	if (overdiv==null) overdiv='overdiv';
	var	xdiv= '<img src="'+xmainpath+'wait.gif'+'"><br>'+'PLEASE WAIT!!!';
	this.phppath=phpfile;
	var xphp=this.phppath;
	if(params!=''){
		var xparam='?'+params+"&sid="+Math.random();
	}
	else{
		var xparam="?sid="+Math.random();
	}
	this.cerere=function(){
		if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0){
			xmlHttp.open("GET", xphp+xparam, true);
				xmlHttp.onreadystatechange = xrez;
				xmlHttp.send(null);
		}
		else{
			ewindow(titlu,xdiv,overdiv);
			
		}
	};
	var xcer=this.cerere;
	this.rezultat=function(){
		if (xmlHttp.readyState == 4){
			if (xmlHttp.status == 200){
				var raspuns = xmlHttp.responseText;
				ewindow(titlu,raspuns,overdiv);
			}
			else{
				alert("Problema la accesare: " +xmlHttp.statusText);
			}
		}
	};
	var xrez=this.rezultat;
	xcer();
	
}


function addsel(elemid,msg){
	var name=prompt(msg,"")
  if (name!=null && name!=""){
    var x=$id(elemid);
	var y=document.createElement('option');
  	y.text=name;
  	try{
    x.add(y,null); // standards compliant
    }
  catch(ex){
    x.add(y); // IE only
    }
    var idx=x.length;
    x.selectedIndex=idx-1;
    }
    
}

function removesel(elemid){
	var x=$id(elemid);
	x.remove(x.selectedIndex);
}

function closeEw(overdiv){
	if (overdiv==null) overdiv='overdiv';
	$html(overdiv,'');
}

function ewindow(titlu,continut,overdiv){
	if (overdiv==null) overdiv='overdiv';
	var theHeight=getwh();
	var mtext='';
	mtext+='<div id="mwindow">';
	mtext+='<table height="100%" width="100%" cellpadding="0" cellspacing="0">';
	mtext+='<tr>';
	mtext+='<td valign="middle" align="center">';
	mtext+='<table style="filter:alpha(opacity=100);-moz-opacity:1;opacity:1;" cellpadding="0" cellspacing="0">';
	mtext+='<tr bgcolor="Blue">';
	mtext+='<td valign="middle" align="center" style="color:Yellow"><b>'+titlu+'</b></td>';
	mtext+='<td width="2"  align="rigth"><input type="button" value="x"  onclick="closeEw(\''+overdiv+'\');">';
	mtext+='</td>';
	mtext+='</tr>';
	mtext+='<tr bgcolor="White">';
	mtext+='<td colspan="2" height="80" >';
	mtext+=continut;
	mtext+='</td>';
	mtext+='</tr>';
	mtext+='</table>';
	mtext+='</td>';
	mtext+='</tr>';
	mtext+='</table>';
	mtext+='</div>';
	$html(overdiv,mtext);
	var mdiv=$id('mwindow');
	mdiv.style.height=theHeight;
}

function voption(a){
	var vrez=new Array;
	var i=0;
	for(i=0;i<a.length;i++){
		vrez.push(a.options[i].text);
	}
	return vrez;
}

function soption(a){
	var vrez=voption(a);
	var srez='';
	srez=vrez.join('|');
	return srez;
}

function getwh(){
	if (parseInt(navigator.appVersion)>3) {
 if (navigator.appName=="Netscape") {
  winW = window.innerWidth;
  winH = window.innerHeight;
 }
 if (navigator.appName.indexOf("Microsoft")!=-1) {
  winW = document.body.offsetWidth;
  winH = document.body.offsetHeight;
 }
}
	return winH;
}


function EjaxwR(phpfile,params,titlu,overdiv){
	if (overdiv==null) overdiv='overdiv';
	var	xdiv= '<img src="'+xmainpath+'wait.gif'+'"><br>'+'PLEASE WAIT!!!';
	this.phppath=phpfile;
	var xphp=this.phppath;
	if(params!=''){
		var xparam='?'+params+"&sid="+Math.random();
	}
	else{
		var xparam="?sid="+Math.random();
	}
	this.cerere=function(){
		if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0){
			xmlHttp.open("GET", xphp+xparam, true);
				xmlHttp.onreadystatechange = xrez;
				xmlHttp.send(null);
		}
		else{
			ewindow(titlu,xdiv,'1');
			
		}
	};
	var xcer=this.cerere;
	this.rezultat=function(){
		if (xmlHttp.readyState == 4){
			if (xmlHttp.status == 200){
				var raspuns = xmlHttp.responseText;
			
			 ewindowR(titlu,raspuns,overdiv);
			}
			else{
				alert("Problema la accesare: " +xmlHttp.statusText);
			}
		}
	};
	var xrez=this.rezultat;
	xcer();
	
}

function closeEwR(overdiv){
	if (overdiv==null) overdiv='overdiv';
	$html(overdiv,'');
	window.location.reload( false );
}

function ewindowR(titlu,continut,overdiv){
	if (overdiv==null) overdiv='overdiv';
	var theHeight=getwh();
	var mtext='';
	mtext+='<div id="mwindow">';
	mtext+='<table height="100%" width="100%" cellpadding="0" cellspacing="0">';
	mtext+='<tr>';
	mtext+='<td valign="middle" align="center">';
	mtext+='<table style="filter:alpha(opacity=100);-moz-opacity:1;opacity:1;" cellpadding="0" cellspacing="0">';
	mtext+='<tr bgcolor="Blue">';
	mtext+='<td valign="middle" align="center" style="color:Yellow"><b>'+titlu+'</b></td>';
	mtext+='<td width="2"  align="rigth"><input type="button" value="x"  onclick="closeEwR(\''+ overdiv+'\');">';
	mtext+='</td>';
	mtext+='</tr>';
	mtext+='<tr bgcolor="White">';
	mtext+='<td colspan="2" height="80" >';
	mtext+=continut;
	mtext+='</td>';
	mtext+='</tr>';
	mtext+='</table>';
	mtext+='</td>';
	mtext+='</tr>';
	mtext+='</table>';
	mtext+='</div>';
	$html(overdiv,mtext);
	var mdiv=$id('mwindow');
	mdiv.style.height=theHeight;
}
var xmlHttp_postcontact=creazaXmlHttp();
function postcontact(form) {
	var params='nume='+encodeURIComponent(form.nume.value)+'&prenume='+encodeURIComponent(form.prenume.value)+'&firma='+encodeURIComponent(form.prenume.value)+'&telefon='+encodeURIComponent(form.telefon.value)+'&email='+encodeURIComponent(form.email.value)+'&mesaj='+encodeURIComponent(form.mesaj.value);
	xmlHttp_postcontact.open("POST", form.action);
	xmlHttp_postcontact.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp_postcontact.setRequestHeader("Content-length", params.length);
	xmlHttp_postcontact.setRequestHeader("Connection", "close");
	xmlHttp_postcontact.onreadystatechange = function () {
		if (xmlHttp_postcontact.readyState == 4){
			document.getElementById('contact_posted').innerHTML=xmlHttp_postcontact.responseText;
			if (xmlHttp_postcontact.responseText=='Mesajul a fost trimis cu succes!<br />Va multumim!') {
				form.reset();
			}
		}
	}
	xmlHttp_postcontact.send(params);
	
}
function redirect(l,g) {
	var link=l;
	if (g!='') {
		var get='&'+g;
		window.location='index.php?action='+link+get;
	} else {
		window.location='index.php?action='+link;
	}
}