// JavaScript Document
var h_dayarray   = new Array("Domingo","Segunda","Ter&ccedil;a","Quarta","Quinta","Sexta","S&aacute;bado");
var h_montharray = new Array("Janeiro","Fevereiro","Mar&ccedil;o","Abril","Maio","Junho","Julho","Agosto","Setembro","Outubro","Novembro","Dezembro");
function getClockDate() {
	var h_date    = new Date();
	var h_year    = h_date.getYear();
	var h_day     = h_date.getDay();
	var h_month   = h_date.getMonth();
	var h_numday  = h_date.getDate();
	var h_hours   = h_date.getHours();
	var h_minutes = h_date.getMinutes();
	var h_seconds = h_date.getSeconds();
	var dn_dn;
	if (h_year < 2000) { h_year = "19" + h_year; }
	if (h_hours > 12) { dn_dn = "PM"; h_hours = h_hours - 12; } else { dn_dn = "AM"; }
	if (h_hours == 0) { h_hours = 12; }
	if (h_minutes <= 9) { h_minutes = "0" + h_minutes; }
	if (h_seconds <= 9) { h_seconds = "0" + h_seconds; }
	document.all["dateObject"].innerHTML = h_dayarray[h_day] + ",&nbsp;dia&nbsp;" + h_numday + " de "+ h_montharray[h_month] + ",&nbsp;" + h_year;
	document.all["tempoObject"].innerHTML = "&nbsp;&nbsp;" + h_hours + ":" + h_minutes + ":" + h_seconds + "&nbsp;" + dn_dn;
}

function jump(qtd, de, para){
	if (de.length >= qtd){
		para.focus();
	}
}

function init() {
    getClockDate();
    setInterval("getClockDate()", 1000);  
}
function pagina(campo){
	location.href='menu.asp?button=' + campo;
}
function abre_janela(width, height, nome) {
var top; var left;
top = ( (screen.height/2) - (height/2) )
left = ( (screen.width/2) - (width/2) )
window.open('',nome,'width='+width+',height='+height+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,left='+left+',top='+top);
window.opener=window;
window.close();
}
function recebe_imagem(campo, imagem){
	var foto = 'img_' + campo
	document.form_incluir[campo].value = imagem;
	document.form_incluir[foto].src = imagem;
}
function recebe_video(campo, imagem){
	document.form_incluir[campo].value = imagem;
}
function confirm_delete(form, action_del) {
  if (confirm("Tem certeza que deseja excluir o registro?")) {
	document[form].action = action_del;
	document[form].submit();
  }
}


function Valida_Form(form) {
var passed = false;
var ok = false
var campo
for (i = 0; i < form.length; i++) {
  campo = form[i].name;
  if (form[campo].id == "obrigatorio") {
	if (form[i].type == "text"  || form[i].type == "textarea" || form[i].type == "select-one") {
      if (form[i].value == "") {
		form[campo].className='Alerta'
        form[campo].focus();
		document.getElementById('alert_fields').innerHTML = form[i].alt //"incorrectly format!"
//        alert("Fill the field "+ form[i].alt +" correctly!");
        return passed;
        stop;
      }
    }else if (form[i].type == "radio") {
      for (x = 0; x < form[campo].length; x++) {
        ok = false;
        if (form[campo][x].checked) {
          ok = true;
          break;
        }
      }
      if (ok == false) {
  		alert("Informe uma das opcões");
        return passed;
        stop;
      }
    }else if (form[i].type == "checkbox" && form[i].name == "terms") {
		if (form[i].checked == false) {
			document.getElementById('alert_fields').innerHTML = form[i].alt
//			alert("Agree to the terms of the website !");
			return passed;
			stop;
        }
    }
	
    var msg = ""
	if (form[campo].title == "Data") msg = Valida_data(form[campo].value);
    if (form[campo].title == "E-mail") msg = Valida_email(form[campo].value);
    if (form[campo].title == "Número") msg = Valida_numerico(form[campo].value);
	if (form[campo].title == "CPF") msg = Valida_cpf(form[campo].value);
    if (form[campo].title == "CNPJ") msg = Valida_cnpj(form[campo].value);
    if (form[campo].title == "CPF_CNPJ") {
	  msg = Valida_cpf(form[campo].value);
	  if (msg != "") msg = Valida_cnpj(form[campo].value);
	}
    if (msg != "") {
	  if (form[campo].title == "CPF_CNPJ") msg = "informe corretamente o número do CPF ou CNPJ";
	  form[campo].className='Alerta'
      form[campo].focus();
      form[campo].select();
	  document.getElementById('alert_fields').innerHTML = msg
//      alert(msg);
      return passed;
      stop;
    }
  }
}
passed = true;
return passed;
}
function desabilitar(campo) {
	campo.className='Formulario';
	document.getElementById('alert_fields').innerHTML = ''
}
function Mascara(src, mask){
	var len = src.value.length;
	var saida = mask.substring(0,1);
	var texto = mask.substring(len);
	if (texto.substring(0,1) != saida){src.value += texto.substring(0,1)};
	if (len>=mask.length) {src.value=src.value.substring(0,mask.length)};
}

function Valida_numerico(String) {
	var mensagem = "Somente números!"
	var msg = "";
	if (isNaN(String)) msg = mensagem;
	return msg;
}
function Valida_email(campo) {
	var mensagem = "Please correct the email!"
	var msg = "";
	var email = campo.match(/(\w+)@(.+)\.(\w+)$/);
	if (email == null){msg = mensagem}
	return msg;
}

function Valida_data(data) { 
	var mensagem = "Please correct the birth date!";
	var msg = "";
	
	mes = (data.substring(0,2));
	dia = (data.substring(3,5));
	ano = (data.substring(6,10));
	
	val = 0;
	if (parseInt(data.length)<10){val = 1}else{
		if ((dia < 01) || (dia < 01 || dia > 30) && (  mes == 04 || mes == 06 || mes == 09 || mes == 11 ) || dia > 31) val = 1;
		if (mes < 01 || mes > 12 ) val = 1;
		if (mes == 2 && ( dia < 01 || dia > 29 || ( dia > 28 && (parseInt(ano / 4) != ano / 4)))) val = 1;
	}
	if (val == 1) msg = mensagem;
	return msg;
}

function Valida_cpf(Objcpf) {
	var mensagem = "informe corretamente o número do CPF!"
	var msg = "";
    var cpf = Objcpf;
    exp = /\.|\-/g
    cpf = cpf.toString().replace( exp, "" ); 
    var digitoDigitado = eval(cpf.charAt(9)+cpf.charAt(10));
    var soma1=0, soma2=0;
    var vlr =11;
    for(i=0;i<9;i++){
        soma1+=eval(cpf.charAt(i)*(vlr-1));
        soma2+=eval(cpf.charAt(i)*vlr);
        vlr--;
    }    
    soma1 = (((soma1*10)%11)==10 ? 0:((soma1*10)%11));
    soma2=(((soma2+(2*soma1))*10)%11);
    
    var digitoGerado=(soma1*10)+soma2;
    if(digitoGerado!=digitoDigitado){msg = mensagem};
	return msg;
}
function Valida_cnpj(ObjCnpj) {
	var mensagem = "informe corretamente o número do CNPJ!"
	var msg = "";

    var cnpj = ObjCnpj;
    var valida = new Array(6,5,4,3,2,9,8,7,6,5,4,3,2);
    var dig1= new Number;
    var dig2= new Number;
    exp = /\.|\-|\//g
    cnpj = cnpj.toString().replace( exp, "" ); 
    var digito = new Number(eval(cnpj.charAt(12)+cnpj.charAt(13)));
    for(i = 0; i<valida.length; i++){
        dig1 += (i>0? (cnpj.charAt(i-1)*valida[i]):0);    
        dig2 += cnpj.charAt(i)*valida[i];    
    }
    dig1 = (((dig1%11)<2)? 0:(11-(dig1%11)));
    dig2 = (((dig2%11)<2)? 0:(11-(dig2%11)));
    
    if(((dig1*10)+dig2) != digito){msg = mensagem};
	return msg;
}
function MascaraMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, e){
    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789';
    var aux = aux2 = '';
    var whichCode = (window.Event) ? e.which : e.keyCode;
    if (whichCode == 13) return true;
    key = String.fromCharCode(whichCode); // Valor para o código da Chave
    if (strCheck.indexOf(key) == -1) return false; // Chave inválida
    len = objTextBox.value.length;
    for(i = 0; i < len; i++)
        if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) break;
    aux = '';
    for(; i < len; i++)
        if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i);
    aux += key;
    len = aux.length;
	
    if (len == 0) objTextBox.value = '';
    if (len == 1) objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
    if (len == 2) objTextBox.value = '0'+ SeparadorDecimal + aux;
	if (len > 2 && len < 6) {
		aux2 = '';
		for (j = 0, i = len - 3; i >= 0; i--) {
			if (j == 3) {
				aux2 += SeparadorMilesimo;
				j = 0;
			}
			aux2 += aux.charAt(i);
			j++;
		}
		objTextBox.value = '';
		len2 = aux2.length;
		for (i = len2 - 1; i >= 0; i--)
		objTextBox.value += aux2.charAt(i);
		objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
	}
	return false;
}
<!-- onKeyPress="return(MascaraMoeda(this,'.',',',event))-->

function confirma_email(Form_user){
	alert('Preencha corretamente seu E-mail');	
	/*if 	(document[Form_user].email.value != "" || document[Form_user].confirma_email.value != ""){
		  if (document[Form_user].email.value == document[Form_user].confirma_email.value){
//			  document[Form_user].email.style.background='#86A686';
//			  document[Form_user].confirma_email.style.background='#86A686';
				alert('certo');
		  }else{
//			  document[Form_user].email.style.background='#A68686';
//			  document[Form_user].confirma_email.style.background='#A68686';
				alert('errado');
		  }
	}else{
		alert('Preencha corretamente seu E-mail');	
	}
	*/
}