	function getAJAX() {
		var page_request = false;
		if (window.XMLHttpRequest){
			page_request = new XMLHttpRequest();
			return page_request;
		}
		else if (window.ActiveXObject){
			try {
				page_request = new ActiveXObject("Msxml2.XMLHTTP");
				return page_request;
			}catch (e){
				try{
					page_request = new ActiveXObject("Microsoft.XMLHTTP");
					return page_request;
				}catch (e){
					return false;
				}
			}
		}else{
			return false;
		}
	}
	function openProdus(id) {
		var ajax = getAJAX();
		var url = "/ajax/";
		ajax.onreadystatechange = function() {
			if (ajax.readyState == 4 && (ajax.status == 200 || window.location.href.indexOf("http") == -1)) {
				var response = ajax.responseText;
				var div = document.getElementById('detalii-produs-' + id);
				div.style.display = 'block';
				div.innerHTML = response;
				var img = document.getElementById('detalii-produs-switch-' + id);
				img.setAttribute('src', '/img/close.jpg');
				img.onclick = new Function('closeProdus(' + id + ')');
			}
		}
		params = "detalii=" + id;
		ajax.open('POST', url, true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
		ajax.setRequestHeader("Content-length", params.length);
		ajax.setRequestHeader("Connection", "close");
		ajax.send(params);
	}
	function closeProdus(id) {
		var div = document.getElementById('detalii-produs-' + id);
		div.style.display = 'none';
		var img = document.getElementById('detalii-produs-switch-' + id);
		img.setAttribute('src', '/img/open.jpg');
		img.onclick = new Function('openProdus(' + id + ')');
	}
	function proforma() {
		var ajax = getAJAX();
		var url = "/ajax/";
		var campuri = {0:'nume', 1:'adresa', 2:'localitate', 3:'zip', 4:'telefon', 5:'email', 6:'cnp', 7:'firma', 8:'cui', 9:'reg', 10:'banca', 11:'cont', 12:'modplata', 13:'persoana'};
		var formular = {};
		for (idx in campuri) {
			var camp = campuri[idx];
			var inp = document.getElementById('client_' + camp);
			formular[camp] = inp.value;
			var sel = document.getElementById('client_judet');
			formular['judet'] = (sel.options[sel.selectedIndex]).value;
		}
		ajax.onreadystatechange = function() {
			if (ajax.readyState == 4 && (ajax.status == 200 || window.location.href.indexOf("http") == -1)) {
				var response = ajax.responseText;
				if (response == '1') {
					popupfactura();
				}
			}
		}
		params = "proforma=set";
		for (camp in formular) {
			params += "&client_" + camp + "=" + formular[camp];
		}
		ajax.open('POST', url, true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
		ajax.setRequestHeader("Content-length", params.length);
		ajax.setRequestHeader("Connection", "close");
		ajax.send(params);
	}
	function popupfactura() {
		window.open( "http://www.buytel.ro/factura/", "Proforma", "status = 1, screenx = 10, screeny = 10, height = 650, width = 680, resizable = 1" )
	}
