var highZ = 3;
var i=0;
var resp=1;
var x_fet='';
var pantalla=0;
var demoApp;
startList = function() {

	document.getElementById('divPopup').style.visibility = 'hidden';
pestanyetes(0);
  d3Setup();
  stripedTable();
 // mapa();

if (document.all&&document.getElementById) {
navRoot = document.getElementById("nav");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace(" over", "");
   }
   }
  }
 }
 
}

function inicialitze () {

	demoApp = new PromptMe;
	}


function PromptMe() {
	// some application vars
	var stateVar = "nothin'", displayDiv = document.getElementById("output");
	var num_add='-1';
	// the sole public method to manipulate this application
	this.promtForNew = function(tip) {

		unFocus.History.addHistory(tip);
		
	};

	// This is the method that will recieve notifications from the History Keeper,
	// which will then update the state of the app.
	// :NOTE: This will be called when a new entry is added.
	// :NOTE: This will be called if another app on the page sets a history,
	//        so you will need to watch out for this, if you have more than
	//        one script using the history keeper, by doing some kind of 
	//        check to make sure that the new hash belongs to this app.
	//        I wouldn't expect this to be a problem all that frequently.
	this.historyListener = function(historyHash) {

		if(historyHash!="")
		{
		var num_tip = historyHash;
		xmlhttpPost_Datos(num_tip);
		}
		else
		{
		//unFocus.History.addHistory(1);
		}
	
		stateVar = historyHash;
		// update display content
		//displayDiv.innerHTML =historyHash;
		// update document title
		//document.title = "unFocus History Keeper - Current History: " + historyHash;
		num_add++;

	};
	// subscribe to unFocus.History

	unFocus.History.addEventListener('historyChange', this.historyListener);
	
	// Check for an initial value (deep link).
	// In this demo app, the historyListener can handle the task.
	this.historyListener(unFocus.History.getCurrent());
	
	num_add++;
};
// instantiate and inialize the app. DOM has to be ready so we can get a ref to
// the HistoryState DOM element (aka the view), so we use QuickLoader to make
// sure it's ready.





function preguntar_alert(tip)
{
	switch(tip)
		{

  case 1:
 		if(confirm(eliminar_tarea)) return true;
 		else return false;
   break;
	}
}

function finalizar_registro(captcha)
{
if(captcha=='1') comprovar_captcha(1);
	if(comprovar_camps2(captcha)) 
	{
	
	// x=codi_captcha(); 
	
	xmlhttpPost_Datos(33);
	 
	}
 }



function desactivar(tip)
{
		document.getElementById(tip).className = "desactivat";


}

function comprovar_camps()
{
var ob = document.getElementById("obligatori");
var valors = ob.getElementsByTagName('input');
no_enviar=1;
campo=campo_obligatorio;
for (i=0; i<valors.length; i++)
 {
 eval ('var valor = document.form.'+valors[i].id+'.value');
 if(valor=="") 
	{
	no_enviar=0;
eval ('document.getElementById("error'+valors[i].id+'").innerHTML = campo;');

	eval ('document.getElementById("error'+valors[i].id+'").style.display = "block";');
	}
else
	{
	eval ('document.getElementById("error'+valors[i].id+'").style.display = "none";');
	}
	
 }
 return no_enviar;
}


function comprovar_camps2(captcha)
{
var ob = document.getElementById("obligatori");
var valors = ob.getElementsByTagName('input');
no_enviar=1;
campo=campo_obligatorio;


for (i=0; i<valors.length; i++)
 {
if(valors[i].id!='a13')
{
 eval ('var valor = document.registro1.'+valors[i].id+'.value');
 if(valor=="") 
	{
	no_enviar=0;
	eval ('document.getElementById("error'+valors[i].id+'").innerHTML = campo;');
	eval ('document.getElementById("error'+valors[i].id+'").style.display = "block";');
	}
else
	{
	eval ('document.getElementById("error'+valors[i].id+'").style.display = "none";');
	}
}	
 }
 eval ('var valor = document.getElementById("usuario").value');
  eval ('var valor2 = document.getElementById("pass").value');
    eval ('var valor3 = document.getElementById("pass2").value');
	
	if(valor2!=valor3)
	{
		campo2="No coincide la contraseña";
		eval ('document.getElementById("errorapass2").innerHTML = campo2;');
		eval ('document.getElementById("errorapass2").style.display = "block";');
		no_enviar=0;
	}
	if(valor=="")
	{
		eval ('document.getElementById("errorausuario").innerHTML = campo;');
		eval ('document.getElementById("errorausuario").style.display = "block";');
		no_enviar=0;
		
	}
	else
	{
		eval ('document.getElementById("errorausuario").style.display = "none";');
	}
 	if(valor2=="")
	{
		eval ('document.getElementById("errorapass").innerHTML = campo;');
		eval ('document.getElementById("errorapass").style.display = "block";');
		no_enviar=0;
	}
	else 
	{
		eval ('document.getElementById("errorapass").style.display = "none";');
	}
	
	 if(valor3=="")
	{
		eval ('document.getElementById("errorapass2").innerHTML = campo;');
		eval ('document.getElementById("errorapass2").style.display = "block";');
		no_enviar=0;
	}
	else if (valor2==valor3)
	{
		eval ('document.getElementById("errorapass2").style.display = "none";');
	}
	
	if(document.log.log_repetit.value=="1")
	{
		no_enviar=0;
			document.getElementById("errorausuario").innerHTML = login_ya_existe;
			document.getElementById("errorausuario").style.display = 'block';

	}
	if(captcha=="1")
	{
		if(document.log.captcha.value=="1")
		{
						eval ('document.getElementById("errorachapta").innerHTML = '+captcha_no_correcto+';');
						eval ('document.getElementById("errorachapta").style.display = "block";');
						no_enviar=0;

		}
		else
		{
		eval ('document.getElementById("errorachapta").style.display = "none";');
		}
	}
	
	if(captcha=="1")
	{
		if(document.captcha.user_code.value=="")
		{
		
						eval ('document.getElementById("errorachapta").innerHTML = '+campo_obligatorio+';');
						eval ('document.getElementById("errorachapta").style.display = "block";');
						no_enviar=0;
		}
		else
		{
		eval ('document.getElementById("errorachapta").style.display = "none";');
		}
	}

	if(document.formNameid1.si_o_no.value=='0' && document.formNameid1.ob.value=='1')
	{
			eval ('document.getElementById("erroraimagen").innerHTML = "'+campo_obligatorio+'";');
			eval ('document.getElementById("erroraimagen").style.display = "block";');
			no_enviar=0;
	}
	else
	{
		eval ('document.getElementById("erroraimagen").style.display = "none";');
	}


 return no_enviar;
}

function comprovar_direccion_correo(nombre,tip)
{


	if(document.tuhora.email.value=="")
	{
	
	if(tip==3)
	{
	tancar_pantalla();
	}
	else
	{
		if (isEmailAddress(nombre)==false && nombre!=null )
		{
		
			if(tip==0) 	
				{
				if(document.tuhora.mail_confirm.value==0) pantalleta(0,3);	
				else pantalleta(1,3);	
				}
			else if(tip==1)
				{
				tancar_pantalla();
				if(document.tuhora.mail_confirm.value==0) pantalleta(0,4);	
				else pantalleta(1,4);	
				}

		}
		
		if (isEmailAddress(nombre)==true)
		{
			if(tip==2) 
				{
				observacions=document.obtener_correo.observacions.value;
				nom=document.obtener_correo.nom.value;
				}
			tancar_pantalla();
			document.tuhora.email.value=nombre;
			if(tip==2) 
				{
				document.tuhora.observaciones.value=observacions;
				document.tuhora.nom.value=nom;
				}
			if(document.tuhora.sistema_prepago.value==1) comprovar_sistema_prepago();
			else xmlhttpPost_Datos(7);
		}

	}
	
	
	}
	else if(document.tuhora.pedir_obs.value==1) 
	{
		if(tip==4)
		{
			observacions=document.obtener_correo.observacions.value;
			nom=document.obtener_correo.nom.value;
			tancar_pantalla();
			document.tuhora.observaciones.value=observacions;
			document.tuhora.nom.value=nom;
			if(document.tuhora.sistema_prepago.value==1) comprovar_sistema_prepago();
			else xmlhttpPost_Datos(7);
		}
		else
		{
		if(tip==3)
		{
			tancar_pantalla();
		}
		else pantalleta(0,5);
		}
	}
	
	else{
			if(document.tuhora.sistema_prepago.value==1) comprovar_sistema_prepago();
			else xmlhttpPost_Datos(7);
	}
}

function comprovar_sistema_prepago()
{

prepago=document.tuhora.tipo_prepago.value;
var array_prepago=prepago.split(",");
num_tipos=array_prepago.length-1;

if(num_tipos==1) pantalleta(array_prepago[0],7);
else pantalleta(prepago,6);

}

function tancar_pantalla()
{
	var div_borrar = document.getElementById('LB_window');
	var padre = div_borrar.parentNode;
	var hijoRemovido = padre.removeChild(div_borrar);
						
	var div_borrar = document.getElementById('LB_overlay');
	var padre = div_borrar.parentNode;
	var hijoRemovido = padre.removeChild(div_borrar);	
}


function isEmailAddress(direccio)
{
var filter=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if (filter.test(direccio) && direccio.length!=0) return true;
else return false;
}

function comprovar_camps3(captcha)
{
no_enviar=1;
if(captcha=='1')
{
comprovar_captcha(0);
}

if(captcha=='1')
{

if(document.log.captcha.value=="1")
	{
					eval ('document.getElementById("errorachapta").innerHTML = "'+chaptcha_no_correcto+'";');
					eval ('document.getElementById("errorachapta").style.display = "block";');
					no_enviar=0;

	}
	else
	{
	eval ('document.getElementById("errorachapta").style.display = "none";');
	}
	
	if(document.tuhora.user_code.value=="")
	{
	
					eval ('document.getElementById("errorachapta").innerHTML = "'+campo_obligatorio+'";');
					eval ('document.getElementById("errorachapta").style.display = "block";');
					no_enviar=0;
	}
	else
	{
	eval ('document.getElementById("errorachapta").style.display = "none";');
	}
}
return no_enviar;	
}


function pestanyetes(tip)
{
var ob = document.getElementById("menu1");
var valors = ob.getElementsByTagName('li');
for (i=0; i<valors.length; i++)
 {
		//Primer els desactivem tots i despues activarem el q s'ha selecciona't
		 //if(valors[i].id=='i1') desactivar("inicio");
		 if(valors[i].id=='i2') desactivar("tuhora");
		 if(valors[i].id=='i3') desactivar("info");
		 if(valors[i].id=='i4') desactivar("imag");
		 if(valors[i].id=='i5') desactivar("noti");
		 if(valors[i].id=='i6') desactivar("formul");
		 if(valors[i].id=='i7') desactivar("reserv");
  }
switch(tip)
		{
		case 0:
		//document.getElementById("inicio").className = "activat";
		
		break;
		case 1:
		document.getElementById("tuhora").className = "activat";
		document.getElementById("menu_dalt").className = "i1";
		break;
		case 2:
		document.getElementById("imag").className = "activat";
		document.getElementById("menu_dalt").className = "i3";
		break;	
		case 3:
		document.getElementById("noti").className = "activat";
		document.getElementById("menu_dalt").className = "i4";
		break;
		case 4:
		document.getElementById("formul").className = "activat";
		document.getElementById("menu_dalt").className = "i5";
		break;
		case 5:
		document.getElementById("info").className = "activat";
		document.getElementById("menu_dalt").className = "i2";
		break;
		case 6:
		document.getElementById("reserv").className = "activat";
		document.getElementById("menu_dalt").className = "i6";
		break;
		}

}

function select_checkbox(id)
{

	
if(pantalla==0)
{
eval ('var check_servei=document.tuhora.a'+id+'.checked;');

if(check_servei==true)
	{
	eval ('document.tuhora.a'+id+'.checked=false;');
	}
else
	{
	eval ('document.tuhora.a'+id+'.checked=true;');
		
	}
	eval ('var ch=document.tuhora.a'+id+'.checked;');
	
	if(document.getElementById('escoger_operario').value=='1' && ch==true && pantalla==0)
	{
	if(isIE7==0) eval ('document.tuhora.selec'+id+'.style.display="block";');
	//else eval ('document.tuhora.selec'+id+'.disabled=false;');
	}
	else if(document.getElementById('escoger_operario').value=='1' && ch==false && pantalla==0)
	{
	if(isIE7==0) eval ('document.tuhora.selec'+id+'.style.display="none";');
	//else eval ('document.tuhora.selec'+id+'.disabled=true;');
	}
	
	if(document.getElementById('escoger_instalacion').value=='1' && ch==true && pantalla==0)
	{
	if(isIE7==0) eval ('document.tuhora.selecs'+id+'.style.display="block";');
	//else eval ('document.tuhora.selec'+id+'.disabled=false;');
	}
	else if(document.getElementById('escoger_instalacion').value=='1' && ch==false && pantalla==0)
	{
	if(isIE7==0) eval ('document.tuhora.selecs'+id+'.style.display="none";');
	//else eval ('document.tuhora.selec'+id+'.disabled=true;');
	}	
}
}

function change_val_select(id,tip)
{

if(tip==0) form="tuhora";
if(tip==1) form="tuhora_";
eval ('var valor_select=document.'+form+'.selec'+id+'.value;');
eval('var selects=document.tuhora.selects.value;');

var miArray=selects.split(",");
var miArray2="";
var fiselects="";
for (i = 0; i < miArray.length; i++){

         miArray2=miArray[i].split("/");
		 if(miArray2[0]==id) 
			{
			miArray2[1]=valor_select;
			}


		 
		 fiselects=fiselects+miArray2[0]+"/"+miArray2[1]+",";
}
eval('document.tuhora.selects.value="'+fiselects+'";');


}

function change_val_select2(id,tip)
{

if(tip==0) form="tuhora";
if(tip==1) form="tuhora_";
eval ('var valor_select=document.'+form+'.selecs'+id+'.value;');
eval('var selects=document.tuhora.selects2.value;');

var miArray=selects.split(",");
var miArray2="";
var fiselects="";
for (i = 0; i < miArray.length; i++){

         miArray2=miArray[i].split("/");
		 if(miArray2[0]==id) 
			{
			miArray2[1]=valor_select;
			}


		 
		 fiselects=fiselects+miArray2[0]+"/"+miArray2[1]+",";
}
eval('document.tuhora.selects2.value="'+fiselects+'";');


}

function desopacitar(id_)
{

eval ('var check_servei=document.tuhora.a'+id_+'.checked;');

if(check_servei==true)
	{
	eval ('document.getElementById("id'+id_+'").className ="noopacitat"');
	}
else
	{
		eval ('document.getElementById("id'+id_+'").className ="opacitat"');
		
	}
}

function pedir_hora()
{
	x=pedir_hora1 + document.getElementById('selec').value + pedir_hora2;
	y=confirm(x);
	
	if (y)
		{
			xmlhttpPost_Datos(7);			
		}
	
}

function pedir_hora2()
{
	x=pedir_hora1 + document.getElementById('selec').value + pedir_hora2;
	y=confirm(x);
	
	if (y)
		{
			var ob = document.getElementById("formnoms");
			var valors = ob.getElementsByTagName('input');
			var separator = "<separator>";
			var is = "<is>";
			var text = "";

			for (i=0; i<valors.length; i++)
			 {
			 eval ('var nom = document.formnoms.'+valors[i].id+'.value');
			 eval ('var valor = document.form.'+valors[i].id+'.value');
			 text=text+nom+is+valor+separator;
			 }
 

			  xmlhttpPost_Datos2(29,text);			
		}
	
}


function comprovar_captcha(tip)
{

  var xmlHttpReq = false;

    var self = this;

    if (window.XMLHttpRequest) // Mozilla & Safar
    {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) // IE
    {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
		self.xmlHttpReq.open('POST', 'inicio1.php', true);
	

    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

    self.xmlHttpReq.onreadystatechange=function()
    {
        if (self.xmlHttpReq.readyState == 4)
        {
			
            textReturn1 = unescape(self.xmlHttpReq.responseText);

				if(textReturn1=="0")
					{
								
					eval ('document.getElementById("errorachapta").innerHTML = "'+chaptcha_no_correcto+'";');
					eval ('document.getElementById("errorachapta").style.display = "block";');
					document.log.captcha.value='1';
					}
				else
					{			
					//eval ('document.getElementById("errorachapta").style.display = "none";');
						document.log.captcha.value='0';
					}
			
		}
		
	}

	
	if(tip==0) self.xmlHttpReq.send('tip=33&captcha='+document.tuhora.user_code.value);
	else self.xmlHttpReq.send('tip=33&captcha='+document.captcha.user_code.value);


}


function comprovar_login(tip,camp_error)
{
var xmlHttpReq = false;

    var self = this;

    if (window.XMLHttpRequest) // Mozilla & Safar
    {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) // IE
    {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
	
	self.xmlHttpReq.open('POST', 'comprovar_login.php', true);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function()
    {
        if (self.xmlHttpReq.readyState == 4)
        {
            textReturn = unescape(self.xmlHttpReq.responseText);
			
			if(textReturn>0) 
			{	
			document.getElementById(camp_error).innerHTML= login_ya_existe;
			document.getElementById(camp_error).style.display = 'block';
			document.log.log_repetit.value='1';
			}
			else 
			{
			document.getElementById(camp_error).style.display = 'none';
			document.log.log_repetit.value='0';
			}
        }
    }

			switch(tip)
		{

    	case 1:
		self.xmlHttpReq.send('tip=2&login='+document.registro1.usuario.value);
		break;

		
		}

}

function verSelects(){
pantalla=0;
if(!window.attachEvent) return false;
var selects = document.getElementsByTagName("select");
for( var i=0; i<selects .length; i++ )
	{
		if( selects[i].style.display == "block" )
		{
			selects[i].style.visibility = "visible";
		}
	}
}

function escondeSelects()
{
if(!window.attachEvent) return false;
var selects = document.getElementsByTagName("select");
for( var i=0; i<selects .length; i++ ){

if( selects[i].style.display == "block" )
		{
			selects[i].style.visibility = "hidden";
		}
}
}

function pantalleta(id,tipus)
{


switch(tipus)
{
	case 0:
		new LITBox('noticies.php?id='+id,{type:'window',overlay:true});
	break;
	case 1:
		new LITBox('informacion_detallada.php?id='+id,{ width:500,height: 290,type:'window',overlay:true});
	break;
	case 2:
		select_checkbox(id);
		pantalla=1;
		escondeSelects();
		new LITBox('informacion_detallada.php?id='+id,{ width:500,height: 290,type:'window',overlay:true});		
	break;
	case 3:
	if(document.tuhora.pedir_obs.value==1) 
		{
		width_pantalla=400;
		height_pantalla=350;
		}
		else 
		{
		width_pantalla=350; 
		height_pantalla=350;
		}
	new LITBox('obtener_correo.php?id='+id+'&pedir_obs='+document.tuhora.pedir_obs.value,{ width:width_pantalla,height: height_pantalla,type:'window',overlay:true});		
	break;
	case 4:
	if(document.tuhora.pedir_obs.value==1) 
		{
		width_pantalla=400;
		height_pantalla=350;
		}
		else 
		{
		width_pantalla=350; 
		height_pantalla=350;
		}
	new LITBox('obtener_correo.php?error=1&id='+id+'&pedir_obs='+document.tuhora.pedir_obs.value,{ width:width_pantalla,height: height_pantalla,type:'window',overlay:true});	
	break;
	case 5:
	new LITBox('obtener_correo.php?pedir_obs=1',{ width:350,height: 350,type:'window',overlay:true});		
	break;
	case 6:
	new LITBox('seleccionar_tipo_pago.php?tipo_prepago='+id,{ width:350,height: 150,type:'window',overlay:true});
	break;
	case 7:
	if(id=='-1')
		{
		id_tipo_prepago=document.getElementById('tipo_sistema_prepago').value;
		tancar_pantalla();
		}
	else
		{
		id_tipo_prepago=id;
		}

	
	xmlhttpPost_Datos(36);
	break;

	
	}
return false;
}

function xmlhttpPost_Datos(tip)
{


tip = parseInt(tip);

	changeModule ();
	
 		document.body.style.cursor = "wait";

    var xmlHttpReq = false;

    var self = this;

    if (window.XMLHttpRequest) // Mozilla & Safar
    {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) // IE
    {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
	if(tip==36) self.xmlHttpReq.open('POST', 'pasarela.php', true);
	else	self.xmlHttpReq.open('POST', 'inicio1.php', true);
	

    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

    self.xmlHttpReq.onreadystatechange = function()
    {
        if (self.xmlHttpReq.readyState == 4)
        {
            textReturn = unescape(self.xmlHttpReq.responseText);
			if(textReturn=="") window.location="index.php";
			else
			{
            var arrayReturn = textReturn.split('<ticketSeparator>'); 

            var showContent = arrayReturn[0].replace(/\+/gi," ");         
  		
		
  			
							
			document.getElementById('contenido1').innerHTML = showContent+"<div id='footer'><span>"+footer_contingut+"</span></div>";
			if (tip==36) document.sermepa.submit();
						
					if(tip!=1 && tip!=10)
					{
					  if (arrayReturn[2]==1) alert(arrayReturn[3]);
					}
					if(tip==1)
					{
					// document.getElementById('procesando').style.visibility = 'hidden';
					}
					if(tip==2 || tip==8 || tip==38)
					{
						initLightbox();
					}
					if(tip==27 || tip==3)
					{
					
					}

		switch(tip)
		{
		//0 es inicio
		//1 es pedir hora
		//2 es imagenes
		//3 es noticias
		//4 es formulario
		//5 es info 
		//6 es reserv
		case 0:
		pestanyetes(0);
		break;
	    case 1:
	    pestanyetes(1);
	    break;
	    case 2:
	    pestanyetes(2);
	    break;
	    case 3:
	    pestanyetes(3);
	    break;
	    case 4:
	    pestanyetes(4);
	    break;
	    case 5:
	    pestanyetes(5);
	    break;
	    case 6:
	    pestanyetes(1);
	    break;
	    case 7:
		pestanyetes(1);
	    break;
	    case 8:
	    pestanyetes(2);
	    break;
		case 10:
		pestanyetes(6);
		break;
		case 11:
	    pestanyetes(3);
	    break;
		case 12:
		pestanyetes(3);
	    break;
		case 13:
		pestanyetes(3);
	    break;
		case 14:
		pestanyetes(1);
	    break;
		case 15:
		pestanyetes(1);
	    break;
		case 16:
		pestanyetes(1);
	    break;		
		case 19:
		pestanyetes(6);
	    break;
		case 24:
		pestanyetes(1);
	    break;
		case 25:
		pestanyetes(1);
	    break;
	    case 26:
		pestanyetes(1);
	    break;
	    case 27:
		pestanyetes(3);
	    break;
		case 28:
		pestanyetes(1);
	    break;
	    
		}
		clavar();
        document.body.style.cursor = "auto";
            
			
			
					
			if(tip==1 || tip==2 || tip==5 || tip==4 || tip==3 || tip==10 || tip==38) 
			{
			if(!demoApp) inicialitze();
			else demoApp.promtForNew(tip);
			}	
        }
		}
    }


	 
		switch(tip)
		{
		case 0:
    self.xmlHttpReq.send('tip='+tip);
    break;
    case 1:
    self.xmlHttpReq.send('tip='+tip);
    break;
    case 2:
    self.xmlHttpReq.send('tip='+tip);
    break;
    case 3:
    self.xmlHttpReq.send('tip='+tip);
    break;
    case 4:
    self.xmlHttpReq.send('tip='+tip);
    break;
    case 5:
    self.xmlHttpReq.send('tip='+tip);
    break;
    case 6:
    self.xmlHttpReq.send('check='+document.tuhora.checks.value+'&dia='+document.getElementById('showDia').value+'&ano='+document.getElementById('showAno').value+'&mes='+document.getElementById('showMes').value+'&selects='+document.getElementById('selects').value+'&selects2='+document.getElementById('selects2').value+'&tip='+tip);
    break;
    case 7:
    self.xmlHttpReq.send('id_reserv='+document.tuhora.id_reserv.value+'&idtareas='+document.tuhora.ids_tareas.value+'&editar='+document.tuhora.editar.value+'&check='+document.tuhora.checks.value+'&tip='+tip+'&dia='+document.getElementById('showDia').value+'&ano='+document.getElementById('showAno').value+'&mes='+document.getElementById('showMes').value+'&anoChange='+document.getElementById('showAno').value+'&mesChange='+document.getElementById('showMes').value+'&hora_selec='+document.getElementById('selec').value+'&selects='+document.getElementById('selects').value+'&selects2='+document.getElementById('selects2').value+'&email='+document.tuhora.email.value+'&observaciones='+document.tuhora.observaciones.value+'&nom='+document.tuhora.nom.value);
    break;
    case 8:
    self.xmlHttpReq.send('tip='+tip+'&pag='+document.galeria.pag.value);
    break;
	case 10:
	  self.xmlHttpReq.send('tip='+tip);
	break;
	case 11:
    self.xmlHttpReq.send('dia='+document.getElementById('showDia').value+'&ano='+document.getElementById('showAno').value+'&mes='+document.getElementById('showMes').value+'&anoChange='+document.getElementById('ano_anterior').value+'&mesChange='+document.getElementById('mes_anterior').value+'&tip='+tip);
    break;
	case 12:
   self.xmlHttpReq.send('dia='+document.getElementById('showDia').value+'&ano='+document.getElementById('showAno').value+'&mes='+document.getElementById('showMes').value+'&anoChange='+document.getElementById('ano_siguiente').value+'&mesChange='+document.getElementById('mes_siguiente').value+'&tip='+tip);
    break;
	 case 13:
    self.xmlHttpReq.send('dia='+document.getElementById('showDia').value+'&ano='+document.getElementById('showAno').value+'&mes='+document.getElementById('showMes').value+'&anoChange='+document.getElementById('showAno').value+'&mesChange='+document.getElementById('showMes').value+'&tip='+tip);
    break;
	case 14:
    self.xmlHttpReq.send('check='+document.tuhora.checks.value+'&idtareas='+document.tuhora.ids_tareas.value+'&id_reserv='+document.tuhora.id_reserv.value+'&dia='+document.getElementById('showDia').value+'&ano='+document.getElementById('showAno').value+'&mes='+document.getElementById('showMes').value+'&anoChange='+document.getElementById('ano_anterior').value+'&mesChange='+document.getElementById('mes_anterior').value+'&tip='+tip+'&selects='+document.getElementById('selects').value+'&selects2='+document.getElementById('selects2').value+'&seleccionat_reserva='+document.tuhora.seleccionat_reserva.value);
    break;
	case 15:
    self.xmlHttpReq.send('check='+document.tuhora.checks.value+'&idtareas='+document.tuhora.ids_tareas.value+'&id_reserv='+document.tuhora.id_reserv.value+'&dia='+document.getElementById('showDia').value+'&ano='+document.getElementById('showAno').value+'&mes='+document.getElementById('showMes').value+'&anoChange='+document.getElementById('ano_siguiente').value+'&mesChange='+document.getElementById('mes_siguiente').value+'&tip='+tip+'&selects='+document.getElementById('selects').value+'&selects2='+document.getElementById('selects2').value+'&seleccionat_reserva='+document.tuhora.seleccionat_reserva.value);
    break;
    case 16:
    self.xmlHttpReq.send('check='+document.tuhora.checks.value+'&idtareas='+document.tuhora.ids_tareas.value+'&id_reserv='+document.tuhora.id_reserv.value+'&dia='+document.getElementById('showDia').value+'&ano='+document.getElementById('showAno').value+'&mes='+document.getElementById('showMes').value+'&anoChange='+document.getElementById('showAno').value+'&mesChange='+document.getElementById('showMes').value+'&tip='+tip+'&selects='+document.getElementById('selects').value+'&selects2='+document.getElementById('selects2').value+'&seleccionat_reserva='+document.tuhora.seleccionat_reserva.value);
    break;
	case 19:
	
    self.xmlHttpReq.send('tip=10&id_reserv='+document.reserv.id_reserva.value);
    break;
	case 24:
    self.xmlHttpReq.send('check='+document.tuhora.checks.value+'&dia='+document.getElementById('showDia').value+'&ano='+document.getElementById('showAno').value+'&mes='+document.getElementById('showMes').value+'&anoChange='+document.getElementById('ano_anterior').value+'&mesChange='+document.getElementById('mes_anterior').value+'&tip='+tip+'&selects='+document.getElementById('selects').value+'&selects2='+document.getElementById('selects2').value);
    break;
	case 25:
    self.xmlHttpReq.send('check='+document.tuhora.checks.value+'&dia='+document.getElementById('showDia').value+'&ano='+document.getElementById('showAno').value+'&mes='+document.getElementById('showMes').value+'&anoChange='+document.getElementById('ano_siguiente').value+'&mesChange='+document.getElementById('mes_siguiente').value+'&tip='+tip+'&selects='+document.getElementById('selects').value+'&selects2='+document.getElementById('selects2').value);
    break;
    case 26:
    self.xmlHttpReq.send('check='+document.tuhora.checks.value+'&dia='+document.getElementById('showDia').value+'&ano='+document.getElementById('showAno').value+'&mes='+document.getElementById('showMes').value+'&anoChange='+document.getElementById('showAno').value+'&mesChange='+document.getElementById('showMes').value+'&tip='+tip+'&selects='+document.getElementById('selects').value+'&selects2='+document.getElementById('selects2').value);
    break;
    case 27:
    self.xmlHttpReq.send('tip='+tip+'&pag='+document.galeria.pag.value);
    break;
	case 28:
	 self.xmlHttpReq.send('id_reserv='+document.tuhora.id_reserv.value+'&idtareas='+document.tuhora.ids_tareas.value+'&editar='+document.tuhora.editar.value+'&check='+document.tuhora.checks.value+'&tip='+tip+'&dia='+document.getElementById('showDia').value+'&ano='+document.getElementById('showAno').value+'&mes='+document.getElementById('showMes').value+'&anoChange='+document.getElementById('showAno').value+'&mesChange='+document.getElementById('showMes').value+'&hora_selec='+document.getElementById('selec').value);
	break;
	case 33:
	 self.xmlHttpReq.send('tip='+document.registro.pantalla.value+'&pantalla='+document.registro.pantalla.value+'&registro_usuario=1&usuario='+document.registro1.usuario.value+'&pass='+document.registro1.pass.value+'&a1='+document.registro1.a1.value+'&a2='+document.registro1.a2.value+'&a3='+document.registro1.a3.value+'&a4='+document.registro1.a4.value+'&a5='+document.registro1.a5.value+'&a6='+document.registro1.a6.value+'&a7='+document.registro1.a7.value+'&a8='+document.registro1.a8.value+'&a9='+document.registro1.a9.value+'&a10='+document.registro1.a10.value+'&a11='+document.registro1.a11.value+'&a12='+document.registro1.a12.value+'&a14='+document.registro1.a14.value);
	break;
	case 34:
	    self.xmlHttpReq.send('tip='+tip);
	break;
	case 35:
	var top=document.getElementById('tableContainer').scrollTop;
	self.xmlHttpReq.send('id_reserv='+document.tuhora.id_reserv.value+'&idtareas='+document.tuhora.ids_tareas.value+'&editar='+document.tuhora.editar.value+'&check='+document.tuhora.checks.value+'&tip='+tip+'&dia='+document.getElementById('showDia').value+'&ano='+document.getElementById('showAno').value+'&mes='+document.getElementById('showMes').value+'&anoChange='+document.getElementById('showAno').value+'&mesChange='+document.getElementById('showMes').value+'&hora_selec='+document.getElementById('selec').value+'&scroll1='+top+'&selects='+document.getElementById('selects').value+'&selects2='+document.getElementById('selects2').value);

		
	break;
	case 36:

	self.xmlHttpReq.send('id_reserv='+document.tuhora.id_reserv.value+'&idtareas='+document.tuhora.ids_tareas.value+'&editar='+document.tuhora.editar.value+'&check='+document.tuhora.checks.value+'&tip='+tip+'&dia='+document.getElementById('showDia').value+'&ano='+document.getElementById('showAno').value+'&mes='+document.getElementById('showMes').value+'&anoChange='+document.getElementById('showAno').value+'&mesChange='+document.getElementById('showMes').value+'&hora_selec='+document.getElementById('selec').value+'&selects='+document.getElementById('selects').value+'&selects2='+document.getElementById('selects2').value+'&email='+document.tuhora.email.value+'&observaciones='+document.tuhora.observaciones.value+'&nom='+document.tuhora.nom.value+'&id_tipo_prepago='+id_tipo_prepago+'&preu='+document.tuhora.preu.value);
	break;
	case 37:
	  self.xmlHttpReq.send('tip='+tip);
	break;
	case 38:
	  self.xmlHttpReq.send('tip='+tip);
	break;        
		}
      

}


function xmlhttpPost_Datos2(tip,another1)
{


	// document.getElementById('procesando').style.visibility = 'visible';
					
	changeModule ();
	
 		document.body.style.cursor = "wait";
		
    var xmlHttpReq = false;

    var self = this;

    if (window.XMLHttpRequest) // Mozilla & Safar
    {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) // IE
    {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
	if(tip==35) self.xmlHttpReq.open('POST', 'ini.php', true);
	else
	{
		self.xmlHttpReq.open('POST', 'inicio1.php', true);
	}

    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

    self.xmlHttpReq.onreadystatechange = function()
    {
        if (self.xmlHttpReq.readyState == 4)
        {
            textReturn = unescape(self.xmlHttpReq.responseText);
			if(textReturn=="") window.location="index.php";
			else
			{
            var arrayReturn = textReturn.split('<ticketSeparator>'); 
            var showContent = arrayReturn[0].replace(/\+/gi," ");       

			
				if(tip!=9)
					{
					  if (arrayReturn[2]==1) alert("Actualmente no disponemos de ningún operario que realize esta tarea");
					}
					
					if(tip==35)
					{
					document.body.innerHTML = showContent;
								switch(pag)
								{
								case 0:
								xmlhttpPost_Datos(1); 
								break;
								case 1:
								xmlhttpPost_Datos(5); 
								break;
								case 2:
								xmlhttpPost_Datos(2); 
								break;
								case 3:
								xmlhttpPost_Datos(3); 
								break;
								case 4:
								xmlhttpPost_Datos(4); 
								break;
								case 5:
								xmlhttpPost_Datos(10); 
								break;								
								}
					
					}
					else
					{
						document.getElementById('contenido1').innerHTML = showContent+"<div id='footer'><span>"+footer_contingut+"</span></div>";
					}
						           // document.getElementById('procesando').style.visibility = 'hidden';
						
            document.body.style.cursor = "auto";
                             switch(tip)
								{
								//0 es inicio
								//1 es pedir hora
								//2 es imagenes
								//3 es noticias
								//4 es formulario
								//5 es info 
								//6 es reserv
							    case 1:
							    pestanyetes(1);
							    break;
								case 6:
								pestanyetes(1);
								break;
							    case 9:
								pestanyetes(1);
								break;
								case 17:
								pestanyetes(6);
								break;
								case 18:
								pestanyetes(1);
								break;
								case 20:
								pestanyetes(6);
								break;
								case 21:
								pestanyetes(1);
								break;
								case 29:
								pestanyetes(1);
								break;								
								case 30:
								pestanyetes(1);
								break;
								case 31:
								pestanyetes(6);
								break;		
								case 32:
								pestanyetes(another1);
								break;
								case 33:
								pestanyetes(1);
								break;
								case 34:
								pestanyetes(1);
								break;
								case 35:
								pestanyetes(1);
								break;
						        }
					if(tip==9)
					{
					 document.getElementById('tableContainer').scrollTop=arrayReturn[2];
					}
					clavar();
					}
								
    }
	}


	 
		switch(tip)
		{
	
    case 1:
    a='a'+another1;
     eval ('var valueCampo = document.tu_hora.'+a+'.checked');
    self.xmlHttpReq.send('dia='+document.getElementById('showDia').value+'&ano='+document.getElementById('showAno').value+'&mes='+document.getElementById('showMes').value+'&anoChange='+document.getElementById('showAno').value+'&mesChange='+document.getElementById('showMes').value+'&tip='+tip+'&algun_checked=1&another='+another1+'&ch1='+valueCampo);
    break;
    case 6:
    eval ('var valueCampo = document.tuhora1.a'+another1+'.checked');
    self.xmlHttpReq.send('check='+document.tuhora.checks.value+'&dia='+document.getElementById('showDia').value+'&ano='+document.getElementById('showAno').value+'&mes='+document.getElementById('showMes').value+'&anoChange='+document.getElementById('showAno').value+'&mesChange='+document.getElementById('showMes').value+'&tip='+tip+'&algun_checked=1&another='+another1+'&check_sino='+valueCampo+'&selects='+document.getElementById('selects').value+'&selects2='+document.getElementById('selects2').value+'&id_reserv='+document.tuhora.id_reserv.value);
    break;
    case 9:
	var top=document.getElementById('tableContainer').scrollTop;
    //eval ('var valueCampo = document.tuhora1.a'+another1+'.checked');
    self.xmlHttpReq.send('check='+document.tuhora.checks.value+'&dia='+document.getElementById('showDia').value+'&ano='+document.getElementById('showAno').value+'&mes='+document.getElementById('showMes').value+'&anoChange='+document.getElementById('showAno').value+'&mesChange='+document.getElementById('showMes').value+'&tip=6&algun_checked=1&seleccionat='+another1+'&selects='+document.getElementById('selects').value+'&selects2='+document.getElementById('selects2').value+'&id_reserv='+document.tuhora.id_reserv.value+'&scroll1='+top+'&editar='+document.tuhora.editar.value+'&id_reserv='+document.tuhora.id_reserv.value+'&hora='+another1);	

    break;
	case 17:
	 self.xmlHttpReq.send('tip='+tip+'&id_servei='+another1);
	break;
	case 18:
	eval ('var checks = document.a'+another1+'.checks.value');
	eval ('var checks_ = document.a'+another1+'.checks_.value');
	eval ('var checks1 = document.a'+another1+'.checks1.value');	
	eval ('var checks2 = document.a'+another1+'.checks2.value');	
	eval ('var dia = document.a'+another1+'.dia.value');
	eval ('var mes = document.a'+another1+'.mes.value');
	eval ('var ano = document.a'+another1+'.ano.value');
	eval ('var hora = document.a'+another1+'.hora.value');

	self.xmlHttpReq.send('check='+checks+'&checks1='+checks1+'&checks2='+checks2+'&checks_='+checks_+'&dia='+dia+'&ano='+ano+'&mes='+mes+'&anoChange='+ano+'&mesChange='+mes+'&tip=6&editar=1&id_reserv='+another1+'&hora='+hora+'&idtareas='+checks+'&first=1');
	break;
	case 20:
	 self.xmlHttpReq.send('tip=17&id_servei='+another1+'&idtareas='+document.reserv1.idstareas.value+'&id_reserv='+document.reserv.id_reserva.value);
	break;
	case 21:
	eval ('var check = document.a'+another1+'.id_servicio.value');
	check=check+',';
	eval ('var dia = document.a'+another1+'.dia.value');
	eval ('var mes = document.a'+another1+'.mes.value');
	eval ('var ano = document.a'+another1+'.ano.value');
	eval ('var hora = document.a'+another1+'.hora.value');
	self.xmlHttpReq.send('check='+check+'&dia='+dia+'&ano='+ano+'&hora='+hora+'&mes='+mes+'&anoChange='+ano+'&mesChange='+mes+'&tip=6&editar=1&id_tarea='+another1+'&idtareas='+document.reserv1.idstareas.value+'&id_reserv='+document.reserv.id_reserva.value);
	break;
	case 22:
	self.xmlHttpReq.send('tip='+tip+'&contingut='+another1+'&mail='+document.form.mail.value+'&titulo='+document.form.titulo.value);
	break;
	case 29:
	self.xmlHttpReq.send('id_reserv='+document.tuhora.id_reserv.value+'&idtareas='+document.tuhora.ids_tareas.value+'&check='+document.tuhora.check.value+'&tip='+tip+'&dia='+document.tuhora.dia.value+'&mes='+document.tuhora.mes.value+'&ano='+document.tuhora.ano.value+'&hora_selec='+document.tuhora.hora_selec.value+'&text='+another1);
	break;
	case 30:
	self.xmlHttpReq.send('tip=1&registro='+document.registro.reg.value+'&usuari='+document.registro1.usuario.value+'&pass='+document.registro1.pass.value);
	break;
	case 31:
	self.xmlHttpReq.send('tip=10&registro='+document.registro.reg.value+'&usuari='+document.registro1.usuario.value+'&pass='+document.registro1.pass.value);
	break;
	case 32:
	
	 self.xmlHttpReq.send('tip='+tip+'&pantalla='+another1+'&selects='+document.getElementById('selects').value+'&selects2='+document.getElementById('selects2').value);
	break;
	case 33:
	var top=document.getElementById('tableContainer').scrollTop;
    self.xmlHttpReq.send('id_reserv='+document.tuhora.id_reserv.value+'&hora_inicial='+document.tuhora.hora_inicial.value+'&idtareas='+document.tuhora.ids_tareas.value+'&editar='+document.tuhora.editar.value+'&scroll1='+top+'&check='+document.tuhora.checks.value+'&dia='+document.getElementById('showDia').value+'&ano='+document.getElementById('showAno').value+'&mes='+document.getElementById('showMes').value+'&anoChange='+document.getElementById('showAno').value+'&mesChange='+document.getElementById('showMes').value+'&tip=9&algun_checked=1&another='+another1);  
	break;
	case 34:
    eval ('var valueCampo = document.getElementById("selec'+another1+'").value');
    self.xmlHttpReq.send('check='+document.tuhora.checks.value+'&dia='+document.getElementById('showDia').value+'&ano='+document.getElementById('showAno').value+'&mes='+document.getElementById('showMes').value+'&anoChange='+document.getElementById('showAno').value+'&mesChange='+document.getElementById('showMes').value+'&tip=6&another='+another1+'&select_sino='+valueCampo+'&selects='+document.getElementById('selects').value+'&selects2='+document.getElementById('selects2').value+'&id_reserv='+document.tuhora.id_reserv.value);
    break;
	case 35:
		self.xmlHttpReq.send('tip='+tip+'&lang='+another1+'&pag_idioma='+pag);		
	break;
  	case 36:
	
	 self.xmlHttpReq.send('tip=32&pantalla='+another1);
	break;
	case 37:
    eval ('var valueCampo = document.getElementById("selecs'+another1+'").value');
    self.xmlHttpReq.send('check='+document.tuhora.checks.value+'&dia='+document.getElementById('showDia').value+'&ano='+document.getElementById('showAno').value+'&mes='+document.getElementById('showMes').value+'&anoChange='+document.getElementById('showAno').value+'&mesChange='+document.getElementById('showMes').value+'&tip=6&another='+another1+'&select_sino2='+valueCampo+'&selects='+document.getElementById('selects').value+'&selects2='+document.getElementById('selects2').value+'&id_reserv='+document.tuhora.id_reserv.value);
    break;		
		}
      

}





function xmlhttpPost_popup(tipo,another)
{
    var xmlHttpReq = false;

    var self = this;

    document.body.style.cursor = "wait";

    if (window.XMLHttpRequest) // Mozilla & Safar
    {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) // IE
    {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }


    self.xmlHttpReq.open('POST', 'submitform_popup_usuario.php', true);
		
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');


    self.xmlHttpReq.onreadystatechange = function()
    {


        if (self.xmlHttpReq.readyState == 4)
        {
        

            textReturn = unescape(self.xmlHttpReq.responseText);
			if(textReturn=="") window.location="index.php";
			else
			{
            var arrayReturn = textReturn.split('<ticketSeparator>');
            var titlePopup = arrayReturn[0].replace(/\+/gi," ");
            var stringReturn = arrayReturn[1].replace(/\+/gi," ");

            document.getElementById('txtTopPopup').innerHTML = titlePopup;
        
            document.getElementById('contenidoPopup').innerHTML = stringReturn;
            
            mostrariposicionardiv('divPopup', tipo);

            document.body.style.cursor = "auto";
			}
          
        }
    }


		
    		self.xmlHttpReq.send('tipo='+tipo+'&another='+another);
   


}



    		
   

function mostrariposicionardiv (div, tipo)
{	
	i=1;
	if(tipo==1)  document.getElementById(div).style.width = '400px';
  else document.getElementById(div).style.width = '800px';
  document.getElementById(div).style.height = '';

    var XpositionDIV = (document.documentElement.clientWidth/2) - (document.getElementById(div).clientWidth/2);
    var YpositionDIV = (document.documentElement.clientHeight/2) - (document.getElementById(div).clientHeight/2);

    document.getElementById(div).style.left = XpositionDIV+'px';
    if(tipo==11)   document.getElementById(div).style.top =  9+'px';
    else document.getElementById(div).style.top =  (YpositionDIV)+'px';

    /*Posicionamos el rincón de resizar el div*/
    d3Paint();

    /*Cerramos el Popup raton*/
 		nd();

    document.getElementById(div).style.visibility = 'visible';

    //document.getElementById('divPantallaNegra').style.width = document.documentElement.clientWidth+'px'

    //document.getElementById('divPantallaNegra').style.height = document.documentElement .clientHeight+'px'
}


function minimizePopup()
{

    if (document.getElementById('divPopup').style.height == '22px')
    {
        document.getElementById('divPopup').style.height = sizeAfterPopup;
    }
    else
    {
        sizeAfterPopup = document.getElementById('divPopup').style.height;

        document.getElementById('divPopup').style.height = '22px';
    }
}

function changeModule ()
{
	if(i!=0)
	{
    if (document.getElementById('divPopup').style.visibility == 'visible')
    {
        document.getElementById('divPopup').style.visibility = 'hidden';
    }
  }
}

function closePopup()
{

    document.getElementById('divPopup').style.visibility = 'hidden';
    if (document.getElementById('selecTimeAviso1')) document.getElementById('selecTimeAviso1').style.visibility = 'hidden';
}



/*Funciones para el div popup resizable*/
function d3Setup()
{
	
  var d3 = xGetElementById('divPopup');
  var rBtn = xGetElementById('divresize');
  var mBtn = xGetElementById('divmaximizar');
  xMoveTo(d3, 350, 200);
  d3Paint();
  xEnableDrag('topPopup', d3BarOnDragStart, d3BarOnDrag, null);
  xEnableDrag(rBtn, d3RBtnOnResizeStart, d3RBtnOnResize, null);
  mBtn.onclick = d3MBtnOnClick;
  xShow(d3);
  
}

function d3Paint()
{
  var d3 = xGetElementById('divPopup');
  var rBtn = xGetElementById('divresize');
  var mBtn = xGetElementById('divmaximizar');
  xMoveTo(rBtn, xWidth(d3) - xWidth(rBtn), xHeight(d3) - xHeight(rBtn));
  xMoveTo(mBtn, xWidth(d3) - xWidth(rBtn), 0);
}

function d3BarOnDragStart(ele, mx, my)
{
  xZIndex('divPopup', highZ++);
}

function d3BarOnDrag(ele, mdx, mdy)
{
  xMoveTo('divPopup', xLeft('divPopup') + mdx, xTop('divPopup') + mdy);
}

function d3RBtnOnResizeStart(ele, mx, my)
{
  xZIndex('divPopup', highZ++);
}

function d3RBtnOnResize(ele, mdx, mdy)
{
  xResizeTo('divPopup', xWidth('divPopup') + mdx, xHeight('divPopup') + mdy);
  d3Paint();
}

function d3MBtnOnClick()
{
  var d3 = xGetElementById('divPopup');
  if (d3.maximized) {
    d3.maximized = false;
    xResizeTo(d3, d3.prevW, d3.prevH);
    xMoveTo(d3, d3.prevX, d3.prevY);
    d3Paint();
  }
  else {
    d3.prevW = xWidth(d3);
    d3.prevH = xHeight(d3);
    d3.prevX = xLeft(d3);
    d3.prevY = xTop(d3);
    xMoveTo(d3, xScrollLeft(), xScrollTop());
    d3.maximized = true;
    xResizeTo(d3, xClientWidth(), xClientHeight());
    d3Paint();
  }

}


function sendDateCalendar(dia, mes, ano, obj,tip)
{
    spans = document.getElementsByTagName('span');

    for (i=0; i<=spans.length-1;i++)
    {
        spans[i].style.backgroundColor = '';
    }

    obj.style.backgroundColor = '#FAF700';

    document.getElementById('showDia').value = dia;
    document.getElementById('showMes').value = mes;
    document.getElementById('showAno').value = ano;

    
    if (tip=='0') xmlhttpPost_Datos(26);
	if (tip=='1') xmlhttpPost_Datos(13);
	if (tip=='2') xmlhttpPost_Datos(16);
}


function posicionarCalendar (e)
{


 if (formInputResult == 'formnuevatarea2') /*Calendario del popup*/
    {
        selecTime = 'selecTimeAviso1';

	
        fechaSelect = valor2;
        
     
    }

    initCalendar(fechaSelect);
    
    if (e.pageX == undefined)
    {
        var mouseX = window.event.clientX;
        var mouseY = window.event.clientY;
    }
    else
    {
        var mouseX = e.pageX;
        var mouseY = e.pageY;
    }

    document.getElementById('containerCalendar').style.visibility = 'visible';
    document.getElementById('containerCalendar').style.left = (mouseX - 168)+'px';
    document.getElementById('containerCalendar').style.top = (mouseY + 5)+'px';

    getClick = 1;

    document.getElementById('containerCalendar').onclick=function(){getClick = 1;};

    document.onclick = contentOnclickCalendar;
}

function contentOnclickCalendar()
{

    if (getClick == 1)
    {
        getClick = 0;
   
    }
    else
    {
        document.getElementById('containerCalendar').style.visibility = 'hidden';
        
   

        if (document.getElementById('showAviso').style.visibility == 'visible')     document.onclick = contentOnclickAviso;
        else                                                                        document.onclick = '';
    }
}

/*Funciones del calendario de YAHOO*/
function initCalendar(fecha)
{
    document.getElementById('contentCalendar').innerHTML = '';

    /*YAHOO.namespace("example.calendar");
	YAHOO.example.calendar.cal1 = new YAHOO.widget.Calendar("YAHOO.example.calendar.cal1","contentCalendar");
	YAHOO.example.calendar.cal1.render();*/

    YAHOO.namespace("example.calendar");
    cal1 = new YAHOO.widget.Calendar("cal1", "contentCalendar");
    cal1.minDate = YAHOO.widget.DateMath.add(new Date(), YAHOO.widget.DateMath.DAY, 0);

    if (fecha != '')
    {
		var month = 9;
		var day = 18;
		var year = 2006;

        arraySplit = fecha.split(' ');

        arrayFecha = arraySplit[0].split('-');
        arrayHora = arraySplit[1].split(':');

		cal1.select((parseInt(arrayFecha[1],10)) + "/" + parseInt(arrayFecha[0],10) + "/" + parseInt(arrayFecha[2],10));
		cal1.setMonth(parseInt(arrayFecha[1],10)-1);

		horas = arrayHora[0];
		minutos = arrayHora[1];
    }
    else
    {
        ahora = new Date();

        horas = ahora.getHours();
        minutos = ahora.getMinutes();

        horas +='';
        minutos +='';

        if (horas.length == 1)      horas = '0'+horas;
        if (minutos.length == 1)    minutos = '0'+minutos;
    }

    document.getElementById('horaCalendar').value = horas;
    document.getElementById('minCalendar').value = minutos;

    cal1.render();
}

function valoresNumericos(evento)
{
    var key = evento.charCode;

    if (!key)
    {
        key = evento.keyCode;
    }

    if ((key < 48 || key > 57) && key != 46 && key != 8 && key != 9)
    {
        alert (errorOnlyNum);
        return false;
    }
}

/**
* Función que con el click aumenta o disminute la hira de un input
*
* @author Eric Corbella <eric.corbella@millorsoft.net>
* @date 11/08/2006 17:06
**/
function changeHour (campo, valor)
{

    eval ('var valueCampo = document.formchange.'+campo+'.value');

    arrayHoras = valueCampo.split('');

    if (arrayHoras[0] == 0) valueCampo = arrayHoras[1];

    valueCampo = parseInt(valueCampo, 10)+valor;

    if (campo == "hora")
    {
        if (valueCampo < 0)         valueCampo = 23;
        else if (valueCampo >= 24)  valueCampo = 0;
    }
    else
    {
        if (valueCampo < 0)         valueCampo = 59;
        else if (valueCampo >= 60)  valueCampo = 0;
    }

    valueCampo = valueCampo.toString();

    if (valueCampo.length == 1) valueCampo = '0'+valueCampo;

    eval ('document.formchange.'+campo+'.value = valueCampo;');
}

function resetInputfechaDest()
{
    eval("document."+formInputResult+".fecha_dest.value = '';");
    document.getElementById('containerCalendar').style.visibility = 'hidden';
}

/**
* Función que copia a un input de texto la fecha seleccionada con el calendario
*
* @author Eric Corbella <eric.corbella@millorsoft.net>
* @date 11/08/2006 17:06
**/
function assignFecha ()
{
    arrayFecha = cal1.getSelectedDates();

 if (formInputResult == 'formnuevatarea2') /*Calendario del popup*/
    {
        selecTime = 'selecTimeAviso1';
			
	
        fechaSelect = valor2;
      
       
    }


    inputhoras = document.getElementById('horaCalendar').value;
    inputminuts = document.getElementById('minCalendar').value;

    horas = parseInt(inputhoras,10);
    minuts = parseInt(inputminuts, 10);


    if (horas >= 24 || horas < 0)   {alert(errorFormatoTime);return false;}
    if (minuts >= 60 || minuts < 0) {alert(errorFormatoTime);return false;}

    if (!arrayFecha || inputhoras == '' ||inputminuts == '') {alert(errorRelleneCamp);return false;}

    if (horas+0 != horas)   {alert(errorOnlyNum); return false;}
    if (minuts+0 != minuts) {alert(errorOnlyNum); return false;}

    horas = horas.toString();
    minuts = minuts.toString();
    arrayFecha[2] = arrayFecha[2].toString();
    arrayFecha[1] = arrayFecha[1].toString();

    if (horas.length == 1)          horas = '0'+horas;
    if (minuts.length == 1)         minuts = '0'+minuts;
    if (arrayFecha[2].length == 1)  arrayFecha[2] = '0'+arrayFecha[2];
    if (arrayFecha[1].length == 1)  arrayFecha[1] = '0'+arrayFecha[1];
    
	

    eval ('$fecha = "'+arrayFecha[2]+'-'+arrayFecha[1]+'-'+arrayFecha[0]+' '+horas+':'+minuts+'";');
		
    document.getElementById('containerCalendar').style.visibility = 'hidden';
  	xmlhttpPost_popup(14,$fecha);

    if (document.getElementById('showAviso').style.visibility == 'visible') document.onclick = contentOnclickAviso;
    else                                                                    document.onclick = '';

    return true;
}



/***************************************SCROLLBAR******************************************/

function removeClassName (elem, className) {
	elem.className = elem.className.replace(className, "").trim();
}

function addCSSClass (elem, className) {
	removeClassName (elem, className);
	elem.className = (elem.className + " " + className).trim();
}

String.prototype.trim = function() {
	return this.replace( /^\s+|\s+$/, "" );
}

function stripedTable() {
	if (document.getElementById && document.getElementsByTagName) {  
		var allTables = document.getElementsByTagName('table');
		if (!allTables) { return; }

		for (var i = 0; i < allTables.length; i++) {
			if (allTables[i].className.match(/[\w\s ]*scrollTable[\w\s ]*/)) {
				var trs = allTables[i].getElementsByTagName("tr");
				for (var j = 0; j < trs.length; j++) {
					removeClassName(trs[j], 'alternateRow');
					addCSSClass(trs[j], 'normalRow');
				}
				for (var k = 0; k < trs.length; k += 2) {
					removeClassName(trs[k], 'normalRow');
					addCSSClass(trs[k], 'alternateRow');
				}
			}
		}
	}
}

/*INICIO FUNCIONES DESPLAZAMIENTO FOTOS*/


var scrollImage = 1;

function move_div(direction, auto)
{
    if (auto == 1)  vel = 3;
    else            vel = 50;


    if ( !window.posicio )
    {
        posicio = 0;
        ampleexterior = document.getElementById('img_secundarias').clientHeight;
        ampleinterior = document.getElementById('img_secundarias').scrollHeight;
    }

    if (direction == 'up') //Amunt
    {
        posicio = posicio + vel;

        if ( posicio >= 0 )
        {
            posicio = 0;
            scrollImage = 0;
        }

    }
    else    //Avall
    {
        posicio = posicio - vel;

        if ( posicio <= ampleexterior - ampleinterior )
        {
            posicio = ampleexterior - ampleinterior;
            scrollImage = 0;
        }
    }

    document.getElementById('prem_hint').style.top = posicio+'px';

    if (scrollImage == 1 && auto == 1) setTimeout("move_div('"+direction+"', 1)", 30);
}


function checks_(id_,tip)
{

if(tip=='0')eval('var ch = document.tuhora.a'+id_+'.checked');
else eval('var ch = document.tuhora1.a'+id_+'.checked');


if( ch ) document.tuhora.checks.value+=id_+',';
else document.tuhora.checks.value=document.tuhora.checks.value.replace(id_+',',''); 

if(document.tuhora.checks.value=='') document.getElementById('siguiente').style.display='none';
else document.getElementById('siguiente').style.display='block';
}
/***Funcio per enviar e-mail desde el formulari****/



function enviar_form()
{
var ob = document.getElementById("formnoms");
var valors = ob.getElementsByTagName('input');
var separator = "<separator>";
var is = "<is>";
var text = "";

for (i=0; i<valors.length; i++)
 {
 eval ('var nom = document.formnoms.'+valors[i].id+'.value');
 eval ('var valor = document.form.'+valors[i].id+'.value');
 text=text+nom+is+valor+separator;
 }
 
 
 xmlhttpPost_Datos2(22,text);
}




function mapa(l1,l2,empresa)
{
		YLog.initSize(new YSize(600,500));
        function StartYMap() {
        var map = new YMap(document.getElementById('ymap')); 
		var cPT = new YGeoPoint(l1,l2);
		map.addZoomLong();
		map.addTypeControl();
		map.disableKeyControls();
		map.drawZoomAndCenter(cPT,3);

		var setupMarker = function(p,d) {
			var m = new YMarker(p);
			m.addAutoExpand(d);
			return m;
		};

		// local search
		var searchF = function(e) {
			var _p = [];
			if (e.Data) {
			for (var a in e.Data.ITEMS) {
				var l = e.Data.ITEMS[a];
				// YLog.print(l);
				if (l.TITLE) {
				var p = new YGeoPoint(l.LATITUDE,l.LONGITUDE);
				_p.push(p);
				var m = setupMarker(p,l.TITLE);
				map.addOverlay(m);
				}
			}
			}


		};
	function onSmartWinEvent() {
var words = '<div style="width:160px;height:50px;"><b>'+empresa+'</b><br><b>ffff</b></div>';
marker.openSmartWindow(words);
}
		var marker = new YMarker(cPT);
		// Add a label to the marker
		marker.addLabel("");
		// Add auto expand
		var _txt = '<div style="width:160px;height:50px;"><b>Més informació</b></div>';
		marker.addAutoExpand(_txt);
		// Call onSmartWinEvent when the user clicks on the marker
		YEvent.Capture(marker, EventsList.MouseClick, onSmartWinEvent);
		// Display the marker
		map.addOverlay(marker);


		// setup capture to process on completion of local search
		YEvent.Capture(map,EventsList.onEndLocalSearch,searchF);
        }
	window.onload = StartYMap;

}


function canviarcheck(tip,id_)
{
	switch(tip)
		{
		case 1:
   	if (eval ('document.tu_hora.a'+id_+'.checked == true '))
   	{
   		document.tu_hora.serveis.value=document.tu_hora.serveis.value+'&'+id_;
   	}
   	else
   		{
   			}
    break;
  }
}
