function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	} else if (obj.x) { curleft += obj.x; }
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	} else if (obj.y) { curtop += obj.y; }
	return curtop;
}

function position(obj, reference) {
	var newX = findPosX(reference);
	var newY = findPosY(reference);
	obj.style.left = newX;
	obj.style.top = newY - obj.style.height.substring(0, obj.style.height.indexOf("px"));
}

function abrirMenu(reference) {
	var menuDiv = document.getElementById("menu");
	if (menuDiv.style.visibility == "hidden") {
		position(menuDiv, reference);
		menuDiv.style.visibility = "visible";
	} else {
		menuDiv.style.visibility = "hidden";
	}
}

function validaBusca() {
	if (document.busca.buscaText.value == "") {
		alert("Por Favor preencha o campo busca.");
		document.busca.buscaText.focus();
		return false;
	}
	return true;
}

function selogarlat() {
	document.logar_lat.senha.value=document.frm1.senha.value;
	if (document.logar_lat.login.value == "") {
		alert("Por Favor preencha o campo Login com seu Email ou Login.");
		document.logar_lat.login.focus();
		return false;
	}
	document.logar_lat.submit();
	return false;
}

function OpenPreviewPopup(arq, width, height, scroll) {
	var URL = arq;
	var W = width;
	var H = height;
	var S = scroll;
	var Wpopupsize =(W/2);
	var Hpopupsize =(H/2);
	var CenterPopUpX = (screen.width/2)-(Wpopupsize);
	var CenterPopUpY = (screen.height/2)-(Hpopupsize);
	var pos = "left="+CenterPopUpX+",top="+CenterPopUpY;
	var desktop = window.open( ""+URL, "", "width="+W+",height="+H+",toolbar=no,location=no,status=no,menubar=no,scrollbars="+S+",resizable=no,"+pos);
}

function OpenBEB() {
	window.location.href="/Web/Br/ForYou/BEB/src/index.asp";
/*	var URL = '/Web/Br/ForYou/BEB/src/index.asp';
	var W = 770;
	var H = 480;
	var S = 'no';
	var Wpopupsize =(W/2);
	var Hpopupsize =(H/2);
	var CenterPopUpX = (screen.width/2)-(Wpopupsize);
	var CenterPopUpY = (screen.height/2)-(Hpopupsize);
	var pos = "left="+CenterPopUpX+",top="+CenterPopUpY;
	var desktop = window.open( ""+URL, "BEB", "width="+W+",height="+H+",toolbar=no,location=no,status=no,menubar=no,scrollbars="+S+",resizable=no,"+pos);
*/
}

function OpenConcurso() {
	var URL = '/Web/Br/ForYou/HotSites/ConcursoCultural/src/ConcursoIndex.asp';
	var W = 640;
	var H = 430;
	var S = 'no';
	OpenPreviewPopup(URL, W, H, S);
}

function montaFlash(movie, width, height, wmode, FlashVars, name) {
	var swf  = '<object id='+name+' name='+name+' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
    + 'width="'+ width +'" height="'+ height +'"'
    + 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">'
    + '<param name="movie" value="'+ movie +'" /><param name="quality" value="high" /><param name="devicefont" value="true" /><param name="wmode" value="'+ wmode +'" /><param name="FlashVars" value="'+ FlashVars +'" />'
    + '<embed src="'+ movie +'" quality="high" devicefont="true" '
    + 'width="'+ width +'" height="'+ height +'" align="middle"'
    + 'play="true"'
    + 'loop="false"'
    + 'quality="high"'
    + 'wmode="'+ wmode +'"'
    + 'allowScriptAccess="sameDomain"'
    + 'type="application/x-shockwave-flash"'
    + 'FlashVars="'+ FlashVars +'"'
    + 'pluginspage="http://www.macromedia.com/go/getflashplayer"'
    + '><\/embed>'
    + '<\/object>';
	document.write(swf);
}

function createCookie(p_value, p_days) {
	var expires = '';
	if (p_days) {
		var date = new Date();
		date.setTime(date.getTime() + (p_days * 24 * 60 * 60 * 1000));
		expires = '; expires=' + date.toGMTString();
	}
	document.cookie = 'redirect=' + p_value + expires + '; path=/';
	setTimeout(function() { document.location.href = p_value; }, 100);
}

function readCookie() {
	var nameEQ = 'redirect=';
	var ca = document.cookie.split(';');
	for (var i = 0, l = ca.length; i < l; i++) {
		var c = ca[i];
		while (c.charAt(0) == ' ') { c = c.substring(1, c.length); }
		if (c.indexOf(nameEQ) == 0) { return c.substring(nameEQ.length, c.length); }
	}
	return null;
}

function eraseCookie() { document.cookie = 'redirect=; expires=-1; path=/'; }
