function mostrarInfoCurso(id){
	var infos = $("#cuerpo ul").find('.infocurso');
	for(var i=0; i<infos.length; i++){
	   $('#'+infos[i].id).hide(0.2);
	 }
	$('#'+id).show(0.2);
}

function muestranumCuenta(){
	$('#label_num_cuenta').show(0.2);
	$('#num_cuenta').show(0.2);
}
function ocultanumCuenta(){
	$('#label_num_cuenta').hide(0.2);
	$('#num_cuenta').hide(0.2);
}

function muestraInputSocio(valor){
	if (valor=='-1')
	{
		document.formu_contacto.numsocio.value="";
		$('#id_numsocio').hide(0.2);
		$('#numsocio').hide(0.2);
		$('#texto_numsocio').hide(0.2);	
	}
	else
	{
		$('#id_numsocio').show(0.2);
		$('#numsocio').show(0.2);
		$('#texto_numsocio').show(0.2);	
	}
}


var http = getHTTPObject();
var nAleatorio = dameAleatorio(); 			
var emilvalido=true;
function dameAleatorio ()
{
	return Math.round(Math.random()*1000000000);
}
function comprobarEdicion()
{
	var idedicion = document.formu_contacto.idedicion.options[document.formu_contacto.idedicion.selectedIndex].value;
  if(idedicion=='')
  {
  	alert('Por favor, seleccione una edición del curso.');
  	document.formu_contacto.idedicion.focus();
  }
}
function llamadaCompruebaNoExistaMail(email,idcurso)
{
	var url = "/servlet/matriculas";
  var idedicion = document.formu_contacto.idedicion.options[document.formu_contacto.idedicion.selectedIndex].value;
  if(idedicion=='')
  	alert('Por favor, seleccione una edición del curso.');
  else
  	http.open("GET", url + "?email="+email.value+"&idcurso="+idcurso+"&idedicion="+idedicion+"&accion=compruebaemail&param=" + nAleatorio, true);
	nAleatorio = dameAleatorio();  
	http.onreadystatechange = comprobarExisteMail;
	http.send("");
}
function comprobarExisteMail()
{
	
	if (http.readyState == 4)
	{
		if (http.status == 200)
		{
			var respuesta = http.responseText;
			$('#email').removeAttr('style');
			$('#error').remove();
			if (respuesta==0)
			{		
				if (!es_email(get('email').value)) {
					$('#formu_contacto').prepend('<p class="error centrado" style="color:#FF0202" id="error">Esta direccion de email no parece válida o el campo está vacio.</p>');
					$('#email').css({ border:'1px solid #FF0202'});
					get('email').focus();
					emilvalido=false;
					return false;
				}else{
					emilvalido=true;
					return true;
				}
			}
			else
			{

				$('#formu_contacto').prepend('<p class="error centrado" style="color:#FF0202" id="error">Esta direccion de email ya está dada de alta para este curso.</p>');				
				$('#email').css({ border:'1px solid #FF0202'});
				get('email').focus();
				emilvalido=false;
				return false;
			}
		}
	}
}
function iniciaForm()
{
	
}
function llamadaMuestraCCAA(elemento)
{
	var url = "/servlet/matriculas";
    var indice = elemento.selectedIndex;
    var el = elemento.options[indice];
    http.open("GET", url + "?idpais="+elemento.options[indice].value+"&accion=dameprovincias&param=" + nAleatorio, true);
	nAleatorio = dameAleatorio();  
	http.onreadystatechange = muestraCCAA;
	http.send("");
}
function muestraCCAA()
{
	
	if (http.readyState == 4)
	{
		if (http.status == 200)
		{
			var respuesta = http.responseXML;
			var nodo = respuesta.documentElement;
			var provincia =	nodo.getElementsByTagName('provincia');
			var numProvincias = provincia.length;
			if (numProvincias>0)
			{
				var cadena='';
				for(var i=0; i<numProvincias; i++)
				{
					var idp = provincia[i].attributes[0].nodeValue;
					var nombre = provincia[i].firstChild.nodeValue;
					cadena+='<option value="'+idp+'">'+nombre+'</option>';
				}
				cadena='<option value="" selected="selected">Seleccione  una opción...</option>'+cadena+'<option value="" selected="selected">Seleccione  una opción...</option>';
				$('#provincia').empty();
				$('#provincia').prepend(cadena);
				//$('#provincia').removeAttr('disabled');
				//$('#centro').attr('disabled','true');
			}
			else
			{
				
				//$('#provincia').attr('disabled','true');
				$('#provincia').empty();
				$('#provincia').append('<option value="" selected="selected">Seleccione  una opción...</option>');
				$('#centros').empty();
				$('#centros').append('<option value="" selected="selected">Seleccione  una opción...</option>');
				get('centro').value="";
				//$('#centros').attr('disabled','true');
				//$('#centro').removeAttr('disabled');
			}
		}
	}
}
function llamadaMuestraCentros(elemento)
{
	var url = "/servlet/matriculas";
    var indice = elemento.selectedIndex;
    var el = elemento.options[indice];
    http.open("GET", url + "?idprovincia="+elemento.options[indice].value+"&accion=damehospitales&param=" + nAleatorio, true);
	nAleatorio = dameAleatorio();  
	http.onreadystatechange = muestraCentros;
	http.send("");
}
function muestraCentros()
{
	
	if (http.readyState == 4)
	{
		if (http.status == 200)
		{
			var respuesta = http.responseXML;
			var nodo = respuesta.documentElement;
			var provincia =	nodo.getElementsByTagName('hospital');
			var numProvincias = provincia.length;
			if (numProvincias>0)
			{
				var cadena='';
				for(var i=0; i<numProvincias; i++)
				{
					var id = provincia[i].attributes[0].nodeValue;
					var nombre = provincia[i].firstChild.nodeValue;
					cadena+='<option value="'+id+'">'+nombre+'</option>';
				}
				cadena='<option value="" selected="selected">Seleccione  una opción...</option>'+cadena+'<option value="Otro" onclick="$(\'#centro\').removeAttr(\'disabled\');">Otro centro...</option>';
				$('#centros').empty();
				$('#centros').prepend(cadena);
				//$('#centros').removeAttr('disabled');
				//$('#centro').attr('disabled','true');
			}
			else
			{
				$('#centros').empty();
				$('#centros').append('<option value="" selected="selected">Seleccione  una opción...</option>');
				get('centro').value="";
				//$('#centros').attr('disabled','true');
				//$('#centro').removeAttr('disabled');
			}
		}
	}
}

function elijeOtro(elemento)
{
	var indice = elemento.selectedIndex;
  var el = elemento.options[indice];
  //if (elemento.options[indice].value=="Otro") $('#centro').removeAttr('disabled');
}

function mostrarClausula ()
{
	var margen = ($('body').width()-860)/2;
	$('body').append('<div id="fondo" style="z-index:100; position:fixed; top:0; left:0; bottom:0; right:0; background-color:#356EF3;"></div>');
	$('#fondo').fadeTo('fast',0.3)
	$('#clausula').css({left:margen+'px', zIndex:'101'});
	$('#clausula').removeClass('oculto');
}

function cierraClausula ()
{
	$("#acepto").attr('checked','checked');
	$('#fondo').remove();
	$('#clausula').addClass('oculto');
}

function getHTTPObject() 
{
	var xmlhttp;
	try{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
   	}catch (e){
		try{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
		}
   }

   if (!xmlhttp && typeof XMLHttpRequest != 'undefined'){
		try{
			xmlhttp = new XMLHttpRequest();
      	} catch (e) {
			xmlhttp = false;
		}
   }
   if(!xmlhttp)
   		muestraAlerta("Error al inicializar XMLHttpRequest",tiempoAlerta1,1);

   return xmlhttp;
}

