function exibeFlash(swf, width, height, wmode, cache)
{
	noCache = cache || cache == undefined ? "" : "?" + new Date();
	if(wmode==undefined) wmode="opaque";

	monta_swf = "";
	monta_swf += "<object id=\""+ swf+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" width=\""+ width +"\" height=\""+ height +"\" title=\"\">";
	monta_swf += "<param name=\"movie\" value=\""+ swf + noCache +"\" >";
	monta_swf += "<param name=\"quality\" value=\"high\" >";
	monta_swf += "<param name=\"menu\" value=\"0\" >";
	monta_swf += "<param name=\"allowScriptAccess\" value=\"always\" >";
	monta_swf += "<param name=\"wmode\" value=\""+ wmode +"\" >";
	monta_swf += "<embed src=\""+ swf + noCache +"\" quality=\"high\" wmode=\""+ wmode +"\" menu=\"0\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\""+ width +"\" height=\""+ height +"\"></embed>";
	monta_swf += "</object>";

	document.write(monta_swf);
}

 

function janela(www,h,w)
{
	var height = window.screen.height - 160;
	var width = window.screen.width;
	var top = (height- h)/2;
	var left = (width - w)/2;
	win = window.open(www,"nova","top=" + top + ",left="+ left +",width="+w+",height="+h+",toolbar=no,location=no,status=no,menubar=no,scrollbars=no,scrolling=no,resizable=no")
	win.focus();
} 

//Utilização: onkeypress="evita_letra(event)" onKeydown="FormataHora('NOMEDOCAMPO','NOMEDOFORM',event)" maxlength="5"
function FormataHora(campo,formname,teclapres){
	var tecla = teclapres.keyCode;
	vr = document[formname][campo].value;
	vr = vr.replace( ":", "" );
	tam = vr.length + 1;
	
	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 ){
			document[formname][campo].value = vr.substr( 0, tam - 2  ) + ':' + vr.substr( tam - 2, tam );
		}
	}
}
// FUNÇÃO QUE AUTOCOMPLETA DATA COM '/'
// COMO UTILIZAR:    onkeydown="FormataData(this.name,this.form.name,event);" 
function FormataData(campo,formname,teclapres) { // Máscara para os campos de data
	var tecla = teclapres.keyCode;
	vr = document[formname][campo].value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 )
			document[formname][campo].value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 10 )
			document[formname][campo].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); 
	}
}
// COMO UTILIZAR: onkeypress="evita_letra2(event)"
// Não permite digitar letras em um input type=text
function evita_letra2(tecla) {
	if (tecla.keyCode < 48 || tecla.keyCode > 57) 
		tecla.returnValue = false;
}


function criaObjetoAjax(){
	
	var httprequest=null;
	/* Mozilla, Safari, FireFox ... */
    if( window.XMLHttpRequest ){
    	
       httprequest = new XMLHttpRequest();
        
    /* IE */
    } else if( window.ActiveXObject){
        try{
            httprequest = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e){
            try{
                httprequest = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }
    
    if(httprequest != null && httprequest != undefined){
		return httprequest;
    }else{
    	return null;
    } 
    
}


function fechar()
{
	document.getElementById('popup').style.display='none';
}

function refresh()
{
 location = 'ajaxcontador.php';
}
	function valida_login(fcad)
{
	if(fcad.usuario.value=='')
	{
		 alert('Campo login vazio.');
		 fcad.usuario.focus();
		 return false;
	}
	if(fcad.senha.value=='')
	{
		 alert('Campo senha vazio.');
		 fcad.senha.focus();
		 return false;
	}
 fcad.submit();
}



function mostrar_texto(tblObj)
		{ 
		  var x = document.getElementById('teste');
		  if(tblObj.style.display=="none") {
			tblObj.style.display = "block";
			
		  }
		  else {
			tblObj.style.display = "none";
		  }
		 return false;
		}

								function createRequestObject(){
	var request_;
	var browser = navigator.appName;

	if(browser == "Microsoft Internet Explorer"){
	 	request_ = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
	 	request_ = new XMLHttpRequest();
	}

	return request_;
}

var http = createRequestObject();
function getInfo2(url){
	http.open('get', url);
	http.onreadystatechange = handleInfo;
	http.send(null);
}

function getInfo(){
   
	http.open('get','ajaxcontador.php');
	http.onreadystatechange = handleInfo;
	http.send(null);
}

function handleInfo(){
	/*if(http.readyState == 1){
	 	document.getElementById('cont').innerHTML = 'Loading...';
	}*/
	if(http.readyState == 4){
		var response = http.responseText;
		document.getElementById('contador').innerHTML = response;
	}
}
var xmlhttp = createRequestObject();


function _getAjax (pagina, obj)
{
	//var getstr = "?";
	var getstr = "";//string que guardara os parametros passados via post
	var i;
	//******************************************************
	
	// Concatena POST pelo elements
	for (i=0; i<obj.elements.length; i++)
	{
		//alert(obj.elements[i].tagName);
			if (obj.elements[i].tagName == "TEXTAREA")
			{
				{
					getstr += obj.elements[i].name + "=" + escape(obj.elements[i].value) + "&"; }
			}
			if (obj.elements[i].tagName == "INPUT")
			{
				if (obj.elements[i].type == "text") 	{ getstr += obj.elements[i].name + "=" + escape(obj.elements[i].value) + "&"; }
				if (obj.elements[i].type == "hidden") 	{ getstr += obj.elements[i].name + "=" + escape(obj.elements[i].value) + "&"; }
				if (obj.elements[i].type == "password") { getstr += obj.elements[i].name + "=" + escape(obj.elements[i].value) + "&"; }
				if (obj.elements[i].type == "checkbox") {
					if (obj.elements[i].checked) { getstr += obj.elements[i].name + "=" + escape(obj.elements[i].value) + "&"; }
					else { getstr += obj.elements[i].name + "=&"; }
				}
				if (obj.elements[i].type == "radio")
				{
					if (obj.elements[i].checked) { getstr += obj.elements[i].name + "=" + escape(obj.elements[i].value) + "&"; }
				}
			}
			else if (obj.elements[i].tagName == "SELECT")
			{
				var sel = obj.elements[i];
				getstr += sel.name + "=" + escape(sel.options[sel.selectedIndex].value) + "&";
			}
	}
	
	
	_makeRequest (pagina, getstr);
	return false;//para retornar e naum enviar quando apertar enter
}




function getPage(url, campo){   
    //Abre a url
	
	var _httpRequest = criaObjetoAjax();
 	var conteudo=document.getElementById(campo);
	
	if(_httpRequest == null){
				
		alert('Requisição não aceita, tente novamente');
		return false;
		
	}else{
		
		conteudo.innerHTML='<img src="images/loading.gif" style="margin-top:30%;">';
		document.body.scrollTop='0';
			
	} 
		
    _httpRequest.open("GET", url,true);

    //Executada quando o navegador obtiver o c?digo

    _httpRequest.onreadystatechange=function() {
        if (_httpRequest.readyState==4){
            //L? o texto
            var texto=_httpRequest.responseText;
            
            //Exibe o texto no div conte?do
           

            conteudo.innerHTML=texto;
           
            
        }
    }
    _httpRequest.send(null);
}



function _makeRequest(url, parameters)
{
	
	
	var _httpRequest = criaObjetoAjax();
	
	if(_httpRequest == null){
		
		document.getElementById('load').style.display='none';
		if(document.getElementById('btnSalvar')!=null)
			document.getElementById('btnSalvar').disabled=false;
		
		alert('Requisição não aceita, tente novamente');
		return false;
		
	}else{
				
		document.getElementById('load').style.display='block';

		if(document.getElementById('btnSalvar')!=null)
			document.getElementById('btnSalvar').disabled=true;
			
	} 
	
	// Parâmetros para POST
	
	
	_httpRequest.onreadystatechange = function(){
		
		if (_httpRequest.readyState == 4)
		{			
			
			if (_httpRequest.status == 200)
			{
				
				document.getElementById('load').style.display='none';
				if(document.getElementById('btnSalvar')!=null)
					document.getElementById('btnSalvar').disabled=false;
				result = _httpRequest.responseText;
				eval(result);
			}			
		}	
	}
	
	
	_httpRequest.open('POST', url, true);
	_httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=ISO-8859-1");
	_httpRequest.setRequestHeader("Content-length", parameters.length);
	_httpRequest.setRequestHeader("Connection", "close");
	_httpRequest.send(parameters);

}


function _alertContents()
{
	if (_httpRequest.readyState == 4)
	{
		
		var status='';
		try{
			status = _httpRequest.status;
		}
		catch(e){
			alert('Problemas de conexão com a internet, verifique sua conexão e tente novamente.');
			document.getElementById('load').style.display='none';
			if(document.getElementById('btnSalvar')!=null)
				document.getElementById('btnSalvar').disabled=false;
			return false;
		}
		
		if (status == 200)
		{
			document.getElementById('load').style.display='none';
			if(document.getElementById('btnSalvar')!=null)
				document.getElementById('btnSalvar').disabled=false;
			result = _httpRequest.responseText;
			eval(result);
		}
		else
		{
			alert('Problemas de conexão com a internet, verifique sua conexão e tente novamente.');
			document.getElementById('load').style.display='none';
			if(document.getElementById('btnSalvar')!=null)
				document.getElementById('btnSalvar').disabled=false;
			return false;
		}
	}
}


function mudaDiv(nome)
{
	obj = document.getElementById(nome);
	if(obj.style.display=='none')
	{
		obj.style.display='block';		
	}else{
		obj.style.display='none';		
	}
}
function habilitaDiv(nome)
{
	obj = document.getElementById(nome);
	if(obj.style.display=='none')
	{
		obj.style.display='block';		
	}
}

function desabilitaDiv(nome)
{
	obj = document.getElementById(nome);
	if(obj.style.display=='block')
	{
		obj.style.display='none';		
	}
}


function mostraMsgAlerta(icone,msg,tempo){
	
	var objIcoAcerto = document.getElementById('icoAcerto');
	var objIcoErro = document.getElementById('icoErro');
	
	if(icone=='acerto'){
		objIcoAcerto.style.display = 'block';
		objIcoErro.style.display = 'none';		
	}else if(icone=='erro'){
		objIcoAcerto.style.display = 'none';
		objIcoErro.style.display = 'block';
	}else{
		objIcoAcerto.style.display = 'none';
		objIcoErro.style.display = 'none';
	}
	
	document.getElementById('MsgAlertTexto').innerHTML = msg;
	//habilitaDiv('divMsgAlert');
	$("#divMsgAlert").fadeIn('fast'); 
	//$("#divMsgAlert").hide('slow'); 
	
	//desbloquearBotao('btEnviarContato');
	setTimeout('$("#divMsgAlert").fadeOut(\'slow\');', tempo);
		
}


function acoesFadeout(){
	
	$("#divMsgAlert", parent.document.body).click(function() { parent.Shadowbox.close();  });
	$("#divMsgAlert", parent.document.body).fadeOut('slow',function() { parent.Shadowbox.close();  });
}

function mostraMsgAlerta2(icone,msg,tempo){//para iframe
	
	var objIcoAcerto = parent.document.getElementById('icoAcerto');
	var objIcoErro = parent.document.getElementById('icoErro');
	
	if(icone=='acerto'){
		objIcoAcerto.style.display = 'block';
		objIcoErro.style.display = 'none';		
	}else if(icone=='erro'){
		objIcoAcerto.style.display = 'none';
		objIcoErro.style.display = 'block';
	}else{
		objIcoAcerto.style.display = 'none';
		objIcoErro.style.display = 'none';
	}
	
	parent.document.getElementById('MsgAlertTexto').innerHTML = msg;
	//habilitaDiv('divMsgAlert');
	//$("#divMsgAlert").fadeIn('fast'); 
	$("#divMsgAlert", parent.document.body).fadeIn('fast'); 
	//$("#divMsgAlert").hide('slow'); 
	
	if(icone=="acerto")
		setTimeout('acoesFadeout()', tempo);
	else if(icone=="erro")
		setTimeout('$("#divMsgAlert", parent.document.body).fadeOut(\'5000\')', tempo);
	else	{
		setTimeout('$("#divMsgAlert", parent.document.body).fadeOut(\'5000\')', tempo);
		setTimeout('acoesFadeout()', tempo);
	}
}

function mostraMsgAlertaPromocao(icone,msg,tempo){//para iframe
	
	
	var objIcoAcerto = document.getElementById('icoAcertoPromocao');
	var objIcoErro = document.getElementById('icoErroPromocao');
	
	if(icone=='acerto'){
		objIcoAcerto.style.display = 'block';
		objIcoErro.style.display = 'none';		
	}else if(icone=='erro'){
		objIcoAcerto.style.display = 'none';
		objIcoErro.style.display = 'block';
	}else{
		objIcoAcerto.style.display = 'none';
		objIcoErro.style.display = 'none';
	}
	
	document.getElementById('MsgAlertTextoPromocao').innerHTML = msg;
	//habilitaDiv('divMsgAlert');
	$("#divMsgAlertPromocao").fadeIn('fast'); 
	//$("#divMsgAlert").hide('slow'); 
	
	//desbloquearBotao('btEnviarContato');
	setTimeout('$("#divMsgAlertPromocao").fadeOut(\'slow\');', tempo);
}


function filtroCidade(div,uf){	
	getPage('ajaxCidade.php?uf='+uf,div);	
}



function trocaFoto(id,idPasta,legenda,arq,nome){
	$("#load").fadeIn('fast'); 
	var diretorio="uploads/galeria/"+idPasta+"/";
	var peq='fotoPeq'+id;
	
	//parent.document.getElementById('fotoGrande').src=diretorio+id+'.jpg';
	//document.getElementById(peq).src=diretorio+id+'_thumb_pb.jpg';	
	
	
	parent.document.getElementById('fotoGrande').src='imagem_layout.php?img='+diretorio+id+'.jpg&largura=400&altura=300';	
	document.getElementById(peq).src='imagem_layout.php?img='+diretorio+id+'_thumb_pb.jpg&largura=75&altura=56';	
	parent.document.getElementById('fotoGrandeLink').href='download.php?r=2&arq='+arq+'&nome='+nome;
	
	
	$("#load").fadeOut('fast'); 
	
}


function trocaFotoLegenda(id,pasta,legenda){//dentro do shadowbox
	
	$("#load").fadeIn('fast'); 
	var diretorio="uploads/"+pasta+"/";
	var peq='fotoPeq'+id;
	
	
	document.getElementById('fotoGrande').src=diretorio+id+'.jpg';
	document.getElementById(peq).src='imagem_layout.php?img=' + diretorio +id+ '_thumb_pb.jpg&largura=75&altura=58';	
	
	document.getElementById('legendaFoto').innerHTML=legenda;	
	
	$("#load").fadeOut('fast'); 
	
}


function limitaTexto(valor,qtde,campo,contador)
{
	
	total = valor.length;
	if(total <= qtde){//mostra quantos caracteres faltam
		resto = qtde - total;
		document.getElementById(contador).value = resto;	
		document.getElementById(contador+'_span').innerHTML = resto;	
		
	}else{
		document.getElementById(campo).value = valor.substr(0,qtde);
		document.getElementById(contador+'_span').innerHTML = valor.substr(0,qtde);;	
	}
	
}





function abreDivComLente(div){
	var objLente = document.getElementById('lente');
	var objDiv = document.getElementById(div);
	var objRadio = document.getElementById('radio');
	
	objLente.style.display = 'block';//mostra a lende
	//objDiv.style.display = 'block';//mostra a div	
	objDiv.style.visibility = 'visible';
	//objRadio.style.visibility = 'hidden';//esconde a radio para não ficar por cima da lente	
	objLente.onclick = function(){fechaDivComLente(div);}//seta o onclick da lente para fechar quando clicar nela	
}

function fechaDivComLente(div){
	var objLente = document.getElementById('lente');
	var objDiv = document.getElementById(div);
	var objRadio = document.getElementById('radio');
	
	//objDiv.style.display = 'none';//esconde a div	
	objDiv.style.visibility = 'hidden';
	objLente.style.display = 'none';//esconte a lende	
	//objRadio.style.visibility = 'visible';//mostra  a radio novamente
	objLente.onclick = function(){}//seta o onclick da lente para vazio	
}

function trocaAudio(id,titulo){
	
	var audioAtivo = document.getElementById('audioAtivo');
	
	//atualiza o player
	var FU = { 	movie:"radio/mediaplayer.swf",width:"320",height:"20",majorversion:"7",build:"0",bgcolor:"#000000",
				flashvars:"file=xml/historico_audio.php?id=" + id + "&displayheight=0&repeat=false&autostart=true&lightcolor=0x666666&backcolor=000000&frontcolor=0xFFFFFF&overstretch=true" };
	UFO.create(	FU, "playerAudio");
	
	//atualiza os nomes das musicas
	document.getElementById('musicaTocando').innerHTML = '&#8226; ' + titulo;
	
	
	
	document.getElementById('nomeAudio'+audioAtivo.value+'_ativo').style.display = 'none';
	document.getElementById('nomeAudio'+audioAtivo.value+'_inativo').style.display = 'block';
		
	document.getElementById('nomeAudio'+id+'_ativo').style.display = 'block';
	document.getElementById('nomeAudio'+id+'_inativo').style.display = 'none';
	
	audioAtivo.value = id;
	
}
function bloquearBotao(id){
	var obj = document.getElementById(id);
	obj.disabled = true;		
}
function desbloquearBotao(id){
	var obj = document.getElementById(id);
	obj.disabled = false;		
}

function mudaImg(id,over){
	var obj = document.getElementById(id);	
	obj.src='images/'+id+over+'.gif';
}

function atualizaLink(local,msg){
	
	tmp = msg.split('++');
	var id = tmp[0];
	var alt = tmp[1];
	
	var objLocal = document.getElementById(local);
	
	objLocal.innerHTML = 'Clique para saber mais sobre a promoção "'+alt+'"';
	objLocal.onclick = function(){
		openShadowboxComTamanho('promocao_lista.php?id='+id,'iframe','',800,600);
	}
}

