/* @module: TABLES */
/* @author: MARCOS DE CASTRO */
/* @client: COLÉGIO EXPONENTE */
/* @date:   27/03/2007 */

var ativo = false;

function changeTableCssClass(e,elementId)
{

	if (e.type == "mouseover")
	{
		document.getElementById(elementId.id).className = "indexCelulaOver";	
	}
	else if (e.type == "mouseout")
	{
		document.getElementById(elementId.id).className = "indexCelulaOut";		
	}

}

function abrirUrl(url)
{
	window.location = url;
}

function abrirHotsite(url)
{
	LeftPosition = (screen.width) ? (screen.width-650)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-500)/2 : 0;
	window.open(url,'Exponente','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=650,height=500,left='+LeftPosition+',top='+TopPosition);
}

function changeTableCssClassHotSite(e,elementId)
{

	if (e.type == "mouseover")
	{
		document.getElementById(elementId.id).className = "hotSiteEsportes2007ItemOver";	
	}
	else if (e.type == "mouseout")
	{
		document.getElementById(elementId.id).className = "hotSiteEsportes2007ItemOut";		
	}

}

function changeTableCssClassProjCult(e,elementId)
{

	if (e.type == "mouseover")
	{
		document.getElementById(elementId.id).className = "hotSiteProjCult2007ItemOver";	
	}
	else if (e.type == "mouseout")
	{
		document.getElementById(elementId.id).className = "hotSiteProjCult2007ItemOut";		
	}

}


function changeTableCssClassHotSiteExpoCartao(e,elementId)
{

	if (e.type == "mouseover")
	{
		document.getElementById(elementId.id).className = "hotSiteExpoCartao2007ItemOver";	
	}
	else if (e.type == "mouseout")
	{
		document.getElementById(elementId.id).className = "hotSiteExpoCartao2007ItemOut";		
	}

}

function ativarSubItem()
{
	if (!ativo)
	{
		document.getElementById('subItem1_1').style.display = 'block';
		document.getElementById('subItem1_2').style.display = 'block';
		ativo = true;
	}
	else
	{
		document.getElementById('subItem1_1').style.display = 'none';
		document.getElementById('subItem1_2').style.display = 'none';
		ativo = false;
	}
	
	
}

function changeTableCssClassHotSiteExpoCartao2(e,elementId)
{

	if (e.type == "mouseover")
	{
		document.getElementById(elementId.id).className = "hotSiteExpoCartaoItemOver";	
	}
	else if (e.type == "mouseout")
	{
		document.getElementById(elementId.id).className = "hotSiteExpoCartaoItemOut";		
	}

}


function changeTableCssClassEnsMedProf(e,elementId)
{

	if (e.type == "mouseover")
	{
		document.getElementById(elementId.id).className = "professorItemOver";	
	}
	else if (e.type == "mouseout")
	{
		document.getElementById(elementId.id).className = "professorItemOut";		
	}

}

function abrirSite(url)
{
	window.open(url,"Links","toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=500,height=500");
}

//MANEIRA DE UTILIZAR: OnKeyUp="mascararInteiro(this,event)" OnBlur="mascararInteiro(this,event)
function mascararInteiro(campo,tamanho)
{
		
	var valorAuxiliar = "";
	digitosValidos = "0123456789" ;
	
	valor = campo.value;
	tammax = tamanho;

	//retira digitos não numericos
	for (i=0;i<valor.length;i++){
		if(digitosValidos.indexOf(valor.charAt(i))>=0) {
			valorAuxiliar += valor.charAt(i);
		}
	}

	//verifica tamanho (tamanho máximo vindo do método)
	if(tammax > 0 && tammax < valorAuxiliar.length) {
		valorAuxiliar = valorAuxiliar.substring(0,tammax);
	}

	valor = valorAuxiliar;
	digitosNumericos = valor.length;

   campo.value = valor;    
} 

//MANEIRA DE UTILIZAR: OnKeyUp="mascararData(this,event)" OnBlur="mascararData(this,event)"
function mascararData(campo,formatacao)
{
		
	var valorAuxiliar = "";
	digitosValidos = "0123456789" ;
	
	valor = campo.value;
	tammax = 8;

	//retira digitos não numericos
	for (i=0;i<valor.length;i++){
		if(digitosValidos.indexOf(valor.charAt(i))>=0) {
			valorAuxiliar += valor.charAt(i);
		}
	}

	//verifica tamanho (tamanho máximo vindo do método)
	if(tammax > 0 && tammax < valorAuxiliar.length) {
		valorAuxiliar = valorAuxiliar.substring(0,tammax);
	}

	valor = valorAuxiliar;
	digitosNumericos = valor.length;

    if (formatacao==1)
    {
    	if (valor.length > 2)
		{ 
	    	valor = valor.substring(0,2) + "/" +  valor.substring(2);
		} 
    }
    else if (formatacao==2)
    {
	    if (valor.length > 2)
		{ 
			valor = valor.substring(0,2) + "/" +  valor.substring(2);		
			if (valor.length > 5) {
				valor = valor.substring(0,5) + "/" +  valor.substring(5);
			}			
		} 
    }

    
	campo.value = valor;    
} 

//MANEIRA DE UTILIZAR: OnKeyUp="mascararCep(this,event)" OnBlur="mascararCep(this,event)"
function mascararCep(campo,evento)
{
	
	if (navigator.appName.indexOf("Microsoft")!= -1) 
		tecla= event.keyCode;
	else
		tecla = evento.which;
	
	if (tecla == 8)
		return false;
			
	var valorAuxiliar = "";
	digitosValidos = "0123456789" ;
	
	valor = campo.value;
	tammax = 8;

	
	//retira digitos não numericos
	for (i=0;i<valor.length;i++){
		if(digitosValidos.indexOf(valor.charAt(i))>=0) {
			valorAuxiliar += valor.charAt(i);
		}
	}

	//verifica tamanho (tamanho máximo vindo do método)
	if(tammax > 0 && tammax < valorAuxiliar.length) {
		valorAuxiliar = valorAuxiliar.substring(0,tammax);
	}
	while (valorAuxiliar.length > 3 && valorAuxiliar.charAt(0) == "0") {
		valorAuxiliar = valorAuxiliar.substring(1);
	}

	valor = valorAuxiliar;
	digitosNumericos = valor.length;

	//insere pontos decimais

	if (valor.length>=2) {
		valor = valor.substring(0,2) + "." +  valor.substring(2);
		if (valor.length >=6) {
			valor = valor.substring(0,6) + "-" +  valor.substring(6);
		}
	}
	
	campo.value = valor;
	
}

function mascararCpf(obj,e) //MANEIRA DE UTILIZAR: OnKeyUp="mascararCpf(this,event)" OnBlur="mascararCpf(this,event)"
{
	if (navigator.appName.indexOf("Microsoft")!= -1) 
		tecla= event.keyCode;
	else
		tecla = e.which;
		
	if (tecla == 8)
		return false;
			
	var myCpf = obj.value;
	var nomeCampo = obj.name;
	


	//QDO O EVENTO FOR onBlur
	if (e.type == "blur")
	{
		
		myCpf = myCpf.replace(".","");
		myCpf = myCpf.replace(".","");
		myCpf = myCpf.replace("-","");
		
		
		myCpf = myCpf.substr(0,3) + "." + myCpf.substr(3,3) + "." +  myCpf.substr(6,3) +  "-" + myCpf.substr(9,2);
		document.forms[0][nomeCampo].value = myCpf; 
	}
	else // OUTRO EVENTO
	{
		if (myCpf.length == 3)
		{
			myCpf = myCpf + '.'; 
			document.forms[0][nomeCampo].value = myCpf; 
		}
		
		if (myCpf.length == 7)
		{
			myCpf = myCpf + '.'; 
			document.forms[0][nomeCampo].value = myCpf; 
		}
		
		if (myCpf.length == 11 && myCpf.substr(3,1) == ".")
		{
			myCpf = myCpf + '-'; 
			document.forms[0][nomeCampo].value = myCpf; 
		}
	}
}