/* Style Switcher by Paul Sowden, see A List Apart: http://www.alistapart.com/articles/alternate/ */

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;
    }
  }
}

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;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
  $('.textsize').css("visibility","visible");
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);


/* Tell A Friend */
function urlencode( str ) {
    var ret = str;
    ret = ret.toString();
    ret = encodeURIComponent(ret);
    ret = ret.replace(/%20/g, '+');
    return ret;
}

var oEcardURLSet= {
    init:function() {
        var sLoc = window.location;
        var sTAF = $($("#utilities").find("a")[2]).attr("href");
        //$($("#utilities").find("a")[2]).bind('click', function() {createCookie('referurl',urlencode(sLoc))});
        $($("#utilities").find("a")[2]).bind('click', function() {createCookie('referurl',sLoc)});
    }
}


/*******************
 WINDOW METHODS
*******************/

function popitup(url){
	newwindow=window.open(url,'name','height=467,width=694');
	if (window.focus) {newwindow.focus()}
	return false;
}

function audioPlayerPopUp(url,version){
	newwindow=window.open(url,'name','height=90,width=340');
	if (window.focus) {newwindow.focus()}
	return false;
}

function openWin(url){
	newwindow=window.open(url,'_blank','channelmode=no,directories=yes,fullscreen=no,location=yes,menubar=yes,resizable=yes,scrollbars=yes,status=yes,titlebar=yes,toolbar=yes','');
	if (window.focus) {newwindow.focus()}
	return false;
}

function loadPage(url,name){
	window.open(url,name,'');
	return false;
}

function loadPagePDF(url,name,tag){

	var axel = Math.random()+"";
	var a = axel * 10000000000000;
	var t = document.createElement('iframe');
	var c = document.getElementsByTagName('body')[0];
	c.appendChild(t);
	t.setAttribute('width',1)
	t.setAttribute('height',1)
	t.setAttribute('src','http://fls.doubleclick.net/activityi;src=1044142;type='+ tag +';cat=test;ord='+a+'?');
	window.open(url,name,'');
	return false;
}

function previewPage(url,name){
	var pWindow = window.open(url,name,'location=no,menubar=no,scrollbars=yes');
    pWindow.focus();
	return false;
}

$(document).ready(function() {
    oEcardURLSet.init();
});

