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_openBrWindow(theURL,winName,features) { //v2.0
  nj = window.open(theURL,winName,features);
  nj.focus();
}

var wait = 0;
var hideTimer;

function keepOpen()
{
	if (hideTimer != null)
		clearTimeout(hideTimer);
}

function hide()
{
	hideTimer = setTimeout("hideAll()", wait);
}

function hideAll()
{
	var i;
	for (i=0; i<menus.length; i++)
	{
		menus[i].style.visibility = "hidden";
	}
}
 
function hideAfter(num)
{
	var i;
	for (i=num+1; i<menus.length; i++)
	{
		menus[i].style.visibility = "hidden";
	}
}

function showMenu(num, pNum)
{
	var cMenu = menus[num];
	if (cMenu.style.visibility != "visible")
	{
		hideAfter(pNum);
		cMenu.style.visibility = "visible";

		for (i=0; i<menus.length; i++) //esconde os outros
		{
			if(num != i){
				menus[i].style.visibility = "hidden";
			}
		}
	}
}

var menus = new Array();
var princ = new Array();

function iniciar(){
	var i;
	for (i=0; i<8; i++)
	{
		menus[i] = MM_findObj("menus" + i);
		menus[i].onmouseover = new Function("keepOpen();");
		menus[i].onmouseout = new Function("hide();");
		menus[i].style.cursor = "hand";
	}

	for (i=0; i<8; i++)
	{
		princ[i] = MM_findObj("princ" + i);
		princ[i].onmouseover = new Function("showMenu(" + i + ", " + (i-1) + ");");
	}
}

function mostrar(id){
	var za = MM_findObj(id);
	za.style.display='block';
}

function esconder(id){
	var za = MM_findObj(id);
	za.style.display='none'
}

function mostrar_esconder(id){
	var za = MM_findObj(id);
	if(za.style.display == 'none'){
		za.style.display='block';
	}else{
		za.style.display='none'
	}
}

function mostrar_esconder_seta(id){
	var za = MM_findObj(id);
	if(za.style.display == 'none'){
		za.style.display='block';
		MM_swapImage('s_' + id,'','imagens/img_seta_acima.gif',1);
	}else{
		za.style.display='none'
		MM_swapImage('s_' + id,'','imagens/img_seta_abaixo.gif',1);
	}
}

//Checa Hora
function valida_Hora(v){
	if(v.length!=5||v.substr( 0, 2  ) > 23||v.substr( 0, 2  ) < 0||v.substr( 3, 2  ) > 59||v.substr( 3, 2  ) < 0){
		return false;
	}else{
		return true;
	}
}

//Formata data
function FormataData(Campo,teclapres) 
{
	var tecla = teclapres.keyCode;
	vr = document.form[Campo].value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;
	if ( tecla != 9 && tecla != 8 )
	{
		if ( tam > 2 && tam < 5 )
			document.form[Campo].value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 10 )
			document.form[Campo].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 );
	}
}

//Formata Hora
function FormataHora(Campo,teclapres) 
{
	var tecla = teclapres.keyCode;
	vr = document.form[Campo].value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ":", "" );
	tam = vr.length + 1;
	if ( tecla != 9 && tecla != 8 )
	{
		if ( tam > 2)
			document.form[Campo].value = vr.substr( 0, 2 ) + ':' + vr.substr(  tam - 2, tam );
	}
}

//Muda de campo após atingir o tamanho máximo
function DFchangeField(f){
	if(f.value.length==f.maxLength){
  	for(var i=0;i<f.form.length;i++){
    	if(f.form[i]==f&&f.form[i+1]){f.form[i+1].focus();break}
		}
	}
}

function somente_numero(){
	if (window.event.keyCode < 48 || window.event.keyCode > 57) {
			window.event.keyCode=0;
			return false;
	}
	return true		
}

function trim(value) {
   var temp = value;
   var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
   if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
   var obj = / +/g;
   temp = temp.replace(obj, " ");
   if (temp == " ") { temp = ""; }
   return temp;

}


function MM_validateForm() { //v4.0
  var i,p,q,nm,nMsg,test,num,tipo,data,d,m,Y,min,max,h,campoOk,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { 
	  test=args[i+2]; 
	  nMsg=args[i+1]; 
	  val=MM_findObj(args[i]);
	  campoOk=0;
    if (val) { 
		nm=val.name;
		tipo = "";
		if(nm == undefined){
			tipo = val[0].type;
		}
		
		if(test.indexOf('isHora')!=-1){
			if(trim(val.value) == "" || valida_Hora(trim(val.value)) == false){
				errors+='- '+nMsg+': Hora inválida.\n';
			}
		}else if(test.indexOf('isCEP')!=-1){
			if(trim(val.value) == "" || valida_CEP(trim(val.value)) == false){
				errors+='- '+nMsg+': CEP inválido.\n';
			}
		}else if(test.indexOf('isCPF')!=-1){
			if(trim(val.value) == "" || DFcheckCpf(trim(val.value)) == false){
				errors+='- '+nMsg+': CPF inválido.\n';
			}
		}else if(test.indexOf('isCNPJ')!=-1){
			if(trim(val.value) == "" || valida_CNPJ(trim(val.value)) == false){
				errors+='- '+nMsg+': CNPJ inválido.\n';
			}
		}else if(nm == "concordo"){
			if(val.checked == false){
				errors+='- '+nMsg+': você precisa concordar com os Termos.\n';
			}
		}else if(tipo == "radio" || tipo == "checkbox"){
			for(h=0;h<val.length;h++){
				if(val[h].checked == true){
					campoOk=1;
				}
			}
			if(campoOk == 0) errors+='- '+nMsg+': você precisa indicar uma opção.\n';
		}else if(val.type == "select-one" || val.type == "select"){
				if(val.selectedIndex < 1)  errors+='- '+nMsg+': você precisa selecionar um.\n';
		}else if ((val=val.value)!="") {
			if (test.indexOf('isEmail')!=-1) { 
				p=val.indexOf('\@');
				if (p<1 || val.indexOf(',') > 1 || p==(val.length-1)) errors+='- '+nMsg+' precisa ser um e-mail.\n';
			} else if (test!='R') {
				if (isNaN(val)) errors+='- '+nMsg+' deve conter apenas números.\n';
				if (test.indexOf('inRange') != -1) {
					p=test.indexOf(':');
					min=test.substring(8,p); max=test.substring(p+1);
					if ((val*1)<(min*1) || (max*1)<(val*1)) errors+='- '+nMsg+' deve conter um número entre '+min+' e '+max+'.\n';
				} 
			} 
		} else if (test.charAt(0) == 'R') errors += '- '+nMsg+' é requerido / is required.\n'; }
  } if (errors) alert('O envio gerou o(s) seguinte(s) avisos / The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

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];}}
}

document.onLoad="MM_preloadImages('images/bt_menuleft.jpg','images/bt_menuleft_on.jpg')"
