function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
			
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
  if (document.getElementById("sm_font"))	document.getElementById("sm_font").className="";
	if (document.getElementById("medium_font")) document.getElementById("medium_font").className="";
	if (document.getElementById("large_font")) document.getElementById("large_font").className="";
	if (document.getElementById(title)) document.getElementById(title).className="active";
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

function initGetStyle() {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  //var title = "medium_font";
  setActiveStyleSheet(title);
  chkSourceIE();
}

function chkSourceIE() {

    var page = window.location.href;
    if (page.indexOf("index.aspx") != -1 && window.location.search.length > 1) {
        var urlParameters = window.location.search.substring(1);
        var parameterPair = urlParameters.split('&');
        var pos = parameterPair[0].indexOf('=');
        var argName = parameterPair[0].substring(0, pos);
        var argVal = parameterPair[0].substring(pos + 1);
        if (argName == 'src') {
            lnk = document.getElementById("lnkemail");
            lnk.click();
        }
    }
}

function chkSource() {

    if ((navigator.userAgent.toLowerCase().indexOf('msie') + 1)) {
        return;
    }
    
    var page = window.location.href;
    if (page.indexOf("index.aspx") != -1 && window.location.search.length > 1) {
        var urlParameters = window.location.search.substring(1);
        var parameterPair = urlParameters.split('&');
        var pos = parameterPair[0].indexOf('=');
        var argName = parameterPair[0].substring(0, pos);
        var argVal = parameterPair[0].substring(pos + 1);
        if (argName == 'src') {
            lnk = document.getElementById("lnkemail");
            if (!window.attachEvent) {
                var evt = document.createEvent("MouseEvents");
                evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
                c = lnk.dispatchEvent(evt);
            }
            else {
                lnk.click();
            }
        }

    }
}

function setStyleCookie() {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

function SetImage(smallImg, middleImg, largeImg)
{
    
    var cookie = readCookie("style");
    var title = cookie ? cookie : getPreferredStyleSheet();
    if(title == "sm_font")
    {
        setLeftSideImage(smallImg);
    }
    else if(title == "medium_font")
    {
        setLeftSideImage(middleImg);
    }
    else
    {
        setLeftSideImage(largeImg);
    }
}

addLoadListener(initGetStyle);
addUnloadListener(setStyleCookie);

function addLoadListener(fn) {
	if (typeof window.addEventListener != 'undefined') {
		window.addEventListener('load', fn, false);
	} else if (typeof document.addEventListener != 'undefined') {
		document.addEventListener('load', fn, false);
	} else if (typeof window.attachEvent != 'undefined') {
		window.attachEvent('onload', fn);
	} else {
		var oldfn = window.onload;
		if (typeof window.onload != 'function') {
			window.onload = fn;
		} else {
			window.onload = function() {
				oldfn();
				fn();
			};
		}
	}
}

function addUnloadListener(fn) {
	if (typeof window.addEventListener != 'undefined') {
		window.addEventListener('unload', fn, false);
	} else if (typeof document.addEventListener != 'undefined') {
		document.addEventListener('unload', fn, false);
	} else if (typeof window.attachEvent != 'undefined') {
		window.attachEvent('onunload', fn);
	} else {
		var oldfn = window.onunload;
		if (typeof window.onunload != 'function') {
			window.onunload = fn;
		} else {
			window.onunload = function() {
				oldfn();
				fn();
			};
		}
	}
}

function setLeftSideImage(image) {
	image = '../images/'+image+'.gif';
	var img = document.getElementById('greyLeftLine');
	img.src = image;
}

function InvokeFloodlightTagOnClick(category) {
    var newimage = document.createElement('script');
    var axel = Math.random() + "";
    var a = axel * 10000000000000;
    var source = "http://fls.doubleclick.net/activityj;src=2381106;type=facec938;cat=" + category + ";ord=" + a + "?"
    newimage.setAttribute("src", source);
}