var errorEmail				    	= "Por favor, revise el campo Email";	
var errorEmailVacio					= "Por favor, rellene el campo Email";
var errorCampos						= "Por favor, rellene todos los campos";
var errorTelefonoMovilIncorrecto 	= "Por favor, revise el campo Teléfono Móvil ";
var errorFecha 						= "Por favor, revise la fecha";
var errorCodigo						= "Por favor, rellene el código de validación";
var errorFechaApuntate  			= "Por favor, revise el campo Fecha";
var errorFechaApuntateER 			= "Por favor, seleccione una fecha";
var errorFechaPasada		 		= "Fecha seleccionada pasada, por favor seleccione otra fecha.";
var OCULTO							= "none";
var VISIBLE							= "block";
var horariopasado					= "Has sobrepasado el horario límite para apuntarte en lista en esta discoteca, por favor llámanos para apuntarte en lista.";
var horarioKapital_000				= "Para entrar en Kapital debes de imprimir los pases de Entrada+2Copas 15e o llamarnos para apuntarte en lista. No puedes apuntarte en lista a través de la web."
var bloqueoGeneral_001				= "Para entrar en esta discoteca debes de llamarnos para que te apuntemos en lista. No puedes apuntarte en lista a través de la web.";
var errorCodigoSeguridadInc			= "Por favor, revise el campo de Código de serguridad";

// Funcion que comprueba si un campo esta vacio
function vacio(strAux){
	var re= new RegExp("^\\s+$");		
	if ( (strAux == null) || (strAux == "") || (re.test(strAux)) ) return true;
	return false;
}

//Validamos que este bien informado la caja del email
function validarEmail(email){
	var msgError = "";
	var patron   = /[\w-\.]{3,}@([\w-]{2,}\.)*([\w-]{2,}\.)[\w-]{2,4}/;		
	
	if(email == "")
		msgError = errorEmailVacio;	
	else if(!patron.test(email))
		msgError = errorEmail;	

	return msgError;
}

//Validamos que este bien informado la caja del email para submitir
function validarMail(mail, formulario){
	
	var email = document.getElementById(mail).value;
	var formulario = document.getElementById(formulario);
	var error = validarEmail(email);
	if (!vacio(error))
		alert (error);
	else
			formulario.submit();	
}


//Validamos que este bien informado la caja del email para submitir
function validarMailIndex(mail, formulario){
	
	var emailIndex = document.getElementById(mail).value;
	var email = document.getElementById('email');
	var formulario = document.getElementById(formulario);
	var error = validarEmail(emailIndex);
	if (!vacio(error))
		alert (error);
	else{
			email.value = emailIndex;
			formulario.submit();	
	}		
}

function limpiar(email){
	
	var email = document.getElementById(email);
	email.value='';
}

//Función que valida que el formulario esté correctamente completado
function validarFormularioEmail(){
	var nombreApellidos = document.forms.frmMail.nombreApellidos.value;
	var telefono1 = document.forms.frmMail.telefono1.value;
	var num_person = document.forms.frmMail.num_person.value;
	var email = document.forms.frmMail.email.value;
	var motivo = document.forms.frmMail.motivo.value;
	var fecha = document.forms.frmMail.fecha.value;
	var mensaje = document.forms.frmMail.mensaje.value;
	var msgError = "";
	
	if (vacio(frmMail) || vacio(telefono1) || vacio(num_person) ||vacio(email) || vacio(motivo) || vacio(fecha) || vacio(mensaje))
		msgError = errorCampos;
		
	if (msgError == ""){
		msgError = validarEmail(email);
		if (msgError==""){
				if (!validateTlfmovil(telefono1)) 
					msgError = errorTelefonoMovilIncorrecto;
		}	
	}
	if (msgError!="")
		alert (msgError);
	else {
		document.getElementById('motivo').disabled = false;
		document.forms.frmMail.submit();
	}	
		
}

//Funcion para validar telefono movil
function validateTlfmovil (str){ 
	var re = /^[6]\d{8}$/;
	var re1 = /^[9]\d{8}$/;
	var re2 = /^[3]\d{10}$/;
	var re3 = /^[+]\d{11}$/;
	return (re.test (str)|| re1.test (str) || re2.test (str) || re3.test (str));
}

function analytics(){
	var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
	document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

	try {
		var pageTracker = _gat._getTracker("UA-11627805-1");
		pageTracker._trackPageview();
	}
	catch(err){}
}

function abrirPopUp(URL,x,y){	
	
	day = new Date();
  	id = day.getTime();                                
  	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=yes,location=0,statusbar=0,menubar=0,resizable=0,width=' + x + ',height=' + y + ',left = 500,top = 200');");          
}

function abrirPopUp(URL,x,y,nameId){	
	                                
  eval("page" + nameId + " = window.open(URL, '" + nameId + "', 'toolbar=0,scrollbars=yes,location=0,statusbar=0,menubar=0,resizable=0,width=' + x + ',height=' + y + ',left = 500,top = 200');");          
}

function abrirFlyer(URL,x,y){
	day = new Date();
 	 id = day.getTime();                                
  	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=no,location=0,statusbar=0,menubar=0,resizable=0,width=' + x + ',height=' + y + ',left = 0,top =0');");
}

//borramos el valor de los imputs, por si selecciona otro día de la semana que no se quede cargada la otra discoteca
//Dejamos seleccionado la opción 0
function borrarformulario(){	
	
	document.getElementById("horario").value 					= "";
	document.getElementById("entrada").value 					= "";
	document.getElementById("vestimenta").value 				= "";
	document.getElementById("lista").value 						= "";	
	document.getElementById("discoteca").options[0].selected 	= true;
	document.getElementById('estadocombo').value 				= "0";
}

function abrirCalendario_lista(nameId){		
	
	borrarformulario();
		
	abrirPopUp('http://www.discotecasgratis.com/comun/calendario_lista.php?imputname='+nameId,'200','200','calendario');
	//abrirPopUp('http://localhost/discotecasgratis-nueva/comun/calendario_lista.php?imputname='+nameId,'200','200','calendario');
}

function abrirCalendario(nameId){	
	
	borrarformulario();
		
	abrirPopUp('http://www.discotecasgratis.com/comun/calendario.php?imputname='+nameId,'200','200','calendario');
	//abrirPopUp('http://localhost/discotecasgratis-nueva/comun/calendario.php?imputname='+nameId,'200','200','calendario');
}

//Función que muestra la capa seleccionada
function mostrarCapaFicha(seccion, position){

	for (i=1;i<=3;i++){
		if (position == i)
			document.getElementById(seccion+i).style.display=VISIBLE;		
		else 
			document.getElementById(seccion+i).style.display=OCULTO;
	}	
}

//Función que valida que todos los campos estén informados
function validarApuntate(nameFrm){	
	
	var fecha			= document.getElementById('fecha_lista');
	if(fecha.value == '')
	{
		alert('Introduce la fecha del día que quieres apuntarte en lista.');
		return;
	}
	var formulario 		= document.getElementById(nameFrm);	
	var codigoseguridad = document.getElementById('tmptxt').value;	
	
	var ajax			= nuevoAjax();						
	ajax.open("GET","http://www.discotecasgratis.com/comun/validacptcha.php?codigoseguridad="+codigoseguridad,true);	
	
	ajax.onreadystatechange=function() 
	{ 			
		if (ajax.readyState==4){
		
			var resp_ajax_codigo = ajax.responseText;	
			//alert(resp_ajax_codigo);			
			var msgError		 = "";
						
			if(resp_ajax_codigo == 0)		
				msgError = errorCodigoSeguridadInc;	
				
			if (vacio(msgError))
				msgError	= comprobarComunesApuntate();								
				
			if (vacio(msgError)){
				document.getElementById('discoteca').disabled = false;
				document.getElementById('horario').disabled = false;
				document.getElementById('entrada').disabled = false;
				document.getElementById('vestimenta').disabled = false;
			  	document.getElementById('lista').disabled = false;
				document.getElementById('fecha_lista').disabled = false;	
				
				formulario.submit();
			}
			else
				alert (msgError);																		
		}			
	}
		
	ajax.send(null);	
}

function validarApuntateLista(nameFrm){
	
	var formulario 	= document.getElementById(nameFrm);
	var msgError 	= comprobarComunesApuntate();
	if (vacio(msgError)){
		document.getElementById('discoteca').disabled = false;
		document.getElementById('horario').disabled = false;
		document.getElementById('entrada').disabled = false;
		if (document.getElementById('fecha_lista').disabled == true)
			document.getElementById('fecha_lista').disabled = false;
		formulario.submit();
	}
	else
		alert (msgError);	
}

// Funcion que comprueba que lo introducido es numérico.
function esnumero(s) {
	var reg= new RegExp("^[0-9]+$");			
	if (!reg.test(s))
		return false;
	return true;
}

function comprobarComunesApuntate(){
	
	var fecha 			= document.getElementById('fecha_lista');
	var grupo 			= document.getElementById('grupo');
	var num_personas 	= document.getElementById('num_person');
	var email 			= document.getElementById('email');
	var telefono 		= document.getElementById('telefono');
	var codigo 			= document.getElementById('tmptxt');
	var discoteca		= document.getElementById('discoteca');
	var horariolimit	= document.getElementById('horario').value;	
	var horasistema		= document.getElementById('horasistema').value;	
	var vHorasistema 	= horasistema.split(":");
	var vHorariolimit 	= horariolimit.split(":");		
	var fechahoy		= document.getElementById('fechahoy').value;		
	var vfechahoy 		= fechahoy.split("/");		
	var fechadiscot		= document.getElementById('fecha_lista').value;	
	var vfechadiscot	= fechadiscot.split("/");			
	var millis_hoy 		= Date.UTC(vfechahoy[2],vfechahoy[1],vfechahoy[0]);
	var millis_disco 	= Date.UTC(vfechadiscot[2], vfechadiscot[1], vfechadiscot[0]);		
	var msgError 		= "";		
	
	if(horariolimit == '000')
			msgError = horarioKapital_000;
	else if(horariolimit == '001')
			msgError = bloqueoGeneral_001;
	
	if(vacio(fecha.value) || !esnumero(millis_disco))
		msgError =  errorFechaApuntate;
	
	if (vacio(msgError))
		msgError = (validarEmail(email.value))
	
	var vEmail 			= email.value;
	vEmail 					= vEmail.split("@");	
	var parteEmail  = vEmail[1];
	
	if (vacio(msgError))
		msgError =  validarPatronesEmail(parteEmail);
		
	if (vacio(msgError)){
		if (!validateTlfmovil(telefono.value)) 
				msgError = errorTelefonoMovilIncorrecto;
	}
		
	if (vacio(msgError)){	
		if(millis_disco == millis_hoy){
			if(vHorariolimit[0] < vHorasistema[0])
					msgError = horariopasado;					
			else if((vHorariolimit[0] == vHorasistema[0]) && (vHorariolimit[1] < vHorasistema[1]))		
						msgError = horariopasado;
		}
		else if(millis_disco < millis_hoy)
			msgError = horariopasado;									
	}
			
	if (vacio(msgError)){
		if ((vacio(grupo.value))||(vacio(num_personas.value))||(vacio(codigo.value))|| (discoteca.value == 0))
				msgError = errorCampos;
	}
	
	return msgError;
}

//Validación de patrones de email usados por error del cliente
function validarPatronesEmail(email){

	var parteEmail 	= email;
	var msgError 	= "";

	if(parteEmail == "homtail.com")
		msgError = errorEmail;	
	if(parteEmail == "htmail.com")
		msgError = errorEmail;
	if(parteEmail == "hotmai.com")
		msgError = errorEmail;
	if(parteEmail == "hotmal.com")
		msgError = errorEmail;
	if(parteEmail == "hotmail.cm")
		msgError = errorEmail;
	if(parteEmail == "hotmail.cmo")
		msgError = errorEmail;
	if(parteEmail == "hotmail.c")
		msgError = errorEmail;
	if(parteEmail == "hotmail.co")
		msgError = errorEmail;
		
		return msgError;
}

function validarFecha(fecha){
	
	variables = fecha.split("/");
	diaFrm = variables[0];
	if (diaFrm.length == '1' && diaFrm<10) diaFrm='0'+diaFrm;
	mesFrm = variables[1];	
	if (mesFrm.length == '1' &&  mesFrm<10) mesFrm='0'+mesFrm;
	anioFrm = variables[2];
	
	fec=new Date;
	dia=fec.getDate();
	if (dia<10) dia='0'+dia;
	mes=fec.getMonth();
	if (mes<10) mes='0'+mes;
	anio=fec.getFullYear();
	
	var error = "";
	
	if ((anioFrm < anio) || (anioFrm>anio+1))	
		error = errorFecha;
	if ((mesFrm < 1) || (mesFrm>12)) 	
		error = errorFecha;
	if ((anioFrm=anio)&&(mesFrm<mes))
		error = errorFecha;	
	if ((diaFrm < 1) || (diaFrm>31))
		error = errorFecha;
	if ((mesFrm=mes) && (diaFrm<dia)){
		error = errorFecha;
	} 
	return error;	
} 

//Función que valida los parámetros del formulario de Recomendar
function validaFormularioRecomendar(){
	var codigo		= document.forms.frmRecomendar.tmptxt.value;
	var email		= document.forms.frmRecomendar.email.value;
	var email1		= document.forms.frmRecomendar.emailAmigo1.value;
	var email2		= document.forms.frmRecomendar.emailAmigo2.value;
	var email3		= document.forms.frmRecomendar.emailAmigo3.value;
	var email4		= document.forms.frmRecomendar.emailAmigo4.value;
	var email5		= document.forms.frmRecomendar.emailAmigo5.value;
	var msgError	= "";
	var msgError1	= "";
	var msgError2	= "";
	var msgError3	= "";
	var msgError4	= "";
	var msgError5	= "";
	var msgErrorCodigo = "";
	
	msgError  = validarEmail(email);	
	msgError1 = validarEmail(email1);
	if (!vacio(msgError))
		alert(msgError);
	else if (!vacio(msgError1))
		alert(msgError1+" 1");
	else if (codigo==""){
		alert(errorCodigo);
		msgErrorCodigo = errorCodigo;
	}	
	else if(email2!= ""){ 
		if(!validaPatron(email2)){
			msgError2 = errorEmail + " 2";
			alert(msgError2);
		}	
	}	
	else if(email3!= ""){  
		if(!validaPatron(email3)){
			msgError3 = errorEmail + " 3";
			alert(msgError3);
		}
	}	
	else if(email4!= ""){ 
		if(!validaPatron(email4)){
			msgError4 = errorEmail + " 4";
			alert(msgError4);	
		}	
	}	
	else if(email5!= ""){ 	
		if(!validaPatron(email5)){
			msgError5 = errorEmail + " 5";
			alert(msgError5);	
		}	
	}	
	
	if(msgError == "" && msgError1=="" && msgError2=="" && msgError3=="" && msgError4=="" && msgError5==""){
		var emails = email1+",";
		if(email2 != "")
			emails = emails + email2+",";				
		if(email3 != "")
			emails = emails + email3+",";				
		if(email4 != "")
			emails = emails + email4+",";				
		if(email5 != "")
			emails = emails + email5+",";
		emails = emails.substring(0,emails.length-1);	
	}	
		
	//Rellenamos la cadena de emails a enviar	
	document.forms.frmRecomendar.emails.value = emails;	
	if(msgError == "" && msgError1=="" && msgError2=="" && msgError3=="" && msgError4=="" && msgError5=="" && msgErrorCodigo=="")
		document.forms.frmRecomendar.submit();
}

function tratarCalendario(dia,mes,anio){
	
	if (dia<10 && dia.toString().length ==1) dia='0'+dia;
	if (mes<10 && mes.toString().length ==1) mes='0'+mes;	
	
	var valorFecha = dia+'/'+mes+'/'+anio;
	var fechaCalendario = document.getElementById('fechaCalendario');
	fechaCalendario.value = valorFecha;

	var frm 		= document.getElementById('frmCalendario');	
	var actionnuevo = frm.action;	
	actionnuevo 	= actionnuevo+"#gogo_calendario";	
	frm.action 		= actionnuevo;
	
	frm.submit();
}

function avanzarMes(dia,mes,anio){
		var fecha = new Date();
		fecha.setFullYear(anio); 
		if (mes==12){
			anio = fecha.getFullYear() + 1;
			mes = 01;
		}	
		else
			mes++;
		tratarCalendario(dia,mes,anio);
}

function retrasarMes(dia,mes,anio){
		var fecha = new Date();
		fecha.setFullYear(anio); 
		if (mes ==01){
			anio = fecha.getFullYear() - 1;
			mes = 12;
		}	
		else
			mes--;
		tratarCalendario(dia,mes,anio);
}

function retrasarMesHome(dia,mes,anio){
	var fecha = new Date();
		fecha.setFullYear(anio); 
		if (mes ==01){
			anio = fecha.getFullYear() - 1;
			mes = 12;
		}	
		else
			mes--;
		tratarCalendarioHome(dia,mes,anio);	
}

function tratarCalendarioHome(dia,mes,anio){
	
	if (dia<10 && dia.toString().length ==1) dia='0'+dia;
	if (mes<10 && mes.toString().length ==1) mes='0'+mes;	
	
	var valorFecha = dia+'/'+mes+'/'+anio;
	var fechaCalendario = document.getElementById('fechaCalendario');
	fechaCalendario.value = valorFecha;
	var frm = document.getElementById('frmCalendario');
	frm.action="index.php#CalendarioFiestas";

	frm.submit();
}

function avanzarMesHome(dia,mes,anio){
	var fecha = new Date();
	fecha.setFullYear(anio); 
	
	if (mes==12){
		anio = fecha.getFullYear() + 1;
		mes = 01;
	}	
	else
		mes++;
		
	tratarCalendarioHome(dia,mes,anio);
}

function submitirFrm(idFrm){
	var formulario = document.getElementById(idFrm);
	formulario.submit();
}

function submitirApuntate(idFrm,negocio,id_negocio,fecha){
	
	var negocioInput 		= document.getElementById('negocio');
	var id_negocio_Input 	= document.getElementById('id_negocio');
	var fecha_Input 		= document.getElementById('fecha');
	
	negocioInput.value = negocio;
	id_negocio_Input.value = id_negocio;
	fecha_Input.value = fecha;
	
	submitirFrm(idFrm);
}

function abrirReproductor(){	
	 
	var reproductor = window.open('http://www.discotecasgratis.com/musica','reproductor','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=250,height=130,left=0,top=0'); 
} 

function nuevoAjax()
{ 
	/* Crea el objeto AJAX. Esta funcion es generica para cualquier utilidad de este tipo, por
	lo que se puede copiar tal como esta aqui */
	var xmlhttp=false;
	try
	{
		// Creacion del objeto AJAX para navegadores no IE
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			// Creacion del objet AJAX para IE
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(E)
		{
			if (!xmlhttp && typeof XMLHttpRequest!='undefined') xmlhttp=new XMLHttpRequest();
		}
	}
	return xmlhttp; 
}


function validarfecha(){
	
	var fecha			= document.getElementById('fecha_lista').value;
	var fechahoy		= document.getElementById('fechahoy').value;
	
	var fechaSplit 		= fecha.split("/");
	var fechahoySplit	= fechahoy.split("/");
			
	dateSeleccionada 	= new Date(fechaSplit[2],fechaSplit[1],fechaSplit[0]);
	dateHoy				= new Date(fechahoySplit[2],fechahoySplit[1],fechahoySplit[0]);
	
	var secondsSeleccionada = dateSeleccionada.getTime();
	var secondsHoy			= dateHoy.getTime();
	
	/*
	document.getElementById('milisegndusoHOY').value = secondsHoy;
	document.getElementById('milisegndusoSeleccionado').value = secondsSeleccionada;
	document.getElementById('resultadoMislisegundos').value = secondsHoy-secondsSeleccionada;
		*/
	var error = 0;
	
	if( secondsSeleccionada > secondsHoy)
		error = 1;
		
	return error;
}

function cargarlista(idSelectOrigen){
	
	// Obtengo el select que el usuario modifico
	var selectOrigen = document.getElementById(idSelectOrigen);
	
//	var error = validarfecha();
	
//	if(error == 0){//si devuelve 1 es que la fecha seleccionada es inferior a la fecha actual	
		// Obtengo la opcion que el usuario selecciono
		var opcionSeleccionada=selectOrigen.options[selectOrigen.selectedIndex].value;
		
		var estadocombo = document.getElementById('estadocombo').value;
			
		if(opcionSeleccionada == 0 && estadocombo == 0)
			cargarnegocios(idSelectOrigen);
//	}
//	else
//		alert(errorFechaPasada);		
}

function cargarlista2(idSelectOrigen, idLocalidad){
	// Obtengo el select que el usuario modifico
	var selectOrigen = document.getElementById(idSelectOrigen);
	//alert(selectOrigen);
	var opcionSeleccionada = -1;
	var estadocombo = -1;
	if(selectOrigen != null)
	{
		opcionSeleccionada = selectOrigen.options[selectOrigen.selectedIndex].value;	
		estadocombo = document.getElementById('estadocombo').value;
	}
	
	if(opcionSeleccionada == 0 && estadocombo == 0)
		cargarnegocios2(idSelectOrigen, idLocalidad);
}

//Cargamos las caracteristicas del negocio seleccionado
function cargaCaracteristicas(idSelectOrigen)
{
	var fecha = document.getElementById('fecha_lista').value;
	// Obtengo el select que el usuario modifico
	var selectOrigen=document.getElementById(idSelectOrigen);
		
	// Obtengo la opcion que el usuario selecciono
	var opcionSeleccionada=selectOrigen.options[selectOrigen.selectedIndex].value;
	
	var tam = selectOrigen.length;	
	var posselec;
	
	for(i=0;i<tam;i++){	  
		
		if(selectOrigen.options[i].value == opcionSeleccionada )
			posselec = i;//no squedamos con la posición del option seleccionado para luego dejarlo seleccionado
				
	}
				
	// Si el usuario eligio la opcion "Elige", no voy al servidor y pongo los selects siguientes en estado "Selecciona opcion..."
	if(opcionSeleccionada!=0)
	{
		// Creo el nuevo objeto AJAX y envio al servidor el ID del select a cargar y la opcion seleccionada del select origen
		var ajax=nuevoAjax();			
		
		//ajax.open("GET", "http://localhost/discotecasgratis-nueva/comun/select_discoteca_proceso.php?opcion="+opcionSeleccionada, true);
		// ajax.open("GET", "http://www.discotecasgratis.com/comun/select_discoteca_proceso.php?opcion="+opcionSeleccionada, true);
		ajax.open("GET", "/comun/select_discoteca_proceso.php?opcion="+opcionSeleccionada, true);
		
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==1)
			{			
				
				selectOrigen.options[0].selected = true; 
				selectOrigen.disabled=true;
				selectOrigen.options[0].text = "Cargando..."; //lo dejamos con el texto cargando mientras
				
			}
			if (ajax.readyState==4)
			{
				var resultadoajax 	= ajax.responseText;				
				var variables 		= resultadoajax.split("@");				
								
				document.getElementById("horario").value 					= variables[0];
				document.getElementById("entrada").value 					= variables[1];				
				document.getElementById("vestimenta").value 				= cambiarnumeroacento(variables[2]);		    		
				document.getElementById("lista").value 						= cambiarnumeroacento(variables[3]);
				document.getElementById("condiciones_lista_email").value 	= cambiarnumeroacento(variables[4]);
				document.getElementById("nombre_rrpp").value 				= cambiarnumeroacento(variables[5]);
				document.getElementById("nombre_negocio").value 			= cambiarnumeroacento(variables[6]);
				document.getElementById("nombre_sesion").value 				= cambiarnumeroacento(variables[7]);
				
				//dejamos seleccionada la discoteca que teniamos antes
								
				selectOrigen.disabled=false;
				selectOrigen.options[0].text = "Elige discoteca"; 		 //dejamos el texto inicial		
				selectOrigen.options[posselec].selected = true; 			
			} 
		}
		ajax.send(null);
	}
	else
	{
		document.getElementById("horario").value 					= "";
		document.getElementById("entrada").value 					= "";				
		document.getElementById("vestimenta").value 				= "";		    		
		document.getElementById("lista").value 						= "";
		document.getElementById("condiciones_lista_email").value 	= "";
		document.getElementById("nombre_rrpp").value 				= "";
		document.getElementById("nombre_negocio").value 			= "";
		document.getElementById("nombre_sesion").value 				= "";
		
		selectOrigen.disabled=false;
		selectOrigen.options[0].text = "Elige discoteca"; 		 //dejamos el texto inicial		
		selectOrigen.options[posselec].selected = true; 
	}
}

//Cambiamos el número por el tipo de caracter
function cambiarnumeroacento(texto){

	texto = texto.replace(/690/g,"ñ");
	texto = texto.replace(/691/g,"á");
	texto = texto.replace(/692/g,"é");
	texto = texto.replace(/693/g,"í");
	texto = texto.replace(/694/g,"ó");
	texto = texto.replace(/695/g,"ú");			
	texto = texto.replace(/696/g,"Á");
	texto = texto.replace(/697/g,"É");			
	texto = texto.replace(/698/g,"Í");
	texto = texto.replace(/699/g,"Ó");
	texto = texto.replace(/6910/g,"Ú");
	texto = texto.replace(/6911/g,"Ñ");
	texto = texto.replace(/6912/g,"€");
	texto = texto.replace(/6913/g,"-");
	
	return texto;
}

//cargamos el listado de negocios según la fecha seleccionada mostrando solo el día de la semana
function cargarnegocios(idSelectOrigen){		
	
	// Obtengo el select que el usuario modifico
	var diasemana			= document.getElementById('diasemana').value;			
	var selectOrigen		= document.getElementById(idSelectOrigen);
	var opcionSeleccionada 	= selectOrigen.options[selectOrigen.selectedIndex].value;
	
	if(diasemana == '')
		alert(errorFechaApuntateER);
	else
	{
		var ajax = nuevoAjax();				
			
		//ajax.open("GET", "http://localhost/discotecasgratis-nueva/comun/select_negocios.php?diasemana="+diasemana, true);
		ajax.open("GET", "http://www.discotecasgratis.com/comun/select_negocios.php?diasemana="+diasemana, true);
		
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==1)
			{
				// Mientras carga elimino la opcion "Selecciona Opcion..." y pongo una que dice "Cargando..."				
				
				selectOrigen.options[0].selected = true; 
				selectOrigen.disabled=true;
				selectOrigen.options[0].text = "Cargando..."; //lo dejamos con el texto cargando mientras
			}
			if (ajax.readyState==4)
			{
				selectOrigen.parentNode.innerHTML=ajax.responseText;
			} 
		}
		ajax.send(null);
	}		
	document.getElementById('estadocombo').value = "1";
}

function cargarnegocios2(idSelectOrigen, idLocalidad){		
	// Obtengo el select que el usuario modifico
	var diasemana			= document.getElementById('diasemana').value;			
	var selectOrigen		= document.getElementById(idSelectOrigen);
	var opcionSeleccionada 	= selectOrigen.options[selectOrigen.selectedIndex].value;
	
	if(diasemana == ''){
		alert(errorFechaApuntateER);
	} else {
		var ajax = nuevoAjax();
		
		ajax.onreadystatechange = function(){ 
			if (ajax.readyState == 4) 
			{
				if(selectOrigen != null)
				{
					// alert('substituyendo: ' + '>'+ajax.responseText+'<'+ajax.status);
					selectOrigen.parentNode.innerHTML=ajax.responseText;
				}
			} 
			else 
			{
				if(selectOrigen != null)
				{
					// Mientras carga elimino la opcion "Selecciona Opcion..." y pongo una que dice "Cargando..."				
				
					selectOrigen.options[0].selected = true; 
					selectOrigen.disabled=true;
					selectOrigen.options[0].text = "Cargando..."; //lo dejamos con el texto cargando mientras
				}
			}
		}
		ajax.open('GET', '/comun/select_negocios.php?diasemana='+diasemana+'&idLocalidad='+idLocalidad, true);
		ajax.send(null);
	}
	
	document.getElementById('estadocombo').value = "1";
	/*
	var tam = selectOrigen.length;	
	var posselec;
	var fecha = document.getElementById('fecha_lista').value;
	if(fecha == '')
	{
		opcionSeleccionada = 0;
		for(i=tam;i>0;i--){  		  
			selectOrigen.remove(i);					
		}
	}
	else
	{
		for(i=0;i<tam;i++){  		  
			if(selectOrigen.options[i].value == opcionSeleccionada )
				posselec = i;//no squedamos con la posición del option seleccionado para luego dejarlo seleccionado	
		}
	}
	*/
}

function submitirAgenda(frm,fecha){
	document.getElementById('fechaAgenda').value= fecha;
	submitirFrm(frm);
}

function submitirNegocioAgenda (frm,negocio,fecha){
	document.getElementById('fecha').value= fecha;
	document.getElementById('negocio').value= negocio;
	submitirFrm(frm);
}

//Validar patron email
function validaPatron(email){

	var patron   = /[\w-\.]{3,}@([\w-]{2,}\.)*([\w-]{2,}\.)[\w-]{2,4}/;		
	
	if(!patron.test(email))
		return false;
			
	return true;
}
