/* =============================================================================
 Simple Javascript Utils
 ------------------------------------------------------------------------------
 Version: 1.2
 Date: 06/17/2008
 Description: A simple utility wrapper library for commonly used functionality
 Dependencies:
	/scripts/js/fwx/prototype.js [v1.5.1] or
	/scripts/js/fwx/mootools.js [v1.2]
	
 Child Dependencies:
 	none
============================================================================== */
function writeYear() {
	var d = new Date()
	document.write(d.getFullYear());
}
function writeFullDate() {
	var d = new Date()
	var mos = ["January","February","March","April","May","June","July","August","September","October","November","December"];
	var mo = mos[d.getMonth()];
	document.write(mo+" "+d.getDate()+", "+d.getFullYear());
}
/* ------------------------------------------------------------------------------ */
/*  Simple Popup Windows
/* ------------------------------------------------------------------------------ */
var PoppedWindows = [];
var popWin = function (url, w, h, centered, chrome, extras){
	w = w != undefined ? w : 640;
	h = h != undefined ? h : 480;
	centered = centered != undefined ? centered : true;
	chrome = chrome != undefined ? chrome : true;
	extras = extras != undefined ? extras : false;
	var x = (screen.width-w)/2;
	var y = (screen.height-h)/2;
	var yno = chrome ? "yes" : "no";
	var eyno = extras ? "yes" : "no";
	var str = [
		"width="+w,
		"height="+h,
		"scrollbars="+yno,
		"resizable="+yno,
		"directories="+eyno,
		"status="+eyno,
		"menubar="+eyno
	];
	var win = window.open(url,"PopWindow"+PoppedWindows.length, str.join(","))
	PoppedWindows.push(win);
	if(centered){ win.moveTo(x,y); }
	win.focus();
};
var closeAllPops = function(){
	for(var i=0; i<PoppedWindows.length; i++){
		var w = PoppedWindows[i];
		if (w != undefined){w.close();}
	}
	PoppedWindows = [];
}
/* ------------------------------------------------------------------------------ */
/*  Simple String Tools
/* ------------------------------------------------------------------------------ */
function trim(input){
	var inputCopy = String(input);
	var outputCopy = "";
	for(var i=0;i<inputCopy.length;i++){
		if(inputCopy.charCodeAt(i) != 32){
			outputCopy = String(input);
			break;
		}
	}
	return outputCopy;
}
function quicktrim(input){
	return String(input).split(" ").join("");
}
/* ------------------------------------------------------------------------------ */
/*  Simple Element Visibility (requires prototype or mootools)
/* ------------------------------------------------------------------------------ */
var toggleShowHideElement = function(e){
	var el = $(e);
	if(el.style.display == "none"){
		el.show();
	}else{
		el.hide();
	}
};
var getElementState = function(elemID){
	var elemState, myElem = $(elemID);
	//
	if(myElem){
		if((!myElem.style.visibility || myElem.style.visibility == 'visible') && (!myElem.style.display || myElem.style.display == 'block')) {
			elemState = "show";
		} else {
			elemState = "hide";
		}
	}
	//
	return elemState;
}
function setElementState(e, s){
	if (e != ""){
		var el = $(e);
		if(typeof el != "undefined"){
			switch(s){
				case "show":
					el.show();
					break;
				case "hide":
					el.hide();
					break;
				case true:
					el.show();
					break;
				case false:
					el.hide();
					break;
				default:
					break;
			}
		}
	}
}
/* ------------------------------------------------------------------------------ */
/*  Active Stylesheet Swap
/* ------------------------------------------------------------------------------ */
function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = $ES("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 = $ES("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 = $ES("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;
}
/* ------------------------------------------------------------------------------ */
/*  Palette Swap
/* ------------------------------------------------------------------------------ */
var palletes = [{news:"#eb8c04",activity:"#1d64a6",locations:"#79b400",teams:"#ffc001",visitor:"#01ae9b"},
			{news:"#3a8d9b",activity:"#b8341f",locations:"#b59e00",teams:"#693365",visitor:"#eb9818"},
			{news:"#863e6c",activity:"#dea500",locations:"#0097be",teams:"#970700",visitor:"#97a720"}];
function swapNavImages(set){
	var imgPath = "images/interface/buttons/";
	$('btn_news').src = imgPath+"colorset"+set.toString()+"/"+"btn_news.gif";
	$('btn_activity').src = imgPath+"colorset"+set.toString()+"/"+"btn_activity.gif";
	$('btn_teams').src = imgPath+"colorset"+set.toString()+"/"+"btn_teams.gif";
	$('btn_locations').src = imgPath+"colorset"+set.toString()+"/"+"btn_locations.gif";
	$('btn_visitorinfo').src = imgPath+"colorset"+set.toString()+"/"+"btn_visitor_info.gif";
}
function changeColorSet(set){
	var pcol = palletes[set-1][pageCat];
	var el = $E("body");
	var fx = new Fx.Style(el,'background-color',{duration: 500, wait: false}).start(pcol);
	swapNavImages(set);
	Cookie.set("curColorSet", set);
}
function setBackgroundColor(bool){
	var ck;
	if(!bool){
		if(ck = Cookie.get("curColorSet")){
			var pcol = palletes[ck-1][pageCat]
			$E("body").setStyle('background-color',pcol);
			swapNavImages(ck);
		}else{
			var pcol = palletes[0][pageCat]
			$E("body").setStyle('background-color',pcol);
			Cookie.set("curColorSet", 1); 
		}
	}else{
		$E("body").setStyle('background-color','');
	}
}
function setHighContrastBackgroundColor(){
	var ck;
	if(ck = Cookie.get("hcstyle")){
		setActiveStyleSheet("high-contrast");
	}else{
		Cookie.set("hcstyle", 1);
	}
}
function setHighContrast(){
	if(getHighContrast()){
		setActiveStyleSheet("standard");
		Cookie.remove("hcstyle");
		setBackgroundColor(false);
		//alert("high contrast deactivated");
	}else{
		setActiveStyleSheet("high-contrast");
		Cookie.set("hcstyle", 1);
		setBackgroundColor(true);
		//alert("high contrast activated");
	}
}
function getHighContrast(){
	var returnVal = false;
	if(Cookie.get("hcstyle")){
		returnVal = true;
	}
	return returnVal;
}

/* ------------------------------------------------------------------------------ */
/*  Misc
/* ------------------------------------------------------------------------------ */
var swapContent = function(from, to, scrolls){
	var c = $('ContentCache');
	var t = $(to);
	var f = $(from);
	c.innerHTML = t.innerHTML;
	/*if(scrolls){
		t.innerHTML = "<div class=\"ScrollBox\" >" + f.innerHTML+"</div>";
	}else{
		t.innerHTML = f.innerHTML;
	}*/
};
/* ------------------------------------------------------------------------------ */
/*  Forms
/* ------------------------------------------------------------------------------ */
var submitOnce = function(theform){
	if (document.all||document.getElementById){
		for (i=0;i<theform.length;i++){
			var tempobj=theform.elements[i];
			if(tempobj.type.toLowerCase()=="submit" || tempobj.type.toLowerCase()=="reset")
				tempobj.disabled=true;
		}
	}
}