// JavaScript Document

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

// Get an object
function getObj(name){
  if (document.getElementById) {
  	this.obj = document.getElementById(name);
	if (this.obj != void(0)) {
		this.style = document.getElementById(name).style;
	}
  } else if (document.all) {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  } else if (document.layers) {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}

// Puts rounded corners on to menu items

function roundedCorners() {
  if (!document.getElementsByTagName) return false;
  var divs = document.getElementsByTagName('div');
  var rounded_divs = [];
  var max_divs= [];
  var class_name = [];
  for (var i = 0; i < divs.length; i++) {
    /*if (/\binnerCurves\b/.exec(divs[i].className)) {
      rounded_divs[rounded_divs.length] = divs[i];
	  max_divs[max_divs.length] = 4;
	  class_name[class_name.length] = 'innerCurves';
    } else if (/\bouterCurves\b/.exec(divs[i].className)) {
		rounded_divs[rounded_divs.length] = divs[i];
	  max_divs[max_divs.length] = 4;
	  class_name[class_name.length] = 'outerCurves';
	 } else if (/\bInnerBox\b/.exec(divs[i].className)) {
	 	rounded_divs[rounded_divs.length] = divs[i];
	 	max_divs[max_divs.length] = 8;
	  	class_name[class_name.length] = 'InnerBox';
    } else*/ if (/\bCornerBox\b/.exec(divs[i].className)) {
	 	rounded_divs[rounded_divs.length] = divs[i];
	 	max_divs[max_divs.length] = 5;
	  	class_name[class_name.length] = 'CornerBox';
    }
  }
  for (var i = 0; i < rounded_divs.length; i++) {
    var original = rounded_divs[i];
	switch (class_name[i]) {
	case 'innerCurves':
		original.className = original.className.replace('innerCurves', 'final');
		var div2 = document.createElement('div');
		div2.className = 'ic';
		break;
	case 'outerCurves':
		original.className = original.className.replace('outerCurves', 'final');
		var div2 = document.createElement('div');
		div2.className = 'oc';
		break;
	case 'InnerBox':
		original.className = original.className.replace('InnerBox', 'final');
		var div2 = document.createElement('div');
		div2.className = 'ib';
		break;
	case 'CornerBox':
		original.className = original.className.replace('CornerBox', 'cb4');
		var div2 = document.createElement('div');
		div2.className = 'cb';
		break;
	default:
		original.className = original.className.replace('box', '');
		var div2 = document.createElement('div');
		div2.className = 'box2';
	}
    original.parentNode.replaceChild(div2, original);
    for (var ii = 3; ii < max_divs[i]+1; ++ii) {
        eval("var div" + ii + " = document.createElement('div');");
		eval("div" + ii + ".className = '" + div2.className  + (ii - 2) + "';");
    }
    for (var iii = 2; iii < max_divs[i]; ++iii) {
        eval("div" + iii + ".appendChild(div" + (iii + 1) + ");");
    }
    eval("div" + max_divs[i] + ".appendChild(original);");
  }
}

function fontDisplay() {

  if (navigator.appName == 'Microsoft Internet Explorer' && navigator.platform == 'MacPPC' || !document.getElementById || !document.getElementById("SubNav")) return false;

  var div = document.createElement("div");
  var h2 = document.createElement("h3");
  h2.appendChild(document.createTextNode("Font size:"));  
  h2.setAttribute("class", "NoShow");
  h2.setAttribute("className", "NoShow");
  
  var ulist = document.createElement("ul");
  ulist.setAttribute("id","fonts");

  var listitem1 = document.createElement("li");
  var ahref1 = document.createElement("a");
  var off1 = document.createElement("span");

  listitem1.setAttribute("class", "sma");
  listitem1.setAttribute("className", "sma");
  ahref1.setAttribute("href","#");
  off1.setAttribute("class", "NoShow");
  off1.setAttribute("className", "NoShow");

  off1.appendChild(document.createTextNode("Regular font size "));
  ahref1.appendChild(off1);
  ahref1.appendChild(document.createTextNode("A"));
  listitem1.appendChild(ahref1);


  var listitem2 = document.createElement("li");
  var ahref2 = document.createElement("a");
  var off2 = document.createElement("span");

  listitem2.setAttribute("class", "med");
  listitem2.setAttribute("className", "med");
  ahref2.setAttribute("href","#");
  off2.setAttribute("class", "NoShow");
  off2.setAttribute("className", "NoShow");

  off2.appendChild(document.createTextNode("Medium font size "));
  ahref2.appendChild(off2);
  ahref2.appendChild(document.createTextNode("A"));
  listitem2.appendChild(ahref2);


  var listitem3 = document.createElement("li");
  var ahref3 = document.createElement("a");
  var off3 = document.createElement("span");

  listitem3.setAttribute("class", "lar");
  listitem3.setAttribute("className", "lar");
  ahref3.setAttribute("href","#");
  off3.setAttribute("class", "NoShow");
  off3.setAttribute("className", "NoShow");
  off3.appendChild(document.createTextNode("Large font size "));
  ahref3.appendChild(off3);
  ahref3.appendChild(document.createTextNode("A"));
  listitem3.appendChild(ahref3);


  ulist.appendChild(listitem1);
  ulist.appendChild(listitem2);
  ulist.appendChild(listitem3);

  var fontch = document.getElementById("SubNav");
  div.appendChild(h2);
  div.appendChild(ulist);
  fontch.appendChild(div);

  ahref1.onclick = function () {changeStyle(''); return false}
  ahref2.onclick = function () {changeStyle('med'); return false}
  ahref3.onclick = function () {changeStyle('lar'); return false}

  ahref1.onmouseover = function () {window.status=''; return true}
  ahref2.onmouseover = function () {window.status=''; return true}
  ahref3.onmouseover = function () {window.status=''; return true}
}

// Stylesheet switcher

function getAllSheets() {
	if( !window.ScriptEngine && navigator.__ice_version ) {
        return document.styleSheets;
    }
	if( document.getElementsByTagName ) {
        var Lt = document.getElementsByTagName('link'), St = document.getElementsByTagName('style');
	} else if(
        document.styleSheets && document.all ) { var Lt = document.all.tags('LINK'), St = document.all.tags('STYLE');
	} else { return []; } for( var x = 0, os = []; Lt[x]; x++ ) {
		var rel = Lt[x].rel ? Lt[x].rel : Lt[x].getAttribute ? Lt[x].getAttribute('rel') : '';
		if( typeof( rel ) == 'string' && rel.toLowerCase().indexOf('style') + 1 ) { os[os.length] = Lt[x]; }
	}
    for(var x = 0; St[x]; x++ ) {
        os[os.length] = St[x];
    }
    return os;
}

function changeStyle() {
	window.userHasChosen = window.MWJss;
	for( var x = 0, ss = getAllSheets(); ss[x]; x++ ) {
		if( ss[x].title ) { ss[x].disabled = true; }
		for( var y = 0; y < arguments.length; y++ ) { if( ss[x].title == arguments[y] ) { ss[x].disabled = false; } }
} }

function rememberStyle( cookieName, cookieLife ) {
	for( var viewUsed = false, ss = getAllSheets(), x = 0; window.MWJss && ss[x]; x++ ) {
        if( ss[x].disabled != MWJss[x] ) {
            viewUsed = true;
            break;
        }
    }
	if( !window.userHasChosen && !viewUsed ) {
        return;
    }
	for( var x = 0, outLine = '', doneYet = []; ss[x]; x++ ) {
		if( ss[x].title && ss[x].disabled == false && !doneYet[ss[x].title] ) {
            doneYet[ss[x].title] = true;
            outLine += ( outLine ? ' MWJ ' : '' ) + escape( ss[x].title );
        }
    }
	if( ss.length ) {
        document.cookie = escape( cookieName ) + '=' + escape( outLine ) + ( cookieLife ? ';expires=' + new Date( ( new Date() ).getTime() + ( cookieLife * 86400000 ) ).toGMTString() : '' ) + ';path=/';
    }
}

function useStyleAgain( cookieName ) {
	for( var x = 0; x < document.cookie.split( "; " ).length; x++ ) {
		var oneCookie = document.cookie.split( "; " )[x].split( "=" );
		if( oneCookie[0] == escape( cookieName ) ) {
			var styleStrings = unescape( oneCookie[1] ).split( " MWJ " );
			for( var y = 0, funcStr = ''; styleStrings[y]; y++ ) { funcStr += ( y ? ',' : '' ) + 'unescape( styleStrings[' + y + '] )'; }
			eval( 'changeStyle(' + funcStr + ');' );
            break;
	   }
    }
    window.MWJss = []; for( var ss = getAllSheets(), x = 0; ss[x]; x++ ) {
        MWJss[x] = ss[x].disabled;
    }
}

var ControlsToValidate = new Array();
var ButtonPressed = "";

function addControlToValidate(FunctionName){
    ControlsToValidate[ControlsToValidate.length++] = FunctionName;
    }
    
function validateControls() {
    var PassedValidation = true;
    for (i=0; i<ControlsToValidate.length; i++){
        if (!ControlsToValidate[i]()) PassedValidation=false;
        }
    return PassedValidation;
    }


window.onload = function(e) {
    useStyleAgain('styleTestStore');
}
window.onunload = function(e) {
    rememberStyle('styleTestStore',10);
}


addLoadEvent(fontDisplay);