var isIE = (navigator.appName.indexOf('Internet Explorer') != -1);
var url = document.location
var titulo = document.title

	function addFavoritos()
	{
		if(document.all)
			window.external.AddFavorite(url,titulo)
	}
function pegamouse(e){
  var x=(netscape)?e.pageX:event.x+document.body.scrollLeft;
  if((x>720)||(x<63)){
    if (x>720){skn.left=x+Xoffset-((netscape)?e.pageX:event.x+document.body.scrollLeft-720);}
    if (x<63){skn.left=1;}
  }else{
    skn.left=x+Xoffset;
  }
  var y=(netscape)?e.pageY:event.y+document.body.scrollTop;skn.top=y+yyy;
}

function kill(){
  if(!velho){yyy=-1000;skn.visibility="hidden";}
}
function passamouse(src,cor,sentido){
  if (sentido == "entra") {
    if(!src.contains(event.fromElement)){
      src.style.cursor='hand';src.bgColor=cor;
    }
  }
  if (sentido == "sai") {
    if(!src.contains(event.toElement)){
      src.style.cursor='default';src.bgColor=cor;
    }
  }
}

function cliquemouse(src){
  if(event.srcElement.tagName=='TD'){
    src.children.tags('A')[0].click();
  }
}


	
	var datas = new Date(); 
	var dia = datas.getDate();
	var DiaHoje = datas.getDay();
	var EsteMes = datas.getMonth();
	var Ano = datas.getYear();
	var DiaMes = datas.getDate();
	var timerID = null;
	var timerRunning = false;
	
	if (DiaMes < 10) {
		DiaMes = "0" + DiaMes
	}
	function CriaTab (n)
	{ 
		this.length = n 
		for (var x = 1 ; x<= n ; x++)
		{
			this[x] = ""
		}
	} 
	NomeDia = new CriaTab(7) 
	NomeDia[0] = "Domingo" 
	NomeDia[1] = "Segunda-feira" 
	NomeDia[2] = "Terça-feira" 
	NomeDia[3] = "Quarta-feira" 
	NomeDia[4] = "Quinta-feira" 
	NomeDia[5] = "Sexta-feira" 
	NomeDia[6] = "Sábado" 
	
	DiaSemana = NomeDia[DiaHoje] 
	
MesAtual = new CriaTab(12)
	MesAtual[0] = "01"
	MesAtual[1] = "02"
	MesAtual[2] = "03"
	MesAtual[3] = "04"
	MesAtual[4] = "05"
	MesAtual[5] = "06"
	MesAtual[6] = "07"
	MesAtual[7] = "08"
	MesAtual[8] = "09"
	MesAtual[9] = "10"
	MesAtual[10] = "11"
	MesAtual[11] = "12"
	
	Mes = MesAtual[EsteMes]
	
function stopclock ()
	{
		if(timerRunning)
			clearTimeout(timerID);
		timerRunning = false;
	}
	
	function zeroclock ()
	{

	var hours = 00;
                var contador = 00;
		var minutes = 1;
                var seconds = 59 - contador
                var timeValue = "" + hours
         	timeValue += ((minutes < 10) ? ":0" : ":") + minutes
		timeValue += ((seconds < 10) ? ":0" : ":") + seconds
		clock.value = timeValue;
	}

	function showtime()
	{
		var now = new Date();
		var hours = now.getHours();
		var minutes = now.getMinutes();
		var seconds = now.getSeconds()
		var timeValue = "" + hours
		//var timeValue = "" + ((hours >12) ? hours -12 :hours)
	
		timeValue += ((minutes < 10) ? ":0" : ":") + minutes
		timeValue += ((seconds < 10) ? ":0" : ":") + seconds
	 // timeValue += (hours >= 12) ? " PM" : " AM"
	
		clock.value = timeValue;
	
		// you could replace the above with this
		// and have a clock on the status bar:
		//window.status = timeValue;
	
		timerID = setTimeout("showtime()",1000);
		timerRunning = true;
	}
                var contador = 00;
		var minutes = 1;

	function showtime1()
	{
		var hours = 00;
                var seconds = 59 - contador
		contador += 1;
		var timeValue = "" + hours
                if (seconds==0){
                contador = 1;
                minutes = minutes - 1;     
                }
		timeValue += ((minutes < 10) ? ":0" : ":") + minutes
		timeValue += ((seconds < 10) ? ":0" : ":") + seconds

		clock.value = timeValue;
		timerID = setTimeout("showtime1()",1000);
		timerRunning = true;
        
        }
	
	function startclock ()
	{
		// Make sure the clock is stopped
		stopclock();
		showtime();
	}

	function startclock1 ()
	{
		// Make sure the clock is stopped
		stopclock();
		showtime1();
	}

function setPointer(theRow, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor = theMarkColor;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()) {
        if (theAction == 'out') {
            newColor = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor = theMarkColor;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor = (thePointerColor != '')
                     ? thePointerColor
                     : theDefaultColor;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function


function tirarZerosEsquerda(STR){
  var sAux='';

  var i=0;

  STR=new String(STR);

  

  while (i < STR.length ){

    if ((STR.charAt(i)!='.') && (STR.charAt(i)!=',') && (STR.charAt(i)!=':')){

	  sAux += STR.charAt(i);

    }

	i++

  }

  STR = new String(sAux);

  sAux = '';

  i=0;

  

  while (i < STR.length ){

    if (STR.charAt(i) != '0'){

      sAux = STR.substring(i,STR.length)

	  i = STR.length;

	}

    i++;

  }

  return  sAux;

}
function formatarOnKeyUp(OBJ){

  var decimal,inteiro;

  var i,count;

  STR = new String(OBJ.value);

  STR = tirarZerosEsquerda(STR);

  inteiro='';

  if (isIE) {

		if (STR.length == 1){

			  inteiro  = '0';

			  decimal = '0' + STR;

			}

			else { 

			  if (STR.length == 2){

				  inteiro  = '0';

				  decimal = STR;

				}

				else{

				  decimal = STR.substring(STR.length-2,STR.length);

				  i=3;

				  count=0;

				  while (i<=STR.length){

			 		if (count==3) {

					  inteiro = '.' + inteiro;

					  count = 0;

					}

				    inteiro = STR.charAt(STR.length-i) + inteiro;

					count++;

					i++;

				  }

				}

			}

    

  

		if (inteiro == '') {

		  inteiro = '0';

		}

  

		if (decimal == '') {

		  decimal = '00';

		}

		OBJ.value = inteiro+','+decimal;

  }

}



function formatarOnKeyDown(OBJ){

  var decimal,inteiro;

  var i,count;

  STR = new String(OBJ.value);

  

  inteiro='';

  

  if (isIE) {	  

	if (OBJ.maxLength > STR.length){     

	  STR = tirarZerosEsquerda(STR); //ESTA FUNCAO TIRA TAMBEM PONTO E VIRGULA

	  

	  if ( ((event.keyCode > 47) && (event.keyCode < 59)) || ((event.keyCode > 95) && (event.keyCode < 106))   ){

	      

			if (STR.length == 0){

			  inteiro  = '0';

			  decimal = '0' + STR;

			}

			else { 

			  if (STR.length == 1){

			    inteiro  = '0';

			    decimal = STR;

			  }

			  else{

			    decimal = STR.substring(STR.length-1,STR.length);

			    i=2;

			    count=0;

			    while (i<=STR.length){

			 		if (count==3) {

			  	  inteiro = '.' + inteiro;

			  	  count = 0;

			  	}

			      inteiro = STR.charAt(STR.length-i) + inteiro;

			  	count++;

			  	i++;

			    }

			  }

			}   

	 

	  }

	  else{ 

	    if (event.keyCode == 8){



	      if (STR.length == 0){

			  inteiro  = '0';

			  decimal = '000';

			}

			else { 

			  if (STR.length == 1){

			    inteiro  = '0';

			    decimal = '00' + STR;

			  }

			  else { 

			    if (STR.length == 2){

		          inteiro  = '0';

			      decimal = '0' + STR;

			     }

		         else{

	 			   decimal = STR.substring(STR.length-3,STR.length);

				   i=4;

				   count=0;

				   while (i<=STR.length){

			 		 if (count==3) {

					   inteiro = '.' + inteiro;

					   count = 0;

					  }

				      inteiro = STR.charAt(STR.length-i) + inteiro;

					  count++;

					  i++;

				    }

			     }

			  } 

	      }

	    }

	    else {

	      

	      if (STR.length == 1){

		 	  inteiro  = '0';

		      decimal = '0' + STR;

			}

			else { 

			  if (STR.length == 2){

				  inteiro  = '0';

				  decimal = STR;

				}

				else{

				  decimal = STR.substring(STR.length-2,STR.length);

				  i=3;

				  count=0;

				  while (i<=STR.length){

			 		if (count==3) {

					  inteiro = '.' + inteiro;

					  count = 0;

					}

				    inteiro = STR.charAt(STR.length-i) + inteiro;

					count++;

					i++;

				  }

				}

			}        

	    }

	  }

	  

	  if (inteiro == '') {

	    inteiro = '0';

	  }

  

	  if (decimal == '') {

	    decimal = '00';

	  }

	  OBJ.value = inteiro+','+decimal;

	}

  }

}



function refreshCampo(obj){
	if (isIE) {
		obj.value = obj.value;
	}
}

function onlynum(e) {
	var keyNumber = (isIE) ? event.keyCode : e.which;
	if (((keyNumber<48)||(keyNumber>57)) && (keyNumber!=13) && (keyNumber!="0") && (keyNumber!=8)) {
		if (isIE) event.keyCode=0;
		return false;
	}
}

function FormataCpf(campo,tammax,teclapres) {
 var tecla = teclapres.keyCode;
  
 vr = event.srcElement.value;
 vr = vr.replace( "/", "" );
 vr = vr.replace( "/", "" );
 vr = vr.replace( ",", "" );
 vr = vr.replace( ".", "" );
 vr = vr.replace( ".", "" );
 vr = vr.replace( ".", "" );
 vr = vr.replace( ".", "" );
 vr = vr.replace( "-", "" );
 vr = vr.replace( "-", "" );
 vr = vr.replace( "-", "" );
 vr = vr.replace( "-", "" );
 vr = vr.replace( "-", "" );
 tam = vr.length;

 if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

 if (tecla == 8 ){ tam = tam - 1 ; }
  
 if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
  if ( tam <= 2 ){ 
    event.srcElement.value = vr ; }
   if ( (tam > 2) && (tam <= 5) ){
    event.srcElement.value = vr.substr( 0, tam - 2 ) + '-' + vr.substr( tam - 2, tam ) ; }
   if ( (tam >= 6) && (tam <= 8) ){
    event.srcElement.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ; }
   if ( (tam >= 9) && (tam <= 11) ){
    event.srcElement.value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ; }
   if ( (tam >= 12) && (tam <= 14) ){
    event.srcElement.value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ; }
   if ( (tam >= 15) && (tam <= 17) ){
    event.srcElement.value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ;}
 }  
}

function Verifica_campo_CPF(campo) {
var CPF = campo.value; // Recebe o valor digitado no campo

CPF = CPF.replace( ".", "" );
CPF = CPF.replace( ".", "" );
CPF = CPF.replace( "-", "" );

// Aqui começa a checagem do CPF
var POSICAO, I, SOMA, DV, DV_INFORMADO;
var DIGITO = new Array(10);
DV_INFORMADO = CPF.substr(9, 2); // Retira os dois últimos dígitos do número informado

// Desemembra o número do CPF na array DIGITO
for (I=0; I<=8; I++) {
  DIGITO[I] = CPF.substr( I, 1);
}

// Calcula o valor do 10º dígito da verificação
POSICAO = 10;
SOMA = 0;
   for (I=0; I<=8; I++) {
      SOMA = SOMA + DIGITO[I] * POSICAO;
      POSICAO = POSICAO - 1;
   }
DIGITO[9] = SOMA % 11;
   if (DIGITO[9] < 2) {
        DIGITO[9] = 0;
}
   else{
       DIGITO[9] = 11 - DIGITO[9];
}

// Calcula o valor do 11º dígito da verificação
POSICAO = 11;
SOMA = 0;
   for (I=0; I<=9; I++) {
      SOMA = SOMA + DIGITO[I] * POSICAO;
      POSICAO = POSICAO - 1;
   }
DIGITO[10] = SOMA % 11;
   if (DIGITO[10] < 2) {
        DIGITO[10] = 0;
   }
   else {
        DIGITO[10] = 11 - DIGITO[10];
   }

// Verifica se os valores dos dígitos verificadores conferem
DV = DIGITO[9] * 10 + DIGITO[10];
   
   if (CPF.length != 11 || CPF == "00000000000" || CPF == "11111111111" ||
           CPF == "22222222222" || CPF == "33333333333" || CPF == "44444444444" ||
           CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" ||
           CPF == "88888888888" || CPF == "99999999999"){
	         alert('O CPF digitado é inválido!');
      campo.focus();

           return false;
   }
   if (DV != DV_INFORMADO) {
      alert('O CPF digitado é inválido!');
      campo.focus();
      return false;
   } 
}

function mascara(mascara,objeto) {
	if (objeto.value.length >= mascara.length){
		objeto.value = objeto.value.substring(0,objeto.value.length-1);
		return true;
	}
	var itemMascara	= '';
	var itemValue	= '';
	itemMascara = mascara.charAt(objeto.value.length);
	if (itemMascara !== '0') {
		objeto.value += itemMascara;
	}
}
