// JavaScript Document

$(function () {
			
/*Menu inicio*/	
	
  // IE6 doesn't handle the fade effect very well - so we'll stick with
  // the default non JavaScript version if that is the user's browser.
  if ($.browser.msie && $.browser.version < 7) return;
  
  $('#menu li')
  
    // remove the 'highlight' class from the li therefore stripping 
    // the :hover rule
    .removeClass('highlight')
    
    // within the context of the li element, find the a elements
    .find('a')
    
    // create our new span.hover and loop through anchor:
    .append('<span class="hover" />').each(function () {
      
      // cache a copy of the span, at the same time changing the opacity
      // to zero in preparation of the page being loaded
      var $span = $('> span.hover', this).css('opacity', 0);
      
      // when the user hovers in and out of the anchor
      $(this).hover(function () {
        // on hover
        
        // stop any animations currently running, and fade to opacity: 1
        $span.stop().fadeTo(1000, 1);
      }, function () {
        // off hover
        
        // again, stop any animations currently running, and fade out
        $span.stop().fadeTo(3000, 0);
      });
    });
	
	
/*Menu Fin*/	
/*overlays*/
$("a[rel]").overlay();

/*Tabs del formulari
// get container for the wizard and initialize its exposing 
    var wizard = $("#wizard").expose({color: '#000', lazy: true}); 
 
    // enable exposing on the wizard 
    wizard.click(function() { 
        $(this).expose().load(); 
    });*/
// enable tabs that are contained within the wizard 
    $("ul.tabs").tabs("div.panes > div",{effect: 'fade'});
	
/*Coses del formulari....UI, sliders... ajax en general...*/
$("#progre1").progressbar({
			value: 0
		});
$("#progre2").progressbar({
			value: 36
		});
$("#progre3").progressbar({
			value: 84
		});
$("#progre4").progressbar({
			value: 100
		});

$("div.barrajx").hide();
$("div.carga").hide();
/*ara les sliders*/
			var abc1 = $('select#vegetariano').selectToUISlider({ tooltip: true }).hide();
			var abc2 = $('select#coche').selectToUISlider({ labels: 5 }).hide();
			var abc3 = $('select#pnj').selectToUISlider({ labels: 5 }).hide();
			var abc4 = $('select#pjd').selectToUISlider({ labels: 5 }).hide();
			var abc5 = $('select#diff').selectToUISlider({ labels: 5 }).hide();
			var abc6 = $('select#atrezzo').selectToUISlider({ labels: 5 }).hide();
			var abc7 = $('select#uniforme').selectToUISlider({ labels: 5 }).hide();
			var abc8 = $('select#nerfsoft').selectToUISlider({ labels: 5 }).hide();
			var abc9 = $('select#estilo1').selectToUISlider({ labels: 5 }).hide();
			var abc10 = $('select#estilo2').selectToUISlider({ labels: 5 }).hide();
			var abc11 = $('select#estilo3').selectToUISlider({ labels: 5 }).hide();
			var abc12 = $('select#adversas').selectToUISlider({ labels: 5 }).hide();
			var abc13 = $('select#amor').selectToUISlider({ labels: 5 }).hide();
			var abc14 = $('select#miedo').selectToUISlider({ labels: 5 }).hide();
			var abc15 = $('select#solitario').selectToUISlider({ labels: 5 }).hide();
			var abc16 = $('select#leal').selectToUISlider({ labels: 5 }).hide();
			var abc17 = $('select#foro').selectToUISlider({ labels: 5 }).hide();
			var abc18 = $('select#conocimientos').selectToUISlider({ labels: 5 }).hide();
			var abc19 = $('select#tipo').selectToUISlider({ labels: 5 }).hide();
			
/*Programacion para enviar el formulario via ajax*/

 $("#sendForm").click(function() {
							   
  		var nom = $("input#nom").val();
  		var cognom = $("input#cognom").val();
  		var edat = $("input#edat").val();
  		var mail = $("input#mail").val();
  		var tel = $("input#tel").val();
  		var vegetariano = $("select#vegetariano").val();
  		var alergias = $("textarea#alergias").val();
  		var coche = $("select#coche").val();
  		var pnj = $("select#pnj").val();
  		
  		var pjd = $("select#pjd").val();
  		var diff = $("select#diff").val();
  		var atrezzo = $("select#atrezzo").val();
  		var uniforme = $("select#uniforme").val();
  		var nerfsoft = $("select#nerfsoft").val();
  		var estilo1 = $("select#estilo1").val();
  		var estilo2 = $("select#estilo2").val();
  		var estilo3 = $("select#estilo3").val();
  		var adversas = $("select#adversas").val();
  		var amor = $("select#amor").val();
  		var miedo = $("select#miedo").val();
  		var solitario = $("select#solitario").val();
  		var foro = $("select#foro").val();
  		var conocimientos = $("select#conocimientos").val();
  		var tipo = $("select#tipo").val();
  		var leal = $("select#leal").val();
  		var personas = $("textarea#personas").val();
  		var comentarios = $("textarea#comentarios").val();
  		//Validamos el nombre i apellido
  		  	if (nom == "") {
  				alert ("Has dejado el nombre sin rellenar.");
				return false;
      		}
  		  	if (cognom == "") {
  				alert ("Has dejado el apellido sin rellenar.");
			return false;
      		}
      //Validamos el mail
  		if (mail == "") {
  			alert ("No has introducido el Mail");
      		return false;
      	}else{
      		if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(mail))){
  				alert ('El mail "'+ mail + '" no es valido.');
     			return false;
      		}
      	}
	
  		//Despues de cargar los datos los metemos en una string que enviaremos al se–or php
  		var dataString = 'nom='+ nom + '&cognom=' + cognom + '&edat=' + edat + '&mail=' + mail+ '&tel=' + tel+ '&vegetariano=' + vegetariano+ '&alergias=' + alergias+ '&coche=' + coche + '&pnj=' + pnj + '&pjd=' + pjd + '&diff=' + diff + '&atrezzo=' + atrezzo + '&uniforme=' + uniforme + '&nerfsoft=' + nerfsoft + '&estilo1=' + estilo1 + '&estilo2=' + estilo2 + '&estilo3=' + estilo3+ '&adversas=' + adversas + '&amor=' + amor + '&miedo=' + miedo + '&solitario=' + solitario + '&foro=' + foro + '&conocimientos=' + conocimientos + '&tipo=' + tipo +'&leal=' + leal + '&personas=' + personas + '&comentarios=' + comentarios;
  	//	alert (dataString);
		$("div.formfinal").fadeOut(500);
		$("div.carga").fadeIn(500);
  		 $.ajax({
		    type: "POST",
		    url: "../contact.php",
		    data: dataString,
		    success: function() {
		   // alert ("Formulario Enviado...");
		$("div.carga").fadeOut(500);
		$("div.barrajx").fadeIn(500);
			//location.href="http://tren.phase-zero.com/inscripcion.html";
		        		}
  		});
  		return false;
  
      
   
      
    });


});