function select_this_news(id)
{
	var el = document.getElementById(id);
	if (el)
	{
		el.className = "news_pbg";
		if (sel_news != id)
		{
			var old_el = document.getElementById(sel_news);
			if (old_el)
				old_el.className = "";
			sel_news = id;
		}
	}
}

function image_zoom(img_big, description)
{
	var temp = new Image();
	temp.src=img_big;
	var page = '<html>'+
					'<head></head>'+
						'<body bgcolor="#ffffff" rightmargin="5" leftmargin="5" bottommargin="5" topmargin="5">'+
						'<table cellspacing="0" cellpadding="0" border="0" width="100%" height="100%">'+
						'<tr><td height="100%" align="center"><img align="middle" src="'+temp.src+'" border=0 onload="self.window.resizeTo((this.width+25),(this.height+110)); if(screen) self.window.moveTo( ((screen.width-this.width)/2), ((screen.height-this.height)/2));"></td></tr>'+
						'<tr><td align="center">'+unescape(description).replace(/\+/g, " ")+'</td></tr>'+
					'</table></body>'+
				'</html>';
	var attribs = ',' + "menubar=0,location=0,toolbar=0,status=0,scrollbars=0,resizable=0, width=100,height=100";
	var wind = window.open('','_blank',attribs);
	wind.document.open();
	wind.document.write(page);
	wind.document.close();
}

function get_cities(id, the_class, change)
{
	var xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
			document.getElementById("centri_cities").innerHTML = xmlHttp.responseText;
	}
	xmlHttp.open ("GET", "__get_cities.php?id=" + id + "&class=" + the_class + "&change=" + change, true);
	xmlHttp.send (null);
}

function get_model(id, vers)
{
	var xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
			document.getElementById("centri_cities").innerHTML = xmlHttp.responseText;
	}
	xmlHttp.open ("GET", "__get_model.php?id=" + id + "&vers=" + vers, true);
	xmlHttp.send (null);
}

function get_prod(id)
{
	var xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
			document.getElementById("prod_cont").innerHTML = xmlHttp.responseText;
	}
	xmlHttp.open ("GET", "__get_prod.php?id=" + id, true);
	xmlHttp.send (null);
}

function get_prod_1(id)
{
	var xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
			document.getElementById("prod_list").innerHTML = xmlHttp.responseText;
	}
	xmlHttp.open ("GET", "__get_prod_1.php?id=" + id, true);
	xmlHttp.send (null);
}

function get_prod_2(id)
{
	var xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
			document.getElementById("prod_cont").innerHTML = xmlHttp.responseText;
	}
	xmlHttp.open ("GET", "__get_prod_2.php?id=" + id, true);
	xmlHttp.send (null);
}


function get_centris(id, id_promotion)
{
	var xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
			document.getElementById("centri_masters").innerHTML = xmlHttp.responseText;
	}
	xmlHttp.open ("GET", "__get_centris.php?id=" + id + "&id_promotion=" + id_promotion, true);
	xmlHttp.send (null);
}

function get_pr_ci_centris(id)
{
	var xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
			document.getElementById("centri_masters").innerHTML = xmlHttp.responseText;
	}
	xmlHttp.open ("GET", "__get_centris.php?id=" + id, true);
	xmlHttp.send (null);
}

function get_con_ci_centris(id)
{
	var xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
			document.getElementById("centri_masters").innerHTML = xmlHttp.responseText;
	}
	xmlHttp.open ("GET", "__get_con_centris.php?id=" + id, true);
	xmlHttp.send (null);
}

function get_the_centri(id)
{
	var xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
			document.getElementById("cnetri_centri").innerHTML = xmlHttp.responseText;
	}
	xmlHttp.open ("GET", "__get_city_centris.php?id=" + id, true);
	xmlHttp.send (null);
}

var img_sel = Array();
var the_sel_an_img = Array();
var tot_imgs = Array();

function prev_pic(id)
{
	if (img_sel[id] > 1)
	{
		var xmlHttp = GetXmlHttpObject();
		if (xmlHttp == null)
		{
			alert ("Your browser does not support AJAX!");
			return;
		}
		xmlHttp.onreadystatechange = function()
		{
			if(xmlHttp.readyState == 4)
			{
				var the_resp = xmlHttp.responseText.split("-sep-");
				document.getElementById("container_" + id).innerHTML = the_resp[3];
				the_sel_an_img[id] = the_resp[0];
				document.getElementById("img_big_" + id).src = the_resp[1];
				//document.getElementById("img_big_a_" + id).href = the_resp[2];
				img_sel[id]--;
			}
		}
		xmlHttp.open ("GET", "__get_news_images.php?id=" + id + "&ind=" + (img_sel[id] - 1), true);
		xmlHttp.send (null);
	}
}

function next_pic(id)
{
	if (img_sel[id] < tot_imgs[id])
	{
		var xmlHttp = GetXmlHttpObject();
		if (xmlHttp == null)
		{
			alert ("Your browser does not support AJAX!");
			return;
		}
		xmlHttp.onreadystatechange = function()
		{
			if(xmlHttp.readyState == 4)
			{
				var the_resp = xmlHttp.responseText.split("-sep-");
				document.getElementById("container_" + id).innerHTML = the_resp[3];
				the_sel_an_img[id] = the_resp[0];
				document.getElementById("img_big_" + id).src = the_resp[1];
				//document.getElementById("img_big_a_" + id).href = the_resp[2];
				img_sel[id]++;
			}
		}
		xmlHttp.open ("GET", "__get_news_images.php?id=" + id + "&ind=" + (img_sel[id] + 1), true);
		xmlHttp.send (null);
	}
}

function go_pic(ind, id)
{
	if ((ind <= tot_imgs[id]) && (ind > 0))
	{
		var xmlHttp = GetXmlHttpObject();
		if (xmlHttp == null)
		{
			alert ("Your browser does not support AJAX!");
			return;
		}
		xmlHttp.onreadystatechange = function()
		{
			if(xmlHttp.readyState == 4)
			{
				var the_resp = xmlHttp.responseText.split("-sep-");
				document.getElementById("container_" + id).innerHTML = the_resp[3];
				the_sel_an_img[id] = the_resp[0];
				document.getElementById("img_big_" + id).src = the_resp[1];
				//document.getElementById("img_big_a_" + id).href = the_resp[2];
				img_sel[id] = ind;
			}
		}
		xmlHttp.open ("GET", "__get_news_images.php?id=" + id + "&ind=" + ind, true);
		xmlHttp.send (null);
	}
}

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 check_form()
{
	var err = "";
	if (document.forms.contact_f.name.value < 3)
		err += "<br />il \'nome\' campo è obbligatorio";
	if ((document.forms.contact_f.email.value < 3) || (!isValidEmail(document.forms.contact_f.email.value)))
		err += "<br />il \'indrizzo e-mail\' campo è obbligatorio";
	if (document.forms.contact_f.message.value < 3)
		err += "<br />il \'richiesta\' campo è obbligatorio";
	if (err.length == 0)
		document.forms.contact_f.submit();
	else
		document.getElementById("c_error").innerHTML = "I seguenti errori si sono verificati:<br />" + err;
}

function isValidEmail(str)
{
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}


function check_ze_form()
{
	var err = "";
	if (document.forms.garanzia_f.name.value < 3)
		err += "<br />il \"nome\" campo è obbligatorio";
	if (document.forms.garanzia_f.email.value < 3)
		err += "<br />il \"indrizzo e-mail\" campo è obbligatorio";
	if (!document.forms.garanzia_f.all_yes.checked)
		err += "<br />\"Accetto legge sulla privacy\" è obbligatorio";
	if (err.length == 0)
	{
		document.forms.garanzia_f.submit();
		document.getElementById("g_error").innerHTML = "";
	}
	else
		document.getElementById("g_error").innerHTML = "I seguenti errori si sono verificati:<br />" + err;
}

function check_ze_other_form()
{
	var err = "";
	if (!document.forms.newsletter_f.privacy.checked)
		err += "\nil \'accetto consens privacy\' campo è obbligatorio";
	if (err.length == 0)
	{
		document.forms.newsletter_f.submit();
		document.getElementById("g_error").innerHTML = "";
	}
	else
		document.getElementById("g_error").innerHTML = "I seguenti errori si sono verificati:<br />" + err;
}

function show_hide(id)
{
	var el = document.getElementById(id);
	if (el)
	{
		if (el.style.display == "block")
			el.style.display = "none";
		else
			el.style.display = "block";
	}
}

function check_uncheck(stat, wha)
{
	document.getElementById(wha + "_yes").checked = stat;
	document.getElementById(wha + "_no").checked = !stat;
}

function gallery_zoom3(elem, text)
{
	// var full_image = new Image();
	// alert(elem.src.replace("thumbs362x271/", "thumbs800x600/"));
	// full_image.src = elem.src.replace("thumbs362x271/", "thumbs800x600/");
	// alert(elem.height);
	// alert(elem.src);
	var i_src = elem.src.replace("thumbs198x131/", "thumbs800x600/");
	
	// alert(full_image);
	// elem = full_image;
	// alert(full_image.width);
	
	Modalbox.show("<center><img onclick='Modalbox.hide();' style='cursor: pointer;' src='"+i_src+"' /><br/>" + (text) + "<br/><a href='javascript://' onclick='Modalbox.hide();'>Click to close</a></center>", 
		{title: elem.title, 
		width: 800 + 20,  
		content: "HTML",
		overlayClose: true});
    // return false;
}

function gallery_zoom2(img, text)
{
	Modalbox.show("<center><img onclick='Modalbox.hide();' style='cursor: pointer;' src='"+img+"' /><br/>" + (text) + "<br/><a href='javascript: //' onclick='Modalbox.hide();'>Click to close</a></center>", 
		{title: "&nbsp;", 
		width: 800 + 20,  
		content: "HTML",
		overlayClose: true});
}

function prev_re_page(id)
{
	if (page_sel > 1)
	{
		var xmlHttp = GetXmlHttpObject();
		if (xmlHttp == null)
		{
			alert ("Your browser does not support AJAX!");
			return;
		}
		xmlHttp.onreadystatechange = function()
		{
			if(xmlHttp.readyState == 4)
			{
				var the_resp = xmlHttp.responseText.split("-sep-");
				document.getElementById("pages").innerHTML = the_resp[0];
				document.getElementById("real").innerHTML = the_resp[1];
				page_sel--;
			}
		}
		xmlHttp.open ("GET", "__get_re_page.php?id=" + id + "&ind=" + (page_sel - 1), true);
		xmlHttp.send (null);
	}
}

function next_re_page(id)
{
	if (page_sel < tot_pages)
	{
		var xmlHttp = GetXmlHttpObject();
		if (xmlHttp == null)
		{
			alert ("Your browser does not support AJAX!");
			return;
		}
		xmlHttp.onreadystatechange = function()
		{
			if(xmlHttp.readyState == 4)
			{
				var the_resp = xmlHttp.responseText.split("-sep-");
				document.getElementById("pages").innerHTML = the_resp[0];
				document.getElementById("real").innerHTML = the_resp[1];
				page_sel++;
			}
		}
		xmlHttp.open ("GET", "__get_re_page.php?id=" + id + "&ind=" + (page_sel + 1), true);
		xmlHttp.send (null);
	}
}

function go_re_page(ind, id)
{
	if ((ind <= tot_pages) && (ind > 0))
	{
		var xmlHttp = GetXmlHttpObject();
		if (xmlHttp == null)
		{
			alert ("Your browser does not support AJAX!");
			return;
		}
		xmlHttp.onreadystatechange = function()
		{
			if(xmlHttp.readyState == 4)
			{
				var the_resp = xmlHttp.responseText.split("-sep-");
				document.getElementById("pages").innerHTML = the_resp[0];
				document.getElementById("real").innerHTML = the_resp[1];
				page_sel = ind;
			}
		}
		xmlHttp.open ("GET", "__get_re_page.php?id=" + id + "&ind=" + ind, true);
		xmlHttp.send (null);
	}
}

function sel_re(id, url)
{
	var xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
		{
			var the_resp = xmlHttp.responseText.split("-sep-");
			document.location.hash = /*the_url + */the_resp[0];
			document.getElementById("cont").innerHTML = the_resp[1];
		}
	}
	xmlHttp.open ("GET", "__get_re_info.php?id=" + id, true);
	xmlHttp.send (null);
}

var images = [];
var da_images = [];
var images_pos = 0;
var images_count = 0;

function slide_next_img()
{
	if ((images_pos + 1) < images_count)
	{
		// go next
		images_pos++;
	}
	else
	{
		// go first
		images_pos = 0;
	}
	if (da_images[images_pos])
	{
		document.getElementById("slide_big_image").src = da_images[images_pos]["path"];
		if (da_images[images_pos]["description"])
			document.getElementById("the_desc").innerHTML = da_images[images_pos]["description"];
	}
}
function gallery_zoom(table, parent, image_id)
{
	// var full_image = new Image();
	// alert(elem.src.replace("thumbs362x271/", "thumbs800x600/"));
	// full_image.src = elem.src.replace("thumbs362x271/", "thumbs800x600/");
	// alert(elem.height);
	// alert(elem.src);
	// var i_src = base_href + full_path;
	
	// alert(full_image);
	// elem = full_image;
	// alert(full_image.width);
	
	Modalbox.show("photo_gallery.php?t="+table+"&parent_id="+parent+"&image_id="+image_id, 
		{title: "Photo Gallery",
		width: 900 + 20, 
		height: 600 + 70,
		overlayClose: true});
    // return false;
}

function slide_prev_img()
{
	if ((images_pos - 1) >= 0)
	{
		// go prev
		images_pos--;
	}
	else
	{
		// go last
		images_pos = images_count - 1;
	}
	if (da_images[images_pos])
	{
		document.getElementById("slide_big_image").src = da_images[images_pos]["path"];
		if (da_images[images_pos]["description"])
			document.getElementById("the_desc").innerHTML = da_images[images_pos]["description"];
	}
}