// JavaScript Document
function getNomeImage(f, c1, c2) 
	{
	var ind = eval("document."+f+"."+c1).value.lastIndexOf("\\");
	if (ind == -1)
		return;
	var tam = eval("document."+f+"."+c1).value.length;
	var valor = eval("document."+f+"."+c1).value.substring(ind+1,tam);
	eval("document."+f+"."+c2).value = valor;
	return
	}
	
	function flutuar(){
	if (document.all){
		flutuador.style.pixelTop=document.body.scrollTop+20;
	}else{
		document.all.flutuador.top=window.pageYOffset+5;
	}
	setTimeout("flutuar()",50);
}
	
function submitForm(form) {
document[form].submit();
}

function abreJanela(pagina, nome, w, h, rolagem) {
var winl = (window.screen.availWidth/2)-(w/2);
var wint = (window.screen.availHeight/2)-(h/2)-12;
var winProps = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+rolagem+',resizable=no';
win = window.open(pagina, nome, winProps)
win.window.focus();
}
function openWin(pagina, nome, w, h, rolagem) {
var winl = (window.screen.availWidth/2)-(w/2);
var wint = (window.screen.availHeight/2)-(h/2)-12;
var winProps = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+rolagem+',resizable=no';
win = window.open(pagina, nome, winProps)
win.window.focus();
}


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+',scrollbars=no,toolbar=no,location=no,status=no,menubar=no,resizable=no,left='+left+',top='+top);
}

function fk(tabela,pk,alt,pkaux){
  parent.sobraFrame.location = "checaFk.asp?strTable="+tabela+"&strPk="+pk+"&strAlt="+alt+"&strPkAux="+pkaux;
}

function recebe_imagem(campo, imagem){
var foto = 'img_' + campo
document.form_incluir[campo].value = imagem;
document.form_incluir[foto].src = imagem;
}

function verifica_form(form) {
var passed = false;
var ok = false
var campo
for (i = 0; i < form.length; i++) {
  campo = form[i].name;
  if (form[i].df_verificar == "sim") {
    if (form[i].type == "text"  | form[i].type == "textarea" | form[i].type == "select-one") {
      if (form[i].value == "" | form[i].value == "http://") {
				form[campo].className='campo_alerta'
        form[campo].focus();
        alert("Preencha corretamente o campo");
        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) {
        form[campo][0].focus();
		form[campo][0].select();
        alert("Informe uma das opcões");
        return passed;
        stop;
      }
    }
    var msg = ""
    if (form[campo].df_validar == "cpf") msg = checa_cpf(form[campo].value);
    if (form[campo].df_validar == "cnpj") msg = checa_cnpj(form[campo].value);
    if (form[campo].df_validar == "cpf_cnpj") {
	  msg = checa_cpf(form[campo].value);
	  if (msg != "") msg = checa_cnpj(form[campo].value);
	}
    if (form[campo].df_validar == "email") msg = checa_email(form[campo].value);
    if (form[campo].df_validar == "numerico") msg = checa_numerico(form[campo].value);
    if (msg != "") {
	  if (form[campo].df_validar == "cpf_cnpj") msg = "informe corretamente o número do CPF ou CNPJ";
	  form[campo].className='campo_alerta'
      form[campo].focus();
      form[campo].select();
      alert(msg);
      return passed;
      stop;
    }
  }
}
passed = true;
return passed;
}

function desabilita_cor(campo) {
  campo.className='campo'
}

function checa_numerico(String) {
var mensagem = "Este campo aceita somente números"
var msg = "";
if (isNaN(String)) msg = mensagem;
return msg;
}

function checa_email(campo) {
var mensagem = "Informe corretamente o email"
var msg = "";
var email = campo.match(/(\w+)@(.+)\.(\w+)$/);
if (email == null){
  msg = mensagem;
  }
return msg;
}

function checa_cpf(CPF) {
var mensagem = "informe corretamente o número do CPF"
var msg = "";
if (CPF.length != 11 || CPF == "00000000000" || CPF == "11111111111" ||
  CPF == "22222222222" ||	CPF == "33333333333" || CPF == "44444444444" ||
  CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" ||
  CPF == "88888888888" || CPF == "99999999999")
msg = mensagem;
soma = 0;
for (y=0; y < 9; y ++)
soma += parseInt(CPF.charAt(y)) * (10 - y);
resto = 11 - (soma % 11);
if (resto == 10 || resto == 11)resto = 0;
if (resto != parseInt(CPF.charAt(9)))
  msg = mensagem; soma = 0;
for (y = 0; y < 10; y ++)
  soma += parseInt(CPF.charAt(y)) * (11 - y);
resto = 11 - (soma % 11);
if (resto == 10 || resto == 11) resto = 0;
if (resto != parseInt(CPF.charAt(10)))
  msg = mensagem;
return msg;
}

function checa_cnpj(s) {
var mensagem = "informe corretamente o número do CNPJ"
var msg = "";
var y;
var c = s.substr(0,12);
var dv = s.substr(12,2);
var d1 = 0;
for (y = 0; y < 12; y++)
{
d1 += c.charAt(11-y)*(2+(y % 8));
}
if (d1 == 0) msg = mensagem;
d1 = 11 - (d1 % 11);
if (d1 > 9) d1 = 0;
if (dv.charAt(0) != d1)msg = mensagem;
d1 *= 2;
for (y = 0; y < 12; y++)
{
d1 += c.charAt(11-y)*(2+((y+1) % 8));
}
d1 = 11 - (d1 % 11);
if (d1 > 9) d1 = 0;
if (dv.charAt(1) != d1) msg = mensagem;
return msg;
}

function mascara_data(data){ 
var mydata = ''; 
mydata = mydata + data; 
if (mydata.length == 2){ 
mydata = mydata + '/'; 
} 
if (mydata.length == 5){ 
mydata = mydata + '/'; 
} 
return mydata; 
} 

function verifica_data(data) { 
if (data.value != "") {
dia = (data.value.substring(0,2));
mes = (data.value.substring(3,5)); 
ano = (data.value.substring(6,10)); 
situacao = ""; 
if ((dia < 01)||(dia < 01 || dia > 30) && (  mes == 04 || mes == 06 || mes == 09 || mes == 11 ) || dia > 31) { 
situacao = "falsa"; 
} 
if (mes < 01 || mes > 12 ) { 
situacao = "falsa"; 
}
if (mes == 2 && ( dia < 01 || dia > 29 || ( dia > 28 && (parseInt(ano / 4) != ano / 4)))) { 
situacao = "falsa"; 
} 
if (situacao == "falsa") { 
data.focus();
data.select();
alert("Data inválida!"); 
}
} 
}

function abre_foto(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+',scrollbars=no,toolbar=no,location=no,status=no,menubar=no,resizable=yes,left='+left+',top='+top);
}

function confirm_delete(form,url) {
  if (confirm("Tem certeza que deseja excluir o registro?")) {
	document[form].action = url;
	document[form].submit();
  }
}

function alertConfirmar(msg, vUrl, fUrl) {
	var args = alertConfirmar.arguments;			// numero de argumentos
	var nArgs = alertConfirmar.arguments.length;	// numero de argumentos
	arg1 = (nArgs > 0) ? args[0] : null;
	arg2 = (nArgs > 1) ? args[1] : null;
	arg3 = (nArgs > 2) ? args[2] : null;
	if (nArgs > 1) {
		if (confirm(msg))
			window.location.href = vUrl;
		else if (arg3 != null)
			window.location.href = fUrl;
	}
	else
		alert("Faltam argumentos...");
	return;
	}
// Fim do arquivo