$(document).ready(function() {
    
    var urlParams = {};
    (function () {
        var e,
            a = /\+/g,  // Regex for replacing addition symbol with a space
            r = /([^&;=]+)=?([^&;]*)/g,
            d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
            q = window.location.search.substring(1);

        while (e = r.exec(q))
        urlParams[d(e[1])] = d(e[2]);
    })();
    
    var queryTab = urlParams["tab"];

	//When page loads...
	$(".tab-content").hide(); //Hide all content
    if (isNaN(queryTab))
    {
        $("ul.tabs li:first").addClass("active").show(); //Activate first tab
        $(".tab-content:first").show(); //Show first tab content
    } else {       
        var n = parseInt(queryTab)+1;
        $("ul.tabs li:nth-child("+n+")").addClass("active").show(); //Activate tab named in query string
        $(".tab"+queryTab).show(); //Show content of named tab
    }	
	

	//On Click Event
	$("ul.tabs li").click(function() {

		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab-content").hide(); //Hide all tab content

		//var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		//$("."+activeTab).fadeIn(); //Fade in the active ID content
        $(".tab"+$(this).index()).fadeIn(); //Fade in the active ID content
		return false;
	});
});

function getParameterByName( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return decodeURIComponent(results[1].replace(/\+/g, " "));
}

