/**
* Script em geral.
*/

/* funções de imagem e janela */

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_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);


function MM_openBrWindow(theURL,winName,features) { //v2.0
var mywindow =window.open(theURL,winName,features); mywindow.focus();
}

function abrePopup(url){
    janela=window.open(url,'Janela','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=320,height=350')
}


/* valida formulario */
function valida_form(theForm){

  if (theForm.entidade.value == ""){
      alert('Você deve escolher um setor.');
      theForm.entidade.focus();      return (false);
  }

  if (theForm.nome.value == ""){
      alert('Você deve informar o seu nome.');
      theForm.nome.focus();      return (false);
  }

  if (theForm.email.value.indexOf('@', 0) == -1 ||
      theForm.email.value.indexOf('.', 0) == -1)
  {
    alert("Você deve informar seu e-mail de contato.");
    theForm.email.focus();    return (false);
  }

  if (theForm.mensagem.value == ""){
      alert('Você deve informar a mensagem.');
      theForm.mensagem.focus();      return (false);
  }

return (true);
}


//SuckerTree Vertical Menu 1.1 (Nov 8th, 06)
//By Dynamic Drive: http://www.dynamicdrive.com/style/

var menuids=["suckertree1"] //Enter id(s) of SuckerTree UL menus, separated by commas

function buildsubmenus(){
for (var i=0; i<menuids.length; i++){
  var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul")
    for (var t=0; t<ultags.length; t++){
    ultags[t].parentNode.getElementsByTagName("a")[0].className="subfolderstyle"
		if (ultags[t].parentNode.parentNode.id==menuids[i]) //if this is a first level submenu
			ultags[t].style.left=ultags[t].parentNode.offsetWidth+"px" //dynamically position first level submenus to be width of main menu item
		else //else if this is a sub level submenu (ul)
		  ultags[t].style.left=ultags[t-1].getElementsByTagName("a")[0].offsetWidth+"px" //position menu to the right of menu item that activated it
    ultags[t].parentNode.onmouseover=function(){
    this.getElementsByTagName("ul")[0].style.display="block"
    }
    ultags[t].parentNode.onmouseout=function(){
    this.getElementsByTagName("ul")[0].style.display="none"
    }
    }
		for (var t=ultags.length-1; t>-1; t--){ //loop through all sub menus again, and use "display:none" to hide menus (to prevent possible page scrollbars
		ultags[t].style.visibility="visible"
		ultags[t].style.display="none"
		}
  }
}

if (window.addEventListener)
window.addEventListener("load", buildsubmenus, false)
else if (window.attachEvent)
window.attachEvent("onload", buildsubmenus)

//3ª conferencia da saúde
function MascaraData(data){
		if(mascaraInteiro(data)==false){
			event.returnValue = false;
		}
		return formataCampo(data, '00/00/0000', event);
	}
	
	function MascaraTelefone(telefone){
		if(mascaraInteiro(telefone)==false){
			event.returnValue = false;
		}
		return formataCampo(telefone, '(000) 0000-0000', event);
	}
	
	function mascaraInteiro(){
		if (event.keyCode < 48 || event.keyCode > 57){
			event.returnValue = false;
			return false;
		}
		return true;
	}

	function formataCampo(campo, Mascara, evento) {
		var boleanoMascara;

		var Digitato = evento.keyCode;
		exp = /\-|\.|\/|\(|\)| /g
		campoSoNumeros = campo.value.toString().replace( exp, "" );

		var posicaoCampo = 0;
		var NovoValorCampo="";
		var TamanhoMascara = campoSoNumeros.length;;

		if (Digitato != 8) { // backspace
			for(i=0; i<= TamanhoMascara; i++) {
				boleanoMascara = ((Mascara.charAt(i) == "-") || (Mascara.charAt(i) == ".")|| (Mascara.charAt(i) == "/"))
				boleanoMascara = boleanoMascara || ((Mascara.charAt(i) == "(")|| (Mascara.charAt(i) == ")") || (Mascara.charAt(i) == " "))
				if (boleanoMascara) {
					NovoValorCampo += Mascara.charAt(i);
					TamanhoMascara++;
				}else {
					NovoValorCampo += campoSoNumeros.charAt(posicaoCampo);
					posicaoCampo++;
				}
			}
			campo.value = NovoValorCampo;
			return true;
		}else {
			return true;
		}
	}
