$(document).ready(function() {
	if($("#hprivacy").length > 0)
	{
		$("#hprivacy").attr("href",$("#hprivacy").attr("href")+"?embed");
		$("#hprivacy").colorbox({width:"80%", height:"80%"});
	}
	if($("#hnotelegali").length > 0)
	{
		$("#hnotelegali").attr("href",$("#hnotelegali").attr("href")+"?embed");
		$("#hnotelegali").colorbox({width:"80%", height:"80%"});
	}
	if($("#hrichval").length > 0)
	{
		$("#hrichval").attr("href",$("#hrichval").attr("href")+"?embed");
		$("#hrichval").colorbox({width:"600px", height:"600px"});
	}
	if($("#htel").length > 0)
	{		
		$("#htel").colorbox({width:"800px", inline:true, href:"#inline_tel"});
	}	
	
});
					
function docerca()
{
	if($("#rva").val() == "")
	{
		alert("Vuoi comprare o affitare?");
		$("#myOpt_rva").click();
		return;
	}
	if(false && $("#rtipo").val() == "")
	{
		alert("Seleziona il tipo immobile che ti interessa");
		$("#myOpt_rtipo").click();
		return;
	}
	if($("#rcomune").val() == "")
	{
		alert("Seleziona il comune");
		$("#myOpt_rcomune").click();
		return;
	}


    if($("#rva").val() != ""  && $("#rcomune").val() != "")
	{
		//alert($("#rcomune option:selected").text().replace(/ /g,'-'));		
		url = $("#rcomune option:selected").text().replace(/ /g,'-')+"_"+$("#rva option:selected").text().replace(/ /g,'-');
		if($("#rtipo").val() != "")
			url += "_" + $("#rtipo option:selected").text().replace(/ /g,'-');
		url += ".php";
		url = encodeURIComponent(accentsTidy(url));
		url+="?";
		if($("#rprzd").val() != "")
			url += "rprzd="+$("#rprzd").val()+"&";
		if($("#rprza").val() != "")
			url += "rprza="+$("#rprza").val()+"&";
		if($("#ricAvanzata").is(":visible"))
		{
			if($("#rzona").val() != "")
				url += "rzona="+$("#rzona").val()+"&";
			if($("#rtipologia").val() != "")
				url += "rtipologia="+$("#rtipologia").val()+"&";
			if($("#rnl").val() != "")
				url += "rnl="+$("#rnl").val()+"&";	
			if($("#rsc").val() != "")
				url += "rsc="+$("#rsc").val()+"&";			
		}	
		if(url.substr(url.length -1,url.length) == "&" || url.substr(url.length -1,url.length) == "?")
			url = url.substr(0,url.length -1)
		document.location = url;
		return;
	}
	else
		$("#form_cerca").submit();
}
accentsTidy = function(s){
                        var r=s.toLowerCase();
                        r = r.replace(new RegExp("\\s", 'g'),"");
                        r = r.replace(new RegExp("[àáâãäå]", 'g'),"a");
                        r = r.replace(new RegExp("æ", 'g'),"ae");
                        r = r.replace(new RegExp("ç", 'g'),"c");
                        r = r.replace(new RegExp("[èéêë]", 'g'),"e");
                        r = r.replace(new RegExp("[ìíîï]", 'g'),"i");
                        r = r.replace(new RegExp("ñ", 'g'),"n");
                        r = r.replace(new RegExp("[òóôõö]", 'g'),"o");
                        r = r.replace(new RegExp("œ", 'g'),"oe");
                        r = r.replace(new RegExp("[ùúûü]", 'g'),"u");
                        r = r.replace(new RegExp("[ýÿ]", 'g'),"y");
                        //r = r.replace(new RegExp("\\W", 'g'),"");
                        return r;
                };
function CleanWordHTML( fieldId ){
	var str = document.getElementById("wysiwyg" + fieldId).contentWindow.document.body.innerHTML;

	str = str.replace(/<!(?:--[\s\S]*?--\s*)?>\s*/g,''); // Removes HTML Comments and their contents, looking for <!-- -->
	str = str.replace(/<o:p>\s*<\/o:p>/g, "") ;
	str = str.replace(/<o:p>.*?<\/o:p>/g, "&nbsp;") ;
	str = str.replace( /\s*mso-[^:]+:[^;"]+;?/gi, "" ) ;
	str = str.replace( /\s*MARGIN: 0cm 0cm 0pt\s*;/gi, "" ) ;
	str = str.replace( /\s*MARGIN: 0cm 0cm 0pt\s*"/gi, "\"" ) ;
	str = str.replace( /\s*TEXT-INDENT: 0cm\s*;/gi, "" ) ;
	str = str.replace( /\s*TEXT-INDENT: 0cm\s*"/gi, "\"" ) ;
	str = str.replace( /\s*TEXT-ALIGN: [^\s;]+;?"/gi, "\"" ) ;
	str = str.replace( /\s*PAGE-BREAK-BEFORE: [^\s;]+;?"/gi, "\"" ) ;
	str = str.replace( /\s*FONT-VARIANT: [^\s;]+;?"/gi, "\"" ) ;
	str = str.replace( /\s*tab-stops:[^;"]*;?/gi, "" ) ;
	str = str.replace( /\s*tab-stops:[^"]*/gi, "" ) ;
	str = str.replace( /\s*face="[^"]*"/gi, "" ) ;
	str = str.replace( /\s*face=[^ >]*/gi, "" ) ;
	str = str.replace( /\s*FONT-FAMILY:[^;"]*;?/gi, "" ) ;
	str = str.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3") ;
	str = str.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3") ;
	str = str.replace (/<\\?\?xml[^>]*>/gi, '') ;
	str = str.replace(/<\/?\w+:[^>]*>/gi, "") ;
	str = str.replace( /<H\d>\s*<\/H\d>/gi, '' ) ;
	str = str.replace( /<H1([^>]*)>/gi, '' ) ;
	str = str.replace( /<H2([^>]*)>/gi, '' ) ;
	str = str.replace( /<H3([^>]*)>/gi, '' ) ;
	str = str.replace( /<H4([^>]*)>/gi, '' ) ;
	str = str.replace( /<H5([^>]*)>/gi, '' ) ;
	str = str.replace( /<H6([^>]*)>/gi, '' ) ;
	str = str.replace( /<\/H\d>/gi, '<br>' ) ; //remove this to take out breaks where Heading tags were
	str = str.replace( /<link [^>]+>/g, '' ) ;
	str = str.replace( /<([^\s>]+)[^>]*>\s*<\/\1>/g, '' ) ;
	str = str.replace( /<([^\s>]+)[^>]*>\s*<\/\1>/g, '' ) ;
	str = str.replace( /<([^\s>]+)[^>]*>\s*<\/\1>/g, '' ) ;
	//some RegEx code for the picky browsers
	var re = new RegExp("(<P)([^>]*>.*?)(<\/P>)","gi") ;
	str = str.replace( re, "<div$2</div>" ) ;

	document.getElementById("wysiwyg" + fieldId).contentWindow.document.body.innerHTML = str; // Sets Wyzz editor to new string
	document.getElementById(fieldId).value = str; // Sets hidden field for Wyzz to new string
}
 String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

function apriRicAv()
{
	if($("#ricAvanzata").is(":visible"))
	{
		$("#ricAvanzata").hide('slow');
		$("#scrittaRicAv").html("[RICERCA AVANZATA]");
	}
	else
	{
		$("#ricAvanzata").show('slow');
		$("#scrittaRicAv").html("[RICERCA SEMPLICE]");
	}

}

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-11731783-3']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();


function recordActionboundLink(category, action) {
  try {
    var myTracker=_gat._getTrackerByName();
    _gaq.push(['myTracker._trackEvent', ' + category + ', ' + action + ']);
  }catch(err){}
  
}

