// JavaScript Document

var primer=1;
var i;
var f;
var posSup=new Array("0","52","104","156","208","260","312","364","416","468","520","572","624","676");
var srAnt;
var i_F;
var f_F;
var srFrAnt;
var posFrame=new Array("0","39","78","117","156","195","234","273","312","351","390","429","468","507","546","585");
var idOld='';

function IdiomaSw(){window.location.reload();}

function mostrar(camp, text){
	eval("document."+camp+".value='"+text+"'");
	eval("document."+camp+".style.visibility='visible'");
}

function amagar(camp){
	eval("document."+camp+".value=''");
	eval("document."+camp+".style.visibility='hidden'");
}

function activarThumb(id){xGetElementById(id).className="thumbRoll";}
function desActivarThumb(id){xGetElementById(id).className="thumbNo";}

function activarThumFr(id){
	if(idOld !=''){xGetElementById(idOld).className="framThmb";}
	xGetElementById(id).className="framThmbSel";
	idOld=id;
}
function desactivarThumFr(){
	if(idOld !=''){xGetElementById(idOld).className="framThmb";}	
}

function saltarObra(id){
	location.href="obra.php?id="+id+"&fn="+i;	
}

function colocarSup(num){
	for(s=0;s< posSup.length ;s++){	
		temp=s+i;
		if(s<num){
			psL=parseInt(posSup[s]);
			xLeft(xGetElementById("T"+temp),psL);
			xTop(xGetElementById("T"+temp),(-40*(s+i-1)));
			xStyle("visibility","visible",xGetElementById("T"+temp));	
		}
	}
}

function movObra(newvideo){
	var flashvars = {"lvideo":newvideo}
	var params = { wmode: "gpu",bgcolor: "#000000",allowfullscreen: "true"}                
	var attributes = {}
	swfobject.embedSWF("continguts/obra/video/defaultBig.swf", "xvideo", "488", "390", "9.0", false, flashvars, params, attributes);
}

function colocarFrame(){
	for(s=0;s< posFrame.length ;s++){	
		temp=s+i_F;
		psL=parseInt(posFrame[s]);
		xLeft(xGetElementById("F"+temp),psL);
		xTop(xGetElementById("F"+temp),(-30*(s+i_F-1)));
		xStyle("visibility","visible",xGetElementById("F"+temp));				
	}
}

function moureObraR(){
	if(f>i+13){
		for(a=1;a<=15;a++){
			temp=a+i-1;
				if(a==1){
					xStyle("visibility","hidden",xGetElementById("T"+temp));
					xLeft(xGetElementById("T"+temp),-1000);
					psL=parseInt(posSup[a-1]);
				}else{
				if(a==15){
					xLeft(xGetElementById("T"+temp),psL);
					xTop(xGetElementById("T"+temp),(oldT-40));
					xStyle("visibility","visible",xGetElementById("T"+temp));
				}else{
					xLeft(xGetElementById("T"+temp),(psL));
					psL=parseInt(posSup[a-1]);
					if(a==14){oldT=xTop(xGetElementById("T"+temp))};
				}
			}
		}
		i++;
		if(f==i+13){document.fletxaR.src=srAnt;}
	}	
}

function moureObraL(){
	if(i>1){
	for(a=14;a>=0;a--){
		temp=a+i-1;
			if(a==14){
				xStyle("visibility","hidden",xGetElementById("T"+temp));
				xLeft(xGetElementById("T"+temp),-1000);
			}
			if(a==1){
				PosLU=xLeft(xGetElementById("T"+temp));
				oldT=xTop(xGetElementById("T"+temp));
			}
			posL=xLeft(xGetElementById("T"+temp));
			xLeft(xGetElementById("T"+temp), posL+52)
			if(a==0){
				xLeft(xGetElementById("T"+temp),PosLU);
				xTop(xGetElementById("T"+temp),-(40*(temp-1)));
				xStyle("visibility","visible",xGetElementById("T"+temp));	
			}
		}
	i--;
	if(i==1){document.fletxaL.src=srAnt;}
	}
}

function moureFrameR(){
	if(f_F>i_F+15){
		for(a=1;a<=17;a++){
			temp=a+i_F-1;
			if(a==1){
				xStyle("visibility","hidden",xGetElementById("F"+temp));
				xLeft(xGetElementById("F"+temp),-1000);
				psL=parseInt(posFrame[a-1]);
			}else{
				if(a==17){
					xLeft(xGetElementById("F"+temp),psL);
					xTop(xGetElementById("F"+temp),(oldT-30));
					xStyle("visibility","visible",xGetElementById("F"+temp));
				}else{
					xLeft(xGetElementById("F"+temp),psL);
					psL=parseInt(posFrame[a-1]);
					if(a==16){oldT=xTop(xGetElementById("F"+temp))};
				}
			}
		}
		i_F++;
		if(f_F==i_F+15){document.fletxaFR.src=srFrAnt;}
	}
	
}

function moureFrameL(){
	if(i_F>1){
	for(a=16;a>=0;a--){
		temp=a+i_F-1;
			if(a==16){
				xStyle("visibility","hidden",xGetElementById("F"+temp));
				xLeft(xGetElementById("F"+temp),-1000);
			}
			if(a==1){PosLU=xLeft(xGetElementById("F"+temp));}
			posL=xLeft(xGetElementById("F"+temp));
			xLeft(xGetElementById("F"+temp), posL+39)
			if(a==0){
				xLeft(xGetElementById("F"+temp),PosLU);
				xTop(xGetElementById("F"+temp),-(30*(temp-1)));
				xStyle("visibility","visible",xGetElementById("F"+temp));	
			}
		}
	i_F--;
	if(i_F==1){document.fletxaFL.src=srFrAnt;}
	}
	
}


function saltarJPS(id){
	location.href="jps.php?id="+id+"&fn="+i;	
}

function rollBotR(sr){
	if(f>i+13){
		srAnt=document.fletxaR.src;
		document.fletxaR.src=sr;
	}
}

function rollBotL(sr){
		if(i>1){
		srAnt=document.fletxaL.src;
		document.fletxaL.src=sr;
	}
}

function rollBotFR(sr){
	if(f_F>i_F+16){
		srFrAnt=document.fletxaFR.src;
		document.fletxaFR.src=sr;
	}
}

function rollBotFL(sr){
		if(i_F>1){
		srFrAnt=document.fletxaFL.src;
		document.fletxaFL.src=sr;
	}
}


function activarAbout(id ,valor){if(valor !=sel){xGetElementById(id).style.color="#e83417";}}
function desActivarAbout(id ,valor){if(valor !=sel){xGetElementById(id).style.color="#ffffff";}}

function saltarAbout(id ,valor,code){
	activarAbout(id ,valor)
	oldSel=sel;
	sel=valor;
	desActivarAbout(idSel ,oldSel);
	idSel=id;
	xajax_swObjecte(code);
}

//////////////////////////FUNCIONS formularis////////////////////////////////

function validarCont(Idioma){
if(document.forms[0].nom.value=="" ||  document.forms[0].mail.value==""){
		if(Idioma=="cat"){alert("Cal omplir tots els camps ");}
		if(Idioma=="ang"){alert("Es necesario rellenar todos los campos");}
		return false;
}else{
		ok=document.forms[0].mail.value.indexOf("@");
		if(ok===-1 || ok===0 || ok===(document.forms[0].mail.value.length)-1 ){
			if(Idioma=="cat"){alert("L'adreça de coreru electrònic no és correcta");}
			if(Idioma=="ang"){alert("El mail no es correcto");}
			return false;
		}	
	}
}

//////////////////////////FUNCIONS GENERALS////////////////////////////////

// CAMBIAR A FORMATO NUMERICO PARA MOSTRAR CON JAVASCRIPT  //
function numerico(numero){
	numero *=100;
	numero=Math.round(numero);
	numero /=100;
	
	numeroCadena=Math.abs(numero).toString();

	if(numeroCadena.indexOf(".")==-1){
		numeroCadena+=".00";
	}else{
		decimales=numeroCadena.substr(numeroCadena.indexOf("."));
		if(decimales.length ==2){
			numeroCadena+="0";
		}
	}
	numeroCadena=numeroCadena.replace(/\./,",");
	if (numeroCadena.length > 6){
		posfinal=numeroCadena.indexOf(",",0);
		dec=numeroCadena.substring(posfinal);
		ent=numeroCadena.substring(0,posfinal);
		longitud=ent.length % 3;
		while (longitud<ent.length){
			if(longitud==0){
				longitud=3;
			}
			ent=ent.substr(0,longitud)+"."+ent.substr(longitud,ent.length);
			longitud+=4
		}
		numeroCadena=ent+dec;
	}
	numeroCadena=numeroCadena+" €";
	
	return numeroCadena;
}

// TRADUCCION NUMERO DECIMAL Y MILLARES  A  FORMATO INGLES//
function formatoNum(numero){
	posfinal=numero.indexOf(",",0);
	dec=numero.substring(posfinal);
	ent=numero.substring(0,posfinal);
	dec=dec.replace(/\,/,".");
	ent=ent.replace(/\./,"");
	numeroCadena=ent+dec
return numeroCadena;
}


//////////////////////////CONTROL POPUPS////////////////////////////////

function AbrirVentanaPop(Direccion,NombreVen){
	navegador=navigator.userAgent;
	window.document.formulario.accept.checked=0;
	if(navegador.indexOf("Safari")==-1){
		parametros="width=780, height=685, left=100, top=50, resizable=no, menubar=no, toolbar=no, directories=no, scrollbars=auto, status=no";
	}else{
		parametros="width=800, height=705, left=100, top=50, resizable=no, menubar=no, toolbar=no, directories=no, scrollbars=auto, status=no";	
	}
	ventanaPop=window.open(Direccion,NombreVen,parametros);	
	ventanaPop.focus();
}

function AbrirVentanaLegal(Direccion,NombreVen){
	navegador=navigator.userAgent;
	if(navegador.indexOf("Safari")==-1){
		parametros="width=805, height=685, left=100, top=50, resizable=no, menubar=no, toolbar=no, directories=no, scrollbars=yes, status=no";
	}else{
		parametros="width=825, height=705, left=100, top=50, resizable=no, menubar=no, toolbar=no, directories=no, scrollbars=yes, status=no";	
	}
	ventanaPop=window.open(Direccion,NombreVen,parametros);	
	ventanaPop.focus();
}

function AbrirVentanaMapa(Direccion,NombreVen){
	navegador=navigator.userAgent;
	if(navegador.indexOf("Safari")==-1){
		parametros="width=705, height=570, left=100, top=50, resizable=no, menubar=no, toolbar=no, directories=no, scrollbars=no, status=no";
	}else{
		parametros="width=725, height=590, left=100, top=50, resizable=no, menubar=no, toolbar=no, directories=no, scrollbars=no, status=no";	
	}
	ventanaPop=window.open(Direccion,NombreVen,parametros);	
	ventanaPop.focus();
}

function CerrarPop(){
	opener.window.document.formulario.accept.checked=1;
	opener.window.document.formulario.accept.value="1";
	window.close();
}

function CerrarMapa(url){
	opener.window.location.href=url;
	window.close();
}


//////////////////////////PAGAMENTS////////////////////////////////

function registrat(camp){
	eval("document."+camp+".submit()");
}

function Refresc(desti){
	location.href=desti;	
}

function VeureAnt(){
	xVisibility("cist_ant",true);
}

//////////////////////////FLV  PLUGINS////////////////////////////////

function MM_CheckFlashVersion(reqVerStr,msg){
  with(navigator){
    var isIE  = (appVersion.indexOf("MSIE") != -1 && userAgent.indexOf("Opera") == -1);
    var isWin = (appVersion.toLowerCase().indexOf("win") != -1);
    if (!isIE || !isWin){  
      var flashVer = -1;
      if (plugins && plugins.length > 0){
        var desc = plugins["Shockwave Flash"] ? plugins["Shockwave Flash"].description : "";
        desc = plugins["Shockwave Flash 2.0"] ? plugins["Shockwave Flash 2.0"].description : desc;
        if (desc == "") flashVer = -1;
        else{
          var descArr = desc.split(" ");
          var tempArrMajor = descArr[2].split(".");
          var verMajor = tempArrMajor[0];
          var tempArrMinor = (descArr[3] != "") ? descArr[3].split("r") : descArr[4].split("r");
          var verMinor = (tempArrMinor[1] > 0) ? tempArrMinor[1] : 0;
          flashVer =  parseFloat(verMajor + "." + verMinor);
        }
      }
      // WebTV has Flash Player 4 or lower -- too low for video
      else if (userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 4.0;

      var verArr = reqVerStr.split(",");
      var reqVer = parseFloat(verArr[0] + "." + verArr[2]);
  
      if (flashVer < reqVer){
        if (confirm(msg))
          window.location = "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
      }
    }
  } 
}

