
var stile = "top=10, left=10, width=250, height=200, status=no, menubar=no, toolbar=no scrollbar=no";
var id_nascosti;
var ind;

//window.onload=read_list_cookies();
// window.onunload=save_list_cookies();

/*
function save_list_cookies(days){
if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
}
  else {
	document.cookie=""
 	  document.cookie = "style="+id_nascosti+";"+expires+"; path=/";
}
}*/
function getIEVersion(){
	if (navigator.appName=='Microsoft Internet Explorer'){
		if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){
			return new Number(RegExp.$1);
		}
	}
	return false;
}
jQuery.setSession=function(sessionName,sessionValue){
	$.ajax({
	type: "POST",
	url: "/ph_ajax",
	dataType: "html",
	data: "action=setSession&sessionName="+sessionName+"&sessionValue="+sessionValue,
	success: function(xml) {
		return;
	}});
	return false;
}
jQuery.goToView=function(sr,view){
	$('#'+sr).empty().append('<span title="Loading..."><img src="/img/PH2008/VIEWSHORT09/loading.gif"/></span>');
	$.ajax({
	type: "POST",
	url: "/ph_ajax",
	dataType: "html",
	data: "action=setSession&sessionName=view&sessionValue="+view,
	success: function(xml) {
		window.location.href=window.location.href;
	}});
	return false;	
}
jQuery.getContactRow=function(sr,id_ann){
	$('#'+sr).append('<span title="Loading..."><img src="/img/PH2008/VIEWSHORT09/loading.gif"/></span>');
	$.ajax({
	type: "POST",
	url: "/ph_ajax",
	dataType: "html",
	data: "action=getContactRow&id_ann="+id_ann,
	success: function(xml) {
		var app=$(xml).find('#append');
		if (app)
			$('#'+sr).empty().append($(app).html());
		}
	});
	return false;
}
jQuery.getContactPrefsRow=function(sr,id_ann){
	$('#'+sr).append('<span title="Loading..."><img src="/img/PH2008/VIEWSHORT09/loading.gif"/></span>');
	$.ajax({
	type: "POST",
	url: "/ph_ajax",
	dataType: "html",
	data: "action=getContactPrefsRow&id_ann="+id_ann,
	success: function(xml) {
		var app=$(xml).find('#append');
		if (app)
			$('#'+sr).empty().append($(app).html());
		}
	});
	return false;
}
jQuery.getContactDetail=function(sr,id_ann){
	$('#'+sr).append('<span title="Loading..."><img src="/img/PH2008/VIEWSHORT09/loading.gif"/></span>');
	$.ajax({
	type: "POST",
	url: "/ph_ajax",
	dataType: "html",
	data: "action=getContactDetail&id_ann="+id_ann,
	success: function(xml) {
		var app=$(xml).find('#append');
		if (app)
			$('#'+sr).empty().append($(app).html());
		}
	});
	return false;
}
jQuery.getDefaultPhoto=function(sr,id_ann){
	$('#'+sr).append('<span title="Loading..."><img src="/img/PH2008/VIEWSHORT09/loading.gif"/></span>');
	$.ajax({
	type: "POST",
	url: "/ph_ajax",
	dataType: "html",
	data: "action=getDefaultPhoto&id_ann="+id_ann,
	success: function(xml) {
		var app=$(xml).find('#append');
		if (app)
			$('#'+sr).empty().append($(app).html());
		}
	});
	return false;
}
function read_list_cookies(id_to_set){
	var cookies=document.cookie;
	var reference="style=";
	 // Separate each cookie.
	var cookieList = document.cookie.split("; ");
	// Array for each cookie in cookieList
	var cookieArray = new Array();
	for (var i = 0; i < cookieList.length; i++) {
		// Separate name-value pairs.
		var name = cookieList[i].split("=");
		// Decode and add to cookie array.
		cookieArray[unescape(name[0])] = unescape(name[1]);
	}
		if (cookieArray['style']){
			valore=cookieArray['style'];
			ids=valore.split("-");
			for(var j=0;j<ids.length;j++){
				if (ids[j]==id_to_set){
					setstyle('super_short_'+ids[j],"");
					setstyle('short_'+ids[j],"none");
				}
// 				ShowHideList('super_short_'+ids[j],'short_'+ids[j]);
			}
		}
// 		alert(valore.replace(reference,""));
// 		return valore.replace(reference,"");
	}


function insert_in_list_cookies(id_hided,days){
 // Separate each cookie.
var cookieList = document.cookie.split("; ");
// Array for each cookie in cookieList
var cookieArray = new Array();
for (var i = 0; i < cookieList.length; i++) {
// Separate name-value pairs.
var name = cookieList[i].split("=");
// Decode and add to cookie array.
cookieArray[unescape(name[0])] = unescape(name[1]);
}

if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
}
  else {
	document.cookie = "style="+cookieArray['style']+"-"+id_hided+";"+expires+"; path=/";
}
}

function delete_from_list_cookies(id_visible,days){
 // Separate each cookie.
var cookieList = document.cookie.split("; ");
// Array for each cookie in cookieList
var cookieArray = new Array();
for (var i = 0; i < cookieList.length; i++) {
// Separate name-value pairs.
var name = cookieList[i].split("=");
// Decode and add to cookie array.
cookieArray[unescape(name[0])] = unescape(name[1]);
}

if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
}
  else {
	document.cookie = "style="+cookieArray['style'].replace(id_visible,"")+";"+expires+"; path=/";
}
}


function init_column_display(){
	url=window.location.href;
	if (url.search('embedded_object')!='-1'){ 
		Hide('header');
		if (document.getElementById('main_column')){
			var el=document.getElementById('main_column');
			el.style.marginLeft=0;
			el.style.marginRight=0;
		}
// 		Hide('left_column');
// 		var el=document.getElementById('left_column');
// 			el.style.width=0;
		Hide('right_column');
		if (document.getElementById('right_column')){
			var el=document.getElementById('right_column');
			el.style.width=0;
		}
		Hide('footer');
		if (document.getElementById('footer')){
			var el=document.getElementById('footer');
			el.style.height=0;
		}
	}
	
}

function goToUrl(url){
	window.location=url;
}

function torna_alla_lista(co,av,city,tipo){
	var url=window.location.href;
	if (url.search('embedded_object')!='-1'){
		window.open("http://www.phosphoro.com/lista/annunci/casa/short_casa/1?public___annunci_casa__pxcmsfilter__cerco_offro="+co+"&public___annunci_casa__pxcmsfilter__affitto_vendo="+av+"&public___annunci_casa__pxcmsfilter__tipo_alloggio="+tipo+"&public___annunci_casa__pxcmsfilter__city="+city+"&public___annunci_casa__pxcmsfilter__price_obj=&public___annunci_casa__pxcmsfilter__id=&global_dynamic_counter=0&filter=apply&reload");
	}
	else {
		window.status='tornando alla lista';
		window.location="http://www.phosphoro.com/lista/annunci/casa/short_casa/1?public___annunci_casa__pxcmsfilter__cerco_offro="+co+"&public___annunci_casa__pxcmsfilter__affitto_vendo="+av+"&public___annunci_casa__pxcmsfilter__tipo_alloggio="+tipo+"&public___annunci_casa__pxcmsfilter__city="+city+"&public___annunci_casa__pxcmsfilter__price_obj=&public___annunci_casa__pxcmsfilter__id=&global_dynamic_counter=0&filter=apply&reload";
	}
	return;
}


function ShowHideList(id){
//memorizzo gli id di quelli nascosti, quindi memorizzo l'id solo se l'id che va in display yes contiene super_short
if(document.getElementById(id)){
    var el=document.getElementById(id);
	if (el.style.display==""){
		el.style.display="none";
	}else{
		el.style.display="";
		if (id.search("super_short")!="-1")
			insert_in_list_cookies(id.replace("super_short_",""));
		else 
			delete_from_list_cookies(id.replace("short_",""));
	}
    }
}

function setstyle(id,value){
	if(document.getElementById(id)){
    	var el=document.getElementById(id);
	el.style.display = value;
	}
}


function Popup(file) {
	window.open(file, "", stile);
}


function PopupCentrata(file) {
	var w = 530;
	var h = 530;
	var l = Math.floor((screen.width-w)/2);
	var t = Math.floor((screen.height-h)/2);
	window.open(file,"","width=" + w + ",height=" + h + ",top=" + t + ",left=" + l);
 }
 
function Show(id){
if(document.getElementById(id)){
    var el=document.getElementById(id);
	el.style.display = "";
    }
}

function ShowName(tagname){
if (document.getElementsByTagName('span')){
	var tag = document.getElementsByTagName('span'); 
	for (var i = 0; i < tag.length; i++) { 
		if (tag[i].getAttribute('name') == tagname)
			tag[i].style.display = "";
	}
}
}

function HideName(tagname){
if (document.getElementsByTagName('span')){
	var tag = document.getElementsByTagName('span'); 
	for (var i = 0; i < tag.length; i++) { 
		if (tag[i].getAttribute('name') == tagname)
			tag[i].style.display = "none";
    	}
}
}

function ShowTag(tagname){
if (document.getElementsByTagName(tagname)){
	var tag = document.getElementsByTagName(tagname); 
	for (var i = 0; i < tag.length; i++) { 
		tag[i].style.display = "";
    	}
}
}

function HideTag(tagname){
if (document.getElementsByTagName(tagname)){
	var tag = document.getElementsByTagName(tagname); 
	for (var i = 0; i < tag.length; i++) { 
		tag[i].style.display = "none";
    	}
}
}



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

function ShowHide(id){
if(document.getElementById(id)){
    var el=document.getElementById(id);
	el.style.display = (el.style.display=="") ? "none" : "";
    }
}



function setShowHide(id){
// 	alert("id value: "+id);
// 	setstyle=readCookie(id,"style")
// 	if (setstyle!=-1){
// 		if(document.getElementById(id)){
// 			var el=document.getElementById(id);
// 			if (setstyle=="") el.style.display = "";
// 			else el.style.display = setstyle;
// 		}
// 	}
}

function ShowHideChange(id1,id2){
	ShowHide(id1);
	ShowHide(id2);
}

function ShowHideChange3(id1,id2,id3){
	ShowHide(id1);
	ShowHide(id2);
	ShowHide(id3);
}

function ShowHideChange4(id1,id2,id3,id4){
	ShowHide(id1);
	ShowHide(id2);
	ShowHide(id3);
	ShowHide(id4);
}

function ShowHideChangeList(id1,id2){
	ShowHideList(id1);
	ShowHideList(id2);
}

function ShowHideChangeList3(id1,id2,id3){
	ShowHideList(id1);
	ShowHideList(id2);
	ShowHideList(id3);
}

function ShowHideChangeList4(id1,id2,id3,id4){
	ShowHideList(id1);
	ShowHideList(id2);
	ShowHideList(id3);
	ShowHideList(id4);
}

function getInputCampo(id,Campo){
if(document.getElementById('public_annunci_casa__'+id+'__'+Campo)){
	var el=document.getElementById('public_annunci_casa__'+id+'__'+Campo);
	return el.value;
	} else {alert("public_annunci_casa__"+id+"__"+Campo+" not found");}
}

function completaLatLon(id){
	if (!id)
		id="";
	var indirizzo=getInputCampo(id,"indirizzo_casa");
	var numero=getInputCampo(id,"num_civ_casa");
	var city=getInputCampo(id,"city");
	var stato=getInputCampo(id,"stato");
	if (indirizzo=="" || city=="" || stato==""){
		return;
	}
	var coordinates=new Array();
	var address=indirizzo+" "+numero+", "+city+", "+stato;
	var geocoder = new GClientGeocoder();
	LatLon=geocoder.getLatLng(address,function(point) {
     		 if (point) {
			document.getElementById("public_annunci_casa__"+id+"__latitudine").value=point.lat();
			document.getElementById("public_annunci_casa__"+id+"__longitudine").value=point.lng();
			alert("added coordinates");
      		} else alert(address+" not found");
    }
  )
}

function verificaLatLon(address){
	var response;
	var coordinates=new Array();
	var geocoder = new GClientGeocoder();
	LatLon=geocoder.getLatLng(address,function(point) {
     		 if (point) {
			response=1;
      		} else response=0;
    	});
	setTimeout("",1250);
	return response;
}

function addEvent( obj, type, fn ) {
  if (obj.addEventListener)
    obj.addEventListener(type, fn , true);
else if (obj.attachEvent)
    obj.attachEvent("on"+type, fn);
}

function removeEvent( obj, type, fn ) {
  if (obj.removeEventListener)
    obj.removeEventListener(type, fn , true);
else if (obj.detachEvent)
    obj.detachEvent("on"+type, fn);
}


function salva_lista(nome){
	var elementi=document.getElementsByName(nome);
	for(var i=0;i<elementi.length;i++){
		var id_val=elementi[i].innerHTML;
// 		dummy_window=new window();
// 		dummy_window=window.open()
// 		var save_form=document.getElementById('public_annunci_casa__'+id_val);
// 		addEvent(save_form,'submit',(function(){return alert('prova');}));
		document.forms['public_annunci_casa__'+id_val].submit();
// 		dummy.close();
// 		dummy.onload=(function(){ /*window.forms[';*/ window.close();});
	}
}

function carica_valore(id_origine,id_destinazione){
	if((document.getElementById(id_origine)) && (document.getElementById(id_destinazione))) 
    		document.getElementById(id_destinazione).value=document.getElementById(id_origine).innerHTML;
}

function assegna_valore(id_origine,valore){
	if(document.getElementById(id_origine)) 
    		document.getElementById(id_origine).value=valore;
}


function carica_gestore(){
	var inp=document.getElementsByName('input_selezione');
	var tel=document.getElementsByName('tel');
	var cell=document.getElementsByName('cell');
	var mail=document.getElementsByName('mail');
	var nome=document.getElementsByName('nome');
	var cognome=document.getElementsByName('cognome');
	for(var i=0;i<inp.length;i++){
		if (inp[i].checked){
			window.opener.document.getElementById("anag_tel").innerHTML=tel[i].innerHTML;
			window.opener.document.getElementById("anag_cell").innerHTML=cell[i].innerHTML;
			window.opener.document.getElementById("anag_mail").innerHTML=mail[i].innerHTML;
			window.opener.document.getElementById("anag_nome").innerHTML=nome[i].innerHTML;
			window.opener.document.getElementById("anag_cognome").innerHTML=cognome[i].innerHTML;
			window.opener.document.getElementsByName("nome")[1].checked=true;
			window.opener.document.getElementsByName("cognome")[1].checked=true;
			window.opener.document.getElementsByName("tel")[1].checked=true;
			window.opener.document.getElementsByName("cell")[1].checked=true;
			window.opener.document.getElementsByName("mail")[1].checked=true;
			window.opener.elimina_nome();
			window.opener.elimina_cognome();
			window.opener.elimina_tel();
			window.opener.elimina_cell();
			window.opener.elimina_mail();
		}
	window.close();
	}
}

function onkeysubmit(keycode,todo,e){
	if (window.event) key = window.event.keyCode;
	else if (e) key = e.which;
	if (key==keycode){
		if (window.event) key = window.event.keyCode;
		else if (e) key = e.which;
		if (key==keycode){
			std_submit(todo);
		}
	}
}


// Title: Timestamp picker
// Description: See the demo at url
// URL: http://us.geocities.com/tspicker/
// Script featured on: http://javascriptkit.com/script/script2/timestamp.shtml
// Version: 1.0
// Date: 12-05-2001 (mm-dd-yyyy)
// Author: Denis Gritcyuk <denis@softcomplex.com>; <tspicker@yahoo.com>
// Notes: Permission given to use this script in any kind of applications if
//    header lines are left unchanged. Feel free to contact the author
//    for feature requests and/or donations
//
// This script has been adapted for using in www.phosphoro.com website

function show_calendar(id_str_target, id_dest2, actual_date, month) {

	var str_target=document.getElementById(id_str_target);
	
	if (!actual_date)
		if (str_target.value)
			var actual_date=str2dt(str_target.value);
		else actual_date = new Date();
	else var actual_date = new Date(actual_date);
	

	var arr_months = ["Gennaio","Febbraio","Marzo","Aprile","Maggio","Giugno","Luglio","Agosto","Settembre","Ottobre","Novembre","Dicembre"];
	var week_days = ["Dom","Lun","Mar","Mer","Gio","Ven","Sab"];
	var n_weekstart = 1; // day week starts from (normally 0 or 1)

	dt_datetime = new Date(actual_date);
	
	if (month=='previous'){
		dt_datetime.setMonth(dt_datetime.getMonth()-1);
		actual_date.setMonth(actual_date.getMonth()-1);
	}
	if (month=='next'){
		dt_datetime.setMonth(dt_datetime.getMonth()+1);
		actual_date.setMonth(actual_date.getMonth()+1);
	}
	var dt_next_month= new Date(dt_datetime);
	dt_next_month.setMonth(dt_next_month.getMonth()+1);
	var dt_firstday = new Date(dt_datetime);
	dt_firstday.setDate(1);
	dt_firstday.setDate(1-(7+dt_firstday.getDay()-n_weekstart)%7);
	var dt_lastday = new Date(dt_next_month);
	dt_lastday.setDate(0);
	
	// html generation (feel free to tune it for your particular application)
	// print calendar header
	var str_buffer = new String (
		"<html>\n"+
		"<head>\n"+
		"	<title>Calendar</title>\n"+
		"</head>\n"+
		"<body bgcolor=\"White\">\n"+
		"<table class=\"clsOTable\" cellspacing=\"0\" border=\"0\" width=\"100%\">\n"+
		"<tr><td bgcolor=\"#4682B4\">\n"+
		"<table cellspacing=\"1\" cellpadding=\"3\" border=\"0\" width=\"100%\">\n"+
		"<tr>\n	<td bgcolor=\"#4682B4\"><a href=\"javascript:window.opener.show_calendar('"+
		id_str_target+"','"+id_dest2+"','"+actual_date+"', 'previous');\">"+
		"<img src=\"/img/buttons/previous.png\" width=\"16\" height=\"16\" border=\"0\""+
		" alt=\"previous month\"></a></td>\n"+
		"	<td bgcolor=\"#4682B4\" colspan=\"5\">"+
		"<font color=\"white\" face=\"tahoma, verdana\" size=\"2\">"
		+arr_months[dt_datetime.getMonth()]+" "+dt_datetime.getFullYear()+"</font></td>\n"+
		"	<td bgcolor=\"#4682B4\" align=\"right\"><a href=\"javascript:window.opener.show_calendar('"
		+id_str_target+"','"+id_dest2+"','"+actual_date+"','next');\">"+
		"<img src=\"/img/buttons/next.png\" width=\"16\" height=\"16\" border=\"0\""+
		" alt=\"next month\"></a></td>\n</tr>\n"
	);

	var dt_current_day = new Date(dt_firstday);
	// print weekdays titles
	str_buffer += "<tr>\n";
	for (var n=0; n<7; n++)
		str_buffer += "	<td bgcolor=\"#87CEFA\">"+
		"<font color=\"white\" face=\"tahoma, verdana\" size=\"2\">"+
		week_days[(n_weekstart+n)%7]+"</font></td>\n";
	// print calendar table
	str_buffer += "</tr>\n";
	while (dt_current_day.getMonth() == dt_datetime.getMonth() ||
		dt_current_day.getMonth() == dt_firstday.getMonth()) {
		// print row heder
		str_buffer += "<tr>\n";
		for (var n_current_wday=0; n_current_wday<7; n_current_wday++) {
				if (dt_current_day.getDate() == dt_datetime.getDate() &&
					dt_current_day.getMonth() == dt_datetime.getMonth())
					// print current date
					str_buffer += "	<td bgcolor=\"#FFB6C1\" align=\"right\">";
				else if (dt_current_day.getDay() == 0 || dt_current_day.getDay() == 6)
					// weekend days
					str_buffer += "	<td bgcolor=\"#DBEAF5\" align=\"right\">";
				else
					// print working days of current month
					str_buffer += "	<td bgcolor=\"white\" align=\"right\">";

				if (dt_current_day.getMonth() == dt_datetime.getMonth())
					// print days of current month
					str_buffer += "<a href=\"javascript:window.opener.document.getElementById('"+id_str_target+
					"').value='"+dt2dtstr(dt_current_day)+"'; window.close();\">"+
					"<font color=\"black\" face=\"tahoma, verdana\" size=\"2\">";
				else 
					// print days of other months
					str_buffer += "<a href=\"javascript:window.opener.document.getElementById('"+id_str_target+
					"')value='"+dt2dtstr(dt_current_day)+"'; window.close();\">"+
					"<font color=\"gray\" face=\"tahoma, verdana\" size=\"2\">";
				str_buffer += dt_current_day.getDate()+"</font></a></td>\n";
				dt_current_day.setDate(dt_current_day.getDate()+1);
		}
		// print row footer
		str_buffer += "</tr>\n";
	}
	// print calendar footer
	str_buffer +=
		"<form name=\"cal\">\n<tr><td colspan=\"7\" bgcolor=\"#87CEFA\">"+
		"<font color=\"White\" face=\"tahoma, verdana\" size=\"2\">"+
		"</table>\n" +
		"</tr>\n</td>\n</table>\n" +
		"<script type=\"text/javascript\">"+
		"window.unload=init();"+
		"var id_str_target='"+id_str_target+"';"+
		"var id_dest2='"+id_dest2+"';"+
		"function init(){"+
		"window.opener.document.getElementById(id_dest2).value=window.opener.document.getElementById(id_str_target).value; }"+
		"</script>"+
		"</body>\n" +
		"</html>\n";

	var vWinCal = window.open("", "Calendar", 
		"width=250,height=250,status=no,resizable=yes,top=200,left=200");
	vWinCal.opener = self;
	var calc_doc = vWinCal.document;
	calc_doc.write (str_buffer);
	calc_doc.close();
}
// datetime parsing and formatting routimes. modify them if you wish other datetime format
function str2dt (str_datetime) {
	var re_date = /^(\d+)\/(\d+)\/(\d+)$/;
	if (re_date.exec(str_datetime))
		return (new Date (RegExp.$3, RegExp.$2-1, RegExp.$1));	
}
function dt2dtstr (dt_datetime) {
	return (new String (
			dt_datetime.getDate()+"/"+(dt_datetime.getMonth()+1)+"/"+dt_datetime.getFullYear()));
}

var iaz_preserved_elements = [];
var iaz_preserved_zindexes = [];

function ie_apply_zindex(element_id, zindex, context_id) {
   // default values
   if (undefined == zindex) { zindex = 1; }
   var context = (undefined == context_id ? $(context_id) : $(document.body));
   var element = $(element_id);

   // undo past ie_apply_zindex()
   for (i = iaz_preserved_elements.length-1; i >= 0; i--) {
      iaz_preserved_elements[i].setStyle({'z-index': iaz_preserved_zindexes[i]});
   }
   iaz_preserved_elements = [];
   iaz_preserved_zindexes = [];

   // find relative-positioned ancestors of element within context
   element.ancestors().each(
      function(ancestor) {
         if ('relative' == ancestor.getStyle('position')) {
            // preserve ancestor's current z-index
            iaz_preserved_elements.push(ancestor);
            iaz_preserved_zindexes.push( ancestor.getStyle('z-index') );

            // apply z-index to ancestor
            ancestor.setStyle({'z-index': zindex});
         }
         if (ancestor == context) { throw $break; }
      }
   );
}