function getHTTPObject(){
	var xmlhttp;
	// Attempt to initialize xmlhttp object
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
    catch (e) {
		// Try to use different activex object
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (E) {
			xmlhttp = false;
		}
	}
	// If not initialized, create XMLHttpRequest object
	if (!xmlhttp) {
		if (typeof XMLHttpRequest != 'undefined') {
			xmlhttp = new XMLHttpRequest();
		}
		else {
			alert("This browser does not support AJAX.");
			return null;
		}
	}
	return xmlhttp;
}

function checkFormOferta(){
	hashpos = document.location.href.indexOf('#');
	if (hashpos == -1)
		document.location.href = document.location.href + '#';
	else
		document.location.href = document.location.href.substring(0, hashpos) + "#";
	
	var msg = "";

	
	with (document.cere_oferta) {
		/*alte campuri*/	
		if (firma.value == "" || pers_contact.value=="" || email.value == "" || telefon.value=="")
			msg = "Campurile marcate cu * sunt obligatorii.<br/>";
		
		if (email.value != "")
			if (!isEmail(email.value) )
				msg += "Adresa de e-mail nu este corecta.<br/>";
	}
	
	if (msg != "") {
		document.getElementById('erori').innerHTML = msg;
		document.getElementById('erori').style.display = "block";
		document.getElementById('erori').className='error';
		return false;
	}
	return true;
}

function setOutput() {
	if (httpObject.readyState == 4) {
		document.getElementById('tabel_oferta').innerHTML += httpObject.responseText;
	}			
}

function adauga_produs3() {
	httpObject = getHTTPObject();
	if (httpObject != null) {
		httpObject.open("GET", "/rud/adauga_rand_tabel", true);
		httpObject.onreadystatechange = setOutput;	
		httpObject.send(null);
	}
}

function adauga_produs2() {
	httpObject = getHTTPObject();
	if (httpObject != null) {
		httpObject.open("POST", "/rud/adauga_rand_tabel", true);
		httpObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		httpObject.setRequestHeader("Connection", "close");
		httpObject.onreadystatechange = setOutput;
		
		params = new Array();
		with (document.cere_oferta) {
			alert(encodeURIComponent(cod[0].value));
			params[params.length] = "width=" + encodeURIComponent(width.value);
			params[params.length] = "height=" + encodeURIComponent(document.getElementById('widget').offsetHeight);
		}		
		httpObject.send(params.join('&'));	
		//httpObject.send(null);

	}
}
