// Document JavaScript

// Funció Slide Show
var slideCache = new Array();
function RunSlideShow(pictureName,imageFiles,displaySecs)
{
	var imageSeparator = imageFiles.indexOf(";");
	var nextImage = imageFiles.substring(0,imageSeparator);
	if (document.all)
	{
	document.getElementById(pictureName).style.filter="blendTrans(duration=2)";
	document.getElementById(pictureName).filters.blendTrans.Apply();
	}
	document.getElementById(pictureName).src = nextImage;
	if (document.all)
	{
	document.getElementById(pictureName).filters.blendTrans.Play();
	}
	var futureImages= imageFiles.substring(imageSeparator+1,imageFiles.length)
	+ ';' + nextImage;
	setTimeout("RunSlideShow('"+pictureName+"','"+futureImages+"',"+displaySecs+")",
	displaySecs*1000);
	imageSeparator = futureImages.indexOf(";");
	nextImage = futureImages.substring(0,imageSeparator);
	if (slideCache[nextImage] == null) {
	slideCache[nextImage] = new Image;
	slideCache[nextImage].src = nextImage;
	}
}
////////////////////////////////////////////
// Funció per mostrar texte lletra a lletra

// Funció per recollir la variable
function envia_text(idtext){ 
var text = idtext
//variable amb la posició del text. Inicialitzar sempre a 0
var pos = 0
anima_text();
}

var text = "Benvinguts a la Web d'ACREFA"
//variable amb la posició del text. Inicialitzar sempre a 0
var pos = 0 
function mostre_text(){ 
    //increment de la posicion a 1 i extreure el text a mostrar en aquest momento. 
   pos = pos + 1 
    if (pos == text.length){ 
       //si hem arribat al final, tornem a la posició del principi 
      //pos = 0 
      return text 
   }else{ 
   return text.substring(0,pos) 
  } 
} 

function anima_text(){ 
    xInnerHtml('textmoviment',mostre_text()) 
   setTimeout("anima_text()",100) 
} 

////////////////////////////////////////////
// Obrir nova finestra
Window1=""
function NewWindow(plana,ample,llarg,barres,posx,posy){
if (Window1!=="") {Window1.close()};
Window1=window.open(plana,"NoContinguts","width=" + ample + ",height=" + llarg + ",toolbar=0,location=0,status=1,menubar=0,scrollbars=" + barres + ",resizable=1,left=" + posx + ",top=" + posy + "");
Window1.focus();
}

// Obrir finestra avís legal
Window1=""
function Avis(){
if (Window1!=="") {Window1.close()};
Window1=window.open('avis.html', 'AVISLEGAL' , 'width=550,height=450,toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=0,left=150,top=200');
Window1.focus();
}
////////////////////////////////////////////
// Validar formularis
function Valida_RegistreCAT()
{
 if ((document.forms[0].usuari.value=="") || (document.forms[0].clau.value==""))
 {
  alert("S'han detectat camps buits, per favor, introdueixi les seves dades de registre.")
  return false
 }
}

function Valida_acrefa03_CAT()
{
 if ((document.forms[1].empresa.value=="") 
	|| (document.forms[1].nif.value=="") 
	|| (document.forms[1].adresa.value=="") 
	|| (document.forms[1].municipi.value=="") 
	|| (document.forms[1].codi.value=="") 
	|| (document.forms[1].telefon.value=="") 
	|| (document.forms[1].web.value=="") 
	|| (document.forms[1].mail.value=="") 
	|| (document.forms[1].nom.value=="") 
	|| (document.forms[1].nifr.value==""))
 {
  alert("S'han detectat camps buits, per favor, introdueixi les dades sol·licitades.")
  return false	
 }

if (document.forms[1].mail.value.length >0)
 {
   i=document.forms[1].mail.value.indexOf("@")
   j=document.forms[1].mail.value.indexOf(".",i)
   k=document.forms[1].mail.value.indexOf(",")
   kk=document.forms[1].mail.value.indexOf(" ")
   jj=document.forms[1].mail.value.lastIndexOf(".")+1
   len=document.forms[1].mail.value.length
   
   if ((i>0) && (j>(i+1)) && (k==-1) && (kk==-1) && (len-jj >=2) && (len-jj<=3)) 
   {
	   
   }
   else 
   {
    alert("Adreça e-mail incorrecta.\n" + 
    document.forms[1].mail.value + " no és vàlida.")
    return false
   }
  }
}
function Valida_acrefa05_CAT()
{
 if ((document.forms[1].nom.value=="") || (document.forms[1].mail.value=="") || (document.forms[1].consulta.value==""))
 {
  alert("S'han detectat camps buits, per favor, introdueixi les dades sol·licitades.")
  return false	
 }

if (document.forms[1].mail.value.length >0)
 {
   i=document.forms[1].mail.value.indexOf("@")
   j=document.forms[1].mail.value.indexOf(".",i)
   k=document.forms[1].mail.value.indexOf(",")
   kk=document.forms[1].mail.value.indexOf(" ")
   jj=document.forms[1].mail.value.lastIndexOf(".")+1
   len=document.forms[1].mail.value.length
   
   if ((i>0) && (j>(i+1)) && (k==-1) && (kk==-1) && (len-jj >=2) && (len-jj<=3)) 
   {
	   
   }
   else 
   {
    alert("Adreça e-mail incorrecta.\n" + 
    document.forms[1].mail.value + " no és vàlida.")
    return false
   }
  }
}

//Mostra text barra propietats
function MM_displayStatusMsg(msgStr) { //v2.0
  status=msgStr;
  document.MM_returnValue = true;
}

/** Funcions de l'scroll **/
function cambiarImagen (nombreImagen,objetoImagen){
	document.images[nombreImagen].src = eval(objetoImagen + ".src");
}
function endavant(marquee){
	document.getElementById(marquee).direction='up';
	document.getElementById(marquee).scrollAmount='5';
}
function normal(marquee){
	document.getElementById(marquee).direction='up';
	document.getElementById(marquee).scrollAmount='1';
}
function enrrere(marquee){
	document.getElementById(marquee).direction='down';
	document.getElementById(marquee).scrollAmount='5';
}
function para(marquee){
	document.getElementById(marquee).stop();
}
function avanti(marquee){
	document.getElementById(marquee).start();
}
/** Fi Funcions de l'scroll **/