﻿// set initial active tab
var activeTab = 1;

function openTab(tabId) {
	setCookie(getCookieName(), tabId, 1);
	// reset old tab and content
	document.getElementById("tabLink"+activeTab).className = "tabLink";
	document.getElementById("tabContent"+activeTab).className = "tabContent";
	// set new tab and content
	document.getElementById("tabLink"+tabId).className = "tabLinkActive";
	document.getElementById("tabContent"+tabId).className = "tabContentActive";
	activeTab = tabId;
}
// added by CAI; select tab at page load
_spBodyOnLoadFunctionNames.push("getQuerystring('tab')");

function getQuerystring(TabKey)
{ 
	TabKey = TabKey.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regex = new RegExp("[\\?&]"+TabKey+"=([^&#]*)");
	var qs = regex.exec(window.location.href);
	if ((qs == null) || (qs[1].toString().search(/^[0-9]+$/) !=0))
	    return false;
	else
	    openTab(qs[1]);
} 

function setCookie(name,value,minutes) {
	if (minutes) {
		var date = new Date();
		date.setTime(date.getTime()+(minutes*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name + "=" + escape(value) + expires + ";";
}

function getCookie(name) {
	var results = document.cookie.match(name + '=(.*?)(;|$)');
	if(results) {
		return(unescape(results[1]));
	}
	else {
		return null;
	}
}

function getCookieName()
{
	return 'cookActiveTab' + location.href.replace(/[^a-zA-Z 0-9]+/g,'');
}