// JavaScript Document
String.prototype.trim= function() {
	return this.replace(/(^\s*)|(\s*$)/g,"");
}
if (window.addEventListener) {
	window.addEventListener('load', loadEvents, false);
}else if (window.attachEvent) {
	window.attachEvent('onload', loadEvents);
}
function loadEvents(){
	//loadReglasForo();
	var idCurso=AJS.$bytc("span", "sep");
	if(idCurso[0]){
		//loadSurvey2();
		//checkRealizada();
		if (idCurso[0].parentNode.childNodes[1].nodeValue.trim() == "EVALPROG1"){
			loadSurvey2();
		}else{
			checkRealizada();
		}
	}
}
function buscarOpcionRetroalimentacion(arreglo,palabraClave){
	var pos=-1;
	for (x=0;x<arreglo.length;x++){
		if (arreglo[x].childNodes[1].firstChild.innerHTML == palabraClave){
			pos=x;
			break;
		}
	}
	return pos;
}
function removerLigasRetroalimentacion(){
	var liga=AJS.$bytc("li", "activity feedback");
	AJS.removeElement(liga[0]);
	
	var divActividad=AJS.$bytc(null, "block_activity_modules");
	var divContent=AJS.$bytc(null, "content",divActividad[0]);
	var ulLista=AJS.$bytc(null, "list",divContent[0]);
	var liLista=AJS.$bytc("li", null,ulLista[0]);
	if(buscarOpcionRetroalimentacion(liLista,"Retroalimentaciones") != -1){
		AJS.removeElement(liLista[buscarOpcionRetroalimentacion(liLista,"Retroalimentaciones")]);
	}
}

function loadReglasForo(){
	if (AJS.$('[POPUP]')){
		GB_showCenter("Reglas del Foro", AJS.$('[POPUP]').href);		
		AJS.$('[POPUP]').onclick=function(){
			GB_showCenter("Reglas del Foro", AJS.$('[POPUP]').href);
			return false;
		}
	}
}
function loadSurvey2(){
	var estudiante=AJS.$bytc("div", "navbutton");
	var forms=AJS.$bytc("form", null,estudiante[0]);
		if (AJS.$bytc("form", null,estudiante[0])){
			if (estudiante[0].firstChild.name=="switchrole"){
				if(estudiante[0].childNodes[0].childNodes[1].childNodes[3].innerHTML != "Administrator"){
					removerLigasRetroalimentacion();
				}
			}else if(forms.length==1){
				removerLigasRetroalimentacion();
			}else{
				var liga=AJS.$bytc("li", "activity feedback");
				if (liga!=""){
					GB_showFullScreen("ENCUESTA", liga[0].childNodes[2].href)
				}
			}
		}
}
function checkRealizada(){
	var realizada=AJS.$bytc("td", "generalboxcontent");
	if (realizada!=""){
		for (x=0;x<realizada.length;x++){
			//SI YA LA REALIZO
			if (AJS.$bytc("h2",null,realizada[x])!=""){
				parent.parent.GB_hide();
				break;
			}
			//SI LA ACABA DE REALIZAR
			if (AJS.$bytc("div",null,realizada[x])!=""){
				var pGracias=AJS.$bytc("div",null,realizada[x]);
				if (pGracias[0].id=="FIN"){
					parent.parent.GB_hide();
					break;
				}
			}
		}
	}
}