// JavaScript Document
/* oculta els submenús emergents */
function amagar_submenus(quin1, quin2){
	for (i=1;i<=2;i++){
		var seccio= eval("quin"+i);
		submenu=document.getElementById(seccio);
		submenu.style.visibility="hidden";
		}
	}
/*fa un preload de les imatges de rollover del menú*/	
function rolls_menu(idioma)	{	
  if (!document.images) return;
  var noms_img = new Array(
    "/imatges/navega/"+idioma+"menu_villas_act.gif",
    "/imatges/navega/"+idioma+"menu_tourism_act.gif",
    "/imatges/navega/"+idioma+"menu_contact_act.gif",
    "/imatges/navega/"+idioma+"menu_villas1_act.gif",
    "/imatges/navega/"+idioma+"menu_villas2_act.gif",
    "/imatges/navega/"+idioma+"menu_villas3_act.gif",
    "/imatges/navega/"+idioma+"menu_villas4_act.gif",
    "/imatges/navega/"+idioma+"menu_tourism1_act.gif",
    "/imatges/navega/"+idioma+"menu_tourism2_act.gif",
    "/imatges/navega/"+idioma+"menu_tourism3_act.gif"
  );
  var imatges = new Array();
  for (var i = 0; i < noms_img.length; i++)
  {
    imatges[i] = new Image();
    imatges[i].src = noms_img[i];
  }
}

/***************MENÚ*****************/
var n4, ie, n6;

var doc,doc2,doc3,sty;

if (document.layers) {
  doc = "document.";
  doc2 = ".document.";
  doc3 = "";
  sty = "";
  n4 = true;
  }
else if (document.all) {
  doc = "document.all.";
  doc2 = "";
  doc3 = "";
  sty = ".style";
  ie = true;
}

else if (document.getElementById) {
  doc = "document.getElementById('";
  doc2 ="')";
  doc3 ="')";
  sty = "').style";
  n6 = "true";
 } 
 

// preload navigation images

var loaded = 0;
var navdir = "imatges/navega/";

function preload(idioma) {
top_home_off = new Image;
top_home_off.src = navdir + idioma + "/menu_home.gif";
top_home_on = new Image;
top_home_on.src = navdir + idioma + "/menu_home_act.gif";

top_villas_off = new Image;
top_villas_off.src = navdir + idioma + "/menu_villas.gif";
top_villas_on = new Image;
top_villas_on.src = navdir + idioma + "/menu_villas_act.gif";

top_tourism_off = new Image;
top_tourism_off.src = navdir + idioma + "/menu_tourism.gif";
top_tourism_on = new Image;
top_tourism_on.src = navdir + idioma + "/menu_tourism_act.gif";

top_contact_off = new Image;
top_contact_off.src = navdir + idioma + "/menu_contact.gif";
top_contact_on = new Image;
top_contact_on.src = navdir + idioma + "/menu_contact_act.gif";


loaded = true;
}

// img src swap function
function onoff (elemparent,elem,state) {

if (loaded) {
newstate = eval(elem+"_"+state);

if (n4) {
menuObj = eval (doc + elemparent + doc2 + elem);
 }
else if (ie || n6) {
menuObj = eval (doc + elem + doc2);
 }
menuObj.src = newstate.src;
 }
}


// mouse over (on) and mouseoff(off) color values
var oncolor = "_act";
var offcolor = "";

function changecolor(divname,colorname,lang) {
stopall();
if (!ie) {
menuObj = eval(doc + divname + doc2);
menuObj.src = "imatges/navega/"+lang+"/menu_"+divname+colorname+".gif";
  }else{
menuObj = eval(doc + divname);
menuObj.src = "imatges/navega/"+lang+"/menu_"+divname+colorname+".gif"; 
	  }
}

// show or hide DIV element
function showhide(divname,state) {
	//alert(state);
if (n4) {
divObj = eval (doc + divname);
//alert("hola n6");
 }
else {
divObj = eval (doc + divname + sty);
//alert("hola else");
}
divObj.visibility = state;
}


// variables that hold the value of the currently active (open) menu
var active_submenu1 = null;
var active_submenu2 = null;
var active_menuelem = null;
var active_topelem = null;

// function closes all active menus and turns back to 'off' state
function closeallmenus() {
if(active_submenu1 != null) {
	//alert("hola");
  showhide(active_submenu1,'hidden');
  }
if(active_submenu2 != null) {
  showhide(active_submenu2,'hidden');
  }
if(active_menuelem != null) {
  changecolor(active_menuelem,offcolor);
  }
if(active_topelem != null) {
  onoff('main_menu',active_topelem,'off');
  }
}

// the menu close timeout variable
var menu_close_timeout = 0;

// delay in miliseconds until the open menus are closed
var delay = 500;

// function calls the closeallmenus() function after a delay
function closeall() {
menu_close_timeout = setTimeout('closeallmenus()',delay);
}

// stop all timeout functions (stops menus from closing)
function stopall() {
clearTimeout(menu_close_timeout);
}

// function controls submenus 
function controlsubmenu(submenu1,submenu2,menuelem,topelem) {
stopall();
closeallmenus();
if (submenu1 != null) {
  showhide(submenu1,'visible');
  active_submenu1 = submenu1;
  }
if (submenu2 != null) {
 showhide(submenu2,'visible');
 active_submenu2 = submenu2;
  }
if (menuelem != null) {
 changecolor(menuelem,oncolor);
 active_menuelem = menuelem;
 }
if (topelem != null) {
 onoff('main_menu',topelem,'on');
 active_topelem = topelem;
 }
}


function initialize(idioma) {
	preload(idioma);
	closeallmenus();
	stopall();
}

// funció per a mostrar i ocultar els preus de les temporades turístiques

//funció per a fer VISIBLES les temporades	
function mostrar(quin_on){
		var desplegable = document.getElementById(quin_on);
		desplegable.style.visibility = "visible";
	}
//funció per a fer INVISIBLES les temporades	
function amagar(quin_off){
		var plegable = document.getElementById(quin_off);
		plegable.style.visibility = "hidden";
	}
	
//CANVIAR FOTOS DE  LES AMPLIACIONS DE VILLADET
function ampliar_foto(quin_zoom){
		ampliacio.src=quin_zoom;
}//

//FUNCIO PER A FER EL ROLLOVER DELS DIES DISPONIBLES DEL CALENDARI DE RESERVAR	
 function canviar_color_selec(on){
	rollo=document.getElementById("calendari_availa_"+on);
	rollo.className = 'calendari_available_roll';
	}
function tornar_hi(on){
	rollo=document.getElementById("calendari_availa_"+on);
	rollo.className = 'calendari_hi';
	}	
function tornar_lo(on){
	rollo=document.getElementById("calendari_availa_"+on);
	rollo.className = 'calendari_lo';
	}	
function tornar_med(on){
	rollo=document.getElementById("calendari_availa_"+on);
	rollo.className = 'calendari_med';
	}	
	
	
//ENFOCAR I DESENFOCAR FORMULARI	
function enfocar (quin){
	quin.className = 'reserva_formu_focus';
	if (quin.value == "Introduzca aquí su texto") quin.value='';
}
function desenfocar (quin){
	quin.className = 'reserva_formu';
}



//GALERIA D'APARTAMENTS
var imatge=new Array
	imatge[0]="v01.jpg";
	imatge[1]="v02.jpg";
	imatge[2]="v03.jpg";
	imatge[3]="v04.jpg";
	imatge[4]="v05.jpg";
	imatge[5]="v06.jpg";
	imatge[6]="v07.jpg";
	imatge[7]="v08.jpg";
	imatge[8]="v09.jpg";
	imatge[9]="v10.jpg";
	imatge[10]="v11.jpg";
	imatge[11]="v12.jpg";
	imatge[12]="v13.jpg";
	imatge[13]="v14.jpg";
	imatge[14]="v15.jpg";
	imatge[15]="v16.jpg";
	imatge[16]="v17.jpg";
	imatge[17]="v18.jpg";
	imatge[18]="v19.jpg";
	imatge[19]="v20.jpg";
	imatge[20]="v21.jpg";
	imatge[21]="v22.jpg";
	imatge[22]="v23.jpg";
	imatge[23]="v24.jpg";
	imatge[24]="v25.jpg";
	imatge[25]="v26.jpg";
//la primera imatge que es mostra quan es carrega la pàgina
function quina_villa(){ 	
		var	num_villa=Math.round(Math.random()*25);
		canvidevilla.src="/imatges/weekend/"+imatge[num_villa];
	}
//

	
// ALGUNES FUNCIONS PROPIES DE DREAMWEAVER PER VALIDAR FORMULARIS
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_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}
	
// Contenido de los archivos de script AC_ActiveX.js y AC_RunActiveContent.js

//v1.0
//Copyright 2006 Adobe Systems, Inc. All rights reserved.
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}

// AC_ActiveX.js

//v1.1
//Copyright 2006 Adobe Systems, Inc. All rights reserved.
function AC_AX_RunContent(){
  var ret = AC_AX_GetArgs(arguments);
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_AX_GetArgs(args){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "pluginspage":
      case "type":
      case "src":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "data":
      case "codebase":
      case "classid":
      case "id":
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  return ret;
}

	
