function retornomail(m){
	if(m!=''){
		alert(m);
		document.getElementById('email').value='';
		document.getElementById('email').focus();
	}
}
function efetua_login(frm){
	if((frm.email.value)&&(frm.senha.value)){
		x_autentica(frm.email.value,frm.senha.value,'login',retornoLogin);
	}
	else{
		alert('Por favor, preecha seu e-mail e senha!');
		frm.email.focus();
	}
}
function efetua_login_esc(frm){
	if(frm.senha.value){
		x_autenticaEscola(frm.id_escola.value,frm.senha.value,'login','');
		return true;
	}
	else{
		alert('Por favor, preecha a senha!');
		frm.senha.focus();
		return false;
	}
}

function retornoLogin(ret){
	if(ret['st']=='N'){
		alert(ret['msg']);
	}
	else{
		document.getElementById('divLogin').innerHTML=ret['painel'];
	}
}

function SomenteNumero(e){
    var tecla=(window.event)?event.keyCode:e.which;
    if((tecla > 47 && tecla < 58)) return true;
    else{
    if (tecla != 8) return false;
    else return true;
    }
}

function campo_obri(frm,arr_campos,arr_linhas){
	for (c=0; c<arr_campos.length; c++){
		campo	= arr_campos[c];
		linha		= arr_linhas[c];
		if ((!eval('frm.'+campo+'.value'))||(eval('frm.'+campo+'.value')==" ")){
			document.getElementById(linha).bgColor="#cccccc";
			eval('frm.'+campo+'.focus()');
			return false;
		}
		else {
			document.getElementById(linha).bgColor="";
		}
	}
}

function veremail(obj, email){
	if (email){
		reemail=/^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
		if (reemail.test(email)) {
			return true;
		}
		else {
			alert(email + " NÃO é um endereço de e-mail válido.");
			obj.focus();
			return false;
		}
	}
}
function mudacor(obj, cor){
	obj.bgColor=cor;
}
function selcampo(obj, cor){
	obj.style.background=cor;
}
function masc_data(objeto,data) 
{ 
    var mydata = ''; 
    mydata = mydata + data; 
    if (mydata.length == 2) { 
        mydata = mydata + '/'; 
		objeto.value = mydata; 
    } 
	if (mydata.length == 5) { 
        mydata = mydata + '/'; 
		objeto.value = mydata; 
    } 
}

function masc_cep(objeto,cep) 
{ 
    var mycep = ''; 
    mycep = mycep + cep; 
    if (mycep.length == 5) { 
        mycep = mycep + '-'; 
		objeto.value = mycep; 
    } 
}


function confsenha(frm){
	if (frm.senha.value){
		if (frm.senha.value!=frm.csenha.value){
			alert('Confirmação de senha inválida, tente novamente');
			frm.senha.value='';
			frm.csenha.value='';
			frm.senha.focus();
			return false;
		}
	}
}

function elimina_virgula(obj, valor){	
	obj.value = valor.replace(',','.');
}

function formataTelefone(campo, e) {
	t = typeof window.event != "undefined" ? window.event.keyCode : e.which;
	if((isNaN(String.fromCharCode(t)) || (t == 32)) && (t != 8 && t != 0)){
		return false;
	}
	campo = typeof(campo) == "object" ? campo : document.getElementById(campo);
	if(campo.value.charAt(0) != "(" && !isNaN(String.fromCharCode(t)))
		campo.value = "("+campo.value;
	if( typeof window.event != "undefined" ) {
		if(window.event.keyCode != 40) {
			if(campo.value.length == 0) {
				campo.value += '(';
			}
		}
		if(window.event.keyCode != 41) {
			if(campo.value.length == 3) {
				campo.value += ')';
			}
		}
		if(window.event.keyCode != 45) {
			if(campo.value.length == 8) {
				campo.value += '-';
			}
		}
	} else {
		if (e.which != 8) {
			if(e.which != 0) {
				if(e.which != 40) {
					if(campo.value.length == 0) {
						campo.value += '(';
					}
				}
			}
			if(e.which != 41) {
				if(campo.value.length == 3) {
					campo.value += ')';
				}
			}
			if(e.which != 45) {
				if(campo.value.length == 8) {
					campo.value += '-';
				}
			}
		}
	}
}

/**
  * Formata a digitação do CEP
  * @param campo String campo que será atualizado
  * @param e event evento
  * @return void
  **/
function formataCep(campo, e) {
	t = typeof window.event != "undefined" ? window.event.keyCode : e.which;
	if((isNaN(String.fromCharCode(t)) || (t == 32)) && (t != 8 && t != 0)) {
		return false;
	}
	if( typeof window.event != "undefined" ) {
		if (window.event.keyCode != 45) {
			if (campo.value.length == 5) {
				campo.value += '-';
			}
		}
	} else {
		if (e.which != 8) {
			if (e.which != 45) {
				if (campo.value.length == 5) {
					campo.value += '-';
				}
			}
		}
	}
}
function verNum(myfield, e, dec) {
  var key;
  var keychar;

  if (window.event)
    key = window.event.keyCode;
  else if (e)
    key = e.which;
  else
    return true;
  keychar = String.fromCharCode(key);

  // control keys
  if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
    return true;

  // numbers
  else if ((("0123456789").indexOf(keychar) > -1))
    return true;

  // decimal point jump
  else if (dec && (keychar == ".")) {
    myfield.form.elements[dec].focus();
    return false;
  } else
    return false;
}