// JavaScript Document
var bIsMobile=false;
jQuery.fn.center = function () {
    this.css("position","absolute");
	var iTop=($(window).height() - this.height() ) / 2+$(window).scrollTop();
	if (iTop<380) iTop=470;
    this.css("top", iTop + "px");
    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
    return this;
}
jQuery.fn.centermobile = function () {
    this.css("position","absolute");
	var iTop=$(window).scrollTop();
    this.css("top", iTop + "px");
    return this;
}
$(document).ready(function() {
  $.post("ajaxhelper.php","funz=screensize&width="+$(window).width()+"&height="+$(window).height(),function (data) { 
 eval(data); 
 $.post("ajaxhelper.php","funz=bloccoricerca",function(retdata2) {
	  var res2=jQuery.parseJSON( retdata2 );
	  $("#bloccoperricerca").html(res2);
	});	
 carica_is_mobile();
 carica_flash_testata(); 
  });
 });
var iLastX,iLastY;
$(document).mousedown(function(e) {
  iLastX=e.pageX; iLastY=e.pageY;
});
$(window).resize(function() {
  $.post("ajaxhelper.php","funz=ismobile",function(retdata) {
		eval(retdata);
		carica_flash_testata();
	});
});

function carica_is_mobile()
{
$.post("ajaxhelper.php","funz=ismobile",function(retdata) {
		eval(retdata);										 									
	});
}

function carica_flash_testata()
{
 if(bIsMobile==false)
 {
 var iW=$("#LayerContenitore").width();
 var iH=parseInt(iW/(766/320));
 var fo = new FlashObject("img/testata.swf", "flash1", iW, iH, 8);
 fo.addParam("quality","high");
 fo.write("flash1");
 }
 else
 {
	$("#menustatico").html("<a href=\"javascript:menu_home()\">Home</a>&nbsp;&nbsp;<a href=\"javascript:menu_valuta()\">Valuta gratis la tua casa</a>&nbsp;&nbsp;<a href=\"javascript:menu_azienda()\">Azienda</a>&nbsp;&nbsp;<a href=\"javascript:menu_lavora()\">Lavora con noi</a>&nbsp;&nbsp;<a href=\"javascript:menu_contatti()\">Contatti</a>&nbsp;&nbsp;"); 
 }
}

var hPIEDettaglio;
function dettaglioimmobile(idimmobile)
{
  $("*").css("cursor", "progress");
  $.post("ajaxhelper.php","funz=dettaglioimmobile&id="+idimmobile,function(retdata) {
  $("*").css("cursor", "auto");
  $("#LayerDettaglio").html(retdata);
  $("#LayerDettaglio").center();
  if($.browser.msie) 
  {
	  var element=document.getElementById("LayerDettaglio");
	  hPIEDettaglio=element.addBehavior ("img/PIE.htc");
  }
  $("#LayerDettaglio").slideDown(1400);
  });
}

function chiudidettaglioimmobile()
{
	if($.browser.msie) 
    {
	  var element=document.getElementById("LayerDettaglio");
	  element.removeBehavior (hPIEDettaglio);
    }
	$('#LayerDettaglio').fadeOut();
	$('*').css('cursor', 'auto');
}

function ricerca()
{
	
}
function infoimmobile(idimmobile)
{
  $("*").css("cursor", "progress");
  $.post("ajaxhelper.php","funz=apriinfoimmobile&id="+idimmobile,function(retdata)  {
  $("*").css("cursor", "auto");																	  $("#LayerRichiestaInfoImmobile").html(retdata);
  if(bIsMobile==true) $("#LayerRichiestaInfoImmobile").centermobile();
  else $("#LayerRichiestaInfoImmobile").center();
  $("#LayerRichiestaInfoImmobile").slideDown(2000);
  });
}
function inviarichiestainfoimmobile()
{
  var strQuery="funz=inviarichiestainfoimmobile";
  var controlli = $("#NOME,#COGNOME,#TELEFONO,#EMAIL,#PRIVACY,#NOTE");
  $.each(controlli, function() {
    strQuery+="&"+(this.id)+"="+encodeURIComponent($(this).val());               
  });
  $("*").css("cursor", "progress");
  $.post("ajaxhelper.php",strQuery,function(retdata) {
    $("*").css("cursor", "auto");
    eval(retdata);
  });
}

function ricerca()
{
 var strQuery="funz=effettuaricerca";
  var controlli = $("#TIPOIMMOBILE,#LOCALITA,#TIPOCONTRATTO,#PREZZOMINIMO,#PREZZOMASSIMO");
  $.each(controlli, function() {
    strQuery+="&"+(this.id)+"="+encodeURIComponent($(this).val());               
  });
  $("*").css("cursor", "progress");
  $.post("ajaxhelper.php",strQuery,function(retdata) {
    $("*").css("cursor", "auto");
	var res=jQuery.parseJSON( retdata ); 
	$("#LayerContenuto").html(res);
	$.post("ajaxhelper.php","funz=bloccoricerca",function(retdata2) {
	  var res2=jQuery.parseJSON( retdata2 );
	  $("#bloccoperricerca").html(res2);
	});													  
  });
}

function ControlloAxl(strEvento,strIdControllo)
{
 var strEvID=strEvento+"_"+strIdControllo.id;
 switch(strEvID)
 {
	default: break; 
 }
}

var hPIEPopUp;
function popupimmagine(idimm)
{
  var strQuery="funz=popupimmagine&id="+idimm;
  $("*").css("cursor", "progress");
  $.post("ajaxhelper.php",strQuery,function(retdata) {
    $("*").css("cursor", "pointer");
    $("#LayerPopupImmagine").html(retdata);
	$("#LayerPopupImmagine").center();
	 if($.browser.msie) 
     {
	  var element=document.getElementById("LayerPopupImmagine");
	  hPIEPopUp=element.addBehavior ("img/PIE.htc");
	 }
	$("#LayerPopupImmagine").slideDown(2000);
  });
}

function popup_forward()
{
 var strQuery="funz=popupforward";
  $("*").css("cursor", "progress");
  $.post("ajaxhelper.php",strQuery,function(retdata) {
  $("*").css("cursor", "pointer");
  eval(retdata);
  });
}

function popup_back() 
{
  var strQuery="funz=popupback";
  $("*").css("cursor", "progress");
  $.post("ajaxhelper.php",strQuery,function(retdata) {
  $("*").css("cursor", "pointer");
  eval(retdata);
  });
}

function popup_chiudi()
{
 if($.browser.msie) 
 {
 var element=document.getElementById("LayerPopupImmagine");
 element.removeBehavior (hPIEPopUp);
 }
 $('#LayerPopupImmagine').slideUp(2000);
}

function menu_home()
{
 window.location.href="index.php";	
}
function menu_azienda()
{
	$("#LayerContenuto").html("<br><br><br><div align=\"justify\" class=\"testopagineinterne\"><blockquote><blockquote>Dal 1978 professionisti nella mediazione immobiliare integrata con i servizi finanziari, offre ai suoi cliente il giusto equilibrio tra realizzazione di un sogno d'impegno economico, ovvero l'acquisto dell'immobile ed il suo finanziamento.<br><br>Il nostro gruppo e' sempre alla ricerca di prodotti fra i piu' innovativi e flessibili, per presentare alla clientela non il mutuo, ma il suo mutuo, ovvero un finanziamento studiato in base alle esigenze del singolo e della famiglia, qualcosa che, nonostante l'andamento del marcato possa offrire ancora la possibilita' a tutti di poter acquistare un'immobile.</blockquote></blockquote></div>");
}
function menu_contatti()
{
	$("*").css("cursor", "progress");
	$.post("ajaxhelper.php","funz=menucontatti",function(retdata) {
    $("*").css("cursor", "auto");
    $("#LayerContenuto").html(jQuery.parseJSON(retdata));
  });
}

function invia_contatti()
{
	 var strQuery="funz=inviacontatti";
  var controlli = $("#NOME,#COGNOME,#TELEFONO,#EMAIL,#PRIVACY,#RICHIESTA");
  if($('#PRIVACY').attr('checked')==false)  { alert("L'accettazione della privacy policy e' obbligatoria"); return; }
  $.each(controlli, function() {
    strQuery+="&"+(this.id)+"="+encodeURIComponent($(this).val());               
  });
  $("*").css("cursor", "progress");
  $.post("ajaxhelper.php",strQuery,function(retdata) {
    $("*").css("cursor", "auto");
    eval(retdata);
  });
}
