		
function verImagen(imagen,id, idioma, tipo){
	var texto="";
	if (tipo ==null){
		tipo= 9
	}
	var result = "";
	if (document.getElementById(id).innerHTML.length>1000){
		result = document.getElementById(id).innerHTML.substring(0,1001)+"...";
	}else{
		result = document.getElementById(id).innerHTML;
	}
	var cruz = "<div style='background-color:#FFFFFF'><span style='background-color:#b7c9cc;margin-right:0px; margin-top:0px;float:right;display:block' class='f_text2' onClick=javascript:visualizar('ejcproc2')><b>&nbsp;X&nbsp;</span>";
	var imagen = "<center><img src="+imagen+"?ale="+String(Math.random())+" style='vertical-align: middle'>";
	texto ="<table style='border: 0px solid #b7c9cc; background-color:#FFFFFF' "
	texto = texto + " width='95%' height='400' cellpadding='5' cellspacing='5' onClick=javascript:visualizar('ejcproc2')>"
	texto = texto + " <tr><td 45%' style='vertical-align: middle' >"
	texto = texto + imagen
	texto = texto + "</td>";
	texto = texto + "<td width= '45%' style='vertical-align: middle;' class='Cabecera'>";
	texto = texto + result;
	texto = texto + "<br><br><br><table align='center' onClick=javascript:vervale('"+id+"','"+tipo+"')><tr><td><img src='images/descarga_"+idioma+".gif'></td></tr></table></td></tr></table>" 
	document.getElementById('ejcproc2').style.display="block"
	document.getElementById('ejcproc').style.display="block"
	document.getElementById('ejcproc2').innerHTML=cruz+texto+"</div>"
	centrarWrapper()
}

function verImagenSes(imagen,id, idioma){

	var texto="";
	var cruz = "<div style='background-color:#FFFFFF'><span style='background-color:#b7c9cc;margin-right:0px; margin-top:0px;float:right;display:block' class='f_text2' onClick=javascript:visualizar('ejcproc2')><b>&nbsp;X&nbsp;</span>";
	var imagen = "<center><img src="+imagen+"?ale="+String(Math.random())+" style='vertical-align: middle'>";
	texto ="<table style='border: 0px solid #b7c9cc; background-color:#FFFFFF' "
	texto = texto + " width='95%' height='400' cellpadding='5' cellspacing='5' onClick=javascript:visualizar('ejcproc2')>"
	texto = texto + " <tr><td 45%' style='vertical-align: middle'>"
	texto = texto + imagen
	texto = texto + "</td>";
	texto = texto + "<td width= '45%' style='vertical-align: middle;'>";
	texto = texto + document.getElementById(id).innerHTML;
	texto = texto + "<br><br><br><table align='center' onClick=javascript:versesiones('"+id+"')><tr><td><img src='images/sesiones_"+idioma+".gif'></td></tr></table></td></tr></table>" 
	document.getElementById('ejcproc2').style.display="block"
	document.getElementById('ejcproc').style.display="block"
	document.getElementById('ejcproc2').innerHTML=cruz+texto+"</div>"
	centrarWrapper()
}

function cargarFormulario(valor){
	var finalurl = "formsesiones.php?Cid="+valor +"&ale="+String(Math.random());
	window.document.getElementById('peticionesIframe').src =finalurl;
}

function cargarDetalleSession(valor){
	var finalurl = "verdetsesion.php?Cid="+valor +"&ale="+String(Math.random());
	window.document.getElementById('peticionesIframe').src =finalurl;
}

function validar(){
	if (document.forms['indentificarse'].email.value=="" || document.forms['indentificarse'].password.value==""){
		alert("Introduzca un usuario y contraseña");
		return false;
	}
	document.forms[1].submit()
}

function numbersonly(campo, e, dec)
{
var tecla;
var caracter;

if (window.event)
   tecla = window.event.keyCode;
else if (e)
   tecla = e.which;
else
   return true;
caracter = String.fromCharCode(tecla);

if ((tecla==null) || (tecla==0) || (tecla==8) || 
    (tecla==9) || (tecla==13) || (tecla==27) )
   return true;
else if ((("0123456789,-").indexOf(caracter) > -1))
   return true;
else if (dec && (caracter == "."))
   {
   campo.form.elements[dec].focus();
   return false;
   }
else
   return false;
}

function validarPago(){
	if (document.forms['pgo'].order.value ==""){
		alert("El número de localizador no puede estar vacío");
		return false;
	}
	if(BuscarCualquierChecked(document.forms['pgo'].pago) ==-1){
			alert("Debe de seleccionar una forma de pago");
			return false;
	}
	document.forms['pgo'].submit();
}


function BuscarCualquierChecked(FieldRadio)
{
//Mediante esta rutina comprobaremos si un campo de tipo checkbox (radio/Check button) tiene algún valor seleccionado. Devolverá -1 en caso que NO haya nada seleccionado y 1 en caso que SI encuentre algún valor seleccionado.
try{
	for(i = 0; i <= FieldRadio.length; i++)
		{
		if(FieldRadio[i].checked) return 1;
	}
	if(i == FieldRadio.length) return -1;
}catch (Exception){
	return -1
}
}

function validarCuestionario(){
	if (trim(document.forms['cuestionario'].empresa.value=="")){
		alert("Debe de informar el nombre de la empresa");
		return 
	}
	if (trim(document.forms['cuestionario'].contacto.value=="")){
		alert("Debe de informar el nombre del contacto");
		return 
	}
	if (trim(document.forms['cuestionario'].telefono.value=="")){
		alert("Debe de informar el teléfono");
		return 
	}
	if (trim(document.forms['cuestionario'].email.value=="")){
		alert("Debe de informar el email");
		return 
	}
	if (trim(document.forms['cuestionario'].comentarios.value=="")){
		alert("Debe de informar las observaciones");
		return 
	}
	document.forms['cuestionario'].submit()
}

function vervale(valor, tipo){
	var ancho = 950;
	var alto = 700;
	var x = (screen.width/2) - (ancho/2);
	var y = (screen.height/2) - (alto/2) - 20;
	var finalurl = "";
	if (tipo=="2" || tipo=="0"){
		finalurl = "vervale.php?Cid="+valor +"&ale="+String(Math.random());
	}else{
		finalurl = "vervalegrupos.php?Cid="+valor +"&ale="+String(Math.random());
	}
	WinNueva = window.open(finalurl,"NuevaBusqueda","top=" + y + ",left=" + x + ",resizable=0,statusbar=yes,scrollbars=yes,width=" + ancho + ",height=" + alto);//creo una pantalla vacia sin 
	WinNueva.focus();
}

function verReservas(id, ciudad){
	try{
		opener.parent.window.frames[0].window.location.href= "cabecera.php?button=6"
		opener.window.location.href="grupos.php?p=6&xs=1&rd="+ciudad.toUpperCase()+"&Cid="+id+"&ale="+String(Math.random());
		window.close();
	}catch (e){
		window.frames[0].window.location.href= "cabecera.php?button=6"
		window.location.href="grupos.php?p=6&xs=1&rd="+ciudad.toUpperCase()+"&Cid="+id+"&ale="+String(Math.random());
	}
}

function presupuesto(valor){
	var finalurl = "presupuesto.php?Cid="+valor +"&ale="+String(Math.random());
	window.location.href = finalurl
}

function cambiarVale(valor, tipo){
	var ancho = 950;
	var alto = 700;
	var x = (screen.width/2) - (ancho/2);
	var y = (screen.height/2) - (alto/2) - 20;
	var finalurl = "";
	if (tipo=="2" || tipo=="0"){
		finalurl = "vervale.php?Cid="+valor +"&ale="+String(Math.random());
	}else{
		finalurl = "vervalegrupos.php?Cid="+valor +"&ale="+String(Math.random());
	}
	window.location.href=finalurl
}

function versesiones(valor){
	var finalurl = "versesiones.php?Cid="+valor +"&ale="+String(Math.random());
	window.document.getElementById('peticionesIframe').src =finalurl;
}

function verImagenBus(imagen,id){
var texto="";
var cruz = "<div style='background-color:#FFFFFF'><span style='background-color:#b7c9cc;margin-right:0px; margin-top:0px;float:right;display:block' class='f_text2'><b>&nbsp;X&nbsp;</span>";
var imagen = "<center><img src="+imagen+"?ale="+String(Math.random())+">";
texto ="<table style='border: 0px solid #b7c9cc; background-color:#FFFFFF' width='100%' height='400'><tr align='center'><td>"
texto = texto + imagen
texto = texto + "</td></tr><table>" 
texto = texto + "<table width='100%' height='22px' style='border: 1px solid #9A4062; background-color:#891637'><tr align='center'></tr></table>"
parent.document.getElementById('ejcproc2').style.display="block"
parent.document.getElementById('ejcproc').style.display="block"
parent.document.getElementById('ejcproc2').innerHTML=cruz+texto+"</div>"
parent.centrarWrapper()

}

//segun el parámetro cargamos un valor u otro en el frame
function cargarContenido(valor){

	if (valor=="home"){
		ajustarFrame('2')
		window.top.menu.location.href = "inicabecera.php"
		window.top.vista.location.href = "presentacion.php"
	}else{
		ajustarFrame('1')
		if (valor=="con"){
			window.top.menu.location.href = "cabecera.php?button=8"
			window.top.vista.location.href = "contactar.php?p=6"
		}
		if (valor=="ser"){
			window.top.menu.location.href = "cabecera.php?button=2"
			window.top.vista.location.href = "servicios.php?p=1"
		}
		if (valor=="car"){
			window.top.menu.location.href = "cabecera.php?button=3"
			window.top.vista.location.href = "cartelera.php?p=4&xs=1"
		}
		if (valor=="sal"){
			window.top.menu.location.href = "cabecera.php?button=6"
			window.top.vista.location.href = "salidas.php?p=3"
		}
	}

}

function ajustarFrame(tipo){
	var objsFrameset=top.document.getElementsByTagName("frameset");
	if (tipo=="1"){
		objsFrameset[0].rows="146,*"
	}else{
		objsFrameset[0].rows="88,*"
	}
}

function desconectar(){
	parent.top.window.location.href="desconectar.php"

}

function verImagen2(imagen,id){
var texto="";
var cruz = "<div style='background-color:#891637'><span style='background-color:#891637;margin-right:0px; margin-top:0px;float:right;display:block' class='f_text2'>&nbsp;X&nbsp;</span>";
var comentario = document.getElementById('idimg'+id).alt
var imagen = "<img src="+imagen+"?ale="+String(Math.random())+" VALIGN='middel'>";
texto ="<table style=' background-color:#891637' width='100%' height='530'><tr align='center'><td VALIGN='bottom'><br><br><br><br><br><br><br>"
texto = texto + imagen
texto = texto + "</td></tr><table>" 
document.getElementById('ejcproc2').style.display="block"
document.getElementById('ejcproc').style.display="block"
document.getElementById('ejcproc2').innerHTML=cruz+texto+"<div>"
ocultarContenido()
centrarWrapper()
}

function mostrarDetalle(objeto){
var cruz = "<span style='background-color:#891637;margin-right:0px; margin-top:0px;float:right;display:block' class='f_text2'>&nbsp;X&nbsp;</span>";
document.getElementById('ejcproc2').style.display="block"
document.getElementById('ejcproc').style.display="block"
document.getElementById('video').style.display="none"
document.getElementById('ejcproc2').innerHTML=cruz+objeto.innerHTML
centrarWrapper()
mostrarContenido(1)
}

function abrirUrlImpacto(op, it){
	var ancho = 1000;
	var alto = 800;
	var x = (screen.width/2) - (ancho/2);
	var y = (screen.height/2) - (alto/2) - 20;
	var finalurl ="impacto.php?op="+op+"&it="+it+"&ale="+String(Math.random());
	WinNueva = window.open(finalurl,'','');//creo 
	WinNueva.focus();
}

function cargarCartelera(tipo, ciudad){
	var ancho = 800;
	var alto = 600;
	var x = (screen.width/2) - (ancho/2);
	var y = (screen.height/2) - (alto/2) - 20;
	var finalurl ="cartelera_print.php?tipo="+tipo+"&rd="+ciudad+"&ale="+String(Math.random());
	WinNueva = window.open(finalurl,'',"top=" + y + ",left=" + x + ",resizable=0,statusbar=yes,scrollbars=yes,width=" + ancho + ",height=" + alto);//creo 
	WinNueva.focus();
}

function abrirUrl(url){
	window.location.href=url
}
function abrirURLframe(url){
	window.top.vista.location.href="http://"+location.host+url
}
function centrarWrapper (){
    var correctorPercent = 1;//En caso de definir las dimensiones del wrapper en porcentajes.
    if (window.innerWidth > document.getElementById('ejcproc2').offsetWidth - correctorPercent){
        document.getElementById('ejcproc2').style.left = '50%';
        document.getElementById('ejcproc2').style.marginLeft = (-1) * document.getElementById('ejcproc2').offsetWidth / 2 + 'px';
        document.getElementById('ejcproc').style.marginLeft = (-1) * document.getElementById('ejcproc').offsetWidth / 2 + 'px';
    }
    if (window.innerHeight > document.getElementById('ejcproc2').offsetHeight - correctorPercent){
        document.getElementById('ejcproc2').style.top = '50%';
        document.getElementById('ejcproc2').style.marginTop = (-1) * document.getElementById('ejcproc2').offsetHeight / 2 + 'px';
        document.getElementById('ejcproc').style.marginTop = (-1) * document.getElementById('ejcproc').offsetHeight / 2 + 'px';
    }
}

function visualizar(valor){
	if (document.getElementById('ejcproc2').style.display=="block"){
		document.getElementById('ejcproc2').style.display="none"
		document.getElementById('ejcproc').style.display="none"
		mostrarContenido()
	}
}

function verProducto(id){
	document.getElementById('peticionesIframe').src="verproducto.php?Cid="+id
}

function verProductoGeneral(id){
	document.getElementById('peticionesIframe').src="verproductogeneral.php?Cid="+id
}

function verNoticia(id){
	document.getElementById('peticionesIframe').src="vernoticia.php?Cid="+id
}

function verArchivo(id){
	document.getElementById('peticionesIframe').src="verarchivo.php?Cid="+id
}

function verFichero(tipo, valor){
	var ancho = 800;
	var alto = 600;
	var x = (screen.width/2) - (ancho/2);
	var y = (screen.height/2) - (alto/2) - 20;
	var finalurl2 = "descargarFichero.php?tipo="+tipo+"&Cid="+valor+"&ale="+String(Math.random());
	parent.document.getElementById('peticionesIframeFichero').src=finalurl2
}


//Funcion de busqueda general para toda la web
function busquedaGeneral(){
	var query = document.forms[0].buscar.value
	if (trim(query) ==""){
	alert("Debe de introducir algún caracter para realizar una búsqueda")
		return;
	}
	
	query = "( gama like '"+query+"%' or texto_desc like '"+query+"%' or nombre like '"+query+"%')"
	window.top.vista.document.forms[0].query.value=query
	window.top.vista.document.forms[0].submit();
}


function buscarproductos(){

	var cat = document.forms[0].Cidioma.value
	var tit= document.forms[0].Cgama.value
	var desc =document.forms[0].Cdescprod.value
	if (cat=="-" && tit=="-" && desc ==""){
		alert("Debe de introducir algún caracter para realizar una búsqueda")
		return;
	}
	
	//montamos la query ej JS categoria like '$idioma' or titulo like '%$titulo%' or descripcion  like '%$desc%'
	var query = "";
	
	if (cat !="-"){
		query = "categoria = '"+cat+"' ";  
	}
	
	if (tit !="-"){
		if (query ==""){
  			query = " gama = '"+replaceSubstring(tit, '+',' ')+"' ";
		}else{
			query += " and gama = '"+replaceSubstring(tit, '+',' ')+"' ";
		}
	}
	
	if (desc !=""){
		if (query ==""){
			query = " texto_desc  like '%"+desc+"%' or nombre like '%"+desc+"%'  ";  
			query += " or gama  like '%"+desc+"%'  ";
		}else{
			query += " and texto_desc  like '%"+desc+"%' or nombre like '%"+desc+"%' ";
			query += " or gama  like '%"+desc+"%'  ";
		}
	}
	document.forms[0].query.value= "( " +query+" )";
	document.forms[0].busqueda.value="1";
	document.forms[0].submit();
}

function buscarnoticias(){
	var desc =document.forms[0].Cdescprod.value
	var query = "";
	if (desc ==""){
		alert("Debe de introducir algún caracter para realizar una búsqueda")
		return;
	}
	
	if (desc !=""){
		if (query ==""){
			query = " titulo  like '%"+desc+"%' or texto like '%"+desc+"%'  ";  
		}else{
			query += " or titulo  like '%"+desc+"%' or texto like '%"+desc+"%' ";
		}
	}
	document.forms[0].query.value= "( " +query+" )";
	document.forms[0].busqueda.value="1";
	document.forms[0].submit();
}

function buscardocumentos(){

	var cat = document.forms[0].Cidioma.value
	var desc =document.forms[0].Cdescprod.value
	if (cat=="-" && desc ==""){
		alert("Debe de introducir algún caracter para realizar una búsqueda")
		return;
	}
	
	//montamos la query ej JS categoria like '$idioma' or titulo like '%$titulo%' or descripcion  like '%$desc%'
	var query = "";
	
	if (cat !="-"){
		query = "categoria = '"+cat+"' ";  
	}
	if (desc !=""){
		if (query ==""){
			query = " nombre  like '%"+desc+"%' or descripcion like '%"+desc+"%'  ";  
		}else{
			query += " or nombre  like '%"+desc+"%' or descripcion like '%"+desc+"%' ";
		}
	}
	document.forms[0].query.value= "( " +query+" )";
	document.forms[0].busqueda.value="1";
	document.forms[0].submit();
}

function verDiv(valor){
	if (document.getElementById(valor).style.display=="none"){
			document.getElementById(valor).style.display="block"
	}else{
		document.getElementById(valor).style.display="none"
	}
}

function cambioIdioma(idioma){
	var path= window.location.href.indexOf("?")
	var path2 = window.top.vista.location.href.indexOf("?")
		if (path==-1){
			window.location.href=window.location.href+"?idioma="+idioma+"&xs=1&rd=BARCELONA&ale="+String(Math.random());;
		}else{
			window.location.href=window.location.href.substring(0,path)+"?idioma="+idioma+"&xs=1&ale="+String(Math.random());;
		}
		if (path2==-1){
			window.top.vista.location.href=window.top.vista.location.href+"?idioma="+idioma+"&xs=1&ale="+String(Math.random());;
		}else{
			window.top.vista.location.href=window.top.vista.location.href.substring(0,path2)+"?idioma="+idioma+"&xs=1&ale="+String(Math.random());;
		}

}

function verImagenVentana(imagen){
	var ancho = 900;
	var alto = 590;
	var x = (screen.width/2) - (ancho/2);
	var y = (screen.height/2) - (alto/2) - 20;
	var path=location.href.substring(0,location.href.lastIndexOf("/"))
	var finalurl = location.protocol+"//"+location.host +"/hps/php/visImage.php?path="+path+"&img="+imagen+"&ale="+String(Math.random())
	WinImagen = window.open(finalurl,"Imagen","top=" + y + ",left=" + x + ",resizable=0,statusbar=yes,scrollbars=yes,width=" + ancho + ",height=" + alto);//creo una pantalla vacia sin documentos
	WinImagen.focus();
}

function verDetalle(id,carpeta){
	var path=location.href.substring(0,location.href.lastIndexOf("/"))
	var finalurl = location.protocol+"//"+location.host +"/hps/php/visDetalle.php?path="+path+"&id="+id+"&carpeta="+carpeta+"&ale="+String(Math.random())
	window.document.getElementById('peticionesIframe').src =finalurl
}

function trim(cadena)
{
	for(i=0; i<cadena.length; )
	{
		if(cadena.charAt(i)==" ")
			cadena=cadena.substring(i+1, cadena.length);
		else
			break;
	}

	for(i=cadena.length-1; i>=0; i=cadena.length-1)
	{
		if(cadena.charAt(i)==" ")
			cadena=cadena.substring(0,i);
		else
			break;
	}
	
	return cadena;
}

function mostrarDetalleSesion(valor){
	ocultarDetalle()
	document.getElementById(valor).style.display="block"
}

function ocultarDetalle(){
	capas=document.getElementsByTagName('tr');
	for (i=0;i<capas.length;i++){
		if ((capas[i].id.indexOf('DET_') != -1)){
				capas[i].style.display='none';
		}
	}
}

function mostrarContenido(flag){
	if (flag==null){
		if (document.getElementById('ejcproc2').style.display=="block"){
			return;
		}
	}
	var pos =0;
	capas=document.getElementsByTagName('div');
	for (i=0;i<capas.length;i++){
		if ((capas[i].id.indexOf('imag') != -1) || (capas[i].id.indexOf('vid') != -1)){
			if ((capas[i].innerHTML.indexOf('#') ==-1) && (capas[i].innerHTML !="")){
				 pos = (capas[i].innerHTML.indexOf('images/'));
				if (pos > 0){
					var hg = capas[i].innerHTML.substring(pos+7,pos+8)
					if (hg !="'"){
						capas[i].style.display='block';
					}
				}
			}
		}
	}
}

function ocultarContenido(){

capas=document.getElementsByTagName('div');
	for (i=0;i<capas.length;i++){
		if ((capas[i].id.indexOf('imag') != -1) || (capas[i].id.indexOf('vid') != -1)){
			if ((capas[i].innerHTML.indexOf('#') ==-1)){
				capas[i].style.display='none';
			}
		}
	}
}

function isNumericField(Field)
{
  var newString = '';
  //Si comprobamos un campo numerico a "" retornamos error
  if (Field==""){
  	return false;
  }
  //Fer les voltes fins saber si es un numero o no
  for (i = 0; i < Field.length; i++)
  {
    ch = Field.substring(i, i+1);
    if (ch >= "0" && ch <= "9")
    {
      newString += ch;
    }
  }
  if (newString  == Field)
  {
    return true;
  }
  else
  {
    return false;
  }
}

function BuscarChecked(FieldRadio, buscarChecked)
{
//Mediante esta rutina comprobaremos si un campo de tipo checkbox (radio/Check button) tiene seleccionado el valor buscarChecked.
	for(i = 0; i<FieldRadio.length; i++)
	{
		if(FieldRadio[i].checked)
		{
			if(FieldRadio[i].value.toUpperCase() == buscarChecked)
			{
				 return 1;
			}
		}
	}
	if(i == FieldRadio.length) return -1;
}

//reemplaza el texto, tantas veces como lo encuentre
function replaceSubstring ( inputString, badString, goodString)
{
	fixedReplace = "";
	UI = inputString;
	UB = badString;
	badEnd = -1;
	badLoc = UI.indexOf(UB);
	if (badLoc != -1)
	{
		for (x=1; (badLoc != -1);x++)
		{
			fixedReplace = fixedReplace + inputString.substring((badEnd + 1), badLoc) + goodString;
			badEnd = badLoc + UB.length - 1;
			badLoc = UI.indexOf(UB, (badLoc + 1));
		}
	  	fixedReplace = fixedReplace + inputString.substring((badEnd+1),inputString.length);
	}
	else
	{
		fixedReplace = inputString;
	}
	return fixedReplace;
}

function omplirAsistenteNombre(){
	document.forms['alta'].nombreasistente.value=document.forms['alta'].nombre.value+" "+document.forms['alta'].apellidos.value
}

function omplirAsistenteApellidos(){
	document.forms['alta'].apellidosasistente.value=document.forms['alta'].apellidos.value
}
