


function showmsg(msgTxt,ok){
	if(ok){
		$("#statusmsg").removeClass("alert-danger");
		$("#statusmsg").addClass("alert-success");
		$("#statusmsg").html("<strong>Ok!</strong> " + msgTxt);
	}
	else{
		$("#statusmsg").removeClass("alert-success");
		$("#statusmsg").addClass("alert-danger");
		var error;
		$("#statusmsg").html("<strong>Error!</strong><br>");
		for(error in msgTxt){			
			$("#statusmsg").append("<span>"+msgTxt[error]+"</span><br>");
		}
	}
	$("#statusmsg").show();
}


function onReturnCallback(response){
	if(response != ""){		
		$("div.g-recaptcha").tooltip("hide");
		$("div.g-recaptcha").tooltip("destroy");		
	}
}

function loadFragments(){
	$("#header").load("snippets/header.html",routeMenu); 
	$("#footer").load("snippets/footer.html"); 
	$(".sidebar").load("snippets/sidebar.html");
}

function routeMenu(){
	var ruta = window.location.pathname.split(".")[0];
	$("ul#menu li").removeClass("selected");
	switch(ruta){
		case "/":
			$("li#home").addClass("selected");
			break;
		case "/contacto":
			$("li#contacto").addClass("selected");
			break;
		case "/registro":
			$("li#registro").addClass("selected");
			break;
		case "/mapa":
			$("li#mapa").addClass("selected");
			break;
		case "/programa":
			$("li#programa").addClass("selected");
			break;
		default:
	}
}

$(document).ready(function(){
	var jumboHeight = $('.jumbotron').outerHeight();
	function parallax(){
	    var scrolled = $(window).scrollTop();
	    $('.bg').css('height', (jumboHeight-scrolled) + 'px');
	}

	$(window).scroll(function(e){
    	parallax();
	});
	
	
	routeMenu();
	
	
	
	$('#contactform').submit(function(event){
        var fail=false;
		$("#statusmsg").hide();
		event.preventDefault();
		if($('#g-recaptcha-response').val() == ""){			
            	$("div.g-recaptcha").tooltip({
				"title":'Marque "No soy un robot"',
				"pacement":"right",
				"trigger":"manual"
			});
			$("div.g-recaptcha").tooltip("show");
			fail=true;
        }
        if(!fail){
            var post = $.post('contact', $(this).serialize());
            post.done(function(data){
                data = $.parseJSON(data);
                if(data.success){
                    showmsg(data.message,true);
                }
                else{
                    showmsg(data.message,false);

                }
                console.log(data)

            });
            post.fail(function(error){
                console.log(error)
            });
        }
	});	
	
	
	
});
