var aHtml=Array();

function makeRequest(id_tag, url, img_name, parameters){
	
	if(url) url+=((url.indexOf('?')==-1) ? '?' : '&')+'js_time='+new Date().getTime();
	//alert(url);
	if(!img_name) img_name="loader_alb.gif";
	//alert(url);
	if(!document.getElementById || !document.getElementById(id_tag)){
		window.location.href=url+'&js_get_pg=';
		return false;		
	}
	
	//memorez contentul tag-ului pentru o eventuala refacere ulterioara (si celalalt buton "comanda" daca exista 2 butoane comanda al aceluiasi produs (vezi pagina detalii produs))
	aHtml[id_tag]=document.getElementById(id_tag).innerHTML;
	
	
	document.getElementById(id_tag).innerHTML=((img_name.indexOf(' ')!=-1) ? img_name : "<center><img src=images/"+img_name+"></center>");
	
	var http_request = false;

	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
			// See note below about this line
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			//try { 
			http_request = new ActiveXObject("Microsoft.XMLHTTP"); 
			//} catch (e) {}
		}
	}
	
	if (!http_request) {
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}
	http_request.onreadystatechange = function() { alertContents(id_tag, http_request, url); };
	//http_request.open('GET', url, true);
	//http_request.send(null);
	
	http_request.open((parameters ? 'POST' : 'GET'), url, true);
	if(parameters){
	  http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	  http_request.setRequestHeader("Content-length", parameters.length);
	  http_request.setRequestHeader("Connection", "close");
	}else parameters=null;
	http_request.send(parameters);	
	
	return false;

}

function alertContents(id_tag, http_request, url) {

	if (http_request.readyState == 4) 
	{
		if (http_request.status == 200)
		{			
			document.getElementById(id_tag).innerHTML = http_request.responseText;
			if (id_tag == "alegeEchipa")
			{
				calculeazaEchipa();
				var ob;
				//alert(document.getElementById("EchipaAsezareId").selectedIndex);
				//alert(document.getElementById("hiddenasezare").value);
				if (ob = document.getElementById("hiddenasezare"))
					document.getElementById("EchipaAsezareId").selectedIndex = parseInt(document.getElementById("hiddenasezare").value) - 1;
			}
		} 
		else 
		{
			window.location.href=url+'&js_get_pg=';
			//alert('There was a problem with the request.');
		}
	}

}

function on_off_tag(id_tag, arata){
	if(!document.getElementById || !document.getElementById(id_tag)) return false;
	//if(arata==null) arata=(document.getElementById(id_tag).style.visibility=='hidden');
	if(arata==null) arata=(document.getElementById(id_tag).style.display=='none');
	try{
		//document.getElementById(id_tag).style.visibility=(arata ? '' : 'hidden');
		//if(!arata) aTAG[id_tag]=document.getElementById(id_tag).innerHTML;
		//document.getElementById(id_tag).innerHTML=(arata ? (aTAG[id_tag] ? aTAG[id_tag] : '.') : '');		
		//document.getElementById(id_tag).style.visibility=(arata ? '' : 'hidden');
		//document.getElementById(id_tag).style.position=(arata ? '' : 'absolute');
		document.getElementById(id_tag).style.display=(arata ? '' : 'none');
	}catch(e){ }
}

function get_var(variable, url) {
  var query = (url==null) ? window.location.search.substring(1) : url.substring(url.indexOf('?')+1);
  var vars = query.split("&"), ret='';
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable)  ret=pair[1];    
  } 
  return ret;
}

function get(frm){
  var sget='', n=null, v=null;
  //alert('ajx');
  if(!frm || !frm.length) return '';
  for(i=0; i<frm.length; i++) if((n=frm.elements[i].name) && ((v=frm.elements[i].value) || (v=='')))
  	sget+=(sget ? '&' : '')+n+'='+encodeURI(v);
  //alert(sget);
  return sget;
}