
/* CODI GENERAL */

var nav = (navigator.appName == "Microsoft Internet Explorer") ? "ie" : "ns";
if(nav=="ns"){
origWidth=innerWidth;origHeight=innerHeight;onresize=function(){if(innerWidth!=origWidth||innerHeight!=origHeight)location.reload()}
if (parseInt(navigator.appVersion)>=5) nav="ns6";
}

function ref(nom_capa)
  {
    if (nav == "ie") return "document.all['" + nom_capa + "'].style.";
    if (nav == "ns") return "document." + nom_capa + ".";
	if (nav == "ns6") return "document.getElementById('" + nom_capa + "').style.";
  } 


function amagar(nom_capa)
  {
    eval(ref(nom_capa) + "visibility = 'hidden'");
  }
 
function amagar2(nom_capa)
  {
   if (nav == "ns") eval("document.principal.document."+nom_capa+".visibility = 'hidden'");
   else eval(ref(nom_capa) + "visibility = 'hidden'");
  }

function amagar3(nom_capa)
  {
   if (nav == "ns") eval("document.principal.document.menu.document."+nom_capa+".visibility = 'hidden'");
   else eval(ref(nom_capa) + "visibility = 'hidden'");
  }

function veure(nom_capa)
  {
    eval(ref(nom_capa) + "visibility = 'visible'");
  }

function veure2(nom_capa)
  {
   if (nav == "ns") eval("document.principal.document."+nom_capa+".visibility = 'visible'");
   else eval(ref(nom_capa) + "visibility = 'visible'");
  }

function veure3(nom_capa)
  {
   if (nav == "ns") eval("document.principal.document.menu.document."+nom_capa+".visibility = 'visible'");
   else eval(ref(nom_capa) + "visibility = 'visible'");
  }

function blockeig(nom_capa)
  {
   if (nav == "ns") eval("document.principal.document.menu.document."+nom_capa+".display = 'none'");
   else eval(ref(nom_capa) + "display = 'none'");
  }

function desblock(nom_capa)
  {
   if (nav == "ns") eval("document.principal.document.menu.document."+nom_capa+".display = 'block'");
   else eval(ref(nom_capa) + "display = 'block'");
  }

function mourecapa(capa,posx,posy)
{
        if (nav=="ns") {
                eval("document."+capa+".left=posx;");
                eval("document."+capa+".top=posy;");
        }
        if (nav == "ie") {
                eval(capa+".style.pixelLeft=posx;");
                eval(capa+".style.pixelTop=posy;");
        }
        if (nav == "ns6") {
                eval("document.getElementById('" + capa + "').style.left=posx");
                eval("document.getElementById('" + capa + "').style.top=posy");
        }
}

function mourecapa2(capa,posx,posy)
{
        if (nav=="ns") {
                eval("document.principal.document."+capa+".left=posx;");
                eval("document.principal.document."+capa+".top=posy;");
        }
        if (nav == "ie") {
                eval(capa+".style.pixelLeft=posx;");
                eval(capa+".style.pixelTop=posy;");
        }
        if (nav == "ns6") {
                eval("document.getElementById('" + capa + "').style.left=posx");
                eval("document.getElementById('" + capa + "').style.top=posy");
        }
}

function mourecapa3(capa,posx,posy)
{
        if (nav=="ns") {
                eval("document.principal.document.texte.document."+capa+".left=posx;");
                eval("document.principal.document.texte.document."+capa+".top=posy;");
        }
        if (nav == "ie") {
                eval(capa+".style.pixelLeft=posx;");
                eval(capa+".style.pixelTop=posy;");
        }
        if (nav == "ns6") {
                eval("document.getElementById('" + capa + "').style.left=posx");
                eval("document.getElementById('" + capa + "').style.top=posy");
        }
}





/* CODI PÀGINA */

/* COOKIES */

function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
{
  var cookie_string = name + "=" + escape ( value );

  if ( exp_y )
  {
    var expires = new Date ( exp_y, exp_m, exp_d );
    cookie_string += "; expires=" + expires.toGMTString();
  }

  if ( path )
        cookie_string += "; path=" + escape ( path );
  // Modif: Fa que les cookies siguin vàlides per a tot el domini
  else
		cookie_string += "; path=/";

  if ( domain )
        cookie_string += "; domain=" + escape ( domain );
  
  if ( secure )
        cookie_string += "; secure";
  
  document.cookie = cookie_string;
}

function delete_cookie ( cookie_name )
{
  var cookie_date = new Date ( );  // current date & time
  cookie_date.setTime ( cookie_date.getTime() - 1 );
  document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}

function get_cookie ( cookie_name )
{
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

  if ( results )
    return ( unescape ( results[2] ) );
  else
    return null;
}

// Fons si no hi ha cookie.
var fonsDefecte = 'fons2.jpg';

// Canviem el fons i fem cookie
function canviaFons(imatge) {
	document.body.style.backgroundImage='url(images/'+imatge+')';
	set_cookie( "colorfons", imatge );
}

// Si no hi ha cookie, posem fons defecte
if ( ! get_cookie( "colorfons" ) ) {
	canviaFons(fonsDefecte);
}
// Si hi ha cookie, posem fons de la cookie
else {
	canviaFons( get_cookie( "colorfons" ) );
}

// FI COOKIES


function isEmailAddress(theElement, nombre_del_elemento)
{
var s = theElement.value;
var filter=/^[A-Za-z][A-Za-z0-9_\-\.]*@[A-Za-z0-9_\-]+\.[A-Za-z0-9_.]+[A-za-z]$/;
if (s.length == 0 ) return true;
if (filter.test(s))
return true;
else
alert("Necesita posar un correu electrònic correcte");
theElement.focus();
return false;
}

function enviar()
{
    if (nav == "ie"){formulari.submit();}
	else{
	     if (nav == "ns"){document.principal.document.texte.document.interior.document.forms.formulari.submit();}
		 else{document.forms.formulari.submit();}
	}
}

// submenu i titol actius
var active_el = null
var active_tit = null

function switchMenuPrinc(obj, tit) {
	var el = document.getElementById(obj);
	if (el.style.display == 'block')
	{
		// clicat un menu actiu
		el.style.display = 'none';
		tit.style.backgroundColor = '#ffffff';
	}
	else
	{
		// clicat un menu inactiu
		// activem el menu
		el.style.display = 'block';
		tit.style.backgroundColor = '#a0ffff';
	}
}

function switchMenu(obj, tit) {
	var el = document.getElementById(obj);
	if (el.style.display == 'block')
	{
		// clicat un menu actiu
		el.style.display = 'none';
		tit.style.backgroundColor = '#ffffff';
		active_el = null;
		active_tit = null;
	}
	else
	{
		// clicat un menu inactiu
		if (active_el != null) 
		{
			// desactivem l'anterior menu
			active_el.style.display = 'none';
			active_tit.style.backgroundColor = '#ffffff';			
		}
		// activem el menu
		active_el = el;
		active_tit = tit;
		el.style.display = 'block';
		tit.style.backgroundColor = '#a0ffff';
	}
}

var on=0;
var on2=0;
var m=0;
var temps;

var img1=new Image();
img1.src="images/menu_casa_1.jpg";
var img2=new Image();
img2.src="images/menu_casa_1on.jpg";

var img3=new Image();
img3.src="images/menu_casa_2.jpg";
var img4=new Image();
img4.src="images/menu_casa_2on.jpg";

var img5=new Image();
img5.src="images/menu_casa_3.jpg";
var img6=new Image();
img6.src="images/menu_casa_3on.jpg";

var img7=new Image();
img7.src="images/menu_casa_4.jpg";
var img8=new Image();
img8.src="images/menu_casa_4on.jpg";

var img9=new Image();
img9.src="images/menu1.jpg";
var img10=new Image();
img10.src="images/menu1on.jpg";

var img11=new Image();
img11.src="images/menu2.jpg";
var img12=new Image();
img12.src="images/menu2on.jpg";

var img13=new Image();
img13.src="images/menu3.jpg";
var img14=new Image();
img14.src="images/menu3on.jpg";

var img15=new Image();
img15.src="images/menu4.jpg";
var img16=new Image();
img16.src="images/menu4on.jpg";

var img17=new Image();
img17.src="images/menu5.jpg";
var img18=new Image();
img18.src="images/menu5on.jpg";
