// FUNCAO ROLLOVER BOTOES
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_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_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 validaEmail(email){
	var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
	if (typeof(email) == "string"){
        if(er.test(email))
        	return true;
		else
			return false;
	}else if (typeof(email) == "object"){
		if(er.test(email.value))
        	return true;
		else
			return false;
	}
};

function validaFormEmkt(pag){
	var nome = document.formNews.txtNome.value;
	var email = document.formNews.txtEmail.value;
	
	if (nome.length < 3)
	{
		alert("Nome informado invalido!");
		nome.focus();
	}
	else if (!validaEmail(email)){
		alert("E-mail informado invalido!");
		email.focus();
	}
	else
	{
		document.formNews.action='incluiemail.php?nomePag='+pag;
		document.formNews.submit();
	}
}


// FUNCAO ABRIR JANELAS
function ABRIR(theURL,winName,features){
window.open(theURL,winName,features);}


//FUNCAO FECHAR JANELAS
function FECHAR(theURL){
window.close("theURL");}

//FUNCAO IMPRIMIR
function IMPRIMIR(theURL){
window.print("theURL");}


//FUNCAO CHAMAR JAVA
function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}

//FUNCAO MENUS
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

//FUNCAO LER PAGINA
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);

//FUNCAO MOSTRAR/OCULTAR CAMADAS
function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

//FUNCAO VALIDADE DE FORMS
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+' não contém um endereço de e-mail válido!.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' não contém um número válido!.\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 um número entre '+min+' e '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += 'O Campo '+nm+' é de preenchimento obrigatório.\n'; }
  } if (errors) alert('Ocorreu os seguintes erros:\n'+errors);
  document.MM_returnValue = (errors == '');
}


// When the page loads: 
window.onload = function(){ 
if (document.getElementsByTagName) { 
// Get all the tags of type object in the page. 
var objs = document.getElementsByTagName("object"); 
for (i=0; i<objs.length; i++) { 
// Get the HTML content of each object tag 
// and replace it with itself. 
objs[i].outerHTML = objs[i].outerHTML; 
} 
} 
} 
// When the page unloads: 
window.onunload = function() { 
if (document.getElementsByTagName) { 
//Get all the tags of type object in the page. 
var objs = document.getElementsByTagName("object"); 
for (i=0; i<objs.length; i++) { 
// Clear out the HTML content of each object tag 
// to prevent an IE memory leak issue. 
objs[i].outerHTML = ""; 
} 
} 
}



function clearText(thefield){
	if (thefield.defaultValue==thefield.value)
	thefield.value = ""
}
function replaceText(thefield){
	if (thefield.value=="")
	thefield.value = thefield.defaultValue
}

//FORMATACAO DE TEXTBOXES
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) { // Nestcape
    nTecla = evtKeyPress.which;
} else {
    nTecla = evtKeyPress.which;
    if (nTecla == 8) {
        return true;
    }
}

sValue = objForm[strField].value;
// Limpa todos os caracteres de formatação que
// já estiverem no campo.
// toString().replace [transforma em sring e troca elementos por ""]
sValue = sValue.toString().replace( "-", "" );
sValue = sValue.toString().replace( "-", "" );
sValue = sValue.toString().replace( ".", "" );
sValue = sValue.toString().replace( ":", "" );
sValue = sValue.toString().replace( ".", "" );
sValue = sValue.toString().replace( "/", "" );
sValue = sValue.toString().replace( "/", "" );
sValue = sValue.toString().replace( "/", "" );
sValue = sValue.toString().replace( "(", "" );
sValue = sValue.toString().replace( "(", "" );
sValue = sValue.toString().replace( ")", "" );
sValue = sValue.toString().replace( ")", "" );
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) == ".") || (sMask.charAt(i) == "/"))
bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " ") || (sMask.charAt(i) == "."))

//Se for true utiliza elementos especiais aumenta a máscara
if (bolMask) {
    sCod += sMask.charAt(i);
    mskLen++;
//Caso false mostra o sValue(o q foi digitado)
} 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;
}
}