var visibleTab = "";

function temasToogle(elmId) {
	var obj;
	ox = origempin.x - mapLeft + (origempin.w / 2);
	oy = origempin.y - mapTop + (origempin.h / 2);	
	dx = destinopin.x - mapLeft + (destinopin.w / 2);
	dy = destinopin.y - mapTop + (destinopin.h / 2);	
	locx = locOrgImgPin.x - mapLeft + (locOrgImgPin.w / 2);
	locy = locOrgImgPin.y - mapTop + (locOrgImgPin.h / 2);	
	
	
	obj = document.getElementById(elmId);
	if (obj.style.display == "none") {
		obj.style.display = "";
		if(widthInMap(ox,oy,false)) {
			origempin.hide();
		}
		
		if(widthInMap(dx,dy,false)) {
			destinopin.hide();
		}
		
		if(widthInMap(locx,locy,false)) {
			locOrgImgPin.hide();
		}
	} else {
		obj.style.display = "none";
		
		if(widthInMap(ox,oy,false)) {
			origempin.show();
		}
		
		if(widthInMap(dx,dy,false)) {
			destinopin.show();
		}
		
		if(widthInMap(locx,locy,false)) {
			locOrgImgPin.show();
		}		
	}	
}

function tooglePins() {
	mapa = document.getElementById("contentuc_mapa"); 
	
	mapLeft = parseInt(mapa.parentNode.parentNode.offsetLeft);  //funciona porque o parent e uma td com style="position:relative"
	mapTop = parseInt(mapa.parentNode.parentNode.offsetTop); //funciona porque o parent e uma td com style="position:relative"

	ox = origempin.x - mapLeft + (origempin.w / 2);
	oy = origempin.y - mapTop + (origempin.h / 2);	
	dx = destinopin.x - mapLeft + (destinopin.w / 2);
	dy = destinopin.y - mapTop + (destinopin.h / 2);	
	locx = locOrgImgPin.x - mapLeft + (locOrgImgPin.w / 2);
	locy = locOrgImgPin.y - mapTop + (locOrgImgPin.h / 2);	
	
	if(origempin.visible) {
		if(widthInMap(ox,oy,false)) {
			origempin.hide();
		}
	} else {
		if(widthInMap(ox,oy,false)) {
			origempin.show();
		}		
	}
	
	if(destinopin.visible) {
		if(widthInMap(dx,dy,false)) {
			destinopin.hide();
		}
	} else {
		if(widthInMap(dx,dy,false)) {
			destinopin.show();
		}
	}
	
	if(locOrgImgPin.visible) {
		if(widthInMap(locx,locy,false)) {
			locOrgImgPin.hide();
		}
	} else {
		if(widthInMap(locx,locy,false)) {
			locOrgImgPin.show();
		}
	}
}

function toogleElm(elmId) {
	var obj;
	
	obj = document.getElementById(elmId);

	if (obj.style.display == "none") {
		obj.style.display = "block";
	} else {
		obj.style.display = "none";
	}

}

var activeInfoEl=1;
function toogleElms(elmId) {
	var obj;
	var parentObj;
	var index;
	
	parentObj = document.getElementById(elmId).parentNode;

	for (index = 0; index < parentObj.childNodes.length; index++) {
		parentObj.childNodes(index).style.display = "none";
	}
		
	obj = document.getElementById(elmId);
	obj.style.display = "";
}

function toogleInfoElms(elmId) {
	var obj;
	var parentObj;
	var index;
	
	//alert(document.getElementById(elmId));
	parentObj = document.getElementById(elmId).parentNode;

	for (index = 0; index < parentObj.childNodes.length; index++) {
		parentObj.childNodes(index).style.display = "none";
	}
		
	obj = document.getElementById(elmId);
	obj.style.display = "";
	
	if (elmId == "paragens") {
		document.getElementById("operadorImg").src = "images/logo_STCP_LL.gif";
	} else if(elmId == "estacoes_metro") {
		document.getElementById("operadorImg").src = "images/logo_METRO_LL.gif";
	} else if(elmId == "estacoes_cp") {
		document.getElementById("operadorImg").src = "images/logo_CP_LL.gif";
	} else {
		document.getElementById("operadorImg").src = "images/px_branco.gif";
	}
	
}

function setPointsOrigem(selectObj,tab) {
	var origem = null;
	var destino = null;
	
	origem = document.getElementById("contentuc_pesquisafiltrouc_results_from_content");
	destino =  document.getElementById("contentuc_pesquisafiltrouc_results_to_content");	
	document.getElementById("menuuc_pesqfrmuc_pontoorigem").value = selectObj.options[selectObj.selectedIndex].value;
	
	if (tab == 2) {
		if (origem.options[origem.selectedIndex].value != "" ) {
			document.getElementById("contentuc_pesquisafiltrouc_pesquisarll").style.display="block";
		} else {
			document.getElementById("contentuc_pesquisafiltrouc_pesquisarll").style.display="none";
		}
		return;
	}
	
	if (destino != null) { 
				
		if (origem.selectedIndex != -1 && destino.selectedIndex != -1) {
			if (origem.options[origem.selectedIndex].value != "" && destino.options[destino.selectedIndex].value != "") {
				document.getElementById("contentuc_pesquisafiltrouc_pesquisar").style.display="block";
			} else {
				document.getElementById("contentuc_pesquisafiltrouc_pesquisar").style.display="none";
			}
		} else {
			document.getElementById("contentuc_pesquisafiltrouc_pesquisar").style.display="none";
		}	

	}
	
	if (origem.selectedIndex != -1) {
		if (origem.options[origem.selectedIndex].value != "") {
			document.getElementById("escolher_como_origem_lnk").style.display="block";
		} else {
			document.getElementById("escolher_como_origem_lnk").style.display="none";
		}	
	}
}

function setPointsDestino(selectObj) {
	var origem;
	var destino;
	
	origem = document.getElementById("contentuc_pesquisafiltrouc_results_from_content");
	destino =  document.getElementById("contentuc_pesquisafiltrouc_results_to_content");
	document.getElementById("menuuc_pesqfrmuc_pontodestino").value = selectObj.options[selectObj.selectedIndex].value;
	
	if (origem != null) { 	
		if (origem.selectedIndex != -1 && destino.selectedIndex != -1) {
			if (origem.options[origem.selectedIndex].value != "" && destino.options[destino.selectedIndex].value != "") {
				document.getElementById("contentuc_pesquisafiltrouc_pesquisar").style.display="block";
			} else {
				document.getElementById("contentuc_pesquisafiltrouc_pesquisar").style.display="none";
			}
		} else {
			document.getElementById("contentuc_pesquisafiltrouc_pesquisar").style.display="none";
		}
	}
	
	if (destino.selectedIndex != -1) {
		if (destino.options[destino.selectedIndex].value != "") {
			document.getElementById("escolher_como_destino_lnk").style.display="block";
		} else {
			document.getElementById("escolher_como_destino_lnk").style.display="none";
		}	
	}	
}

var closeWin = false;
function showlayer(layerid) {
	document.getElementById(layerid).style.display = "";
}

function hidelayer(layerid) {
	if (document.getElementById(layerid) != null)
		document.getElementById(layerid).style.display = "none";
		
	if (closeWin) window.close();
}

function imprime(oque) {
	if(oque == "rotasandmapa") {
		window.open("imprimir.aspx?content=print_rtmapa","Imprimir","height=0,width=0")	
	} else if(oque == "mapa_linhas") {
		window.open("imprimir.aspx?content=print_linh_mapa","Imprimir","height=0,width=0")	
	} else if(oque == "mapa_paragens") {
		window.open("imprimir.aspx?content=print_para_mapa","Imprimir","height=0,width=0")	
	} else {
		alert("Opção desconhecida.\nUnknownk option.")
	}
}

function envia(oque) {
	if(oque == "rotasandmapa") {
		window.open("enviar.aspx?content=envia_rtandmapa","Enviar","height=350,width=500")	
	} else if(oque == "mapalinhas") {
		window.open("enviar.aspx?content=envia_mapalinhas","Enviar","height=350,width=500")	
	} else if(oque == "paragensmapa") {
		window.open("enviar.aspx?content=envia_paragensmapa","Enviar","height=350,width=500")	
	} else if(oque == "tarifario") {
		window.open("../enviar.aspx?content=envia_tarifario","Enviar","height=350,width=500")	
	} else if(oque == "horario") {
		window.open("../enviar.aspx?content=envia_horario","Enviar","height=350,width=500")	
	} else if(oque == "wizard") {
		window.open("enviar.aspx?content=envia_wizard","Enviar","height=350,width=500")	
	} else {
		alert("Opção desconhecida.\nUnknown option.")
	}
}

var url = "";
var activeParagem = "";
function setParagemNoMapa(img,paragemid) {
	var x;
	var y;
	var point = new Array();

	x = paragens[paragemid].split("#")[0];
	y = paragens[paragemid].split("#")[1];


	//tsa, 3-2-2005: transformar o ponto da paragem escolhida para a localizacao correcta no extent do mapa actual
	point = converteToImageCoord(x,y);
	x = point[0];
	y = point[1];
	
	document.getElementById("paragemNoMapa").style.top = (y - 7) + "px";
	document.getElementById("paragemNoMapa").style.left = (x - 5) + "px";
	document.getElementById("paragemNoMapa").style.display = "";
	
	if (activeParagem != "") {
		if (url == "") {
			document.getElementById(activeParagem).src = "images/paragem_autocarro_branco.gif"
		} else {
			document.getElementById(activeParagem).src = url + "/images/paragem_autocarro_branco.gif"
		}		
		activeParagem = img.id;
	} else {
		activeParagem = img.id;
	}
	
	if (url == "") {
		img.src = "images/paragem_autocarro1.gif"	
	} else {
		img.src = url + "/images/paragem_autocarro1.gif"	
	}		
	
}

var activeLinha = "";
function setParagemNoMapaResult(linha, codigolinha,tipo,direcao,modo) {
	var img;
	
	/*img = document.getElementById("img" + codigolinha);
	setParagemNoMapa(img,codigolinha);
	toogleElm(codigolinha);*/
	
	if (activeLinha != "") {
		document.getElementById(activeLinha).className = "texto";
		activeLinha = "tr" + modo + linha + tipo + direcao;
	} else {
		activeLinha = "tr" + modo + linha + tipo + direcao;
	}
	
	document.getElementById(activeLinha).className = "selectedLine";
}

function callParentWindowDrawLine(linha,tipo,direcao,modo) {
	var parentWnd;
	parentWnd = window.top;
	if (parentWnd != null) {
		parentWnd.drawLine(linha,tipo,direcao,modo);
	}
	
}

function drawLine(linha,tipo,direcao,modo) {

	if (url == "") {
		//o-d
		if(document.location.href.indexOf("tab=1") != -1 || document.location.href.indexOf("tab") == -1) {
			document.location.href = "default.aspx?tab=3&line=" + linha + "&mode=" + modo + "&tipo=" + tipo + "&direcao=" + direcao;
		} else if(document.location.href.indexOf("tab=3") != -1) { //minha linha
			document.location.href = "default.aspx?tab=3&line=" + linha + "&mode=" + modo + "&tipo=" + tipo + "&direcao=" + direcao;
		} else {
			document.getElementById("contentuc_line").value = linha;
			document.getElementById("contentuc_modo").value = modo;
			document.getElementById("contentuc_tipolinha").value = tipo;
			document.getElementById("contentuc_direcaolinha").value = direcao;
			
			document.getElementById("contentuc_toolAction").value = "drawline";		
			document.forms[0].submit();			
		}
		showEsperaLayer();
	}
}

function showEsperaLayer() {
	var centerx;
	var centery;
	
	centerx = (document.getElementById("contentuc_mapa").width /2) + document.getElementById("contentuc_mapa").parentNode.parentNode.offsetLeft;
	centery = (document.getElementById("contentuc_mapa").height /2) + document.getElementById("contentuc_mapa").parentNode.parentNode.offsetTop;
	
	centerx = centerx - 100;
	centery = centery - 20;
	
	hidelayer("mensagens"); //escondo a janela das mensagens
	hidelayer('barraTemasDiv'); //escondo a janela de temas
	hidelayer('contentuc_pesquisafiltrouc_pesquisa'); //escondo a janela de filtragem de resultaos de pesquisas de texto
	toggleDisplay("wait","HelpShim","frm","center",centerx,centery);

	return true;
}

function mapaOp(op) {
	
	if (op == 1) { 
		//centrar mapa na origem
		document.getElementById("contentuc_toolAction").value = "centraorigem";		
		document.forms[0].submit();	
		showEsperaLayer();
	} else if (op == 2) {
		//centrar mapa no destino
		document.getElementById("contentuc_toolAction").value = "centradestino";		
		document.forms[0].submit();	
		showEsperaLayer();
	} else if (op == 3) { 
		//ver rota inteira
		document.getElementById("contentuc_toolAction").value = "zoomrota";		
		document.forms[0].submit();	
		showEsperaLayer();
	} else {
		//lixo
	}
}

function toogleLines(baseurl,img,elId) {
	var indice;
	var display;
	
	if (img.src.indexOf("mais") != -1) {
		img.src = baseurl + "/images/menos.gif";
		display = "";
	} else {
		img.src = baseurl +  "/images/mais.gif";
		display = "none";
	}	
	
	for (indice = 1; indice < 1000; indice++) {
		if(document.getElementById(elId + indice) != null) {
			document.getElementById(elId + indice).style.display = display;
		} else {
			if (indice == 1) {
				continue;
			}
			break;
		}
	}		
	
}

function setODLbl(selectObj,mode) {
	
	if (mode == "BUS") {
		if (selectObj.selectedIndex != 0) {
			document.getElementById("menuuc_linhasMLUc_odlbl").innerText = linhasMLBUS[selectObj.options[selectObj.selectedIndex].value];
			document.getElementById("menuuc_linhasMLUc_de_para").value = linhasMLBUS[selectObj.options[selectObj.selectedIndex].value];
		} else {
			document.getElementById("menuuc_linhasMLUc_odlbl").innerText = "";
			document.getElementById("menuuc_linhasMLUc_de_para").value = "";
		}
		
		if (document.getElementById("menuuc_linhasMLUc_odlblnovarede")) 
			document.getElementById("menuuc_linhasMLUc_odlblnovarede").innerText = "";
	} else if (mode == "METRO") {
		if (selectObj.selectedIndex != 0) {
			document.getElementById("menuuc_linhasMLUc_odlbl").innerText = linhasMLMETRO[selectObj.options[selectObj.selectedIndex].value];
			document.getElementById("menuuc_linhasMLUc_de_para").value = linhasMLMETRO[selectObj.options[selectObj.selectedIndex].value];
		} else {
			document.getElementById("menuuc_linhasMLUc_odlbl").innerText = "";
			document.getElementById("menuuc_linhasMLUc_de_para").value = "";
		}
		
		if(document.getElementById("menuuc_linhasMLUc_odlblnovarede"))
			document.getElementById("menuuc_linhasMLUc_odlblnovarede").innerText = "";
	} else if (mode == "CP") {
		document.getElementById("menuuc_linhasMLUc_odlbl").innerText = "";
		document.getElementById("menuuc_linhasMLUc_odlblnovarede").innerText = "";
		document.getElementById("menuuc_linhasMLUc_de_para").value = "";
	} else if (mode == "BUSNOVAREDE") {
		document.getElementById("menuuc_linhasMLUc_odlbl").innerText = "";
		if (selectObj.selectedIndex != 0) {
			document.getElementById("menuuc_linhasMLUc_odlblnovarede").innerText = linhasMLBUSNOVAREDE[selectObj.options[selectObj.selectedIndex].value];
			document.getElementById("menuuc_linhasMLUc_de_para").value = linhasMLBUSNOVAREDE[selectObj.options[selectObj.selectedIndex].value];
		} else {
			document.getElementById("menuuc_linhasMLUc_odlbl").innerText = "";
			document.getElementById("menuuc_linhasMLUc_de_para").value = "";
		}
	}
	
	//05-05-2006: hide the buttons
	if (document.getElementById("horarios"))
		document.getElementById("horarios").style.display = "none";
	if (document.getElementById("tarifas"))
		document.getElementById("tarifas").style.display = "none";
}

function abre(endereco,w_width,w_height, scroll)
{
	if (url!="") {
		if (endereco.indexOf("tarifas.aspx") != -1) {
			endereco = url + endereco;
		}
	}	
	window.open(endereco,'endereco',"top=0,left=0,toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=1,copyhistory=0,scrollbars="+scroll+",z-lock=0,"+"width="+w_width+",height="+w_height);
}

function abre_compara(endereco,w_width,w_height, resizable, scroll)
{
	window.open(endereco,'1',"top=0,left=0,toolbar=0,location=0,directories=0,status=0,menubar=0,resizable="+resizable+",copyhistory=0,scrollbars="+scroll+",z-lock=0,"+"width="+w_width+",height="+w_height);
}


function abre_basico(endereco) {
	window.open(endereco);
}

function toggleDisplay(div,iframe,objpos,pos,x,y)
{
	var t=0;
	var l=0;
	var state=false;

	var cNode = document.getElementById(objpos);
	while(cNode.tagName!='BODY'){ 
       		l+=cNode.offsetLeft; 
       		t+=cNode.offsetTop; 
       		cNode=cNode.offsetParent; 
    	}

	var DivRef = document.getElementById(div);
	var IfrRef = document.getElementById(iframe);
   	var ObjPos = document.getElementById(objpos);

	if (DivRef.style.display=="none") {
		state=true;
	} else {
		state=false;
	}

   	if(state)
   	{
    		DivRef.style.display = "block";
    		IfrRef.style.width = DivRef.offsetWidth;
    		IfrRef.style.height = DivRef.offsetHeight;
	
	switch (pos) {
		case "left": 
    			DivRef.style.top = t;
    			DivRef.style.left = (l-ObjPos.offsetWidth);
    			IfrRef.style.top = t;
    			IfrRef.style.left = (l-ObjPos.offsetWidth);
	  		break;
		case "right": 
			DivRef.style.top = t;
			DivRef.style.left = (l+ObjPos.offsetWidth);
    			IfrRef.style.top = t;
    			IfrRef.style.left = (l+ObjPos.offsetWidth);
	  		break;
		case "bottom": 
			DivRef.style.top = (t+ObjPos.offsetHeight);
    			DivRef.style.left = l;
    			IfrRef.style.top = (t+ObjPos.offsetHeight);
    			IfrRef.style.left = l;
	  		break;
		case "top": 
    			DivRef.style.top = (t-ObjPos.offsetHeight);
    			DivRef.style.left = l;
    			IfrRef.style.top = (t-ObjPos.offsetHeight);
    			IfrRef.style.left = l;
	  		break;
	  	case "center": 
    			DivRef.style.top = y;
    			DivRef.style.left = x;
    			IfrRef.style.top = y;
    			IfrRef.style.left = x;
	  		break;
        	}


    	IfrRef.style.zIndex = DivRef.style.zIndex - 1;
    	IfrRef.style.display = "block";
    	IfrRef.style.backgroundColor = "black";
   	}
   	else
   	{
    		DivRef.style.display = "none";
    		IfrRef.style.display = "none";
   	}

}

function prevInfo(el) {
	if (activeInfoEl==1) return;
	activeInfoEl--;
	if (document.getElementById(el+activeInfoEl) != null) {
		
		toogleElms(el+activeInfoEl);
	} else {
		activeInfoEl++;
	}
	setInfoWndBounds();
}

function nextInfo(el) {
	activeInfoEl++;
	if (document.getElementById(el+activeInfoEl) != null) {
		toogleElms(el+activeInfoEl);
	} else {
		activeInfoEl--;
	}
	setInfoWndBounds();
}

function pesqFormTextChange(textvalue) {
	//alert(textvalue);
	if (textvalue == "") {
		document.getElementById("contentuc_toolAction").value = ""
	} else {
		document.getElementById("contentuc_toolAction").value = "pesqtexto"
	}
}

function abreInquerito(szUrl)
{
	window.open(szUrl,'Inquerito','top=100,width=729,height=600,location=0,resizable=0,toolbar=0,menubar=0,scrollbars=1');
}

function toogleCheck(cb,parentTable) {
	var cb_items;
	var index,index_interno;
	
	cb_items = document.getElementById(parentTable).all.tags("INPUT");
	if (cb.value == 64) { //todos
		if (cb.checked) {
			for(index = 0; index < cb_items.length; index++) {
				if (cb_items[index].value != 64) cb_items[index].checked = false;
			}
		}
	} else {
		if (cb.checked) {
			for(index = 0; index < cb_items.length; index++) {
				if (cb_items[index].value == 64) cb_items[index].checked = false;
			}
		}
	}
}

var visibleOp = "menuuc_linhasMLUc_linhasddl";
function toogleOperador(operadorItem) {
	var obj;
	obj = document.getElementById(operadorItem);
	
	document.getElementById(visibleOp).style.display="none";
	obj.style.display="";
	visibleOp = operadorItem	
	
	if (operadorItem == "menuuc_linhasMLUc_linhasddlnovarede") {
		setODLbl(obj,"BUSNOVAREDE");
		document.getElementById("menuuc_linhasMLUc_odlbl").style.display = "none";
		document.getElementById("menuuc_linhasMLUc_odlblnovarede").style.display = "";
	} else if(operadorItem == "menuuc_linhasMLUc_linhasddl") {
		setODLbl(obj,"BUS");
		document.getElementById("menuuc_linhasMLUc_odlbl").style.display = "";
		document.getElementById("menuuc_linhasMLUc_odlblnovarede").style.display = "none";
	} else if(operadorItem == "menuuc_linhasMLUc_linhasddlmetro") {
		setODLbl(obj,"METRO");
		document.getElementById("menuuc_linhasMLUc_odlbl").style.display = "";
		document.getElementById("menuuc_linhasMLUc_odlblnovarede").style.display = "none";
	} else if(operadorItem == "menuuc_linhasMLUc_linhascp") {
		setODLbl(obj,"CP");
		document.getElementById("menuuc_linhasMLUc_odlbl").style.display = "";
		document.getElementById("menuuc_linhasMLUc_odlblnovarede").style.display = "none";
	} else {
		document.getElementById("menuuc_linhasMLUc_odlbl").style.display = "";
		document.getElementById("menuuc_linhasMLUc_odlblnovarede").style.display = "none";
	}
		
}

// Funções adicionadas por LAG
function abreHorario(szUrl)
{
	oWin=window.open(szUrl,'Horario','top=10,width=560,height=300,location=0,resizable=1,toolbar=0,menubar=0,scrollbars=0');
	oWin.focus();
}
/* Versão Temporária para testes no Piloto1
function abreHorario(szUrl)
{
    var vLinha='';
    var vOp='STCP';
    var vLang='pt';
    aUrl = szUrl.split("?");
    if (aUrl.length>1)
    {
        params=aUrl[1].split("&");
        for (i=0;i<params.length;i++)
        {
            param=params[i].split("=");
            if (param.length>1)
            {
//                alert(''+param[0]+'['+param[1]+']');
                if (param[1] && param[1]!='')
                {
                    if (param[0]=='linha')
                    {
                        vLinha=param[1];
                    }
                    else if (param[0]=='lang')
                    {
                        vLang=param[1];
                    }
                    else if (param[0]=='op')
                    {
                        vOp=param[1];
                    }
                }
            }
        }
    }
    if (vOp=='STCP')
    {
        if (vLinha!='')
        {
            window.open('http://stcp.piloto.imedita.pt/' + vLang + '/horarios/horario_'+vLinha+'_I_U.htm', 'Horario','toolbar=no,width=460,height=460,left=80,top=100, status=no,scrollbars=no,resizable=yes');
        }
    }
    else
    {    
        	window.open(szUrl,'Horario','top=10,width=560,height=300,location=0,resizable=1,toolbar=0,menubar=0,scrollbars=0');
    }
}
*/
function abreTarifario(szUrl)
{
	oWin=window.open(szUrl,'Tarifario','top=10,width=560,height=300,location=0,resizable=1,toolbar=0,menubar=0,scrollbars=0');
	oWin.focus();
}
function trocaFundo(aObj,aColor)
{
	aObj.bgColor=aColor;
}
function abreMapaWizard(szUrl)
{
	var owin;
	vWidth=609;
	vHeight=522;
	vLeft=(window.screen.width/2)-(vWidth/2);
	vTop=(window.screen.height/2)-(vHeight/2);

	
	//tsa, 16-08-2005: se ja tiver sido escolhido o pt entao quero-o desenhado no mapa.
	if (szUrl.indexOf("OD=X") != -1) {
		if (document.getElementById("ContentObj_ODX").value != "" && document.getElementById("ContentObj_ODY").value != "") {
			szUrl = szUrl + "&amp;coordx=" + document.getElementById("ContentObj_ODX").value + "&amp;coordy=" + document.getElementById("ContentObj_ODY").value
		}
	} else if (szUrl.indexOf("OD=Y") != -1) {
		if (document.getElementById("ContentObj_DDX").value != "" && document.getElementById("ContentObj_DDY").value != "") {
			szUrl = szUrl + "&amp;coordx=" + document.getElementById("ContentObj_DDX").value + "&amp;coordy=" + document.getElementById("ContentObj_DDY").value			
		}
	}
	owin = window.open(szUrl,'MapaWizard','left='+vLeft+',top='+vTop+',width='+vWidth+',height='+vHeight+',location=0,resizable=1,toolbar=0,menubar=0,scrollbars=0');	

	owin.focus();

}
var bAcessoFacil=false;
function clickAcessoFacil(aObj)
{
	bAcessoFacil=!bAcessoFacil;
	aObj.checked = bAcessoFacil;
}

var bRedeAndante=false;
function clickRedeAndante(aObj)
{
	bRedeAndante=!bRedeAndante;
	aObj.checked = bRedeAndante;
}


function showWizardHelp(aObj,aLayerName,aX,aY)
{
	aLayer=document.getElementById(aLayerName);
	if (aX>0)
		aLayer.style.left=aX+'px';
	if (aY>0)
		aLayer.style.top=aY+'px';
}
function initWizard()
{
	obj=document.getElementById("ContentObj_DoAction");
	if (obj)
	{
		if (obj.value!='RESULTADO')
		{
			obj=document.getElementById("ContentObj_TextBoxP");
			if (obj)
			{
				obj.focus();
			}
			else
			{
				obj=document.getElementById("ContentObj_PartidaDropDownList");
				if (obj)
				{
					obj.focus();
				}		
			}
		}
	}
}
function procurarWizard()
{
	oDoAction=document.getElementById("ContentObj_DoAction");
	if (oDoAction) 
	{
		oODX=document.getElementById("ContentObj_ODX");
		oDDX=document.getElementById("ContentObj_DDX");
		oTextBoxP=document.getElementById("ContentObj_TextBoxP");
		oTextBoxC=document.getElementById("ContentObj_TextBoxC");
		if (oDoAction.value=='')
		{
			oDoAction.value='PESQUISAR';
		}
		if (oDoAction.value=='PESQUISAR')
		{
			if ((oODX) && (oDDX))
			{
				if ((oODX.value!='') && (oDDX.value!=''))
				{
					//tsa, 20-01-2006: estes dois ifs permitem ao utilizador escolher uma pesquisa por texto apos terem
					//efectuado a escolha de ptos no mapa
					if ((document.getElementById("ContentObj_TableWizPartida").style.display == "block" || document.getElementById("ContentObj_TableWizPartida").style.display == "") && oTextBoxP.value != "") {
						;
					} else if( (document.getElementById("ContentObj_TableWizChegada").style.display == "block" || document.getElementById("ContentObj_TableWizChegada").style.display == "") && oTextBoxC.value != "") {
						;
					} else {
						if (!isValidDate())
							return;
						oDoAction.value='RESULTADO';
						showlayer('wait');
						document.getElementById("frm").submit();
						return; //agora esta tudo na pag o pesquisar e o resultado por isso tenho de bazar
					}
					
				}
			}
			if (oTextBoxP)
			{
				if ((oTextBoxP.value=='') && (oODX.value==''))
				{
					alert(errPartida);
					return;
				}
			}
			if (oTextBoxC)
			{
				if ((oTextBoxC.value=='') && (oDDX.value==''))
				{
					alert(errChegada);
					return;
				}
			}
		}		
		if (oDoAction.value=='RESULTADO')
		{
			oPartida=document.getElementById("ContentObj_PartidaDropDownList");
			if (oPartida)
			{
				if ((oPartida.selectedIndex<1) && (oODX.value==''))
				{
					alert(errPartida);
					return;
				}
				if (document.getElementById("ContentObj_TextP"))
					document.getElementById("ContentObj_TextP").value = oPartida[oPartida.selectedIndex].text;				
			}
			oChegada=document.getElementById("ContentObj_ChegadaDropDownList");
			if (oChegada)
			{
				if ((oChegada.selectedIndex<1) && (oDDX.value==''))
				{
					alert(errChegada);
					return;
				}
				if (document.getElementById("ContentObj_TextC"))
					document.getElementById("ContentObj_TextC").value = oChegada[oChegada.selectedIndex].text;
			}
		}
		if (!isValidDate())
			return;
		showlayer('wait');		
		document.getElementById("frm").submit();		
	}
}
function setPontoEscolhidoMapa(aStr)
{
	sLayerName=aStr + 'Div';
	showlayer(sLayerName);
	
	if (aStr == "OD") {
		if (document.getElementById("ContentObj_TableWizPartida2").style.display ==  "block") {
			toogleElm('ContentObj_TableWizPartida');
			toogleElm('ContentObj_TableWizPartida2');
			document.getElementById("ContentObj_TextBoxP").value = "";
			document.getElementById("ContentObj_DoAction").value = "PESQUISAR";			
		} else {
			document.getElementById("ContentObj_TextBoxP").value = "";
			document.getElementById("ContentObj_errlblde").innerText = "";
			document.getElementById("ContentObj_DoAction").value = "PESQUISAR";			
		}
	} else if(aStr == "DD") {
		if (document.getElementById("ContentObj_TableWizChegada2").style.display ==  "block") {
			toogleElm('ContentObj_TableWizChegada');
			toogleElm('ContentObj_TableWizChegada2');
			document.getElementById("ContentObj_TextBoxC").value = "";
			document.getElementById("ContentObj_DoAction").value = "PESQUISAR";			
		} else {
			document.getElementById("ContentObj_TextBoxC").value = "";			
			document.getElementById("ContentObj_errlblpara").innerText = "";
			document.getElementById("ContentObj_DoAction").value = "PESQUISAR";			
		}		
	}
	
}

function setInfoWndBounds() {
	window.top.document.getElementById("info").style.width="100px";
	window.top.document.getElementById("info").style.height="100px";
	if (document.getElementById("infotable").offsetWidth < 300) {
		window.top.document.getElementById("info").style.width="300px";
	} else {
		window.top.document.getElementById("info").style.width=document.getElementById("infotable").offsetWidth + "px";
	}
	
	if (document.getElementById("infotable").offsetHeight < 200) {
		window.top.document.getElementById("info").style.height="200px";
	} else {
		window.top.document.getElementById("info").style.height=document.getElementById("infotable").offsetHeight + "px";
	}

	mapw = parseInt(window.top.document.getElementById("contentuc_mapa").parentNode.parentNode.offsetLeft) + parseInt(window.top.document.getElementById("contentuc_mapa").width);
	maph = parseInt(window.top.document.getElementById("contentuc_mapa").parentNode.parentNode.offsetTop) + parseInt(window.top.document.getElementById("contentuc_mapa").height);

	//a posicao na janela
	if (parseInt(window.top.document.getElementById("info").style.top.replace("px","")) + parseInt(window.top.document.getElementById("info").style.height.replace("px","")) > maph) {
		window.top.document.getElementById("info").style.top = (parseInt(window.top.document.getElementById("info").style.top.replace("px","")) - parseInt(window.top.document.getElementById("info").style.height.replace("px",""))) + "px";
	}
	
	if (parseInt(window.top.document.getElementById("info").style.left.replace("px","")) + parseInt(window.top.document.getElementById("info").style.width.replace("px","")) > mapw)
		window.top.document.getElementById("info").style.left = (parseInt(window.top.document.getElementById("info").style.left.replace("px","")) - parseInt(window.top.document.getElementById("info").style.width.replace("px",""))) + "px";

}

function isValidDate()
{
	oDate=new Date();
	oAno=document.getElementById("ContentObj_AnoTextBox");
	if (parseInt(oAno.value)<oDate.getYear())
	{
		alert(errData);
		return false;
	}
	oMes=document.getElementById("ContentObj_MesDropdownlist");
	if ((parseInt(oMes[oMes.selectedIndex].value)<oDate.getMonth()+1) && (parseInt(oAno.value)==oDate.getYear()))
	{
		alert(errData);
		return false;				
	}
	oDia=document.getElementById("ContentObj_DiaDropDownList");
	if ((parseInt(oDia[oDia.selectedIndex].value)<oDate.getDate()) && (parseInt(oMes[oMes.selectedIndex].value)==oDate.getMonth()+1) && (parseInt(oAno.value)==oDate.getYear()))
	{
		alert(errData);
		return false;				
	}
	if (parseInt(oMes[oMes.selectedIndex].value)==2) 
	{
		// Check for leap year
		if ( ( (parseInt(oAno.value)%4==0)&&(parseInt(oAno.value)%100 != 0) ) || (parseInt(oAno.value)%400==0) ) 
		{ // leap year
			if (parseInt(oDia[oDia.selectedIndex].value) > 29)
			{
				alert(errData);
				return false; 
			}
		}
		else 
		{ 
			if (parseInt(oDia[oDia.selectedIndex].value) > 28)
			{
				alert(errData);	
				return false; 
			}
		}
	}
	if ((parseInt(oMes[oMes.selectedIndex].value)==4)||(parseInt(oMes[oMes.selectedIndex].value)==6)||(parseInt(oMes[oMes.selectedIndex].value)==9)||(parseInt(oMes[oMes.selectedIndex].value)==11))
	{
		if (parseInt(oDia[oDia.selectedIndex].value) > 30)
		{
			alert(errData);
			return false;
		}
	}
	return true;
}
function checkSubmit()
{
	if (event.keyCode==13)
	{
		procurarWizard();
		return false;
	}
	else
		return true;
}
function checkOp(aObjId)
{
	var aObj;
	aObj = document.getElementById(aObjId);
	
	if (!aObj) {
		document.getElementById("ContentObj_CheckboxOp1").checked = true;
		document.getElementById("ContentObj_CheckboxOp2").checked = false;
		document.getElementById("ContentObj_CheckboxOp3").checked = false;
		document.getElementById("ContentObj_CheckboxOp4").checked = false;			
	}
	
	if (aObj.id=='ContentObj_CheckBoxOp1')
	{
		if (aObj.checked)
		{
			document.getElementById("ContentObj_CheckboxOp2").checked = false;
			document.getElementById("ContentObj_CheckboxOp3").checked = false;
			document.getElementById("ContentObj_CheckboxOp4").checked = false;			
		}
		else
		{
			document.getElementById("ContentObj_CheckboxOp1").checked = true;
		}
	}
	else
	{
		if (aObj.checked)
		{
			document.getElementById("ContentObj_CheckboxOp1").checked = false;		
		}
		else
		{
			if (!document.getElementById("ContentObj_CheckboxOp2").checked && !document.getElementById("ContentObj_CheckboxOp3").checked && !document.getElementById("ContentObj_CheckboxOp4").checked)
			{
				document.getElementById("ContentObj_CheckboxOp1").checked = true;
			}
		}
	}

}

function hideSpecial() {
	if (visibleTab != "") {
		if (visibleTab == "pesqformtbl")
			if (document.getElementById("pesqformtbl").style.display!="")
				toogleMarcadores(false);
		else if(visibleTab == "marcadorestbl")
			if (document.getElementById("marcadorestbl").style.display!="")
				toogleMarcadores(true);
	}	
}


var go = false;
function isgo(show) {
	go = true;
	toogleMarcadores(show);
}

function toogleMarcadores(show) {
	
	if(!go) {
		toogleElm('marcadorestbl');	
		toogleElm('marcadoresToogler');
		setTimeout("isgo(" + show + ")",1)
	} else {
		go = false;
		toogleElm('pesqfrmToogler');
		toogleElm('pesqformtbl');	
		
		if (show) {
			if ( (document.location.href.indexOf("tab") == -1) || (document.location.href.indexOf("tab=1") != -1)) {
				origempin.show();
				destinopin.show();
			} else if(document.location.href.indexOf("tab=2") != -1) {
				locOrgImgPin.show();
			}
		} else {
			if (document.getElementById("contentuc_CoordenadaOrigemX").value == -1) origempin.hide();
			if (document.getElementById("contentuc_CoordenadaDestinoX").value == -1) destinopin.hide();
			if (document.getElementById("contentuc_CoordenadaOrigemX").value == -1) locOrgImgPin.hide();	
		}
	}	
}

function trocaTipoRota(aObj)
{
	oTipoRota=document.getElementById("ResultWizObj_TipoRota");
	if (oTipoRota)
	{
		if (aObj.id=='ResultWizObj_TDMaisRapido')
		{
			oTipoRota.value='1';
			showlayer('wait');		
			document.getElementById("frm").submit();
		}
		if (aObj.id=='ResultWizObj_TDMenosTransbordos')
		{
			oTipoRota.value='2';
			showlayer('wait');		
			document.getElementById("frm").submit();
		}
		if (aObj.id=='ResultWizObj_TDMaisEconomico')
		{
			oTipoRota.value='4';		
			showlayer('wait');		
			document.getElementById("frm").submit();
		}
	}		
}

function toogleLinesWizard(baseurl,img,elId) {
	var indice;
	var display;
	
	if (img.src.indexOf("mais") != -1) {
		img.src = baseurl + "/images/wizard/b_menos.gif";
		display = "";
	} else {
		img.src = baseurl +  "/images/wizard/b_mais.gif";
		display = "none";
	}	
	
	for (indice = 1; indice < 1000; indice++) {
		if(document.getElementById(elId + indice) != null) {
			document.getElementById(elId + indice).style.display = display;
		} else {
			if (indice == 1) {
				continue;
			}
			break;
		}
	}		
	
}

function verNoMapa()
{
	if (document.getElementById("ResultWizObj_TipoRota").value + "" != "") {
		if (document.location.href.indexOf("comparedwizard") != -1)
			abreMapaWizard('default.aspx?wizardcompared=1&mapwiz=2&result=' + document.getElementById("ResultWizObj_TipoRota").value);
		else
			abreMapaWizard('default.aspx?mapwiz=2&result=' + document.getElementById("ResultWizObj_TipoRota").value);
	}	
}
function enviarEmail()
{
	envia('wizard');
}

function imprimirResultado()
{

	oWin=window.open('ImprimirRota.htm','ImprimirWizard','left=10,top=10,width=680,height=480,location=0,resizable=1,toolbar=0,menubar=0,scrollbars=1');
	oWin.focus();
}
function novaPesquisa()
{
	document.location = 'wizard.aspx';
}

function createPT(imgsrc,x,y,imgw,imgh) {
	document.write("<div style='position:absolute;left:" + eval(x - (imgw/2)) + "px;top:" + eval(y - (imgh/2)) + "px;'><img src='" + imgsrc + "'></div>"); 
}

function abreMapaWizardCompared() {
	var owin;
	var url;
	var isredeandante;
	var ano;
	var mes;
	var dia;
	var dateCompareResult;
	vWidth=809;
	vHeight=552;
	vLeft=(window.screen.width/2)-(vWidth/2);
	vTop=(window.screen.height/2)-(vHeight/2);

	//tsa,10-11-2006
	dia = document.getElementById("ContentObj_DiaDropDownList").options[document.getElementById("ContentObj_DiaDropDownList").selectedIndex].value;
	mes = document.getElementById("ContentObj_MesDropDownList").options[document.getElementById("ContentObj_MesDropDownList").selectedIndex].value;
	ano = document.getElementById("ContentObj_AnoTextBox").value;
	isredeandante = document.getElementById("ContentObj_andante").checked;
	if (!isredeandante) {
		dateCompareResult = compareDates(dia + "/" + mes + "/" + ano,"d/M/y","1/1/2007","d/M/y");
		if (dateCompareResult != -1) {
			if (dateCompareResult == 1) isredeandante = true;
		}
	}
	
	//tsa, 05-09-2005
	url = 'comparador.aspx?togo=comparedwizard.aspx&dia=' + document.getElementById("ContentObj_DiaDropDownList").options[document.getElementById("ContentObj_DiaDropDownList").selectedIndex].value + 
			'&mes=' + document.getElementById("ContentObj_MesDropDownList").options[document.getElementById("ContentObj_MesDropDownList").selectedIndex].value + 
			'&ano=' + document.getElementById("ContentObj_AnoTextBox").value + 
			'&hora=' + document.getElementById("ContentObj_HoraDropDownList").options[document.getElementById("ContentObj_HoraDropDownList").selectedIndex].value  + 
			'&min=' + document.getElementById("ContentObj_MinutoDropDownList").options[document.getElementById("ContentObj_MinutoDropDownList").selectedIndex].value   + 
			'&operadores=' + document.getElementById("ResultWizObj_operadores").value +  
			'&andarape=' + document.getElementById("ContentObj_AndarAPeDropDownList").options[document.getElementById("ContentObj_AndarAPeDropDownList").selectedIndex].value + 
			'&redeandante=' + !isredeandante;

	owin = window.open(url,'MapaWizardCompared','left='+vLeft+',top='+vTop+',width='+vWidth+',height='+vHeight+',location=0,resizable=1,toolbar=0,menubar=0,scrollbars=1');	
	owin.focus();	
}

