function veridata(adata) { // Verifica data casamento
var hoje = new Date();
hjdia = hoje.getDate();
hjmes = hoje.getMonth()+1;
hjano = hoje.getFullYear();
if(hjdia<10) hjdia = "0"+hjdia.toString();
if(hjmes<10) hjmes = "0"+hjmes.toString();

var dtqueb = adata.value.split("index.html");
dtdia = dtqueb[0];
dtmes = dtqueb[1];
dtano = dtqueb[2];

var dtjuli= dtano.toString()+dtmes.toString()+dtdia.toString();
var hjjuli =  hjano.toString()+hjmes.toString()+hjdia.toString();

compar = (parseInt(dtjuli))-(parseInt(hjjuli));

if (compar<0) { 
	alert("Data anterior a atual!");
	adata.value="";
	adata.focus();
	return false; }
else { return true; }
}

// formata campos -------------------------------
function txtBoxFormat(objForm, strField, sMask, evtKeyPress) {
var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

if(document.all) { // Internet Explorer
nTecla = evtKeyPress.keyCode; }
else if(document.layers||document.getElementById) { // Nestcape
nTecla = evtKeyPress.which;
}

sValue = objForm[strField].value;

// Limpa todos os caracteres de formatação que
// já estiverem no campo.
sValue = sValue.toString().replace( "-", "" );
sValue = sValue.toString().replace( "-", "" );
sValue = sValue.toString().replace( ".", "" );
sValue = sValue.toString().replace( ".", "" );
sValue = sValue.toString().replace( "index.html", "" );
sValue = sValue.toString().replace( "index.html", "" );
sValue = sValue.toString().replace( "(", "" );
sValue = sValue.toString().replace( "(", "" );
sValue = sValue.toString().replace( ")", "" );
sValue = sValue.toString().replace( ")", "" );
sValue = sValue.toString().replace( "h", "" );
sValue = sValue.toString().replace( "h", "" );
sValue = sValue.toString().replace( " ", "" );
sValue = sValue.toString().replace( " ", "" );

fldLen = sValue.length;
mskLen = sMask.length;

i = 0;
nCount = 0;
sCod = "";
mskLen = fldLen;

while (i <= mskLen) {
bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "index.html") || (sMask.charAt(i) == "h"))
bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))
//bolMask = bolMask || ((sMask.charAt(i) == ":"))

if (bolMask) {
sCod += sMask.charAt(i);
mskLen++; }
else {
sCod += sValue.charAt(nCount);
nCount++;
}

i++;
}

objForm[strField].value = sCod;

if (nTecla != 8) { // backspace
if (sMask.charAt(i-1) == "9") { // apenas números...
return ((nTecla > 47) && (nTecla < 58)); } // números de 0 a 9
else { // qualquer caracter...
return true;
} }
else {
return true;
}
}

// valida data -----------------------------------

function check_date(field){

var checkstr = "0123456789";
var DateField = field;
var Datevalue = "";
var DateTemp = "";
var seperator = "index.html";
var day;
var month;
var year;
var leap = 0;
var err = 0;
var i;

  err = 0;
  DateValue = DateField.value;
  /* Delete all chars except 0..9 */
  for (i = 0; i < DateValue.length; i++) {
  if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
     DateTemp = DateTemp + DateValue.substr(i,1);
  }
  }
  DateValue = DateTemp;
  /* Always change date to 8 digits - string*/
  /* if year is entered as 2-digit / always assume 20xx */
  if (DateValue.length == 6) {
     DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); }
  if (DateValue.length != 8) {
     err = 20;}
  /* year is wrong if year = 0000 */
  year = DateValue.substr(4,4);
  if (year == 0) {
     err = 20;
  }
  /* Validation of month*/
  month = DateValue.substr(2,2);
  if ((month < 1) || (month > 12)) {
     err = 21;
  }
  /* Validation of day*/
  day = DateValue.substr(0,2);
  if (day < 1) {
    err = 22;
  }
  /* Validation leap-year / february / day */
  if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
     leap = 1;
  }
  if ((month == 2) && (leap == 1) && (day > 29)) {
     err = 23;
  }
  if ((month == 2) && (leap != 1) && (day > 28)) {
     err = 24;
  }
  /* Validation of other months */
  if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
     err = 25;
  }
  if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
     err = 26;
  }
  /* if 00 ist entered, no error, deleting the entry */
  if ((day == 0) && (month == 0) && (year == 00)) {
     err = 0; day = ""; month = ""; year = ""; seperator = "";
  }
  /* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
  if (err == 0) {
     DateField.value = day + seperator + month + seperator + year;
  }
  /* Error-message if err != 0 */
  else {
     alert("Data incorreta!");
	 DateField.value="";
     DateField.select();
  	 DateField.focus();
	 return false
  }
  return true
}


function MM_findObj(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;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' deve ter um e-mail válido.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' deve conter um número.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' deve ter um número entre '+min+' e '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' é necessário.\n'; }
  } if (errors) alert('Erro(s) de preenchimento:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function validaform(oform) { // valida campos do formulário
// verifica se data é anterior a atual 
//var dataini=oform.Data_publicacao.value;
//if(dataini!="") {
//	var resp = (veridata(oform.Data_publicacao));
//	if (resp==false) return false;
//	}

var paramfunc = validaform.arguments;
var contpar=paramfunc.length;
for (i=1; i<contpar; i++) {
	ocampo=eval(paramfunc[i]);
	if(ocampo.value=="") {
		alert("Campo obrigatório");
		ocampo.focus();
		return false;
		}
	}
MM_validateForm('Titulo','','R','Data_publicacao','','R')
if (document.MM_returnValue==false) {
	return document.MM_returnValue;
	}
else {
	updateRTEs();
	oform.submit();
	return true;
	}
}

function validafile(campo) // valida campo file
{
 ender = campo.value;   // recebe valor do campo
 ext = ender.substring(ender.length-3,ender.length);   // separa extensão do arquivo
 ext = ext.toLowerCase(); // passar para minúscula

 if (ext != "jpg" || ender.length < 5 || ender.indexOf('.')==-1) // verifica arquivo
 {
  alert("Erro: Arquivo inválido!");
  campo.value="";
  campo.focus()
  campo.select();
  return false;
 }
}

function verincluir(oform,campo1,campo2,campo3,campo4) {
	if((campo1.value==""&&campo2.value=="")||(campo3.value==""||campo4.value=="")) {
		alert("Atenção!\nCampo obrigatório não preenchido!");
		return false;
	} else {
		return true;
	}
}