function getHTTPObject() {
    var xmlhttp;
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        try {
	    xmlhttp = new XMLHttpRequest();
        } catch (e) {
	    xmlhttp = false;
        }
    }
    return xmlhttp;
}

function showFeedback() {
    $('#contacto').slideToggle('slow');
}
    
function feedback_submit(contacto) {
    var baseURL = "http://www5.usc.es/osl/temp/dereito/";
    var correoContacto =  "osl@usc.es";
    document.getElementById("sending").style.display = "inline";
    document.getElementById("sendbutton").style.display = "none";
        
    var http = getHTTPObject();
    http.open("POST", "http://www.usc.es/osl/ubuntu/" + "enviomail.php", true);
    http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
     
    if (contacto==0) {               
	document.getElementById("sending2").style.display = "inline";
	document.getElementById("sendbutton2").style.display = "none";
	var name = document.getElementById("name2").value;
	var mail = document.getElementById("mail2").value;
	var comentarios = document.getElementById("comentarios2").value;
	var conocementos= document.getElementById("conocementos").value; 
	var envio = "contacto=0&name=" + name + "&email=" + mail + "&comentarios=" + comentarios + "&conocementos=" + conocementos;
	http.send(envio);
    }
    else {                                                            
	document.getElementById("sending").style.display = "inline";
	document.getElementById("sendbutton").style.display = "none";
	var name = document.getElementById("nome").value;       
	var mail = document.getElementById("mail").value;
	var comentarios = document.getElementById("feedback").value;
	var envio = "contacto=1&name=" + name + "&email=" + mail + "&comentarios=" + comentarios ;
	http.send(envio);
    }; 
    http.onreadystatechange = function () {
	if (http.readyState == 4) {              
	    if (http.responseText == "1") {
		document.getElementById("aftercontacto").style.color ="#888";
		document.getElementById("afterinscricion").style.color ="#888";
		document.getElementById("aftercontacto").innerHTML = "<strong>Grazas!</strong> O teu contacto foi enviado.";
		document.getElementById("afterinscricion").innerHTML = "<strong>Grazas!</strong> A t&uacute;a subscripci&oacute;n foi enviada.";
		if (contacto ==0) {
		    document.getElementById("afterinscricion").style.display= "block";
		}else {
		    document.getElementById("aftercontacto").style.display= "block";
		};
		$('#contacto').hide('slow');
		$('#inscricion').hide('slow');
	    } else {
		if (contacto ==0 ) {
		    document.getElementById("afterinscricion").style.display= "block";
		}else {
		    document.getElementById("aftercontacto").style.display= "block";   
		};
		$('#contacto').hide('slow');
		$('#inscricion').hide('slow');
		document.getElementById("aftercontacto").innerHTML = "Ocurreu un erro &oacute; enviar o correo, tentao m&aacute;is tarde<br/> ou envia un correo a " + $correoContacto;
		document.getElementById("aftercontacto").style.color ="Red";
		document.getElementById("afterinscricion").style.color ="Red";
		document.getElementById("afterinscricion").innerHTML = "Ocurreu un erro &oacute; enviar o correo, tentao m&aacute;is tarde<br/> ou envia un correo a " + $correoContacto;
	    };

	}
    }                      
     
    document.getElementById("sending").style.display = "none";
    document.getElementById("sendbutton").style.display = "block";
    document.getElementById("sending2").style.display = "none";
    document.getElementById("sendbutton2").style.display = "block";
     
}
    
function badgeHover(text) {
    if (text == null || text == "") {
	document.getElementById("badgelabel").firstChild.data = " ";
    }
    else {
	document.getElementById("badgelabel").firstChild.data = text;                
    }
}
    
$(document).ready(function() {
        $('#badges a').click(function() {  
		if ($(this).attr("className") == "activo") { return false; };
		$('#badges a').each(function() { $(this).removeClass("activo"); });
		$(this).toggleClass("activo");
		$('#aftercontacto').hide('slow');
		$('#afterinscricion').hide('slow');
		$('#sendbutton').show('fast');
		$('#sendbutton2').show('fast');
		$('#cuerpo > div').each(function(index) {
			$(this).hide('slow'); });

		if ($(this).attr("id") == "abrir_inicio") { $('#inicio').show("slow"); };
		if ($(this).attr("id") == "abrir_ponencias") { $('#ponencias').show("slow"); };
		if ($(this).attr("id") == "abrir_onde") { $('#onde').show("slow"); };
		if ($(this).attr("id") == "abrir_contacto") { $('#contacto').show("slow"); };
		if ($(this).attr("id") == "abrir_inscricion") { $('#inscricion').show("slow"); };
		    /*

			$('#abrir_inicio').click(function() { 
				$('#inicio').show("slow");
			    }); 
			$('#abrir_ponencias').click(function() { 
				alert("Estamos entrando no bucle.");
				$('#ponencias').show('slow');
				//				$('#ponencias .dia').show('slow');
			    });
			$('#abrir_onde').click(function() {  
				$('#onde').show('slow'); 
			    });
			$('#abrir_contacto').click(function() { 
				$('#contacto').show('slow');
			    });
			$('#abrir_inscricion').click(function() {
				$('#inscricion').show('slow');
			    });   
			    }); */
	    });
	$('.dia .grupo_1').click(function() {
		$('#grupo_1 .ponencia').slideToggle("slow");
	    });
	$('.dia .grupo_2').click(function() {
		$('#grupo_2 .ponencia').slideToggle("slow");
	    });
	$('.dia .grupo_3').click(function() {
		$('#grupo_3 .ponencia').slideToggle("slow");
	    });
	$('.dia .grupo_4').click(function() {
		$('#grupo_4 .ponencia').slideToggle("slow");
	    });
	$('.dia .grupo_5').click(function() {
		$('#grupo_5 .ponencia').slideToggle("slow");
	    });
    });

