﻿
//Incio da function Mascara
function Textbox_Mask(pControle, pMask) 
{
	var shift = window.event.shiftKey;
	var tecla = window.event.keyCode;
	var ctl = window.event.controlKey;
	
	if ( event.keyCode >= 48 && event.keyCode <= 57 ){
		if(! KeyControl(tecla)) 
		{
		
			curPos = textPos(pControle);
			
			if (tecla == 46) 
			{
				pControle.value = pControle.value.substring(0, curPos -1);
				//event.keyCode = 0;
				//event.returnValue = false;
			}
			else {
				if (! validChar(pControle, pMask, curPos)) {
					event.keyCode = 0;
					event.returnValue = false;
				}
			}
		}
	}
	else
		event.returnValue = false;
}

function KeyControl(tecla) 
{
	var alt		= window.event.altKey;
	var shift	= window.event.shiftKey;	
	var ctl = window.event.ctrlKey			
	return (ctl && (tecla ==67 || tecla==86)) || ( tecla == 16 || (shift && tecla == 16) || alt || tecla == 8 || tecla == 9 || tecla == 13 || tecla == 35 || tecla == 36 || tecla == 37 || tecla == 38 || tecla == 39 || tecla == 40 || tecla == 45 || tecla == 17 );
}

function textPos(textEl)
{
	var i=textEl.value.length+1;
	if (textEl.createTextRange) {
		theCaret = document.selection.createRange().duplicate();
		while (theCaret.parentElement() == textEl && theCaret.move('character',1)==1)
			--i;
		return i;
	}
	else{
		return -1;
	}
}

function validChar(pControle, pMask, pPos)
{
	var shift = window.event.shiftKey;
  var tecla = (window.Event) ? window.event.which : window.event.keyCode;
	if (pControle.value.length >= pMask.length) 
	{
		return false
	}
	charMask = pMask.substring(pPos - 1, pPos - 0);
	if (charMask == '#') 
	{
		if(shift || (! (tecla >= 48 && tecla <= 57)) && (! (tecla >= 96 && tecla <= 105))) 
			return false;

	}
	else if (charMask == 'X')
	{
		if(! (tecla >= 65 && tecla <= 90)) 
		{
			return false;
		}
		else 
		{
			return true;
		}
	}
	else if (charMask == '@')
	{
		return true;
	}
	else {
		lastchar = pControle.value.substring(pControle.value.length-1,pControle.value.length)

		if (lastchar==charMask) 
		{
			event.keyCode = 0;
			event.returnValue = false;
			return false;
		}

		pControle.value = pControle.value + charMask;
		if (! validChar(pControle, pMask, pPos + 1)) 
		{
			event.keyCode = 0;
			event.returnValue = false;
		}
	}
	return true;
}
// Fim da function mascara


function mNumero(obj)
{    
	if ( event.keyCode >= 48 && event.keyCode <= 57 ){      
        event.returnValue = true;
    }
    else {
        event.returnValue = false;
    }
}

var z = null;
function openWin(sURL,sNome,iWidth,iHeight)
{
    z = window.open(sURL,sNome,"status=no,menubar=no,toolbar=no,width="+ iWidth +",height="+ iHeight +",scrollbars=yes, top=0,left="+(screen.width - iWidth)/2 + "directories=no");
    z.focus();
    return false;
}
//HOVER IMAGEM
//---------------------------------------
var ImagemAtual = "";
function TrocarImagemOver(obj,img){

    obj.style.cursor = "pointer";
    ImagemAtual = obj.src;
    obj.src = img;

}

function TrocarImagemOut(obj){
    obj.src = ImagemAtual;
    ImagemAtual = "";
}
//---------------------------------------


function $(id){
    return document.getElementById(id);
}


function AbrirComunicarErro(erro){
    var w = window.open('ComunicarErros.aspx?erro='+erro, 'ComunicarErro', 'menubar=no,scrollbars=yes,resizable=yes,location=no,toolbar=no,width=400px,height=400px' ) ;
    w.focus();
}

function Imprimir(sessao){
    var w = window.open('Imprimir.aspx?sessao='+sessao, 'Imprimir', 'menubar=no,scrollbars=yes,resizable=yes,location=no,toolbar=no,width=600px,height=700px' ) ;
    w.focus();
}

function EnviarPorEmail(titulo,codigo,tipo){
    var w = window.open('EnviarPorEmail.aspx?tipo='+tipo+'&codigo='+ codigo + '&titulo='+titulo, 'EnviarPorEmail', 'menubar=no,scrollbars=yes,resizable=yes,location=no,toolbar=no,width=400px,height=500px') ;
    w.focus();
}



//Pontuação
//-----------------------------------------------

var img1 = '';
var img2 = '';
var img3 = '';
var img4 = '';
var img5 = '';
var oImg1 = '';
var oImg2 = '';
var oImg3 = '';
var oImg4 = '';
var oImg5 = '';

function NaoPontuar(o,num,id,botao){
    
    if(manterEstado==true)
        return;
        
        
   /* for(i = 1;i<=5;i++){
        eval("oImg"+i).src = eval("img"+i);
        eval("img"+i) = '';
    }*/ 
    
    
    oImg1.src = img1;
    oImg2.src = img2;
    oImg3.src = img3;
    oImg4.src = img4;
    oImg5.src = img5;
    img1 = '';
    img2 = '';
    img3 = '';
    img4 = '';
    img5 = '';
    
}

function Pontuar(o,num,id,botao){
    
    
    manterEstado=false;
        
    
    var i = 1;
    var oID = o.id.substring(0,o.id.length-3);
   
    for(i = 1;i<=5;i++){
    
        //armazenando a imagem atual em variável
        if(i == 1 && img1 == ''){
            img1 = $(oID+'__'+i).src;
            oImg1 =  $(oID+'__'+i);
        }else if(i == 2 && img2 == ''){
            img2 = $(oID+'__'+i).src;
            oImg2 =  $(oID+'__'+i);
        }else if(i == 3 && img3 == ''){
            img3 = $(oID+'__'+i).src;
            oImg3 =  $(oID+'__'+i);
        }else if(i == 4 && img4 == ''){
            img4 = $(oID+'__'+i).src;
            oImg4 =  $(oID+'__'+i);
        }else if(i == 5 && img5 == ''){
            img5 = $(oID+'__'+i).src;
            oImg5 =  $(oID+'__'+i);
        }

        

        if(i<=num)
            $(oID+'__'+i).src = $(oID+'__'+i).src.replace('vazia','ponto').replace('cheia','ponto').replace('metade','ponto');
        else
            $(oID+'__'+i).src = eval("img"+i);
        
    }
    
    //armazena pontos
    $(id).value = num;
}

var manterEstado = false;
function ConfirmaPontuacao(o,num,id,botao,adicionarAcaoParaConfirmarNota){

    manterEstado = true;

    if(adicionarAcaoParaConfirmarNota.toString().toLowerCase() != "true")
        return false;

    if($('ctl00_txtUsuario')!=null)
    {
        alert('Para confirmar a nota, é necessário estar logado no site.\r\nPor favor, clique em OK, efetue o login e confirme novamente sua nota.');
        $('ctl00_txtUsuario').focus();

        return false;
    }else{
      $(botao).click();
    }
}

//-----------------------------------------------

function UsuarioLogado(){
    
    if($('ctl00_txtUsuario')!=null)
    {
        alert('É necessário estar logado no site para continuar.\r\nPor favor, clique em OK e efetue o login.');
        $('ctl00_txtUsuario').focus();

        return false;
    }
    
}

/************ CLASSE MSG ************/
	function Msg(){
	this.arr = new Array();
	this.exceptions = new Array();
	function Msg(){
		this.arr = null;	
		this.exceptions = null;
	}
	//Retorna se existe mensagem
	this.HasMsg = function(){
		if(this.arr.length > 0|| this.exceptions.length > 0)
			return true;
			
		return false;
	}
	//Adiciona uma msg
	this.Add = function (s){
		var tamArray = this.arr.length;
		this.arr[tamArray] = s;
	}
	//Adiciona uma exception
	this.Exception = function(s){
		var tamArray = this.exceptions.length;
		this.exceptions[tamArray] = s;
	}

	//Mostra as Mensagens
	this.Show = function (){
		
		var SumarioErro = document.getElementById('ctl00_ContentPlaceHolder1_Validationsummary2');
		SumarioErro.style.display = 'block';

		var msgs = '<ul>';
		
		
		
		if(this.exceptions.length <= 0){
			for(var i = 0;i< this.arr.length;i++){
				msgs += '<li>' + this.arr[i] + "</li>";
			}
		}else
			msgs += '<li>' + this.exceptions[0] + "</li>";
		msgs += '</ul>';
				
		SumarioErro.innerHTML = msgs; 
        window.scrollTo(0,getPosicaoElemento(SumarioErro).top - 100);
        
        this.arr = new Array();	
		this.exceptions = new Array();
        
	}
	
	this.NoShow = function(){
		var SumarioErro = document.getElementById('ctl00_ContentPlaceHolder1_Validationsummary2');
		SumarioErro.style.display = 'none';
	}
}

function getPosicaoElemento(elemID){
    //var offsetTrail = document.getElementById(elemID);
    var offsetTrail = elemID;
    var offsetLeft = 0;
    var offsetTop = 0;
    var offsetWidth = 0;
    var offsetHeight = 0;
    
    offsetWidth = offsetTrail.offsetWidth;
    offsetHeight = offsetTrail.offsetHeight;
    
    while (offsetTrail) {
        offsetLeft += offsetTrail.offsetLeft;
        offsetTop += offsetTrail.offsetTop;
        offsetTrail = offsetTrail.offsetParent;
    }
    if (navigator.userAgent.indexOf("Mac") != -1 && 
        typeof document.body.leftMargin != "undefined") {
        offsetLeft += document.body.leftMargin;
        offsetTop += document.body.topMargin;
    }
    return {left:offsetLeft, top:offsetTop, width:offsetWidth, height:offsetHeight};
}


//abrir banners
function OpenBanner(codigoBanner,secao,destino){

    var w = window.open('cliqueBanner.aspx?l='+window.location.href+'&c=' + codigoBanner+'&s=' + secao+'&d=' + destino);
    w.focus();

}


function AbrirInscricao(codigo,titulo){

    var w = window.open('inscricao.aspx?cod='+codigo+'&curso='+titulo, 'Insricao', 'menubar=no,scrollbars=yes,resizable=yes,location=no,toolbar=no,width=520px,height=550px' );
    w.focus();
    
}

function SetFocusUsuario(){
   
    $('ctl00_txtUsuario').focus();
}


function FocusUsuario(){
    setTimeout("SetFocusUsuario()",200);
}