//Corrige problema com transparencia no ie6
// correctly handle PNG transparency in Win IE 5.5 & 6.
function correctPNG()
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5 && version <= 6.5) && (document.body.filters))
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }    
}
if (window.attachEvent){
    window.attachEvent("onload", correctPNG);
}

//---------------------

var aux = 10;
function alterarFonte(id, acao){
  if(acao == 'maior'){
    if(aux < 16) aux += 1;
  }
  else{
    if(aux > 10) aux -= 1;
  }

 document.getElementById(id).style.fontSize = aux+'px';
}

//---------------------

function flash(url, largura, altura){
 var aux = '';
 aux += '<object classid="clsid:clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' +largura+ '" height="' +altura+ '" align="middle">';
 aux += '<param name="allowScriptAccess" value="sameDomain" />';
 aux += '<param name="movie" value="' +url+ '">';
 aux += '<param name="loop" value="false" />';
 aux += '<param name="menu" value="false" />';
 aux += '<param name="quality" value="high">';
 //aux += '<param name="wmode" value="transparent" />'; // se preciso, habilitar WMODE
 aux += '<embed src="' +url+ '" quality="high" wmode="transparent" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="' +largura+ '" height="' +altura+ '"></embed>';
 //aux += '<embed src="' +url+ '" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="' +largura+ '" height="' +altura+ '"></embed>';
 aux += '</object>';
 document.write (aux);
}



// -----------------------------

var passou=0;
var typeEl;
var reDigits = /^\d+$/;

String.prototype.trim = function(){
  return this.replace(/^\s*/, '').replace(/\s*$/, '');
}

String.prototype.haveNo = function(){
  return this.toLowerCase().search(/no/)>-1?true:false;
}

function mailCheck(m){
  return (m.search(/^[a-zA-Z][\.\w-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/)==-1||m.search(/\.{2,}|\.-|-\.|-{2,}|\._|_\./)>-1)?false:true;
}

function alerta(nC,el){
  window.alert('Por favor, preencha o campo ' +nC.toUpperCase()+ ' corretamente!');
  
  if(typeEl != 'radio' && typeEl != 'checkbox'){
	  try{
		el.focus();
		el.select();
	  }
	  catch(e){}
  }
}

function alertaNumber(nC,el){
  window.alert('O campo ' +nC.toUpperCase()+ ' deve conter apenas números!');
  
  if(typeEl != 'radio' && typeEl != 'checkbox'){
	  try{
		el.focus();
		el.select();
	  }
	  catch(e){}
  }
}

function isRadio(f,t){
  var fld = f.elements[t];
  var x, len = fld.length;
  for(x=0; x<len; ++x) if(fld[x].checked) break;
  return len<=x?false:true;
}

function validarCampos(f){
  var i,el,nC,vC,totalEl=f.elements.length,al='alerta(nC,el)',aln='alertaNumber(nC,el)';

  for(var i=0; i<totalEl; i++){
    el=f.elements[i];
    nC=el.name;
    nClass=el.className;
	vC=el.value;
	typeEl = el.type;

    if(typeEl!='hidden' && typeEl!='submit' && !nClass.haveNo()){

		if(typeEl!='file' && typeEl!='password'){
		  try{
			  vC=el.value.trim();
		  } catch(e){}
		  el.value=vC;
		}

		if(vC=='' && typeEl!='radio'){
		  eval(al);
		  return false;
		}

		if(typeEl=='radio' && !isRadio(f,nC)){
		  eval(al);
		  return false;
		}

		if(el.className.toLowerCase().search(/email/)>-1 && !mailCheck(vC)){
		  eval(al);
		  return false;
		}

		if(el.className.toLowerCase().search(/number/)>-1 && !reDigits.test(vC)){
		  eval(aln);
		  return false
		}

		if(passou==1){
		  window.alert('Por favor, aguarde. Processo em andamento!');
		  return false;
		}

	}
  }
  passou=1;
  return true;
}


function validarExtensao(fV,ext) {
	fV=fV.toLowerCase();
	if(fV!='' && ext.indexOf(fV.substr(fV.length-3).toLowerCase())==-1)
	  return false;
}


function validateExt(arq, ext){
	if(validarExtensao(arq, ext)==false){
	  window.alert('Formato de arquivo inválido!');
	  document.getElementById('file').innerHTML = document.getElementById('file').innerHTML;
	  return false;
	}
}

// ----- função para expandir menu
status = 0;
function mostrar(id){
  if (status == 0){
    $(id).show('normal');
    status = 1;
  }
  else{
    $(id).hide('normal');
    status = 0;
  }
}

