function goPop(theURL,winName,features,popWidth,popHeight,winAlign,ignorelink,alwaysOnTop,autoCloseTime,borderless) { //v2.0
  var leftPos=0,topPos=0,autoCloseTimeoutHandle, ontopIntervalHandle, w = 480, h = 340;
  if (popWidth > 0) features += (features.length > 0 ? ',' : '') + 'width=' + popWidth;
  if (popHeight > 0) features += (features.length > 0 ? ',' : '') + 'height=' + popHeight;
  if (winAlign && winAlign != "" && popWidth > 0 && popHeight > 0) {
    if (document.all || document.layers || document.getElementById) {w = screen.availWidth; h = screen.availHeight;}
    if (winAlign.indexOf("center") != -1) {topPos = (h-popHeight)/2;leftPos = (w-popWidth)/2;}
    if (winAlign.indexOf("bottom") != -1) topPos = h-popHeight; if (winAlign.indexOf("right") != -1) leftPos = w-popWidth;
    if (winAlign.indexOf("left") != -1) leftPos = 0; if (winAlign.indexOf("top") != -1) topPos = 0;


    features += (features.length > 0 ? ',' : '') + 'top=' + topPos+',left='+leftPos;}
  if (document.all && borderless && borderless != "" && features.indexOf("fullscreen") != -1) features+=",fullscreen=1";
  if (window["popupWindow"] == null) window["popupWindow"] = new Array();
  var wp = popupWindow.length;
  popupWindow[wp] = window.open(theURL,winName,features);
  if (popupWindow[wp].opener == null) popupWindow[wp].opener = self;
  if (document.all || document.layers || document.getElementById) {
    if (borderless && borderless != "") {popupWindow[wp].resizeTo(popWidth,popHeight); popupWindow[wp].moveTo(leftPos, topPos);}
    if (alwaysOnTop && alwaysOnTop != "") {
      ontopIntervalHandle = popupWindow[wp].setInterval("window.focus();", 50);
      popupWindow[wp].document.body.onload = function() {window.setInterval("window.focus();", 50);}; }
    if (autoCloseTime && autoCloseTime > 0) {
      popupWindow[wp].document.body.onbeforeunload = function() {
        if (autoCloseTimeoutHandle) window.clearInterval(autoCloseTimeoutHandle);
        window.onbeforeunload = null;	}
       autoCloseTimeoutHandle = window.setTimeout("popupWindow["+wp+"].close()", autoCloseTime * 1000); }
    window.onbeforeunload = function() {for (var i=0;i<popupWindow.length;i++) popupWindow[i].close();}; }
  document.MM_returnValue = (ignorelink && ignorelink != "") ? false : true;
}

function in_array(the_needle, the_haystack){
  var the_hay = the_haystack.toString();
  if(the_hay == ''){
    return false;
  }
  var the_pattern = new RegExp(the_needle, 'g');
  var matched = the_pattern.test(the_haystack);
  return matched;
}
// JavaScript Document

// Correctly handle PNG transparency in Win IE 5.5 or higher.
// http://homepage.ntlworld.com/bobosola. Updated 02-March-2004

function correctPNG() {
   for(var i=0; i<document.images.length; i++)
      {
    var img = document.images[i]
    var imgName = img.src.toUpperCase()
    if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
       {
     var imgID = (img.id) ? "id='" + img.id + "' " : ""
     var imgClass = (img.className) ? "class='" + img.className + "' " : ""
     var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
     var imgStyle = "display:inline-block;" + img.style.cssText
     if (img.align == "left") imgStyle = "float:left;" + imgStyle
     if (img.align == "right") imgStyle = "float:right;" + imgStyle
     if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
     var strNewHTML = "<span " + imgID + imgClass + imgTitle
     + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
       + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
     + "(src=\'" + img.src + "\', sizingMethod='image');\"></span>"
     img.outerHTML = strNewHTML
     i = i-1
  }
  }
}

function tipo(n) {
  $('barred').style.backgroundImage="url('img/bar_"+n+".jpg')";
  var url = baseurl+'lib/xml/form_home.php';
  var pars = 'tipo='+n;
  var myAjax = new Ajax.Updater('form',url ,
                {method: 'get', parameters: pars}
                );

  o=$('tipologia_id');

  var url = baseurl+'uramakisan/_modules/immobili/tipologie.xml.php';
  var pars = 'tipo='+n;
  var myAjax = new Ajax.Request(
          url,
          {method: 'get', parameters: pars, onComplete: tipologieXMLHandler}
  );
}

function tipologieXMLHandler(req) {
  o=document.getElementById('tipologia_id');

  while(o.hasChildNodes()) {
    o.removeChild(o.lastChild);
  }
  option=document.createElement('option');
  option.setAttribute('value', '');
  option.innerHTML='Tipologia';
  o.appendChild(option);

  tipologieNode=req.responseXML.documentElement;
  for (i=0;i<tipologieNode.childNodes.length; i++) {
    tipologiaNode=tipologieNode.childNodes[i];
    tipologiaIdNode=tipologiaNode.firstChild;
    tipologiaNameNode=tipologiaIdNode.nextSibling;
    option=document.createElement('option');
    option.setAttribute('value', tipologiaIdNode.firstChild.nodeValue);
    option.innerHTML=tipologiaNameNode.firstChild.nodeValue;
    o.appendChild(option);
  }
}

function showHide(whichLayer) {
  if (document.getElementById) { 	// this is the way the standards work
    var style2 = document.getElementById(whichLayer);
    if(style2.className=="mostra"){
      style2.className="nascondi";
    } else {
      style2.className="mostra";
    }
  } else if (document.all) { 		// this is the way old msie versions work
    var style2 = document.all[whichLayer];
    if(style2.className=="mostra"){
      style2.className="nascondi";
    } else {
      style2.className="mostra";
    }
  } else if (document.layers) { 	// this is the way nn4 works
    var style2 = document.layers[whichLayer];
    if(style2.className=="mostra"){
      style2.className="nascondi";
    } else {
      style2.className="mostra";
    }
  }
}

function doLogin(o) {
  var plainPasswd=o.plainpassword.value;
  o.password.value=hex_md5(plainPasswd);
  o.plainpassword.value="";
  return true;
}

// DIV Cliccabile
function goToURL() {
  window.location = baseurl+"index.php";
}
var oldHtmlFiltro;
function atnz() {
  oldHtmlFiltro = $('immobile_dettagli').innerHTML;
    if ($('citta')) {
      var x=$('citta')
      var ct= x.value
      var tx= x.options[x.selectedIndex].text
      filtra ('lib/xml/zone.php','zn_city', 'citta='+x.value);
      $('city').value=ct;
      $('cname').innerHTML='<strong>Citt&agrave;:</strong> '+tx;
      filtra ('listaimmobili.php', 'immobile_dettagli', Form.serialize('agenziefiltra'));
  }
}

function filtra (page, element, filter) {
  var url    = baseurl+page;
  var pars   = filter+"&m="+ new Date().getTime();
  var myAjax = new Ajax.Updater(element,url ,
                {method: 'get', parameters: pars, evalScripts: true}
                );
}

function selZ (id) {
  var x=$(id);
  var cnt=0;
  if (id=='zona') {
    var item='Zone';
  } else {
    var item='Citt&agrave;';
  }
  for (var i=0; i<x.length; i++) {
    if (x.options[i].selected==true) {
      cnt++;
    }
  }
  if($('citta_s')) {
    var x=$('citta_s');
    var tx= x.options[x.selectedIndex].text;
    $('cname').innerHTML='<strong>Citt&agrave;:</strong> '+tx;
  }
  $('selezionate').innerHTML= item+' selezionate ' +cnt;
}

var oldTab;
function tabperiodo (id) {
  if(!oldTab) {
    oldTab = $('immobile_dettagli').innerHTML;
  }
  var url    = baseurl+'periodotab.php';
  var pars   = 'id='+id+"&m="+ new Date().getTime();
  var myAjax = new Ajax.Updater(id, url ,
                {method: 'get', parameters: pars}
                );
}
function chiudi(id){
  $(id).innerHTML = oldTab;
}

var oldH;
function inviaAmico(filter) {
	if ($('danome').value=="" || $('anome').value=="" || $('aemail').value=="" || $('msg').value=="") {
		alert ('devi compilare tutti i campi obbligatori contrassegnati da *');
		return false;
  } else 	if ($('inviaamico_checkAgree').checked == false) {
				alert ('devi accettare le note sulla privacy');			
				return false;
	} else {
	  oldH = $('rataresult').innerHTML;
  	var url    = 'amico.php';
  	var pars   = filter+"&m="+ new Date().getTime();
  	var myAjax = new Ajax.Request(url ,
                {method: 'get', parameters: pars, onComplete: alert('Email correttamente inviata')}
                );
  }
}
function backFiltro () {
  $('immobile_dettagli').innerHTML = oldHtmlFiltro;
}

var oldR;
function rata(filter) {
  oldH = $('ratadiv').innerHTML;
  var url    = 'rataAjax.php';
  var pars   = filter+"&m="+ new Date().getTime();
  var myAjax = new Ajax.Updater('ratadiv',url ,
                {method: 'get', parameters: pars}
                );
}
function ripristina (){
  $('ratadiv').innerHTML = oldH;
}

function sowperiodo (id) {
  oldTab="";
  var url    = baseurl+'periodotab.php';
  var pars   = 'id='+id+"&m="+ new Date().getTime()+'&g=g';
  var myAjax = new Ajax.Updater('periodo_tab', url ,
                {method: 'get', parameters: pars}
                );
}
function vAll(){
  $('cname').innerHTML='<strong>Citt&agrave;:</strong> Nessun parametro';
  $('pname').innerHTML='<strong>Provincia:</strong> Nessun parametro';
  $('rname').innerHTML='<strong>Regione:</strong> Nessun parametro';
  filtra ('lib/xml/citta.php','cit_sel', 'prov=');
}

function check(form) {
	if(($('cognome').value == '') || ($('nome').value == '') || ($('email').value == '') || ($('citta').value == '') || ($('note').value == '')) {
		alert ('devi compilare tutti i campi obbligatori contrassegnati da *');
		return false;
	}
	if ($(form+'_checkAgree')) {
		if ($(form+'_checkAgree').checked == false) {
			alert ('devi accettare le note sulla privacy');			
			return false;
		}
	}
}

function checkF(formId) {
  var lista = $(formId).getElementsByTagName('input');
  var array = new Array(
    'cognome',
    'nome',
    'citta',
    'email'
  );
  for (i=0;i<lista.length;i++){
    if(in_array(lista[i].name, array) && (lista[i].value == '')) {
        lista[i].setAttribute("style", "border:1px solid red;");
        var alrt = 'err!';
    }
  }
  if (alrt=='err!') {
    alert ('devi compilare tutti i campi obbligatori');
    return false;
  }
}

function tipoC() {
  n = $('tipo_c').value;
  o=$('tipologia_id');
  var url = baseurl+'uramakisan/_modules/immobili/tipologie.xml.php';
  var pars = 'tipo='+n;
  var myAjax = new Ajax.Request(
          url,
          {method: 'get', parameters: pars, onComplete: tipologieXMLHandler, evalScripts: true}
  );
}
function getWeeks(year, month, start) {
  if(year > 0 && month > 0) {
    var url  = baseurl+'lib/xml/_settimane.php';
    var pars = 'y='+year+'&m='+month+'&d='+start;
    var myAjax = new Ajax.Updater('pweekDiv', url, {method: 'get', parameters: pars});
  }
}

function turistico(n) {
  if(n=='1') {
    $('pmese').style.visibility='hidden';
    $('pweekDiv').style.visibility='hidden';
  } else {
    $('pmese').style.visibility='visible';
    $('pweekDiv').style.visibility='visible';
  }
}

/* SLIDESHOW START */
var interval = 6000;
var ImgNum = 0;
var tot_img = 0;

/* image counting */
function initImg() {
  fader = new fx.Opacity('big_img');
  var nodes = new Array();
  var preloadImages = new Array();
  for(var i=0; i<10; i++) {
    if($('img'+i)) {
      nodes[i] = $('img'+i).src;
      preloadImages[i] = new Image();
      preloadImages[i].src = $('img'+i).src.replace("thumb", "preview");
    } else {
      break;
    }
  }
  tot_img = nodes.length;
}

/* get next image */
function getNextImg() {
  ImgNum = (ImgNum+1) % tot_img;
  var new_img = $('img'+ImgNum).src.replace("thumb", "preview");
  return new_img;
}
/*show previous image*/
function getPrevImg() {
  ImgNum = (ImgNum-1) % tot_img;
  if(ImgNum ==-1) {
    ImgNum = tot_img-1;
  }
  var new_img = $('img'+ImgNum).src.replace("thumb", "preview");
  return new_img;
}
function prevImg() {
  var new_img = getPrevImg();
  fader.custom(0.2, 1);
  $('big_img').src = new_img;
  $('did_img').innerHTML = $('img'+ImgNum).alt;
  clearTimeout(timerImgID);
}

/*show next image*/
function nextImg() {
  var new_img = getNextImg();
  fader.custom(0.2, 1);
  $('big_img').src = new_img;
  $('did_img').innerHTML = $('img'+ImgNum).alt;
  clearTimeout(timerImgID);
}

/*thumbnail onclick*/
function thisImg(id) {
  ImgNum = id;
  var new_img = $('img'+ImgNum).src.replace("thumb", "preview");
  fader.custom(0.2, 1);
  $('big_img').src = new_img;
  $('did_img').innerHTML = $('img'+ImgNum).alt;
  clearTimeout(timerImgID);
}
/*show images*/
function rotateImage() {
  var new_img = getNextImg();
  fader.custom(0.2, 1);
  $('big_img').src = new_img;
  fader.custom(1, 0.2);
  $('did_img').innerHTML = $('img'+ImgNum).alt;
  var recur_call = "rotateImage()";
  if (tot_img > 1) {
    timerImgID = setTimeout(recur_call, interval);
  }
}
/*SLIDESHOW END*/
var ImgCount = 0;
var imgs = new Array();

function selImgToPrint(id){
  if($('D'+id).className == 'unselected') {
    $('D'+id).className = 'selected';
    var i = document.createElement('input');
    i.setAttribute('type', 'hidden');
    i.setAttribute('value', id);
    i.id = 'i'+id;
    i.name = 'i'+id;
    $('imgsForm').appendChild(i);
  } else {
    $('D'+id).className = 'unselected';
    $('imgsForm').removeChild($('i'+id));
  }
}
