//var host='http://localhost/reabilitar-em-casa/';
//var host='http://www.gbcreation.com/';
//var host='http://www.centrodermatologia.com/';
var host='http://www.reabilitar-em-casa.com/';
var cake = document.location+""; 
var slice = cake.split("/", 3);
var host = 'http://'+slice[2]+'/';
var inputs;
var imgFalse = host+'imagens/false.png';
var imgTrue = host+'imagens/true.png';
var histData=new Array();
var histDiv=new Array();
var histInt=0;
var separador="";
var oFCKeditor = null;
var phpValue="";
var tinymceConfigs = 
	[{
	mode : "textareas",
	theme : "advanced",
	plugins : "table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,zoom,media,searchreplace,print,contextmenu,paste,directionality,fullscreen",
	theme_advanced_buttons1_add_before : "save,newdocument,separator",
	theme_advanced_buttons1_add : "fontselect,fontsizeselect",
	theme_advanced_buttons2_add : "separator,insertdate,inserttime,preview,zoom,separator,forecolor,backcolor",
	theme_advanced_buttons2_add_before: "cut,copy,paste,pastetext,pasteword,separator,search,replace,separator",
	theme_advanced_buttons3_add_before : "tablecontrols,separator",
	theme_advanced_buttons3_add : "emotions,iespell,media,advhr,separator,print,separator,ltr,rtl,separator,fullscreen",
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left",
	theme_advanced_statusbar_location : "bottom",
	content_css : "../tinymce/examples/example_word.css",
    plugi2n_insertdate_dateFormat : "%Y-%m-%d",
    plugi2n_insertdate_timeFormat : "%H:%M:%S",
	external_link_list_url : "../tinymce/examples/example_link_list.js",
	external_image_list_url : "../tinymce/examples/example_image_list.js",
	media_external_list_url : "../tinymce/examples/example_media_list.js",
	file_browser_callback : "fileBrowserCallBack",
	paste_use_dialog : false,
	theme_advanced_resizing : true,
	theme_advanced_resize_horizontal : false,
	theme_advanced_link_targets : "_something=My somthing;_something2=My somthing2;_something3=My somthing3;",
	paste_auto_cleanup_on_paste : true,
	paste_convert_headers_to_strong : false,
	paste_strip_class_attributes : "all",
	paste_remove_spans : false,
	paste_remove_styles : false
	},{
	theme : "advanced",
	mode : "none",
	language : "en",
	height:"200",
	width:"100%",
	theme_advanced_layout_manager : "SimpleLayout",
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left",
	theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull",
	theme_advanced_buttons2 : "",
	theme_advanced_buttons3 : ""
	},{
	theme : "advanced",
	mode : "none",
	language : "en",
	width:"100%",
	theme_advanced_layout_manager : "SimpleLayout",
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left"
	}];

/*function tinyfy(settingid,divId) 
	{
    tinyMCE.settings = tinymceConfigs[settingid];
    tinyMCE.execCommand('mceAddControl', false, divId);        	
	}
*/	

function noticiasLerMais(id){
	jQuery("div#noticiaresumo"+id+"b").css("display","none");
	jQuery("div#noticiaresumo"+id).css("display","none");
	jQuery("div#noticiatexto"+id+"b").css("display","");
	jQuery("div#noticiatexto"+id).css("display","");
}

function noticiasLerMenos(id){
	jQuery("div#noticiaresumo"+id+"b").css("display","");
	jQuery("div#noticiaresumo"+id).css("display","");
	jQuery("div#noticiatexto"+id+"b").css("display","none");
	jQuery("div#noticiatexto"+id).css("display","none");
}
	
function tinyfy(settingid, div )
{
 	oFCKeditor = new FCKeditor( div ) ;
	oFCKeditor.BasePath	= host+'js/fckeditor/';

	var sSkinPath = oFCKeditor.BasePath + 'editor/skins/silver/' ;

	oFCKeditor.Height   = 300;
	oFCKeditor.Config['SkinPath'] = sSkinPath ;	
	oFCKeditor.Config['PreloadImages'] =
		sSkinPath + 'images/toolbar.start.gif' + ';' +
		sSkinPath + 'images/toolbar.end.gif' + ';' +
		sSkinPath + 'images/toolbar.buttonbg.gif' + ';' +
		sSkinPath + 'images/toolbar.buttonarrow.gif' ;
	
	oFCKeditor.ReplaceTextarea() ;
}

function limpaTiny(conteudo)
	{
	var content = conteudo;
	content = content.replace(/\+/g, "&#43;");
	content = content.replace(/\\/g, "&#92");
	//content = content.replace(/\&/g, "&#38");
	//content = content.replace(/\38/g, "&#38");
	//content = content.replace(/\x38/g, "&#38");
	//content = content.replace(/'/g, "&#39");
	return content;	
	}
function checkboxes()
	{
	replaceChecks();
	}
function replaceChecks() 
	{
	inputs = document.getElementsByTagName('input');
	for(var i=0; i < inputs.length; i++) 
		{
		if(inputs[i].getAttribute('type') == 'checkbox') 
			{
			var img = document.createElement('img');
			if(inputs[i].checked) 
				{
				img.src = imgTrue;
				} 
			else 
				{
				img.src = imgFalse;
				}
			img.id = 'checkImage'+i;
			img.onclick = new Function('checkChange('+i+')');
			inputs[i].parentNode.insertBefore(img, inputs[i]);
			inputs[i].style.display='none';
			}
		}
	}
function checkChange(i) 
	{
	if(inputs[i].checked) 
		{
		inputs[i].checked = '';
		document.getElementById('checkImage'+i).src=imgFalse;
		}
	else
		{
		inputs[i].checked = 'checked';
		document.getElementById('checkImage'+i).src=imgTrue;
		}
	}
// JANELA
	var mousex = 0;
	var mousey = 0;
	var grabx = 0;
	var graby = 0;
	var orix = 0;
	var oriy = 0;
	var elex = 0;
	var eley = 0;
	var diffx = 0;
	var diffy = 0;
	var algor = 0;
	var dragobj = null;
	var isMozilla = (document.all) ? 0 : 1;
    if (isMozilla) 	{document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);}
	function falsefunc() { return false; } // used to block cascading events
	function getMouseXY(e) // works on IE6,FF,Moz,Opera7
		{
	  	if (!e) e = window.event; // works on IE, but not NS (we rely on NS passing us the event)
		if (e)
			{
	    	if (e.pageX || e.pageY)
	    		{ // this doesn't work on IE6!! (works on FF,Moz,Opera7)
			    mousex = e.pageX;
			    mousey = e.pageY;
			    algor = '[e.pageX]';
			    if (e.clientX || e.clientY) algor += ' [e.clientX] '
	    		}
	    	else if (e.clientX || e.clientY)
	    		{ // works on IE6,FF,Moz,Opera7
	      		/*mousex = e.clientX + document.body.scrollLeft;
	      		mousey = e.clientY + document.body.scrollTop;*/
	      		mousex = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
			    mousey = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	      		algor = '[e.clientX]';
	      		if (e.pageX || e.pageY) algor += ' [e.pageX] '
	    		}  
	  		}
		}	
	function update(e)
		{
		getMouseXY(e); // NS is passing (event), while IE is passing (null)
		}
	function grab(context)
		{if (isMozilla) {document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);}
		document.onmousedown = falsefunc; // in NS this prevents cascading of events, thus disabling text selection
		dragobj = context;
	  	dragobj.style.zIndex = 10; // move it to the top
	  	document.onmousemove = drag;
	  	document.onmouseup = drop;
	  	grabx = mousex;
	  	graby = mousey;	  	
	  	if (isMozilla) 
	  		{/*
            elex= orix =e.layerX;
            eley= oriy =e.layerY;*/
        	}
        else 
        	{
            elex = orix =dragobj.offsetLeft;
	  		eley = oriy =dragobj.offsetTop;
            }
	  	update();
		}
	function drag(e) // parameter passing is important for NS family 
		{
	  	if (dragobj)
	  		{	  		
	    	if (isMozilla) 
	    		{
	    		if (diffx==0) 
		    		{
		    		diffx=e.pageX-parseInt(dragobj.style.left.replace(/px/,"").toString());
		    		diffy=e.pageY-parseInt(dragobj.style.top.replace(/px/,"").toString());
					}
		    	elex=e.pageX-diffx;
		    	eley=e.pageY-diffy; 
		    	}
        	else 
        		{
        		if (diffx==0) 
		    		{
		    		diffx=mousex-parseInt(dragobj.style.left.replace(/px/,"").toString());
		    		diffy=mousey-parseInt(dragobj.style.top.replace(/px/,"").toString());
					}
		    	elex=mousex-diffx;
		    	eley=mousey-diffy;
		    	}
			dragobj.style.position = "absolute";  		
			dragobj.style.top = (eley).toString(10) + 'px';
			dragobj.style.left = (elex).toString(10) + 'px';
	    	update();
	  		}	  	
	  	return false; // in IE this prevents cascading of events, thus text selection is disabled
		}	
	function drop()
		{
	  	if (dragobj)
	  		{
	    	//dragobj.style.zIndex = 1;
	    	dragobj = null;
	  		}
	  	update();
	  	document.onmousemove = update;
	  	document.onmouseup = null;
	  	document.onmousedown = null;   // re-enables text selection on NS
	  	diffx=0;
	  	diffy=0;
		}
	function closeForm(accao,idDiv)
		{
		try {for (n in tinyMCE.editors) {tinyMCE.execCommand('mceRemoveControl', false, n);}} catch(e){}
		//alert(accao+'&pagina='+document.getElementById('paginas').value+'&palavra='+document.getElementById('palavra').value,'grelha');
		//utilizadoresPesquisar&pagina=&palavra=
		try{ abrir(accao+'&pagina='+document.getElementById('pagina').value+'&palavra='+document.getElementById('palavra').value,'grelha'); }catch(e){}		
		document.getElementById(idDiv).innerHTML="";
		jQuery('#mask').hide();
		}
	function closeFormulario(idDiv){
		document.getElementById(idDiv).innerHTML="";
	}	
	function closePesquisa(idDiv)
		{
		document.getElementById(idDiv).innerHTML="";
		}
	function esconderDiv(id)
		{
			document.getElementById(id).style.display='none';
		}
	function mostrarDiv(id)
		{
			document.getElementById(id).style.display='block';
		}		
	function destrocarDiv(id)
		{
			if (document.getElementById(id).style.display!='none') 
				{document.getElementById(id).style.display='none';}
			else
				{document.getElementById(id).style.display='block';}
		}
	function alternarDiv(idSelect, valor)
		{
		for(i=0;i<document.getElementById(idSelect).length;i++)
			{
			if(document.getElementById(idSelect).options[i].value==valor)
				{
				document.getElementById(valor).style.display='block';
				}
			else
				{
				document.getElementById(document.getElementById(idSelect).options[i].value).style.display='none';
				}
			}
		}
		
////////////////////////////////////////
// AJAX
	function criarXML(form,divID) 
		{
		get(host+'includes/response.php', form,divID)
		}
	function tipoProcedimento(prodVar) 
		{
		var procedimento = document.getElementById('procedimento');
		procedimento.value = prodVar; 
		}
	function tipoParametros()
		{
		var nomeFilhoVar;
		var raizXMLVar = document.getElementById('raizXML');
		var procedimentoVar = document.getElementById('procedimento');
		var filhoVar = document.getElementById('nomeFilho');
		var estadoVar = document.getElementById('tipoEstado');
		  
		var xmlObj = document.getElementById('arvoreXML');
		var i;
		var count = 0;
		for (i=0; i<xmlObj.options.length; i++) 
			{
		    if (xmlObj.options[i].selected) 
				{
				nomeFilhoVar = xmlObj.options[i].value;
				}
			}
		raizXMLVar.value = nomeFilhoVar;
		procedimentoVar.value = document.getElementById('procedimento').value;
		filhoVar.value = document.getElementById('nomeFilho').value;
		estadoVar.value = document.getElementById('tipoEstado').value;
		
		abrir('tiposCriarXML&pai='+nomeFilhoVar+'&procedimento='+procedimentoVar.value+'&filho='+filhoVar.value+'&estado='+estadoVar.value,'formAuxiliar');
		}
	
	function abrirf(accao, divName, idMenu, banner){
		
		if(accao=='frontend'){		
			jQuery("div#menuops").children().each(function(){
			
				//mudar a cor da seccao activa no elemento <a>
	   			if(this.id==("menuop"+idMenu)){
					jQuery(this).find("a.menuop").css("color","#112c65");
					jQuery(this).find("a.menuop").css("font-weight","bold");
					//actualizar a localizacao
					//jQuery("div#menuoplocation").html("Home"+ ((jQuery(this).find("a.menuop").text()=="Home")?" ":" > "+jQuery(this).find("a.menuop").text()) );
	    		}else{
	    			jQuery(this).find("a.menuop").css("color","#154179");
	    			jQuery(this).find("a.menuop").css("font-weight","");
	    		}
			});
		
			jQuery("div#[id^=submenugroup]").children().each(function(){
				jQuery(this).find("a.menuop").css("color","#53b7e6");
			});
							
			//actualizar o banner da seccao
			if(banner!=''){ jQuery("img#imagem_banner").attr("src",banner);	}
	
			//carregar a seccao com um pedido ajax
			//alert(host+'includes/response.php?div='+divName+'&accao='+accao+'&id='+idMenu);
			getData(host+'includes/response.php?div='+divName+'&accao='+accao+'&id='+idMenu, divName);
		}else{
			//entao usamos a banner como seccao (reutilizacao do codigo... ou perguica)
			if(accao=='subscrever'){jQuery("div#form").change();}
			getData(host+'includes/response.php?div='+divName+'&accao='+accao+'&id='+idMenu+'&seccao='+banner, divName);
		}
	}	
	
	function toggleSubs($id){
		
		if(jQuery("div#submenugroup"+$id).css("display")=='none'){
			jQuery("div#[id^=submenugroup]").hide();
			jQuery("div#submenugroup"+$id).show();
		}else{
			jQuery("div#submenugroup"+$id).hide();
		}
	
	}
		
	function reajustaDim(){
		var A;
	 	//var x; 	
		if(window.innerHeight!==undefined){ 		
			A = [window.innerWidth,window.innerHeight];
			//ieh e global
			ieh = ((A[1]-253)+"px");
			jQuery("div#pagina").css("height",ieh);
		 	//abrir('utilizadoresHome','pagina');
		 }else{
		 	//alert("debug code.js 409 "+ieh);
			var D = (document.body.clientWidth)? document.body: document.documentElement;
			A = [D.clientWidth,D.clientHeight];
			//alert("debug code.js 412 "+A[1]+" "+(jQuery(window).height()-284));
			if(A[1]<(jQuery(window).height()-284)){
				ieh = ((A[1]+73));
			}else{
				ieh= A[1];
			}
			jQuery("body").css("height",ieh+"px");
			//jQuery("div#pagina").css("min-height",ieh+"px");
			jQuery("div#pagina").css("height","100%");
			jQuery("div#pagina").css("display","block");
			//trigo tambem e global 
			trigo = setInterval("dimIt('"+ieh+"')",50);
			//alert(" debug code.js 418 "+jQuery("div#bgwrap").height());
			//abrir('utilizadoresHome','pagina');		
		}
	}	
		
	function abrir(accao,divName)
		{
		
		//alert("debug code.js 404"+accao+" "+divName);
		//isto e so para o backoffice
		if(divName=='pagina'){ reajustaDim(); }
	
		if(accao=="utilizadoresProcurar"){
			alert("debug code.js 409 "+accao+" "+divName+" "+jQuery("input#q").val());
			getData(host+'includes/response.php?div='+divName+'&accao='+accao+'&palavra='+jQuery("input#q").val(),divName);
		}else{
			//alert("debug code.js 431"+accao+" "+divName);
			getData(host+'includes/response.php?div='+divName+'&accao='+accao,divName);
		}
		
		/*jQuery stuff for modal behavior*/
		if(divName=="form"){
			//Get the A tag
			var id = jQuery(this).attr(divName);
			//Get the screen height and width
			var maskHeight = jQuery(document).height();
			var maskWidth = jQuery(window).width();
			//Set heigth and width to mask to fill up the whole screen
			jQuery('#mask').css({'width':maskWidth,'height':maskHeight});
			//transition effect		
			jQuery('#mask').fadeIn(500);	
			jQuery('#mask').fadeTo("slow",0.8);	
			jQuery("div#form").change();			
			//transition effect
			jQuery(id).fadeIn(2000);
		}
		//alert(host+'includes/response.php?div='+divName+'&accao='+accao);

	}
 	
 	function openBanner(id,path){
 		//alert(path);
 		if(path!=''){ window.open(path); }
		getData(host+'includes/response.php?accao=countbanner&id='+id,'form');		
	}
 	
 	function valida(form){
 		//var email = document.getElementById('emailaddress');
 		var email = jQuery("#email").val();
		var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
		
		if (!filter.test(email)) {
			jQuery("#msgform").html('<div style="float:left;width:100%;font-size:10px;color:#f00;" >&nbsp;endere&ccedil;o de email inv&aacute;lido.</div>');
			jQuery("#email").focus();
		}else if(jQuery("#nome").val()==''){
			jQuery("#msgform").html('<div style="float:left;width:100%;font-size:10px;color:#f00;" >&nbsp;o nome &eacute; necess&aacute;rio.</div>');
			jQuery("#nome").focus();
		}else{
			
			post('frontendNL',form,'msgform');		
		}
 	}
 	
	function contactosSeleccionar(valor)
		{
		abrir('contactosFiltro&conta='+valor,'grelha');	
		}
		
	function alojamentosSeleccionar(valor)
		{
		abrir('alojamentosSeleccionar&alojamento='+valor,'auxiliarAlojamentos');		
		}
	function utilizadoresSeleccionar(valor)
		{
		abrir('utilizadoresSeleccionar&empresa='+valor,'auxiliarUtilizadores');		
		}
	function encomendasUtilizadoresListar(valor)
		{
		abrir('encomendasUtilizadoresListar&palavra='+valor,'auxiliarEncomendas');		
		}
	function catalogoSeleccionar(valor)
		{
		abrir('marcacoesCatalogoListar&palavra='+valor,'catalogoListar');		
		}
	function marcacoesUtilizadoresListar(valor)
		{
		abrir('marcacoesUtilizadoresListar&palavra='+valor,'auxiliarMarcacoes');		
		}
	function empresasTipo(valor)
		{
		abrir('empresasTipo&tipo='+valor,'auxiliarEmpresas');		
		}
	function catalogoEmpresa(valor1,valor2)
		{
		abrir('catalogoEmpresa&tipo='+valor1+'&pagina='+valor2,'produtosMontra');		
		}		
	function produtosSeleccionar(valor1,valor2,valor3)
		{
		abrir('catalogoMontra&empresa='+valor1+'&paginaEmpresas='+valor2+'&paginaProdutos='+valor3,'produtosMontra');		
		}
	function detalheProduto(valor1,valor2,valor3)
		{
		abrir('catalogoMontraDetalhe&id='+valor1+'&paginaEmpresas='+valor2+'&paginaProdutos='+valor3,'produtosMontra');	
		}
	function tipoPerfil(perfil)
		{
		if(perfil=='Interagir')
			{
			document.getElementById('trPerfil').style.display='block';
			}
		else
			{
			document.getElementById('trPerfil').style.display='none';
			document.getElementById('perfil').checked='false';
			}
		}
	function disablePerfil(frm)
		{
		inputs = document.getElementsByTagName('input');
		for(var i=0; i < inputs.length; i++) 
			{
			if(inputs[i].getAttribute('type') == 'checkbox') 
				{
				inputs[i].disabled = true;
				inputs[i].checked = true;
				}
			}
		}	
	function enablePerfil(frm)
		{
		inputs = document.getElementsByTagName('input');
		for(var i=0; i < inputs.length; i++) 
			{
			if(inputs[i].getAttribute('type') == 'checkbox') 
				{
				inputs[i].disabled = false;
				inputs[i].checked = false;
				}
			}
		}
	function pesquisar(accao,divName)
		{
		getData(host+'includes/response.php?div='+divName+'&accao='+accao+'&pagina=1&palavra='+document.getElementById('palavra').value,divName);
		}
	function paginar(accao,pagina,divName)
		{
		getData(host+'includes/response.php?div='+divName+'&accao='+accao+'&pagina='+pagina+'&ordem='+document.getElementById('ordem').value+'&palavra='+document.getElementById('palavra').value,divName);
		}
	function ordenar(accao,ordem,divName)
		{
		document.getElementById('ordem').value=ordem;
		getData(host+'includes/response.php?div='+divName+'&accao='+accao+'&pagina='+document.getElementById('paginas').value+'&ordem='+document.getElementById('ordem').value+'&palavra='+document.getElementById('palavra').value,divName);
		}
	function pesquisaTotal(accao,divName)
		{//alert(host+'includes/response.php?div='+divName+'&accao='+accao+'&pagina='+document.getElementById('paginas').value+'&ordem='+document.getElementById('ordem').value+'&palavra='+document.getElementById('palavra').value);
		getData(host+'includes/response.php?div='+divName+'&accao='+accao+'&pagina='+document.getElementById('paginas').value+'&ordem='+document.getElementById('ordem').value+'&palavra='+document.getElementById('palavra').value,divName);
		}
	function profundidade(accao,idProfundidade,divName)
		{
		document.getElementById('idProfundidade').value=idProfundidade;
		getData(host+'includes/response.php?div='+divName+'&accao='+accao+'&pagina=1&palavra=%&idProfundidade='+document.getElementById('idProfundidade').value,divName);
		}
	function antes()
		{
		historicoInt--;
		if(historicoInt<=0) { historicoInt=0; }
		abrir('historicoVer&id='+historico[historicoInt][0],historico[historicoInt][1]);			
		}
	function depois()
		{
		historicoInt++;
		if(historicoInt>=(historico.length-1)) { historicoInt=historico.length-1; }
		abrir('historicoVer&id='+historico[historicoInt][0],historico[historicoInt][1]);		
		}
	function stopRKey(evt,tipo,pesquisa,ordem) 
		{
	  	evt = (evt) ? evt : ((event) ? event : null);
	  	var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
	  	if ((evt.keyCode == 13) && (node.type=="text"))  
	  		{
	  		pesquisar(tipo,pesquisa,ordem);
	  		return false;
	  		}
	  	return true;
		}
	function alterarArea(form,texto)
		{
		var primeiraCaixa=false;
		var estado=false;
		for (var i=0;i<form.length;i++) 
			{
			var current = form.elements[i];
			if (current.type=='checkbox' && current.name.indexOf(texto)!=-1) 
				{
				if(!primeiraCaixa) {estado=form.elements[i].checked; primeiraCaixa=true;}
				current.checked=!estado;
				}
			}
		}
		
	function postRCE(accao,form, divID, editor){
		try{
			//alert(" ["+accao+"] ["+divID+"] ");
			//var x =	document.getElementById('html___Frame').contentWindow.document.getElementById('xEditingArea').getElementsByTagName('iframe')[0].contentWindow.document.getElementsByTagName('html')[0].innerHTML;
			var x = jQuery("#"+editor+"___Frame").contents().find("#xEditingArea").contents().contents().find("body").html();
			//var x = window.frames[0].document.getElementById('xEditingArea').getElementsByTagName('iframe')[0].contentWindow.document.getElementsByTagName('body')[0].innerHTML;
			if(x==null || typeof(x)=="undefined"){ x = jQuery("textarea#"+editor).html(); }
			form[editor].innerHTML = x;
			post(accao, form, divID);
		}catch(e){
			post(accao, form, divID);
		}
	}
	 		
	function post(accao,form,divID)
		{
		//alert(accao+" "+form+" "+divID);
		var dataSource=host+'includes/archive.php';
		var params='accao='+accao+'&div='+divID+'&';
		for (var i=0;i<form.length;i++) 
			{
			var current = form.elements[i];
			if (current.type=='radio' || current.type=='checkbox') 
				{if(current.checked){params+=current.name+"="+ current.value+"&";}}
			else if (current.type=='select-multiple') 
				{
				for (var j=0;j<current.length;j++)
					{
					if(current.options[j].selected){params+=current.name+"="+ current.options[j].value+"&";}
					}
				} 
			else if(current.type=='textarea' && current.name.indexOf('Editor')!=-1) 
				{				
					if(oFCKeditor != null && typeof('FCKeditorAPI') != 'undefined')
					{
						var ei = FCKeditorAPI.GetInstance(oFCKeditor.InstanceName);
						if (ei != null)
							current.value=ei.GetHTML();
						params+=current.name+"="+ escape(limpaTiny(current.value))+"&";
				}
				else
				{
					try
						{current.value=tinyMCE.get(current.name).getContent();
						try{tinyMCE.execCommand('mceRemoveControl', false, current.name);} catch(e) {alert(e);}
						}
					catch(e){}
					params+=current.name+"="+ escape(limpaTiny(current.value))+"&";
					}
				}
			else 
				{
				if(current.name!='') {params+=current.name+"="+current.value+"&";}
				}	
			}
		//alert(dataSource+" "+params+" "+divID);
		postData(dataSource, params,divID);
		}
	function get(dataSource, form,divID)
		{
		var current='';
		dataSource+='?div='+divID+'&';		
		for (var i=0;i<form.length;i++) {current = form.elements[i];dataSource+=current.name+"="+ current.value+"&";}
		getData(dataSource, divID);
		}
	function voltar()
		{
		if (histInt-1>0) 
			{
			histInt--;
			getData1(histData[histInt],histDiv[histInt]);
			}
		else
			{
			histInt=0;
			//getData1(host+'includes/response.php?div=conteudo&page=home','conteudo');
			}
		}
	function setSeparador(sep)
		{
		separador=sep.getAttribute('id');
		//alert(separador);
		for(var i=0; i<document.getElementsByTagName('a').length; i++)
			{
			var current=document.getElementsByTagName('a')[i];
			//alert(current.getAttribute('id'));	
			try
				{
				if(current.getAttribute('id')==separador && current.getAttribute('id').indexOf('separador')!=-1) 
					{current.style.color='#FF0000';}//est� seleccionado
				if(current.getAttribute('id')!=separador && current.getAttribute('id').indexOf('separador')!=-1) 
					{current.style.color='#0000FF';}// nao est�
				}
			catch (e){}
			}
		}
	function getData(dataSource, divID)
		{
		histInt++;
		histData[histInt]=dataSource;
		histDiv[histInt]=divID;
		
		var XMLHttpRequestObject = false;
		if (window.XMLHttpRequest) {XMLHttpRequestObject = new XMLHttpRequest();} 
		else if (window.ActiveXObject) {
		try {XMLHttpRequestObject = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {
	         	try {XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");} catch (e) {}}}
		if(XMLHttpRequestObject) 
			{
			var obj = document.getElementById(divID);
			XMLHttpRequestObject.open("GET", dataSource,true);
			XMLHttpRequestObject.setRequestHeader("Content-Type","text/xml");
	        XMLHttpRequestObject.setRequestHeader("encoding","ISO-8859-1");
			XMLHttpRequestObject.onreadystatechange = function()
				{ 
				//document.getElementById('loader').innerHTML="<img src='"+host+"imagens/ajax-loader.gif' alt=''/>";
				if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) 
					{
					obj.innerHTML = XMLHttpRequestObject.responseText;	
					delete XMLHttpRequestObject;
					XMLHttpRequestObject = null;
					//document.getElementById('loader').innerHTML="";			
					}
				}
			XMLHttpRequestObject.send(null);	
			}
		}
	function getData1(dataSource, divID)
		{
		var XMLHttpRequestObject = false;
		if (window.XMLHttpRequest) {XMLHttpRequestObject = new XMLHttpRequest();} 
		else if (window.ActiveXObject) {
		try {XMLHttpRequestObject = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {
	         	try {XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");} catch (e) {}}}
		if(XMLHttpRequestObject) 
			{
			var obj = document.getElementById(divID);
			XMLHttpRequestObject.open("GET", dataSource,true);
			XMLHttpRequestObject.setRequestHeader("Content-Type","text/xml");
	        XMLHttpRequestObject.setRequestHeader("encoding","ISO-8859-1");
			XMLHttpRequestObject.onreadystatechange = function()
				{
				if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) 
					{
					obj.innerHTML = XMLHttpRequestObject.responseText;											
					delete XMLHttpRequestObject;
					XMLHttpRequestObject = null;					
					}
				}
			XMLHttpRequestObject.send(null);			
			}
		}	
	function postData(dataSource,parameters,divID)
		{
		//alert(dataSource+" "+parameters+" "+divID);
		var XMLHttpRequestObject = false;
		if (window.XMLHttpRequest) {XMLHttpRequestObject = new XMLHttpRequest();} 
		else if (window.ActiveXObject) {
		try {XMLHttpRequestObject = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {
	         	try {XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");} catch (e) {}}}
		if(XMLHttpRequestObject) 
			{
			var obj = document.getElementById(divID);
			XMLHttpRequestObject.open("POST", dataSource,true);
			XMLHttpRequestObject.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			XMLHttpRequestObject.setRequestHeader("Content-length", parameters.length);
	   		XMLHttpRequestObject.setRequestHeader("Connection", "close");
			XMLHttpRequestObject.onreadystatechange = function()
				{
				document.getElementById('loader').innerHTML="<img src='"+host+"imagens/ajax-loader.gif' alt=''/>";
				if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) 
					{
					//alert("["+XMLHttpRequestObject.responseText+"]");
					obj.innerHTML = XMLHttpRequestObject.responseText;							
					delete XMLHttpRequestObject;
					XMLHttpRequestObject = null;
					document.getElementById('loader').innerHTML="";
					}
				}		
			//alert(parameters);	
			XMLHttpRequestObject.send(parameters);			
			}
		}
	function getValue(dataSource,id)
		{
		dataSource=host+'includes/response.php?accao='+dataSource;
		var value="";
		var XMLHttpRequestObject = false;
		if (window.XMLHttpRequest) {XMLHttpRequestObject = new XMLHttpRequest();} 
		else if (window.ActiveXObject) {
		try {XMLHttpRequestObject = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {
	         	try {XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");} catch (e) {}}}
		if(XMLHttpRequestObject) 
			{
			XMLHttpRequestObject.open("GET", dataSource,true);
			XMLHttpRequestObject.setRequestHeader("Content-Type","text/xml");
	        XMLHttpRequestObject.setRequestHeader("encoding","ISO-8859-1");
			XMLHttpRequestObject.onreadystatechange = function()
				{
				if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) 
					{
					document.getElementById(id).value = XMLHttpRequestObject.responseText;							
					delete XMLHttpRequestObject;
					XMLHttpRequestObject = null;
					}return false;
				} 		
			XMLHttpRequestObject.send(null);
			}
		}
	function getPhpValue(dataSource)
		{
		dataSource=host+'includes/response.php?accao='+dataSource;
		var value="";
		var XMLHttpRequestObject = false;
		if (window.XMLHttpRequest) {XMLHttpRequestObject = new XMLHttpRequest();} 
		else if (window.ActiveXObject) {
		try {XMLHttpRequestObject = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {
	         	try {XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");} catch (e) {}}}
		if(XMLHttpRequestObject) 
			{
			XMLHttpRequestObject.open("GET", dataSource,false);
			XMLHttpRequestObject.setRequestHeader("Content-Type","text/xml");
	        XMLHttpRequestObject.setRequestHeader("encoding","ISO-8859-1");
			XMLHttpRequestObject.send(null);
			if (XMLHttpRequestObject.status == 200) 
				{
				phpValue = XMLHttpRequestObject.responseText;							
				delete XMLHttpRequestObject;
				XMLHttpRequestObject = null;
				}		
			}
		}
	function uploadFicheiros(idFrame,idField,pasta)
		{//alert(isMozilla);
		var ficheiro='';
		var arrFich='';
		if(!isMozilla)
			{
			try	{
				if(document.frames[idFrame].document.forms[0].elements[0].value!='') 
					{
					ficheiro=document.frames[idFrame].document.forms[0].elements[0].value;
					document.frames[idFrame].document.forms[0].elements[1].value=pasta;
					document.frames[idFrame].document.forms[0].elements[2].value=idField;
					if (ficheiro!='') 
						{
						if(ficheiro.indexOf("/")!=-1)	{	arrFich=ficheiro.split("/"); }
						if(ficheiro.indexOf("\\")!=-1)	{	arrFich=ficheiro.split("\\");}
						document.getElementById(idField).value=arrFich[arrFich.length-1];
						document.frames[idFrame].document.forms[0].submit();
						}					
					}
				}
			catch (e) {}
			}
		else
			{
			try	{
				var j=-1;
				for(var i=0;i<window.frames.length;i++)
					{
					if(window.frames[i].name==idFrame) {j=i;}
					}
				if(j==-1) {return false;}
				if(window.frames[j].document.forms[0].elements[0].value!='') 
					{
					ficheiro=window.frames[j].document.forms[0].elements[0].value;
					window.frames[j].document.forms[0].elements[1].value=pasta;
					window.frames[j].document.forms[0].elements[2].value=idField;
					if (ficheiro!='') 
						{
						if(ficheiro.indexOf("/")!=-1)		{	arrFich=ficheiro.split("/"); }
						else if(ficheiro.indexOf("\\")!=-1)	{	arrFich=ficheiro.split("\\");}	
						document.getElementById(idField).value=arrFich[arrFich.length-1];
						window.frames[j].document.forms[0].submit();
						}					
					}
				}
			catch (e) 
				{}
			}
		return false;		
		}
	function uploadF(accao,form,divID)
		{
		var current='';
		dataSource=host+'includes/archive.php';
		var params='accao='+accao+'&div='+divID+'&';
		if (!validar(form)) {return false;}
		var imagemPequena=imagemGrande=kmz='';
		var f = document.frames || window.frames;
		try	{if(f[0].document.forms[0].elements[0].value!='') {imagemPequena=f[0].document.forms[0].elements[0].value;}}catch (e) {}
		try	{if(f[0].document.forms[0].elements[1].value!='') {imagemGrande=f[0].document.forms[0].elements[1].value;}}catch (e) {}
		try	{if(f[1].document.forms[0].elements[0].value!='') {kmz=f[1].document.forms[0].elements[0].value;}}catch (e) {}
		try	{f[0].document.forms[0].submit();}catch (e) {}
		try	{f[1].document.forms[0].submit();}catch (e) {}
			
		for (var i=0;i<form.length;i++) 
			{
			current = form.elements[i];
			current.value=trim(current.value);
			if (current.name=='imagemPequena' && imagemPequena!='') 	{current.value=imagemPequena;}
			if (current.name=='imagemGrande'  && imagemGrande!='') 		{current.value=imagemGrande;}
			if (current.name=='kmz'           && kmz!='') 				{current.value=kmz;}
			if (current.type=='radio') 	{if(current.checked){params+=current.name+"="+ current.value+"&";}}
			else 						{params+=current.name+"="+ current.value+"&";}	
			}
		//alert(dataSource+'-'+params+'-'+divID);
		postData(dataSource, params,divID);
		return true;
		}	
	function formMsg(msg) {document.getElementById('msg').innerHTML="<div style='font-family: Arial, Helvetica, sans-serif; font-size: 9px; font-style: normal; line-height: normal; font-weight: bold; font-variant: normal; text-transform: uppercase; color: #AA3333; text-decoration: none;'><img src='"+host+"imagens/10pixel.gif' alt='' width='20' height='20' />"+msg+"</div>";	}
	function personalizar(dataSource,form,divID)
		{
		var facturacao=false;
		var entrega=false;
		var current='';
		for (var i=0;i<form.length;i++) 
			{
			current = form.elements[i];
			if(current.name=="facturacao" && current.checked) {facturacao=true;}
			if(current.name=="entrega" && current.checked) {if (current.value=="outra") {entrega=true;}}
			}
		if (!facturacao)
			{
			for (var i=0;i<form.length;i++) 
				{current = form.elements[i];
				if (current.name=="ftrato" || current.name=="fnome" || current.name=="fmorada" || current.name=="fnif" || 
					current.name=="fcodigoPostal" || current.name=="flocalidade" || current.name=="fpais"  )
					{if(!(current.value.length>0)) {formMsg("O "+current.name.substring(1,(current.name.length-1))+" � um campo mandat�rio.");return false;}}
				}
			}
		if (entrega)
			{
			for (var i=0;i<form.length;i++) 
				{current = form.elements[i];
				if (current.name=="etrato" || current.name=="enome" || current.name=="emorada" || current.name=="enif" || 
					current.name=="ecodigoPostal" || current.name=="elocalidade" || current.name=="epais"  )
					{if(!(current.value.length>0)) {formMsg("O "+current.name.substring(1,(current.name.length))+" � um campo mandat�rio.");return false;}}
				}
			}
		post(dataSource, form,divID);
		return true;	
		}
	function getRandomNum(lbound, ubound) 
		{
		return (Math.floor(Math.random() * (ubound - lbound)) + lbound);
		}
	function getRandomChar(number, lower, upper, other, extra) 
		{
		var numberChars = "0123456789";
		var lowerChars = "abcdefghijklmnopqrstuvwxyz";
		var upperChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		var otherChars = "`~!@#$%^&*()-_=+[{]}\\|;:'\",<.>/? ";
		var charSet = extra;
		if (number == true)	charSet += numberChars;
		if (lower == true)	charSet += lowerChars;
		if (upper == true)	charSet += upperChars;
		if (other == true)	charSet += otherChars;
		return charSet.charAt(getRandomNum(0, charSet.length));
		}
	function getPassword(length, extraChars, firstNumber, firstLower, firstUpper, firstOther,latterNumber, latterLower, latterUpper, latterOther) 
		{
		var rc = "";
		if (length > 0)	rc = rc + getRandomChar(firstNumber, firstLower, firstUpper, firstOther, extraChars);
		for (var idx = 1; idx < length; ++idx)
			{
			rc = rc + getRandomChar(latterNumber, latterLower, latterUpper, latterOther, extraChars);
			}
		return rc;
		}
	function validar(form)
		{
		var current='';
		for (var i=0;i<form.length;i++) 
			{
			current = form.elements[i];
			current.value=trim(current.value);
			if (current.name=="codigo") {if(!(current.value.length>0)){formMsg("O c�digo � um campo mandat�rio.");return false;}}
			if (current.name=="voucher") {if(!(current.value.length>0)){formMsg("O voucher � um campo mandat�rio.");return false;}}
			if (current.name=="nome") 	{if(!(current.value.length>0)){formMsg("O Nome � um campo mandat�rio.");return false;}}
			if (current.name=="femail") {if(!(current.value.length>0)){formMsg("A Email � um campo mandat�rio.");return false;}}
			if (current.name=="acesso") {if(!(current.value.length>7)){formMsg("O Acesso tem que ter pelo menos 8 caracteres.");return false;}}
			if (current.name=="chave") 	{if(!(current.value.length>7)){formMsg("A Chave tem que ter pelo menos 8 caracteres.");return false;}}
			if (current.name=="acesso" || current.name=="chave")
				 {if(!isAlphaNum(current.value)){formMsg("S� podem ser caracteres do '0' ao '9' e de 'a' a 'z'.");return false;}}
			if (current.name=="preco") 	{if(!(current.value.length>0)){formMsg("O Pre�o � um campo mandat�rio.");return false;}}
			if (current.name=="preco" || current.name=="custo")
				{if (current.value.length>0)
					{var decimal=/^((\d+(\.\d+)?)|((\d+\.)?\d+))$/;
					if(current.value.search(decimal)==-1) {formMsg("Os campos pre�o e custo s�o decimais.(eg: 12.35)");return false;}
					}
				}
			if (current.name.indexOf("email")!=-1) 	{if(!validarEmail(current.value)) {formMsg("Email inv�lido.");return false;}}
			if ((current.name.indexOf("pontos")!=-1) ||(current.name.indexOf("milhas")!=-1))  
				{var inteiro=/^[0-9]+$/;if(current.value.search(inteiro)==-1) {formMsg("Os campos pontos e milhas t�m que ser inteiros.");return false;}}			
			}
		return true;
		}
	function isAlphaNum(tStr)
		{
		var alphaNum=/[0-9a-z]*/;
		var arr=tStr.match(alphaNum);
		if (arr==null) {return false;}
		if (arr[0].length!=tStr.length){return false;}
		return true;
		}
	function validarEmail(emailStr)
		{ 
		var checkTLD=1;
		var knownDomsPat=/^([a-zA-Z]{2,})$/;
		var emailPat=/^(.+)@(.+)$/;
		var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
		var validChars="\[^\\s" + specialChars + "\]";
		var quotedUser="(\"[^\"]*\")";
		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
		var atom=validChars + '+';
		var word="(" + atom + "|" + quotedUser + ")";
		var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
		var matchArray=emailStr.match(emailPat);
		if (matchArray==null) {return false;	}
		var user=matchArray[1];
		var domain=matchArray[2];
		for (i=0; i<user.length; i++) {if (user.charCodeAt(i)>127) {return false; }}
		for (i=0; i<domain.length; i++) {if (domain.charCodeAt(i)>127) {return false; }}
		if (user.match(userPat)==null) {return false;}
		var IPArray=domain.match(ipDomainPat);
		if (IPArray!=null) {for (var i=1;i<=4;i++) {if (IPArray[i]>255) {return false;}}return true;}
		var atomPat=new RegExp("^" + atom + "$");
		var domArr=domain.split(".");
		var len=domArr.length;
		for (i=0;i<len;i++) {if (domArr[i].search(atomPat)==-1) {return false;}}
		if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) 
		{return false;}
		if (len<2) {return false;}
		return true;
		}
	function trim(s) {return rtrim(ltrim(s));}
	function ltrim(s)
		{
		var l=0;
		while(l < s.length && s[l] == ' '){l++;}
		return s.substring(l, s.length);
		}
	function rtrim(s)
		{
		var r=s.length -1;
		while(r > 0 && s[r] == ' '){r-=1;}
		return s.substring(0, r+1);
		}
	function mudarLayer(open,close)
		{
		abrirl=open.split(",");
		fechar=close.split(",");
		for(i=0;i<abrirl.length;i++) 
			{
    		if (abrirl[i]!='') {document.getElementById(abrirl[i]).style.display="block";}
  			}
		for(j=0;j<fechar.length;j++) 
			{
    		if (fechar[j]!='') {document.getElementById(fechar[j]).style.display="none";}
  			}
		}
	function limpa(campo,valorInicial) 
		{
		if (valorInicial!=undefined)
			{
				if (campo.value == valorInicial)
				{
				campo.value="";
				}
			}
		else
			{
			campo.value="";
			}
		}	
	function setSession(session,value)
		{
		//alert(session+"----"+value);
		getValue(host+'includes/response.php?sessao='+session+'&valor='+value);
		}
	function display(layer)
		{
		if (document.getElementById(layer).style.display=="none")
			{document.getElementById(layer).style.display="block";}
		else
			{document.getElementById(layer).style.display="none";}
		}
	function inteiro(evt) 
		{ 
    	var charCode = (evt.which) ? evt.which : window.event.keyCode; 
		if (charCode <= 13) 
			{ 
			return true; 
			} 
    	else 
    		{ 
        	var keyChar = String.fromCharCode(charCode); 
        	var re = /[0-9]/ 
        	return re.test(keyChar); 
    		}
    	}
    function moeda(fld, milSep, decSep, e) 
    	{
  		var sep = 0;
  		var key = '';
  		var i = j = 0;
  		var len = len2 = 0;
  		var strCheck = '0123456789';
  		var aux = aux2 = '';
  		var whichCode = (window.Event) ? e.which : e.keyCode;
		if (whichCode == 13) return true;  // Enter
		if (whichCode == 8) return true;  // Delete
		key = String.fromCharCode(whichCode);  // Get key value from key code
		if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
		len = fld.value.length;
		for(i = 0; i < len; i++)
			if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
  		aux = '';
  		for(; i < len; i++)
  			if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
		aux += key;
		len = aux.length;
		if (len == 0) fld.value = '';
		if (len == 1) fld.value = '0'+ decSep + '0' + aux;
		if (len == 2) fld.value = '0'+ decSep + aux;
		if (len > 2) 
			{
		  	aux2 = '';
		  	for (j = 0, i = len - 3; i >= 0; i--) 
		  		{
		    	if (j == 3) 
		    		{
		      		aux2 += milSep;
		      		j = 0;
		    		}
		    	aux2 += aux.charAt(i);
		    	j++;
		  		}
			fld.value = '';
		  	len2 = aux2.length;
		  	for (i = len2 - 1; i >= 0; i--)
		  		fld.value += aux2.charAt(i);
		  	fld.value += decSep + aux.substr(len - 2, len);
			}
		return false;
		}
	function latlong(src, event, sn)
		{
		var s = src.value;
		var ls = s[s.length-1];
		var unicode = event.charCode ? event.charCode : event.keyCode;		
		if (unicode<32) return;		
		var c = String.fromCharCode(unicode);
		var i = s.length;
		c = c.toUpperCase();
		//alert(i);
		if (i==0)
			{
			if(sn.indexOf(c)<0) c = '';
			else c += ' ';
			}

		if (i==2 && !(c>='0' && c<='9')) c = '';
		if (i==3)
			{
			if (ls=='9' && c!='0') c = '';
			if (ls!='9' && !(c>='0' && c<='9')) c = '';
			if (c!='') c += '�';
			}
		if (i==5 && !(c>='0' && c<='1')) c = '';
		if (i==6)
			{
			if (ls=='1' && !(c>='0' && c<='8')) c = '';
			if (ls!='1' && !(c>='0' && c<='9')) c = '';				
			}
		if (i==7)
			{
			if (!(c>='0' && c<='9')) c = '';
			if (c!='') c += "'";
			}
		if (i==9 && !(c>='0' && c<='9')) c = '';
		if (i==10)
			{
			if (ls=='9' && c!='0') c = '';
			if (ls!='9' && !(c>='0' && c<='9')) c = '';
			if (c!='') c += '.';
			}
		if (i==15)	{c='"';}
		if (i>15)
			{c='';}
		if (c!='') src.value = s+c;
		if ( window.ActiveXObject ) 
			{event.returnValue = false;}
		else 
			{event.preventDefault();}
		}		
		
		
/***********************  MAPS	START ********************/
 	var map = null;
    var geocoder = null;
    //ABQIAAAAET7M_JXw0z2YvIsLVhowfRT2yXp_ZAY8_ufC3CFXhHIE1NvwkxTK3QJ8SRPXkHk0rJP2zaodi1xwHA
	//ABQIAAAAET7M_JXw0z2YvIsLVhowfRSLuE7hPfVipgYVIQlAqEMArEPx_hTqU4LWbraqUVGywm-SGcqmP5Afrw
    function initialize(address,info,tipo) {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(45.80230, -100.2312 ), 15);
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        geocoder = new GClientGeocoder();
      }
    showAddress(address,info,tipo);
    }

    function showAddress(address,info,tipo) {
    	var icon = new GIcon();
    	if(tipo=="alojamento"){icon.image = host+'imagens/icons/alojamento_black.png';}
    	if(tipo=="animacao"){icon.image = host+'imagens/icons/animacao_black.png';}
    	if(tipo=="atraccao"){icon.image = host+'imagens/icons/atraccao_black.png';}    	
		icon.iconSize = new GSize(30,30);
		icon.shadowSize = new GSize(30, 30);
		icon.iconAnchor = new GPoint(11, 15);
		icon.infoWindowAnchor = new GPoint(11, 15);
		icon.shadow = "";
		
	   
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert(address + " not found");
            } else {
              map.setCenter(point, 15);
              var marker = new GMarker(point,icon);
              map.addOverlay(marker);
              marker.openInfoWindowHtml(info,{ maxWidth: 250 ,maxHeight: 150});
            }
          }
        );
      }
    }
    
/***********************  MAPS	********************/

	function initializeMultiple() 
		{
		if (GBrowserIsCompatible()) 
			{
        	var map = new GMap2(document.getElementById("map_canvas"));
       		map.addControl(new GSmallMapControl());
	  		map.addControl(new GMapTypeControl());
       		map.setCenter(new GLatLng(38.18000, -8.22000), 8);       		
       		    					
			function createMarker(latlng, tipo, info) {
				var icon = new GIcon();				
				icon.image = host+'imagens/icons/'+tipo+"_black.png";	
				icon.iconSize = new GSize(25,25);
				icon.shadowSize = new GSize(25, 25);
				icon.iconAnchor = new GPoint(11, 8);
				icon.infoWindowAnchor = new GPoint(11, 8);
				icon.shadow = "";
						  			
			  	var marker = new GMarker(latlng,icon);
			  	GEvent.addListener(marker, "click", function() {
			    	marker.openInfoWindowHtml(info,{ maxWidth: 150 ,maxHeight: 50});
			  	});
			 	return marker;
				}
       		
	        GDownloadUrl(host+"includes/data.php", function(data) 
	        	{
	          	var xml = GXml.parse(data);
	          	var markers = xml.documentElement.getElementsByTagName("marker");
	          	for (var i = 0; i < markers.length; i++) 
	          		{	
	          		//alert(markers[i].getAttribute("lat")+"-"+markers[i].getAttribute("lng")+"-"+markers[i].getAttribute("info")+"-"+markers[i].getAttribute("tipo"));					                
	              	var tipo = markers[i].getAttribute("tipo");
	              	var info = markers[i].getAttribute("info");
	                
	                var latlng = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
	               				parseFloat(markers[i].getAttribute("lng")));
			  		map.addOverlay(createMarker(latlng, tipo, info));
	          		}
        		});
      		}
    	}

function getElementByClass(theClass) {
	
	var allHTMLTags = new Array();
	allHTMLTags=document.getElementsByTagName("*");
	for (i=0; i<allHTMLTags.length; i++) {
		if (allHTMLTags[i].className==theClass) {
			//allHTMLTags[i].style.
			
			//allHTMLTags[i].style.display='none';
		}
	}
}

function checkByType(tipoAlvo, tiro) {
	var allHTMLTags = new Array();
	allHTMLTags=document.getElementsByTagName("*");
	for (i=0; i<allHTMLTags.length; i++) {
		if (allHTMLTags[i].type==tipoAlvo) {
			if (allHTMLTags[i].style.display!='none'){
				
				allHTMLTags[i].checked = tiro;
			}
		}
	}
}

function changeTab(tab)
		{
		if(tab=='tabContactos')
			{
			document.getElementById('tabContactos').style.backgroundColor="#4A7497";
			document.getElementById('tabContactos').style.border="1px solid #cccccc";
			document.getElementById('tabContactos').style.color="#ffffff";
			document.getElementById('tabUtilizadores').style.backgroundColor="#ffffff";
			document.getElementById('tabUtilizadores').style.border="1px solid #cccccc";
			document.getElementById('tabUtilizadores').style.color="#000000";
			document.getElementById('tabAreas').style.backgroundColor="#ffffff";
			document.getElementById('tabAreas').style.border="1px solid #cccccc";
			document.getElementById('tabAreas').style.color="#000000";
			document.getElementById('tabDocumentos').style.backgroundColor="#ffffff";
			document.getElementById('tabDocumentos').style.border="1px solid #cccccc";
			document.getElementById('tabDocumentos').style.color="#000000";
			}
		if(tab=='tabUtilizadores')
			{
			document.getElementById('tabUtilizadores').style.backgroundColor="#4A7497";
			document.getElementById('tabUtilizadores').style.border="1px solid #cccccc";
			document.getElementById('tabUtilizadores').style.color="#ffffff";
			document.getElementById('tabContactos').style.backgroundColor="#ffffff";
			document.getElementById('tabContactos').style.border="1px solid #cccccc";
			document.getElementById('tabContactos').style.color="#000000";
			document.getElementById('tabAreas').style.backgroundColor="#ffffff";
			document.getElementById('tabAreas').style.border="1px solid #cccccc";
			document.getElementById('tabAreas').style.color="#000000";
			document.getElementById('tabDocumentos').style.backgroundColor="#ffffff";
			document.getElementById('tabDocumentos').style.border="1px solid #cccccc";
			document.getElementById('tabDocumentos').style.color="#000000";
			}
		if(tab=='tabAreas')
			{
			document.getElementById('tabAreas').style.backgroundColor="#4A7497";
			document.getElementById('tabAreas').style.border="1px solid #cccccc";
			document.getElementById('tabAreas').style.color="#ffffff";
			document.getElementById('tabUtilizadores').style.backgroundColor="#ffffff";
			document.getElementById('tabUtilizadores').style.border="1px solid #cccccc";
			document.getElementById('tabUtilizadores').style.color="#000000";
			document.getElementById('tabContactos').style.backgroundColor="#ffffff";
			document.getElementById('tabContactos').style.border="1px solid #cccccc";
			document.getElementById('tabContactos').style.color="#000000";
			document.getElementById('tabDocumentos').style.backgroundColor="#ffffff";
			document.getElementById('tabDocumentos').style.border="1px solid #cccccc";
			document.getElementById('tabDocumentos').style.color="#000000";
			}
		if(tab=='tabDocumentos')
			{
			document.getElementById('tabDocumentos').style.backgroundColor="#4A7497";
			document.getElementById('tabDocumentos').style.border="1px solid #cccccc";
			document.getElementById('tabDocumentos').style.color="#ffffff";
			document.getElementById('tabContactos').style.backgroundColor="#ffffff";
			document.getElementById('tabContactos').style.border="1px solid #cccccc";
			document.getElementById('tabContactos').style.color="#000000";
			document.getElementById('tabUtilizadores').style.backgroundColor="#ffffff";
			document.getElementById('tabUtilizadores').style.border="1px solid #cccccc";
			document.getElementById('tabUtilizadores').style.color="#000000";
			document.getElementById('tabAreas').style.backgroundColor="#ffffff";
			document.getElementById('tabAreas').style.border="1px solid #cccccc";
			document.getElementById('tabAreas').style.color="#000000";
			}
		}   	
 /***********************  MAPS	END********************/ 
