// JavaScript Document

//***************************************************************************************************************
//******************Funcions Motorent Pujols
function makevisible(cur,which){
strength=(which==0)? 1 : 0.5
if (cur.style.MozOpacity)
cur.style.MozOpacity=strength
else if (cur.filters)
cur.filters.alpha.opacity=strength*100
}

function makevisible2(cur,which){
strength=(which==0)? 0.5 : 1
if (cur.style.MozOpacity)
cur.style.MozOpacity=strength
else if (cur.filters)
cur.filters.alpha.opacity=strength*100
}

function XTCbgcolor(lloc,color){
document.getElementById(lloc).style.backgroundColor=color;
}

function XTCbgimage(lloc,imatge){
	document.getElementById(lloc).filters.blendTrans.apply();
	document.getElementById(lloc).style.backgroundImage =  'url('+imatge+')';
	document.getElementById(lloc).filters.blendTrans.play();
}

function XTCcamvi(lloc,imatge){
		document.getElementById(lloc).filters.blendTrans.apply();
		document.getElementById(lloc).src=imatge;
		document.getElementById(lloc).filters.blendTrans.play();
}

function asigna(num_img){
XTCcamvi("moto1","../misc/mujer-inicio"+num_img+".gif");
XTCcamvi("moto2","../misc/mto-inicio"+num_img+".jpg");
XTCbgimage("moto3","../misc/moto-clara-inicio"+num_img+".jpg");
num_img++;
if (num_img>4){num_img=1;}
setTimeout('asigna("'+num_img+'")',8000)
}

function AniIni(){
img_aleat=Math.floor(Math.random()*3);
if (img_aleat==0)img_aleat=4;
setTimeout('asigna("'+img_aleat+'")',8000);
}

function calculo(){
fecha1=document.frmBusca.fecha_abre.value;
fecha2=document.frmBusca.fecha_cierra.value;
document.frmBusca.resultado.value=(aleatorio(1,30)*20)+"€";
//alert(fecha1);
}

function aleatorio(inferior,superior){ 
    numPosibilidades = superior - inferior 
    aleat = Math.random() * numPosibilidades 
    aleat = Math.round(aleat) 
    return parseInt(inferior) + aleat 
} 
//***************************************************************************************************************


var ns4 = (document.layers); 
var ie4 = (document.all && !document.getElementById); 
var ie5 = (document.all && document.getElementById); 
var ns6 = (!document.all && document.getElementById); 
function attach(id)
{
 var obj
  if(ns4) obj = document.layers[id];
  else if(ie4) obj = document.all[id];
   else if(ie5 || ns6) obj = document.getElementById(id);
  return obj
} 


function validaDel(id,nombre,url){
	msg="¿Desea borrar "+ nombre +"?\n Los datos no se podran recuperar.";
	if (confirm(msg)){
		window.location=url+"?ac=borrar&id="+id;
		}
}

function act_idioma(nom_idioma,nom_desti,texte,lloc){
//alert(nom_idioma);
var camp=nom_idioma+nom_desti;
//alert(camp);
document.frm.elements[camp].value=texte.value;
XTCmsg(texte.value.length+" caracteres",lloc);
window.status=document.frm.elements[camp].value;
}

function idiomalang(nom_idioma2,idioma){
//alert(nom_idioma);
nom_idioma=idioma;
//alert(idioma);
//alert(nom_idioma);
}

function lnk(obj,clase){obj.className=clase;}

function XTCtrans(cur,which){
	strength=(which==0)? 0.70 : 1
		if (cur.style.MozOpacity)
			cur.style.MozOpacity=strength
		else if (cur.filters)
			cur.filters.alpha.opacity=strength*100
}

function XTCbgcolor(objNom,color){
document.getElementById(objNom).style.backgroundColor=color;
}

function XTClnktaula(obj,clase){obj.className=clase;}

function XTCmsg(msg,lloc){
	if (document.all||document.getElementById){
	      if (document.getElementById) {
			document.getElementById(lloc).innerHTML = ""+msg+"&nbsp;";
  			}
         else {
			lloc.innerHTML = ""+msg+"&nbsp;";	
			}
   } 
}


lang='es';
var promptOn = true;




function capturaTecla(frm) 
    {
        if(document.all)
            tecla=event.keyCode;
        else
        {
            tecla=e.which; 
        }
     if(tecla==13)
        {
            //alert("a");//
			frm.value+="<br>";
        }
    }  
   // if ()
	//document.onkeydown = capturaTecla;


function AddMessageCode(code, promptText, InsertText, NombreTextarea) {
	if (code != "") {
		if (promptOn == true){
			insertCode = prompt(promptText + "\n<" + code + ">xxx</" + code + ">", InsertText);
				if ((insertCode != null) && (insertCode != "")){
					cadena="document.frm."+ NombreTextarea +  ".value +=\"<" + code + ">" + insertCode + "</" + code + ">\"";
					//alert(cadena);
					eval(cadena);
				}
		}
		else{
			//document.frmNews.NombreTextarea.value += "<" + code + "></" + code + ">";
			
			cadena="document.frm."+ NombreTextarea +  ".value +=\"<" + code + "></" + code + ">\"";
			eval(cadena);
		}
	}
				
	//document.frmNews.NombreTextarea.focus();
	cadena="document.frm."+ NombreTextarea +  ".focus()";
	eval(cadena);
}


function AddCode(code, NombreTextarea) {

	//Añadir un link a la pagina
	if ((code != "") && (code == "URL")) {
		insertText = prompt("Introduzca el texto del enlace (texto que se pulsará)", "");
			
			if ((insertText != null) && (insertText != "") && (code == "URL")){
				insertCode = prompt("Introduzca la URL (direccion web) a la que llevará el enlace.", "http://");
					
					if ((insertCode != null) && (insertCode != "") && (insertCode != "http://")){					
						//document.frmNews.NombreTextarea.value += '<a href="' + insertCode + '">' + insertText + '</a>';
						cadena="document.frm."+ NombreTextarea +  ".value +=\"<a href='" + insertCode + "' target='_blank' class='texto_normal'>" + insertText + "</a>\"";
						eval(cadena);
					}
			}
	}
	
	//Añadir email a la pagina
	if ((code != "") && (code == "EMAIL")) {
		insertText = prompt("Introduzca el texto del email (texto que se pulsará)", "");
			
			if ((insertText != null) && (insertText != "")){
				insertCode = prompt("Introduzca el E-mail (xxxx@yyy.zz) al que llevará el enlace.", "");
					
					if ((insertCode != null) && (insertCode != "")){					
					//document.frmNews.NombreTextarea.value += '<a href="mailto:' + insertCode + '">' + insertText + '</a>';
					cadena="document.frm."+ NombreTextarea +  ".value +=\"<a href='mailto:" + insertCode + "' target='_blank' class='texto_normal'>" + insertText + "</a>\"";
					//cadena="document.frmNews."+ NombreTextarea +  ".value +=\"<a href=\"mailto:" + insertCode + "\">" + insertText + "</a>\"";
					eval(cadena);
				}
			}
	}
	
	//Comentarios en verde en las páginas
	if ((code != "") && (code == "BLOQUE")) {
		insertText = prompt("Introduzca el título del comentario", "");
			
			if ((insertText != null) && (insertText != "")){
				insertCode = prompt("Introduzca el texto del comentario.", "");
					
					if ((insertCode != null) && (insertCode != "")){					
					//document.frmNews.NombreTextarea.value += '<a href="mailto:' + insertCode + '">' + insertText + '</a>';
					cadena="document.frm."+ NombreTextarea +  ".value +=\"<br><br><span class='tverd'><b>" + insertText + "</b><br><br>" + insertCode + "</span><br>\"";
					//cadena="document.frmNews."+ NombreTextarea +  ".value +=\"<a href=\"mailto:" + insertCode + "\">" + insertText + "</a>\"";
					eval(cadena);
				}
			}
	}
}






/////////////////////////////

function damunt(Imatge,img,lay,w,h,step_h,step_v,count_lay,num_lay) { 
	if (document.images) {  
		document[Imatge].src=img; 
		//rttreterte/
		//alert(lay);
		temp_Obj = attach(lay);
		//step_h = 10;
		//step_v = 10;
		//temp_Obj = attach(id); 
		if(ns4) { temp_Obj.visibility = "hidden";temp_Obj.zIndex = parseInt(3);document.parent.zIndex = parseInt(15);temp_Obj.top = parseInt(temp_Obj.top) - step_v; temp_Obj.left = parseInt(temp_Obj.left) - step_h; temp_Obj.visibility = "visible";
		}
		else {temp_Obj.style.visibility = "hidden";temp_Obj.style.zIndex = parseInt(100);temp_Obj.style.top = parseInt(temp_Obj.style.top) - step_v; temp_Obj.style.left = parseInt(temp_Obj.style.left) - step_h; temp_Obj.style.visibility = "visible";
				//*****************************************
				for (x=0;x<count_lay;x++){
				if(x==num_lay){
				document.getElementById("parent_"+x).style.zIndex=100;
				document.getElementById("lay_"+x).style.zIndex=101;
				}else{
					document.getElementById("parent_"+x).style.zIndex=x;
					document.getElementById("lay_"+x).style.zIndex=x;
					}
				}
				//window.status=lay+"-"+parent_1.style.zIndex;
				//*******************************************
		}
		document[Imatge].width=w;  
		document[Imatge].height=h;  
		//alert(temp_Obj.style.zIndex);
	} 
return temp_Obj;} 

function fora(Imatge,lay,w,h,step_h,step_v,count_lay) {  
	if (document.images) { 
		temp_Obj = attach(lay);
		//step_h = 10;
		//step_v = 10;
		//temp_Obj = attach(id);
		if(ns4) {temp_Obj.zIndex = parseInt(1);temp_Obj.top = parseInt(temp_Obj.top) + step_v; temp_Obj.left = parseInt(temp_Obj.left) + step_h; }
		else {temp_Obj.style.zIndex = parseInt(1);temp_Obj.style.top = parseInt(temp_Obj.style.top) + step_v; temp_Obj.style.left = parseInt(temp_Obj.style.left) + step_h; }
				//*****************************************
				for (x=0;x<count_lay;x++){
				
					document.getElementById("parent_"+x).style.zIndex=x;
					document.getElementById("lay_"+x).style.zIndex=x;
					
				}
	 			//window.status=lay+"-"+parent_1.style.zIndex;
				//*******************************************
		document[Imatge].width=w;
		document[Imatge].height=h;    
	} 
 return temp_Obj;} 



function popUpWindow(imag, left, top, width, height)
{
  popUpWin = open("../imagen.php?imag="+imag+"&w="+width+"&h="+height, 'popUpWin', 'scrollbars=no,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
  popUpWin.focus();
}
function popUpWindow2(src, left, top, width, height)
{
  popUpWin2 = open(src, 'popUpWin2', 'scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
  popUpWin2.focus();
}

function mapa(urlmapa){
var windowX = (screen.width/2)-(800/2);
var windowY = (screen.height/2)-(600/2);
var localitzar = window.open(urlmapa,"imatge","width=798,height=550,scrollbars=yes,resizable=yes");
localitzar.moveTo(windowX,windowY);
localitzar.focus();
}


function format_num(total,decimals)
 {
      var num = parseFloat(total);
      // First section sets non-number value to zero
          if (!(num = parseFloat(num)))
               num = "0.00";
      // Second section sets two decimal place format
          var Pad = "";
          num = "" + Math.floor(num * Math.pow(10,decimals + 1) + 5);
          // Pad if less than 0.10
          if(num.length < decimals+1) 
          {
               for(Count = num.length; Count <= decimals; Count++)
                    Pad += "0";
          }
          num = Pad + num;
     // Parse into final string
          num = num.substring(0,num.length - decimals - 1) + 
               "." + num.substring(num.length - decimals -1, num.length -1);
     // If less than 1 then add 0 to the left of the decimal
          if((num == "") || (parseFloat(num) < 1))
               num = "0" + num;
     // Final section returns formatted number
          return num;
}




function validare_form(){
	var falta = "";
	var falta_entre="";
	var i,i_tmp,arg=validare_form.arguments; 
	for(i=2; i<arg.length; i=i+2){
		//alert(eval('document.toto.'+arg[i]+'.value'));
		temp_Obj = attach(arg[i+1]);
		//alert(typeof('document.'+arg[0]+'.'+arg[i+1]));
		//if(typeof('document.'+arg[0]+'.'+arg[i+1])!="undefined"  ){
		//
		if(arg[i]=='num'){
		//alert(eval('document.'+arg[0]+'.'+arg[i+1]+'.value'));
		//alert(!isNaN(eval('document.'+arg[0]+'.'+arg[i+1]+'.value')));
			if(isNaN(eval('document.'+arg[0]+'.'+arg[i+1]+'.value')) || eval('document.'+arg[0]+'.'+arg[i+1]+'.value') == '') {
				falta += "algo";//alert();
				if(ns4) { temp_Obj.color = 'red'; }
				else {temp_Obj.style.color = 'red'; }
			}
			else {
				if(ns4) { temp_Obj.color = 'black'; }
				else {temp_Obj.style.color = 'black'; }
			}
		}
		else if(arg[i]=='ad_mail'){// (mail.indexOf("@")>=0) && (mail.indexOf(".")>=0)
			if((eval('document.'+arg[0]+'.'+arg[i+1]+'.value').indexOf("@")==-1) || (eval('document.'+arg[0]+'.'+arg[i+1]+'.value').indexOf(".")==-1)) {
				falta += "algo";
				if(ns4) { temp_Obj.color = 'red'; }
				else {temp_Obj.style.color = 'red'; }
			}
			else {
				if(ns4) { temp_Obj.color = 'black'; }
				else {temp_Obj.style.color = 'black'; }
			}
		}
		else if(arg[i]=='uno_entre'){ //'uno_entre','Numero_campos_dependente','val_verif_campo_dependente','Nombre_campo_dependente',...
			var campos_dependente= arg[i+1];
			i=i+2;
			i=i+(2*campos_dependente);
			/* i_tmp=i;
			
			for(var cpt1=0;cpt1<campos_dependente;cpt1++){
				//temp_Obj = attach(arg[i+1]);
				if(eval('document.'+arg[0]+'.'+arg[i_tmp+1]+'.value') == arg[i_tmp]) {
					falta_entre += "algo";
				}
				i_tmp=i_tmp+2;
			}
			
			
				for(var cpt2=0;cpt2<campos_dependente;cpt2++){
					temp_Obj = attach(arg[i+1]);
					if(falta_entre != "") {
						//falta += "algo";
						if(ns4) { temp_Obj.color = 'red'; }
						else {temp_Obj.style.color = 'red'; }
					}
					else {
						if(ns4) { temp_Obj.color = 'black'; }
						else {temp_Obj.style.color = 'black'; }
					}
					i=i+2;
				} */
		}
		// multi mira la existencia de un campo, antes de verificar los demas
		else if(arg[i]=='multi'){//'multi','Numero_campos_dependente','val_verif_campo_master','nombre_campo_master','','nb_adulto',
			var campos_dependente= arg[i+1];
			//alert('document.'+arg[0]+'.'+arg[i+1]);
			i=i+2;
			temp_Obj = attach(arg[i+1]);
			if(eval('document.'+arg[0]+'.'+arg[i+1]+'.value') == arg[i]) {
				falta += "algo";
				//alert('document.'+arg[0]+'.'+arg[i+1]+" "+i);
				if(ns4) { temp_Obj.color = 'red'; }
				else {temp_Obj.style.color = 'red'; }
				//i=i+2;
				i=i+(2*campos_dependente);
				//alert('document.'+arg[0]+'.'+arg[i+1]+' '+campos_dependente);
			}
			else {
				if(ns4) { temp_Obj.color = 'black'; }
				else {temp_Obj.style.color = 'black'; }
				//i=i+2;
				//temp_Obj = attach(arg[i+1]);
				for(var cpt=0;cpt<campos_dependente;cpt++){
					i=i+2;
					temp_Obj = attach(arg[i+1]);
					if(eval('document.'+arg[0]+'.'+arg[i+1]+'.value') == arg[i]) {
						falta += "algo";
						if(ns4) { temp_Obj.color = 'red'; }
						else {temp_Obj.style.color = 'red'; }
					}
					else {
						if(ns4) { temp_Obj.color = 'black'; }
						else {temp_Obj.style.color = 'black'; }
					}
				}
			}
		}
		else{
			//alert(arg[i]);
			if(eval('document.'+arg[0]+'.'+arg[i+1]+'.value') == arg[i]) {
				falta += "algo";
				if(ns4) { temp_Obj.color = 'red'; }
				else {temp_Obj.style.color = 'red'; }
			}
			else {
			//alert('document.'+arg[0]+'.'+arg[i+1]+" "+i);
				if(ns4) { temp_Obj.color = 'black'; }
				else {temp_Obj.style.color = 'black'; }
			}
		}
	}
	if (falta != "") {
		falta =' '+arg[1]+' ';
		alert(falta);
		return false;
	}
	else {
		return true;
	}
}