// Funcoes globais em JavaScript //////////////////////////////

// scripts personalizados

// Abrir janela para andamento de processos
function janela(url,titulo,w,h,scrol){

	lado=(screen.width)?(screen.width-w)/2:100;
	cima=(screen.height)?(screen.height-h)/2-28:20;
	settings='width='+w+',height='+h+',top='+cima+',left='+lado+',scrollbars='+scrol;
	window.open(url,titulo,settings);

}

// Abrir e fechar div

function me(div) {
var divq = document.getElementById(div).style;
if (divq.display == 'none') {
divq.display = 'block';

}
else {
divq.display = 'none';
}
}

function ma(div) {
var divq = document.getElementById(div).style;
if (divq.display == 'block') {
divq.display = 'none';
}
else {
divq.display = 'block';
}
}




// FUNCOES UTILIZADAS NAS MAIORIAS DOS CLIENTES

/////////////////////////////////////////////////////////////////////////////////////////
// FUNCAO    :  MM_openBrWindow(theURL,winName,features)
// DESCRICAO :  Abrir janela padrao do DW
// SINTÁXE   :  onClick="MM_openBrWindow(theURL,winName,features)"
// PARAMETROS:  theURL - URL do arquivo que ira abrir na janela
//		        winName - nome da janela
// 				features - Caracteristicas da janela. Ex.: toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=400,height=350
/////////////////////////////////////////////////////////////////////////////////////////
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}




/////////////////////////////////////////////////////////////////////////////////////////
// FUNCAO    :  ShowImage(nome,detalhe)
// DESCRICAO :  Passa o nome e descricao da fotos para ampliar na tela
// SINTÁXE   :  onClick="ShowImage(nome,detalhe)"
// PARAMETROS:  nome - Nome da fotos que sera exibida
//		        detalhe - descricao da fotos
/////////////////////////////////////////////////////////////////////////////////////////
function ShowImage(nome, detalhe) {
	document.images["NomeImagem"].src=nome;
	document.depoimento.depoimento.value=detalhe;
}


/////////////////////////////////////////////////////////////////////////////////////////
// FUNCAO    :  mudaFoco(caracteres,focoAtual,novoFoco)
// DESCRICAO :  Passa o foco para outro componente apos digitar n caracteres
// SINTÁXE   :  onkeyup="javascript:mudaFoco(caracteres,focoAtual,novoFoco)"
// PARAMETROS:  caracteres - Numero - Quantidade de caracteres digitados ate perder o foco
//		        focoAtual - Componente - Componente de um form onde será digitado os caracteres
// RETORNO   :  novoFoco - Componente - Componente de um form que ganhara o foco apos ser
//										digitado a qtd de caracteres no focoAtual
/////////////////////////////////////////////////////////////////////////////////////////
 function mudaFoco(caracteres,focoAtual,novoFoco)
 {
  if (focoAtual.value.length==caracteres)
  {
    novoFoco.focus();
  }
 }




 /////////////////////////////////////////////////////////////////////////////////////////
// FUNCAO    :  numbersOnly(myfield,e)
// DESCRICAO :  Impede que o usuario digite valores nao numericos
// SINTÁXE   :  onKeyPress="return numbersOnly(this, event)"
// PARAMETROS:  myfield  - o campo que sofrerá esta restricao(basta colocar this)
//		        e - evento(basta colocar o event)
// RETORNO   :  true caso seja numero e false caso contrario
/////////////////////////////////////////////////////////////////////////////////////////

function numbersOnly(myfield, e)
{
    if (myfield.length ==0)
	    myfield.value=0;
	  var key;
	  var keychar;
    if (window.event)
     key = window.event.keyCode;
    else if (e)
     key = e.which;
    else
     return true;
	  keychar = String.fromCharCode(key);
    if ((key==null) || (key==0) || (key==8) ||
		      (key==9)|| (key==13)|| (key==27) )
     return true;
    else if ((("0123456789").indexOf(keychar) > -1))
	     return true;
	else
   return false;
}



/////////////////////////////////////////////////////////////////////////////////////////
// FUNCAO    :  javascript:ts('newsContent',+1)
// DESCRICAO :  Aumenta o tamanho do texto
// SINTÁXE   :  <a href="javascript:ts('newsContent',+1)">+ Aumentar</a> <a href="javascript:ts('newsContent',-1)">- Diminuir</a>
// PARAMETROS:  trgt  - div onde será aplicado o script <div id="newsContent">textos</div>
//		        inc - se aumenta ou diminui a fonte
// RETORNO   :  true caso seja numero e false caso contrario
/////////////////////////////////////////////////////////////////////////////////////////

var tgs = new Array('div');

//Especificar os tamanhos de fonte:
var szs = new Array( '09px','10px','11px','14px','16px' );
var startSz = 2;


function ts( trgt,inc ) {
	if (!document.getElementById) return
	var d = document,cEl = null,sz = startSz,i,j,cTags;

	sz += inc;
	if ( sz < 0 ) sz = 0;
	if ( sz > 4 ) sz = 4;
	startSz = sz;

	if ( !( cEl = d.getElementById( trgt ) ) ) cEl = d.getElementsByTagName( trgt )[ 0 ];

	cEl.style.fontSize = szs[ sz ];

	for ( i = 0 ; i < tgs.length ; i++ ) {
		cTags = cEl.getElementsByTagName( tgs[ i ] );
		for ( j = 0 ; j < cTags.length ; j++ ) cTags[ j ].style.fontSize = szs[ sz ];
	}
}



/***********************************************************************/
/*********************** Scripts basicos do DW *************************/
/***********************************************************************/

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);

// PRELOAD IMAGES
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];}
}





/////////////////////////////////////////////////////////////////////////////////////////
// FUNCAO    :  MM_validateForm()
// DESCRICAO :  Validacao de formulario
/////////////////////////////////////////////////////////////////////////////////////////

function MM_validateForm() { //v4.0
  if (document.getElementById){
    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=document.getElementById(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 conter e-mail valido.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' deve conter numeros.\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 conter numeros entre '+min+' e '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' é necessario.\n'; }
    } if (errors) alert('Erro(s) ao tentar enviar:\n'+errors);
    document.MM_returnValue = (errors == '');
} }


