/*****************************************************************/
function display(idObj,valor){
	obj = document.getElementById(idObj); 
	if(obj){
		if(valor){
			obj.style.display = valor;
		}else{
			var dsp = obj;
			if(dsp.style.display == 'none' || dsp.style.display.length == 0){
				dsp.style.display = 'block';
			}else{
				dsp.style.display = 'none';
			}
		}
	}
}

function strip_tags(str, allowed_tags){
    var key = '', allowed = false;
    var matches = [];    
	var allowed_array = [];
    var allowed_tag = '';
    var i = 0;
    var k = '';
    var html = ''; 
    var replacer = function (search, replace, str){ return str.split(search).join(replace); };
    if(allowed_tags){ allowed_array = allowed_tags.match(/([a-zA-Z0-9]+)/gi); }
    str += ''; 
    matches = str.match(/(<\/?[\S][^>]*>)/gi);
    for(key in matches){
        if(isNaN(key)){continue;}
        html = matches[key].toString();
        allowed = false; 
        for(k in allowed_array){
            allowed_tag = allowed_array[k];
            i = -1; 
            if(i != 0){ i = html.toLowerCase().indexOf('<'+allowed_tag+'>');}
			if(i != 0){ i = html.toLowerCase().indexOf('<'+allowed_tag+' ');}
            if(i != 0){ i = html.toLowerCase().indexOf('</'+allowed_tag);} 
            if(i == 0){ allowed = true; break; }
        }
         if(!allowed){ str = replacer(html,"",str); }
    }
     return str;
}


function wopen(page,nwin,larg,altu,scroll){
	window.open(page,nwin,'width='+larg+',height='+altu+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+scroll+',resizable=no,menubar=no,top=10,left=10');
}

function addFav(){
    var url      = window.location;
	var title = 'Guia do Estudante';
	if(document.getElementsByTagName("META").title){
		title    += ' - '+document.getElementsByTagName("META").title.content;
	} else if(document.getElementsByTagName("title")[0].innerHTML){
		title = document.getElementsByTagName("title")[0].innerHTML;
	}
	
    if (window.sidebar) window.sidebar.addPanel(title, url,"");
    else if(window.opera && window.print){
        var mbm = document.createElement('a');
        mbm.setAttribute('rel','sidebar');
        mbm.setAttribute('href',url);
        mbm.setAttribute('title',title);
        mbm.click();
    }
    else if(document.all){window.external.AddFavorite(url, title);}
}

/******************************** FUNCOES DE AJAX ***************************************/ 
var http_request = false;
function getXmlHttp(){
	 if(window.XMLHttpRequest){
		 return new XMLHttpRequest();
	 } else if (window.ActiveXObject) {			 
		 var axO=['Microsoft.XMLHTTP','Msxml2.XMLHTTP','Msxml2.XMLHTTP.6.0','Msxml2.XMLHTTP.4.0','Msxml2.XMLHTTP.3.0'];
		 for(var i=0;i<axO.length;i++){ 
			try{ 
				return new ActiveXObject(axO[i]);
				}catch(e){
					
				} 
		}
	}
 }  
 
function makeRequest(url,funcao,isAssincrono,isPost,campos) {	//MakeREQUEST
	if(!isAssincrono){
		isAssincrono = true;
	}
	http_request=getXmlHttp();

	if (!http_request) {			
		return false;
	}
	if(!funcao){
		funcao = defaultRequest;
	}		
	http_request.onreadystatechange = function(){
		//alert(http_request.responseText)
		if (http_request.readyState == 4 && http_request.status == 200){
			funcao();
		}
	};
	
	if(isPost){
		http_request.open('POST', url, isAssincrono);			
		http_request.setRequestHeader("Content-type","application/x-www-form-urlencoded");	
		http_request.setRequestHeader("Content-length",campos.length);				
		http_request.send(campos);
	}else{
		http_request.open('GET', url, isAssincrono);
		http_request.send(null);
	}
}
	
function getDadosXml(xml){
	var obj = new Object();
	for(var i=0;i<xml.childNodes.length;i++){
		var tagNome = xml.childNodes[i].nodeName;
		if(tagNome == "link"){
			tagNome = "Link";
		}
		if(xml.childNodes[i].nodeType == 1){
			var node = xml.childNodes[i].childNodes[0].data;			
			node = node.replace(new RegExp("[']",'gi'), "&quot;");
			node = node.replace(new RegExp('["]','gi'), "&quot;");
			obj[tagNome] = node;
		}
	}
	return obj;
}



/*******************************************************************************************************************/	
 function geraQueryString(frm){
	var query = '';
	var cont = 0;
	for (var i = 0; i < frm.elements.length; i++) {
		if(frm.elements[i].type){
			if(frm.elements[i].type.indexOf('text') == 0){
				if (cont==0) {
					query = frm.elements[i].name + '=' + frm.elements[i].value;
				} else {
					query = query + '&' + frm.elements[i].name + '=' + frm.elements[i].value;
				}
				cont++;
			}else if(frm.elements[i].type.indexOf('checkbox')== 0){			
				if(frm.elements[i].checked){
					query = query + '&' + frm.elements[i].name + '=' + frm.elements[i].value;
					cont++;
				}			
			}else{
				query = query + '&' + frm.elements[i].name + '=' + frm.elements[i].value;
				cont++;		
			}
		}else{
			
		}
		
	}
	return (query);
}


function sapo_replace(strFind,newValue,str){
	while(str.indexOf(strFind)!=-1){
			str = str.replace(strFind,newValue); 
		} 
	return str;	
}
/*** VARIAVEIS DE VALIDACAO DE FORMULARIO ***/
var msg = Array();
var vld = Array();
var destino_frm = "";
var target_frm = "adm_miolo";
/*** ************************************ ***/

function validaFormulario(idForm,funcSucesso,funcErro){	
	var frm = document.forms[idForm];
	var checagem = 1;
	var count = frm.elements.length;
	var str_campo = "";
	for(i=0; i<frm.elements.length; i++){
		if(msg[frm.elements[i].name]){
			if(vld[frm.elements[i].name] == 1){
				checagem = validaCampo(frm.elements[i]);
			}
			else if(vld[frm.elements[i].name] == 2){
				checagem = validaEmail(frm.elements[i]);
			}else if(vld[frm.elements[i].name] == 3){
				 checagem = validaData("d-m-y");
			}else if(vld[frm.elements[i].name] == 4){
				 checagem = validaData("d-m");
			}else if(vld[frm.elements[i].name] == 5){
				 checagem = validaData("m-y");
			}else if(vld[frm.elements[i].name] == 6){
				 checagem = validaData("y");
			}else if(vld[frm.elements[i].name] == 7){
				 checagem = validaDataFinal("d-m-y");
			}else if(vld[frm.elements[i].name] == 8){
				 checagem = validaDataFinal("d-m");
			}else if(vld[frm.elements[i].name] == 9){
				 checagem = validaDataFinal("m-y");
			}else if(vld[frm.elements[i].name] == 10){
				 checagem = validaDataFinal("y");
			}
			
			if(!checagem){
				str_campo += msg[frm.elements[i].name] + ",";
				count --;
			}
		}
	}
	if(count == frm.elements.length){
		if(funcSucesso){
			funcSucesso(destino_frm);
		}
	}else{	
		if(funcErro){
			funcErro(str_campo);
		}
		return false;
	}
}

function validaCampo(campo){
	return campo.value != "";
}

function validaEmail(campo){
	return (campo.value != "" && campo.value.indexOf("@") > 0 && campo.value.indexOf(".") > 0);
}

function apenasNum(campo){
	campo.value = campo.value.replace(/[^0-9]/g, '');
}

function setCookie(name, value, expiresdays, path, domain, secure) {
	var today = new Date();
	var expires = new Date();
	expires.setTime(today.getTime() + 3600000*24*expiresdays);
    document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}


function atualizaForm(idFormulario){
	document.forms['formulario'+idFormulario].submit();
}


var Ids = '';
function getSelecao(){
	Ids = '';
	$('.cbkEdicao').each(function(i){
		if($(this).attr('checked')){
			Ids +=','+$(this).attr('value');
		}		
	});
	Ids =Ids .substring(1);
	return Ids;
}
function selecionaTudo(obj){
	$('.cbkEdicao').each(function(i){
		$(this).attr('checked',$("#todosCkb").attr('checked'));		
	});
}

function wopen(page,nwin,larg,altu, scroll){
    window.open(page,nwin,'width='+larg+',height='+altu+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+scroll+',resizable=no,menubar=no,top=80,left=100');
}



/*function getPermissoes(valores){
    var frm = document.formulario;
    frm.permissoes.value = valores;
    alert('Permissões salvas com sucesso');
}*/
function addInputHidden(nome,value){
	var frm = document.formulario;
	var input = document.createElement("input");
	input.setAttribute("type","hidden");
	input.setAttribute("name",nome);
	input.setAttribute("id",nome);
	input.value = value;
	frm.appendChild(input);	
}



	function alteraStatus(id,status,idSecao,idBloco,classAtivo,classNA){
		if(!classAtivo){
			classAtivo = 'panel verde';
		}
		
		if(!classNA){
			classNA = 'panel';
		}
		if(idBloco){
			idBloco = idBloco.split(',');			
		}
		
		if(status == 0){
			if(!confirm('Deseja realmente exclúir este item ?')){
				return;
			}
		}
		
		var url = 'controle.php?acao=alterarStatus&id='+id+'&status='+status+'&idSecao='+idSecao;	
		var func = function(){
			if (http_request.readyState == 4 && http_request.status == 200){ 
				var retorno = http_request.responseText;
				if(retorno){					
					if(retorno == '0'){
						if(idBloco){
							for(var i = 0; i < idBloco.length; i++){
								$('#'+idBloco[i]).hide();
							}
						}
					}else if (retorno == '2'){
						if(idBloco){
							for(var i = 0; i < idBloco.length; i++){
								$('#'+idBloco[i]).attr('class',classNA);
							}
						}
					}
				}	
			}
		}		
		
		makeRequest(url,func);
	}


function limpaCampos(idForm,strCamposAux){
	var frm = document.forms[idForm];
	if(strCamposAux){
		var arr = strCamposAux.split(',');
		for(i = 0; i < arr.length; i++){
			for (var j = 0; j < frm.elements.length; j++) {
				if(arr[i] == frm.elements[j].id){
					frm.elements[j].value='';							
				}
			}
		}		
	}
	
	for (var i = 0; i < frm.elements.length; i++) {
		if(frm.elements[i].type){
			if(frm.elements[i].type.indexOf('text') == 0){
				frm.elements[i].value='';
			}else if(frm.elements[i].type.indexOf('checkbox')== 0){			
				frm.elements[i].checked = false;			
			}else if(frm.elements[i].type.indexOf('select')== 0){	
				var sele = frm.elements[i];	
				if(sele[0]){
					sele[0].selected = true;
				}
			}
		}		
	}	
}

function getCoordsMouse(ev){    
    if(typeof(ev.pageX)!=="undefined"){
      return {x:ev.pageX, y:ev.pageY};
    }else{
        return {
          x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
          y:ev.clientY + document.body.scrollTop  - document.body.clientTop
        };
    }
}

function inArray(obj,valor){
	for(var i=0;i<obj.length;i++) {
		if(obj[i] == valor) {
			return true;
		}
	}
	return false;
}

function limpaform(idformulario,excessoes){
	if(excessoes)
	excessoes = excessoes.split(',')
	var frm =document.forms[idformulario];
	for (i=0;i<frm.elements.length;i++){
		var nome = frm.elements[i].getAttribute("id") || frm.elements[i].getAttribute("name");
		if(excessoes){
			if(!inArray(excessoes,nome))
				frm.elements[i].value = '';			
		}else{
			frm.elements[i].value = '';
		}
	}	
}

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable){
      return pair[1];
    }
  } 
  return "";
}

function Trim(str){
	return str.replace(/^\s+|\s+$/g,"");
}


function isLocation(nome){
	str = window.location.toString();
	if(str.indexOf(nome) > -1){
		return true;	
	}else{
		return false;	
	}	
}

function pressedEnter(event){
	var keynum;       
	if(window.event) { //IE  
		keynum = event.keyCode  
	} else if(event.which) { // Netscape/Firefox/Opera AQUI ESTAVA O PEQUENINO ERRO ao invés de "e." é "event."  
		keynum = event.which  
	}  
	if( keynum==13 ) {// <!-- 13 é o código do Enter --> AQUI TAMBEM  
		return true;		
	}else{
		return false;
	} 
}

function checarTecla(event,funcao){
	if(pressedEnter(event)){		
		funcao();
	}
}

function toggleQuadro(id,callBack){
	if($(id).css("display") == "none"){
		$(id).slideDown("normal",callBack);
	}else{
		$(id).slideUp("normal",callBack);
	}
}

/*** INPUT COM CALENDARIO ***/
showInputCalendar = function(elem){
	var me = this;
	if(me.elem){
		$("#container_calendario").remove();
	}
	if(me.elem != elem){
		me.elem = elem;
		$(elem).after("<span id='container_calendario' style='display:none' ></span>");	
		cal = new Calendario({
			instanceName:'cal',
			closeable:true,
			destino:'#container_calendario'
		});	
		cal.onClose = function(){
			$("#container_calendario").remove();
			me.elem = null;
		}
		if(elem.value != ''){
			var data = elem.value.split('/');
			cal.atualizar(data[0],data[1],data[2]);
		}		
		$("#container_calendario").show("normal");
		/*$("#container_calendario").mouseover(function(){		   
			me.manterAberto = true;
		});		
		$(elem).mouseover(function(){		   
			me.manterAberto = true;
		});		
		$("#container_calendario").mouseout(function(){
			me.manterAberto = false;
			timer = setTimeout(function(){
				if(!me.manterAberto){
					cal.close();
				}								
			},100);
		});*/
		
		cal.aoSelecionarData = function(){		
			$(elem).val(this.getData('d/m/y'));
			cal.close();
		}
	}else{
		me.elem = null;
	}	
}

function uploadMedia(campo,onUpload,idForm){
	if(Media.status != "em_andamento"){
		if(idForm)
			var frm = document.forms[idForm];
		else
			var frm = document.formulario;
		Media.status = "em_andamento";		
		destino_frm = "media_controle.php?acao=upLoad&campo="+campo;
		var onLoad = function(res){
			Media.url = res;
			Media.status = "upload_com_sucesso";
			Media.campo = campo;
			if(onUpload)
			onUpload();
		}
		frm.action = destino_frm;
		Media.upLoad(frm, {'onStart' : function(){},'onComplete' : onLoad})
	}	
}

	
/*function getTextEditor(inputName){
	eval("var txt = CKEDITOR.instances."+inputName+".getData();");
	return txt;		
}*/

function setTextEditor(campo,valor){
	eval("CKEDITOR.instances."+inputName+".setData("+texto+");");
}


function getTextEditor(campo){
	eval("var txt = document.getElementById('cke_contents_"+campo+"').getElementsByTagName('iframe')[0].contentWindow.document.body.innerHTML;");
	return txt;		
}


function getObjData(str){
	if(str.indexOf(" ")!=-1){
		arrData = str.split(" ");
		arrD = arrData[0].split('-');
		arrH = arrData[1].split(':');
		return new Date(arrD[0],arrD[1],arrD[2],arrH[0],arrH[1],arrH[2]);
	}else{
		arrD = str.split('-');
		return new Date(arrD[0],arrD[1],arrD[2]);
	}
	

}


/**********************************************   SANTA MARINA *****************************************************************************************************/


	
/*******************************************************  CARROSSEL - INICIO *********************************************************/

var contador = 0;
var leftAtual;
function Carrossel(acao,seletor1,seletor2){
	var tamanho = $(seletor1).width()+6;
	if(!leftAtual){
		leftAtual = 0;
	}
	var count = $(seletor1).length;
	if(acao == "Anterior"){			
		if(leftAtual == 0){
			leftAtual = 0;
		}else{
			leftAtual = (leftAtual + tamanho);
		}
	}else{
		if(Math.abs(leftAtual) < ((count-4)*tamanho)){
			leftAtual = (leftAtual - tamanho);
		}
	}	
	$(seletor2).each(function(i){	
		$(this).animate({left:leftAtual+"px"},"slow");
	});
}

function showImg(image,titulo,idImg,idTit){
	$(idImg).attr("src",image);
	$(idTit).html(titulo);
}
/*******************************************************  CARROSSEL - FIM *********************************************************/


fErro = function(strErro){
	var str = sapo_replace(",",";\n",strErro);
	alert("Por favor preencha os campos:\n"+str);
	enviando = 0;	
}

var enviandoForm = false
function salvarCadastroNewsletter(){
	if(!enviandoForm){
		enviandoForm = true;
		var frm = document.form_news;
		msg['nome'] = "Nome";
		vld['nome'] = 1;
		msg['email'] = "E-mail";
		vld['email'] = 2;
		fSucess = function(url){	
			var url = "controle_site.php?acao=assinarNews&nome="+frm.nome.value+"&email="+frm.email.value;
			makeRequest(url,function(){				
				if(http_request.responseText == "salvo"){
					alert("Assinatura salva com sucesso");
					frm.nome.value='';
					frm.email.value='';
				}else if(http_request.responseText == "cadastro_existente"){
					alert("Email já cadastrado em nosso sistema");
				}
				enviandoForm = false;
			})
		}
		validaFormulario('form_news',fSucess,fErro)
	}
}

function enviarMsnParaCoor(){
	if(!enviandoForm){
		enviandoForm = true 
		var frm = document.formulario;
		msg['nome'] = "Nome";
		vld['nome'] = 1;
		msg['email'] = "E-mail";
		vld['email'] = 2;	
		fSucess = function(url){
			var url = "controle_site.php?acao=enviarMsnParaCoor";
			campos = geraQueryString(frm).replace("&aceitoNews=","&aceitoNews="+frm.aceitoNews.checked);
			makeRequest(url,function(){	
				//alert(http_request.responseText)
				if(http_request.responseText == "salvo"){	
					$("#formulario").css("display","none");
					$("#box-msn").css("display","block");
					limpaform('formulario','idSecao,idConteudo');
					//setTimeout(fecharBoxMsn,2000)				
				}	
				enviandoForm = false;
			},true,true,campos)
		}
		validaFormulario('formulario',fSucess,fErro)
	}
}

function fecharBoxMsn(){
	$("#formulario").css("display","block");
	$("#box-msn").css("display","none");
}

function fecharBoxMsnHidden(){
	$("#formulario").css("visibility","visible");
	$("#box-msn").css("display","none");		
}

function slideUpDown(id,id2){
	var obj = $(id);
	if(obj.css("display") == "none"){
		obj.slideDown();
		$(id2).attr("class","active");
	}else{
		obj.slideUp();
		$(id2).attr("class","");
	}
}

function liberaCampo(val){
	if(val == ASSUNTO_TCN){
		display('blk1',"block");
		display('blk3',"block");
	}else{
		display('blk1',"none");
		display('blk2',"none");
		display('blk3',"none");
	}
}
function liberaCampo2(val){
	if(val == "Docente"){
		display('blk2',"block");
	}else{
		display('blk2',"none");
	}
}

function enviarFaleConosco(){
	if(!enviandoForm){
		enviandoForm = true;
		var frm = document.formulario;
		msg['nome'] = "Nome";
		vld['nome'] = 1;
		msg['email'] = "E-mail";
		vld['email'] = 2;
		msg['assunto'] = "Assunto";
		vld['assunto'] = 1;		
		msg['texto'] = "Mensagem";
		vld['texto'] = 1;	
		frm.aceitoNews.value = frm.aceitoNews.checked;
		fSucess = function(url){
			funcSalvar = function(){
				var url = "controle_site.php?acao=enviarFaleConosco";
				campos = geraQueryString(frm);
				makeRequest(url,function(){								
					if(http_request.responseText == "salvo"){
						$("#formulario").css("visibility","hidden");
						$("#box-msn").css("display","block");
						limpaform('formulario');
						//setTimeout(fecharBoxMsnHidden,5000)				
					}		
					enviandoForm = false;
				},true,true,campos)			
			}
			if(frm.arquivo.value){
				if(Media.status != "em_andamento"){
					Media.status = "em_andamento";		
					frm.action = "controle_site.php?acao=uploadArquivo";					
					Media.upLoad(frm, {'onStart' : function(){},'onComplete' : function(res){					
						if(res != "não tem arquivo" && res != "formato incorreto"){
							Media.status = "upload_com_sucesso";
							frm.urlArquivo.value = res;
							funcSalvar();	
						}else{
							alert(res);
							enviandoForm = false;
						}
					}})
				}
			}else{
				funcSalvar();
			}
	
	
		}
		validaFormulario('formulario',fSucess,fErro);
	}
}

function intCalendario(idsecao){					   
	cal = new Calendario({
		instanceName:'cal',
		destino:'#container_calendario'
	});	
	/*** LEGENDAS ***/
	//cal.legendas = [];
	for(var i= 0;i<7;i++){
		cal.legendas[i] = {};
	}
	// CLASSES
	cal.legendas[0].classe = '';
	cal.legendas[1].classe = 'vermelho'
	cal.legendas[2].classe = 'laranja';
	cal.legendas[3].classe = 'amarelo';
	cal.legendas[4].classe = 'verde';
	cal.legendas[5].classe = 'azul-escuro';		
	cal.legendas[6].classe = 'roxo';	
	// PRIORIDADE
	cal.legendas[0].prio = 7;
	cal.legendas[1].prio = 1;
	cal.legendas[2].prio = 2;
	cal.legendas[3].prio = 3;
	cal.legendas[4].prio = 4;
	cal.legendas[5].prio = 5;		
	cal.legendas[6].prio = 6;
	
	/****************************/
	
	cal.aoMudarMes = function(callBack){
		cal.limparMarcacoes();
		var url = "controle_site.php?acao=listarXmlCalendario&curso="+idsecao+"&data="+cal.getData('y-m-d');
		makeRequest(url,function(){	
			//alert(http_request.responseText)
			var html = '';					 
			if(http_request.responseText){						
				res = http_request.responseXML.getElementsByTagName('Calendario');				
				for(i=0;i<res.length;i++){
					obj = getDadosXml(res[i]);							
					//if(obj.nome_legenda.length > 1){
						if(obj.texto.length>1)
							Title = obj.nome_legenda+": "+Trim(obj.texto)
						else
							Title = obj.nome_legenda;
						cal.setMarcacao(obj.data_inicial,obj.data_final,Title,obj.id_legenda);								
					//}
				}
				
				res2 = http_request.responseXML.getElementsByTagName('Evento');
				for(i=0;i<res2.length;i++){
					obj = getDadosXml(res2[i]);	
					if(obj.tipo == 1){
						if(obj.id_secao == 15)
							Link = "proximos-eventos-escola.php?id="+obj.id;
						else
							Link = "proximos-eventos-faculdade.php?id="+obj.id;
					}else{
						if(obj.id_secao == 15)
							Link = "aconteceu-escola.php?id="+obj.id;
						else
							Link = "aconteceu-faculdade.php?id="+obj.id;
					}
					cal.setMarcacao(obj.data_inicial,obj.data_final,"Evento: "+obj.titulo,6,Link);
				}
				cal.odernarMarcacoes();
				cal.atualizar();	
				marcacoes = cal.getMarcacoes();
				for(var i=0 ;i<marcacoes.length ;i++){
					if(marcacoes[i].msg.indexOf(":") != -1){
						if(marcacoes[i].data_inicial == marcacoes[i].data_final){
							data = marcacoes[i].data_inicial.split("-");
							periodo =  "Dia "+data[2];
						}else{
							dataIni = marcacoes[i].data_inicial.split("-");
							dataFim = marcacoes[i].data_final.split("-");
							periodo = "De "+dataIni[2]+"/"+dataIni[1]+" a "+dataFim[2]+"/"+dataFim[1];
						}
						titulo = marcacoes[i].msg.split(":")[1];
						html+='<p><b>'+periodo+':</b>'+titulo+'</p>';
					}
				}
								
			}		
			strMesAno = '<strong id="mes-ano">'+cal.getMes("extenso")+'/'+cal.getAno()+'</strong>';
			//strDiaLet = '<small>Dias Letivos: <b>'+cal.getQntDiasLetivos()+'</b></small>';
			strDiaLet = '<br>';
			$("#datas-marcadas").html(strMesAno+strDiaLet+html);
		});				
	}
	cal.aoMudarMes();
}

function initPaginacaoAjax(url,countTotal,aoPaginar){
	pag = new PaginacaoAjax({
		nome:'pag',
		url:url,				   
		qntdReg:LIMREGPAG,
		ultimoReg:countTotal,
		container_navegacao:'.paginacao-lista',
		aoPaginar:aoPaginar
	});
}

function getListaEventosAconteceu(res){			
	var html = '<span>';
	count = 0;
	qntPorCol = Math.ceil(res.length/3);
	if(isLocation("eventos-escola.php")){
		area = 'escola';
	}else{
		area = 'faculdade';
	}	
	for(var i=0;i<res.length;i++){
		evento = getDadosXml(res[i]);
		if(count > 0){
			if(count%qntPorCol == 0){
				html += "</span><span>";
			}
		}
		
		var data = evento.data_inicial.split("-");
		html += '<small>'+data[2]+'/'+data[1]+'/'+data[0]+'</small><strong>'+evento.titulo+'</strong><p><a href="aconteceu-'+area+'.php?id='+evento.id+'">'+evento.olho+'</a></p><i></i>';
		count++;
	}
	html += '</span>';
	html = '<b>Aconteceu no Santa Marina</b>'+html;
	return html;			
}

function getListaProxEventos(res){			
	var html = '';
	if(isLocation("eventos-escola.php")){
		area = 'escola';
		cor = 'azul';
	}else{
		area = 'faculdade';
		cor = 'verde';
	}
	for(var i=0;i<res.length;i++){
		evento = getDadosXml(res[i]);
		if(evento.imagem.length>1){
			img = '<img src="imagens/tmb_'+evento.imagem+'" />';
			classeP = ' class="com-foto"';
		}else{
			img = classeP ='';
		}
		var data = evento.data_inicial.split("-");	
		html += '<div class="furo-'+cor+'"><p'+classeP+'><b>'+data[2]+'/'+data[1]+'/'+data[0]+'</b><strong><a href="proximos-eventos-'+area+'.php?id='+evento.id+'" title="'+evento.titulo+'">'+evento.titulo+'</a></strong><a>'+evento.olho+'</a></p>'+img+'</div>';			
	}
	html = '<div><h3>Próximos Eventos</h3>'+html+'</div>';
	return html;	
}

function ordenaArray(arr){
	for(j=0;j<(arr.length - 1);j++){
		for(i=j+1;i<arr.length;i++){
			if(parseInt(arr[j].data) < parseInt(arr[i].data)){
				aux = arr[j];
				arr[j] = arr[i];
				arr[i] = aux;				
			}			
		}			
	}
	return arr;
}

/*** PAIS E ALUNO ***/
function logar(idForm){
	var frm = document.forms[idForm];
	msg['codigo'] = "Código";
	vld['codigo'] = 1;
	msg['senha'] = "Senha";
	vld['senha'] = 1;	
	fSucess = function(url){
		apenasNum(frm.codigo)
		/*apenasNum(frm.senha)*/
		var url = "controle_site.php?acao=logar&"+geraQueryString(frm);
		makeRequest(url,function(){	
			//alert(http_request.responseText)
			if(http_request.responseText == "logado"){	
				limpaform(idForm,'idSecao');
				//setTimeout(fecharBoxMsn,2000)
				window.location.reload();
			}else{
				alert("Seu código ou sua senha estão digitados de forma incorreta, verifique os dados e tente novamente.")	
			}						
		})
	}
	validaFormulario(idForm,fSucess,fErro)
}

function logout(idSecao){
	var url = "controle_site.php?acao=logout&idSecao="+idSecao;
	makeRequest(url,function(){	
		//alert(http_request.responseText)
		if(http_request.responseText == "deslogado"){	
			window.location.reload();
		}						
	});
}


function forgot_password(){
	var sfeatures = 'dialogHeight:290px;dialogWidth:257px;center:yes;help:no;resizable:no;status:no;';
	var myret = window.showModalDialog("http://www.notasonline.com/pages/logon_forgot_password.asp", "", sfeatures);	
	if (myret != null){
		sfeatures = 'dialogHeight:212px;dialogWidth:257px;center:yes;help:no;resizable:no;status:no;';
		window.showModalDialog("http://www.notasonline.com/pages/logon_forgot_password_action.asp?result=" + myret, "", sfeatures);
	}	
}

function logarNoNotasOnline(){
	var form = document.frmForeign
	msg['txtID_foreign'] = "Login";
	vld['txtID_foreign'] = 1;
	msg['txtPWD_foreign'] = "Senha";
	vld['txtPWD_foreign'] = 1;	
	fSucess = function(url){
		form.submit();
	}
	validaFormulario('frmForeign',fSucess,fErro)
}

function salvarInscricao(){
	if(!enviandoForm){
		enviandoForm = true;
		var frm = document.formulario;
		msg['nome'] = "Nome";
		vld['nome'] = 1;
		msg['email'] = "E-mail";
		vld['email'] = 2;
		
		//frm.aceitoNews.value = frm.aceitoNews.checked;
		fSucess = function(url){
			var url = "controle_site.php?acao=salvarInscricao";
			campos = geraQueryString(frm);
			makeRequest(url,function(){								
				if(http_request.responseText == "salvo"){
					$("#formulario").css("visibility","hidden");
					$("#box-msn").css("display","block");
					limpaform('formulario');
				}
				enviandoForm = false;				
			},true,true,campos);	
		}
		validaFormulario('formulario',fSucess,function(str){fErro(str);enviandoForm = false;});
	}
}
