// JavaScript Document


//VALIDAR USUARIS
function validar(idioma) {
   if (validar_user.usuari.value == "") {
	   if (idioma==1) {
		   alert("Falta introducir el usuario.");
	   } 
	   else {
		   alert("Falta introduir l'usuari.");
	   }
     validar_user.usuari.focus();
     return false;
    }
   else if (validar_user.pass.value == ""){
	   if (idioma==1) {
		  alert("Falta introducir la contraseña."); 
	   }
	   else {
		   alert("Falta introduir la contrasenya.");
	   }
     validar_user.pass.focus();
     return false;
    }
   else {
     return true;
    }
  }

//TRIA PAGINA
function comprovar_cat(valor){
 if (valor==false)
 {
 window.location="cat/index_cat.htm";
 }
 else
 {
 window.parent.location="cat/index.htm";
 }
}
function comprovar_cast(valor){
 if (valor==false)
 {
 window.location="cast/index_cast.htm";
 }
 else
 {
 window.parent.location="cast/index.htm";
 }
}


//BUSCAR CONTINGUTS
function validar_buscar(){
if(document.form1.buscar.value=="")
{
	alert ('Introduce una palabra para buscar.');
	form1.buscar.focus();            
	return false;
}   
    //form1.buscar.value="";
	return true;
}

function validar_buscar_cat(){
if(document.form1.buscar.value=="")
{
	alert ('Introdueix una paraula per buscar.');
	form1.buscar.focus();            
	return false;
}   
    //form1.buscar.value="";
	return true;
}

//MENU FIREWORKS
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


//NETSCAPE
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);


//MENUS PANEL CONTROL
var isShowedSeccion1= false;
var isShowedSeccion2= false;
var isShowedSeccion3= false;
var isShowedSeccion4= false;
var isShowedSeccion5= false;
function ClickOnMenuSeccion( numSecc ) {
	if (numSecc == 1) {
		if (isShowedSeccion1) {
			document.getElementById("menuSeccion1").style.display= "none";
			isShowedSeccion1= false;
		}
		else {
			document.getElementById("menuSeccion1").style.display= "inline";
			isShowedSeccion1= true;
		}
		
		document.getElementById("menuSeccion2").style.display= "none";
		isShowedSeccion2= false;
		document.getElementById("menuSeccion3").style.display= "none";
		isShowedSeccion3= false;
		document.getElementById("menuSeccion4").style.display= "none";
		isShowedSeccion4= false;
		document.getElementById("menuSeccion5").style.display= "none";
		isShowedSeccion5= false;
	}
	else if (numSecc == 2) {
		if (isShowedSeccion2) {
			document.getElementById("menuSeccion2").style.display= "none";
			isShowedSeccion2= false;
		}
		else {
			document.getElementById("menuSeccion2").style.display= "inline";
			isShowedSeccion2= true;
		}
		
		document.getElementById("menuSeccion1").style.display= "none";
		isShowedSeccion1= false;
		document.getElementById("menuSeccion3").style.display= "none";
		isShowedSeccion3= false;
		document.getElementById("menuSeccion4").style.display= "none";
		isShowedSeccion4= false;
		document.getElementById("menuSeccion5").style.display= "none";
		isShowedSeccion5= false;
	}
	else if (numSecc == 3) {
		if (isShowedSeccion3) {
			document.getElementById("menuSeccion3").style.display= "none";
			isShowedSeccion3= false;
		}
		else {
			document.getElementById("menuSeccion3").style.display= "inline";
			isShowedSeccion3= true;
		}
		
		document.getElementById("menuSeccion1").style.display= "none";
		isShowedSeccion1= false;
		document.getElementById("menuSeccion2").style.display= "none";
		isShowedSeccion2= false;
		document.getElementById("menuSeccion4").style.display= "none";
		isShowedSeccion4= false;
		document.getElementById("menuSeccion5").style.display= "none";
		isShowedSeccion5= false;
	}
	else if (numSecc == 4) {
		if (isShowedSeccion4) {
			document.getElementById("menuSeccion4").style.display= "none";
			isShowedSeccion4= false;
		}
		else {
			document.getElementById("menuSeccion4").style.display= "inline";
			isShowedSeccion4= true;
		}
		
		document.getElementById("menuSeccion1").style.display= "none";
		isShowedSeccion1= false;
		document.getElementById("menuSeccion2").style.display= "none";
		isShowedSeccion2= false;
		document.getElementById("menuSeccion3").style.display= "none";
		isShowedSeccion3= false;
		document.getElementById("menuSeccion5").style.display= "none";
		isShowedSeccion5= false;

	}
	else if (numSecc == 5) {
		if (isShowedSeccion5) {
			document.getElementById("menuSeccion5").style.display= "none";
			isShowedSeccion5= false;
		}
		else {
			document.getElementById("menuSeccion5").style.display= "inline";
			isShowedSeccion5= true;
		}
		
		document.getElementById("menuSeccion1").style.display= "none";
		isShowedSeccion1= false;
		document.getElementById("menuSeccion2").style.display= "none";
		isShowedSeccion2= false;
		document.getElementById("menuSeccion3").style.display= "none";
		isShowedSeccion3= false;
		document.getElementById("menuSeccion4").style.display= "none";
		isShowedSeccion4= false;
	}
}

//VALIDAR PREGUNTES
function validar_pregunta(valor) {
	if (valor.pregunta.value=="") {
		alert("Falta introducir la pregunta.");
		valor.pregunta.focus();
		return false;
	}
	else if (valor.r1.value=="" || valor.r2.value=="") {
		alert("Falta introducir alguna respuesta.");
		return false;
	}
	else if (!valor.op[0].checked && !valor.op[1].checked && !valor.op[2].checked) {
		alert("Falta escojer una respuesta.");
		return false;
	}
	else {
		return true;
	}
}

//VALIDAR COMENTARIS
function validar_consulta(valor) {
	if (valor.nombre.value=="") {
		alert("Falta introducir un nombre.");
		valor.nombre.focus();
		return false;
	}
	else if ((valor.mail.value=="") || (valor.mail.value.indexOf('@')==-1) || (valor.mail.value.indexOf('.') == -1)) {
		alert("La dirección de e-mail no es correcta.");
		valor.mail.focus();
		return false;
	}
	else if (valor.consulta.value=="") {
		alert("Falta introducir la consulta.");
		valor.consulta.focus();
		return false;
	}
	else {
		return true;
	}
}

//TORNAR A LA PAGINA DE TRIA EXAMS
function tornar_exam(id,nivell){
	window.location="tria_cursos.asp?id_user=" + id + "&nivell=" + nivell + "&val=2";

}

//TORNAR A LA PAGINA DE TRIA LLIÇONS
function tornar_llicons(){
	id=form2.id_user.value;
	nivell=form2.nivell.value;
	window.location="tria_cursos.asp?id_user=" + id + "&nivell=" + nivell;
}
