﻿function validarCadastro() {

//    if ($('txtNome').value.trim() == '' || $('txtNome').value.trim() == 'Usuário') {
//        alert('Informe o Nome');
//        $('txtNome').focus();
//        return false;
//    }

//    if ($('txtEmail').value.trim() == '' || $('txtEmail').value.trim() == 'Senha') {
//        alert('Informe a Senha');
//        $('txtEmail').focus();
//        return false;
//    }

    /*if ((/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test($('txtEmail').value.trim()) == false)) {
        alert("Informe um Email válido");
        $('txtEmail').focus();
        return (false);
    }*/

    return true;
}

function focusNome() {
    if ($('txtNome').value == 'Usuário') {
        $('txtNome').value = '';
        $('txtNome').className = 'input';
    }
}

function blurNome() {
    if ($('txtNome').value == '') {
        $('txtNome').value = 'Usuário';
        $('txtNome').className = 'input infoForm';
    }
}

function focusEmail() {
    if ($('txtEmail').value == 'Senha') {
        $('txtEmail').value = '';
        $('txtEmail').className = 'input';
    }

}

function blurEmail() {
    if ($('txtEmail').value == '') {
        $('txtEmail').value = 'Senha';
        $('txtEmail').className = 'input infoForm';
    }

}

function isCurrentBrowser(browserName){	
	if(navigator.userAgent.search(browserName) != -1)
		return true;
	else
		return false;
}
 

function navHoverAux() {
    var lis = $$('.headerControl_navmenu_h li');
    for (var i = 0; i < lis.length; i++) {
        $(lis[i]).addEvents({
            'mouseover': function() {
                $('map3d').setStyle('top', '-10000px');
                $('lsEstados').setStyle('top','379px');
                $('mapa').setStyle('height', $('map3d').getStyle('height'));
                
            },
            'mouseout': function() {
                $('map3d').setStyle('top', '0px');
                $('mapa').setStyle('height', '0px');
				
				if(isCurrentBrowser("MSIE"))
                	$('lsEstados').setStyle('top', '379px');
				else
					$('lsEstados').setStyle('top', '379px');
            }
        });

        /*lis[i].onmouseover = function() {
            this.className += " iehover";
            
            $('teste').setStyle('top', '-1000px');
        }
        lis[i].onmouseout = function() {
            this.className = this.className.replace(new RegExp(" iehover\\b"), "");
            $('teste').setStyle('top', '0px');
        }*/
    }

}


navHover = function() {
    var lis = document.getElementById("headerControl_navmenu_h").getElementsByTagName("LI");
    for (var i = 0; i < lis.length; i++) {
        lis[i].onmouseover = function() {
            this.className += " iehover";
            
        }
        lis[i].onmouseout = function() {
            this.className = this.className.replace(new RegExp(" iehover\\b"), "");
        }
    }

}
if (window.attachEvent) window.attachEvent("onload", navHover);


function getAddress(){
    $('txtCEP_2').addEvent('blur', function(e) {

	    if ($('txtCEP_1').value.trim() != '' && $('txtCEP_2').value.trim() != '') {
		    var url = 'services/CEP.aspx?cep=' + $('txtCEP_1').value + $('txtCEP_2').value;
		    var request = new Json.Remote(url,
	    {

		    onComplete: function(retorno) {
			    if (retorno.status == 0) {
				    $('txtEndereco').value = retorno.endereco;
				    $('cmbUF').value = retorno.UF;
				    __doPostBack('cmbUF', retorno.cidade)
			    }
			    else
				    alert(retorno.message);

		    } .bind(this)
	    }).send();

	    }
    });
}

function validarCpfCnpj(e, obj) {
	if (!Validador.validarCPF(obj.Value) && !Validador.validarCNPJ(obj.Value)) {
		e.style.display = 'inline';
		e.style.visibility = 'visible';
		return false;
	}
}
 
function validar(opt) {
	if($('txtInstituicao').value =='') {
		alert('Informe o Nome da Instituição');
		$('txtInstituicao').focus();
		return false;
	}
	
	if($('txtNome').value == '') {
		alert('Informe o nome da pessoa física ou jurídica');
		$('txtNome').focus();
		return false;
	}


	if (!Validador.validarCPF($('txtCNPJ').value.trim()) && !Validador.validarCNPJ($('txtCNPJ').value.trim())) {
		alert("Verifique o valor informado para o campo 'CPF/CNPJ'.");
		return false;
	}

	if($('cmbTipoInstituicao').value =='0') {
		alert('Selecione o tipo da instituição');
		$('cmbTipoInstituicao').focus();
		return false;
	}
	
	if($('txtSiglaInstituicao').value == '') {
		alert('Informe a sigla da instituição');
		$('txtNome').focus();
		return false;
	}
	
	if($('txtEmail').value == '') {
		alert('Informe o Email');
		$('txtEmail').focus();
		return false;
	}
	
	if(!RegExp(/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/).test($('txtEmail').value)) {
		alert('O email informado é inválido');
		$('txtEmail').focus();
		return false;
	}
	
	if($('txtCEP_1').value == '') {
		alert('Informe o CEP corretamente');
		$('txtCEP_1').focus();
		return false;
	}
	
	if($('txtCEP_2').value == '') {
		alert('Informe o CEP corretamente');
		$('txtCEP_2').focus();
		return false;
	}
    
	if($('cmbUF').value == '0') {
		alert('Selecione o Estado');
		$('cmbUF').focus();
		return false;
	}
	
	if($('cmbMunicipio').value == '0') {
		alert('Selecione o Município');
		$('cmbMunicipio').focus();
		return false;
	}
	
	if($('txtEndereco').value == '') {
		alert('Informe o Endereço');
		$('txtEndereco').focus();
		return false;
	}
	
	if($('txtNumero').value == '') {
		alert('Informe o Número');
		$('txtNumero').focus();
		return false;
	}
	
	if($('txtDD1').value == '') {
		alert('Informe o DDD do contato');
		$('txtDD1').focus();
		return false;
	}
	
	if($('txtTelefone1').value == '') {
		alert('Informe o telefone do contato');
		$('txtTelefone1').focus();
		return false;
	}
	
	if($('txtContato1').value == '') {
		alert('Informe o nome do contato');
		$('txtContato1').focus();
		return false;
	}
	
	if($('txtEmail1').value == '') {
		alert('Informe o email do contato');
		$('txtEmail1').focus();
		return false;
	}
	
	if
	(
		($('txtTelefone1').value != '' && ($('txtDD1').value == '' || $('txtContato1').value == '' || $('txtEmail1').value == ''))
		||
		($('txtDD1').value != '' && ($('txtTelefone1').value == '' || $('txtContato1').value == '' || $('txtEmail1').value == ''))
		||
		($('txtContato1').value != '' && ($('txtDD1').value == '' || $('txtTelefone1').value == '' || $('txtEmail1').value == ''))
		||
		($('txtEmail1').value != '' && ($('txtDD1').value == '' || $('txtContato1').value == '' || $('txtTelefone1').value == ''))
	) 
		{
			alert('Verifique os dados informados para o primeiro contato.\nÉ necessário que o contato possua um nome, telefone e e-mail.');
			return false;
		}


		if
	(
		($('txtTelefone2').value != '' && ($('txtDD2').value == '' || $('txtContato2').value == '' || $('txtEmail2').value == ''))
		||
		($('txtDD2').value != '' && ($('txtTelefone2').value == '' || $('txtContato2').value == '' || $('txtEmail2').value == ''))
		||
		($('txtContato2').value != '' && ($('txtDD2').value == '' || $('txtTelefone2').value == '' || $('txtEmail2').value == ''))
		||
		($('txtEmail2').value != '' && ($('txtDD2').value == '' || $('txtContato2').value == '' || $('txtTelefone2').value == ''))
	) {
			alert('Verifique os dados informados para o segundo contato.\nÉ necessário que o contato possua um nome, telefone e e-mail.');
			return false;

	}
	
	if($('txtInstituicao').value == '') {
		alert('Informe o Nome da instituição.');
		$('txtInstituicao').focus();
		return false;
	}

	if (opt == true) {
		if ($('rdAceitoProt').checked != true) {
			alert('Concorde com o Protocolo.');
			$('rdAceitoProt').focus();
			return false;
		}
	}
}
