/* Abre um popup pré-configurado.
 */
function popup(url, width, height, scrollbars)
{
	var config = 'width=' + width + ',height=' + height 
		+ ',menubar=1,toolbar=0,location=0,statusbar=1,scrollbars='
		+ (scrollbars == 1 ? '1' : '0') + ',resizable=0,top='
		+ ((window.screen.height - height) / 4) + ',left='
		+ ((window.screen.width - width) / 2);
	var o = window.open(url, '', config);
}

/* Obtém um objeto DOM
 */
function getDOM(id, win_obj)
{
	if(win_obj == null)
			win_obj = window;
	var o = win_obj.document.all ? win_obj.document.all[id] : win_obj.document.getElementById(id);
	return o;
}

/* Função-base do relógio da barra superior
 */
function setClock()
{
	var d = new Date();
	
	var dia = d.getDate();
	var mes = d.getMonth() + 1;
	var ano = d.getFullYear();
	var hora = d.getHours();
	var minuto = d.getMinutes();
	var segundo = d.getSeconds();
	
	if(dia < 10) dia = '0' + dia;
	if(mes < 10) mes = '0' + mes;
	if(hora < 10) hora = '0' + hora;
	if(minuto < 10) minuto = '0' + minuto;
	if(segundo < 10) segundo = '0' + segundo;
	
	var data = dia + '/' + mes + '/' + ano + ' - ' + hora+ ':' + minuto;// + ':' + segundo;
	try {
		getDOM('lrRelogio').innerHTML = data;
		setTimeout('setClock()', 15000);
	}
	catch(err) { return; }
}

/* Alternância de cor */
function swap_bgcolor(obj_id, color) {
	var obj = getDOM(obj_id);
	if(!obj) return;
	if(!obj.style.backgroundColorFix) {
		if(color == null) {
				obj.style.backgroundColor = '';
		}
		else {
			obj.style.backgroundColor = color;
		}
	}
}

/* Máscara de data */
function mascData(obj, e) {
	if(e.keyCode == 8 || e.keyCode == 46) return;
	/*if(obj.value.match(/^(0-9|\/)+$/) == null) 
			obj.value = "";*/
	if(obj.value.length == 2) obj.value += "/";
	else if(obj.value.length == 5) obj.value += "/";
}

/* Verificação de data e hora
 * A data deve estar dentro da época padrão do Unix
 */
function verificarData(data, hora) {
	if(hora == null) {
		hora = '00:00:00';
	}
	var a = data.split('/');
	if(a.length != 3) {
		a = data.split('-');
	}
	var b = hora.split(':');
	if(b.length == 2) {
		b[2] = '00';
	}
	var ano = parseInt(a[2], 10);
	var mes = parseInt(a[1], 10) - 1;
	var dia = parseInt(a[0], 10);
	var hora = parseInt(b[0], 10);
	var minuto = parseInt(b[1], 10);
	var segundo = parseInt(b[2], 10);
	
	var d = new Date(ano, mes, dia, hora, minuto, segundo, 0);
	return d.getTime() > 0;
}
var tamanho = "13";
function aumentaTexto() {
	var texto = document.getElementById('texto');
	var novoTamanho = tamanho+2;
	if (novoTamanho < 25) {
		tamanho = novoTamanho;
		texto.style.fontSize = novoTamanho;
		}
	}
	function diminuiTexto() {
		var texto = document.getElementById('texto');
		var novoTamanho = tamanho-2;
	if (novoTamanho > 8) {
		tamanho = novoTamanho;
		texto.style.fontSize = novoTamanho;
		}
}
function changeFontSize() {
	var c = document.getElementById('conteudo');
	if(c.style.fontSize == '' || c.style.fontSize == 'small') {
		c.style.fontSize = 'medium';
		createCookie('fontSizeCursoImasters','medium',30);
	} else if(c.style.fontSize == 'medium') {
		c.style.fontSize = 'large';
		createCookie('fontSizeCursoImasters','large',30);
	} else if(c.style.fontSize == 'large') {
		c.style.fontSize = 'x-small';
		createCookie('fontSizeCursoImasters','x-small',30);
	} else {
		c.style.fontSize = 'small';
		createCookie('fontSizeCursoImasters','small',30);
	}
}

function verifyFontSize() {
	var cookie = readCookie('fontSizeCursoImasters')
	
	if(cookie) {
		document.getElementById('conteudo').style.fontSize = cookie;
	}
}
function isNum( caractere )   
{ 
	var strValidos = "0123456789" 
	  
	if ( strValidos.indexOf( caractere ) == -1 ) 
	  
		return false; 		  
		return true;   
} 
  
function validaTecla(campo, event)   
{   
	var BACKSPACE= 8; 
	  
	var key; 
	  
	var tecla; 	  
	  
	CheckTAB=true; 
	  
	if(navigator.appName.indexOf("Netscape")!= -1)	  
		tecla= event.which;	  
	else 
	  
	tecla= event.keyCode; 	  
	  
	key = String.fromCharCode( tecla); 
	  
	//alert( 'key: ' + tecla + ' -> campo: ' + campo.value); 	  
	  
	if ( tecla == 13 ) 
	  
		return false; 
	  
	if ( tecla == BACKSPACE ) 
	  
		return true; 
		  
		return ( isNum(key)); 
  
}  

function isNum( caractere )   
{ 
  
	var strValidos = "0123456789," 
	  
	if ( strValidos.indexOf( caractere ) == -1 ) 
	  
		return false; 		  
		return true;   
} 
  
function validaLimite(campo, event)   
{   
	var BACKSPACE= 8; 
	  
	var key; 
	  
	var tecla; 	  
	  
	CheckTAB=true; 
	  
	if(navigator.appName.indexOf("Netscape")!= -1)	  
		tecla= event.which;	  
	else 
	  
	tecla= event.keyCode; 	  
	  
	key = String.fromCharCode( tecla); 
	  
	//alert( 'key: ' + tecla + ' -> campo: ' + campo.value); 	  
	  
	if ( tecla == 13 ) 
	  
		return false; 
	  
	if ( tecla == BACKSPACE ) 
	  
		return true; 
		  
		return ( isNum(key)); 
  
}   
//-----> máscara cpf: 

function m_CPF(campo,tammax) {
var vr = campo.value;

vr = vr.replace( "-", "" );

vr = vr.replace( ".", "" );

vr = vr.replace( ".", "" );

var tam = vr.length;

if (tam < tammax) { tam = vr.length + 1; }

tam = tam - 1;

if ( (tam > 2) && (tam <= 11) ) {

vr = vr.substr( 0, tam - 1 ) + '-' + vr.substr( tam - 1, tam ); }

if ( (tam == 10) ) {

vr = vr.substr( 0, tam - 7 ) + '.' + vr.substr( tam - 7, 3 ) + '.' + vr.substr( tam - 4, tam ); }
campo.value = vr;

}

//-----> máscara cep:

function m_CEP(campo,tammax) {
var vr = campo.value;

vr = vr.replace( "-", "" );

vr = vr.replace( ".", "" );

var tam = vr.length;
if (tam < tammax) { tam = vr.length + 1; }
tam = tam - 1;

if ( (tam > 2) && (tam <= 8) ) {

vr = vr.substr( 0, tam - 2 ) + '-' + vr.substr( tam - 2, tam ); }

if ( (tam == 7) ) {

vr = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, tam ); }
campo.value = vr;

}
//-----> máscara data:

function m_DATA(campo,tammax,tecla) {

if(typeof(tecla) == 'undefined')

var tecla = window.event;

var codigo = (tecla.which ? tecla.which : tecla.keyCode ? tecla.keyCode : tecla.charCode);
var vr = campo.value;
vr = vr.replace( "/", "" );
vr = vr.replace( "/", "" );
var tam = vr.length;
if (tam < tammax) { tam = vr.length + 1; }
if (codigo == 8) { tam = tam - 1; }
tam = tam - 1;

if ( (tam >= 2) && (tam < 3) ) {

vr = vr.substr( 0, tam - 0 ) + '/' + vr.substr( tam - 0, 2 ); }

if ( (tam >= 3) && (tam < 4) ) {

vr = vr.substr( 0, tam - 1 ) + '/' + vr.substr( tam - 1, 2 ); }

if (tam == 4) {

vr = vr.substr( 0, tam - 2 ) + '/' + vr.substr( tam - 2, 2 ) + '/' + vr.substr( tam - 0, 5 ); }

if (tam == 5) {

vr = vr.substr( 0, tam - 3 ) + '/' + vr.substr( tam - 3, 2 ) + '/' + vr.substr( tam - 1, 6 ); }

if (tam == 6) {

vr = vr.substr( 0, tam - 4 ) + '/' + vr.substr( tam - 4, 2 ) + '/' + vr.substr( tam - 2, 7 ); }

if (tam == 7) {

vr = vr.substr( 0, tam - 5 ) + '/' + vr.substr( tam - 5, 2 ) + '/' + vr.substr( tam - 3, 8 ); }
campo.value = vr;

}

//-----> máscara hora:

function m_HORA(campo,tammax,tecla) {
if(typeof(tecla) == 'undefined')

var tecla = window.event;

var codigo = (tecla.which ? tecla.which : tecla.keyCode ? tecla.keyCode : tecla.charCode);
var vr = campo.value;

vr = vr.replace( ":", "" );

vr = vr.replace( ":", "" );

var tam = vr.length;
if (tam < tammax) { tam = vr.length + 1; }

if (codigo == 8) { tam = tam - 1; }

tam = tam - 1;

if ( (tam >= 2) && (tam < 3) ) {

vr = vr.substr( 0, tam - 0 ) + ':' + vr.substr( tam - 0, 2 ); }

if ( (tam >= 3) && (tam < 4) ) {

vr = vr.substr( 0, tam - 1 ) + ':' + vr.substr( tam - 1, 2 ); }

if (tam == 4) {

vr = vr.substr( 0, tam - 2 ) + ':' + vr.substr( tam - 2, 2 ) + ':' + vr.substr( tam - 0, 5 ); }

if (tam == 5) {

vr = vr.substr( 0, tam - 3 ) + ':' + vr.substr( tam - 3, 2 ) + ':' + vr.substr( tam - 1, 6 ); }

campo.value = vr;

}


function Mascara (formato, keypress, objeto){
campo = eval (objeto);

// cep
if (formato=='cep'){
separador = '-';
conjunto1 = 5;
if (campo.value.length == conjunto1){
campo.value = campo.value + separador;}
}

// cpf
if (formato=='cpf'){
separador1 = '.'; 
separador2 = '-'; 
conjunto1 = 3;
conjunto2 = 7;
conjunto3 = 11;
if (campo.value.length == conjunto1)
  {
  campo.value = campo.value + separador1;
  }
if (campo.value.length == conjunto2)
  {
  campo.value = campo.value + separador1;
  }
if (campo.value.length == conjunto3)
  {
  campo.value = campo.value + separador2;
  }
}

// nascimento
if (formato=='nascimento'){
separador = '/'; 
conjunto1 = 2;
conjunto2 = 5;
if (campo.value.length == conjunto1)
  {
  campo.value = campo.value + separador;
  }
if (campo.value.length == conjunto2)
  {
  campo.value = campo.value + separador;
  }
}

// telefone
if (formato=='telefone'){
separador1 = '(';
separador2 = ')';
separador3 = '-';
conjunto1 = 0;
conjunto2 = 3;
conjunto3 = 8;
if (campo.value.length == conjunto1){
campo.value = campo.value + separador1;
}
if (campo.value.length == conjunto2){
campo.value = campo.value + separador2;
}
if (campo.value.length == conjunto3){
campo.value = campo.value + separador3;
}
}
}

function MascaraMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, e){
    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789';
    var aux = aux2 = '';
    var whichCode = (window.Event) ? e.which : e.keyCode;
    if (whichCode == 13) return true;
    key = String.fromCharCode(whichCode); // Valor para o código da Chave
    if (strCheck.indexOf(key) == -1) return false; // Chave inválida
    len = objTextBox.value.length;
    for(i = 0; i < len; i++)
        if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) break;
    aux = '';
    for(; i < len; i++)
        if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i);
    aux += key;
    len = aux.length;
    if (len == 0) objTextBox.value = '';
    if (len == 1) objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
    if (len == 2) objTextBox.value = '0'+ SeparadorDecimal + aux;
    if (len > 2) {
        aux2 = '';
        for (j = 0, i = len - 3; i >= 0; i--) {
            if (j == 3) {
                aux2 += SeparadorMilesimo;
                j = 0;
            }
            aux2 += aux.charAt(i);
            j++;
        }
        objTextBox.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)
        objTextBox.value += aux2.charAt(i);
        objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
    }
    return false;
}


	

