function BrowserCheck() {
	var b = navigator.appName
	var agente=(navigator.userAgent);
	if (b=="Netscape") this.b = "ns"
	else if (b=="Microsoft Internet Explorer") this.b = "ie"
	else this.b = b
	this.version = navigator.appVersion
	this.platf = navigator.platform.toUpperCase()
	this.v = parseInt(this.version)
	this.ns = (this.b=="ns" && this.v>=4)
	this.ns4 = (this.b=="ns" && this.v==4)
	this.ns5 = (this.b=="ns" && this.v==5)
	this.ns6 = (this.b=="ns" && this.v==6)
	this.ie = (this.b=="ie" && this.v>=4)
	this.ie4 = (this.version.indexOf('MSIE 4')>0)
	this.ie5 = (this.version.indexOf('MSIE 5')>0)
	this.ie6 = (this.version.indexOf('MSIE 6')>0)
	this.linux = (this.platf.indexOf('LINUX')>0)
	this.win = (this.platf.indexOf('WIN')>0)
	this.mac = (this.platf.indexOf('MAC')>0)
	this.konqueror = (agente.indexOf('Konqueror')>0);
	this.firefox = (agente.indexOf('Firefox')>0);
	this.galeon = (agente.indexOf('Galeon')>0);
	this.min = (this.ns||this.ie)
	this.comp = (this.ns5||this.ns6||this.ie5||this.ie6||this.konqueror||this.firefox||this.galeon||this.mac)
}
is = new BrowserCheck()
var noshow=false;

function findWH() {
	winW = (is.ns)? window.innerWidth : document.body.offsetWidth-20//-16
	if(is.ns4) winW+=-16;
	winH = (is.ns)? window.innerHeight : document.body.offsetHeight-4
	altplus=16;
	ampleplus=388;
	posH=(winW-675)/2+ampleplus;
	posV=(winH-397)/2+altplus;
	if(posH<ampleplus)posH=ampleplus;
	if(posV<altplus)posV=altplus;
}

function ventana(talla,pag,nom){
  aw=screen.availWidth-10;
  switch (talla){
    case 0://copyright, aviso legal, web accesible
	ancho=460;alto=450;
	xc=(aw-ancho)/2;
carac='status=yes,scrollbars=yes,menubar=no,toolbar=no,location=no,directories=no,resizable=yes,copyhistory=no,width='+ancho+',height='+alto+',left='+xc+',top=0,screenX='+xc+',screenY=0';
    break;
	case 1://mapa web
	ancho=400;alto=450;
	xc=(aw-ancho)/2;
carac='status=yes,scrollbars=yes,menubar=no,toolbar=no,location=no,directories=no,resizable=yes,copyhistory=no,width='+ancho+',height='+alto+',left='+xc+',top=0,screenX='+xc+',screenY=0';
    break;
	case 2://minisite alumnos
	ancho=700;alto=455;
	xc=(aw-ancho)/2;
carac='status=yes,scrollbars=yes,menubar=yes,toolbar=yes,location=yes,directories=no,resizable=yes,copyhistory=no,width='+ancho+',height='+alto+',left='+xc+',top=0,screenX='+xc+',screenY=0';
    break;
	case 3://enviar amigo
	ancho=460;alto=450;
	xc=(aw-ancho)/2;
carac='status=no,scrollbars=yes,menubar=no,toolbar=no,location=no,directories=no,resizable=yes,copyhistory=no,width='+ancho+',height='+alto+',left='+xc+',top=0,screenX='+xc+',screenY=0';
    break;
	case 4://Versión textual donde estamos
	ancho=390;alto=450;
	xc=(aw-ancho)/2;
carac='status=yes,scrollbars=yes,menubar=no,toolbar=no,location=no,directories=no,resizable=yes,copyhistory=no,width='+ancho+',height='+alto+',left='+xc+',top=0,screenX='+xc+',screenY=0';
    break;
    case 5://participa
	ancho=500;alto=450;
	xc=(aw-ancho)/2;
carac='status=no,scrollbars=yes,menubar=no,toolbar=no,location=no,directories=no,resizable=yes,copyhistory=no,width='+ancho+',height='+alto+',left='+xc+',top=0,screenX='+xc+',screenY=0';
    break;
    case 6: //print
	ancho=600;alto=450;
    xc=(aw-ancho)/2;
carac='status=no,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;
	 case 7: //comunidad autonoma no almadraba
	ancho=515;alto=275;
    xc=(aw-ancho)/2;
carac='status=no,scrollbars=no,menubar=no,toolbar=no,location=no,directories=no,resizable=yes,copyhistory=no,width='+ancho+',height='+alto+',left='+xc+',top=0,screenX='+xc+',screenY=0';
	break;
	case 8: //posters verticales
	ancho=370;alto=520;
    xc=(aw-ancho)/2;
carac='status=no,scrollbars=no,menubar=no,toolbar=no,location=no,directories=no,resizable=yes,copyhistory=no,width='+ancho+',height='+alto+',left='+xc+',top=0,screenX='+xc+',screenY=0';
	break;
	case 9: //posters horizontales
	ancho=404;alto=285;
    xc=(aw-ancho)/2;
carac='status=no,scrollbars=no,menubar=no,toolbar=no,location=no,directories=no,resizable=yes,copyhistory=no,width='+ancho+',height='+alto+',left='+xc+',top=0,screenX='+xc+',screenY=0';
	break;
	case 10: //pedidos
	ancho=440;alto=475;
    xc=(aw-ancho)/2;
carac='status=no,scrollbars=yes,menubar=no,toolbar=no,location=no,directories=no,resizable=yes,copyhistory=no,width='+ancho+',height='+alto+',left='+xc+',top=0,screenX='+xc+',screenY=0';
	break;
	case 11: //bamboo
	ancho=920;alto=635;
	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;
	case 12: //fitxerpdf
	ancho=920;alto=635;
	xc=(aw-ancho)/2;
	carac='status=yes,scrollbars=yes,menubar=yes,toolbar=yes,location=yes,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);
}

function obre_document(){
	//bamboo=document.getElementById("select_bamboo").value;
	fitxerpdf=document.getElementById("select_pdf").value;
	//if(bamboo!="") ventana(11,bamboo,'Vbamboo');
	//else
	if(fitxerpdf!="") ventana(12,fitxerpdf,'Vpdf');
}

function toggle(capa){	
	if(document.getElementById(capa).style.display=="block") document.getElementById(capa).style.display="none";
	else document.getElementById(capa).style.display="block";
}

function changeClass(regformoption) 
  { 
  if (document.getElementById(regformoption).className=="withcode") document.getElementById(regformoption).className="withoutcode";
  else document.getElementById(regformoption).className="withcode";
  } 


/* només Almadraba */
inter_com=1;
function comunitats(imatge){
	//***** pendent de millora
	visibilitat=(inter_com==1)?'show':'hide';
	sufix=(inter_com==1)?'_on':'';
	MM_showHideLayers('comunidades','',visibilitat);
	MM_swapImage(imatge,'','/img/'+imatge+sufix+'.gif',1);
	inter_com=-inter_com;
}

perfil_ini="";
function canvi(onoff,quina){
	sufix=(onoff==0)?"":"_on";
	if(quina!=perfil_ini){
		MM_swapImage(quina,'','/img/'+quina+sufix+'.gif',1);
	}
}

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_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.getElementById(n); return x;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

// escribe las posiciones y características de las capas, como una hoja de estilos
function css(id,left,top,width,height,vis,z,clip,color,other) {
        if (id=="START") return '<STYLE TYPE="text/css">\n'
        else if (id=="END") return '</STYLE>'
        var str = (left!=null && top!=null)? '#'+id+' {position:absolute; left:'+left+'px; top:'+top+'px;' : '#'+id+' {position:relative;'
        if (arguments.length>=4 && width!=null) str += ' width:'+width+'px;'
        if (arguments.length>=5 && height!=null) {
                str += ' height:'+height+'px;'
        }      
        if (arguments.length>=6 && vis!=null) str += ' visibility:'+vis+';'
        if (arguments.length>=7 && z!=null) str += ' z-index:'+z+';'
        if (arguments.length>=8 && clip==true) str += ' clip:rect('+ 0 + ' ' + width + ' ' + height + ' ' + 0 +');'
        if (arguments.length>=9 && color!=null) str += (is.ns4)? ' layer-background-color:'+color+';' : ' background-color:'+color+';'
        if (arguments.length==10 && other!=null) str += ' '+other + ';'
        str += '}\n'
        var index = id.indexOf("Div")
        return str
}

function writeCSS(str,showAlert) {
        str = css('START')+str+css('END')
        document.write(str)
        if (showAlert) alert(str)
}

function es_nulo(campo){
	if (campo.value=="") return true;
	else return false;
}
function es_mail(cadena){
	var ER = new RegExp("@") ;	
	if (ER.test(cadena))  return true ;				
	else return (false) ;				
}
function extension_ok(campo){
	s = String(campo);
	s = s.substring(s.lastIndexOf(".")+1,s.length);
	if(s=="pdf" || s=="doc") return true;
	return false;
}
function validarFrm(tipo){
	var arTextos = new Array();	
	if(tipo!=6 && !document.form1.leeraviso.checked) return 4;
	
	switch(tipo){
		case 0:
			arTextos=["nom","cognoms","organitzacio","provincia","adreca","telefon","email","poblacio"];
			arSelect=["tipus_solicitud","segell","comunitat"];
			break;
		case 1:
			arTextos=["nom","cognoms","organitzacio","email","poblacio"];
			arSelect=["comunitat"];
			break;
		case 2:
			arTextos=["nom","cognoms","telefon","email","cvitae","poblacio"];
			arSelect=["area"];
			break;
		case 5:
			arTextos=["nom","email","centre","adreca","provincia","comentaris","poblacio"];
			arSelect=["comunitat"];
			break;
		case 6:
			arTextos=[];
			arSelect=["crit_class"];
			break;
		case 7:
			arTextos=["rao_social","nom_comercial","cif_nif","representant_legal","telefon","adreca","cp","poblacio"];
			arSelect=["comunitat"];
			break;
		case 8:
			arTextos=["rao_social","cif_nif","responsable_administracio","adreca","cp","poblacio","telefon","email"];
			arSelect=["comunitat"];
			break;
		case 9:
			arTextos=["nom","email","centre","adreca","provincia","cp","poblacio"];
			arSelect=["comunitat","exemplar","tipuscentre","areaconeixement","etapa"];
			break;
		default:
			arTextos=["emailfrom","namefrom","emailto","nameto"];
			arSelect=[];			
	}
	
	for(i=0;i<arSelect.length;i++){		
		if(eval("document.form1."+arSelect[i]).selectedIndex == 0) return 1;		
	}
	
	for(i=0;i<arTextos.length;i++){		
		if(es_nulo(eval("document.form1."+arTextos[i]))) return 1;
	}	
	if(tipo!=4 && tipo!=6 && tipo!=7 && !es_mail(document.form1.email.value)) return 2;	
	if(tipo==2 && !extension_ok(document.form1.cvitae.value))return 3;
	if(tipo==4 && (!es_mail(document.form1.emailfrom.value) || !es_mail(document.form1.emailto.value)))
		return 2;
	if(tipo==7 && 
		(
			(!es_mail(document.form1.email_contacte.value)) || 
			(document.form1.email_compres.value!="" && !es_mail(document.form1.email_compres.value)) ||
			(document.form1.email_administracio.value!="" && !es_mail(document.form1.email_administracio.value))
		)	
	)
			return 2;
	return 0;
}

function imprimir(tipus,params){	
	ventana(6,'print_'+tipus+'.jsp?'+params,'Vprint');
}
             
function carga_pag(url){
	if(opener) opener.location=url;
	else return false;
}

function amic(){
	url=document.location;	
	ventana(3,'form_friend.jsp?url='+escape(url),'Vamic');
}

function abrepdf(){
	urlPDF = document.formularios_pdf.select_pdf[document.formularios_pdf.select_pdf.selectedIndex].value;
	if( urlPDF != '' ) window.open(urlPDF);
}