var movieName = "em";

function thisMovie(movieName) {
    if (navigator.appName.indexOf ("Microsoft") !=-1)
    {
        return window[movieName]
      }
    else
    {
        return document[movieName]
    }
}
var ultimo=0;
function mudaclasse(i){
	document.getElementById(i).className="selecionado";
	document.getElementById('d'+i).className="selecionado";
	document.getElementById(ultimo).className="";
	document.getElementById('d'+ultimo).className="";
	ultimo=i;
	
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Formato de e-mail inválido")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Formato de e-mail inválido")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Formato de e-mail inválido")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Formato de e-mail inválido")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Formato de e-mail inválido")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Formato de e-mail inválido")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Formato de e-mail inválido")
		    return false
		 }

 		 return true					
	}


 
function cursorMapa(posx,posy,dest_nome) {
    thisMovie(movieName).SetVariable("posx",posx);   
    thisMovie(movieName).SetVariable("posy",posy);   
    thisMovie(movieName).SetVariable("destinonome",dest_nome);  
    return;
}
function alte_senha() {
	document.getElementById("alterar_senha").style.display = "block";
	document.getElementById("logado").style.display = "none";
}
function alte_dados() {
	document.getElementById("alterar_dados").style.display = "block";
	document.getElementById("logado").style.display = "none";
}
function salv (){
	alert("Salvo com sucesso!");
	document.getElementById("alterar_senha").style.display = "none";
	document.getElementById("alterar_dados").style.display = "none";
	document.getElementById("logado").style.display = "block";
}
function cancel (){
	document.getElementById("alterar_senha").style.display = "none";
	document.getElementById("alterar_dados").style.display = "none";
	document.getElementById("logado").style.display = "block";
}
function enviaform(frm,novo){
	var f = document.forms[frm];
	if (validar(frm,novo)){
	
		f.submit();
	}
}
function enviafoto(frm,foto){
	
	var f = document.forms[frm];
	var x = f.pk_foto.value;
	if (x!=""){
	document.getElementById(x).style.display="none";
	}
	document.getElementById('envie_cartao').style.display="block";
	document.getElementById(foto).style.display="block";
	f.pk_foto.value=foto;
	
}
function mandaresposta(){
		var f = document.forms['enquete'];
		var resposta="";
		for (i=0; i<f.resp_enq.length; i++) {
				if (f.resp_enq[i].checked) {
					marcado = i;
					resposta = f.resp_enq[i].value;
				}
			}
		for (i=0; i<f.resp_enq.length; i++) {
				f.resp_enq[i].checked=false;
		}
		return resposta;
}
function pegaposicao(posx,posy){
	document.alteradestino.X.value = posx;
	document.alteradestino.Y.value = posy;
}

function openAsk(mypage, myname, w, h)
{
		var winl = [(screen.width - w) / 2]- 6;
		var wint = [((screen.height)- h) / 2]- 40;
		var winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=auto,resizable=no,menubar=no'
		var win = window.open(mypage, myname, winprops)
		if (parseInt(navigator.appVersion) >= 4) {win.window.focus();}
}

function validar(frm,novo){
	var f = document.forms[frm];	
	switch (frm){
		case 'alterasenha':
			if (f.senha_atual.value==""){
				alert('Entre com a sua senha');
				f.senha_atual.focus();
				return false;
			}
			if (f.nova_senha.value==""){
				alert('Entre com a Nova Senha');
				f.nova_senha.focus();
				return false;
			}
			if (f.confirma_nova_senha.value==""){
				alert('Entre com a Confirmação da Nova Senha');
				f.confirma_nova_senha.focus();
				return false;
			}
			if (f.nova_senha.value==f.senha_atual.value){
				alert('A sua nova senha deve ser diferente da senha atual');
				f.nova_senha.value="";
				f.nova_senha.focus();
				return false;
			}
			if (f.nova_senha.value!=f.confirma_nova_senha.value){
				alert('A confirmação da nova senha não confere com a nova senha');
				f.nova_senha.value="";
				f.confirma_nova_senha.value="";
				f.nova_senha.focus();
				return false;
			}
			break;
		case 'alterapromocao':
			if (f.titulo.value==""){
				alert('Entre com o Título');
				f.titulo.focus();
				return false;
			}
			if (f.destino.value==""){
				alert('Entre com o Destino');
				f.destino.focus();
				return false;
			}
			if (f.periodo.value==""){
				alert('Entre com o Periodo');
				f.periodo.focus();
				return false;
			}
			if (f.valor.value==""){
				alert('Entre com o Valor');
				f.valor.focus();
				return false;
			}
			if (f.texto.value==""){
				alert('Entre com o Texto');
				f.texto.focus();
				return false;
			}
			
			break;
		case 'enviacartao':
			if (f.pk_foto.value==""){
				alert('Escolha uma Picture para enviar');
				return false;
			}
			if (f.in_nome.value==""){
				alert('Entre com o seu nome');
				f.in_nome.focus();
				return false;
			}
			
			if (f.in_email.value==""){
				alert('Entre com o seu email');
				f.in_email.focus();
				return false;
			}
			if (echeck(f.in_email.value)==false){
				f.in_email.value=""
				f.in_email.focus()
				return false
			}
			if (f.in_amigo.value==""){
				alert('Entre com o nome do seu amigo');
				f.in_amigo.focus();
				return false;
			}
			if (f.in_email_amigo.value==""){
				alert('Entre com o email do seu amigo');
				f.in_email_amigo.focus();
				return false;
			}
			if (echeck(f.in_email_amigo.value)==false){
				f.in_email_amigo.value=""
				f.in_email_amigo.focus()
				return false
			}
			if (f.mensagem.value==""){
				alert('Entre com a Mensagem');
				f.texto.focus();
				return false;
			}
			
			
			break;
		case 'indique':
			if (f.in_nome.value==""){
				alert('Entre com o seu nome');
				f.in_nome.focus();
				return false;
			}
			if (f.in_email.value==""){
				alert('Entre com o seu email');
				f.in_email.focus();
				return false;
			}
			if (echeck(f.in_email.value)==false){
				f.in_email.value=""
				f.in_email.focus()
				return false
			}
			if (f.in_amigo.value==""){
				alert('Entre com o nome do seu amigo');
				f.in_amigo.focus();
				return false;
			}
			if (f.in_email_amigo.value==""){
				alert('Entre com o email do seu amigo');
				f.in_email_amigo.focus();
				return false;
			}
			if (echeck(f.in_email_amigo.value)==false){
				f.in_email_amigo.value=""
				f.in_email_amigo.focus()
				return false
			}
			break;
		case 'contato':
			if (f.nome.value==""){
				alert('Entre com o seu nome');
				f.nome.focus();
				return false;
			}
			if (f.email.value==""){
				alert('Entre com o seu email');
				f.email.focus();
				return false;
			}
			if (echeck(f.email.value)==false){
				f.email.value=""
				f.email.focus()
				return false
			}
			if (f.telefone.value==""){
				alert('Entre com o seu telefone');
				f.telefone.focus();
				return false;
			}
			if (f.mensagem.value==""){
				alert('Entre com a sua mensagem');
				f.mensagem.focus();
				return false;
			}
			break;
		case 'cadastranews':
			if (f.nome.value==""){
				alert('Entre com o seu nome');
				f.nome.focus();
				return false;
			}
			if (f.email.value==""){
				alert('Entre com o seu email');
				f.email.focus();
				return false;
			}
			if (echeck(f.email.value)==false){
				f.email.value=""
				f.email.focus()
				return false
			}
			if (f.cidade.value==""){
				alert('Entre com a sua Cidade');
				f.cidade.focus();
				return false;
			}
			if (f.estado.value==""){
				alert('Selecione o estado');
				f.estado.focus();
				return false;
			}
			marcado = -1;
			for (i=0; i<f.tempo_surf.length; i++) {
				if (f.tempo_surf[i].checked) {
					marcado = i;
					resposta = f.tempo_surf[i].value;
				}
			}
			if (marcado == -1) {
				alert("Selecione o tempo de surf.");
				f.tempo_surf.focus();
				return false;
			}	
			if (f.idade.value==""){
				alert('Entre com a sua idade');
				f.idade.focus();
				return false;
			}
			marcado = -1;
			for (i=0; i<f.surf_fora.length; i++) {
				if (f.surf_fora[i].checked) {
					marcado = i;
					resposta_surf = f.surf_fora[i].value;
				}
			}
			if (marcado == -1) {
				alert("Selecione o se já surfou fora do Brasil ou não.");
				f.surf_fora.focus();
				return false;
			}	
			if (resposta_surf=='1'){
				if (f.aonde.value==""){
					alert("Entre com o local aonde surfou");
					f.aonde.focus();
					return false;
				}
			}
			marcado = -1;
			for (i=0; i<f.cliente.length; i++) {
				if (f.cliente[i].checked) {
					marcado = i;
					resposta = f.cliente[i].value;
				}
			}
			if (marcado == -1) {
				alert("Selecione o se é cliente SurfTravel ou não.");
				f.cliente.focus();
				return false;
			}
			break;
		case 'envia_mail':
			marcado = -1;
			for (i=0; i<f.layout.length; i++) {
				if (f.layout[i].checked) {
					marcado = i;
					resposta = f.cliente[i].value;
				}
			}
			if (marcado == -1) {
				alert("Selecione o tipo de Layout.");
				f.layout.focus();
				return false;
			}	
			if (f.assunto.value==""){
				alert('Entre com o Assunto');
				f.assunto.focus();
				return false;
			}
			if (f.mensagem.value==""){
				alert('Entre com a Mensagem');
				f.mensagem.focus();
				return false;
			}
			marcado = -1;
			for (i=0; i<=4; i++) {
				if (document.getElementById('filtro'+i).checked==true) {
					marcado = i;
					//resposta = f.cliente[i].value;
				}
			}
			if (marcado == -1) {
				alert("Selecione pelo menos um dos filtros");
				return false;
			}
			if 	(document.getElementById('filtro1').checked==true){
				if (document.getElementById('idade_inicio').value=="" && document.getElementById('idade_fim').value==""){
					alert("Entre com a idade mínima ou com a idade máxima de envio");
					f.idade_inicio.focus();
					return false;
				}
			}
			if 	(document.getElementById('filtro2').checked==true){
				marcado = -1;
				for (i=0; i<f.viagem_fora.length; i++) {
					if (f.viagem_fora[i].checked) {
						marcado = i;
						resposta = f.viagem_fora[i].value;
					}
				}
				if (marcado == -1) {
					alert("Selecione uma opção do filtro de Viagem.");
					f.viagem_fora.focus();
					return false;
				}
			}
			if 	(document.getElementById('filtro3').checked==true){
				marcado = -1;
				for (i=1; i<=4; i++) {
					if (document.getElementById('tempo_'+i).checked==true) {
						marcado = i;
						//resposta = f.viagem_fora[i].value;
					}
				}
				if (marcado == -1) {
					alert("Selecione uma opção do tempo de surf.");
					f.tempo_1.focus();
					return false;
				}
			}
			if 	(document.getElementById('filtro4').checked==true){
				marcado = -1;
				for (i=0; i<f.cliente.length; i++) {
					if (f.cliente[i].checked) {
						marcado = i;
						resposta = f.cliente[i].value;
					}
				}
				if (marcado == -1) {
					alert("Selecione uma opção do filtro 'É cliente surftravel?'.");
					f.cliente.focus();
					return false;
				}
			}
			break;
		case 'alteradestino':
			if (f.nome.value==""){
				alert('Entre com o nome do destino');
				f.nome.focus();
				return false;
			}
			if (f.X.value=="" || f.Y.value==""){
				alert('Selecione a localidade no mapa mundi');
				return false;
			}
			break;	
		case 'altsenha':
			if (f.senha_atual.value==""){
				alert('Entre com a sua senha');
				f.senha_atual.focus();
				return false;
			}
			if (f.senha_nova.value==""){
				alert('Entre com a Nova Senha');
				f.senha_nova.focus();
				return false;
			}
			if (f.confirm_senha_nova.value==""){
				alert('Entre com a Confirmação da Nova Senha');
				f.confirm_senha_nova.focus();
				return false;
			}
			break;
		case 'altusuario':
			if (f.nome.value==""){
				alert('Entre com o Nome');
				f.nome.focus();
				return false;
			}
			if (f.email.value==""){
				alert('Entre com o E-mail');
				f.email.focus();
				return false;
			}
			if (f.cidade.value==""){
				alert('Entre com a Cidade');
				f.cidade.focus();
				return false;
			}
			if (f.estado.value==""){
				alert('Selecione o estado');
				f.estado.focus();
				return false;
			}	
			if (f.cidade.value==""){
				alert('Entre com a Cidade');
				f.cidade.focus();
				return false;
			}
			marcado = -1;
			for (i=0; i<f.cliente.length; i++) {
				if (f.cliente[i].checked) {
					marcado = i;
					resposta = f.cliente[i].value;
				}
			}
			if (marcado == -1) {
				alert("Selecione se é cliente Surf Travel ou não.");
				f.cliente.focus();
				return false;
			}	
			marcado = -1;
			for (i=0; i<f.tempo_surf.length; i++) {
				if (f.tempo_surf[i].checked) {
					marcado = i;
					resposta = f.tempo_surf[i].value;
				}
			}
			if (marcado == -1) {
				alert("Selecione o Tempo de Surf.");
				f.tempo_surf.focus();
				return false;
			}
			if (f.idade.value==""){
				alert('Entre com a Idade');
				f.idade.focus();
				return false;
			}
			marcado = -1;
			for (i=0; i<f.surf_fora.length; i++) {
				if (f.surf_fora[i].checked) {
					marcado = i;
					resposta = f.surf_fora[i].value;
				}
			}
			if (marcado == -1) {
				alert("Selecione se Já Surfou Fora do Brasil.");
				f.surf_fora.focus();
				return false;
			}
			if (f.surf_fora[0].checked==true && f.aonde.value==""){
				alert('Entre com o local aonde já Surfou');
				f.aonde.focus();
				return false;
			}
			break;
		case 'gera_rel':
			if (f.status.value==""){
				alert('Selecione o status do pedido');
				f.senha_atual.focus();
				return false;
			}
			break;
	
		case 'excluir':
			continuar = 0;
			for (i=0; i<f.elements.length; i++) {
				campo = f.elements[i];
				if (campo.name.substr(0, 7) == "excluir") {
					if (campo.checked) continuar = 1;
				}
			}
	
			if (continuar == 0) {
				alert ("Selecione pelo menos um registro a ser excluído.");
				return false;
			}else {
				del = confirm('Você deseja excluir esse cadastro?');
				if (del==false){
  					return false;
				}
			}
			break;
		case 'enviedepoimento':
			if( $('nome').value == "") 									{alert('Digite seu nome'); 												$('nome').focus(); 			return false;}
			if( !is_numeric($('idade').value)) 									{alert('Digite corretamente sua idade'); 		$('idade').value=""; 	$('idade').focus();			return false;}
			if( $('cidade').value == "") 										{alert('Digite corretamente sua cidade');								$('cidade').focus(); 		return false;}
			if( $('texto').value == "") 										{alert('Digite corretamente seu depoimento');							$('texto').focus(); 		return false;}
			if( !isRadioChecked('cliente')) 									{alert('Você é um cliente stc?');							 										return false;}
			if( ( !is_numeric(valueCombo('destino')) ) && ( $('outros').value.length == 0))	{alert('Para onde você viajou?');										$('destino').focus();		return false;}
			break;
			
	}
		
	return true;
}

function $(el){
	if( document.getElementById(el) )
		return document.getElementById(el);
	else
		alert('Elemento '+el+' não encontrado');
}

function is_numeric(valor){
	newValor = parseInt(valor);
	if(!isNaN(newValor)) return true;
	else return false;	
}
function valueCombo(combo){
	if( $(combo).selectedIndex == -1 )	return false;
	else return	$(combo).options[$(combo).selectedIndex].value;	
}
function isRadioChecked(radio){
	var form = document.forms[1];
	for (i=0;i<form.elements.length;i++)
		if (form.elements[i].type == "radio")
			if (form.elements[i].checked)
				return true;
	return false;
}


