function SelOption(k,v){
	if(typeof(v)=='undefined') return;
	for (var s = 0; s < k.length; s++) {
		if(k.options[s].value==v){
			k.selectedIndex=s;
		}
	}
}


function resetF(f){ 
	f.reset();
	return false;
}


function checkME(ME, rv){
	if(ME.value==rv){
		ME.checked=true
		ME.focus();
	}else{
		for(k=0; k<ME.length; k++){
			if(ME[k].value==rv){
				ME[k].checked=true
				ME[k].focus();
			}
		}
	}
}

function clickBanner(url, target){
	if(target=="_self"){
		document.location.href=url
	}else{
		window.open(url)
	}
}


function abrejanela(url, altura, largura, scrolbar) {
	var winleft = (screen.width - largura) / 2;
	var wintop = (screen.height - altura) / 2;
	if(typeof(popup) == 'object'){
		if(popup.closed==false)
		{
			popup.location=url;
		}else{
		popup=window.open(url,'','resizable=yes,location=yes,menubar=yes,scrollbars=yes,status=yes,toolbar=yes,fullscreen=no,dependent=no,width='+altura+',height='+largura+',left='+winleft+',top='+wintop+'');
		}
	}else{
		popup=window.open(url,'','resizable=yes,location=yes,menubar=yes,scrollbars=yes,status=yes,toolbar=yes,fullscreen=no,dependent=no,width='+altura+',height='+largura+',left='+winleft+',top='+wintop+'');
	}
	
	//popup.closed=function(){alert('close');document.popup="undefined"}
	if (parseInt(navigator.appVersion) >= 4) { popup.window.focus(); }
}



function reloadWin(){
	if(popupR.closed){
		if(typeof (document.UrlToReload)!="undefined" && document.UrlToReload!=""){
			document.location=document.UrlToReload
		}
	}else{
		//alert("em espera")
	}
}
function addFav(){
	var ver = navigator.appName;
	var num = parseInt(navigator.appVersion);
	if ((ver == "Microsoft Internet Explorer")&&(num >= 4)) {
		window.external.AddFavorite(document.location.href,document.title)
	}else{
		alert("Clic \"Ctrl+D\" para adicionar "+document.title+" aos seus favoritos")
	}
}

function makDestrito(f, v){
	var aDestritoa = sDestritos.split("||");
	k=1;
	for (var i = 0; i < aDestritoa.length; i++) {
			var D = aDestritoa[i].split("|");
			v.options[k] = new Option(D[1], D[0]);
			k = k + 1;
	}
}
function PreencheConcelhos(f, v, ds) {
	var index = ds.selectedIndex;
	var distrito = ds.options[index].value;
	v.options.length = 1;
	var aConcelhos = sConcelhos.split("||");
	var n = 1;
	for (var i = 0; i < aConcelhos.length; i++) {
		var a = aConcelhos[i].split("|");
		if (a[0]== parseInt(distrito)) {
			v.options[n] = new Option(a[2], a[1]);
			n = n + 1;
		}
	}
}
function makSRT_PAISES(campo){
	var aSRT_PAISES = SRT_PAISES.split("||");
	k=1;
	
	for (var i = 0; i < aSRT_PAISES.length; i++) {
			var D = aSRT_PAISES[i].split("|");
			campo.options[k] = new Option(D[1], D[0]);
			k = k + 1;
	}
}
function SellSRT_PAISES(campo, sel){
	if(typeof(sel)=="undefined")return
	for (var s = 0; s < campo.length; s++) {
		if(campo.options[s].value==sel){
			campo.selectedIndex=s;
		}
	}
}
function SellDistriAuto(f, v, sel){
	if(typeof(sel)=="undefined")return
	for (var s = 0; s < v.length; s++) {
		if(v.options[s].value==sel){
			v.selectedIndex=s;
		}
	}
}
function SellConceAuto(f, v, sel){
	if(typeof(sel)=="undefined")return
	for (var i = 0; i < v.length; i++) {
		if (v.options[i].value== sel) {
			v.selectedIndex = i;
		}
	}
}
function Fill_ano(f) {
	calDate = new Date();
	ano = calDate.getFullYear();
	var n = 1;
	for (var i = ano-10; i >= ano-80; i--) {
		f.ano.options[n] = new Option(i, i);
		n = n + 1;
	}
}
function showImgPalco(src){
	el=document.getElementById("img_palco");
	el.src=src
}
var ns = (navigator.appName.indexOf("Netscape") != -1);
var d = document;
var px = document.layers ? "" : "px";
function JSFX_FloatDiv(id, sx, sy)
{
	var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
	window[id + "_obj"] = el;
	if(d.layers)el.style=el;
	el.cx = el.sx = sx;el.cy = el.sy = sy;
	el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;};
	el.flt=function()
	{
		var pX, pY;
		pX = (this.sx >= 0) ? 0 : ns ? innerWidth : 
		document.documentElement && document.documentElement.clientWidth ? 
		document.documentElement.clientWidth : document.body.clientWidth;
		pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? 
		document.documentElement.scrollTop : document.body.scrollTop;
		if(this.sy<0) 
		pY += ns ? innerHeight : document.documentElement && document.documentElement.clientHeight ? 
		document.documentElement.clientHeight : document.body.clientHeight;
		this.cx += (pX + this.sx - this.cx)/8;this.cy += (pY + this.sy - this.cy)/8;
		this.sP(this.cx, this.cy);
		setTimeout(this.id + "_obj.flt()", 40);
	}
	return el;
}
/*
JSFX_FloatDiv("divTopLeft",       10,   10).flt();
JSFX_FloatDiv("divTopRight", 	  -100,   10).flt();
JSFX_FloatDiv("divBottomLeft",    10, -100).flt();
JSFX_FloatDiv("divBottomRight", -100, -100).flt();
*/

function enviarAumAmigo(mail){

	if(!_is_mail(mail.value)){
		alert("verifique o seu E-mail")
		mail.focus();
		return false
	}
	xmlLoader = new dtmlXMLLoaderObject(null,null,false);
	url=escape(document.location);
 
	titulo=document.title;
	queryString="mail="+mail.value+"&url="+url+"&titulo="+titulo;
	xmlLoader.loadXML("inc/enviarAumAmigo.php?"+queryString);
	alert("Os seus dados foram submetidos com sucesso, obrigado!")
	return false;
}


function fixFla(){
	objects = document.getElementsByTagName("object");
	if(document.all){
		
		for (var i = 0; i < objects.length; i++)
		{
			objects[i].outerHTML = objects[i].outerHTML;
			
		}
	}
	
	
	objects = document.getElementsByTagName("embed");
	
	doTracer("n swfs: "+objects.length)
	
	for (var i = 0; i < objects.length; i++)
	{
		w		=	objects[i].width
		h		=	objects[i].height
		swfSrc	=	objects[i].src
		doTracer(swfSrc)

		if(swfSrc.toLowerCase().indexOf("swf")==-1){
			continue;	
		}
		
		raiz	=	objects[i].parentNode

		raiz.removeChild(objects[i])
		
		holdAhtml	=	raiz.innerHTML;
		
		var so = new SWFObject(swfSrc, "swf_"+i, w, h, "8", "#144065");
	    so.addParam("quality", "best");
	    so.addParam("wmode", "transparent");
		//so.addParam("salign", "l");
		so.addParam("menu", "false");
		//so.addParam("scale", "noscale");
		so.addParam("scale", "noborder");
		
		pos1	=	swfSrc.indexOf("?")
		uri		=	swfSrc.slice(pos1+1)
		if(uri){
			uri	=	uri.split("&")
			for ( v = 0; v < uri.length; v++ ) {
				pos			=	uri[v].indexOf("=")
				
				varName		=	uri[v].slice(0,pos)
				varValue	=	uri[v].slice(pos+1)
				doTracer("vars >>> "+varName + "="+ varValue)
				
				so.addVariable(varName, varValue);
				
			}
		}
		//so.addVariable("variable1", "value1");

		so.write(raiz);
		raiz.innerHTML	+= holdAhtml;	
		
/*
		var backFr=document.createElement("IFRAME")
		backFr.id='FRM'+i
		backFr.width=w
		backFr.height=h
		backFr.style.position='absolute'
		//backFr.style.visibility='hidden'
		backFr.style.backgroundColor='green'
		backFr.style.zIndex=0
		backFr.scrolling='no'
		backFr.frameBorder=0
		
		raiz.appendChild(backFr)
*/
		
	}
}

function doTracer(v){
	document.getElementById("tracer").innerHTML	+=	"<br>"+v
}

