/*--------------------------------------------------------*
* Copyright (C) 2006 Verthink S.r.l. - Italy
*
* File: main.js
* Author: Aldo Armiento e Osiride Cascioli
* Version: 20060605.1
*---------------------------------------------------------*/

var gvaOptList = new Array();
var gvnACActive = 0;
var gvnACTimeOut = null;
var gvaCheckItem = new Array();
var gvaScrollInt = new Array();
var gvaScrollTID = new Array();
var gvsOldFonteHTMLValue = "";
var gvnCheckRequests = 0;

var MAX_CHECK_REQUEST = 15;

var gvaMiniMaps = new Array();
var gvaMiniMapsTI = new Array();
var gvaMiniMapsLL = new Array();

/*---------------------------------------------------------*
*
*----------------------------------------------------------*/

function contattaDaMappa(nIDAnnuncio)
{
	Lightbox.hideContents();
	Lightbox.showBoxByAJAX(nIDAnnuncio, 615, 197, function() { Lightbox.showContents() });
}

/*---------------------------------------------------------*
*
*----------------------------------------------------------*/

function mapSearch()
{
	var oEl = vslGetHTMLElement("casa_map");
	var oForm = vslGetHTMLElement("frm_casa");
	var oGeo = vslGetHTMLElement("field_casa_dove");
	if (!oEl || !oForm || !oGeo)
		return;

	oEl.value = "1";
	oForm.submit();
}

/*---------------------------------------------------------*
*
*----------------------------------------------------------*/
function mostraDIV()
{

}



function showTimeCheck(sType, sUniqID)
{
	var oXMLReq = vslGetXMLReq();
	if (!oXMLReq) return(false);

	var sURL = '/remote/timeCheck/' + sType.vslURLEncodeR() + '/' + sUniqID + '?r=' + vslGetRand(100000);

	oXMLReq.open('GET', sURL, true);
	oXMLReq.onreadystatechange = function ()
	{	var sRet = '';

		if (oXMLReq.readyState != 4) return(false);

		try
		{	if (oXMLReq.status != 200) return(false);
			sRet = oXMLReq.responseText;
		}
		catch (e)
		{	return(false);
		}

		sRet = sRet.vslTrim();

		alert(sRet);

		return(true);
	}

	oXMLReq.send(null);
}

/*---------------------------------------------------------*
*
*----------------------------------------------------------*/

function miniMapCtrl(sCmd, nPos)
{
	var oGMap = gvaMiniMaps[nPos];

	if (!oGMap)
		return(false);

	try
	{	clearInterval(gvaMiniMapsTI[nPos]);
	}
	catch(e) {}

	switch (sCmd)
	{
		case "zoomin":
			oGMap.zoomIn();
			break;

		case "zoomout":
			oGMap.zoomOut();
			break;

		case "size":

			var nNewHeight = vslGetElementWidth("item_map_" + nPos);
			nNewHeight -= parseInt((nNewHeight / 100) * 40);

			if (nNewHeight <= 0)
				nNewHeight = 300;

			var oEl = vslGetHTMLElement("item_gmap_" + nPos);
			if (!oEl.style)
				return(false);

			var oElToolbarIcon = vslGetHTMLElement("mini_map_size_icon_" + nPos);
			var oElToolbarLabel = vslGetHTMLElement("mini_map_size_label_" + nPos);

			if (!oElToolbarIcon || !oElToolbarLabel)
				return(false);

			if (parseInt(oEl.style.height) < (nNewHeight - 1))
			{
				oEl.style.height = nNewHeight + "px";
				oElToolbarIcon.src = "/vimages/map/Riduci.png";
				oElToolbarLabel.innerHTML = "Riduci mappa";

				vslCollapseEL("item_map_" + nPos, 249, nNewHeight + 50, 20, 25, function ()
				{	oGMap.checkResize();
					oGMap.setCenter(gvaMiniMapsLL[nPos]);
				});
			}
			else
			{
				oElToolbarIcon.src = "/vimages/map/Allarga.png";
				oElToolbarLabel.innerHTML = "Allarga mappa";

				vslCollapseEL("item_map_" + nPos, nNewHeight + 50, 249, -20, 25, function ()
				{	oEl.style.height = "200px";
					oGMap.checkResize();
					oGMap.setCenter(gvaMiniMapsLL[nPos]);
				});
			}

			break;

		case "center":
			oGMap.returnToSavedPosition();
			break;

		case "satellite":
			oGMap.setMapType(G_SATELLITE_MAP);
			break;

		case "mappa":
			oGMap.setMapType(G_NORMAL_MAP);
			break;

		case "ibrida":
			oGMap.setMapType(G_HYBRID_MAP);
			break;

		case "panoramica":
			oGMap.returnToSavedPosition();

			oGMap.zoomOut();

			gvaMiniMapsTI[nPos] = setInterval(function()
			{
				if (oGMap.getZoom() > 11)
				{	oGMap.zoomOut();
				}
				else
				{	try
					{	clearInterval(gvaMiniMapsTO[nPos]);
					}
					catch(e) {}
				}
			}, 2500);

			break;
	}
}

/*---------------------------------------------------------*
*
*----------------------------------------------------------*/

function miniMap(nPos, nLat, nLon, nAcc)
{	
	var oGMap = new GMap2(document.getElementById("item_gmap_" + nPos));
	
	

	if (!oGMap)
		return(false);
	
	
	gvaMiniMaps[nPos] = oGMap;
	gvaMiniMapsLL[nPos] = new Array(nLat, nLon);

	//oGMap.addControl(new GScaleControl());
	oGMap.addControl(new GLargeMapControl());
	oGMap.addControl(new GMapTypeControl());

	var oLatLng = new GLatLng(nLat, nLon);
	gvaMiniMapsLL[nPos] = oLatLng;

	var nZoom = 15;

	var oIcon = new GIcon();

	if (nAcc <= 5)
	{	oIcon.image = "/vimages/map/cityMarker2.png";
		oIcon.iconSize = new GSize(15, 31);
		oIcon.iconAnchor = new GPoint(15, 31);
		oIcon.infoWindowAnchor = new GPoint(5, 1);

		nZoom = 14;
	}
	else if (nAcc <= 6)
	{	oIcon.image = "/vimages/map/streetMarker2.png";
		oIcon.iconSize = new GSize(15, 31);
		oIcon.iconAnchor = new GPoint(15, 31);
		oIcon.infoWindowAnchor = new GPoint(5, 1);

		nZoom = 15;
	}
	else
	{	oIcon.image = "/vimages/map/addressMarker.png";
		oIcon.iconSize = new GSize(15, 31);
		oIcon.iconAnchor = new GPoint(15, 31);
		oIcon.infoWindowAnchor = new GPoint(5, 1);

		nZoom = 16;
	}

	oGMap.setCenter(oLatLng, nZoom);
	oGMap.savePosition();

	oGMap.addOverlay(new GMarker(oLatLng, oIcon));
	

}

/*---------------------------------------------------------*
*
*----------------------------------------------------------*/

function personalFilterOKP(sFieldID, sBaseURL, eClick)
{
	var nKey;

	try
	{	if(window.event)
			nKey = eClick.keyCode;
		else if(eClick.which)
			nKey = eClick.which;

		if (nKey == 13)
			return(personalFilterClick(sFieldID, sBaseURL));
	}
	catch(e)
	{	return;
	}
}


/*---------------------------------------------------------*
*
*----------------------------------------------------------*/

function personalFilterClick(sFieldID, sBaseURL)
{
	var oField = vslGetHTMLElement(sFieldID);
	if (!oField)
		return(false);

	var sFieldValue = oField.value;

	if (sFieldValue != "")
	{
		if (sBaseURL == "_MAP_")
		{	if (!oGMap)
				return(false);

			bigMapFilter(oGMap, "pers", sFieldValue);
		}
		else
		{
			try
			{	sFieldValue.vslURLEncodeR2();
			}
			catch(e)
			{	return(false);
			}

			if (sBaseURL.charAt(sBaseURL.length - 1) != "/")
				sBaseURL += "/";

			location.href = sBaseURL + "pers-" + sFieldValue;
		}
	}
	else	alert("Specificare almeno una parola da ricercare");

	return(true);
}

/*---------------------------------------------------------*
*
*----------------------------------------------------------*/

function optListHS(sOptionsID, sSection)
{
	var sOptList = 'optList_' + sOptionsID;

	if (vslElIsVisible(sOptList))
		optListH(sOptionsID, sSection);
	else
	{	optListHA(sSection);
		optListS(sOptionsID, sSection);
	}
}

/*---------------------------------------------------------*
*
*----------------------------------------------------------*/

function fltListHS(sOptionsID, sBaseURL)
{
	var sOptList = 'fltList_' + sOptionsID;

	if (vslElIsVisible(sOptList))
		fltListH(sOptionsID);
	else
	{	getFilter("filter_" + sOptionsID, sOptionsID, sBaseURL);
		fltListS(sOptionsID);
	}
}


/*---------------------------------------------------------*
*
*----------------------------------------------------------*/

function optListS(sOptionsID, sSection)
{
	var sOptList = 'optList_' + sOptionsID;
	var sOptListImg = 'optListImg_' + sOptionsID;
	var sOptListLabel = 'optListLabel_' + sOptionsID;

	var oImg = vslGetHTMLElement(sOptListImg);
	var oLabel = vslGetHTMLElement(sOptListLabel);

	if (!oImg || !oLabel)
		return(false);

	vslSEL(sOptList);
	oLabel.className = 'optList_TxtLabel_Active';
	if (oImg)
		oImg.src = '/vimages/optListUp_' + sSection + '.gif';

	gvaOptList[sOptionsID] = true;

	return(true);
}

/*---------------------------------------------------------*
*
*----------------------------------------------------------*/

function optListH(sOptionsID, sSection)
{
	var sOptList = 'optList_' + sOptionsID;
	var sOptListImg = 'optListImg_' + sOptionsID;
	var sOptListLabel = 'optListLabel_' + sOptionsID;

	var oImg = vslGetHTMLElement(sOptListImg);
	var oLabel = vslGetHTMLElement(sOptListLabel);

	if (!oImg || !oLabel)
		return(false);

	vslHEL(sOptList);
	oLabel.className = 'optList_TxtLabel';
	if (oImg)
		oImg.src = '/vimages/optListDown_' + sSection + '.gif';

	gvaOptList[sOptionsID] = false;

	return(true);
}

/*---------------------------------------------------------*
*
*----------------------------------------------------------*/

function fltListS(sOptionsID)
{
	var sOptList = 'fltList_' + sOptionsID;
	var sOptListImg = 'fltListImg_' + sOptionsID;
	var sOptListLabel = 'fltListLabel_' + sOptionsID;

	var oImg = vslGetHTMLElement(sOptListImg);
	var oLabel = vslGetHTMLElement(sOptListLabel);

	if (!oImg || !oLabel)
		return(false);

	vslSEL(sOptList);
	oLabel.className = 'fltList_TxtLabel_Active';
	if (oImg)
		oImg.src = '/vimages/fltListUp.gif';

	return(true);
}

/*---------------------------------------------------------*
*
*----------------------------------------------------------*/

function fltListH(sOptionsID)
{
	var sOptList = 'fltList_' + sOptionsID;
	var sOptListImg = 'fltListImg_' + sOptionsID;
	var sOptListLabel = 'fltListLabel_' + sOptionsID;

	var oImg = vslGetHTMLElement(sOptListImg);
	var oLabel = vslGetHTMLElement(sOptListLabel);

	if (!oImg || !oLabel)
		return(false);

	vslHEL(sOptList);
	oLabel.className = 'fltList_TxtLabel';
	if (oImg)
		oImg.src = '/vimages/fltListDown.gif';

	return(true);
}

/*---------------------------------------------------------*
*
*----------------------------------------------------------*/

function optListHA(sSection)
{
	for (var sOptionID in gvaOptList)
	{	if (gvaOptList[sOptionID])
			optListH(sOptionID, sSection);
	}
}


/*---------------------------------------------------------*
*
*----------------------------------------------------------*/

function _acClearTimeout()
{
	if (gvnACTimeOut)
	{	try
		{	clearTimeout(gvnACTimeOut);
		}
		catch(e)
		{	return(false);
		}
	}
}

/*---------------------------------------------------------*
*
*----------------------------------------------------------*/

function acUpdateObjContent(oEvent, oInput, sIDObj, sRemotePage)
{
	var nKeyCode = vslGetKeyCode(oEvent);
	if (nKeyCode == 40 || nKeyCode == 38 || nKeyCode == 13 || nKeyCode == 39 || nKeyCode == 37 || nKeyCode == 35 || nKeyCode == 36)
		return(false);

	gvnACActive = 0;

	_acClearTimeout();

	var sTextValue = oInput.value;
	if (sTextValue.vslTrim() == '')
	{	vslHEL(sIDObj + '_Box');
		return(false);
	}

	var sOldTextValue = oInput.value;
	sOldTextValue.vslTrim();

	gvnACTimeOut = setTimeout(function()
	{
		var oXMLReq = vslGetXMLReq();

		if (!oXMLReq)
			return(false);

		var oInputUpd = vslGetHTMLElement(oInput.id);
		var sTextValue = oInputUpd.value;
		sTextValue = sTextValue.vslTrim();

		if (sTextValue != '')
			sTextValue = sTextValue.vslURLEncode();
		else
		{	vslHEL(sIDObj + '_Box');
			return(true);
		}

		oXMLReq.open('GET', sRemotePage + oInput.value.vslURLEncodeR(), true);
		oXMLReq.onreadystatechange = function ()
		{
			var sRet = '';

			var oInputUpd = vslGetHTMLElement(oInput.id);
			var sTextValue = oInputUpd.value;
			sTextValue = sTextValue.vslTrim();

			if (sTextValue == '')
				return(false);

			//if (sTextValue != sOldTextValue)
			//	return(false);

			if (oXMLReq.readyState != 4)
				return(false);

			try
			{	if (oXMLReq.status != 200)
					return(false);

				sRet = oXMLReq.responseText;
			}
			catch (e)
			{	return(false);
			}

			var oEl = vslGetHTMLElement(sIDObj + '_Box');

			if (!oEl)
				return(false);

			oElContent = vslGetHTMLElement(sIDObj + '_ContentBox');
			if (!oElContent)
				return(false);

			oElContent.innerHTML = sRet.vslTrim();

			if (oElContent.innerHTML != '')
				vslSEL(sIDObj + '_Box');
			else 	vslHEL(sIDObj + '_Box');

			return(true);
		}

		oXMLReq.send(null);

	}, 100);

	return(true);
}


/*---------------------------------------------------------*
*
*----------------------------------------------------------*/

function acCtrlKP(oEvent, oInput, sIDObj)
{
	if (!vslElIsVisible(sIDObj + '_Box'))
		return(true);

	var nKeyCode = vslGetKeyCode(oEvent);

	for (var i = 1; i < 100; i++)
	{	var oOpt = vslGetHTMLElement(sIDObj + '_' + i);
		if (!oOpt)
			break;

		acHLOption(oOpt, false);
	}

	i--;
	var bUpDown = false;

	if (nKeyCode == 40) // DOWN
	{	gvnACActive++;
		if (gvnACActive >= i)
			gvnACActive = i;

		bUpDown = true;
	}
	else if (nKeyCode == 38) // UP
	{	gvnACActive--;
		if (gvnACActive <= 1)
			gvnACActive = 1;

		bUpDown = true;
	}
	else if (nKeyCode == 13) // ENTER
	{
		oDiv = vslGetHTMLElement(sIDObj + '_' + gvnACActive);
		if (!oDiv)
			return(true);

		var sInputValue = oDiv.innerHTML;

		sInputValue = sInputValue.replace(/<span[^>]*>.*<\/span>/ig, "");
		sInputValue = sInputValue.vslTrim();

		acUpdateField(sIDObj, sInputValue)

		return(false);
	}

	if (bUpDown)
	{	var oOpt = vslGetHTMLElement(sIDObj + '_' + gvnACActive);
		if (oOpt)
			acHLOption(oOpt, true);

		oDiv = vslGetHTMLElement(sIDObj + '_' + gvnACActive);
		if (!oDiv)
			return(false);

		var sInputValue = oDiv.innerHTML;

		sInputValue = sInputValue.replace(/<span[^>]*>.*<\/span>/ig, "");
		sInputValue = sInputValue.vslTrim();

		var oInput = vslGetHTMLElement(sIDObj);

		if (!oInput)
			return(false);

		oInput.value = sInputValue;

		return(false);
	}

	return(true);
}

/*---------------------------------------------------------*
*
*----------------------------------------------------------*/

function acUpdateField(sIDObj, sInputValue)
{
	var oInput = vslGetHTMLElement(sIDObj);

	if (!oInput)
		return(false);

	oInput.value = sInputValue;

	vslHEL(sIDObj + '_Box');

	return(true);
}


/*---------------------------------------------------------*
*
*----------------------------------------------------------*/

function acHLOption(oOpt, bHL)
{
	if (!oOpt)
		return(true);

	if (bHL)
		oOpt.className = 'autoComplete_OptionOver';
	else	oOpt.className = 'autoComplete_Option';

	return(true);
}


/*---------------------------------------------------------*
*
*----------------------------------------------------------*/

function acHide(sIDObj)
{
	setTimeout(function()
	{
		vslHEL(sIDObj + '_Box');
	}, 300);
}


/*---------------------------------------------------------*
*
*----------------------------------------------------------*/

function itemExpand(nItemPos)
{
	var oItem = vslGetHTMLElement('citem_' + nItemPos);
	if (!oItem)
		return(false);

	var oItemExp = vslGetHTMLElement('eitem_' + nItemPos);
	if (!oItemExp)
		return(false);

	oItem.className = 'item_expanded';
	vslHEL('eitem_' + nItemPos);
}


/*---------------------------------------------------------*
*
*----------------------------------------------------------*/

function checkAddItem(sType, nItemPos, sUniqID)
{	gvaCheckItem[nItemPos] = new Array(sType, sUniqID);
}

/*---------------------------------------------------------*
*
*----------------------------------------------------------*/

function checkStart(sType)
{
	var oXMLReq = vslGetXMLReq();
	if (!oXMLReq)
		return(false);

	var sItemsID = "";
	for (var i = 1; i < gvaCheckItem.length; i++)
	{	var aItem = gvaCheckItem[i];

		if (!aItem || aItem[0] != sType)
			continue;

		if (sItemsID != '')
			sItemsID += '/';

		sItemsID += "p" + i + "-" + aItem[1].vslURLEncodeR();
	}

	var sURL = '/remote/checkItem/' + sType.vslURLEncodeR() + '/' + sItemsID + '?r=' + vslGetRand(100000);

	oXMLReq.open('GET', sURL, true);
	oXMLReq.onreadystatechange = function ()
	{
		var sRet = '';
		var bRecall = false;

		if (oXMLReq.readyState != 4)
			return(false);

		try
		{	if (oXMLReq.status != 200)
				return(false);

			sRet = oXMLReq.responseText;
		}
		catch (e)
		{	return(false);
		}

		try
		{	sRet = sRet.vslTrim();
		}
		catch (e)
		{
		}

		var aLines = sRet.split("\n");

		for (var i = 0; i < aLines.length; i++)
		{	try
			{
				var aPosStatus = aLines[i].split("|");

				if (!aPosStatus || parseInt(aPosStatus[0]) <= 0)
					continue;

				var nPosition = parseInt(aPosStatus[0]);
				var nStatus = parseInt(aPosStatus[1]);

				if (nStatus == 0)
				{	if (!gvaCheckItem[nPosition][2] || gvaCheckItem[nPosition][2] != "KO")
					{	gvaCheckItem[nPosition][2] = "KO";
						checkWrongItem(nPosition);
						checkItemUpdateLoadingImage(nPosition, 0);
					}
				}
				else if (nStatus == 1)
				{	if (!gvaCheckItem[nPosition][2] || gvaCheckItem[nPosition][2] != "OK")
					{	gvaCheckItem[nPosition][2] = "OK";
						checkItemUpdateLoadingImage(nPosition, 1);
					}
				}
				else if (nStatus == -1)
				{	if (gvnCheckRequests < MAX_CHECK_REQUEST)
						bRecall = true;
					else if (!gvaCheckItem[nPosition][2] || gvaCheckItem[nPosition][2] != "ND")
					{	gvaCheckItem[nPosition][2] = "ND";
						checkItemUpdateLoadingImage(nPosition, -1);
					}
				}
			}
			catch (e)
			{	return(false);
			}
		}

		if (bRecall)
			setTimeout("checkStart('"+ sType +"')", (gvnCheckRequests+1) * 600);

		return(true);
	}

	oXMLReq.send(null);

	gvnCheckRequests++;
}

/*---------------------------------------------------------*
*
*----------------------------------------------------------*/

function checkItemUpdateLoadingImage(nItemPos, nStatus)
{
	var oEl = vslGetHTMLElement('check_item_' + nItemPos);
	if (!oEl)
		return(false);

	if (nStatus == 0)
		oEl.innerHTML = '<img src="/vimages/icoNotActive.gif" border="0" width="16" height="16" title="Annuncio non attivo" />'
	else if (nStatus == 1)
		oEl.innerHTML = '<img src="/vimages/icoActive.gif" border="0" width="16" height="16" title="Annuncio attivo" />'
	else	oEl.innerHTML = '<span class="info_status_nd">n.d.</span>';

	return(true);
}

/*---------------------------------------------------------*
*
*----------------------------------------------------------*/

function checkWrongItem(nItemPos)
{
	var oItem = vslGetHTMLElement('citem_' + nItemPos);
	if (!oItem)
		return(false);

	if (oItem.className == 'item_collapsed')
	{	var oItemExp = vslGetHTMLElement('eitem_' + nItemPos);
		if (oItemExp)
			vslDissolveEL('eitem_' + nItemPos, 100, 20, -10, 50, null);
	}

	if (window.navigator.userAgent.indexOf("MSIE") > 0)
	{	vslDissolveEL('citem_left_' + nItemPos, 100, 20, -10, 50, null);
		vslDissolveEL('citem_center_' + nItemPos, 100, 20, -10, 50, null);
		vslDissolveEL('citem_right_' + nItemPos, 100, 20, -10, 50, null);
	}
	else	vslDissolveEL('citem_' + nItemPos, 100, 20, -10, 50, null);

}


/*---------------------------------------------------------*
*
*----------------------------------------------------------*/

function onItemOver(nItemPos, bOver)
{	checkUpdate(nItemPos, bOver);
}

/*---------------------------------------------------------*
*
*----------------------------------------------------------*/

function checkUpdate(nItemPos, bOver)
{
	if (!gvaCheckItem || !gvaCheckItem[nItemPos] || !gvaCheckItem[nItemPos][2])
		return(false);

	if (gvaCheckItem[nItemPos][2] != "KO")
		return(false);

	if (bOver)
	{
		if (window.navigator.userAgent.indexOf("MSIE") > 0)
		{	vslDissolveEL('citem_left_' + nItemPos, -1, 100, 10, 50, null);
			vslDissolveEL('citem_center_' + nItemPos, -1, 100, 10, 50, null);
			vslDissolveEL('citem_right_' + nItemPos, -1, 100, 10, 50, null);
		}
		else	vslDissolveEL('citem_' + nItemPos, -1, 100, 10, 50, null);
		errorTip("L'annuncio potrebbe non essere pi? disponibile sul sito originario.", "Attenzione");
	}
	else
	{	nd();
		if (window.navigator.userAgent.indexOf("MSIE") > 0)
		{	vslDissolveEL('citem_left_' + nItemPos, -1, 20, -10, 50, null);
			vslDissolveEL('citem_center_' + nItemPos, -1, 20, -10, 50, null);
			vslDissolveEL('citem_right_' + nItemPos, -1, 20, -10, 50, null);
		}
		else	vslDissolveEL('citem_' + nItemPos, -1, 20, -10, 50, null);
	}

	return(true);
}


/*---------------------------------------------------------*
*
*----------------------------------------------------------*/

function errorTip(sTitle, sText)
{
	overlib("<b>"+ sTitle +"</b>", HAUTO, VAUTO, FGCOLOR, '#FFFFFF', CAPTION, sText, CAPCOLOR, '#FFFFFF', BGCOLOR, '#A00000', CELLPAD, 4, TEXTCOLOR,'#000000', DELAY, 500);
}

/*---------------------------------------------------------*
*
*----------------------------------------------------------*/

function prefSetUID(sUID)
{
	if (vslGetCookie('savePrefs') != sUID)
		vslSetCookie('savePrefs', sUID, 3650);
}

/*---------------------------------------------------------*
*
*----------------------------------------------------------*/

function exChangeValue(sFormField, bOnClick)
{
	var oFormField = null;
	var oFormFieldEx = null;
	var bFocus = true;

	if (arguments.length > 2)
		bFocus = arguments[3];

	if (!(oFormField = vslGetHTMLElement(sFormField)))
		return(false);

	if (!(oFormFieldEx = vslGetHTMLElement('ex_' + sFormField)))
		return(false);

	if (bOnClick)
	{	vslHEL('ex_' + sFormField);
		if (bFocus)
			oFormField.focus();
	}
	else
	{	if (!oFormField.value || (oFormField.value && oFormField.value.vslTrim() == ''))
			vslSEL('ex_' + sFormField);
	}
}


/*---------------------------------------------------------*
*
*----------------------------------------------------------*/

function exSuggValue(oLabel, sFormField)
{
	if (!oLabel || sFormField == '')
		return(false);

	var sValue = oLabel.innerHTML;

	if (sValue == '')
		return(false);

	var oFormField = null;
	if (!(oFormField = vslGetHTMLElement(sFormField)))
		return(false);

	oFormField.value = sValue;
	exChangeValue(sFormField, true, false);

	return(true);
}

/*---------------------------------------------------------*
*
*----------------------------------------------------------*/

function scrBox(oScroll, sID, sDir)
{
	var oEl = vslGetHTMLElement(sID);
	if (!oEl || !oEl.style)
		return(false);

	if (sDir != '')
	{	if (sDir == 'click')
			gvaScrollInt[sID] += 50;
		else
		{	gvaScrollInt[sID] = 0;
			gvaScrollTID[sID] = setInterval("scrBoxCB('" + sID + "', '" + sDir + "')", 25);
		}

		oScroll.className = 'boxScrollHover';
	}
	else
	{	if (gvaScrollTID[sID])
		{	gvaScrollInt[sID] = 0;
			setTimeout("clearInterval(" + gvaScrollTID[sID] + ")", 200);
		}

		oScroll.className = 'boxScroll';
	}
}


/*---------------------------------------------------------*
*
*----------------------------------------------------------*/

function scrBoxCB(sID, sDir)
{
	var oEl = vslGetHTMLElement(sID);
	if (!oEl || !oEl.style)
		return(false);

	if (!gvaScrollInt[sID])
		gvaScrollInt[sID] = 0;

	switch (sDir)
	{
		case 'down':
		case 'up':
			var nElCntHeight = vslGetElementHeight(sID);
			var nElHeight = parseInt(oEl.style.height);
			var nOffset = Math.round(gvaScrollInt[sID] / 5);
			break;
		case 'right':
		case 'left':
			var nElCntWidth = vslGetElementWidth(sID);
			var nElWidth = parseInt(oEl.style.width);
			var nOffset = Math.round(gvaScrollInt[sID] / 10);
			break
	}

	if (nOffset <= 0)
		nOffset = 1;
	else if (nOffset > 50)
		nOffset = 50;

	switch (sDir)
	{
		case 'down':
			if (nElCntHeight - oEl.scrollTop <= nElHeight + 100)
				nOffset = 3;
			oEl.scrollTop += nOffset;
			break;
		case 'up':
			if (nElCntHeight - oEl.scrollTop >= nElCntHeight - 100)
				nOffset = 3;
			oEl.scrollTop -= nOffset;
			break;
		case 'right':
			if (nElCntWidth - oEl.scrollLeft <= nElWidth + 100)
				nOffset = 3;
			oEl.scrollLeft += nOffset;
			break;
		case 'left':
			if (nElCntWidth - oEl.scrollLeft >= nElCntWidth - 100)
				nOffset = 3;
			oEl.scrollLeft -= nOffset;
			break;
	}

	gvaScrollInt[sID]++;
}


/*---------------------------------------------------------*
*
*----------------------------------------------------------*/

function czBookmark()
{
	var sURL = window.location;
	var sText = "Eurekasa - Il miglior modo di trovare casa";

	try
	{	if (window.sidebar)
			window.sidebar.addPanel(sText, sURL, "");
		else if (window.external)
			window.external.AddFavorite(sURL, sText);
		else if (window.opera && window.print)
		{	var oA = document.createElement('a');
			oA.setAttribute('rel','sidebar');
			oA.setAttribute('href', sURL);
			oA.setAttribute('title', sText);
			oA.click();
		}
	}
	catch (e)
	{
	}
}


/*---------------------------------------------------------*
*
*----------------------------------------------------------*/

function getFilter(sContentID, sFilter, sBaseURL, nAccFrom, nAccTo)
{
	var oEl = vslGetHTMLElement(sContentID);
	if (!oEl)
		return(false);

	if (sFilter == '' || sBaseURL == '')
		return(false);

	oEl.innerHTML = '<img src="/vimages/icoLoading.gif" style="vertical-align:middle; margin-right:10px" width="16" height="16">Caricamento in corso...';

	var sRemoteURL = "";

	if (sBaseURL == "_MAP_")
	{	if (!oGMap)
			return(false);
		var oBounds = oGMap.getBounds();

		var nAcc1 = 0; var nAcc2 = 0;
		if (gvnAccFrom && gvnAccTo)
		{	nAcc1 = gvnAccFrom;
			nAcc2 = gvnAccTo;
		}

		sRemoteURL = '/remote/getFilter/' + sFilter + vslGetLocationPathName() + "lat1-" + String(oBounds.getSouthWest().lat()).vslURLEncodeR() + "/lon1-" + String(oBounds.getSouthWest().lng()).vslURLEncodeR() + "/lat2-" + String(oBounds.getNorthEast().lat()).vslURLEncodeR() + "/lon2-" + String(oBounds.getNorthEast().lng()).vslURLEncodeR();
		sRemoteURL += "/acc1-" + nAcc1 + "/acc2-" + nAcc2;
		sRemoteURL += "/zoom-" + oGMap.getZoom();

		if (gvaFiltersArgs)
		{	sRemoteURL += vslGetChangedParms(gvaFiltersArgs);
			sRemoteURL  = vslGetChangedVirt(sRemoteURL, gvaFiltersArgs, 4);
		}

		sRemoteURL += '?r=' + vslGetRand(100000);
	}
	else	sRemoteURL = '/remote/getFilter/' + sFilter + sBaseURL + '?r=' + vslGetRand(100000);

	var oXMLReq = vslGetXMLReq();
	if (!oXMLReq)
		return(false);

	oXMLReq.open('GET', sRemoteURL, true);
	oXMLReq.onreadystatechange = function ()
	{
		var sRet = '';
		if (oXMLReq.readyState != 4)
			return(false);

		try
		{	if (oXMLReq.status != 200)
				return(false);

			oEl.innerHTML = oXMLReq.responseText;

			oElFilterTextDetails = vslGetHTMLElement('filterTextDetails_' + sContentID);
			if (oElFilterTextDetails)
			{	var reActiveFilter = /<span[ ]+class="optList_TxtOption_Selected">([^<]+)<\/span>/i;
				var aMatch = oXMLReq.responseText.match(reActiveFilter);
				if (aMatch)
				{	oElFilterTextDetailsValue = vslGetHTMLElement('filterTextDetails_' + sContentID + '_value');
					if (oElFilterTextDetailsValue)
					{	oElFilterTextDetailsValue.innerHTML = aMatch[1];
						vslSEL('filterTextDetails_' + sContentID);
					}
				}
			}

		}
		catch (e)
		{	return(false);
		}

		return(true);
	}

	oXMLReq.send(null);
}

/*---------------------------------------------------------*
*
*----------------------------------------------------------*/

function unloadQueue(sQueueID)
{

	var oXMLReq = vslGetXMLReq();
	if (!oXMLReq)
		return(false);

	var sRemoteURL = '/remote/unloadQueue/' + sQueueID + '?r=' + vslGetRand(100000);

	oXMLReq.open('GET', sRemoteURL, false);
	oXMLReq.send(null);

	return(true);
}
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}
function sendEmail(nPos){
	if (vslElIsVisible("item_email_" + nPos)){
		vslCollapseEL("item_email_" + nPos, vslGetElementHeight("item_email_" + nPos), 1, -35, 25, function () {

			oEl = vslGetHTMLElement("item_email_" + nPos);
			if (oEl.style)
				oEl.style.height = "1px";

			vslHEL("item_email_" + nPos);
		});
	}else{
		vslSEL('item_email_' + nPos);
		vslCollapseEL('item_email_' + nPos, 1, 205, 20, 25, null);
	}
}

function openHiddenBlock(blockId, nHeight){
	if (vslElIsVisible(blockId)){
		vslCollapseEL(blockId, vslGetElementHeight(blockId), 1, -35, 25, function () {

			oEl = vslGetHTMLElement(blockId);
			if (oEl.style)
				oEl.style.height = "1px";

			vslHEL(blockId);
		});
	}else{
		vslSEL(blockId);
		vslCollapseEL(blockId, 1, nHeight, 20, 25, null);
	}
}

function toggleVisibleEKBL(tagId)
{
	if(tagId == 'box_invia_amico')
		vslGetHTMLElement('box_segnalazione_errore').style.display='none';
	if(tagId == 'box_segnalazione_errore')
		vslGetHTMLElement('box_invia_amico').style.display='none';
	visibilityStatus = vslGetHTMLElement(tagId).style.display;
	if (visibilityStatus=='none')
		vslGetHTMLElement(tagId).style.display='block';
	else
		vslGetHTMLElement(tagId).style.display='none';
}

var aZone = new Array();
function toggleAbsoluteVisible(event, tagId, sIdPosHolder)
{
	var oEl = vslGetHTMLElement(tagId);
	var oPosHolder = vslGetHTMLElement(sIdPosHolder);

	if (!oEl)
		return false;

	var sVisibilityStatus = oEl.style.display;

	var oTableZone = document.getElementById("searchForm");
	var aInputZone = $A(oTableZone.getElementsByTagName('input')).map(Element.extend);


	if (sVisibilityStatus == 'none')
	{	

		for (i = 0; i < aInputZone.length; i++)
		{
			aZone.push(aInputZone[i].id + ":" + aInputZone[i].checked);
		}
	
		Element.extend(oEl);
		var nElWidth = oEl.getDimensions().width;
		if (nElWidth < 400)
		{
			oEl.style.width = "500px";
			nElWidth = 500;
		}

		if (!sIdPosHolder)
		{
			var nPosY = Event.pointerY(event)+10;
			var nPosX = ((document.body.clientWidth/2) - (nElWidth/2));
		}

		else
		{
			if (!oPosHolder)
				return false;
 			Element.extend(oPosHolder);
			var nPosX = oPosHolder.positionedOffset()[0];
			var nPosY = oPosHolder.positionedOffset()[1]+20;
		}
  		oEl.style.left = nPosX + 'px';
  		oEl.style.top = nPosY + 'px';
  		oEl.style.display = 'block';
		if (vslGetHTMLElement("zone") && vslGetHTMLElement("zone").disabled=="" && isIe())
			vslGetHTMLElement("zone").disabled="disabled";	
	}
	else
	{
		if (isIe())
			vslGetHTMLElement("zone").disabled = "";

		oEl.style.display = 'none';

		for (i = 0; i < aInputZone.length; i++)
		{
			if (aZone.vslInArray(aInputZone[i].id + ":" + aInputZone[i].checked))
				continue;
			document.forms.search.submit();
		}
		aZone = new Array();
		return true;

	}

}

function homePageSearchManager(sCategory) {
	changeFocus('superficie_min_' + sCategory);
	searchAdvanced('searchAdvanced_' + sCategory, true);
	switchTextEKBL(dojo.byId('AdvSearchText_' + sCategory),'searchAdvanced_' + sCategory, ekLang._('Ricerca avanzata'), ekLang._('Ricerca base'));
	return false;
}

function switchTextEKBL(node, tagId, showText, hideText){
	visibilityStatus = document.getElementById(tagId).style.display;
	if (visibilityStatus=='none')
		node.innerHTML = showText;
	else
		node.innerHTML = hideText;

}

var inputText = "inserisci comune";
var inputTextAgency = "Inserisci un'agenzia";
var inputTextnuoveCostruzioni = "inserisci provincia";

function validateFormSearch(id) {
	oInputDove = document.getElementById(id);
	if (!oInputDove)
	{	
		if (document.getElementById('keywords') && document.getElementById('keywords').value == inputTextAgency)
			document.getElementById('keywords').value = "";
	}
	sInputDoveValue = oInputDove.value;
	sInputDoveValue = sInputDoveValue.trim();

	if (sInputDoveValue == inputText || sInputDoveValue == inputTextnuoveCostruzioni)
	{
		var sDivErrorId = "e1";
		if (id.lastIndexOf("_") != -1)
		{
			var sCategory = id.substr(id.lastIndexOf("_"));
			sDivErrorId += sCategory;
		}
		else
		{
			var sCategory = "agenzie";
			sDivErrorId += "_"+sCategory;
		}

		oErrorDiv = document.getElementById(sDivErrorId);
		
		alert("Il campo 'Comune o Provincia' deve essere valorizzato");
		if (!oErrorDiv)
			return false;

		oErrorDiv.style.display = "block";
		return false;
	}
	else{
		if (sInputDoveValue.length > 0) {
			return true;
		} 
		else {
			alert("Il campo 'Comune o Provincia' deve essere valorizzato");
			oErrorDiv = document.getElementById("e1");
			if (!oErrorDiv)
				return false;
			oErrorDiv.style.display = "block";
			return false;
		}
	}
}

function sbHPOnInputFocus(oInput, bOnFocus) {
	if (!oInput)
		return(false);

	if (bOnFocus)
		oInput.style.backgroundColor = '';
	else	oInput.style.backgroundColor = '';
}

function ResetTabs(tabPrefix, tabCount, otherclass) {
		
	if(tabPrefix == 'menuMid'){
		for(i = 1; i <= tabCount; i++) {
			var activeDiv = document.getElementById(tabPrefix + "_div_" + i);
			var activeTab = document.getElementById(tabPrefix + "_" + i);
			var activeTabRight = document.getElementById(tabPrefix+"_right_"+i);
			var activeTabLeft = document.getElementById(tabPrefix+"_left_"+i);
			if(activeDiv != null) {
				activeDiv.style.display = "none";
			}
			if(activeTab != null) {
				activeTab.className ="blockleft";
			}
			if(activeTabRight != null){
				activeTabRight.className = "right blockleft";
			}
			if(activeTabLeft != null){
				activeTabLeft.className = "left blockleft";
			}
		}
	}
	else{
		document.getElementById(tabPrefix+'_menu_div_border_left').className = 'menuBorder leftInitial';
		if(tabPrefix == 'menuRight'){
			document.getElementById(tabPrefix+'_menu_div_border_right').className = 'menuBorder rightInitial';
		}
		for(i = 1; i <= tabCount; i++) {
			aDiv = document.getElementById(tabPrefix + "_div_" + i);
			if(tabPrefix == 'menuRight'){
				aDivTop = document.getElementById(tabPrefix + "Top_div_" + i);
				if(aDivTop != null) {
					aDivTop.style.display = "none";
				}
			}
			activeTitleDiv = document.getElementById(tabPrefix + "_div_tittle_"+i);
			aTab = document.getElementById(tabPrefix + "_" + i);
			aDivMenu = document.getElementById(tabPrefix + "_menu_div_" + i);
			var tabRight = document.getElementById(tabPrefix+"_right_"+i);
			if(activeTitleDiv != null)
				activeTitleDiv.style.display = "none";
			if(aDiv != null) {
				aDiv.style.display = "none";
			}
			if(aDivMenu != null){
				aDivMenu.className = "menuSupElement bigtitle bold";
			}
			if(aTab != null)
				aTab.className ="bigtitle";
			if(tabRight != null){
				if (i== tabCount)
					tabRight.className ='menuBorder rightInitial';
				else
					tabRight.className ='menuBorder right';
			}
				
		}
	}	
}

//TO MODIFICATE
function ShowTab(tabPrefix,categoria, tab, tabCount, otherclass) {
	if(tabPrefix == 'home'){
		if (tabCount == '')
			tabCount = 3;
		var activeDiv = document.getElementById(tabPrefix + "_div_" + tab);
		var activeMenuDiv = document.getElementById(tabPrefix + "_menu_div_" + tab);
		var activeTab = document.getElementById(tabPrefix + "_" + tab);
		var activeTabRight = document.getElementById(tabPrefix+"_right_"+tab);
		ResetTabs(tabPrefix, tabCount, otherclass);
		if(tab == 1)
			document.getElementById('home_menu_div_border_left').className = 'menuBorder leftSelectedInitial';
		if(activeDiv != null) {
			activeDiv.style.display = "block";
		}
		if(activeMenuDiv != null) {
			activeMenuDiv.className =" menuSupElement blockleft bigtitle bold";
		}
		if(activeTab != null) {
			activeTab.className ="bigtitle selected";
		}
		if(activeTabRight != null){
			activeTabRight.className = "menuBorder rightSelected";
		}
		if(tab == 6){
			activeTabRight.className = "menuBorder rightSelectedInitial";
		}
		if(tab > 1){
			var tabAux = parseInt(tab) - 1;
// 			if (tab == 6)
// 				tabAux = parseInt(tab) - 2;
			var activeTabLeft = document.getElementById(tabPrefix+"_right_"+tabAux);
			activeTabLeft.className = "menuBorder leftSelected";
		}
		
	}
	else if(tabPrefix == 'menuRight'){
		var activeDiv = document.getElementById(tabPrefix + "_div_" + tab);
		var activeDivTop = document.getElementById(tabPrefix + "Top_div_" + tab);
		var activeMenuDiv = document.getElementById(tabPrefix + "_menu_div_" + tab);
		var activeTab = document.getElementById(tabPrefix + "_" + tab);
		var activeTabRight = document.getElementById(tabPrefix+"_right_"+tab);
		var activeTitleDiv = document.getElementById(tabPrefix + "_div_tittle_"+tab);

		ResetTabs(tabPrefix, tabCount, otherclass);
		
		if(tab == 1){
			document.getElementById(tabPrefix+'_menu_div_border_left').className = 'menuBorder leftSelectedInitial';
		}
		else if(tab == tabCount){
			document.getElementById(tabPrefix+'_menu_div_border_right').className = 'menuBorder rightSelectedInitial';
		}
		
		if(activeDiv != null) {
			activeDiv.style.display = "block";
		}
		if(activeDivTop != null) {
			activeDivTop.style.display = "block";
		}
		if(activeTitleDiv != null) {
			activeTitleDiv.style.display = "block";
		}
		if(activeMenuDiv != null) {
			activeMenuDiv.className =" menuSupElement blockleft bigtitle bold";
		}
		if(activeTab != null) {
			activeTab.className ="bigtitle selected";
		}
		if(activeTabRight != null){
			activeTabRight.className = "menuBorder rightSelected";
		}

		if(tab > 1){
			var tabAux = parseInt(tab) - 1;
			var activeTabLeft = document.getElementById(tabPrefix+"_right_"+tabAux);
			activeTabLeft.className = "menuBorder leftSelected";
		}
	}
	else if(tabPrefix == 'menuMid'){
		var activeDiv = document.getElementById(tabPrefix + "_div_" + tab);
		//var activeMenuDiv = document.getElementById(tabPrefix + "_menu_div_" + tab);
		var activeTab = document.getElementById(tabPrefix + "_" + tab);
		var activeTabRight = document.getElementById(tabPrefix+"_right_"+tab);
		var activeTabLeft = document.getElementById(tabPrefix+"_left_"+tab);
		ResetTabs(tabPrefix, tabCount, otherclass);
		if(activeDiv != null) {
			activeDiv.style.display = "block";
		}
// 		if(activeMenuDiv != null) {
// 			activeMenuDiv.className =" menuSupElement blockleft bigtitle bold";
// 		}
		if(activeTab != null) {
			activeTab.className ="selected blockleft";
		}
		if(activeTabRight != null){
			activeTabRight.className = "rightSelected blockleft";
		}
		if(activeTabLeft != null){
			activeTabLeft.className = "leftSelected blockleft";
		}
	}

	else{
			
		if (tabCount == '')
			tabCount = 3;
		var activeDiv = document.getElementById(tabPrefix + "_div_" + tab);
		var activeTab = document.getElementById(tabPrefix + "_" + tab)
		ResetTabs(tabPrefix, tabCount, otherclass);
		if(activeDiv != null) {
			activeDiv.style.display = "block";
		}
		if(activeTab != null) {
			activeTab.className ="selected";
		}
	}
	
	
}

/*---------------------------------------------------------*
*
*----------------------------------------------------------*/

var aTxtName = new Array();
aTxtName['email'] = 'email';
aTxtName['invemail'] = 'invia email';
aTxtName['chiudi'] = 'chiudi';
aTxtName['mappa'] = 'mappa';
aTxtName['vedimappa'] = 'vedi mappa';
aTxtName['amappa'] = 'Allarga mappa';
aTxtName['nome'] = 'nome';
aTxtName['privacy'] = 'Confermo di aver letto l&#39;informativa sulla <a href="/casa/informazioni/politica-di-privacy.php" rel="nofollow">privacy</a> e <input type="checkbox" name="privacy" value="S" checked="checked" />Acconsento al trattamento dei dati personali da parte di Eurekasa.';
aTxtName['acconsento'] = 'Acconsento ';
aTxtName['privacySmall'] = ' al trattamento dei dati personali (<a href="/casa/informazioni/politica-di-privacy.php" rel="nofollow">leggi l\'informativa</a>)';
//aTxtName['privacySmall'] = '<input type="checkbox" name="privacy" value="S" checked="checked" id="privacy" /> al trattamento dei dati personali (<a href="/casa/informazioni/politica-di-privacy.php" rel="nofollow">leggi l\'informativa</a>)';
aTxtName['privacySmallA'] = ' al trattamento dei dati personali (<a href="/casa/informazioni/politica-di-privacy.php" rel="nofollow">leggi l\'informativa</a>)';
//aTxtName['privacySmallA'] = '<input type="checkbox" name="privacy" value="S" checked="checked" id="privacy_a" /> al trattamento dei dati personali (<a href="/casa/informazioni/politica-di-privacy.php" rel="nofollow">leggi l\'informativa</a>)';
aTxtName['invia'] = 'Invia un\'email all\'agenzia immobiliare';
aTxtName['messaggio'] = 'messaggio';
aTxtName['telefono'] = 'telefono';
aTxtName['indicazione'] = 'L\'indicazione si riferisce alla strada o piazza ove &egrave; ubicata l\'agenzia immobiliare.';
aTxtName['ingrandimento'] = 'ingrandimento';
aTxtName['centra'] = 'centra';
aTxtName['satellite'] = 'satellite';
aTxtName['ibrida'] = 'ibrida';
aTxtName['primopiano'] = ekLang._("Annuncio in Primo Piano");
aTxtName['ingrandiscifoto'] = 'Ingrandisci foto';
aTxtName['fstwb1'] = "FASTWEB porta a casa tua Internet Superveloce, Telefono e TV Digitale. Verifica subito se sei raggiunto. E se ti abboni online, per te 50 " + ekLang._("\x80") + " di sconto!";
aTxtName['fstwb2'] = "FASTWEB ha l'offerta ideale per professionisti, aziende, bar e negozi che vogliono usufruire di servizi di Telefonia, Internet, TV e VideoSorveglianza: scoprila subito!";

function DynInnerHTML()
{
	oSpan = document.getElementsByTagName("span");

	for (i = 0; i < oSpan.length; i++)
	{
		if (oSpan[i].id.substring(0, 3) == "sw_")
		{
			var sFieldName = oSpan[i].id.substring(3, oSpan[i].id.length);

			for (x in aTxtName)
			{
				if (x == sFieldName.substring(0, sFieldName.indexOf("_"))) {
					document.getElementById(oSpan[i].id).innerHTML = aTxtName[x];
					break;
				}
			}

		}
	}
}

function createMultipleList(oDynamicSelect)
{
	oDynamicSelect.addSelect(sSelectBoxName);
	for(i = 0; i < aType.length; i++)
	{
		oDynamicSelect.selects[sSelectBoxName].addOption(aType[i]);
		if (aType[i] == "0")
		{
			aPricesText = aPricesVenditaText;
			aPricesValue = aPricesVenditaValue;
		}
		else
		{
			aPricesText = aPricesAffittoText;
			aPricesValue = aPricesAffittoValue;
		}

		for(y = 0; y < aPricesText.length; y++)
		{
			oDynamicSelect.selects[sSelectBoxName].options[aType[i]].createOption(aPricesText[y], aPricesValue[y]);
		}
	}
	return oDynamicSelect;
}

function dynamicSelect()
{
	this.selects = new Array();

	this.addSelect = function(name)
	{
		this.selects[name] = new selectObj();
	}



	this.updateOptions = function(source, target)
	{
		var form = source.form;
		var target = form.elements[target];
		var value = source.value;

		while(target.options.length) target.remove(0);

		if(!this.selects[source.name].options[value])
		{
			//alert('Invalid selection.'); //For debugging while you set it up
			return;
		}

		var data = this.selects[source.name].options[value].options;

		for(var x=0; x<data.length; x++)
		{
			try
			{
				target.add(data[x]);
			}
			catch(e)
			{
				target.add(data[x], null);
			}
		}

		target.selectedIndex = 0;
	}

}



function selectObj()
{
	this.options = new Array();

	this.addOption = function(value)
	{
		this.options[value] = new optionObj();
	}
}



function optionObj()
{
	this.options = new Array();

	this.createOption = function(name, value)
	{
		this.options[this.options.length] = new Option(name, value);
	}
}

function windowOpen(sUrl)
{
	if (sUrl && sUrl.indexOf('http') == 0)
		sUrl = sUrl;
	else if(sUrl && sUrl != "")
		sUrl="http://www.immobiliare.it/" + sUrl;
//sUrl.substr(0, 4) == 'http'
	else
		sUrl="http://www.immobiliare.it/";

	sParams = "";
	sParams += "channelmode=yes";
	sParams += ", fullscreen=yes";
	sParams += ", toolbar=yes";
	sParams += ", location=yes";
	sParams += ", directories=no";
	sParams += ", status=yes";
	sParams += ", menubar=yes";
	sParams += ", scrollbars=yes";
	sParams += ", resizable=yes";
	sParams += ", copyhistory=yes";
	sParams += ", width="+screen.width;
	sParams += ", height="+screen.height;
	sParams += ", top=20, left=20";

	window.open(sUrl, "_blank", sParams )
}

function dynWriteAutopromo(sId)
{
	oAutopromo = document.getElementById(sId);
	if (!oAutopromo)
		return;

	oAutopromo.innerHTML='<div class="blockright"><a class="forceLink" onClick="Lightbox.showBoxByID(\'ekit\', 470, 330);" title="Immobiliare.it">' + ekLang._("network") + ' <img src="/vimages/default/IT/immobiliare90.jpg" style="margin-bottom:-2px;"/></a></div><div class="empty" />';
	oAutopromo.style.display="block";
}

function dynWriteFooter()
{
	oDynFooter = document.getElementById('footerDynColumn');
	if (!oDynFooter)
		return;

	oDynFooter.innerHTML = '<div class="footerSeparator blockleft"></div>\
	<div class="divFooter blockleft  divJustify" style="padding-right:20px; margin-top:10px;">\
		<span class="bold grigio">Il Gruppo Immobiliare.it</span><br>\
		<span><a class="dashed black" onclick="windowOpen();">www.immobiliare.it</a></span><br>\
		<span><a class="dashed black" href="http://www.eurekasa.it/">www.eurekasa.it</a></span><br>\
		<span><a class="dashed black" onclick="windowOpen(\'http://www.nuovecostruzioni.it/\');">www.nuovecostruzioni.it</a></span><br>\
	</div>';
}

/*---------------------------------------------------------*
*	Funzione STATICA per il controllo preventivo dell'invio email senza i dati obbligatori
*----------------------------------------------------------*/

var emailRegEx = new RegExp(/^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/);
var telephoneRegEx = new RegExp(/^\+?[\d ]+[\/\-]?[\d ]+$/m);

function checkEmailForm(form) {
	try {
		var sError = "Attenzione\n";
		var oNome = form.nome;

		if (!oNome) {
			return false;
		}

		var oEmail = form.email;
		if (!oEmail) {
			return false;
		}

		var oTelefono = form.telefono
		if (!oTelefono) {
			return false;
		}

		var oPrivacy = form.privacy
		if (!oPrivacy) {
			return false;
		}

		if (oNome.value == "" || oNome.value == "Nome") {
			sError += "\n - Il campo NOME deve essere obbligatoriamente compilato\n";
		}

		if ((oEmail.value == "" || oEmail.value == "Email" ) && (oTelefono.value == "" || oTelefono.value == "Telefono")) {
			sError += "\n - Almeno uno tra i campi EMAIL / TELEFONO deve essere obbligatoriamente compilato\n";
		}

		if (oTelefono.value != "Telefono" && !telephoneRegEx.test(oTelefono.value)){
			sError += "\n - Inserire un telefono valido o lasciare il campo vuoto.\n";
		}

		if (oEmail.value != "" && oEmail.value != "Email" && !emailRegEx.test(oEmail.value)) {
			sError += "\n - Inserire un EMAIL in formato valido\n";
		}

		if (oPrivacy.checked != true) {
			sError += "\n - Deve essere acconsentito il trattamento dei dati personali\n";
		}

		if (sError != "Attenzione\n") {
			alert(sError);
			return false;
		}

		if (oNome.value == "Nome") {
			oNome.value = "";
		}
		if (oEmail.value == "Email") {
			oEmail.value = "";
		}
		if (oTelefono.value == "Telefono") {
			oTelefono.value = "";
		}
		return true;
	} catch(e) {
		//alert(e.description);
		return false;
	}
}



function createElementDiv()
{	var oDivNew = document.createElement('div');
	oDivNew = setAttribute('id', 'oDivNewId');

	if (width)
		oDivNew.style.width = 300;

	if (height)
		oDivNew.style.height = 300;

	if ((left || top) || (left && top))
	{
		oDivNew.style.position = "absolute";

		if (left)
			oDivNew.style.left = left;

		if (top)
			oDivNew.style.top = top;
	}

	oDivNew.style.background = "#00C";
	oDivNew.style.border = "4px solid #000";

	if (html)
		oDivNew.innerHTML = html;
	else
		oDivNew.innerHTML = "nothing";

	document.body.appendChild(oDivNew);

}

/*---------------------------------------------------------*
* Funzioni per la gestione delle Foto Plus
*----------------------------------------------------------*/

var nTipo = 0;
var nFotoplus = 0;

function fotoPlus(id, nTipoImg)
{
	if (nFotoplus == 0)
	{
		//alert("A");
		nFotoplus = id;
		setTimeout("openFotoPlus("+id+")", 1000);

	}
	else if (nFotoplus == id)
	{
		//alert("B");
		closeFotoPlus(id, nTipoImg);
	}
	else
	{
		//alert("C");
		closeFotoPlus(nFotoplus);
		nFotoplus = id;
		setTimeout("openFotoPlus("+id+")", 1000);
	}
}

function openFotoPlus(id)
{
	if (nFotoplus == id)
	{
		oDivOmbra = document.getElementById("FotoPlus_"+id);
		oImage = document.getElementById("FotoPlusImg_"+id);

		oDivOmbra.style.display = "block";
		oImage.onload = initImage;
		//oImage.src = "/thumbs/620x460/"+id+"/1/FotoPlus.jpg";
		oImage.src = "/thumbs/400x300/"+id+"/1/FotoPlus.jpg";
	}
}

function closeFotoPlus(id, nTipoImg)
{
	oDivOmbra = document.getElementById("FotoPlus_"+id);
	oImage = document.getElementById("FotoPlusImg_"+id);

	if (nTipoImg == 1 && oDivOmbra.style.display == "block")
		return;

	oImage.style.visibility='hidden';
	oDivOmbra.style.display = "none";
	nFotoplus = 0;
}


function initImage()
{
	setOpacity(0);
	oImage.style.visibility='visible';
	fadeIn(0);
}


function setOpacity(opacity)
{
	opacity = (opacity == 100)?99.999:opacity;
	oImage.style.filter = "alpha(opacity:"+opacity+")"; // IE/Win
	oImage.style.KHTMLOpacity = opacity/100; // Safari<1.2, Konqueror
	oImage.style.MozOpacity = opacity/100; // Older Mozilla and Firefox
	oImage.style.opacity = opacity/100; // Safari 1.2, newer Firefox and Mozilla, CSS3
}

function fadeIn(opacity) {
	if (opacity <= 100)
	{
		setOpacity(opacity);
		opacity += 10;
		window.setTimeout("fadeIn("+opacity+")", 50);
	}
}

function changeInputTextColor (oObj, sText, bOnFocus, sColor)
{
	if (!oObj)
		return(false);

	sbHPOnInputFocus(oObj, bOnFocus);

	if(oObj.value=='' || oObj.value==sText)
	{
		if (bOnFocus){
			oObj.value="";
		}
		else	
			oObj.value=sText;
	}
	else	sColor = oObj.style.color;

	oObj.style.color=sColor;


	return (true);
}

/*---------------------------------------------------------*
*
*----------------------------------------------------------*/

function updateInputAttribute(sInputId, sInputAttribute, sInputValue)
{
	var oEl = vslGetHTMLElement(sInputId);
	if (!oEl)
		return false;

	if (oEl[sInputAttribute] == sInputValue)
		oEl[sInputAttribute] = '';
	else
		oEl[sInputAttribute] = sInputValue;

	return true;
}

function hideAllBlocks()
{
	var aoClassOpening = document.getElementsByClassName("opening");
	for (i=0; i < aoClassOpening.length; i++)
		aoClassOpening[i].style.display = "none";
}



function simulateSelect(sDivId, sSpanId, sInputId)
{
	var oDiv = vslGetHTMLElement(sDivId);
	var oSpan = vslGetHTMLElement(sSpanId);
	var oInput = vslGetHTMLElement(sInputId);

	if (!oDiv || !oSpan || !oInput)
		return false;

	if (isIe())
		var sDivTxt = oDiv.value;//var sDivTxt = oDiv.options[0].text;
	else	var sDivTxt = oDiv.value;//vslGetHTMLElement('falseOption').innerHTML;

	var nZone = sDivTxt.substring(0, sDivTxt.indexOf(" "));

	if(oInput.checked)
	{
		oSpan.className= "zoneSelected";

		if (/MSIE 6./i.test(navigator.userAgent))
			oSpan.innerHTML = oSpan.innerHTML;

		nZone++;
	}
	else
	{
		
		oSpan.className= "zone";
		nZone--;
	}
	
	oDiv.value = nZone + " zone selezionate";

}

function patchIE(sPatch, sId)
{	
	if (isIe())
	{
		switch (sPatch)
		{
			case "iframe":
				/*patch per IE6 e precedenti per sovrapporre un layer a campi select */
				document.write("<iframe frameborder=\"0\"></iframe>");
			break;
	
			case "iframeStyle":
				oEl = vslGetHTMLElement(sId);
				if (!oEl)
					return false;
				
				oEl.style.marginTop = "-152px";
			break;
			
			case "select":
				document.write("<select id=\"zone\" class=\"tendina\" style=\"background-color: #FFF\" onclick=\"toggleAbsoluteVisible(event, 'filter_zone_left', 'zone');\"><option>0 zone selezionate</option></select>");
			break
		}
	}
	else
	{
		switch (sPatch)
		{
			case "select":
				document.write("<select id=\"zone\" class=\"tendina\" style=\"background-color: #FFF;\" onclick=\"toggleAbsoluteVisible(event, 'filter_zone_left', 'zone');\"><option class=\"helHide\" style=\"width: 1px; height: 1px; overflow: hidden;\"></option></select>");
				document.write("<div id=\"falseOption\" class=\"falseOption\" onclick=\"toggleAbsoluteVisible(event, 'filter_zone_left', 'zone');\">0 zone selezionate</div>");
			break
		}
	}
}

function isIe()
{	
	if (navigator.userAgent.toLowerCase().indexOf("msie") != -1 && navigator.userAgent.toLowerCase().indexOf("msie 7") == -1)
		return true;
	return false;
}

function searchAdvanced(sIdDiv, bShow)
{
	if (!dojo.byId(sIdDiv))
		return false;

	if (bShow)
	{

		elem = dojo.byId(sIdDiv);

		if (elem.style.display == 'none') {
			elem.style.display = 'block';
		} else {
			elem.style.display = 'none';
		}
	}
}

function changeFocus(sId)
{
	sId = 'page';
	
	if (!(oId = vslGetHTMLElement(sId)))
		return(false);

	oId.focus();
}

function addMapOnLoad(id, lat, lon)
{
	dojo.addOnLoad(function() {
		if (!streetviewClient) {
			var streetviewClient = new GStreetviewClient();
		}
		streetviewClient.getNearestPanoramaLatLng(new GLatLng(lat, lon),
			function(exists) {
				if (exists) {
					dojo.byId(id).style.display = 'block';
				}
			}
		);
	});
}

	function checkErrorReportingForm() {
		try {
			var sError = "Attenzione\n";
			var oNome = errorReporting.nome;
			var oEmail = errorReporting.email;
			var oDescription = errorReporting.richieste;
			var oPrivacy = errorReporting.privacy;
			if (oNome.value == "") {
				sError += "\n - Il campo NOME deve essere obbligatoriamente compilato\n";
			}
			if (oEmail.value == "") {
				sError += "\n - Il campo EMAIL deve essere obbligatoriamente compilato\n";
			}
			if (oDescription.value == "") {
				sError += "\n - Il campo 'Descrivi l'errore' deve essere obbligatoriamente compilato\n";
			}
			if (oPrivacy.checked != true) {
				sError += "\n - Deve essere acconsentito il trattamento dei dati personali\n";
			}
			if (sError != "Attenzione\n") {
				alert(sError);
				return false;
			}
			return true;
		} catch(e) {
			return false;
		}
}

