﻿function setMouseOverColor(element) 
{ 
    oldgridSelectedColor = element.style.backgroundColor; 
    element.style.backgroundColor='#DEECEF'; 
    element.style.cursor='hand'; 
} 

function setMouseOutColor(element) 
{ 
    element.style.backgroundColor = oldgridSelectedColor; 
    element.style.textDecoration = 'none'; 
} 

function setMouseClicked(element, index) 
{ 
    ResetTheTable(index); 
    oldgridSelectedColor = "#DEECEF";
} 

function ResetTheTable(index) 
{ 
    var vTable = document.getElementById("tableList"); 
    var vRows = vTable.getElementsByTagName("tr"); 

    // we start from 1 because 0 is the header 
    for(i = 1; i < vRows.length; i++){ 
        if(i%2) 
        { 
            vRows[i].style.backgroundColor = '#F7F6F3'; 
            vRows[i].style.color = '#333333'; 
            vRows[i].style.fontWeight = 'normal'; 
        } 
        else 
        { 
            vRows[i].style.backgroundColor = '#FFFFFF'; 
            vRows[i].style.color = '#284775'; 
            vRows[i].style.fontWeight = 'normal'; 
        } 
    } 
    
    vRows[index+1].style.backgroundColor = '#DEECEF'; 
    vRows[index+1].style.color = '#333333'; 
    vRows[index+1].style.fontWeight = 'bold'; 
} 

// Mascara CPF
function Mascara(tipo, campo, teclaPress) {
    if (window.event)
    {
        var tecla = teclaPress.keyCode;
    } else {
        tecla = teclaPress.which;
    }

    var s = new String(campo.value);
    // Remove todos os caracteres à seguir: ( ) / - . e espaço, para tratar a string denovo.
    s = s.replace(/(\.|\(|\)|\/|\-| )+/g,'');

    tam = s.length + 1;

    if ( tecla != 9 && tecla != 8 ) {
        switch (tipo)
        {
        case 'CPF' :
            if (tam > 3 && tam < 7)
                campo.value = s.substr(0,3) + '.' + s.substr(3, tam);
            if (tam >= 7 && tam < 10)
                campo.value = s.substr(0,3) + '.' + s.substr(3,3) + '.' + s.substr(6,tam-6);
            if (tam >= 10 && tam < 12)
                campo.value = s.substr(0,3) + '.' + s.substr(3,3) + '.' + s.substr(6,3) + '-' + s.substr(9,tam-9);
        break;

        case 'CNPJ' :

            if (tam > 2 && tam < 6)
                campo.value = s.substr(0,2) + '.' + s.substr(2, tam);
            if (tam >= 6 && tam < 9)
                campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,tam-5);
            if (tam >= 9 && tam < 13)
                campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,3) + '/' + s.substr(8,tam-8);
            if (tam >= 13 && tam < 15)
                campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,3) + '/' + s.substr(8,4)+ '-' + s.substr(12,tam-12);
        break;

        case 'TEL' :
            if (tam > 2 && tam < 4)
                campo.value = '(' + s.substr(0,2) + ') ' + s.substr(2,tam);
            if (tam >= 7 && tam < 11)
                campo.value = '(' + s.substr(0,2) + ') ' + s.substr(2,4) + '-' + s.substr(6,tam-6);
        break;

        case 'DATA' :
            if (tam > 2 && tam < 4)
                campo.value = s.substr(0,2) + '/' + s.substr(2, tam);
            if (tam > 4 && tam < 11)
                campo.value = s.substr(0,2) + '/' + s.substr(2,2) + '/' + s.substr(4,tam-4);
        break;
        
        case 'CEP' :
            if (tam > 5 && tam < 7)
                campo.value = s.substr(0,5) + '-' + s.substr(5, tam);
        break;
        }
    }
}

function stripCharsNotInBag(bag, campo) { //campo só deve ser passado se for para alterar seu valor
	//bag = "0123456789";

	var temp="";
	if (campo==null) temp=this;
	if (campo!=null) temp=campo.value;

	var result = "";
	for (i=0; i<temp.length; i++){
		character = temp.charAt(i);
		if (bag.indexOf(character) != -1)
			result += character;
	}
	if (campo!=null && campo.value!=result) {
		campo.value=result;
	}
	return result;
}

// create the prototype on the String object
String.prototype.stripCharsNotInBag = stripCharsNotInBag;

function stripNotNumber(num) {
	return num.stripCharsNotInBag("0123456789");
}

var BASE_DATE = new Date("1997","09","07")  // 1999-out-07
var MAX_DATE = new Date("2025","01","21")   // 2025-fev-21

function ValidaData (data) {
	dt = data.value;

	if (dt.length<10) {
		alert("Tamnho inválido, digitar no formato dd/mm/aaaa.");
		data.select();
		return false;
	}

	dia = dt.substring(0,2);
	mes = dt.substring(3,5);
	ano = dt.substring(6,10);

	// month argument must be in the range 1 - 12
	// javascript month range : 0- 11
	var tempDate = new Date(ano,mes-1,dia);
		
	if ( (ano == tempDate.getFullYear()) &&
	     (mes == (tempDate.getMonth()+1)) &&
	     (dia == tempDate.getDate()) ) {
		var tmp = new Date();
		var todayDate = new Date(tmp.getFullYear(), tmp.getMonth(), tmp.getDate());

	     	//return (tempDate >= BASE_DATE && tempDate<=MAX_DATE && tempDate>=todayDate)
	     	return (tempDate >= BASE_DATE && tempDate<=MAX_DATE)
	} else {
		alert("Data inválida, digitar no formato dd/mm/aaaa.");
		data.select();
		return false;
	}
}

function formataCPF(campo) {
    // retira tudo que nao eh numerico
    var temp=campo.value;
    var valor="";

    valor=stripNotNumber(temp);

    if (valor.length>14) { valor=valor.substring(0,14); }

    var j=0;
    temp="";
    
    for (var tam=0; tam < valor.length; tam++) 
    {
        if (valor.length < 12)
        {
            if (j==0) {
                temp += valor.substring(tam,tam + 1);
                if ( (tam==2) && (valor.length>3) ) { j++; temp += "."; }
            } else if (j==1) {
                temp += valor.substring(tam,tam + 1);
                if ( (tam==5) && (valor.length>6) ) { j++; temp += "."; }
            } else if (j==2) {
                temp+=valor.substring(tam, tam + 1);
                if ( (tam==8) && (valor.length>9) ) { j++; temp += "-"; }
            } else if (j==3) {
                temp += valor.substring(tam, tam + 1);
            }
        }
        else
        {
            if (j==0) {
                temp += valor.substring(tam,tam + 1);
                if ( (tam==1) && (valor.length>2) ) { j++; temp += "."; }
            } else if (j==1) {
                temp += valor.substring(tam,tam + 1);
                if ( (tam==4) && (valor.length>5) ) { j++; temp += "."; }
            } else if (j==2) {
                temp+=valor.substring(tam, tam + 1);
                if ( (tam==7) && (valor.length>8) ) { j++; temp += "/"; }
            } else if (j==3) {
                temp+=valor.substring(tam, tam + 1);
                if ( (tam==11) && (valor.length>12) ) { j++; temp += "-"; }
            } else if (j==4) {
                temp += valor.substring(tam, tam + 1);
            }
        }   
    }

    if (campo.value!=temp) 
    {
        campo.value=temp;
    }
}

// Menu Floting

/* 
   Float Submit Button To Right Edge Of Window
   Version 1.0
   April 11, 2010

   Will Bontrager
   http://www.willmaster.com/
   Copyright 2010 Bontrager Connection, LLC

   Generated with customizations on June 06, 2010 at
   http://www.willmaster.com/library/manage-forms/floating-submit-button.php

   Bontrager Connection, LLC grants you 
   a royalty free license to use or modify 
   this software provided this notice appears 
   on all copies. This software is provided 
   "AS IS," without a warranty of any kind.
*/

//*****************************//

/** Five places to customize **/

// Place 1:
// The id value of the button.

var ButtonId = "floatingbutton";


// Place 2:
// The width of the button.

var ButtonWidth = 100;


// Place 3:
// Left/Right location of button (specify "left" or "right").

var ButtonLocation = "right";


// Place 4:
// How much space (in pixels) between button and window left/right edge.

var SpaceBetweenButtonAndEdge = 0;


// Place 5:
// How much space (in pixels) between button and window top edge.

var SpaceBetweenButtonAndTop = 0;


/** No other customization required. **/

//************************************//

TotalWidth = parseInt(ButtonWidth) + parseInt(SpaceBetweenButtonAndEdge);
ButtonLocation = ButtonLocation.toLowerCase();
ButtonLocation = ButtonLocation.substr(0,1);
var ButtonOnLeftEdge = (ButtonLocation=='l') ? true : false;

function AddButtonPlacementEvents(f)
{
   var cache = window.onload;
   if(typeof window.onload != 'function') { window.onload = f; }
   else { window.onload = function() { if(cache) { cache(); } f(); }; }
   cache = window.onresize;
   if(typeof window.onresize != 'function') { window.onresize = f; }
   else { window.onresize = function() { if(cache) { cache(); } f(); }; }
}

function WindowHasScrollbar() {
var ht = 0;
if(document.all) {
   if(document.documentElement) { ht = document.documentElement.clientHeight; }
   else { ht = document.body.clientHeight; }
   } 
else { ht = window.innerHeight; }
if (document.body.offsetHeight > ht) { return true; }
else { return false; }
}

function GlueButton(ledge) {
var did = document.getElementById(ButtonId);
did.style.top = SpaceBetweenButtonAndTop + "px";
did.style.width = ButtonWidth + "px";
did.style.left = ledge + "px";
did.style.display = "block";
did.style.zIndex = "9999";
did.style.position = "fixed";
}

function PlaceTheButton() {
if(ButtonOnLeftEdge) {
   GlueButton(SpaceBetweenButtonAndEdge);
   return;
   }
if(document.documentElement && document.documentElement.clientWidth) { GlueButton(document.documentElement.clientWidth-TotalWidth); }
else {
   if(navigator.userAgent.indexOf('MSIE') > 0) { GlueButton(document.body.clientWidth-TotalWidth+19); }
   else {
      var scroll = WindowHasScrollbar() ? 0 : 15;
      if(typeof window.innerWidth == 'number') { GlueButton(window.innerWidth-TotalWidth-15+scroll); }
      else { GlueButton(document.body.clientWidth-TotalWidth+15); }
      }
   }
}

AddButtonPlacementEvents(PlaceTheButton);
//--></script>