var _selected=null,
      _dominio,
      _ext=null,
      _disponible;

$(function(){
	_dominio = $('.dominio').val();
	
	$('.resultados tr').click(function(){
		if(_selected!=null){
			_selected.removeClass("selected");
			_selected.find("input").attr("checked", "");
		}
		$(this).addClass("selected");
		$(this).find("input").attr("checked", "checked");
		_selected = $(this);
		_ext = $(this).attr("id");
		_disponible = $(this).find("input").attr("rel");
	});
	
	$('#btn_ultimopaso').bind("click", paso3);
	
	//Slider
	$('.anythingSlider').anythingSlider({
		easing: "easeOutElastic",
		delay: 4000,
		animationTime: 1000,
		buildNavigation: false,
		pauseOnHover: true
	});
});

function paso2(){
	//var disponible = $('#disponible').val();
	if(_selected==null) $('#msgerror').show();
	else document.location.href="suscribirse.php?dominio="+_dominio+"&ext="+_ext+"&disp="+_disponible;
}

function paso3(){
	var nombre = $('#nombre').val();
	var email = $('#email').val();
	var from = $('#from').val();
	//var clave = $('#clave').val();
	var codigo = $('#codigo_pregunta').val();
	var respuesta = $('#respuesta').val();
	//var whregistra = $('#whregistra').val();
	
	$.ajax({
		type: "POST",
		url: "includes/check_code.php",
		data: "codigo="+codigo+"&respuesta="+respuesta,
		success: function(msg){
			if(msg=="ok"){
				if(nombre!='' && email!='' && codigo!=''){	
					//Si está todo OK, se envia el formulario :)
					$('#form_paso2').attr("action", "form.php");
					$('#form_paso2').submit();
				} else {
					$('#msgerror').show();
				}
			} else {
				//Error en la pregunta de seguridad
				$('#captchaerror').show();
			}
		}
	});
}

function checkForm(){
	var nombre = $("#nombre").val();
	var telefono = $("#telefono").val();
	var email = $("#email").val();
	var mensaje = $("#mensaje").val();
	
	if(!nombre || !telefono || !email || !mensaje){
		$("#msg").slideDown();
		return false
	}
}

function GetChar (event){
	var chCode = ('charCode' in event) ? event.charCode : event.keyCode;
	if(chCode==46){
		event.preventDefault();
		return false;
	}
}

