// JavaScript Document

/* AJAX Stuff */
function createRequestObject()
{
	var request;
	var browser=navigator.appName;
	if(browser=="Microsoft Internet Explorer")
		request=new ActiveXObject("Microsoft.XMLHTTP");
	else
		request=new XMLHttpRequest();
	return request;
}

var http=createRequestObject();

function getCentral(b_id,ordine)
{
	http.open('GET', 'ajax/form_central.php?b_id='+escape(b_id)+'&ordine='+escape(ordine));
	http.onreadystatechange=showCentral;
	try {http.send(null);} catch(e1) {}
	return;
}

function showCentral()
{
	//http.setHeader("Cache-Control", "no-cache");
	if(http.readyState==4)
	{
		destDiv1=document.getElementById('central_frame');
		destDiv1.style.display="block";
		x=document.getElementById('central_data');
		var d=document.createElement("div");
		d.innerHTML=http.responseText;
		while(x.firstChild)
			x.removeChild(x.firstChild);
		x.appendChild(d);
		/*var response=http.responseText;
		destDiv2.innerHTML=response;*/
	}
}

function getPromo(b_id, absPath)
{
	http.open('GET', absPath+'ajax/form_promo.php?art_id='+escape(b_id));
	http.onreadystatechange=showPromo;
	try {http.send(null);} catch(e1) {}
	return;
}

function showPromo()
{
	//http.setHeader("Cache-Control", "no-cache");
	if(http.readyState==4)
	{
		destDiv1=document.getElementById('promo_frame');
		destDiv1.style.display="block";
		x=document.getElementById('promo_data');
		var d=document.createElement("div");
		d.innerHTML=http.responseText;
		while(x.firstChild)
			x.removeChild(x.firstChild);
		x.appendChild(d);
		/*var response=http.responseText;
		destDiv2.innerHTML=response;*/
	}
}

var CrtCtrl="";
function getLocalitatiCos(jud_id, id1, valoare)
{
	CrtCtrl=id1;
	http.open('GET', 'ajax/sel_localitati_cos.php?jud_id='+escape(jud_id)+'&id1='+escape(id1)+'&valoare='+escape(valoare));
	http.onreadystatechange=showLocalitati;
	try {http.send(null);} catch(e1) {}
	return;
}


function showLocalitatiCos()
{
	if(http.readyState==4)
	{
		destDiv1=document.getElementById('localitati_result_'+CrtCtrl);
		destDiv1.innerHTML=http.responseText;
	}
}

var CrtCtrl="";
function getLocalitati(jud_id, id1, valoare)
{
	CrtCtrl=id1;
	http.open('GET', 'ajax/sel_localitati.php?jud_id='+escape(jud_id)+'&id1='+escape(id1)+'&valoare='+escape(valoare));
	http.onreadystatechange=showLocalitati;
	try {http.send(null);} catch(e1) {}
	return;
}


function showLocalitati()
{
	if(http.readyState==4)
	{
		destDiv1=document.getElementById('localitati_result_'+CrtCtrl);
		destDiv1.innerHTML=http.responseText;
	}
}

function getLocalitati1(jud_id, id1, valoare)
{
	CrtCtrl=id1;
	http.open('GET', 'ajax/sel_localitati.php?jud_id1='+escape(jud_id)+'&id1='+escape(id1)+'&valoare='+escape(valoare));
	http.onreadystatechange=showLocalitati1;
	try {http.send(null);} catch(e1) {}
	return;
}


function showLocalitati1()
{
	if(http.readyState==4)
	{
		destDiv1=document.getElementById('localitati_result_'+CrtCtrl);
		destDiv1.innerHTML=http.responseText;
	}
}

function getStrada(jud_id, id1, valoare, valoare1)
{
	CrtCtrl=id1;
//	alert(jud_id);
	if((jud_id+0)>0){
		http.open('GET', 'ajax/sel_localitati.php?loc_id='+escape(jud_id)+'&id1='+escape(id1)+'&valoare='+escape(valoare)+'&valoare1='+escape(valoare1));
		http.onreadystatechange=showStrazi;
		try {http.send(null);} catch(e1) {}
	}
	return;
}


function showStrazi()
{
	if(http.readyState==4)
	{
//		alert(http.responseText);
		destDiv1=document.getElementById('localitati_result_'+CrtCtrl);
		destDiv1.innerHTML=http.responseText;
	}
}

function SelectCodPostal(loc, strada)
{
//	alert(loc);
//	alert(strada);
	if((loc+0)>0){
		http.open('GET', 'ajax/sel_localitati.php?coduri_p=1&localitate='+escape(loc)+'&strada='+escape(strada));
		http.onreadystatechange=ShowCodPostal;
		try {http.send(null);} catch(e1) {}
	}else{
		alert("Trebuie sa selectati mai intai localitatea!");
	}
	return;
}


function ShowCodPostal()
{
	if(http.readyState==4)
	{
//		alert(http.responseText);
		destDiv1=document.getElementById('dvCoduriPostale');
		destDiv1.innerHTML=http.responseText;
	}
}

var http7=createRequestObject();
function ajax_doListaLocalitati(jud_id, oras)
{
	var myurl="ajax/doSelectLocalitati.php";
	myRand=parseInt(Math.random()*99999999);						// cache buster
	myurl+="?rand="+myRand;
	theDiv=document.getElementById('divDisplayLocalitati');
	myurl+="&judet="+escape(jud_id)+"&oras="+escape(oras);
	//alert(myurl);
	http7.open("GET", myurl, true);
	http7.onreadystatechange=function() {
		x=theDiv;
		if (http7.readyState==4)
		{
			var d=document.createElement('div');
			d.innerHTML=http7.responseText;
			while(x.firstChild)
				x.removeChild(x.firstChild);
			x.appendChild(d);
		}
	}
	http7.send(null);
}