// JavaScript Document

function checadata(dia,mes,ano) {
// Apenas retorna true ou false
	situacao = "";
	// verifica o dia valido para cada mes
	if ((dia < 1)||(dia < 1 || dia > 30) && (  mes == 4 || mes == 6 || mes == 9 || mes == 11 ) || dia > 31) {
		situacao = "falsa";
	}
	
	// verifica se o mes e valido
	if (mes < 1 || mes > 12 ) {
		situacao = "falsa";
	}

	// verifica se o ano e valido
	if (ano =='') {
		situacao = "falsa";
	}
	

	// verifica se e ano bissexto
	if (mes == 2 && ( dia < 1 || dia > 29 || ( dia > 28 && (parseInt(ano / 4) != ano / 4)))) {
		situacao = "falsa";
	}
	
	if (situacao == "falsa") {
		return false;
	} else {
		return true;
	}
} 


function mostraAba(qual,total) {
	for (x=1;x<=total;x++) {
		aba = 'aba'+x;
		if (qual!=aba) MM_dmenuh(aba);
	}
	MM_dmenu(qual);	
}

// Funcao para pular de um campo para outro em um form
function autofocus(field, limit, next, evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
        ((evt.which) ? evt.which : 0));
    if (charCode > 31 && field.value.length == limit) {
        field.form.elements[next].focus( );
    }
}

function verificaFormNewsletter(_form) {
	if (_form.nome.value=='nome') {
		alert('Erro: Nome inválido');
		return false;
	}
	if (_form.email.value=='email') {
		alert('Erro: e-mail inválido');
		return false;
	}
	return true;
}
	

function IEHoverPseudo() {

	var navItems = document.getElementById("primary-nav").getElementsByTagName("li");
	
	for (var i=0; i<navItems.length; i++) {
		if(navItems[i].className == "menuparent") {
			navItems[i].onmouseover=function() { this.className += " over"; }
			navItems[i].onmouseout=function() { this.className = "menuparent"; }
		}
	}

}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_dmenu(objname) {
  var obj = MM_findObj(objname);
  if(obj && obj.style) obj.style.display = (obj.style.display=="none") ? "" : "none";
}

function MM_dmenuh() {
  var a=MM_dmenuh.arguments;
  for (i=0; i<a.length; i++) {var obj = MM_findObj(a[i]); if(obj && obj.style) obj.style.display = "none"; }
}

function MM_dmenus() {
  var a=MM_dmenus.arguments;
  for (i=0; i<a.length; i++) {var obj = MM_findObj(a[i]); if(obj && obj.style) obj.style.display = ""; }
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// Uso: onkeydown="if (!isDigit(event)) { return false }"
var ie4up, ns6, ns4, dom;
if ( navigator.appName == "Microsoft Internet Explorer" ) 
   ie4up = parseInt ( navigator.appVersion ) >= 4;
else if ( navigator.appName == "Netscape" ) {
   ns6 = parseInt ( navigator.appVersion ) >= 5;
   ns4 = parseInt ( navigator.appVersion ) < 5;
}

function isDigit ( evt ) {
   var keyCode = evt.which ? evt.which : evt.keyCode;
   digit = !isNaN ( parseInt ( String.fromCharCode ( keyCode ) ) ) || 
   	   // testa o "ponto"
      // ( keyCode == 190 || keyCode == 110 ) || 
      ( keyCode >= 8 && keyCode <= 46 &&
      keyCode !=16 && keyCode !=32 );
   digit = ie4up ? digit || ( keyCode >= 96 && keyCode <=105 ) : digit;
   return ( digit );
}

function numbersonly(myfield, e, dec) {
	var key;
	var keychar;
	
	if (window.event)
	   key = window.event.keyCode;
	else if (e)
	   key = e.which;
	else
	   return true;
	keychar = String.fromCharCode(key);
	
	// control keys
	if ((key==null) || (key==0) || (key==8) || 
		(key==9) || (key==13) || (key==27) )
	   return true;
	
	// numbers
	else if ((("0123456789").indexOf(keychar) > -1))
	   return true;
	
	// decimal point jump
	else if (dec && (keychar == ".")) {
	   myfield.form.elements[dec].focus();
	   return false;
	} else
	   return false;
}

function formataTel(Campo, e){

	if (numbersonly(Campo, e)) {
		if (window.event)
	   		var tecla = window.event.keyCode;
		else if (e)
	  		tecla = e.which;
		
		var v = Campo.value;
		v = v.replace(/\D/g,"");
        v = v.replace(/^(\d\d)(\d)/g,"($1) $2");
        v = v.replace(/(\d{4})(\d)/,"$1-$2");
		Campo.value = v;
		return true;
	} else {
		return false;
	}
}
