var oCookie;Array.prototype.indexOf=function(elem){	for(var x=0; x<this.length; x++)	{		if(this[x]==elem)		{			return x;		}	}	return -1;}var imoList= new Array();var nodeList= new Array();//var lng ="PT";function addImo(clid){	//alert("pushing :"+clid);	loaded=true;	imoList.push(parseInt(clid));}function remImo(clid){	loaded=true;	if(imoList.indexOf(clid)!=-1)	{		imoList.splice(imoList.indexOf(clid),1);	}}var loaded=false;function initFavourites(){	//lng=lang;			if(cookiesEnabled())		{			var list=readCookie('favourites');			if(list!="")			{				imoList=list.split(',');				loaded=true;				//alert('getting from cookie');			}		}				nodeList=getElements();	refreshNodes();}function refreshNodes(){	//alert("on init "+imoList.length + "location :"+window.location.href);	//alert("Refreshing nodes");	for(var g=0;g<nodeList.length;g++)	{               		var node=nodeList[g];		if(imoList.indexOf(node.getAttribute("favourite"))==-1)		{							node.ondoubleclick=function(){}			node.style.cursor="hand";				node.src=node.getAttribute('addImage');			node.alt=node.getAttribute('addAlt');			node.onclick=function()			{				addImo(this.getAttribute("favourite"));				refreshNodes();												if(this.getAttribute("_onClick"))					eval(this.getAttribute("_onClick"));			}		}		else		{			node.ondoubleclick=function(){}			node.style.cursor="hand";				node.src=node.getAttribute('remImage');			node.alt=node.getAttribute('remAlt');			node.onclick=function()			{				remImo(this.getAttribute("favourite"));				refreshNodes();									if(this.getAttribute("_onClick"))					eval(this.getAttribute("_onClick"));			}		}				if(node.getAttribute("favouriteStyle"))		{			node.className=node.tagName+'favourite';		}	}//end for}//end function////////////////////////Interface functions /////////////////////////function listFavourites(url){	if(!url)		url="listagem.htm";			var href="?"+getFavourites();	window.location.href=url+href;}function getFavourites(){	var aux;		if(loaded)		aux=imoList.join(',');				else		aux=readCookie('favourites')		aux=aux.charAt(0)==","?aux.substring(1):aux;	aux=aux==""?0:aux;	return "RIL="+aux;}function clearCookies(_refresh){	imoList= new Array();	saveCookie();		if(_refresh)		refreshNodes();}function saveCookie(){	var Realestatelist=imoList.join(',');	Realestatelist = Realestatelist.charAt(0) == "," ? Realestatelist.substring(1) : Realestatelist;	var dat = new Date();	var nextYear = dat.getTime()+ (365 * 24 * 60 * 60 * 1000);	dat.setTime(nextYear);	document.cookie='favourites='+Realestatelist+';expires='+dat.toGMTString()+';path=/';}////////////////////////guardar cookie /////////////////////////window.onbeforeunload=function(){	if(loaded)		saveCookie();}/*** verifica se os cookies estão bloqueados ***/function cookiesEnabled(){	var _date = new Date();	_date.setTime(_date.getTime()+9000);	document.cookie='test=true;expires='+_date.toGMTString();	var aux=readCookie('test');	if(aux != "")	{		return true;		}		return false;}/*** Percorre todos os elementos do body e devolde um array com a referência dos que manipulam os favoritos  ***/function getElements(){	var temp= new Array(document.body);	var fav= new Array();	//var temp= document.body.childNodes;		for(var i=0; i<temp.length; i++)	{		if(temp[i].hasChildNodes)		{			for(var x=0; x<temp[i].childNodes.length;x++)			{				var node=temp[i].childNodes[x];				if(node.nodeType==1)				{					temp.push(node);					if(node.getAttribute('favourite'))						fav.push(node);				}			}		}	}	return fav}/////////////////////////////  Generic functions  ////////////////////////*** Devolve o valor de uma determinada chave do cookie ***/function readCookie(val){	var scrambles=new Array();	scrambles=document.cookie.split(';');	for(var x=0; x<scrambles.length;x++)	{		var keys= new Array();		keys= scrambles[x].split('=');				var aux=keys[0].toLowerCase();		if(aux.trim()==val.toLowerCase() && keys[1] && keys[1]!="")		{				return keys[1];		}	}	return "";}String.prototype.lTrim=function(){	var index=0;	while(this.charCodeAt(index)==32 && index<this.length)	{		index++; 	}		if(index==this.length)		return "";	else		return this.substring(index);}String.prototype.rTrim=function(){	var index=this.length-1;		while(this.charCodeAt(index)==32 && index>0)	{		index--;		}		if(index==0 && this.charAt(index)==32)		return "";	else		return this.substring(0, index+1);}String.prototype.trim=function(){	var aux=this.rTrim();	return aux.lTrim();}