/**
 * @author Edu
 */

 function desocultar(id){
 	document.getElementById(id).style.display = 'block';
 }
 function ocultar(id){
 	document.getElementById(id).style.display = 'none';
 }
 function deseleccionar_todo(id){
 	var form = document.getElementById(id);
   for (i=0;i<form.elements.length;i++)
      if(form.elements[i].type == "checkbox")
         form.elements[i].checked=0
} 
 
 /* ***********************************************************************************
  * mostrarError: 
  * 
  * ***********************************************************************************/

 function mostrarError(mensajeError,titulo) {
 	titulo = titulo || 'Error en la operación';
 	Sexy.alert('<h1>'+titulo+'</h1><p>'+mensajeError+'</p>');
 }



 /* ***********************************************************************************
  * MostrarConfirmacion: 
  * 
  * ***********************************************************************************/

 function MostrarConfirmacion(mensajeVentana,funcionSi,funcionNo,titulo,txtBotonContinuar,txtBotonCancelar){
 	//titulo = titulo || 'Confirmación de la operación';
 	txtBotonContinuar = txtBotonContinuar || 'Continuar';
 	txtBotonCancelar = txtBotonCancelar || 'Cancelar';
 	Sexy.confirm('<h1>'+titulo+'</h1><p>'+mensajeVentana+'</p>',{onComplete:function(returnvalue) { if(returnvalue) { eval(funcionSi+';'); } else { eval(funcionNo+';'); } },textBoxBtnOk:txtBotonContinuar,textBoxBtnCancel: txtBotonCancelar });
 }
 
 function irReserva(ruta){
	 alert(ruta);
	 return false;
 }
 
 function cancelarReserva(){
	 return false;
 }
 
 
 function colocarFechas(){
	 var linkAnterior = document.getElementById('linkMesAnterior');
	 var linkPosterior = document.getElementById('linkMesPosterior');
	 var caja1 = document.getElementById('f1');
	 var caja2 = document.getElementById('f2');
	 
	 if(linkAnterior!=null) linkAnterior.href = linkAnterior.href + '&f1=' + caja1.value + '&f2=' + caja2.value + '&pd=true';
	 if(linkPosterior!=null)linkPosterior.href = linkPosterior.href + '&f1=' + caja1.value + '&f2=' + caja2.value + '&pd=true';
 }
 
 /* ***********************************************************************************
 * SimularClick: Simular un click en un objeto.
 *   idObjecte : objecte sobre el cual se aplica el evento click
 * ***********************************************************************************/
 function SimularClick(idObjete){
	 var nouEvent = document.createEvent("MouseEvents");
	 nouEvent.initMouseEvent("click", true, true, window,0, 0, 0, 0, 0, false, false, false, false, 0, null);
	 var objecte = document.getElementById(idObjete);
	 var canceled = !objecte.dispatchEvent(nouEvent);
 }
 
function sustitucionGMaps(stringALimpiar){
	var string = stringALimpiar;
	string = string.replace(/ /g,'+');
	string = string.replace(/á/g,'%C3%A1');
	string = string.replace(/à/g,'%C3%A0');
	string = string.replace(/é/g,'%C3%A9');
	string = string.replace(/è/g,'%C3%A8');
	string = string.replace(/í/g,'%C3%AD');
	string = string.replace(/ì/g,'%C3%AC');
	string = string.replace(/ó/g,'%C3%B3');
	string = string.replace(/ò/g,'%C3%B2');
	string = string.replace(/ú/g,'%C3%BA');
	string = string.replace(/ù/g,'%C3%B9');
	string = string.replace(/ï/g,'%C3%AF');
	string = string.replace(/ü/g,'%C3%BC');
	string = string.replace(/ñ/g,'%C3%B1');
	string = string.replace(/ç/g,'%C3%A7');
	string = string.replace(/·/g,'%C2%B7');
	return string;
}

function generarUrlGMaps(adress,num,pc,coordenadas){
	var direccion = '';
	var url = 'http://maps.google.es/?iwloc=&z=15&hl=es&ie=UTF8&q=';
	
	direccion = direccion + adress;
	direccion = direccion + ', ' + num;
	direccion = direccion + ' - ' + pc;
	
	if(coordenadas!=''){
		direccion = direccion + '&sll=' + coordenadas;
	}
	
	document.getElementById('iframeGMaps').src = url + sustitucionGMaps(direccion) + '&output=embed';
	return false;
}

function ponerFechaSalida(idDestino,valor,idCajaOrigen){
	 if(document.getElementById(idDestino).value==''){
		 //esta vacío, lo llenaremos con una dia mas
		 arrayFecha = valor.split('/');
		 fecha = new Date( arrayFecha[2],(parseInt(arrayFecha[1]*1)-1),(parseInt(arrayFecha[0]*1)+1) );
		 document.getElementById(idDestino).value = fecha.getDate() + '/' + (fecha.getMonth()+1) + '/' + (fecha.getFullYear());
		 
		// $("#" + idDestino).datepicker( "option", "minDate", new Date(fecha.getYear(), (parseInt(fecha.getDate()-1), fecha.getDate()) );
	 }else{
		 //no esta vacío, mimramos si es incorrecta la fecha
		 arrayFecha = valor.split('/');
		 fecha = new Date( (parseInt(arrayFecha[1]*1))+'/'+(parseInt(arrayFecha[0]*1))+'/'+(parseInt(arrayFecha[2])) );
		 
		 valor2 = document.getElementById(idDestino).value;
		 arrayFechaDestino = valor2.split('/');
		 fechaDestino = new Date( (parseInt(arrayFechaDestino[1]*1))+'/'+(parseInt(arrayFechaDestino[0]*1))+'/'+(parseInt(arrayFechaDestino[2])) );
		 
		 if(fecha>fechaDestino){
			 document.getElementById(idDestino).value='';
			 ponerFechaSalida(idDestino,valor,idCajaOrigen);
		 }
	 }
}

function ponerFechaEntrada(idDestino,valor,idCajaOrigen){
	 if(document.getElementById(idDestino).value==''){
		 //esta vacío, lo llenaremos con un dia menos
		 arrayFecha = valor.split('/');
		 fecha = new Date( arrayFecha[2],(parseInt(arrayFecha[1]*1)-1),(parseInt(arrayFecha[0]*1)-1) );
		 document.getElementById(idDestino).value = fecha.getDate() + '/' + (fecha.getMonth()+1) + '/' + (fecha.getFullYear());
		 //$("#" + idDestino).datepicker( "option", "maxDate", new Date(fechaLocal[2], (parseInt(fechaLocal[0]*1)-1), fechaLocal[1]) );
	 }
}

function ucFirst(string) {
	return string.substring(0, 1).toUpperCase() + string.substring(1).toLowerCase();
}

function comprobarPrefijoInternacional(string){
	if(string.length>5){
		alert('El prefijo introducido es incorrecto');
		return false;
	}
	return true;
}
