function buscar(formulario){
		
		submitform(document.getElementById(formulario),"buscar.php","box4","espera");
		document.getElementById('paginaprincipal').className="wrapper bg3_2";
	}
function clicar(formulario,web){
		
		submitform(document.getElementById(formulario),"updateipbanner.php","espera","espera");
		window.open(web,'window','scrollbars=1');
		
	}



function cambiaridioma(idioma){
	formulario = "formidioma";
	document.getElementById("cambiaidioma").value =idioma;
	submitform(document.getElementById(formulario),"cambiaridioma.php","espera","espera","Si");
}

function enviarurlrequery(){
	formulario = "formrequery";
	submitform(document.getElementById(formulario),"enviarurlrequery.php","espera","espera","Si");
}
function enviarurlleft(){
	formulario = "formleft";
	submitform(document.getElementById(formulario),"enviarurl.php","espera","espera","Si");
}
function enviarurllefts(){
	formulario = "formlefts";
	submitform(document.getElementById(formulario),"enviarurl.php","espera","espera","Si");
}
function enviarurlright(){
	formulario = "formright";
	submitform(document.getElementById(formulario),"enviarurl.php","espera","espera","Si");
}
function enviarurlrights(){
	formulario = "formrights";
	submitform(document.getElementById(formulario),"enviarurl.php","espera","espera","Si");
}
function enviarurlpaginanueva(){
	/*hacer una pagina nueva x registros que hay que hacer para la pagina*/
	formulario = "formpaginanueva";
	submitform(document.getElementById(formulario),"hacerpaginanueva.php","espera","espera","Si");
}

function enviarurlpaginanuevaentre(){
	/*hacer una pagina nueva x registros que hay que hacer para la pagina*/
	formulario = "formpaginanueva";
	submitform(document.getElementById(formulario),"hacerpaginanuevaentre.php","espera","espera","Si");
}



function sugerencia(object,celdas){	
	/*Le ponemos el valor cojido del combo en el valor a modificar*/
	ref = "refoem" + celdas;
	mivalor=document.getElementById(ref).options[document.getElementById(ref).selectedIndex].text;
	newArray = mivalor.split('/');
	if (newArray.length >=1){
		document.getElementById("oeminput").value =newArray[0];
	}
	if (newArray.length >=2){
		document.getElementById("oeminput2").value =newArray[1];
	}
	ensenardatosoem();
}

function anadirtitulo(){	
	var ref;
	formulario = "formtitulo";
	submitform(document.getElementById(formulario),"anadirtitulo.php","titulopagina","espera");
}

function anadirreftype(titulo,traduccion){
		var ref;
	/*Le ponemos el valor cojido del combo en el valor a modificar*/
  	if (titulo!=1){
			alert(traduccion);
			return false;
		
	}
	
	ref = "selreftype";
	mivalor=document.getElementById(ref).options[document.getElementById(ref).selectedIndex].value;
	document.getElementById("reftype").value =mivalor;
	formulario = "formresultadoreftype";
	submitform(document.getElementById(formulario),"anadirdatosreftype.php","espera","espera","Si");
}

function ensenardatosoem(){	
		var ref;
		ref="resultadooem";
		
		theObject = document.getElementById(ref);
		theObject.style.visibility = "visible";
		theObject.style.width = "152px";

		var posx = 0;
		var posy = 0;

		posx = (findPosX (document.getElementById("oeminput2")) + 1);
		posy = (findPosY (document.getElementById("oeminput2")) + 23);

		theObject.style.left = posx + "px";
		theObject.style.top = posy + "px";
	
	//ref="formresultadooem";
		if (document.getElementById(ref).style.display != "block"){
			document.getElementById(ref).style.display = 'block';
		}else{
			document.getElementById(ref).style.display = 'none';
	}
}

function ensenardatosaplicacion(celdas){	
		var ref;
		ref="formresultadoaplicacion";	
		
	/*submitform(document.getElementById(ref),"autocomaplicaciones.php","autocompletardiv","espera");*/
	
		theObject = document.getElementById(ref);
		theObject.style.visibility = "visible";
		theObject.style.width = "152px";

		var posx = 0;
		var posy = 0;

		posx = (findPosX (document.getElementById("aplicacioninput")) + 1);
		posy = (findPosY (document.getElementById("aplicacioninput")) + 23);

		theObject.style.left = posx + "px";
		theObject.style.top = posy + "px";
	
	if (document.getElementById(ref).style.display != "block"){
		document.getElementById(ref).style.display = 'block';
		}else{
		document.getElementById(ref).style.display = 'none';
	}
}


function ensenardatosaplicacionizq(){	
	var ref;
	ref="formcaracteristicasizq";
		
		theObject = document.getElementById(ref);
		theObject.style.visibility = "visible";
		theObject.style.width = "152px";

		var posx = 0;
		var posy = 0;

		posx = (findPosX (document.getElementById("aplicacioncaracizqinput")) + 1);
		posy = (findPosY (document.getElementById("aplicacioncaracizqinput")) + 23);

		theObject.style.left = posx + "px";
		theObject.style.top = posy + "px";
	
	
	if (document.getElementById(ref).style.display != "block"){
		document.getElementById(ref).style.display = 'block';
		}else{
		document.getElementById(ref).style.display = 'none';
	}
}

function ensenardatosaplicacionder(){	
	var ref;
	ref="formcaracteristicasder";
		theObject = document.getElementById(ref);
		theObject.style.visibility = "visible";
		theObject.style.width = "152px";

		var posx = 0;
		var posy = 0;

		posx = (findPosX (document.getElementById("aplicacioncaracderinput")) + 1);
		posy = (findPosY (document.getElementById("aplicacioncaracderinput")) + 23);

		theObject.style.left = posx + "px";
		theObject.style.top = posy + "px";
	
	if (document.getElementById(ref).style.display != "block"){
		document.getElementById(ref).style.display = 'block';
		}else{
		document.getElementById(ref).style.display = 'none';
	}
	
}


function sugerenciaaplicacion(object,celdas){	
	/*Le ponemos el valor cojido del combo en el valor a modificar*/
	ref = "refaplicacion" + celdas;
	document.getElementById("aplicacioninput").value=document.getElementById(ref).options[document.getElementById(ref).selectedIndex].text;
	ensenardatosaplicacion();
	
}
function sugerenciaaplicacionizq(object,celdas){	
	/*Le ponemos el valor cojido del combo en el valor a modificar*/
	ref = "caracteristicasizq" + celdas;
	/*Le ponemos el valor cojido del combo en el valor a modificar*/
	document.getElementById("aplicacioncaracizqinput").value=document.getElementById(ref).options[document.getElementById(ref).selectedIndex].text;
	ensenardatosaplicacionizq();
}

function sugerenciaaplicacionder(object,celdas){	
	/*Le ponemos el valor cojido del combo en el valor a modificar*/
	ref = "caracteristicasder" + celdas;
/*Le ponemos el valor cojido del combo en el valor a modificar*/
	document.getElementById("aplicacioncaracderinput").value=document.getElementById(ref).options[document.getElementById(ref).selectedIndex].text;
	ensenardatosaplicacionder();
}

function canviovalorcheck(referencia){
	var ref;
	ref="checkbox"+referencia;
	if (document.getElementById(ref).value="on"){
		 document.getElementById(ref).value="off";
	}else{
		document.getElementById(ref).value="on";
	}
}

//
//Esta funcion tiene que mirar que no hayan mas de 2 seleccionadas , solo se pueden seleccionar 2
function canviovalorcheckpics(referencia,traduccion){
	var ref;
	var quantos;
	quantos = 0;
	ref="checkboxpics"+referencia;
	if (document.getElementById(ref).value=='on'){
		document.getElementById(ref).value='off';
	}else{
		var inputs = document.getElementsByTagName("input");
		for(var i=0; i<inputs.length; i++){
				if(inputs[i].getAttribute('type')=='checkbox'){
					if (inputs[i]["checked"]){
							quantos = quantos + 1;
					}
				}
		}
		if (quantos < 3){
			document.getElementById(ref).value="on";
		}else{
			alert(traduccion);
			document.getElementById(ref).value='off';
			document.getElementById(ref).checked = 0;
		}
		
		
	}
}


//
//Esta funcion tiene que mirar que no hayan mas de 5 referencias seleccionadas , solo se pueden seleccionar 5
function canviovalorcheckreferencias(referencia,traduccion){
	var ref;
	var quantos;
	quantos = 0;
	ref="checkboxref"+referencia;
	if (document.getElementById(ref).value=='on'){
		document.getElementById(ref).value='off';
	}else{
		var inputs = document.getElementsByTagName("input");
		for(var i=0; i<inputs.length; i++){
				if(inputs[i].getAttribute('type')=='checkbox'){
					if (inputs[i]["checked"]){
							quantos = quantos + 1;
					}
				}
		}
		if (quantos <6){
			document.getElementById(ref).value="on";
		}else{
			alert(traduccion);
			document.getElementById(ref).value='off';
			document.getElementById(ref).checked = 0;
		}
		
		
	}
}


function habilitar(referencia){
	var ref;
	ref="refnumsub"+referencia;
	document.getElementById(ref).disabled=!document.getElementById(ref).disabled;
}
function misubmit(referencia){
	var ref;
	var formulario;
	ref="resultado"+referencia;
	formulario = "formtest"+referencia ;
	submitform(document.getElementById(formulario),"resultado.php",ref,"espera");
}

function misubmitsave(referencia){
	var ref;
	var formulario;
	ref="resultado"+referencia;
	formulario = "formtest"+referencia ;
	submitform(document.getElementById(formulario),"guardar.php",ref,"espera");
}


function anadirvalor(referencia,pagina,reinicio,traduccion){
	/*aqui seleccionamos las referencias para poder ser seleccionadas*/
	/*si reinicion =="reiniciar" -->entonces tengo que preguntar si quiero borrar todo o no*/
	var ref;
	var formulario;
	var funcion1;
	if (reinicio!=0){
		if (!confirm(traduccion)){
			return false;
		}
	}
	ref="milistboxorigen";
	formulario = "formanadir"+referencia;
	/*para saber la linea seleccionada en cual esto*/
	document.getElementById('lineaseleccionada').value=referencia;
	document.getElementById('paginaseleccionada').value=pagina;
	/*ejecute la funcion1, quando acaba
		El "No", quiere decir no refresque la pantalla al final,,
		Mejoras en la funcion submitform, que le podamos pasar un conjunto de funciones para ejecutarse
	*/
	funcion1 = "document.getElementById('anadireferencia').style.zIndex=1";
	submitform(document.getElementById(formulario),"anadireferencia.php",ref,"espera","No",funcion1);
}


function borrar_registro(referencia,traduccion){
	/*aqui seleccionamos las referencias para poder ser seleccionadas*/
	if (confirm(traduccion)){
		var ref;
		var formulario;
		formulario = "formanadir"+referencia;
		/*para saber la linea seleccionada en cual esto*/
		submitform(document.getElementById(formulario),"borrar_registro.php","espera","espera","Si");
	}
}

function borrar_pagina(traduccion){
	/*aqui seleccionamos las referencias para poder ser seleccionadas*/
	if (confirm(traduccion)){
		var ref;
		var formulario;
		formulario = "formpaginanueva";
		/*para saber la linea seleccionada en cual esto*/
		submitform(document.getElementById(formulario),"borrar_pagina.php","espera","espera","Si");
	}
}

function anadir_blanco(referencia){
	/*aqui seleccionamos las referencias para poder ser seleccionadas*/
	var ref;
	var formulario;
	ref="oems"+referencia;
	formulario = "formanadir"+referencia;
	/*para saber la linea seleccionada en cual esto*/
	submitform(document.getElementById(formulario),"anadir_blanco.php","espera","espera","Si");
}

/*
Funciones en la parte de añadir las oems, submit form de las oems
*/

function anadiroems(referencia,e){
	/*aqui seleccionamos las referencias para poder ser seleccionadas*/
	var ref;
	var formulario;
		/*asi para que funcione en firefox, y en todo lo demas*/
		var e=e? e : window.event;
		var event_element=e.target? e.target : e.srcElement;
	/*
	e.type -->retorna click
	e.srcElement
	*/
	if(event_element.tagName=='TD'){ 
	ref="oems"+referencia;
	formulario = "formoems"+referencia;
	/*para saber la linea seleccionada en cual esto*/
	submitform(document.getElementById(formulario),"anadiroems.php",ref,"espera");
	}
}

function anadirresultadooem(referencia){
	/*Aqui grabamos en la base de datos los datos seleecionados*/
	var ref;
	var formulario;
	ref="oems"+referencia;
	formulario = "formresultadooem"+referencia;
	/*para saber la linea seleccionada en cual esto*/
	submitform(document.getElementById(formulario),"anadirdatosoems.php",ref,"espera");
}
/*
Final Funciones en la parte de añadir las oems, submit form de las oems
*/

/*
Funciones en la parte de añadir las aplicaciones y caracteristicas, submit form de las oems
*/

function anadiraplicaciones(referencia,e){
	/*aqui seleccionamos las referencias para poder ser seleccionadas*/
	var ref;
	var formulario;
		/*asi para que funcione en firefox, y en todo lo demas*/
		var e=e? e : window.event;
		var event_element=e.target? e.target : e.srcElement;
	/*
	e.type -->retorna click
	e.srcElement
	*/
	if(event_element.tagName=='TD'){ 
		ref="aplicaciones"+referencia;
		formulario = "formaplicaciones"+referencia;
		/*para saber la linea seleccionada en cual esto*/
		submitform(document.getElementById(formulario),"anadiraplicaciones.php",ref,"espera");
	}
}

function anadirresultadoaplicaciones(referencia){
	/*Aqui grabamos en la base de datos los datos seleecionados*/
	var ref;
	var formulario;
	ref="aplicaciones"+referencia;
	formulario = "formresultadoaplicaciones"+referencia;
	/*para saber la linea seleccionada en cual esto*/
	submitform(document.getElementById(formulario),"anadirdatosaplicaciones.php",ref,"espera");
}
/*
Final Funciones en la parte de añadir las aplicaciones, submit form de las oems
*/

function anadirresultadoref(referencia){
	/*Aqui grabamos en la base de datos los datos seleecionados*/
	var ref;
	var formulario;
	ref="resultado"+referencia;
	formulario = "formresultadoref"+referencia;
	/*para saber la linea seleccionada en cual esto*/
	submitform(document.getElementById(formulario),"anadirdatosref.php",ref,"espera","Si");
}

function pasaradestino(){
	/*pasamos la seleccionada a la base de datos*/
	var ref;
	var formulario;
	var ref2;
    /*ref2="refnumsub"+referencia;*/
	referencia = document.getElementById('lineaseleccionada').value;
	ref="resultado"+referencia;
	formulario = "formnavegar";
	document.getElementById("refseleccionado").value = document.getElementById("referenciaprincipal").value;
	/*document.getElementById("referenciaisubactiva").value = document.getElementById(ref2).value;*/
	/*alert(document.getElementById("referenciaisubactiva").value);*/
	submitform(document.getElementById(formulario),"anadirref.php",ref,"espera");
	document.getElementById('anadireferencia').style.zIndex=-1;
	
}

function anadirref(referencia,nueva,paginaactual,limpiar,e,traduccion){
		
		
		
		var ref;
		var formulario;
		/*asi para que funcione en firefox, y en todo lo demas*/
		var e=e? e : window.event;
		var event_element=e.target? e.target : e.srcElement;
	/*
	e.type -->retorna click
	e.srcElement
	*/
	if ((event_element.tagName=='TD') || (event_element.tagName=='DIV')){ 
	/*aqui seleccionamos las referencias para poder ser seleccionadas*/
		ref="resultado"+referencia;
		formulario = "formreferencia"+referencia;
		/*para saber la linea seleccionada en cual esto*/
		if (nueva!=1){
			submitform(document.getElementById(formulario),"anadirref.php",ref,"espera");
		}else{
			anadirvalor(referencia,paginaactual,0,traduccion);
		}
	}
	
}

function subirref(referencia){
	/*subimos la linea a la de arriba*/
	var ref;
	var formulario;
	ref="resultado"+referencia;
	formulario = "formsubirref"+referencia;
	submitform(document.getElementById(formulario),"subirref.php","espera","espera","Si");
	
}
function bajarref(referencia){
	/*subimos la linea a la de arriba*/
	var ref;
	var formulario;
	ref="resultado"+referencia;
	formulario = "formsubirref"+referencia;
	submitform(document.getElementById(formulario),"bajarref.php","espera","espera","Si");
	
}


/*
Funciones en la parte de aÃ±adir las pics, submit form de las oems
*/

function anadirpics(referencia,e){
	/*aqui seleccionamos las referencias para poder ser seleccionadas*/
	var ref;
	var formulario;
		/*asi para que funcione en firefox, y en todo lo demas*/
		var e=e? e : window.event;
		var event_element=e.target? e.target : e.srcElement;
	/*
	e.type -->retorna click
	e.srcElement
	*/
	/*Aqui tengo que poner tambien div, porque ocupa todo el div, mas adelante tendremos que poner */
	if ((event_element.tagName=='TD') || (event_element.tagName=='DIV')){ 
		ref="pics"+referencia;
		formulario = "formpics"+referencia;
		/*para saber la linea seleccionada en cual esto*/
		submitform(document.getElementById(formulario),"anadirpics.php",ref,"espera");
	}
}
function anadirresultadopics(referencia){
	/*Aqui grabamos en la base de datos los datos seleecionados*/
	var ref;
	var formulario;
	ref="pics"+referencia;
	formulario = "formresultadopics"+referencia;
	/*para saber la linea seleccionada en cual esto*/
	submitform(document.getElementById(formulario),"anadirdatospics.php",ref,"espera");
}

function anadirresultadotitulo(){
	submitform(document.getElementById("formtitulo"),"anadirdatostitulo.php","formtitulo","espera","Si");
}


/*funciones de terceros*/
 function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

function cambiar(esto)
{
	vista=document.getElementById(esto).style.display;
	if (vista=='none')
		vista='block';
	else
		vista='none';

	document.getElementById(esto).style.display = vista;
}


  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }



function onKeyPress () {

  var keycode;

  if (window.event) keycode = window.event.keyCode;

  else if (e) keycode = e.which;

  else return true;

  if (keycode == 13) {

    alert("Pulse enviar para enviar su consulta.");

    return false

  }

return true 

}

document.onkeypress = onKeyPress;





function setfocus() {

        document.Reserva.nom.focus();

        return;

}





function validar(formulari)

{



  if (formulari.nom.value.length < 2)

  {



  alert("Por favor indique su nombre.");

    formulari.nom.focus();

    return (false);

  }



  var checkOK = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚabcdefghijklmnñopqrstuvwxyzáéíóúàèò .:,/";

  var checkStr = formulari.nom.value;

  var allValid = true;

  for (i = 0;  i < checkStr.length;  i++)

  {

    ch = checkStr.charAt(i);

    for (j = 0;  j < checkOK.length;  j++)

      if (ch == checkOK.charAt(j))

        break;

    if (j == checkOK.length)

    {

      allValid = false;

      break;

    }

  }

  if (!allValid)

  {

    alert("Por favor indique su nombre.");

    formulari.cognoms.focus();

    return (false);

  }



    if (formulari.cognoms.value.length < 2)

  {



  alert("Por favor indique su apellido.");

    formulari.cognoms.focus();

    return (false);

  }



  var checkOK = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚabcdefghijklmnñopqrstuvwxyzáéíóúàèò .:,/";

  var checkStr = formulari.cognoms.value;

  var allValid = true;

  for (i = 0;  i < checkStr.length;  i++)

  {

    ch = checkStr.charAt(i);

    for (j = 0;  j < checkOK.length;  j++)

      if (ch == checkOK.charAt(j))

        break;

    if (j == checkOK.length)

    {

      allValid = false;

      break;

    }

  }

  if (!allValid)

  {

    alert("Por favor indique su apellido.");

    formulari.cognoms.focus();

    return (false);

  }



   

 



  if ((formulari.email.value.indexOf ('@', 0) == -1)||(formulari.email.value.length < 5)) { 

    alert("Dirección de email incorrecta.");

    formulari.email.focus();

    return (false); 

  }

  return (true);

}


function valida_envia(){
    //valido el CIF
    if (document.alta.cif.value.length<9){
       alert("CIF/NIF Incorrecto EJEMPLO: B12345678")
       document.alta.cif.focus()
       return 0;
    }
	if (document.alta.pasword.value.length<5){
       alert("Tiene que escribir una contraseña de almenos 5 caracteres")
       document.alta.pasword.focus()
       return 0;
    }
    //el formulario se envia
    alert("Registro Completado");
    document.alta.submit();
} 

function valida_envia_cr(){
    //valido el CIF
    if (document.alta.cif.value.length<9){
       alert("CIF/NIF Incorrecto EJEMPLO: B12345678")
       document.alta.cif.focus()
       return 0;
    }
	if (document.alta.pasword.value.length<5){
       alert("Tiene que escribir una contraseña de almenos 5 caracteres")
       document.alta.pasword.focus()
       return 0;
    }
	if ((document.alta.email.value.indexOf ('@', 0) == -1) || (document.alta.email.value.length < 5)){
		alert("Dirección de email incorrecta.")
		document.alta.email.focus()
		return 0;
	}
	if (document.alta.nom.value.length<1){
		alert("Tiene que escribir el nombre del alojamiento")
		document.alta.nom.focus()
		return 0;
	}
	if (document.alta.poblacio.value.length<1){
		alert("Tiene que escribir alguna población")
		document.alta.poblacio.focus()
		return 0;
	}
    //el formulario se envia
    alert("Registro Completado");
    document.alta.submit();
} 

function valida_envia2(){
    //valido el CIF
    if (document.alta.cif.value.length<9){
       alert("CIF/NIF Incorrecto EJEMPLO: B12345678")
       document.alta.cif.focus()
       return 0;
    }
	
    //el formulario se envia
    
    document.alta.submit();
} 


