// JavaScript Document
//////////////////////////////////////////////////////////////////////////////////////
//ADM

//Funcao mask utilizada para criar mascaras para campos

function mask(o,opt){
    v_obj=o
    v_opt=opt
    setTimeout("execMask()",1)
}

function execMask(){
    v_obj.value=doMask(v_opt, v_obj.value)
}

////VALIDACOES
//-*-* CPF
function isCPF(cpf) {
   var filtro = /^\d{3}.\d{3}.\d{3}-\d{2}$/i;
   if (!filtro.test(cpf)) {
      return false;
   }

   cpf = cpf.replace(/[.-]/g, "");

   if (cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" ||
		cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" ||
		cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" ||
		cpf == "88888888888" || cpf == "99999999999") {
      return false;
   }

   soma = 0;
   for (i = 0; i < 9; i++) soma += parseInt(cpf.charAt(i)) * (10 - i);
   resto = 11 - (soma % 11);
   if (resto == 10 || resto == 11) resto = 0;
   if (resto != parseInt(cpf.charAt(9))) {
      return false;
   }

   soma = 0;
   for (i = 0; i < 10; i++) soma += parseInt(cpf.charAt(i)) * (11 - i);
   resto = 11 - (soma % 11);
   if (resto == 10 || resto == 11) resto = 0;
   if (resto != parseInt(cpf.charAt(10))) {
      return false;
   }
   return true;
}
//-*-* CNPJ
function isCNPJ(cnpj) {
   var filtro = /^\d{2}.\d{3}.\d{3}\/\d{4}-\d{2}$/i;

   if (!filtro.test(cnpj)) {
      return false;
   }

   cnpj = cnpj.replace(/[.\/-]/g, "");

   var a = [];
   var b = new Number;
   var c = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
   for (i = 0; i < 12; i++) {
      a[i] = cnpj.charAt(i);
      b += a[i] * c[i + 1];
   }
   if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11 - x }
   b = 0;
   for (y = 0; y < 13; y++) {
      b += (a[y] * c[y]);
   }
   if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11 - x; }
   if ((cnpj.charAt(12) != a[12]) || (cnpj.charAt(13) != a[13])) {
      return false;
   }
   return true;

}


///VALIDADCOES

//----------------------------------------------------------------------------------------------//

function doMask(option, value) {
	value = value.replace(/\D/g,"");
	
	switch (option) {
		case "phone": // (11) 1111-1111
			value=value.replace(/^(\d{2})(\d)/g,"($1) $2");
    		value=value.replace(/(\d{4})(\d)/,"$1-$2");
		break;
		case "vox": // 1111-11
			value=value.replace(/^(\d{4})(\d)/g,"$1-$2");
		break;
		case "zipcode": // CEP: 11111-11
			value=value.replace(/^(\d{5})(\d)/g,"$1-$2");
		break;
		case "date": // 11/11/1111
			value=value.replace(/^(\d{2})(\d)/g,"$1/$2");
			value=value.replace(/(\d{2})(\d)/,"$1/$2");
		break;
		case "decimal": // 11111,11
			value=value.replace(/(\d)(\d{2})$/g,"$1,$2");
		break;
      case "cpf": // 111.111.111-11
         value = value.replace(/^(\d{3})(\d)/g, "$1.$2");
         value = value.replace(/(\d{3})(\d)/, "$1.$2");
         value = value.replace(/(\d{3})(\d)/, "$1-$2");
      break;
	}
	return value;
}
// Funcao utilizada para bloquear a digitacao de caracteres que nao sejam numeros
function noDigit( o ){
	var objVal = o.value;
	var objId = o.id;
	
    objVal=objVal.replace(/\D/g,"");  
    document.getElementById( objId ).value= objVal;  
}



//////////////////////////////////////////////////////////////////////////////////////
//Funcao para exibir data
hoje = new Date()
dia = hoje.getDate()
dias = hoje.getDay()
mes = hoje.getMonth()
ano = hoje.getYear()

if (ano < 2000)    // Y2K Fix, Isaac Powell
	ano = ano + 1900; 		
	if (dia < 10)
		dia = "0" + dia

function CriaArray (n) {
	this.length = n
}

NomeDia = new CriaArray(7)
NomeDia[0] = "Domingo"
NomeDia[1] = "Segunda-feira"
NomeDia[2] = "Ter&ccedil;a-feira"
NomeDia[3] = "Quarta-feira"
NomeDia[4] = "Quinta-feira"
NomeDia[5] = "Sexta-feira"
NomeDia[6] = "S&aacute;bado"
NomeMes = new CriaArray(12)
NomeMes[0] = "janeiro"
NomeMes[1] = "fevereiro"
NomeMes[2] = "mar&ccedil;o"
NomeMes[3] = "abril"
NomeMes[4] = "maio"
NomeMes[5] = "junho"
NomeMes[6] = "julho"
NomeMes[7] = "agosto"
NomeMes[8] = "setembro"
NomeMes[9] = "outubro"
NomeMes[10] = "novembro"
NomeMes[11] = "dezembro"

function escreveData(){
	document.write (dia + " de " + NomeMes[mes] + " de " + ano)
}

function escreveDia (){
	document.write (NomeDia[dias])
}
//Funcao para exibir data
//////////////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////////////
//Funcoes Dreamweaver
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_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];}
}

function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//Funcoes Dreamweaver
//////////////////////////////////////////////////////////////////////////////////////

//ADM
//////////////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////////////
//Site

//////////////////////////////////////////////////////////////////////////////////////
///Saudacao: Bom dia, tarde e noite
var hoje = new Date();
var hours = hoje.getHours();
var saudacao = '';
if (hours >=0 && hours <12){
	saudacao = "Bom dia"
}
if(hours >=12 && hours <18){
	saudacao = "Boa tarde"
}
//if(hours >18 && hours <=23){
if(hours >=18){
	saudacao = "Boa noite";
}
function escreveSaudacao(){
	document.write(saudacao)
}
///Saudacao: Bom dia, tarde e noite
//////////////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////////////
///Iframe ajustavel
function iframeAutoHeight(altura){
    //by Micox - elmicox.blogspot.com - elmicox.com - webly.com.br  
    if(navigator.appName.indexOf("Internet Explorer")>-1){ //ie sucks
        var func_temp = function(){
            var val_temp = altura.contentWindow.document.body.scrollHeight
            altura.style.height = val_temp + "px";
        }
        setTimeout(function() { func_temp() },100) //ie sucks
    }else{
        var val = altura.contentWindow.document.body.parentNode.offsetHeight
        altura.style.height= val + "px";
    }    
}
///Iframe ajustavel
//////////////////////////////////////////////////////////////////////////////////////

//Site
//////////////////////////////////////////////////////////////////////////////////////

