/*	BOX RICERCA RIFERIMENTO IN HOME										*/
function ricercariferimento()
	{
		testo = $('#text_riferimento').val();
		testo = testo.replace(/ /g, "+");
		testo = testo.replace(/\\/g, "_");
		parole2 = testo.replace(/'/g, "");
		
		if($('#text_riferimento').val() != "Ricerca per riferimento...")
			{
				if(($('#text_riferimento').val() != "industria") && ($('#text_riferimento').val() != "industrie"))
					{
						page = "/attivita-in-vendita/cerca-" + testo + ".html";
					}
				else
					{
						page = "/attivita-in-vendita/industria-produzione-installatori-lavorazione_m6.html";
					}
				location=(page);
				return false;
			}
		else
			{
				alert("Devi inserire un riferimento");
				return false;
			}
	}

function handlericercariferimento()
	{
		$('#text_riferimento').click(function(){ 
		if (this.value == "Ricerca per riferimento...")
			{
				$(this).css({ color: '#333' });
				$(this).attr('value','');
			}
		});
		$('#text_riferimento').blur(function(){ 
			if(this.value == "")
				{
					$(this).css({ color: '#AAA' });
					this.value = "Ricerca per riferimento...";
				}
		});

	}

/*	ANIMAZIONE SUI PULSANTI CATEGORIE IN HOME						*/
function handle_bottonihome()
	{
		$('#home_category_buttons a').hover(
			function () {
				var button = $(this);
				button.animate({ marginTop: "0px" }, 200);
				
				var offset = button.offset();
				var tooltipname = (((button.attr("id")).replace('btn_','tlt_')));
				$('#' + tooltipname).css({
				'display' : 'block',
				'left' : offset.left-9,
				'top' : offset.top-55
			});
				
			}, function () {
				var button = $(this);
				button.animate({ marginTop: "4px" }, 200);
				
				var tooltipname = (((button.attr("id")).replace('btn_','tlt_')));
				$('#' + tooltipname).css('display','none');

				
			}
		);
	}

//CONTROLLO VALIDITA MAIL
function checkEmail(email) {
	if (/^([a-zA-Z0-9_.-]+)@([a-zA-z0-9-]+)\.([a-zA-Z0-9]{2,4})$/.test(email)) {
		return true;
	} else {
		return false;
	}
}

/* CONTROLLO INVIO FORM RICHIESTA INFORMAZIONI */
function check_infomodule($this) {
	$noerror = true;
	if($this == "rilevare_attivita")
		{
			if(($("input[name='tipologia']:checked").val() == 'acquisto_attivita') || ($("input[name='tipologia']:checked").val() == 'acquisto_immobile') || ($("input[name='tipologia']:checked").val() == 'altro'))
				$noerror = true;
			else
				$noerror = false;
		}
	else if($this == "cedere_attivita")
		{
			if(($("input[name='tipologia']:checked").val() == 'vendita_attivita') || ($("input[name='tipologia']:checked").val() == 'ricerca_socio') || ($("input[name='tipologia']:checked").val() == 'ricerca_partner') || ($("input[name='tipologia']:checked").val() == 'vendita_immobile') || ($("input[name='tipologia']:checked").val() == 'altro'))
				$noerror = true;
			else
				$noerror = false;
		}
	if($noerror == true)
		{
			if($("#text_responsabile").val() != "")
				{
					if(($("#text_telefono").val() != "") || ($("#text_email").val() != ""))
						{
							if($("#text_email").val() != "")
								{
									if(checkEmail($("#text_email").val()) == false)
										{
											alert("Devi inserire una mail valida per proseguire.");
											return false;
										}
								}
							if($("#sel_provincia").val() != "0")
								{
									if($("#text_settore").val() != "")
										{
											return true;
										}
									else
										{
											alert("Devi inserire un settore per proseguire.");
											return false;
										}
								}
							else
								{
									alert("Devi scegliere una provincia per proseguire.");
									return false
								}
						}
					else
						{
							alert("Devi inserire il numero di telefono o una email per proseguire.");
							return false;
						}
				}
			else
				{
					alert("Devi inserire il nome di un responsabile per proseguire.");
					return false;
				}
		}
	else
		{
			alert("Devi scegliere una delle opzioni per proseguire.");
			return false;
		}
}


/* CONTROLLO INVIO FORM RICHIESTA INFORMAZIONI DA SLIDER HOME*/
function check_infoslidermodule($this) {
	$noerror = true;
	if($("#text_responsabile").val() != "")
		{
			if(($("#text_telefono").val() != "") || ($("#text_email").val() != ""))
				{
					if($("#text_email").val() != "")
						{
							if(checkEmail($("#text_email").val()) == false)
								{
									alert("Devi inserire una mail valida per proseguire.");
									return false;
								}
						}
					if($("#sel_provincia").val() != "0")
						{
							if($("#text_settore").val() != "")
								{
									return true;
								}
							else
								{
									alert("Devi inserire un settore per proseguire.");
									return false;
								}
						}
					else
						{
							alert("Devi scegliere una provincia per proseguire.");
							return false
						}
				}
			else
				{
					alert("Devi inserire il numero di telefono o una email per proseguire.");
					return false;
				}
		}
	else
		{
			alert("Devi inserire il nome di un responsabile per proseguire.");
			return false;
		}
}


/* BOX RICERCA IN ATTIVITA IN VENDITA */
function ricercaattivita()
	{
		testo = $('#textricerca').val();
		testo = testo.replace(/ /g, "+");
		parole2 = testo.replace(/'/g, "");
		
		if($('#textricerca').val() != "Ricerca un'attivita...")
			{
				//page = "/attivita-in-vendita/cerca-" + testo + ".html";
				if(($('#textricerca').val() != "industria") && ($('#textricerca').val() != "industrie"))
					{
						page = "/attivita-in-vendita/cerca-" + testo + ".html";
					}
				else
					{
						page = "/attivita-in-vendita/industria-produzione-installatori-lavorazione_m6.html";
					}
				
				location=(page);
				return false;
			}
		else
			{
				alert("Devi inserire un termine di ricerca");
				return false;
			}
	}

function handlericercaattivita()
	{
		$('#textricerca').click(function(){ 
		if (this.value == "Ricerca un'attivita...")
			{
				$(this).css({ color: '#333' });
				$(this).attr('value','');
			}
		});
		$('#textricerca').blur(function(){ 
			if(this.value == "")
				{
					$(this).css({ color: '#AAA' });
					this.value = "Ricerca un'attivita...";
				}
		});

	}
/* FINE BOX RICERCA IN ATTIVITA IN VENDITA */


function annuncio_send_contact() {
	if($("#inp_nome").val() != "")
		{
			if(($("#inp_email").val() != "") || ($("#inp_telefono").val() != ""))
				{
					if($("#inp_email").val() != "")
						{
							if(checkEmail($("#inp_email").val()) == false)
							{
								alert("Devi inserire una mail valida per proseguire.");
								return false;
							}
						}
					return true;
				}
			else
				{
					alert("Devi inserire il numero di telefono o una email per proseguire.");
					return false;
				}
		}
	else
		{
			alert("Devi inserire un nome per proseguire.");
			return false;
		}
}

$(function(){
	handlericercariferimento();
	handle_bottonihome();
	handlericercaattivita();
});

function highlightbase($imgbase){
	$("#italymap").attr("src","../../img/layout/italia/" + $imgbase + ".gif");
}
function highlightnorth(){
	$("#italymap").attr("src","../../img/layout/italia/italynorth.gif");
}
function highlightcenter(){
	$("#italymap").attr("src","../../img/layout/italia/italycenter.gif");
}
function highlightsouth(){
	$("#italymap").attr("src","../../img/layout/italia/italysouth.gif");
}
function highlightisles(){
	$("#italymap").attr("src","../../img/layout/italia/italyisles.gif");
}

function previousnext(id,direction)
	{
		var photoul_name	= "#photo_ul_" + id;
		if(direction == "left")
			{
				var photoul_next	= "#photo_ul_" + (id+1);
				$(photoul_next).slideDown(1000);
				$(photoul_name).slideUp(1000);
			}
		else
			{
				var photoul_prev	= "#photo_ul_" + (id-1);
				$(photoul_prev).slideDown(1000);
				$(photoul_name).slideUp(1000);
			}
	}




function sideExpandClick() {
	$(".sideTrIcon").click(function () {
		cliccato	= $(this).parent();
		if(cliccato.hasClass("side_close") == true)
			{
				cliccato.removeClass("side_close");
				cliccato.addClass("side_open");
				$(cliccato + " > ul").slideDown();
				
			}
		else if(cliccato.hasClass("side_open") == true)
			{
				cliccato.removeClass('side_open');
				cliccato.addClass("side_close");
				$(cliccato + " > ul").slideUp();
			}
	});
}

$(document).ready(function() {
	sideExpandClick();
});
