var ie6;

if (document.all) {
  if ((navigator.userAgent.indexOf('MSIE 5') > 0) || (navigator.userAgent.indexOf('MSIE 6') > 0)) {
    ie6 = true;
  }
}

function mouseOverBt(id, img){
  id.src = "/matricula/images/bts/"+img+"_over.jpg";
}

function mouseOutBt(id,img){
    id.src = "/matricula/images/bts/"+img+".jpg";
}

function mouseOverMenu(id,img){
    id.src = "/matricula/images/menusup/"+img+"_over.gif";
}
function mouseOutMenu(id,img){
    id.src = "/matricula/images/menusup/"+img+".gif";
}

function mouseOverTopo(id,img){
    id.src = "/matricula/images/menusup/"+img+"_over.png";
}
function mouseOutTopo(id,img){
    id.src = "/matricula/images/menusup/"+img+".png";
}

function tooltip(a, id, flag, e, span){
  span = document.getElementById(id);
  e = e ? e : window.event;
  
  if(flag == 1){
    span.style.display = 'block';
    span.style.position = 'relative';
    span.style.width = '230px';
    span.style.top = '3em';
    span.style.background = '#e0ffff';
    span.style.left = '0';
    span.style.padding = '5px 10px';
    span.style.border = '1px solid #999';
    span.style.color = '#000000';
    a.style.zIndex = '25';
  } else {
    a.style.position = 'relative';
    a.style.padding = '0';
    a.style.textDecoration = 'none';
    a.style.cursor = 'help';
    a.style.zIndex = '24';
    span.style.display = 'none';
  }
}

function fieldMask(objeto, evt, mask) {
  var LetrasU = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  var LetrasL = 'abcdefghijklmnopqrstuvwxyz';
  var Letras  = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
  var Numeros = '0123456789';
  var Fixos  = '().-:/ ';
  var Charset = " !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_/`abcdefghijklmnopqrstuvwxyz{|}~";

  evt = (evt) ? evt : (window.event) ? window.event : "";
  var value = objeto.value;
  if (evt) {
   var ntecla = (evt.which) ? evt.which : evt.keyCode;
   tecla = Charset.substr(ntecla - 32, 1);
   if (ntecla < 32) return true;

   var tamanho = value.length;
   if (tamanho >= mask.length) return false;

   var pos = mask.substr(tamanho,1);
   while (Fixos.indexOf(pos) != -1) {
    value += pos;
    tamanho = value.length;
    if (tamanho >= mask.length) return false;
    pos = mask.substr(tamanho,1);
   }

   switch (pos) {
     case '#' : if (tecla == '' || Numeros.indexOf(tecla) == -1) return false; break;
     case 'A' : if (LetrasU.indexOf(tecla) == -1) return false; break;
     case 'a' : if (LetrasL.indexOf(tecla) == -1) return false; break;
     case 'Z' : if (Letras.indexOf(tecla) == -1) return false; break;
     case '*' : objeto.value = value; return true; break;
     default : return false; break;
   }
  }
  objeto.value = value;
  return true;
}

function mask(obj, evt, type) {
  switch(type) {
    case 'cep': return fieldMask(obj, evt, '#####-###'); break
    case 'tel_ddd': return fieldMask(obj, evt, '(##) ####-####'); break
    case 'tel': return fieldMask(obj, evt, '####-####'); break
    case 'cpf': return fieldMask(obj, evt, '###.###.###-##'); break
    case 'cnpj': return fieldMask(obj, evt, '##.###.###/####-##'); break
    case 'data': return fieldMask(obj, evt, '##/##/####'); break
    default: return fieldMask(obj, evt, type); break;
  }
}

function is_email(email){
  var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
  if (er.test(email)) {
    return true;
  } else {
    return false;
  }
}


function is_cpf(strcpf)
{
  if (strcpf != "" && strcpf != null) {
    str_aux = "";
    for (i = 0; i <= strcpf.length - 1; i++) {
      if ((strcpf.charAt(i)).match(/\d/)) {
        str_aux += strcpf.charAt(i);
      }
      else if (!(strcpf.charAt(i)).match(/[\.\-]/)) {
        return false;
      }
    }
    
    if (str_aux.length != 11) {
      return false;
    }

    for (i=0;i<11;i++) {
      for (j=i+1;j<11;j++) {
        if (strcpf.charAt(i) != strcpf.charAt(j)) {
          j = 12;
          i = 12;
        }
      }
    }

    if (i == 11) {
      return false;
    }
  
    soma1 = soma2 = 0;

    for (i = 0; i <= 8; i++) {
      soma1 += str_aux.charAt(i) * (10-i);
      soma2 += str_aux.charAt(i) * (11-i);
    }

    d1 = ((soma1 * 10) % 11) % 10;
    d2 = (((soma2 + (d1 * 2)) * 10) % 11) % 10;

    if ((d1 != str_aux.charAt(9)) || (d2 != str_aux.charAt(10))) {
      return false;
    }

    return true;
  } else {
    return false;
  }
}

function abrirCarregando()
{
  if ($('divLoadingAjax') == null) {
    var b = document.getElementsByTagName("BODY");
    if (!b) { return false; };
    b = b[0];

    var layer = document.createElement("DIV");
    layer.id = 'divLoadingAjax';  
    layer.className = 'loading';  
    layer.innerHTML = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0\" width=\"200\" height=\"50\" id=\"loading\" align=\"middle\"><param name=\"movie\" value=\"/matricula/images/loading.swf\" /><param name=\"quality\" value=\"high\" /><param name=\"bgcolor\" value=\"#ffffff\" /><param name=\"wmode\" value=\"transparent\"><embed src=\"/matricula/images/loading.swf\" width=\"200\" height=\"50\" align=\"middle\" quality=\"high\" bgcolor=\"#ffffff\" name=\"loading\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" wmode=\"transparent\" /></object>";
    b.appendChild(layer);
  } else {
    $('divLoadingAjax').style.display = '';
  }
  
  if (ie6) {
    var s = document.getElementsByTagName("SELECT");
    for (i=0; i<s.length; i++) {
      s[i].style.display = 'none';  
    }
  }
}

function fecharCarregando()
{
  if ($('divLoadingAjax') != null) {
    $('divLoadingAjax').style.display = 'none';
  }
  
  if (ie6) {  
    var s = document.getElementsByTagName("SELECT");
    for (i=0; i<s.length; i++) {
      s[i].style.display = '';  
    }
  }
} 
