//// Stylesheet switcher ******************************************************************************
var prefsLoaded = false;
var currentFontSize = 11;
function changeTxt(sizeDifference){
	currentFontSize = parseInt(currentFontSize) + parseInt(sizeDifference);
	if(currentFontSize > 14){
		currentFontSize = 14;
	}else if(currentFontSize < 11){
			currentFontSize = 11;
	}
	setFontSize(currentFontSize);
};
function setFontSize(fontSize){
	var stObj = (document.getElementById) ? document.getElementById('container') : document.all('container');
	if (stObj)	stObj.style.fontSize = fontSize + 'px';
};
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 = "a51size" + name + "=" + value + expires + "; path=/";
};
function readCookie(name) {
  var nameEQ = "a51size" + 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 = setUIOptions;
function setUIOptions(){
	if(!prefsLoaded){
		cookie = readCookie("fontSize");
		currentFontSize = cookie ? cookie : 11;
		setFontSize(currentFontSize);
		
		prefsLoaded = true;
	}
}
window.onunload = saveSettings;
function saveSettings()
{
  createCookie("fontSize", currentFontSize, 365);
}

//// IE browser hover and focus 
function suckerfish(type, tag, parentId) {
	if (window.attachEvent) {
		window.attachEvent("onload", function() {
			var sfEls = (parentId==null)?document.getElementsByTagName(tag):document.getElementById(parentId).getElementsByTagName(tag);
			type(sfEls);
		});
	}
}
ieHover = function(sfEls) {
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" iehover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" iehover\\b"), "");
		}
	}
}
ieFocus = function(sfEls) {
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onfocus=function() {
			this.className+=" iefocus";
		}
		sfEls[i].onblur=function() {
			this.className=this.className.replace(new RegExp(" iefocus\\b"), "");
		}
	}
}

suckerfish(ieHover, "LI");
suckerfish(ieHover, "INPUT");
suckerfish(ieFocus, "INPUT");
suckerfish(ieFocus, "TEXTAREA");

//// Alternative for target="_blank" to validate the xhtml
function addEvent(obj, evType, fn) {
  if (obj.addEventListener) {
    obj.addEventListener(evType, fn, false)
  } else if (obj.attachEvent) {
    obj.attachEvent("on"+evType, fn)
  }
}
function externalLinks() {
 if (!document.getElementsByTagName) return;
 var objects = document.getElementsByTagName("a");
 for (var i=0; i<objects.length; i++) {
   var object = objects[i];
   if (object.getAttribute("href") && object.getAttribute("rel") == "external") {
     object.target = "_blank";
   }
 }
 var objects = document.getElementsByTagName("form");
 for (var i=0; i<objects.length; i++) {
   var object = objects[i];
   if (object.getAttribute("rel") == "external") {
     object.target = "_blank";
   }
 }
}
addEvent(window, "load", externalLinks);

//// Popup a window
function popup(theURL,winName,features) 
{
	var hWin = window.open(theURL,winName,features);
	if (hWin) hWin.focus();
}

//// gets image width
function getSrcWidth(imgwidth) {
    sw = screen.width;
	if(sw<imgwidth) return sw-50; else return imgwidth;
}

//// gets img height
function getSrcHeight(imgheight) {
    sh = screen.height;
    if(sh<imgheight) return sh-100; else return imgheight;
}

//// Userscore rollover
function doUserScoreHover(index) 
{
	var userScoreObject = document.getElementById("userscoreimage");
	userScoreObject.className = "hover" + index;
}

//// Perform vote on cms item
function doUserScorePost(index) 
{
	var f = document.getElementById("formPageItemVoting");
	f.cmd.value = 'addvote';
	f._vote_amount.value = index;
	f.submit();
}

/*function doUserScorePost(index, type, id, item) 
{
	// determine language
	var lang = document.location.pathname.substring(0,4);

	// do vote through php script
	var img = new Image();
	img.src = lang + "_common/voting/vote.php?type=" + type + "&vote=" + vote + "&id=" + id + "&item=" + item + "&x=" + new String (Math.random());
}*/


//// Loads print dialog for page
function showPrint()
{
	if (window.print != null) { 
		window.print();
	}
}

//// Common popup code
var newWindow = null;
function popUpWin(url, type, strWidth, strHeight){
	var tools="";
	if (type == "withscroll") tools = "resizable,scrollbars=yes,width="+strWidth+",height="+strHeight;
	if (type == "noscroll") tools = "resizable,scrollbars=no,width="+strWidth+",height="+strHeight;
	newWindow = window.open(url, 'newWin', tools);
	newWindow.focus();
}

//// Popup FAQ item
function popUpFAQ(url)
{
	popUpWin(url, "withscroll", 480, 300);
}

function popupDnld(url)
{
	popUpWin(url, "withscroll", 480, 300);
}

//// DoubleClick partner ads variable
var adid = "";