<!-- 
// 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]);		
		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]);			
			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){
	for (j=0; objChk[j]; j++)
		if (objChk[j].checked)
			return true;
	return false;
};

// 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";

// 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();
  });
};



var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		return false
	}
return true
}



//-->