  var switchMonth = false;

    function classSwapping(a,o,c1,c2)
    {
      switch (a){
        case 'swap':
          o.className =! classSwapping('check',o,c1)?o.className.replace(c2,c1):
          o.className.replace(c1,c2);
        break;
        case 'add':
          if(!classSwapping('check',o,c1)){o.className+=o.className?' '+c1:c1;}
        break;
        case 'remove':
          var rep=o.className.match(' '+c1)?' '+c1:c1;
          o.className=o.className.replace(rep,'');
        break;
        case 'check':
          return new RegExp('\\b'+c1+'\\b').test(o.className)
        break;
      }
    }

  function getHTTPRequest()
  {
    var xmlHttp;
    try
    {
      // Firefox, Opera 8.0+, Safari
      xmlHttp=new XMLHttpRequest();
    }
    catch (e)
    {
      // Internet Explorer
      try
      {
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
      catch (e)
      {
        try
        {
          xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (e)
        {
          alert("Your browser does not support AJAX, which is required to use this website.");
          xmlHttp = false;
        }
      }
    }
    return xmlHttp;
  }
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

function showSubs()
{
  for(var i = 0; i < this.childNodes.length; i++)
  {
    if(this.childNodes[i].tagName == 'DIV')
    {
      for(var e = 0; e < this.childNodes[i].childNodes.length; e++)
      {
        if(this.childNodes[i].childNodes[e].tagName == 'UL')
        {
          classSwapping('remove', this.childNodes[i].childNodes[e], 'hidden');
        }
      }
    }
  }
  hideEmbeds();
}

function hideEmbeds()
{
  var embeds = document.getElementsByTagName('embed');
  if(embeds)
  {
    for(var i = 0; i < embeds.length; i++)
    {
      classSwapping('add', embeds[i], 'hidden');
    }
  }
  var placeHolder = document.getElementById('placeHolder');
  if(placeHolder)
  {
    classSwapping('remove', placeHolder, 'hidden');
  }
}

function showEmbeds()
{
  var embeds = document.getElementsByTagName('embed');
  if(embeds)
  {
    for(var i = 0; i < embeds.length; i++)
    {
      classSwapping('remove', embeds[i], 'hidden');
    }
  }
  var placeHolder = document.getElementById('placeHolder');
  if(placeHolder)
  {
    classSwapping('add', placeHolder, 'hidden');
  }
}
function hideSubs()
{
  for(var i = 0; i < this.childNodes.length; i++)
  {
    if(this.childNodes[i].tagName == 'DIV')
    {
      for(var e = 0; e < this.childNodes[i].childNodes.length; e++)
      {
        if(this.childNodes[i].childNodes[e].tagName == 'UL')
        {
          classSwapping('add', this.childNodes[i].childNodes[e], 'hidden');
        }
      }
    }
  }
  showEmbeds();
}
function addHoverControls(obj)
{
  //alert(obj.tagName + ' : ' + obj.id);
  obj.onmouseover = showSubs;
  obj.onmouseout = hideSubs;
}
var calendar_day;
function checkForSubNavigation()
{
  var listItems = document.getElementsByTagName('li');
  if(listItems)
  {
    for(var i = 0; i < listItems.length; i++)
    {
      if(classSwapping('check', listItems[i], 'hasSubs'))
      {
        addHoverControls(listItems[i]);
      }
    }
  }
  
  
  var mainHeading = document.getElementById('mainHeadingInnerHTML');
  if(mainHeading)
  {
    mainHeading.focus();
  }

  setSponsorHovers();
  
  setSponsorRandomizers();

  var CalendarHolder = document.getElementById('PhyneasJavascriptCalendarPlaceHolder');
  
  var this_year;
  var this_month;
  var this_date;
  if(calendar_day)
  {
    var this_year = calendar_day.getFullYear();
    var this_month = calendar_day.getMonth();
    var this_date = calendar_day.getDate();
  }

  if(CalendarHolder)
  {
    addEventCalendar(CalendarHolder, this_year, this_month, this_date);
  }
  
}

function setSponsorRandomizers()
{
  if(document.getElementById('sponsorImage_0'))
  {
    setTimeout('changeSpon(0, 5000)', 5000);
    setTimeout('changeSpon(1, 10000)', 10000);
    setTimeout('changeSpon(2, 6125)', 6125);
    setTimeout('changeSpon(3, 8175)', 8175);
  }
}

function changeSpon(num, freq)
{
  /*
  var newSpon = getRandomSponsor();
  if(newSpon)
  {
    document.getElementById('sponsorA_' + num).href = newSpon['link'];
    document.getElementById('sponsorImage_' + num).src = newSpon['src'];
    document.getElementById('sponsorImage_' + num).src = newSpon['src'];
    document.getElementById('sponsorImage_' + num).alt = newSpon['alt'];
    document.getElementById('sponsorImage_' + num).title = newSpon['title'];
  }*/
  
  var ajaxHandler = getHTTPRequest();
  if(ajaxHandler)
  {
    ajaxHandler.onreadystatechange = function()
    {
      if(ajaxHandler.readyState==4)
      {
        var responseText = ajaxHandler.responseText;
        var spon = false;
        spon = eval('(' + responseText + ')');
        if(spon)
        {
          document.getElementById('sponsorA_' + spon.num).href = spon.link;
          document.getElementById('sponsorImage_' + spon.num).src = spon.src;
          document.getElementById('sponsorImage_' + spon.num).alt = spon.alt;
          document.getElementById('sponsorImage_' + spon.num).title = spon.title;
        }
        setTimeout('changeSpon(' + spon.num + ', ' + spon.freq + ')', spon.freq);
      }
    }
    ajaxHandler.open("GET","randomsponsor.php?num=" + num + "&freq=" + freq,true);
    ajaxHandler.send(null);
  
  }
  
  
  
  
  
  /*
  jx.load(
    'randomsponsor.php',
    function(data)
    {
        var spon = false;
        spon = data;
        if(spon)
        {
          document.getElementById('sponsorA_' + num).href = spon.link;
          document.getElementById('sponsorImage_' + num).src = spon.src;
          document.getElementById('sponsorImage_' + num).alt = spon.alt;
          document.getElementById('sponsorImage_' + num).title = spon.title;
        }
        setTimeout('changeSpon(' + num + ', ' + freq + ')', freq);
    },
    'json'
  );
  */
}
/*
function getRandomSponsor()
{
  var spon = false;
  
  
  
  return spon;
}
*/
String.prototype.checkFor2Char = function()
{
  if(this.length < 2)
  {
    return "0" + this;
  }
  else
  {
    return this;
  }
}
function setSponsorHovers()
{
  var som = document.getElementById('sponsorImage_som');
  var spon0 = document.getElementById('sponsorImage_0');
  var spon1 = document.getElementById('sponsorImage_1');
  var spon2 = document.getElementById('sponsorImage_2');
  var spon3 = document.getElementById('sponsorImage_3');
  
  if(som && spon0 && spon1 && spon2 && spon3)
  {
    som.onmouseover = function()
    {
      setImageType(this, 'color');
    }
    som.onmouseout = function()
    {
      setImageType(this, 'grey');
    }
    spon0.onmouseover = function()
    {
      setImageType(this, 'color');
    }
    spon0.onmouseout = function()
    {
      setImageType(this, 'grey');
    }
    spon1.onmouseover = function()
    {
      setImageType(this, 'color');
    }
    spon1.onmouseout = function()
    {
      setImageType(this, 'grey');
    }
    spon2.onmouseover = function()
    {
      setImageType(this, 'color');
    }
    spon2.onmouseout = function()
    {
      setImageType(this, 'grey');
    }
    spon3.onmouseover = function()
    {
      setImageType(this, 'color');
    }
    spon3.onmouseout = function()
    {
      setImageType(this, 'grey');
    }
  }
}

function getRandomTimeOut()
{
  return ( Math.floor ( Math.random ( ) * n + 5 ) ) * 1000;
}

function setImageType(obj, whichImage)
{
  var otherImage = whichImage == 'color'? 'grey': 'color';
  obj.src = obj.src.replace(otherImage, whichImage);
}

function elementControlFunction(obj)
{
  var elementId = obj.getAttribute('elementId');
  switch(obj.getAttribute('function'))
  {
    case 'save':
      document.getElementById('editForm').submit();
    break;
    case 'delete':
      document.getElementById('deleteElement_' + elementId).value = elementId;
      document.getElementById('editForm').submit();
    break;
    case 'moveu':
      document.getElementById('moveUpElement_' + elementId).value = elementId;
      document.getElementById('editForm').submit();
    break;
    case 'moved':
      document.getElementById('moveDownElement_' + elementId).value = elementId;
      document.getElementById('editForm').submit();
    break;
  }
}

function changeElementType(obj)
{
  var mainHeadingAction = (obj.value == 'mainHeading')? 'remove': 'add';
  var subHeadingAction = (obj.value == 'subHeading')? 'remove': 'add';
  var paragraphAction = (obj.value == 'paragraph')? 'remove': 'add';
  var attachmentAction = (obj.value == 'attachment')? 'remove': 'add';
  var pictureAction = (obj.value == 'picture')? 'remove': 'add';
  classSwapping(mainHeadingAction, document.getElementById('mainHeadingInnerHTML'), 'hidden');
  classSwapping(subHeadingAction, document.getElementById('subHeadingInnerHTML'), 'hidden');
  classSwapping(paragraphAction, document.getElementById('paragraphInnerHTML'), 'hidden');
  classSwapping(attachmentAction, document.getElementById('elementFile'), 'hidden');
  classSwapping(pictureAction, document.getElementById('pictureFile'), 'hidden');
  
  document.getElementById(obj.getAttribute('for')).focus();
  
}
jx = {
	//Create a xmlHttpRequest object - this is the constructor.
	getHTTPObject : function() {
		var http = false;
		//Use IE's ActiveX items to load the file.
		if(typeof ActiveXObject != 'undefined') {
			try {http = new ActiveXObject("Msxml2.XMLHTTP");}
			catch (e) {
				try {http = new ActiveXObject("Microsoft.XMLHTTP");}
				catch (E) {http = false;}
			}
		//If ActiveX is not available, use the XMLHttpRequest of Firefox/Mozilla etc. to load the document.
		} else if (window.XMLHttpRequest) {
			try {http = new XMLHttpRequest();}
			catch (e) {http = false;}
		}
		return http;
	},
	// This function is called from the user's script.
	//Arguments -
	//	url	- The url of the serverside script that is to be called. Append all the arguments to
	//			this url - eg. 'get_data.php?id=5&car=benz'
	//	callback - Function that must be called once the data is ready.
	//	format - The return type for this function. Could be 'xml','json' or 'text'. If it is json,
	//			the string will be 'eval'ed before returning it. Default:'text'
	load : function (url,callback,format) {
		var http = this.init(); //The XMLHttpRequest object is recreated at every call - to defeat Cache problem in IE
		if(!http||!url) return;
		if (http.overrideMimeType) http.overrideMimeType('text/xml');

		if(!format) var format = "text";//Default return type is 'text'
		format = format.toLowerCase();

		//Kill the Cache problem in IE.
		var now = "uid=" + new Date().getTime();
		url += (url.indexOf("?")+1) ? "&" : "?";
		url += now;

		http.open("GET", url, true);

		http.onreadystatechange = function () {//Call a function when the state changes.
			if (http.readyState == 4) {//Ready State will be 4 when the document is loaded.
				if(http.status == 200) {
					var result = "";
					if(http.responseText) result = http.responseText;

					//If the return is in JSON format, eval the result before returning it.
					if(format.charAt(0) == "j") {
						//\n's in JSON string, when evaluated will create errors in IE
						result = result.replace(/[\n\r]/g,"");
						result = eval('('+result+')');
					}

					//Give the data to the callback function.
					if(callback) callback(result);
				} else { //An error occured
					if(error) error(http.status);
				}
			}
		}
		http.send(null);
	},
	init : function() {return this.getHTTPObject();}
}

