<!-- 
// RICARDO MOMM / Natela WebSolutions

/******************************************
/* Validação dos campos
/*****************************************/

// Validação de Formulários
MM_validateForm = function() { 
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=2; i<(args.length-2); i+=3) { 
		erro = "";
		val=MM_findObj(args[i]);		
		if (args[0]!='')
			val.className = args[0];		
		test=args[i+2]; 
    if (val) { 
			nm=args[i+1];
			if (test.indexOf('isCheckbox')!=-1) {
				if (!testaCheckbox(MM_findObj(args[i])))
					erro ='- '+nm+': você deve selecionar pelo menos uma opção.\n';
			}else{	
				if ((val=val.value)!="") {
	      	if (test.indexOf('isEmail')!=-1)
						if (!testaEmail(val))
	        		erro ='- '+nm+' deve conter um endereço de e-mail.\n';
					if (test.indexOf('isCPF')!=-1)
						if (!testaCPF(val))
	        		erro ='- '+nm+' deve conter um CPF válido.\n';						
					if (test.indexOf('isCNPJ')!=-1)
						if (!testaCNPJ(val))
							erro ='- '+nm+' deve conter um CNPJ válido.\n';
					if (test.indexOf('isData')!=-1)
						if (!testaData(val))
							erro ='- '+nm+' deve conter uma data válida.\n';
					if (test.indexOf('isHora')!=-1)
						if (!testaHora(val))
							erro ='- '+nm+' deve conter uma hora válida.\n';
					if (test.indexOf('isLink')!=-1)
						if (!testaLink(val))
							erro ='- '+nm+' deve conter um link válido (com HTTP://).\n';
					if (test.indexOf('isNum')!=-1)
						if (isNaN(val))
							erro ='- '+nm+' deve conter um número.\n';
					if (test.indexOf('isSeguro')!=-1) {
						if (!testaSeguro(val))
							erro ='- '+nm+' deve conter somente letras, _ e números.\n';
					}
				} else 
					if (test.charAt(0) == 'R') erro = '- '+nm+' é requerido.\n'; 
			}
  	}
		if (erro!=""){
			errors+=erro;
			val=MM_findObj(args[i]);		
			if (args[1]!='')
				val.className = args[1];
		}
	} 
	if (errors) alert('Erro:\n'+errors);
  document.MM_returnValue = (errors == '');
};

MM_findObj = function(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
};

// Testa um grupo de CheckBox ou RadioButton
testaCheckbox = function(objChk){
	if (objChk[0]){
		for (j=0; objChk[j]; j++)
			if (objChk[j].checked)
				return true;
		return false;	
	}else
		return (objChk.checked);
};

// Testa um e-mail
testaEmail = function(strEmail){
	var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // e-mail inválido
  var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // e-mail válido
  return (!reg1.test(strEmail) && reg2.test(strEmail));
};

// Testa um CPF
testaCPF = function(strCPF){
    var c = strCPF;
    if((c = c.replace(/[^\d]/g,"").split("")).length != 11) return false;
    if(new RegExp("^" + c[0] + "{11}$").test(c.join(""))) return false;
    for(var s = 10, n = 0, i = 0; s >= 2; n += c[i++] * s--);
    if(c[9] != (((n %= 11) < 2) ? 0 : 11 - n)) return false;
    for(var s = 11, n = 0, i = 0; s >= 2; n += c[i++] * s--);
    if(c[10] != (((n %= 11) < 2) ? 0 : 11 - n)) return false;
    return true;
};

// Testa um CNPJ
testaCNPJ = function(strCNPJ){
    var b = [6,5,4,3,2,9,8,7,6,5,4,3,2], c = strCNPJ;
    if((c = c.replace(/[^\d]/g,"").split("")).length != 14) return false;
    for(var i = 0, n = 0; i < 12; n += c[i] * b[++i]);
    if(c[12] != (((n %= 11) < 2) ? 0 : 11 - n)) return false;
    for(var i = 0, n = 0; i <= 12; n += c[i] * b[i++]);
    if(c[13] != (((n %= 11) < 2) ? 0 : 11 - n)) return false;
    return true;
};

// Testa uma Data
testaData = function(strData){
	if (strData.length > 10) return false;
	if (!isNaN(strData)) return false;
	if ((separador1=strData.indexOf("/"))==-1) return false;
	if ((separador2=strData.indexOf("/",separador1+1))==-1) return false;
	var dia = strData.substring(0,separador1);
	var mes = strData.substring(eval(separador1 + 1),separador2);
	var ano = strData.substring(eval(separador2 + 1),strData.length);
	if (mes<1&&mes>12) return false;
	if (dia<1&&dia>31) return false;
	if (mes==2)
		if (dia>29) 
			return false;
		else
			if (dia==29&&((ano%4)!=0)) return false;
	if ((mes == 4)||(mes == 6)||(mes == 9)||(mes == 11))
		if ((dia <= 0 ) && (dia > 30)) return false;
	if ((mes == 1)||(mes == 3)||(mes == 5)||(mes ==7)||(mes == 8)||(mes == 10)||(mes == 12))
		if ((dia <= 0) && (dia > 31)) return false;
	return true;
};

// Testa uma hora
testaHora = function(horario) {
	if (horario.indexOf(".") == -1)
		if (horario.indexOf(":") != -1){
			div    = horario.indexOf(":");
			tam    = horario.length;
			hora   = horario.substring(0,div);
			minuto = horario.substring(div+1,tam);
			msg    = "";
			if ((!isNaN(hora))&&(!isNaN(minuto))){
				if ((minuto>=60)||(minuto<0))
					return false;
				if ((hora>24)||(hora<0))
					return false;
				return true;
			}
		}
	return false;
};

// Testa um link
testaLink = function(strLink) {
   var reg1 = /http?:\/\/([-\w\.]+)+(:\d+)?(\/([\w\/_\.]*(\?\S+)?)?)?/;
   return reg1.test(strLink);
};

// Testa se um valor é seguro 
testaSeguro = function(strSeguro){
	var reg1 = /(\%27)|(\')|(\-\-)|(\%23)|(#)/i;
	return !reg1.test(strSeguro);
};

/******************************************
/* Mascara para os campos
/*****************************************/

// Adiciona um evento a uma função/campo
addEvent = function(o, e, f, s){
    var r = o[r = "_" + (e = "on" + e)] = o[r] || (o[e] ? [[o[e], o]] : []), a, c, d;
    r[r.length] = [f, s || o], o[e] = function(e){
        try{
            (e = e || event).preventDefault || (e.preventDefault = function(){e.returnValue = false;});
            e.stopPropagation || (e.stopPropagation = function(){e.cancelBubble = true;});
            e.target || (e.target = e.srcElement || null);
            e.key = (e.which + 1 || e.keyCode + 1) - 1 || 0;
        }catch(f){}
        for(d = 1, f = r.length; f; r[--f] && (a = r[f][0], o = r[f][1], a.call ? c = a.call(o, e) : (o._ = a, c = o._(e), o._ = null), d &= c !== false));
        return e = null, !!d;
    }
};

// Remove um evento de uma função/campo
removeEvent = function(o, e, f, s){
    for(var i = (e = o["_on" + e] || []).length; i;)
        if(e[--i] && e[i][0] == f && (s || o) == e[i][1])
            return delete e[i];
    return false;
};

// Função que cria a maskara
MaskInput = function(f, m){ //v1.0
    function mask(e){
        var patterns = {"1": /[A-Z]/i, "2": /[0-9]/, "4": /[À-ÿ]/i, "8": /./ },
            rules = { "a": 3, "A": 7, "9": 2, "C":5, "c": 1, "*": 8};
        function accept(c, rule){
            for(var i = 1, r = rules[rule] || 0; i <= r; i<<=1)
                if(r & i && patterns[i].test(c))
                    break;
                return i <= r || c == rule;
        }
        var k, mC, r, c = String.fromCharCode(k = e.key), l = f.value.length;
        (!k || k == 8 ? 1 : (r = /^(.)\^(.*)$/.exec(m)) && (r[0] = r[2].indexOf(c) + 1) + 1 ?
            r[1] == "O" ? r[0] : r[1] == "E" ? !r[0] : accept(c, r[1]) || r[0]
            : (l = (f.value += m.substr(l, (r = /[A|9|C|\*]/i.exec(m.substr(l))) ?
            r.index : l)).length) < m.length && accept(c, m.charAt(l))) || e.preventDefault();
    }
    for(var i in !/^(.)\^(.*)$/.test(m) && (f.maxLength = m.length), {keypress: 0, keyup: 1})
        addEvent(f, i, mask);
};

// Formata uma data
var DATA = "99/99/9999";
// Formata um Cpf
var CPF  = "999.999.999-99";
// Formata um CNPJ
var CNPJ = "99.999.999/9999-99";
// Formata uma HORA
var HORA = "99:99";
// Formata um TELEFONE
var FONE = "(99) 9999-9999";
// Formata um CEP
var CEP  = "99999-999";
var RG  = "9.999.999-9";

// Formata um VALOR
FormataValor = function(o, n, dig, dec) {
  o.c = !isNaN(n) ? Math.abs(n) : 2;
  o.dec = dec || ",", o.dig = dig || ".";
  addEvent(o, "keypress", function(e){
      if(e.key > 47 && e.key < 58){
          var o, s = ((o = this).value.replace(/^0+/g, "") + String.fromCharCode(e.key)).replace(/\D/g, ""), l, n;
          (l = s.length) <= (n = o.c) && (s = new Array(n - l + 2).join("0") + s);
          for(var i = (l = (s = s.split("")).length) - n; (i -= 3) > 0; s[i - 1] += o.dig);
          n && n < l && (s[l - ++n] += o.dec);
          o.value = s.join("");
      }
      e.key > 30 && e.preventDefault();
  });
};


function pop_up_center(local, w, h, o){
	largura = screen.width;
	altura 	= screen.height;
	XX 		= (largura-w)/2;
	YY		= (altura-h)/2;
	opcoes = (o!='')?o:'scrollbars=no,status=no,resizable=no, toolbar=no,directories=no,menubar=no';
	janela = window.open(local,'POP_UP','width='+w+',height='+h+',left='+XX+',top='+YY+','+opcoes);
	janela.focus();
}

function pop_up_center1(local, w, h, scrol)
{
largura = screen.width;
altura 	= screen.height;
XX 		= (largura-w)/2;
YY		= (altura-h)/2;
janela = window.open(local,'POP_UP'+XX+''+YY,'width='+w+',height='+h+',left='+XX+',top='+YY+',scrollbars='+scrol+',status=no,resizable=yes, toolbar=no,directories=no,menubar=no');
janela.focus();
}

function addToFavorites(pageName){
	if(window.external){
		window.external.AddFavorite(window.location,pageName);
	}else{
		alert('Desculpe, seu browser não suporta esta função. Efetue o procedimento manualmente.');
	}
}

function mount_XMLHttp()
{
	try{
		xmlhttp = new XMLHttpRequest();
	}catch(ee){
		try{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(E){
				xmlhttp = false;
			}
		}
	}
return xmlhttp;
}


carrega_cargo	=	function(c){

	xmlhttp	=	mount_XMLHttp();
	url	=	"../inc/inc.cargo.asp?v="+c.value;
	xmlhttp.open("GET", url,true);
	xmlhttp.onreadystatechange=function() {
		if(xmlhttp.readyState==4){
			if(xmlhttp.responseText!="OK"){
				eval(xmlhttp.responseText);
				c.focus();
			}
		}
	}
	
	xmlhttp.send(null);

}

carrega_local	=	function(c){

	xmlhttp	=	mount_XMLHttp();
	url	=	"../inc/inc.local.asp?v="+c.value;
	xmlhttp.open("GET", url,true);
	xmlhttp.onreadystatechange=function() {
		if(xmlhttp.readyState==4){
			if(xmlhttp.responseText!="OK"){
				eval(xmlhttp.responseText);
				c.focus();
			}
		}
	}
	
	xmlhttp.send(null);

}

//-->