//Array com todas as janelas abertas
var janelasAbertas	= new Array();
var _listaLoaded	= false;

var _execLoc		= false;
var _execjsLoc		= "";

var _flexCarregado	= false;

function esconde_select(){
	if ( navigator.appVersion.indexOf("MSIE 6") > -1 ) {
		svn=document.getElementsByTagName("SELECT");
		for (a=0;a<svn.length;a++){
			svn[a].style.visibility="hidden";
		}
	}
}

function mostra_select(camada_index){
	if ( navigator.appVersion.indexOf("MSIE 6") > -1 ) {
		svn=document.getElementsByTagName("SELECT");
		
		for (a=0;a<svn.length;a++){
			if ( camada_index ) {
				svn[a].style.visibility="visible";    
			} else {
				if ( svn[a].name != "pesquisabasica_genero_index" ) { 
					svn[a].style.visibility="visible";    
				}
			}
		}
	}
}
	
function tamanhoJanela(tipojanela){
	var alturautilNavegador = 0;

	//verifiando se o browser é IE, caso for pega a area util do navegador IE, caso contrário pega o do firefox.
	if(navigator.appName =='Microsoft Internet Explorer'){
		alturaUtilNavegador = document.body.clientHeight;
	}else{
		alturaUtilNavegador = window.innerHeight;
	}
	
	var scroll_el = document.getElementById(tipojanela+"scroll");
	
	if (scroll_el && ((alturaUtilNavegador != scroll_el.alturaJanela) || (scroll_el.scrollHeight != scroll_el.alturaScroll))) {
		if (scroll_el.larguraInicial) {
			scroll_el.style.height 	= "auto";
			scroll_el.style.width 	= scroll_el.larguraInicial+"px";
		} else {
			scroll_el.larguraInicial = scroll_el.offsetWidth;
		}		
		scroll_el.alturaJanela = alturaUtilNavegador;
		scroll_el.alturaScroll = scroll_el.scrollHeight;
	}
	
	var alturaJanela = document.getElementById(tipojanela).offsetHeight;
	alturaUtilNavegador -= 20;
	if(alturaJanela > alturaUtilNavegador ){
		var alturaScroll = scroll_el.offsetHeight;
		var redimensionar = alturaScroll - (alturaJanela - alturaUtilNavegador);
		scroll_el.style.height = redimensionar+"px";
		scroll_el.style.width = scroll_el.offsetWidth+20+"px";
	}
}
	
//Função para centralizar a pagina na tela
function mostraDiv(idDiv){
	document.getElementById(idDiv).style.marginTop = "-600px";
	document.getElementById(idDiv).style.marginLeft = "-600px";
	document.getElementById(idDiv).style.display = "block";	
	
	//Centraliza a janela no meio da tela
	tamanhoJanela(idDiv);
	document.getElementById(idDiv).style.marginTop = -((document.getElementById(idDiv).offsetHeight/2) - ((document.all)?document.body.scrollTop:window.pageYOffset))+"px";
	document.getElementById(idDiv).style.marginLeft = -( document.getElementById(idDiv).offsetWidth /2)+"px";
}
	
//função para fechar o div
function fechaDiv(idDiv)
{
	document.getElementById(idDiv).style.display = "none";	
}
	
//Abre as janelas uma por cima da outra, coloca o zindex da que está embaixo com 0, fazendo com que a outra fique por cima, 
//nome do div tb fica com o nome do tipojanela
function abrirJanela(tipojanela,parametros){
	esconde_select();

	if (janelasAbertas.length>0) {
		for(i=0;i<janelasAbertas.length;i++) {
			$(janelasAbertas[i]).style.zIndex = 1;
		}
	}

	peliculaTela.display();
	mostraDiv("carregando");

	/* 
	*** Para não ter que ficar dando escape() nos parâmetros passados faz-se o seguinte, var par recebe parametros quebrados no &,
	*** percorre-se esse array par(split('&') com isso torna-se um array) fazendo a mesma coisa na var parunico separados por =,
	*** depois novoparametros recebe nome do atributo concatenado com seu valor(parunico[0]+'='+escape(parunico[1])), e a cada ite-
	*** ração do forverifica se novoparametros != "", caso sim é pq temos um novo parâmetro então concatena-se com &.
	*** Ex. nome=teste&idade=25  => nome=Teste|&|idade=24 => nome|=|Teste, idade|=|24
	*/
	var novoparametros = '';
	var par = parametros.split('&');
	for(var i = 0; i < par.length; i++){
		var parunico = par[i].split('=');
		if(novoparametros!=''){
			novoparametros += '&';
		}
		novoparametros += parunico[0]+'='+escape(parunico[1]);
	}

	//Envia para conteudojanela.php tipojanela e parametros se houver
	var url = "janelas/conteudojanela.php?"+antiCache()+"&tipojanela="+tipojanela;
	if(parametros!=""){
		url += "&"+novoparametros;
	}

	new Request.HTML({
		url: url,
		method: 'get',
		evalScripts: false,
		evalResponse:false,
		onComplete: function(responseTree, responseElements, responseHTML, responseJavaScript) {
			$(tipojanela).set('html',responseHTML);				
			$exec(responseJavaScript);

			janelasAbertas.push(tipojanela);
			fechaDiv("carregando");
			mostraDiv(tipojanela);
			fixedDiv.init(tipojanela);
		}
	}).send();
}

function vit_aj(tipojanela,parametros) {
	abrirJanela(tipojanela,parametros);
}

//função responsavel por fechar a janela
function fecharJanela() {
	if (janelasAbertas.length > 0) {	
		var janela = janelasAbertas.pop();
		fixedDiv.end(janela);
		fechaDiv(janela);
	
		if(janelasAbertas[(janelasAbertas.length-1)]=='filmes' ){
			atualizaFlexFilmes();
		}		
		if(janelasAbertas[(janelasAbertas.length-1)]=='filme' ){
			atualizaFlex2();
		}
	
		//Verifica se é a janela de filme 
		if(janela=='filme'){
			//Se tem trailer tira ele para não ficar rodando.
			if( $('filmetemtrailer').value == 'sim' ){
				$('playerTrailer').innerHTML = '';
			}
	
			//Se voltou para janela de filmes, atualiza as cestas de locação e reserva
			if(janelasAbertas[(janelasAbertas.length-1)]=='filmes' ){
				carregaCestaDeFilmesEmFilmes();
			}
	
			//Se voltou para janela de filme, atualiza as cestas de locação e reserva
			if(janelasAbertas[(janelasAbertas.length-1)]=='filme' ){
				carregaCestaDeFilmesEmFilme();
			}
		}
		
		if (janela == 'filmes') {
			_flexCarregado = false;
		}
		
		if(janela=='reservafilme'){
			//Se voltou para janela de filmes, atualiza as cestas de locação e reserva
			if(janelasAbertas[(janelasAbertas.length-1)]=='filmes' ){
				carregaCestaDeFilmesEmFilmes();
			}
		}
		
		if(janela=='locacaoonline'){
			//Se voltou para janela de filmes, atualiza as cestas de locação e reserva
			if(janelasAbertas[(janelasAbertas.length-1)]=='filmes' ){
				carregaCestaDeFilmesEmFilmes();
			}
			if(janelasAbertas[(janelasAbertas.length-1)]=='filme' ){
				carregaCestaDeFilmesEmFilme();
			}
		}
	
		if(janelasAbertas.length==0){
			peliculaTela.close();
			locadoraLogin();
			locadoraOnline();
			mostra_select(true);
		}else{
			$(janelasAbertas[(janelasAbertas.length-1)]).style.zIndex = 2;
			mostra_select(false);
		}
	}
}
	
function vit_fj(){
	fecharJanela();
}
	
function vit_fj_todas(){
	while (janelasAbertas.length > 0){
		var janela = janelasAbertas.pop();
		fechaDiv(janela);//tira da ultima posição
	}
	if ( janelasAbertas.length==0){
		peliculaTela.close();
	}
}
	
function mostraCarregando(){
	if(janelasAbertas.length>0){
		for(i=0;i<janelasAbertas.length;i++){
			$(janelasAbertas[i]).style.zIndex = 1;
		}
	}
	peliculaTela.display();
	mostraDiv("carregando");		
}

function vit_mc(){
	mostraCarregando();
}
	
function fechaCarregando(){
	fechaDiv("carregando");
	if(janelasAbertas.length==0){
		peliculaTela.close();
	}else{
		$(janelasAbertas[(janelasAbertas.length-1)]).style.zIndex = 2;
	}
}
	
function vit_fc(){
	fechaCarregando();
}

//função anti cache
function antiCache(){
	var dt = new Date();
	return encodeURI(Math.random() + "_" + dt.getTime());
}
	
function gravaCookie(chave,nome) {
	var c = chave;
	var n = nome;

	if (c!=null && c!="" && c>0) {
		document.cookie= "_c=" +escape(c);
		document.cookie= "n=" +escape(n);
		document.cookie= "l=LOJA";
		locadoraOnline();
		locadoraLogin();
	} else {
		document.cookie= "cv=" +escape(0);
		document.cookie= "_c=" +escape(0);
		document.cookie= "n=" +escape(0);
		document.cookie= "l=" +escape(0);
	}
}

function verificaCadastroLO() {
	var nameEQ = "l=";
	var local = "";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) local = unescape(c.substring(nameEQ.length,c.length));
	}
	
	if (local == "LOJA") {
		return true;	
	} else {
		alert('Cliente não habilitado a realizar locação online.');	
	}
	
	return false;	
}	
function get_cookie(c_name){
	var nameEQ = c_name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return unescape(c.substring(nameEQ.length,c.length));
	}
	return "0";
}
		
function FlexLocacaoOnline()
{
	var c = get_cookie('_c');
	if ( c == 0 ) {
		var exec = 'vit_aj("loflex","enviarpedido=nao");';
		vit_aj('loginlo','exec='+escape(exec));
	}else {
		vit_aj('loflex','enviarpedido=nao');
	}
}
	
/*********************************************************************************************/
//Funcões responsáveis por fazer o fundo escuro
DHTML_peliculaTela = function()
{
	var divs_transparentDiv; //Transparent div covering page content
}
	
DHTML_peliculaTela.prototype = {

	display : function()
	{
		//document.body.style.overflowY = "hidden";
		if(!this.divs_transparentDiv){
			this.__createDivs();
		}	
		this.divs_transparentDiv.style.display='block';
		this.__repositionTransparentDiv();
		
	}
	,
	close : function()
	{
		document.body.style.overflowY = "";
		this.divs_transparentDiv.style.display='none';
	}	
	,
	addEvent : function(whichObject,eventType,functionName,suffix)
	{ 
	  if(!suffix)suffix = '';
	  if(whichObject.attachEvent){ 
		whichObject['e'+eventType+functionName+suffix] = functionName; 
		whichObject[eventType+functionName+suffix] = function(){whichObject['e'+eventType+functionName+suffix]( window.event );} 
		whichObject.attachEvent( 'on'+eventType, whichObject[eventType+functionName+suffix] ); 
	  } else 
		whichObject.addEventListener(eventType,functionName,false); 	    
	} 
	,
	__createDivs : function()
	{
		// Creating transparent div
		this.divs_transparentDiv = document.createElement('DIV');
		this.divs_transparentDiv.className='modalDialog_transparentDivs';
		this.divs_transparentDiv.style.left = '0px';
		this.divs_transparentDiv.style.top = '0px';
		
		this.divs_transparentDiv.onclick = new Function("fecharJanela()");
		
		document.body.appendChild(this.divs_transparentDiv);

		window.refToModMessage = this;
		this.addEvent(window,'resize',function(e){ window.refToModMessage.__repositionTransparentDiv() });
	}
	,
	__getBrowserSize : function()
	{
		
		var bodyWidth, bodyHeight; 
		   bodyWidth = document.body.clientWidth;
			bodyHeight = document.body.clientHeight;
		   //if(document.body.scrollHeight > 100){
				if(document.body.scrollHeight > document.body.clientHeight){
					bodyHeight = document.body.scrollHeight ;
				}
		  // }
		return [bodyWidth,bodyHeight];		
		
	}
	,
	__repositionTransparentDiv : function()
	{
	
		//this.divs_transparentDiv.style.height = 0;
		var brSize = this.__getBrowserSize();
		var bodyWidth = brSize[0];
		var bodyHeight = brSize[1];
		this.divs_transparentDiv.style.width = bodyWidth + 'px';
		this.divs_transparentDiv.style.height = bodyHeight + 'px';
				
	}
}

/*function carregaTrailer(trailer){
	var FO = {	movie:"trailer/flvplayer.swf",id:"mediaplayerfilme",width:"288",height:"225",majorversion:"7",build:"0",bgcolor:"#FFFFFF",wmode:"transparent",
	flashvars:"file="+trailer+"&showdigits=true&autostart=false&showfsbutton=false&fsreturnpage=index.html" };
	UFO.create(	FO, "playerTrailer");
	setTimeout("enviaEvento('volume',100)", 2000);	
}
*/

function carregaTrailer(trailer, Largura, Altura){
	// w 288 h 225
	// w 320 h 260
	var FO = {	movie:"trailer/flvplayer.swf",id:"mediaplayerfilme",width: Largura, height: Altura, majorversion:"7",build:"0",bgcolor:"#FFFFFF", wmode:"transparent",
	flashvars:"file="+trailer+"&showdigits=true&autostart=false&showfsbutton=false&fsreturnpage=index.php" };
	UFO.create(	FO, "playerTrailer");
	setTimeout("enviaEvento('volume',100)", 2000);
}

function enviaEvento(typ,prm) {
	thisMovie("mediaplayerfilme").sendEvent(typ,prm);
}
	
function thisMovie(movieName) {
	if(navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
}

function locadoraOnline(){		
	var url = "janelas/locadoraestaonline.php?"+antiCache();
	
	new Request.HTML({
		url: url,
		method: 'get',
		evalScripts: false,
		evalResponse:false,
		onComplete: function(responseTree, responseElements, responseHTML, responseJavaScript) {
			$('div_status_locadoraonline').set('html',responseHTML);				
			$exec(responseJavaScript);
		}
	}).send();		
}

function locadoraLogin(){		
	var url = "janelas/locadoralogin.php?"+antiCache();
	
	new Request.HTML({
		url: url,
		method: 'get',
		evalScripts: false,
		evalResponse:false,
		onComplete: function(responseTree, responseElements, responseHTML, responseJavaScript) {
			$('div_status_login').set('html',responseHTML);				
			$exec(responseJavaScript);
		}
	}).send();	
}

function getQuizLateral(){
	
	var carregandoquizlateral = '';
	carregandoquizlateral +=    '<table width="100%" height="7" border="0" align="center" cellpadding="0" cellspacing="0">';
	carregandoquizlateral +=        '<tr>';
	carregandoquizlateral +=            '<td></td>';
	carregandoquizlateral +=        '</tr>';
	carregandoquizlateral +=    '</table>';
	carregandoquizlateral +=    '<table width="100%" height="237" border="0" cellpadding="0" cellspacing="0" class="QUADRO">';
	carregandoquizlateral +=        '<tr>';
	carregandoquizlateral +=            '<td valign="top" height="100%">';
	carregandoquizlateral +=                '<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">';
	carregandoquizlateral +=                    '<tr>';
	carregandoquizlateral +=                        '<td valign="top">';
	carregandoquizlateral +=                            '<table width="100%" border="0" cellpadding="0" cellspacing="0" style="cursor:default;">';
	carregandoquizlateral +=                                '<tr>';
	carregandoquizlateral +=                                    '<td class="TITULO_PADRAO">';
	carregandoquizlateral +=                                        '<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">';
	carregandoquizlateral +=                                            '<tr>';
	carregandoquizlateral +=                                                '<td>';
	carregandoquizlateral +=                                                    '<table height="100%" align="left" border="0" cellspacing="0" cellpadding="0">';
	carregandoquizlateral +=                                                        '<tr>';
	carregandoquizlateral +=                                                            '<td valign="top" class="TITULO_FONT">&nbsp;&nbsp;Quiz</td>';
	carregandoquizlateral +=                                                        '</tr>';
	carregandoquizlateral +=                                                    '</table>';
	carregandoquizlateral +=                                                '</td>';
	carregandoquizlateral +=                                            '</tr>';
	carregandoquizlateral +=	                                       '</table>';
	carregandoquizlateral +=                                    '</td>';
	carregandoquizlateral +=                                '</tr>';
	carregandoquizlateral +=                            '</table>';
	carregandoquizlateral +=                        '</td>';
	carregandoquizlateral +=                    '</tr>';
	carregandoquizlateral +=                    '<tr>';
	carregandoquizlateral +=                        '<td valign="top">';
	carregandoquizlateral +=                            '<table width="100%" cellpadding="0" cellspacing="0" border="0" class="LAYOUT_JANELA_FUNDO">';
	carregandoquizlateral +=                                '<tr>';
	carregandoquizlateral +=                                    '<td height="100%" valign="middle"  align="center">';
	carregandoquizlateral +=                                        '<img src="imagens/carregando.gif" border="0" height="105" width="105">';
	carregandoquizlateral +=                                    '</td>';
	carregandoquizlateral +=                                '</tr>';
	carregandoquizlateral +=                            '</table>';
	carregandoquizlateral +=                        '</td>';
	carregandoquizlateral +=                    '</tr>';
	carregandoquizlateral +=                '</table>';
	carregandoquizlateral +=            '</td>';
	carregandoquizlateral +=        '</tr>';
	carregandoquizlateral +=    '</table>';

	$('quiz_lateral').set('html',carregandoquizlateral);
	var url = "modelo_quiz_lateral.php?"+antiCache();
	
	new Request.HTML({
		url: url,
		method: 'get',
		evalScripts: false,
		evalResponse:false,
		onComplete: function(responseTree, responseElements, responseHTML, responseJavaScript) {
			$('quiz_lateral').set('html',responseHTML);
			$exec(responseJavaScript);
			getClickResponderQuiz('lateral');
		}
	}).send();
}

function getQuizCentral(){
	
	var carregandoquizcentral =	'<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" class="QUADRO">';
	carregandoquizcentral +=		'<tr>';
	carregandoquizcentral +=			'<td valign="top">';
	carregandoquizcentral +=				'<table width="100%" border="0" cellpadding="0" cellspacing="0" style="cursor:default;">';
	carregandoquizcentral +=					'<tr>';
	carregandoquizcentral +=						'<td class="TITULO_LEFT"></td>';
	carregandoquizcentral +=						'<td class="TITULO_PADRAO">';
	carregandoquizcentral +=							'<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">';
	carregandoquizcentral +=								'<tr>';
	carregandoquizcentral +=									'<td>';
	carregandoquizcentral +=										'<table height="100%" align="left" border="0" cellspacing="0" cellpadding="0">';
	carregandoquizcentral +=											'<tr>';
	carregandoquizcentral +=												'<td valign="top"><div class="TITULO_FONT">Quiz</div ></td>';
	carregandoquizcentral +=											'</tr>';
	carregandoquizcentral +=										'</table>';
	carregandoquizcentral +=									'</td>';
	carregandoquizcentral +=								'</tr>';
	carregandoquizcentral +=							'</table>';
	carregandoquizcentral +=						'</td>';
	carregandoquizcentral +=						'<td class="TITULO_RIGHT"></td>';
	carregandoquizcentral +=					'</tr>';
	carregandoquizcentral +=				'</table>';
	carregandoquizcentral +=				'<table width="100%" border="0" cellpadding="0" cellspacing="0">';
	carregandoquizcentral +=					'<tr>';
	carregandoquizcentral +=						'<td valign="top">';
	carregandoquizcentral +=							'<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">';
	carregandoquizcentral +=								'<tr>';
	carregandoquizcentral +=									'<table width="100%" cellpadding="0" cellspacing="0" border="0" class="LAYOUT_JANELA_FUNDO"><tr><td height="100%" valign="middle"  align="center"><img src="imagens/carregando.gif" border="0" height="105" width="105"></td></tr></table>'
	carregandoquizcentral +=								'</tr>';
	carregandoquizcentral +=							'</table>';
	carregandoquizcentral +=						'</td>';
	carregandoquizcentral +=					'</tr>';
	carregandoquizcentral +=				'</table>';
	carregandoquizcentral +=			'</td>';
	carregandoquizcentral +=		'</tr>';
	carregandoquizcentral +=	'</table>';
	
	$('quiz_central').set('html',carregandoquizcentral);
	var url = "modelo_quiz_central.php?"+antiCache();
	
	new Request.HTML({
		url: url,
		method: 'get',
		evalScripts: false,
		evalResponse:false,
		onComplete: function(responseTree, responseElements, responseHTML, responseJavaScript) {
			$('quiz_central').set('html',responseHTML);
			$exec(responseJavaScript);
			getClickResponderQuiz('central');
		}
	}).send();
}


function getClickResponderQuiz(local)
{
	if(get_cookie('_c')!="0"){
		if(local=='lateral'){
			$('btn_responder_quiz_lateral').onclick = enviaRespostaRadioBQuizLateral;
		}
	}else{
		$('btn_responder_quiz_'+local).onclick = loginQuiz;
	}
}

function horarioEntrega() {		
	var url = "janelas/horariolocacao.php?"+antiCache();
	
	new Request.HTML({
		url: url,
		method: 'get',
		evalScripts: false,
		evalResponse:false,
		onComplete: function(responseTree, responseElements, responseHTML, responseJavaScript) {
			$('div_horarioentrega').set('html',responseHTML);
			$exec(responseJavaScript);
		}
	}).send();	
}

peliculaTela = new DHTML_peliculaTela();//Termina as funções responsáveis pelo fundo escuro
document.write('<div id="carregando" style="display:none;position:absolute;top:50%;left:50%; z-index:2;" align="center"><img src="padroes/ajax-loader.gif" border="0"></div>');

var fixedDiv=function(){	
	return{
		init:function(id){
			var el=document.getElementById(id);
			if(document.layers)el.style=el;
			clearInterval(el.timer);
			el.timer=setInterval("fixedDiv.stayTopLeft('"+id+"')",200);
		},
		stayTopLeft:function(id){
			var el=document.getElementById(id);
			tamanhoJanela(id);
			var margin = -((el.offsetHeight/2) - ((document.all)?document.body.scrollTop:window.pageYOffset));
			el.style.marginTop=margin+"px";
		},
		end:function(id){
			var el=document.getElementById(id);
			clearInterval(el.timer)
		}
	};
}();

function formataCampoMascara(campo)
{
	var validas	= "0123456789(),.-:/ ";
	var texto	= "";

	for (i = 0; i < campo.value.length; i++) { 
		Caracter = campo.value.charAt(i); 
		if (validas.indexOf(Caracter)>-1) {
			texto += Caracter;
		}
	}
	campo.value = texto;
}

function Mascara(objeto, evt, mask) {
	
	var LetrasU = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
	var LetrasL = 'abcdefghijklmnopqrstuvwxyz';
	var Letras = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
	var Numeros = '0123456789';
	var Fixos = '(),.-:/ ';
	var Charset = " !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_/`abcdefghijklmnopqrstuvwxyz{|}~";
	
	evt = (evt) ? evt : (window.event) ? window.event : "";
	
	var value = objeto.value;
	
	if (evt) {

		var ntecla = (evt.which) ? evt.which : evt.keyCode;
		tecla = Charset.substr(ntecla - 32, 1);
		
		if (ntecla < 32){
			return true;
		}
		
		var tamanho = value.length;
		
		if (tamanho >= mask.length){
			return false;
		}
		
		var pos = mask.substr(tamanho,1);
		
		while (Fixos.indexOf(pos) != -1) {
			
			value += pos;
			tamanho = value.length;
			
			if (tamanho >= mask.length){
				return false;
			}
			
			pos = mask.substr(tamanho,1);
		}
		
		switch (pos) {
			case '#' : if (Numeros.indexOf(tecla) == -1) return false; break;
			case 'A' : if (LetrasU.indexOf(tecla) == -1) return false; break;
			case 'a' : if (LetrasL.indexOf(tecla) == -1) return false; break;
			case 'Z' : if (Letras.indexOf(tecla) == -1) return false; break;
			case '*' : objeto.value = value; return true; break;
			default : return false; break;
		}
	}
	
		objeto.value = value;
		return true;
}


function validaCPF(obj){
	
	cpf = obj.value;
	cpf = cpf.replace("-" , "");
	cpf = cpf.replace("." , "");
	cpf = cpf.replace("." , "");
	
	erro = new String;
	if (cpf.length < 11){
		erro += "São necessários 11 dígitos para verificação do CPF! \n\n";
	}
	
	var nonNumbers = /\D/;
	
	if (nonNumbers.test(cpf)){
		erro += "A verificação de CPF suporta apenas números! \n\n";
	}
	
	if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999"){
		erro += "Numero de CPF inválido!";
	}
	
	var a = [];
	var b = new Number;
	var c = 11;
	
	for (i=0; i<11; i++){
		a[i] = cpf.charAt(i);
		if (i < 9){
			b += (a[i] * --c);
		}
	}
	
	if ((x = b % 11) < 2) {
		a[9] = 0;
	} else {
		a[9] = 11-x;
	}
	
	b = 0;
	c = 11;
	
	for (y=0; y<10; y++){
		b += (a[y] * c--);
	}
	
	if ((x = b % 11) < 2) {
		a[10] = 0;
	} else {
		a[10] = 11-x;
	}
	
	if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])){
		erro +="CPF Inválido!";
	}
	
	if (erro.length > 0){
		alert(erro);
		return false;
	}
	return true;
} 


function MascaraDataIndex(objeto, evt){
	Mascara(objeto, evt, '##/##/####');
}

function MascaraCPF(objeto, evt){
	Mascara(objeto, evt, '###.###.###-##');
}

function MascaraTelefone(objeto, evt){
	Mascara(objeto, evt, '(##)####-####');
}

function MascaraCEP(objeto, evt){
	Mascara(objeto, evt, '#####-###');
}

function vit_tooltip(tooltip,acao){
	if(acao=='in'){
		$(tooltip).style.display = 'block';
	}else{
		$(tooltip).style.display = 'none';
	}
}

function vit_trim(string){
	var ini = 0;
	var fim = 0;
	
	for(i=0;i<string.length;i++){
		c = string.charAt(i);
		if(c==" "){
			ini++;
		}else{
			break;
		}
	}
	
	string = string.substr(ini);
	
	for(i=string.length;i>=0;i--){
		c = string.charAt(i);
		if(c==" "){
			fim++;
		}else{
			break;
		}
	}
	
	string = string.substr(0, string.length - fim);
	
	return string;
	
}

function confirmaSenha(senha1, senha2, img1c, img1e, img2c, img2e, btn){
	if (senha1.length >= 3){
		$(img1c).style.display	= '';
		$(img1e).style.display	= 'none';
	}else{
		$(img1c).style.display	= 'none';
		$(img1e).style.display	= '';
	}
	if ( (senha1 == senha2) && (senha1.length >= 3) ) {
		$(img2c).style.display	 = '';
		$(img2e).style.display	 = 'none';
		$(btn).disabled = false;
	}else{
		$(img2c).style.display	 = 'none';
		$(img2e).style.display	 = '';
		$(btn).disabled = true;
	}
}

function Logout()
{
	var url = "janelas/logout.php?"+antiCache();
	var pars = "&deslogar=sim";
	url += pars;
	new Request.HTML({
		url: url,
		method: 'post',
		evalScripts: false,
		evalResponse:false,
		onComplete: function(responseTree, responseElements, responseHTML, responseJavaScript) {
			//
		}
	}).send();
}

function janelaFilmesAberta()
{
	var retorno = false;
	for (i=0; i<janelasAbertas.length; i++) {
		if (janelasAbertas[i] == "filmes"){
			retorno  = true;
			break;
		}
	}
	return retorno;
}

function abreJanelaFilmes(parametros)
{
	if (!janelaFilmesAberta()) {
		
		tipojanela = 'filmes';
		
		esconde_select();
	
		//peliculaTela.display();
		//mostraDiv("carregando");
	
		/* 
		*** Para não ter que ficar dando escape() nos parâmetros passados faz-se o seguinte, var par recebe parametros quebrados no &,
		*** percorre-se esse array par(split('&') com isso torna-se um array) fazendo a mesma coisa na var parunico separados por =,
		*** depois novoparametros recebe nome do atributo concatenado com seu valor(parunico[0]+'='+escape(parunico[1])), e a cada ite-
		*** ração do forverifica se novoparametros != "", caso sim é pq temos um novo parâmetro então concatena-se com &.
		*** Ex. nome=teste&idade=25  => nome=Teste|&|idade=24 => nome|=|Teste, idade|=|24
		*/
		var novoparametros = '';
		var par = parametros.split('&');
		for(var i = 0; i < par.length; i++){
			var parunico = par[i].split('=');
			if(novoparametros!=''){
				novoparametros += '&';
			}
			novoparametros += parunico[0]+'='+escape(parunico[1]);
		}
	
		//Envia para conteudojanela.php tipojanela e parametros se houver
		var url = "janelas/conteudojanela.php?"+antiCache()+"&tipojanela="+tipojanela;
		if(parametros!=""){
			url += "&"+novoparametros;
		}
	
		new Request.HTML({
			url: url,
			method: 'get',
			evalScripts: false,
			evalResponse:false,
			onComplete: function(responseTree, responseElements, responseHTML, responseJavaScript) {
				$(tipojanela).set('html',responseHTML);				
				$exec(responseJavaScript);
	
				janelasAbertas.unshift(tipojanela);
				//fechaDiv("carregando");
				mostraDiv(tipojanela);
				fixedDiv.init(tipojanela);
				for(i=0;i<janelasAbertas.length-1;i++) {
					$(janelasAbertas[i]).style.zIndex = 1;
				}
			}
		}).send();
	}
}

function getExecLoc()
{
	if (_execLoc) {
		$exec(_execjsLoc);
		resetExecutarLoc();
	}
}

function setExecutarLoc(exec)
{
	_execLoc = true;
	_execjsLoc = exec;
}

function resetExecutarLoc()
{
	_execLoc = false;
	_execjsLoc = "";
}

function OrkutShare(titulo, subtitulo, link, imgs){
	var params = {};
	params[google.orkut.share.Field.TITLE]				= titulo;
	params[google.orkut.share.Field.DESTINATION_URL]	= link;
	params[google.orkut.share.Field.CONTENT]			= subtitulo;
	params[google.orkut.share.Field.THUMBNAIL]			= imgs;
	var connection = new google.orkut.share.Connection(params);
	connection.send('orkut.com', {});
}

function encode_utf8( s )
{
	return encodeURIComponent( s );
}

function TwitterShare(str)
{
	window.open("http://twitter.com/?status="+encode_utf8(str));
}
