// JavaScript Document

				
		///////// FUNCIONS FORMULARI DE RESERVES ////////////////

///////// FUNCIONS FORMULARI DE RESERVES ////////////////
var inicial="";
function ajaxpage(url, containerid){
	
	if (inicial!=""){
		oculta(inicial);
	}
	
	inicial=containerid;
 document.getElementById(containerid).style.display="block";
 var page_request = false
 
 if (window.XMLHttpRequest) // if Mozilla, Safari etc
  page_request = new XMLHttpRequest() 
 else if (window.ActiveXObject){ // if IE
  try {
    page_request = new ActiveXObject("Msxml2.XMLHTTP")
  }
  
  catch (e){
  try{
   page_request = new ActiveXObject("Microsoft.XMLHTTP")
  }
  catch (e){}
  }
  }
  else
  return false   	 

  page_request.onreadystatechange=function(){  	
  loadpage(page_request, containerid)
  }
  
  page_request.open('GET', url, true)
  page_request.send(null)  
}


function loadpage(page_request, containerid){	
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
		document.getElementById(containerid).innerHTML=page_request.responseText
}
 
function loadobjs(){
  if (!document.getElementById)
  return
  for (i=0; i<arguments.length; i++){
  var file=arguments[i]
  var fileref=""
  if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
  if (file.indexOf(".js")!=-1){ //If object is a js file
  fileref=document.createElement('script')
  fileref.setAttribute("type","text/javascript");
  fileref.setAttribute("src", file);
  }
  else if (file.indexOf(".css")!=-1){ //If object is a css file
  fileref=document.createElement("link")
  fileref.setAttribute("rel", "stylesheet");
  fileref.setAttribute("type", "text/css");
  fileref.setAttribute("href", file);
  }
  }
  if (fileref!=""){
  document.getElementsByTagName("head").item(0).appendChild(fileref)
  loadedobjects+=file+" " //Remember this object as being already added to page
  }
  }
  }
 
  
  function carregar_calendari(target,mes,any,mes_any,dia_sel,tipus_data,idm,f)
	{
		document.getElementById(target).innerHTML = '';
		var myConn = new XHConn();
		if (!myConn) alert("XMLHTTP no esta disponible. Inténtalo con un navegador más actual.");
		var peticion = function (oXML) {  document.getElementById(target).innerHTML = oXML.responseText; };
		myConn.connect("includes/cal.php?f="+f+"&mes="+mes+"&any="+any+"&mes_any="+mes_any+"&item_oculta="+target+"&dia_sel="+dia_sel+"&tipus_data="+tipus_data+"&idm="+idm+"&", "GET", "", peticion);
	} 
	
function cargar_contenido2(target,dades)
 {
 	alert(target+" - "+dades);
  document.getElementById(target).innerHTML = '<table bgcolor="CCCCCC" class="load"><tr><td>Cargan dades...</td></tr></table>';
  var myConn = new XHConn();
   if (!myConn) alert("XMLHTTP no esta disponible. Inténtalo con un navegador más actual.");
   var peticion = function (oXML) {  document.getElementById(target).innerHTML = oXML.responseText; };
   myConn.connect(dades, "GET", "", peticion);
 }
 
 function oculta(element){
  document.getElementById(element).style.display="none";
}

function menor(x){
	x=parseInt(x);
	if (x<10){x="0"+x;}
	return x;
}


// FUNCIONS DE CANVI DE IMATGE //

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_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_openBrWindow(theURL,winName,features,dades1,dades2,tipus_data) { //v2.0
  theURL=theURL+"&mes_any="+dades1+"&dia_sel="+dades2+"&tipus_data="+tipus_data;
  window.open(theURL,winName,features);
}

function obre_finestra(theURL,winName,features) {
	alert(theURL); alert(winName); alert(features);
  window.open(theURL,winName,features);
}

	
function startSlideshow() {
	var slideshow1 = new timedSlideShow($('mySlideshow1'), mySlideData1);
	var slideshow2 = new timedSlideShow($('mySlideshow2'), mySlideData2);
	var slideshow3 = new timedSlideShow($('mySlideshow3'), mySlideData3);
	var slideshow4 = new timedSlideShow($('mySlideshow4'), mySlideData4);
}

function startSlideshow2() {
	var slideshow5 = new timedSlideShow($('mySlideshow5'), mySlideData5);
}

function startSlideshow3() {
	var slideshow6 = new timedSlideShow($('mySlideshow6'), mySlideData6);
}



function scrollVertical(id){
 
  var xScroll, yScroll;
  if (window.innerHeight && window.scrollMaxY) {
   xScroll = window.innerWidth + window.scrollMaxX;
   yScroll = window.innerHeight + window.scrollMaxY;
  } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
   xScroll = document.body.scrollWidth;
   yScroll = document.body.scrollHeight;
  } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
   xScroll = document.body.offsetWidth;
   yScroll = document.body.offsetHeight;
  }
  var windowWidth, windowHeight;
  if (self.innerHeight) { // all except Explorer
   if(document.documentElement.clientWidth){
    windowWidth = document.documentElement.clientWidth;
   } else {
    windowWidth = self.innerWidth;
   }
   windowHeight = self.innerHeight;
  } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
   windowWidth = document.documentElement.clientWidth;
   windowHeight = document.documentElement.clientHeight;
  } else if (document.body) { // other Explorers
   windowWidth = document.body.clientWidth;
   windowHeight = document.body.clientHeight;
  }
  // for small pages with total height less then height of the viewport
  if(yScroll < windowHeight){
   pageHeight = windowHeight;
 
  } else {
   pageHeight = yScroll;
 
  }
  // for small pages with total width less then width of the viewport
  if(xScroll > windowWidth){
   pageWidth = xScroll; 
  } else {
   pageWidth = windowWidth;
  }
 
 document.getElementById(id).style.height=pageHeight+"px";//scroll vertical
 
}

function scrollVertical2 (id, id2)
{
	document.getElementById(id).style.height = document.getElementById(id2).offsetHeight+"px";
}

function send (m1, m2, m3, m4)
{
	var nom = document.getElementById('nom').value;
	var tlfn = document.getElementById('tlfn').value;
	var email = document.getElementById('email').value;

    //Validem nom
    if (nom.length==0){
       alert(m1)
       document.getElementById('nom').focus();
       return 0;
    }
      
     //Validem tlfn
     if (tlfn.length==0){
       alert(m2)
        document.getElementById('tlfn').focus();
       return 0;
    }
    
    //Validem email
     if (email.length==0){
       alert(m3)
       document.getElementById('email').focus();
       return 0;
    }
        
    //Controlem que el mail tingui el format correcte
    if (email.length > 0)
    {
    	apos = email.indexOf("@");
		dotpos = email.lastIndexOf(".");
		
		if (apos<1 || dotpos-apos<2) 
	  	{
	  		alert(m4);
	  		document.getElementById('email').focus();
    		return 0;
	  	}
    }
         
   	document.getElementById('formulari').submit();	
}

//--------------------- LOAD MAPA GOOGLE ------------------------------->
//<![CDATA[
function load() {
	if (GBrowserIsCompatible()) {
	
		 var map = new GMap2(document.getElementById("mapa_google"));	
		 map.setUIToDefault();
		//centrem mapa 
		 var una=41.883450;
		 var dos=2.706478;
		 map.setCenter(new GLatLng(una, dos), 13);						          
		
		var icon = new GIcon();
		icon.image = "logo_mapa.png"; //icona	
		icon.iconSize = new GSize(40,50); // tamany icona	
		icon.iconAnchor = new GPoint(1, 50);
		icon.infoWindowAnchor = new GPoint(1, 50);	
		var point = new GLatLng(una,dos);
		map.addOverlay(new GMarker(point, icon));	
	
	}
}
//]]>
//--------------------- LOAD MAPA GOOGLE ------------------------------->

function canvi_idioma(url,idio){
	if(url.indexOf('idm=1')==-1 && url.indexOf('idm=2')==-1 && url.indexOf('idm=7')==-1){
		url = url+'index.php?idm='+idio;
	}else{
		url = url.replace("idm=1", "idm="+idio);
		url = url.replace("idm=2", "idm="+idio);
		url = url.replace("idm=7", "idm="+idio);
	}
	self.location=url;
}