function canvi(quina,onoff){
 sufix=(onoff==1)?"_on":"";
 eval("document.getElementById('"+quina+"').src='"+dir+"img/"+quina+sufix+".gif'");
}

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];}}
}

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 imprimir(){
	urlimp=new String(document.location);
	urlimp+=(urlimp.indexOf("?")!=-1)?"&print=1":"?print=1";
	ventana(0,urlimp,'Vimprimir');
}

function ventana(talla,pag,nom){
  aw=screen.availWidth-10;
  switch (talla){
    case 0://imprimir
	ancho=660;alto=450;
    xc=(aw-ancho)/2;
carac='status=yes,scrollbars=yes,menubar=yes,toolbar=yes,location=no,directories=no,resizable=yes,copyhistory=no,width='+ancho+',height='+alto+',left='+xc+',top=0,screenX='+xc+',screenY=0';
	break;
	default:
	ancho=650;alto=450;
	xc=(aw-ancho)/2;
	carac='status=no,scrollbars=yes,menubar=no,toolbar=yes,location=no,directories=no,resizable=yes,copyhistory=no,width='+ancho+',height='+alto+',left='+xc+',top=0,screenX='+xc+',screenY=0';
	break;
  }
  if(!nom)nom='FINESTRA';
  eval(nom+'=window.open("'+pag+'","'+nom+'","'+carac+'")');
  setTimeout("eval("+nom+".focus())",400);
}

//estudis

	function cridaSimple (psOpcion) {
		switch (psOpcion) {
			case 1 : 
				document.llamada.action = "cercadorestudis_cercador.jsp" ;				
				break ;
			case 2 :
				document.llamada.action = "cercadorestudis_resultat.jsp" ;					 
				break ;
			case 3 : 
				document.llamada.action = "cercadorestudis_fitxa_estudi.jsp" ;
				break ;
		}		
		document.llamada.submit () ;
	}
	
function crida(psOpcion, psCodigoEstud, psCodigoCentr) {
	var sPagina = "" ;
	switch (psOpcion) {
		case 1 : sPagina = "cercadorestudis_cercador.jsp" ;
		break ;
		case 2 : sPagina = "cercadorestudis_fitxa_estudi.jsp" ;
		document.llamada.codi_estudi.value = psCodigoEstud ;
		document.llamada.codi_centre.value = psCodigoCentr ;
		break ;
		case 3 : sPagina = "cercadorestudis_fitxa_centreestudi.jsp" ;
		document.llamada.codi_estudi.value = psCodigoEstud ;
		document.llamada.codi_centre.value = psCodigoCentr ;			
		break ;
	}		
	document.llamada.action = sPagina ;
	document.llamada.submit () ;
}
	
function completeSelect(nameform,nameselect,array){
	select = eval("document."+nameform+"."+nameselect);
	for(i=0;i<array.length;i=i+2){
		select.options[(i/2)+1].value=array[i];
		select.options[(i/2)+1].text=array[i+1];
	}
}
function completehidden(select,hidden){	
	if(select && select.options[select.selectedIndex].value!=""){		
		value = select.options[select.selectedIndex].text;				value = value.replace(/^\s*|\s*$/g,"");		hidden.value=value;
	}
}

function completeForm (formu,complete,text_alerta){
	formu.action="cercadorestudis_resultat.jsp"
	completehidden(formu.area,formu.criterio_area);
	if(complete==1) completehidden(formu.estudio,formu.criterio_estudio);
	completehidden(formu.universidad,formu.criterio_univ);
	if(formu.criterio_area.value=='' && formu.criterio_univ.value=='' && formu.criterio_estudio.value=='' && formu.estudi_like.value==''){
		alert(text_alerta);
		return false;
	}
	formu.submit();
}


function MM_jumpMenu(targ,selName,restore){
	var selObj = MM_findObj(selName);
	if(selObj){
		if(selObj.options[selObj.selectedIndex].value!='')
			eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
		if (restore) selObj.selectedIndex=0;
	}
}

function anar(on){
	if(on=='')return;
	document.location(on);
	return;
}

arObligatoris=[];
arSelectObligatoris=[];
arEmails=[];

//formularis
function validEmail(ek){
	if(ek.indexOf("@")==-1)	return false;
	return true;
}

function isEmpty(ek){
	if(ek==null || ek=="") return true;
	return false;
}

function validaInputForm(form){	
	for(i=0;i<arObligatoris.length;i++) if(isEmpty(eval("form."+arObligatoris[i]+".value"))) return -1;
	for(i=0;i<arSelectObligatoris.length;i++) if(eval("form."+arSelectObligatoris[i]+".selectedIndex")==0) return -1;
	for(i=0;i<arEmails.length;i++) if(!validEmail(eval("form."+arEmails[i]+".value"))) return -2;		
	return 0;
}

function validaform(form,name){
	switch(name){
		case "send_friend":
			arObligatoris=["destinatari_correu","captcha"];
			arEmails=["destinatari_correu"];
			break;
		case "contacta":
			arObligatoris=["nom","cognoms","mail","comentari","captcha"];
			arEmails=["mail"];
			break;
	}	
	return validaInputForm(form);
}


