function GetXmlHttpObject()
{
	var xmlHttp = null;
	try
	{
		xmlHttp = new XMLHttpRequest();
	}
	catch (e)
	{
		try
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function adauga_newsletter()
{
	var the_email = document.newsletter_form.email.value;
	if ((the_email.length == 0) || !chkem(the_email))
	{
		alert("Nu ai introdus o adresa de email corecta");
		return false;
	}
	else
	{
		document.newsletter_form.submit();
		return true;
	}
	var xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	xmlHttp.onreadystatechange = function()
	{
		if (xmlHttp.readyState == 4)
		{
			alert(xmlHttp.responseText);
			document.newsletter_form.email.value = "";
		}
	}
	xmlHttp.open("GET", base_href + "_add_newsletter.php?email=" + the_email, true);
	xmlHttp.send(null);
}

function validate_email()
{
	var eroare = '';
	if (document.newsleta.nume.value.length < 3)
		eroare += "Nu ati introdus numele\n";
	if (document.newsleta.firma.value.length < 3)
		eroare += "Nu ati introdus firma\n";
	if ((document.newsleta.localitate.value == 0) && (document.newsleta.oras2.value.length == 0))
		eroare += "Nu ati introdus orasul\n";
	if (document.newsleta.telefon.value.length < 3)
		eroare += "Nu ati introdus telefonul\n";
	if (document.newsleta.mesaj.value.length < 3)
		eroare += "Nu ati introdus mesaj\n";
	var the_email = document.newsleta.email.value;
	if ((the_email.length == 0) || !chkem(the_email))
		eroare += "Nu ati introdus o adresa de email corecta\n";
	if(document.newsleta.vcode.value.length<4)
		eroare += "Nu ati introdus codul de verificare\n";
	if (eroare.length > 0)
	{
		alert("Informatiile nu s-au putut trimite, deoarece\n\n" + eroare);
		return false;
	}
	else
		return true;
	
}

function validate_email_2()
{
	var eroare = '';
	if (document.newsleta.nume.value.length < 3)
		eroare += "Nu ati introdus numele salonului\n";
	if ((document.newsleta.localitate.value == 0) && (document.newsleta.oras2.value.length == 0))
		eroare += "Nu ati introdus orasul\n";
	if (document.newsleta.adresa.value.length < 3)
		eroare += "Nu ati introdus adresa\n";
	if (document.newsleta.telefon.value.length < 3)
		eroare += "Nu ati introdus telefonul\n";
	if (document.newsleta.persoana.value.length < 3)
		eroare += "Nu ati introdus persoana de contact\n";
	var the_email = document.newsleta.email.value;
	if ((the_email.length == 0) || !chkem(the_email))
		eroare += "Nu ati introdus o adresa de email corecta\n";
	if (document.newsleta.mobil.value.length < 3)
		eroare += "Nu ati introdus mobil persoanei de contact\n";
	if (document.newsleta.mesaj.value.length < 3)
		eroare += "Nu ati introdus mesaj\n";
	if(document.newsleta.vcode.value.length<4)
		eroare += "Nu ati introdus codul de verificare\n";
	var the_email = document.newsleta.email.value;
	if (eroare.length > 0)
	{
		alert("Informatiile nu s-au putut trimite, deoarece\n\n" + eroare);
		return false;
	}
	else
		return true;
}

function chkem(a)
{
	ero = "`=[];\',/\\#$%^&*()+{}:\"<>?| ";
	ned = "@.";
	er = 0;
	if (a.length == 0)
		return false;
	else if (a.length < 4)
		return false;
	else
	{
		for (j = 0; j <= ero.length - 1; j++)
			if (a.indexOf(ero.substring(j, j + 1)) != -1)
				er = 1;
		for (j = 0; j <= ned.length - 1; j++)
		{
			aos = a.split(ned.substring(j, j + 1));
			for (var i = 0; i < aos.length - 1; i++)
				if (aos[i] < 1)
					er = 1;
			if (a.indexOf(ned.substring(j, j + 1)) == -1)
				er = 1;
		}
		if (er==1)
			return false;
	}
	return true;
}

function schimba_zona(id_local, id_zona)
{
	var xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	xmlHttp.onreadystatechange = function()
	{
		if ((xmlHttp.readyState == 4) && (xmlHttp.responseText != "no-local"))
			document.getElementById("cautare_zona").innerHTML = xmlHttp.responseText;
	}
	xmlHttp.open("GET", base_href + "_change_zone.php?local=" + id_local + "&zona=" + id_zona, true);
	xmlHttp.send(null);
}

function ascunde_texte()
{
	var the_as = document.getElementById("header").getElementsByTagName("a");
	for (var i = 0; i < the_as.length; i++)
		if (the_as[i].className.substr(0, 4) == "menu")
			the_as[i].innerHTML = "";
}

function cauta_saloane()
{
	//alert("Cautam saloane");
	document.cautare_saloane.submit();
}

function change_rate(rate, type)
{
	eval ("var rata = document.comment_form.rate_"+type+";");
	rata.value = rate;
	for (var i = 1; i <= rate; i++)
	{
		var img = document.getElementById(type + "_" + i);
		img.src = 'i/star2.gif';
	}
	for (var i = rate + 1; i <= 5; i++)
	{
		var img = document.getElementById(type + "_" + i);
		img.src = 'i/star3.gif';
	}
}

function highlight_rate(rate, type)
{
	for (var i = 1; i <= rate; i++)
	{
		var img = document.getElementById(type + "_" + i);
		img.src = 'i/star2.gif';
	}
	for (var i = rate + 1; i <= 5; i++)
	{
		var img = document.getElementById(type + "_" + i);
		img.src = 'i/star3.gif';
	}
}

function out_highlight_rate(rate, type)
{
	eval ("var rate = document.comment_form.rate_"+type+".value;");
	for (var i = 1; i <= rate; i++)
	{
		var img = document.getElementById(type + "_" + i);
		img.src = 'i/star2.gif';
	}
	for (var i = parseInt(rate) + 1; i <= 5; i++)
	{
		var img = document.getElementById(type + "_" + i);
		img.src = 'i/star3.gif';
	}
}

function change_gal_image(id)
{
	var big_img = document.getElementById("salon_big_img");
	big_img.src = images[id]["src"];
	big_img.alt = images[id]["title"];
	big_img.title = images[id]["title"];
	document.getElementById("asp_" + old_id).style.display = 'none';
	document.getElementById("asp_" + id).style.display = 'block';
	old_id = id;
}
function show_modal(id, image_id)
{
	Modalbox.show("_photo_gallery.php?salon=" + id + "&image_id=" + image_id, 
		{title: "Galerie Foto",
		width: 900 + 20, 
		height: 500 + 70, 
		overlayClose: true});
}
function map_zoom(hlat, hlong, nume)
{
	Modalbox.show("_big_map.php?lat=" + hlat + "&long=" + hlong + "&nume=" + nume, 
		{title: nume + " - Harta mare",
		width: 900 + 20, 
		height: 500 + 70, 
		overlayClose: true});
}

var images = [];
var images_pos = 0;
var images_count = 0;

function slide_next_img()
{
	if ((images_pos + 1) < images_count)
	{
		images_pos++;
	}
	else
	{
		images_pos = 0;
	}
	if (images[images_pos])
	{
		document.getElementById("slide_big_image").src = images[images_pos]["path"];
	}
}

function slide_prev_img()
{
	if ((images_pos - 1) >= 0)
	{
		images_pos--;
	}
	else
	{
		images_pos = images_count - 1;
	}
	if (images[images_pos])
	{
		document.getElementById("slide_big_image").src = images[images_pos]["path"];
	}
}

function show_hide_adv_search(el)
{
	if (el.innerHTML == "Mai multe optiuni")
	{
		el.innerHTML = "Mai putine optiuni";
		document.getElementById("show_hide_adv_srch").style.display = "block";
	}
	else
	{
		el.innerHTML = "Mai multe optiuni";
		document.getElementById("show_hide_adv_srch").style.display = "none";
	}
}
