var statusMsg = null;
                var textMsg = null;
                var velocidade=60;
                var startup=30;

function oneShotScroll() {
					
                        if (statusMsg.length>1) {
                               statusMsg=statusMsg.substring(1,statusMsg.length);
                        } else {
                                statusMsg=textMsg;
                        }
                        window.status=statusMsg;
                        timer=window.setTimeout("oneShotScroll()" ,velocidade);
                }
function scrolling(millisec, numOfSpaces) {
					
                        var t1  = "Olimpíadas Portuguesas de Matemática - Sociedade Portuguesa de Matemática";
                        textMsg=t1;
                        var spaces = "                                             ";
                        for (c=0 ; c < numOfSpaces ; c++) {
                                spaces+=" ";
                        }
                        textMsg = spaces + textMsg;
                        statusMsg = textMsg;
                        var command="oneShotScroll()";
                        window.status=statusMsg;
                        timer=window.setTimeout(command ,velocidade);
                }
                
                


function openNewWindow (URL, windowName, windowOptions)
{
	var window = getWindow (URL, windowName, windowOptions);
}

function getWindow(URL, windowName, windowOptions)
{
	var newWindow = open (URL, windowName, windowOptions)
	newWindow.focus();
	//top.allOpenWindows[top.allOpenWindows.length] = newWindow;
	return window;
}

function mouseOver(elem)
{
	elem.style.backgroundColor = '#DDDDDD';
	elem.style.border = '1px solid #000000'; 
	elem.style.cursor = 'hand';
}

function mouseOut(elem)
{
	elem.style.backgroundColor= '#F5F5F5';
	elem.style.border= '1px solid #F5F5F5'; 
	elem.style.cursor = 'auto';
}

function expand(tahw, pathOpen, pathClose, doc){
	table_contract = new Image(1,1);
	table_contract.src = pathOpen;
	table_expand = new Image(1,1);
	table_expand.src = pathClose;
	
	what  = tahw + "_menu"
	where = tahw + "_table"
	
	// expandir menu	
	if(doc.getElementById(what).style.display == "none"){
		doc.getElementById(what).style.display = "block";
		doc.getElementById(where).src = table_expand.src;
		doc.getElementById(where).alt = "Botão contrair menu";
		updateOpenedOptions(tahw,1);
	}
	else { // contrair menu 
		doc.getElementById(what).style.display = "none";
		doc.getElementById(where).src = table_contract.src;
		doc.getElementById(where).alt = "Botão expandir menu";
		updateOpenedOptions(tahw,0);
	}
}

function updateOpenedOptions(option, operation){
	var now = new Date();
	fixDate(now);
	now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
	
	var openedOptions = getCookie("menu","/","10.4.0.2");
	var newOpenedOptions = "";
	
	if (operation == 1){ //add
		if (!openedOptions) {
			newOpenedOptions = option + "."; 
		} else {
			newOpenedOptions = openedOptions + option + ".";
		}
	} else { //remove
		if(openedOptions.indexOf(option) > 0){
			newOpenedOptions = openedOptions.substr(0, openedOptions.indexOf(option)-1);
			newOpenedOptions = newOpenedOptions + openedOptions.substr(openedOptions.indexOf(option) + option.length, openedOptions.length);
		} else {
			newOpenedOptions = openedOptions.substr(option.length + 1, openedOptions.length);
		}
	}
	if (newOpenedOptions == null) 
		newOpenedOptions = "";
	deleteCookie("menu","/","10.4.0.2");
	setCookie("menu", newOpenedOptions, now, "/", "10.4.0.2");
}

function getDate(){
	var Today=new Date();

	var Day = new Array();
    Day[0]="Domingo";
    Day[1]="Segunda-feira";
    Day[2]="Terça-feira";
    Day[3]="Quarta-feira";
    Day[4]="Quinta-feira";
    Day[5]="Sexta-feira";
    Day[6]="Sábado";

    var Month=new Array();
    Month[1]="Janeiro";
    Month[2]="Fevereiro";
    Month[3]="Março";
    Month[4]="Abril";
    Month[5]="Maio";
    Month[6]="Junho";
    Month[7]="Julho";
    Month[8]="Agosto";
    Month[9]="Setembro";
    Month[10]="Outubro";
    Month[11]="Novembro";
    Month[12]="Dezembro";

	document.write(Day[Today.getDay()] + ", " + Today.getDate() + " de " + Month[Today.getMonth()+1] + " de " + Today.getFullYear());
}



function sortSelect(obj) {
	var o = new Array();
	for (var i=0; i<obj.options.length; i++) {
		o[o.length] = new Option( obj.options[i].text, obj.options[i].value, obj.options[i].defaultSelected, obj.options[i].selected) ;
		}
	o = o.sort( 
		function(a,b) { 
			if ((a.text+"") < (b.text+"")) { return -1; }
			if ((a.text+"") > (b.text+"")) { return 1; }
			return 0;
			} 
		);

	for (var i=0; i<o.length; i++) {
		obj.options[i] = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
	}
}

function moveSelectedOptions(from,to) {
	// Move them over
	for (var i=0; i<from.options.length; i++) {
		var o = from.options[i];
		if (o.selected) {
			to.options[to.options.length] = new Option( o.text, o.value, false, false);
			}
		}
		// Delete them from original
	for (var i=(from.options.length-1); i>=0; i--) {
		var o = from.options[i];
		if (o.selected) {
			from.options[i] = null;
			}
		}
		
	if ((arguments.length<3) || (arguments[2]==true)) {
		sortSelect(from);
		sortSelect(to);
		}
	from.selectedIndex = -1;
	to.selectedIndex = -1;
}


function selectAllOptions(obj) {
	for (var i=0; i<obj.options.length; i++) {
		obj.options[i].selected = true;
	}
}

function selectAllOptionsFromBoothBox(obj1, obj2) {
	if (obj1 != null) {
		for (var i=0; i<obj1.options.length; i++) {
			obj1.options[i].selected = true;
		}
	}

	if (obj2 != null) {
		for (var i=0; i<obj2.options.length; i++) {
			obj2.options[i].selected = true;
		}
	}
}

function selectAllOptionsFromThreeBoxes(obj1, obj2, obj3) {
	if (obj1 != null) {
		for (var i=0; i<obj1.options.length; i++) {
			obj1.options[i].selected = true;
		}
	}

	if (obj2 != null) {
		for (var i=0; i<obj2.options.length; i++) {
			obj2.options[i].selected = true;
		}
	}
	
	if (obj3 != null) {
		for (var i=0; i<obj3.options.length; i++) {
			obj3.options[i].selected = true;
		}
	}	
}

function clearTextBox(obj) {
	obj.value = "";
}

function appletPop(beginTime, endTime, interval, docenteId){
	var w = 625;
	var h = 350;
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;

	winprops = 'height=' + h + ', width=' + w + ', top=' + wint + ', left=' + winl + ', scrollbars=no, resizable=no, status=yes';
	win = window.open('/weboncampus/distribution/preferencias.jsp?beginTime='+beginTime+'&endTime='+endTime+'&interval='+interval+'&docenteId='+docenteId, 'calendario', winprops);

	if (parseInt(navigator.appVersion) >= 4)
		win.window.focus();
}

function validateMenuSearchForm(){
	if(document.formSearchFromMenu.searchString.value == ""){
		alert("Escreva pelo menos um termo de pesquisa!");
		document.formSearchFromMenu.searchString.focus();
		return false;
	} else {
		return true;
	}
}

function activeButtons(){
	if(document.formEditAvaliations.dataUm.value == "" || document.formEditAvaliations.horasUm.value == ""){
		document.formEditAvaliations.salasUm.disabled = true;
		document.formEditAvaliations.vigilanciasUm.disabled = true;
	} else {
		document.formEditAvaliations.salasUm.disabled = false;
		document.formEditAvaliations.vigilanciasUm.disabled = false;
	}
	
	if(document.formEditAvaliations.dataDois.value == "" || document.formEditAvaliations.horasDois.value == ""){
		document.formEditAvaliations.salasDois.disabled = true;
		document.formEditAvaliations.vigilanciasDois.disabled = true;
	} else {
		document.formEditAvaliations.salasDois.disabled = false;
		document.formEditAvaliations.vigilanciasDois.disabled = false;
	}
	
	if(document.formEditAvaliations.dataTres.value == "" || document.formEditAvaliations.horasTres.value == ""){
		document.formEditAvaliations.salasTres.disabled = true;
		document.formEditAvaliations.vigilanciasTres.disabled = true;
	} else {
		document.formEditAvaliations.salasTres.disabled = false;
		document.formEditAvaliations.vigilanciasTres.disabled = false;
	}
	
	if(document.formEditAvaliations.dataQuatro.value == "" || document.formEditAvaliations.horasQuatro.value == ""){
		document.formEditAvaliations.salasQuatro.disabled = true;
		document.formEditAvaliations.vigilanciasQuatro.disabled = true;
	} else {
		document.formEditAvaliations.salasQuatro.disabled = false;
		document.formEditAvaliations.vigilanciasQuatro.disabled = false;
	}
	
	if(document.formEditAvaliations.dataCinco.value == "" || document.formEditAvaliations.horasCinco.value == ""){
		document.formEditAvaliations.salasCinco.disabled = true;
		document.formEditAvaliations.vigilanciasCinco.disabled = true;
	} else {
		document.formEditAvaliations.salasCinco.disabled = false;
		document.formEditAvaliations.vigilanciasCinco.disabled = false;
	}
	
	if(document.formEditAvaliations.dataSeis.value == "" || document.formEditAvaliations.horasSeis.value == ""){
		document.formEditAvaliations.salasSeis.disabled = true;
		document.formEditAvaliations.vigilanciasSeis.disabled = true;
	} else {
		document.formEditAvaliations.salasSeis.disabled = false;
		document.formEditAvaliations.vigilanciasSeis.disabled = false;
	}	
}

function activeButtonsUm(){
	if(document.formEditAvaliations.dataUm.value == "" || document.formEditAvaliations.horasUm.value == ""){
		document.formEditAvaliations.salasUm.disabled = true;
		document.formEditAvaliations.vigilanciasUm.disabled = true;
	} else {
		document.formEditAvaliations.salasUm.disabled = false;
		document.formEditAvaliations.vigilanciasUm.disabled = false;
	}
}

function activeButtonsDois(){	
	if(document.formEditAvaliations.dataDois.value == "" || document.formEditAvaliations.horasDois.value == ""){
		document.formEditAvaliations.salasDois.disabled = true;
		document.formEditAvaliations.vigilanciasDois.disabled = true;
	} else {
		document.formEditAvaliations.salasDois.disabled = false;
		document.formEditAvaliations.vigilanciasDois.disabled = false;
	}
}

function activeButtonsTres(){
	if(document.formEditAvaliations.dataTres.value == "" || document.formEditAvaliations.horasTres.value == ""){
		document.formEditAvaliations.salasTres.disabled = true;
		document.formEditAvaliations.vigilanciasTres.disabled = true;
	} else {
		document.formEditAvaliations.salasTres.disabled = false;
		document.formEditAvaliations.vigilanciasTres.disabled = false;
	}
}

function activeButtonsQuatro(){	
	if(document.formEditAvaliations.dataQuatro.value == "" || document.formEditAvaliations.horasQuatro.value == ""){
		document.formEditAvaliations.salasQuatro.disabled = true;
		document.formEditAvaliations.vigilanciasQuatro.disabled = true;
	} else {
		document.formEditAvaliations.salasQuatro.disabled = false;
		document.formEditAvaliations.vigilanciasQuatro.disabled = false;
	}
}

function activeButtonsCinco(){
	if(document.formEditAvaliations.dataCinco.value == "" || document.formEditAvaliations.horasCinco.value == ""){
		document.formEditAvaliations.salasCinco.disabled = true;
		document.formEditAvaliations.vigilanciasCinco.disabled = true;
	} else {
		document.formEditAvaliations.salasCinco.disabled = false;
		document.formEditAvaliations.vigilanciasCinco.disabled = false;
	}
}

function activeButtonsSeis(){
	if(document.formEditAvaliations.dataSeis.value == "" || document.formEditAvaliations.horasSeis.value == ""){
		document.formEditAvaliations.salasSeis.disabled = true;
		document.formEditAvaliations.vigilanciasSeis.disabled = true;
	} else {
		document.formEditAvaliations.salasSeis.disabled = false;
		document.formEditAvaliations.vigilanciasSeis.disabled = false;
	}	
}

function MM_checkPlugin(plgIn, theURL, altURL, autoGo) { //v4.0

	wFlash = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="737" height="108"> <param name="movie" value="/weboncampus/images/top_dei.swf"> <param name="quality" value="high"> <embed src="/weboncampus/images/top_dei.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="737" height="108"></embed></object>';
	woFlash = '<img src="/weboncampus/images/top_dei_natal.gif" border=0 usemap="#Map" width="737">';
	
	var ok=false;
	document.MM_returnValue = false;
	
	with (navigator) if (appName.indexOf('Microsoft')==-1 || (plugins && plugins.length)) {
		ok=(plugins && plugins[plgIn]);
	} else if (appVersion.indexOf('3.1')==-1) { //not Netscape or Win3.1
		if (plgIn.indexOf("Flash")!=-1 && window.MM_flash!=null)
			ok=window.MM_flash;
		else if (plgIn.indexOf("Director")!=-1 && window.MM_dir!=null)
			ok=window.MM_dir;
		else
			ok=autoGo;
	}
	
	if (!ok)
		finalURL = woFlash;
	else
		finalURL = wFlash;
		
	return finalURL;
}

function answerCommentPop(questionId, teoricalClassId, praticalClassId, courseId){
	var w = 400;
	var h = 275;
	var winl = (screen.width - w) - 20;
	var wint = 50;

	winprops = 'height=' + h + ', width=' + w + ', top=' + wint + ', left=' + winl + ', scrollbars=no, resizable=no, status=no';
	arguments = '?questionId='+questionId+'&teoricalClassId='+teoricalClassId+'&praticalClassId='+praticalClassId+'&courseId='+courseId;
	win = window.open('/weboncampus/survey/commentquestion.do'+arguments, 'comments', winprops);

	if (parseInt(navigator.appVersion) >= 4)
		win.window.focus();
}

function rotateBlocks(array, blockId){
	for(i=0; i<array.length; i++){
		document.getElementById(array[i]).style.zIndex = 4;
	}
	
	for(i=0; i<array.length; i++){
		if(blockId.id == array[i]){
			if((i+1) == array.length){
				document.getElementById(array[0]).style.zIndex = 5;
			} else {
				document.getElementById(array[(i+1)]).style.zIndex = 5;
			}
		}
	}
}

/* Copyright (c) 2004 by Nuno Miguel Gil Fonseca (ngil <at> flordeutopia <dot> pt)
*  You can use this code as long as you credit me.
*/
function spamKiller(ml){
	var eml = "";
	for(var i = ml.length-1; i >= 0; i--) {
		if (ml.charAt(i) == '$') eml = eml + '@'
		else if (ml.charAt(i) == '&') eml = eml + '.'
		else eml = eml + ml.charAt(i)
	}
	return eml
}

/*
   name - name of the cookie
   value - value of the cookie
   [expires] - expiration date of the cookie
     (defaults to end of current session)
   [path] - path for which the cookie is valid
     (defaults to path of calling document)
   [domain] - domain for which the cookie is valid
     (defaults to domain of calling document)
   [secure] - Boolean value indicating if the cookie transmission requires
     a secure transmission
   * an argument defaults when it is assigned null as a placeholder
   * a null placeholder is not required for trailing omitted arguments
*/

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}


/*
  name - name of the desired cookie
  return string containing value of specified cookie or null
  if cookie does not exist
*/

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));
}


/*
   name - name of the cookie
   [path] - path of the cookie (must be same as path used to create cookie)
   [domain] - domain of the cookie (must be same as domain used to
     create cookie)
   path and domain default if assigned null or omitted if no explicit
     argument proceeds
*/

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";
  }
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"

function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

function getTime() {
	var today = new Date();
	var hours = today.getHours();
	var minutes = today.getMinutes();
	var seconds = today.getSeconds();
	document.write( checkZero(hours) + ":" + checkZero(minutes) + ":" + checkZero(seconds) );
}

function checkZero(n) {
	return ((n <= 9) ? ("0" + n) : n);
}

function getShortDate(){
	var today=new Date();
	var day = today.getDate();
	var month = today.getMonth();
	var year = today.getFullYear();

	document.write(checkZero(day) + "/" + checkZero(month+1) + "/" + checkZero(year));
}

function popup(url,name,dimension)
{
	window.open(url,name,dimension);
}

