// JavaScript Document
function redirect_banner()
{
	window.location.href('../homesite/redirect_banner.asp?idbanner=');
}



function editor(campo,diretorio) {
	var strValue = window.open('../../editor/default.asp?campo='+campo+'&diretorio='+diretorio,'editor',"height=430,width=550,scroll=no")
}

function editor_alterar(campo,tabela,campotabela,cod,diretorio) {
	var strValue = window.open('../../editor/default_altera.asp?campo='+campo+'&tabela='+tabela+'&cod='+cod+'&campotabela='+campotabela+'&diretorio='+diretorio,'editor',"height=430,width=550,scroll=no")
}


function escolhe_imagem(campo) {
	window.open('../imagens/default.asp?campo='+ campo,'enviar_imagem','width=350,height=350,top=100,left=100')
}

function imagem(campo,diretorio) {
window.open('../../editor/insere_imagem.asp?campo='+campo+'&diretorio='+diretorio,'insere_imagens','height=230,width=275','status=yes');
}


function confirm_excluir(arq,acao) {
	if (confirm('Deseja realmente Excluir esta Categoria ? \n \n Atenção ! Esta ação não terá retorno.'))
		{
			window.open(''+arq+''+acao,'_top');
		} 
/*		else
			{
				window.open('categorias.asp','_top');
			}
*/
}


function select_box(url_link,opcao) {
    var url = opcao.options[opcao.selectedIndex].value;
    if (url) {
        location.href = url_link + url;
    }
}


function imprimir(url) {
	var strValue = window.open(''+url+'','Janela','scrollbars=yes,status=no,location=no,toolbar=no,menubar=no,resizable=yes,height=300,width=640');
}

function abre_janela(url) {
	var strValue = window.open(''+url+'','Janela','scrollbars=yes,status=no,location=no,toolbar=no,menubar=no,resizable=yes');
}

function abre_enquete(url) {
	var strValue = window.open(''+url+'','Janela','scrollbars=yes,status=no,location=no,toolbar=no,menubar=no,resizable=yes,height=230,width=250');
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function valida_form() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=valida_form.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
	if (val) { nm=val.name; if ((val=val.value)!="") {
	  if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
		if (p<1 || p==(val.length-1)) errors+='O campo '+nm+' precisa ser um e-mail válido.\n';
	  } else if (test!='R') { num = parseFloat(val);
		if (isNaN(val)) errors+='O campo '+nm+' precisa ser um número.\n';
		if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
		  min=test.substring(8,p); max=test.substring(p+1);
		  if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
	} } } else if (test.charAt(0) == 'R') errors += 'O campo '+nm+' é obrigatório.\n'; }
  } if (errors) alert('O(s) seguinte(s) erro(s) ocorreu(ram):\n\n'+errors);
  document.VF_returnValue = (errors == '');
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function janela_imagem(arquivo,id) {
	var strValue = window.open(''+arquivo+'?id_midia='+id,'Imagem','scrollbars=no,status=no,location=no,toolbar=no,menubar=no,resizable=yes,height=10,width=10');
}

function janela_video(arquivo,id) {
//	var strValue = window.open(''+arquivo+'?id_midia='+id,'Imagem','scrollbars=no,status=no,location=no,toolbar=no,menubar=no,resizable=no,height=10,width=10');
	var strValue = window.open(''+arquivo+'?id='+id,'Vídeo','scrollbars=no,status=no,location=no,toolbar=no,menubar=no,resizable=no,height=258,width=325');
}

// função de redimencionar as janelas
function redirWindow(){

	ladoTela = (screen.width-document.images['foto'].width+10)/2;
	cimaTela = (screen.height-document.images['foto'].height)/2-50;

	window.resizeTo (document.images['foto'].width + 10, document.images['foto'].height);
	window.moveTo(ladoTela,cimaTela);

}

function abremapa() {
	var strValue = window.open('../homesite/mapa_plaza.html','Mapa','scrollbars=no,status=no,location=no,toolbar=no,menubar=no,resizable=no,height=570,width=570');
}

function redimImagem(){

	var win_w = document.body.offsetWidth;
	var win_h = document.body.offsetHeight;
	var img_w = document.images['foto'].width + 10;
	var img_h = document.images['foto'].height + 10;

	document.images['foto'].width = (win_w - 5);
	document.images['foto'].height = (win_h - 10);

}

function dim_img(x) {
	x.width = x.width / 1.3;
	x.height = x.height;
}

var ieBlink = (document.all)?true:false;
function doBlink(){
	if(ieBlink){
		obj = document.getElementsByTagName('BLINK');
		for(i=0;i<obj.length;i++){
			tag=obj[i];
			tag.style.visibility=(tag.style.visibility=='hidden')?'visible':'hidden';
		}
	}
}

function change_background() {
	document.getElementById("newsletter").contentWindow.document.body.style.backgroundColor = "#CDD2E4";
}

NumeroCampo = 0;
function Add() {
    if(NumeroCampo < 2) {
        NumeroCampo++;
        data = "<span id='campo"+NumeroCampo+"'><input type=\"file\" name=\"file[]\" size=\"33\" /> <input type=\"button\" value=\"Remover\" onclick=\"Delcampo('campo"+NumeroCampo+"')\" /></span>";
        campo = document.getElementById("campos");
        campo.innerHTML = campo.innerHTML + data;
    }    
}

function Delcampo(IDDiv) {
    var d = document.getElementById('campos');
    var olddiv = document.getElementById(IDDiv);
    d.removeChild(olddiv);
    NumeroCampo--;
}

function checkRequired(forma)
	{
		var frm = document.getElementById(forma);
		var num_patt = /^[0-9]{1,9}$/;
		var mail_patt = /^[A-Za-z][\w-\.]*\@[A-Za-z0-9]+(\.[\w-]+)*\.[A-Za-z]{2,3}$/;

		var fields = ['nome01', 'email01', 'telefone01'];

		for(var i=0; i<fields.length; i++)
		{
			if (frm[fields[i]].value == '')
			{
				alert ('Todos os campos com * devem ser preenchidos');
				frm[fields[i]].focus();
				return false;
			}
		}

		if (!mail_patt.test(frm['email01'].value)) {
				alert ('E-mail inválido');
				frm['email01'].focus();
				return false;
		}


		return true;
	}