// JavaScript Ilustri
// 2  de abr 2008
//*********************************************************
//onsubmit="javascript:return VerificaCampo(['nome','email','endereco'],['Nome do usuario','Email do responsavel','Endereço']);"
function VerificaCampo(array,arrayb){
	mensagem = "Há campos obrigatórios que estão vazios!\nPor favor preencha os campos: \n\n"
	if (array.length>0) {
		i = 0;
		while (i<array.length) {
			if(document.all[array[i]].value == ""){
				mensagem = mensagem + arrayb[i] + "\n"
				alert(mensagem)
				return false
			}
			i++
		}
	}
	return true
}
//*********************************************************

function VerificaCampoB(array){
	mensagem = "Há campos obrigatórios que estão vazios!\nPor favor preencha os campos: \n\n"
	if (array.length>0) {
		i = 0;
		while (i<array.length) {
			if(document.all[array[i]].value == ""){
				mensagem = mensagem + array[i] + "\n"
				alert(mensagem)
				return false
			}
			i++
		}
	}
	return true
}
//*********************************************************
//document.myFORM.myTA.value = window.clipboardData.getData("Text"); 
function IlustriTransferencia(txt){
  if( window.clipboardData && clipboardData.setData ){
	 clipboardData.setData("Text", txt);
  }else{
	 alert("Por favor copie o caminho no modo tradicional /n Pois este recurso é somente para Internet Explorer.");
  }
}
//*********************************************************
function IlustriFlashColor(txt,bg) {
	window.open("IlustriFlashColor.asp?txt="+txt+"&bg="+bg, "IlustriFlashColor","width=385,height=270,top=200,left=200");
}
//*********************************************************
function Downloadbanco(arquivo) {
		var uri = "DownloadIlustri.asp?arquivobanco="+arquivo;
		location.href = uri;
}
//*********************************************************
function DownloadIlustri(arquivo) {
		var uri = "DownloadIlustri.asp?arquivo="+arquivo;
		location.href = uri;
}
//*********************************************************
function download(categoria, imagem) {
		var uri = "download_ilustri.asp?categoria="+categoria+"&arquivo="+imagem;
		location.href = uri;
}
//*********************************************************
function enquete(id){
	var opcao = 0;
	var flag=0;
	for(var i=0; i < form_enq.resposta.length; i++){
		if (form_enq.resposta[i].checked){
			opcao = form_enq.resposta[i].value;
			flag++;
		}
	}
	if (flag==0){
		alert("Selecione uma opção!");
	}else{
		MM_openBrWindow('resultadoEnq.asp?idEnquete='+id+'&resposta='+opcao+'','resultado','width=220,height=270');
	}
}
//*********************************************************
function MM_openBrWindow(theURL,winName,features) {
	//v2.0
	window.open(theURL,winName,features);
}
//*********************************************************
function popup(theURL) {
	window.open(theURL,"impressao",'width=740,height=500');
}
//*********************************************************
function Ilustripop(theURL,L,H,scrol) {
	window.open(theURL,'janela'+L,'width='+L+',height='+H+',scrollbars='+scrol);
}
//*********************************************************
function popupb(txt) {
	window.open("indicar.asp?url="+txt,"indicar",'width=350,height=350');
}
//*********************************************************
function IndicarFoto(txt) {
	window.open("indicarfoto.asp?url="+txt,"indicar",'width=400,height=500,scrollbars=1');
}
//*********************************************************
function popupc(txt) {
	window.open("comentar.asp?url="+txt,"comentar",'width=350,height=350');
}
//*********************************************************
function popupd(txt) {
	window.open("fale.asp","faleconosco",'width=350,height=350');
}
//*********************************************************
function outraedicao(txt){
	edicaoanterior = document.form_edicoes.edicoes.value
	if(edicaoanterior == "-"){
		alert("Por Favor, selecione uma edição válida!")
	}else if(edicaoanterior == txt){
		alert("Você já está na edição de "+edicaoanterior+"!")
	}else{
		window.location = "eshoje.asp?edicao=" + edicaoanterior
	}
}

function buscar(){
	buscar = document.form_edicoes.buscar.value
	window.location = "noticia.asp?buscar="+buscar
}
//*********************************************************
// SPAM DISPLAY

function display(oque){
	if (oque.style.display=='none'){
		oque.style.display='';
	}else{
		oque.style.display='none'
	}
}
function showhide(oque){
	if (oque.style.display=='none'){
		oque.style.display='';
	}else{
		oque.style.display='none'
	}
}
function expandirtodas(){
	menu1.style.display='';
	menu2.style.display='';
	menu3.style.display='';
	menu4.style.display='';
	menu5.style.display='';
	menu6.style.display='';
	menu7.style.display='';
	menu8.style.display='';
	menu9.style.display='';
	menu10.style.display='';
	menu11.style.display='';
	menu12.style.display='';
}
//FIM  SPAM DISPLAY
//*********************************************************
function ValidaContatoIlustri(){
	if ((document.form1.nome.value == "")
		|| (document.form1.email.value == "")
		|| (document.form1.mensagem.value == "")
		){
		window.alert("Atenção! \n Não pode haver campos em branco!");
		return false;
	}
	return true;
}
//*********************************************************
function isValidEmail(str) {
	return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}
//*********************************************************
function ValidaIndicacaoIlustri(){
	if ((document.form1.nome.value == "")
		|| (document.form1.email.value == "")
		|| (document.form1.seunome.value == "")
		|| (document.form1.seuemail.value == "")
		|| (document.form1.comentario.value == "")
		){
		window.alert("Atenção! \nNão pode haver campos em branco!");
		return false;
	}
	email1 = document.form1.seuemail.value 
	if(isValidEmail(email1) == false){
		window.alert("Atenção! \nEmail incorreto!");
		return false;
	}
	email2 = document.form1.email.value 
	if(isValidEmail(email2) == false){
		window.alert("Atenção! \nEmail incorreto!");
		return false;
	}
	return true;
}
//*********************************************************
function ValidaEmailIlustri(objeto){
	email = objeto.value
	if (txtemail == ""){
		window.alert("Atenção! \nCampo de email em branco!");
		return false;
	}
	if(isValidEmail(email) == false){
		window.alert("Atenção! \nEmail incorreto!");
		return false;
	}
	return true;
}
//*********************************************************
function ilustriCalendario(txt) {
	window.open("admin/ilustriCalendario.asp?txt="+txt, "Calendario","width=240,height=190,top=200,left=200");
}
function Admin_ilustriCalendario(txt) {
	window.open("ilustriCalendario.asp?txt="+txt, "Calendario","width=240,height=190,top=200,left=200");
}

//*********************************************************
function ValidaNewsIlustri(){
	if ((document.form1.nome.value == "")
		|| (document.form1.email.value == "")
		){
		window.alert("Atenção! \nNão pode haver campos em branco!");
		return false;
	}
	return true;
}
//*********************************************************
// Central imagens
function centralpopup(id,tabela,atualizacao,ilustri){
	//atualizacao - atualizar o banco coloque =  1 
	//não houver atualizar coloque  =  0 - e mude para zero as var do banco
	window.open("uploadcentral.asp?banco="+tabela+"&atualizacao="+atualizacao+"&ilustri="+ilustri+"&id="+id,"centralpopup","width=570 height=290  scrollbars=yes ")
}

//*********************************************************

//	onfocus="IlustriFocus(this, 'seu@email.com.br')" 
//	onblur="IlustriFocus(this, 'seu@email.com.br')"  

function IlustriFocus(editBox, defaultText){
	if ( editBox.value == defaultText ) {
		editBox.value = '';
	}
	else if ( editBox.value.length == 0 ) {
		editBox.value = defaultText;
		editBox.type = 'text'
	}
	return true;
}
//*********************************************************
// onClick="if(this.value == 'Seu email') { this.value=''; this.focus(); }"
//*********************************************************
function taLimit() {
	var taObj=event.srcElement;
	if (taObj.value.length==taObj.maxLength*1) return false;
}

function taCount(visCnt) { 
	var taObj=event.srcElement;
	if (taObj.value.length>taObj.maxLength*1) taObj.value=taObj.value.substring(0,taObj.maxLength*1);
	if (visCnt) visCnt.innerText=taObj.maxLength-taObj.value.length;
}
//*********************************************************
// Formata em tipo preço = 12.012.332.124,65
// não deixa digitar pontos letras etc..
// tambem existe a Função em ASP - IlustriFormataPreco no ilustri.asp
//onkeydown="IlustriFormataPreco(this,event,17,2);"
function IlustriFormataPreco(objeto,teclapres,tammax,decimais) 
{
	var tecla			= teclapres.keyCode;
	var tamanhoObjeto	= objeto.value.length;
	if ((tecla == 8) && (tamanhoObjeto == tammax))
	{
		tamanhoObjeto = tamanhoObjeto - 1 ;
	}
    if (( tecla == 8 || tecla == 88 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ) && ((tamanhoObjeto+1) <= tammax))
	{
		vr	= objeto.value;
		vr	= vr.replace( "/", "" );
		vr	= vr.replace( "/", "" );
		vr	= vr.replace( ",", "" );
		vr	= vr.replace( ".", "" );
		vr	= vr.replace( ".", "" );
		vr	= vr.replace( ".", "" );
		vr	= vr.replace( ".", "" );
		tam	= vr.length;
		if (tam < tammax && tecla != 8)
		{
			tam = vr.length + 1 ;
		}
		if ((tecla == 8) && (tam > 1))
		{
			tam = tam - 1 ;
			vr = objeto.value;
			vr = vr.replace( "/", "" );
			vr = vr.replace( "/", "" );
			vr = vr.replace( ",", "" );
			vr = vr.replace( ".", "" );
			vr = vr.replace( ".", "" );
			vr = vr.replace( ".", "" );
			vr = vr.replace( ".", "" );
		}
		if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )
		{
			if (decimais > 0)
			{
				if ( (tam <= decimais) )
				{ 
					objeto.value = ("0," + vr) ;
				}
				if( (tam == (decimais + 1)) && (tecla == 8))
				{
					objeto.value = vr.substr( 0, (tam - decimais)) + ',' + vr.substr( tam - (decimais), tam ) ;	
				}
				if ( (tam > (decimais + 1)) && (tam <= (decimais + 3)) &&  ((vr.substr(0,1)) == "0"))
				{
					objeto.value = vr.substr( 1, (tam - (decimais+1))) + ',' + vr.substr( tam - (decimais), tam ) ;
				}
				if ( (tam > (decimais + 1)) && (tam <= (decimais + 3)) &&  ((vr.substr(0,1)) != "0"))
				{
				    objeto.value = vr.substr( 0, tam - decimais ) + ',' + vr.substr( tam - decimais, tam ) ; 
				}
				if ( (tam >= (decimais + 4)) && (tam <= (decimais + 6)) )
				{
			 		objeto.value = vr.substr( 0, tam - (decimais + 3) ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
				}
			 	if ( (tam >= (decimais + 7)) && (tam <= (decimais + 9)) )
				{
			 		objeto.value = vr.substr( 0, tam - (decimais + 6) ) + '.' + vr.substr( tam - (decimais + 6), 3 ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
				}
				if ( (tam >= (decimais + 10)) && (tam <= (decimais + 12)) )
				{
			 		objeto.value = vr.substr( 0, tam - (decimais + 9) ) + '.' + vr.substr( tam - (decimais + 9), 3 ) + '.' + vr.substr( tam - (decimais + 6), 3 ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
				}
				if ( (tam >= (decimais + 13)) && (tam <= (decimais + 15)) )
				{
			 		objeto.value = vr.substr( 0, tam - (decimais + 12) ) + '.' + vr.substr( tam - (decimais + 12), 3 ) + '.' + vr.substr( tam - (decimais + 9), 3 ) + '.' + vr.substr( tam - (decimais + 6), 3 ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
				}
			}
			else if(decimais == 0)
			{
				if ( tam <= 3 )
				{ 
			 		objeto.value = vr ;
				}
				if ( (tam >= 4) && (tam <= 6) )
				{
					if(tecla == 8)
					{
						objeto.value = vr.substr(0, tam);
						window.event.cancelBubble = true;
						window.event.returnValue = false;
					}
					objeto.value = vr.substr(0, tam - 3) + '.' + vr.substr( tam - 3, 3 ); 
				}
				if ( (tam >= 7) && (tam <= 9) )
				{
					if(tecla == 8)
					{
						objeto.value = vr.substr(0, tam);
						window.event.cancelBubble = true;
						window.event.returnValue = false;
					}
					objeto.value = vr.substr( 0, tam - 6 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, 3 ); 
				}
				if ( (tam >= 10) && (tam <= 12) )
				{
			 		if(tecla == 8)
					{
						objeto.value = vr.substr(0, tam);
						window.event.cancelBubble = true;
						window.event.returnValue = false;
					}
					objeto.value = vr.substr( 0, tam - 9 ) + '.' + vr.substr( tam - 9, 3 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, 3 ); 
				}

				if ( (tam >= 13) && (tam <= 15) )
				{
					if(tecla == 8)
					{
						objeto.value = vr.substr(0, tam);
						window.event.cancelBubble = true;
						window.event.returnValue = false;
					}
					objeto.value = vr.substr( 0, tam - 12 ) + '.' + vr.substr( tam - 12, 3 ) + '.' + vr.substr( tam - 9, 3 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, 3 ) ;
				}			
			}
		}
	}
	else if((window.event.keyCode != 8) && (window.event.keyCode != 9) && (window.event.keyCode != 13) && (window.event.keyCode != 35) && (window.event.keyCode != 36) && (window.event.keyCode != 46))
		{
			window.event.cancelBubble = true;
			window.event.returnValue = false;
		}
}
//*********************************************************
function upload_banner(width, height, nome) {
	var top; var left;
	top = ( (screen.height/2) - (height/2) )
	left = ( (screen.width/2) - (width/2) )
	window.open('banner/upload_banner.asp?campo=banner_arquivo&pasta=banners',nome,'width='+width+',height='+height+',scrollbars=no,toolbar=no,location=no,status=no,menubar=no,resizable=no,left='+left+',top='+top);
}
//*********************************************************
function XmlElemento(name,content){
    var xml
    if (!content){
        xml='<' + name + '/>'
    }
    else {
        xml='<'+ name + '>' + content + '</' + name + '>'
    }
    return xml
}
//*********************************************************
function XmlParametro(name,content){
    var xml
        xml='<'+ name +' '+ content + ' />'
    return xml
}
//*********************************************************
//Replace criado por Ilustri, que substitui apostrofo por aspas
function ReplaceAspas(txt) {
	apostrofo = "'"
	aspas = '"'
	var intIndexOfMatch = txt.indexOf(apostrofo);
	while (intIndexOfMatch != -1){
		txt = txt.replace(/'/, aspas)
		intIndexOfMatch = txt.indexOf(apostrofo);
	}
	return txt 
}
//*********************************************************
