
// set all tracking cookies
function SetAll()
{
	SetClickTracksCookie();
	StoreVar('source');
	StoreVar('id');
	StoreReferrer('referrer');
}

// this creates a unique value for sourceid - if it does not exist
function SetClickTracksCookie()
{
	var thisCookie = GetCookie("sourceid");
	if( thisCookie != null) {
		SetCookie("sourceid", thisCookie, 1);
		return;
	}

	//create a unique random cookie value
	var myValue = new Date();
	var randNum = rand(1000);
	var tracker = myValue.getTime() + "_" + randNum;

	SetCookie("sourceid", tracker, 365 * 5);
}

// this looks for the name in the url and if it's there, stores it - only if not already a cookie
function StoreVar(name)
{

	var thisCookie = GetCookie(name);
	if( thisCookie != null) {
		SetCookie( name, thisCookie, 365 * 5 );
		return;
	}

	var query = this.location.search.substring(1);
	if( query.length > 0 ) {
		var params = query.split( "&" );
		for( var i = 0; i < params.length; i++ ) {
			var assignIndex = params[i].indexOf( "=" );
			if( name == params[i].substring(0, assignIndex) ) {
				var val = params[i].substring( assignIndex + 1 );
				SetCookie( name, val, 365 * 5 );
				return;
			}
		}
	}
}

// this looks for the referer and if it's there, stores it - only if not already a cookie
function StoreReferrer(name)
{

	var thisCookie = GetCookie(name);
	if( thisCookie != null) {
		SetCookie( name, thisCookie, 365 * 5 );
		return;
	}

	var val = document.referrer;
	if ((val == null) || (val.length == 0))
		return;

	var index = val.indexOf('//');
	if (index != -1)
		val = val.substring(index+2);
	index = val.indexOf('/');
	if (index != -1)
		val = val.substring(0, index);

	SetCookie( name, val, 365 * 5 );
}

// return a random number
function rand(number) {
	return Math.ceil(Math.random()*number);
}

// store info on cookie.
function SetCookie(name, value, days) {

	var expire = new Date ();
	expire.setTime (expire.getTime() + (24 * 60 * 60 * 1000) * days);
	document.cookie = name + "=" + escape(value) + "; path=/;domain=." + GetBaseDomain() + ";expires=" + expire.toGMTString() + ";";
}

// retrieve info on cookie.
function GetCookie(name) {

	var cookies = document.cookie;
	var startIndex = 0;

	while(cookies.length > 0) {

		startIndex = cookies.indexOf(name + "=");
		if (startIndex == -1)
			return null;

		if (startIndex == 0)
			break;
		if ((cookies.charAt(startIndex-1) == ' ') || (cookies.charAt(startIndex-1) == ';'))
			break;
		cookies = cookies.substring(startIndex + name.length + 1);
	}
	if (cookies.length == 0)
		return null;

	var endIndex = cookies.indexOf(";", startIndex);
	if (endIndex == -1)
		endIndex = cookies.length;
	return unescape(cookies.substring(startIndex+name.length+1, endIndex));
}

function GetBaseDomain()
{

	var parts = document.domain.split(".");
	if (parts.length < 2)
		return document.domain;

	return parts[parts.length-2] + "." + parts[parts.length-1];
}


/***********************************************
* DD Tab Menu II script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

//Set tab to intially be selected when page loads:
//[which tab (1=first tab), ID of tab content to display]:
var initialtab=[1, "sc1"]

//Turn menu into single level image tabs (completely hides 2nd level)?
var turntosingle=0 //0 for no (default), 1 for yes

//Disable hyperlinks in 1st level tab images?
var disabletablinks=0 //0 for no (default), 1 for yes


////////Stop editting////////////////

var previoustab=""

if (turntosingle==1)
	document.write('<style type="text/css">\n#tabcontentcontainer{display: none;}\n</style>')

function expandcontent(cid, aobject) {

	if (disabletablinks==1)
		aobject.onclick=new Function("return false")

	if (document.getElementById && turntosingle==0){
		highlighttab(aobject)
		if (previoustab!="")
			document.getElementById(previoustab).style.display="none"
		document.getElementById(cid).style.display="block"
		previoustab=cid
	}
}

function clearcontent(aobject) {

	if (disabletablinks==1)
		aobject.onclick=new Function("return false")

	if (document.getElementById && turntosingle==0) {
		highlighttab(aobject)
		if (previoustab!="")
			document.getElementById(previoustab).style.display="none"
		previoustab=""
	}
}


function highlighttab(aobject) {

	if (typeof tabobjlinks=="undefined")
		collectddimagetabs()
	for (i=0; i<tabobjlinks.length; i++)
		tabobjlinks[i].className=""
	aobject.className="current"
}

function collectddimagetabs() {

	var tabobj=document.getElementById("ddimagetabs")
	tabobjlinks=tabobj.getElementsByTagName("A")
}

function do_onload() {

	collectddimagetabs()
	expandcontent(initialtab[1], tabobjlinks[initialtab[0]-1])
}

// call this from html!
function setuptabs(num, id) {

	initialtab=[num, id]

	if (window.addEventListener)
		window.addEventListener("load", do_onload, false)
	else if (window.attachEvent)
		window.attachEvent("onload", do_onload)
	else if (document.getElementById)
		window.onload=do_onload
}

