
var aHtml=Array();

function makeRequest(id_tag, url, img_name, parameters, exec_code_after){
	
	if(!img_name) img_name="te rugam sa astepti..."; //loader_alb.gif";	
	
	//se adauga la url un text. Daca nu se adauga acest text atunci nu se va cere pagina de pe server ci va fi folosita o pagina cache-uita de browser
	if(url) url+=((url.indexOf('?')==-1) ? '?' : '&')+'js_time='+new Date().getTime();
	
	//memorez contentul tag-ului pentru o eventuala refacere ulterioara
	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, exec_code_after); };
	//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, exec_code_after) {

	if (http_request.readyState == 4) {
		if (http_request.status == 200) {			
			document.getElementById(id_tag).innerHTML = http_request.responseText;  //aici se modifica informatia din tagul cu id=id_tag (ex: <span id='abc'></span> )
			if(exec_code_after) try{ eval(exec_code_after); }catch(e){ }
		} 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;
  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);
  return sget;
}
*/