var verificaData = function(data) {

	var dia = (data.substring(0,2));
	var mes = (data.substring(3,5));
	var ano = (data.substring(6,10));
	
	var situacao = "";
	
	// verifica o dia valido para cada mes
	if ((dia < '01')||(dia < '01' || dia > '30') && (  mes == '04' || mes == '06' || mes == '09' || mes == '11' ) || dia > '31') {
		return false;
	}
	
	// verifica se o mes e valido
	if (mes < '01' || mes > '12' ) {
	    return false;
	}
	
	// verifica se e ano bissexto
	if (mes == 2 && ( dia < 01 || dia > 29 || ( dia > 28 && (parseInt(ano / 4) != ano / 4)))) {
		return false;
	}
	
	if (data == "") {
		return false;
	}
	
	return true;
};

var mascaraCampo = function(campo,masc) {
	
	var i,j,sResult='';
	var sValor = campo.value;
	var sSemMask = soNumeros(tiraMascara(sValor));
	
	if (masc != null) 
	{
		j = 0;
		
		for (i=0;i<masc.length;i++)
		{
			if (masc.charAt(i) != "#")
			{
				sResult += masc.charAt(i);
			}
			else 
			{
				sResult += sSemMask.charAt(j);
				if (j >= sSemMask.length-1)
				{
					break;
				}
				else
				{
					j++;
				}
			}
		}
	}
	else
	{
		sResult = sValor;
	}
	
	if (trim(sResult) != "")
	{
		campo.value = sResult;
	}
	else
	{
		campo.value = '';
	}
};

var tiraMascara = function(sValor) {

	var sMASKS = " -\\/._,";
	var cChar, i;
	var sResult="";
	
	for (i = 0; i < sValor.length; i++)
	{
		cChar = sValor.charAt(i);
		
		if (sMASKS.indexOf(cChar) == -1)
		{
			sResult += cChar;
		}
	}
	
	return sResult;
};

var soNumeros = function(sValor) {
	
	var sResult = '', i;
	var sNUMS = "0123456789";
	
	for (i = 0; i < sValor.length; i++)
	{
		if (sNUMS.indexOf(sValor.charAt(i)) > -1)
		{
			sResult += sValor.charAt(i);
		}
	}
	return sResult;
};

var soNumero = function(e) {

	if (window.Event) {
		if ((e.which < 48 && e.which != 8 && e.which != 0 && e.which !=13 && e.which != 44) || (e.which > 57)) {
			return false;
		}
	} else {
 		if ((event.keyCode < 48 && event.keyCode != 8 && event.keyCode != 0 && event.keyCode != 13 && event.keyCode != 44) || (event.keyCode > 57)) {
			event.keyCode=0;
		}
	}
};

var trim = function(str) {
	return str.replace(/^\s*|\s*$/g,"");
};

var validarLogin = function() {
	
	var login		= document.getElementById('login');
	var senha		= document.getElementById('senha');
	var textoErro	= " Digite ";
	var erro		= false;
	
	if (login.value == "") {
		erro = true;
		textoErro = textoErro+"o Login";
	}
	
	if (senha.value == "") {
		if (erro) {
			textoErro = textoErro+" e a Senha";
		} else {
			erro = true;
			textoErro = textoErro+"a Senha";
		}
	}
	
	if (erro) {
		alert(textoErro+"!");
		return false;
	}
	
	document.getElementById('form').method = 'post';
	document.getElementById('form').action = 'logar.php';
	document.getElementById('form').submit();
};

var validarLoginSite = function() {
	
	var login		= document.getElementById('login');
	var senha		= document.getElementById('senha');
	var textoErro	= " Digite ";
	var erro		= false;
	
	if (login.value == "") {
		erro = true;
		textoErro = textoErro+"o Login";
	}
	
	if (senha.value == "") {
		if (erro) {
			textoErro = textoErro+" e a Senha";
		} else {
			erro = true;
			textoErro = textoErro+"a Senha";
		}
	}
	
	if (erro) {
		alert(textoErro+"!");
		return false;
	}
	
	document.getElementById('form').method = 'post';
	document.getElementById('form').target = '_blank';
	document.getElementById('form').action = 'restrito/logar.php';
	document.getElementById('form').submit();
};

var paginar = function(pagina) {
	var div = 'conteudo_admin';
	var parametros = 'pagina='+pagina+'&'+$('frm').serialize();
	Utilidades.makeAjax('usuarios.grid.php', div, parametros, true);
};

var carregaPagina = function(pagina) {
	var parametros = '';
	Utilidades.makeAjax(pagina, 'paginas_ambiente', parametros, true);
};

var check = false;

// Versão Criada JS
var marcarTodos = function(){
	if(check == false){
		for (i=0;i<document.frm.elements.length;i++){
			if(document.frm.elements[i].type == "checkbox"){
				document.frm.elements[i].checked=1
				check = true
			}
		}
	}
	else{
		desmarcarTodos()
		check = false
	}
};

var desmarcarTodos = function(){
	for (i=0;i<document.frm.elements.length;i++)
			if(document.frm.elements[i].type == "checkbox")
				document.frm.elements[i].checked=0
};

var marcarTodasChecksBoxes = function(idform,nameCheck,retorno){
	$(idform).getInputs('checkbox',nameCheck).each(function (elemento, indice){ elemento.checked=retorno; });
};

function verifica_data (data) 
{
    dia = (data.substring(0,2));
    mes = (data.substring(3,5));
    ano = (data.substring(6,10));

    situacao = "";
    // verifica o dia valido para cada mes
    if ((dia < '01')||(dia < '01' || dia > '30') && (  mes == '04' || mes == '06' || mes == '09' || mes == '11' ) || dia > '31') {
        return false;
    }

    // verifica se o mes e valido
    if (mes < '01' || mes > '12' ) {
        return false;
    }

    // verifica se e ano bissexto
    if (mes == 2 && ( dia < 01 || dia > 29 || ( dia > 28 && (parseInt(ano / 4) != ano / 4)))) {
        return false;
    }

    if (data == "") {
       return false;
    }
    return true;
    /*if (situacao == "falsa") {
        document.forms[0].data.focus();
    }*/
};

var PaginarAjax = function(pagina, arquivo, param, div) {
	
	if (param=='' || param == null) {
		var parametros = 'optTela=montaGrid&pagina='+pagina;
		var div = 'divGrid_'+arquivo;
	} else {
		var parametros = param+'&pagina='+pagina;
		var div = 'divGrid_'+div;
	}
	
	Utilidades.makeAjax(arquivo+'.grid.php', div, parametros, true);
};

var mostraCampo = function(campo, codigo) {
	if (campo == 1) {
		if (codigo == 3) {
			$('idTextoVaga').show();
		} else {
			$('idTextoVaga').hide();
		}
	}
};

var confirmaFormularioVaga = function(arquivo, div)
{
	$('id_botoes').hide();
	var parametros = 'optTela=cadastraVaga&'+$('frm').serialize();
	Utilidades.makeAjax(arquivo, div, parametros, true);
};

var buscaVagaSite = function()
{
	if ($F('pesquisa') != "" && $F('pesquisa') != null) {
		$('form_busca').submit();
	} else {
		$('pesquisa').focus();
	}
};

var redireciona = function(pagina) {
	window.location = pagina;
};

var escolhe_cadastro = function() {
	return MensagemPrototype.msgcadastro('Escolha o tipo de cadastro','redireciona(\'cadastro_empresa.php\')','redireciona(\'cadastro.php\')');
};
