//if (window.attachEvent) window.attachEvent("onload", ieInit);
if (window.attachEvent) {
	addDomFunction(ieInit, {'main' : 'id'})
}

// When <div id="main"></div> loads, initiate rotating banner script
addDomFunction(rotate, {'main' : 'id'})
function rotate() {
	// Detect rotating banners
	if(document.getElementById('rotate')) {
		var rotator = document.getElementById('rotate');
		var banners = rotator.getElementsByTagName('div');
		key = [];
		for(var k=0; k<banners.length; k++) {
			key.push(k);
			banners[k].style.display = 'none';
		}
		// fisherYates is an algorithm for shuffling an array
		key = fisherYates(key);
		banners[parseInt(key)].style.display = 'block';
	}
}


<!--//--><![CDATA[//><!--
//if (window.attachEvent) window.attachEvent("onload", init);
window.onload = init;
window.onresize = resize;
//if (window.attachEvent) window.attachEvent("onresize", resize);

function resize() {
	changeHeight();
}

/*SIMILAR TO getElementById()*/
function getElementsByClassName(node, classname){
	var a = [];
	var re = new RegExp('\\b' + classname + '\\b');
	var els = node.getElementsByTagName("*");
	for(var i=0,j=els.length; i<j; i++)
		if(re.test(els[i].className))a.push(els[i]);
	return a;}
	
LINEHEIGHT = 25;
IFRAMEWIDTH = 168 + 'px';

LINEHEIGHT_C = 16;
IFRAMEWIDTH_C = 122 + 'px';

sfHover = function() {
	if (document.getElementById("nav") == undefined)
		return;
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
		
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
			if(this.parentNode.id == 'nav') 
			{
				numLIs = this.getElementsByTagName('li').length;
				// LINEHEIGHT includes the border-bottom of each li
				// However, the last li does not have a border, we need to subtract 1
				// 
				this.getElementsByTagName('iframe')[0].style.height = (LINEHEIGHT * numLIs - 1) + 'px';
				this.getElementsByTagName('iframe')[0].style.width = IFRAMEWIDTH;
				this.getElementsByTagName('iframe')[0].style.display = 'block';
			}
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			
			if(this.parentNode.id == 'nav') {
				this.getElementsByTagName('iframe')[0].style.display = 'none';
			}
		}
	}
}


	sfHover2 = function(test) {
		var sfEls = test.getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
				if(this.parentNode.className == 'nav') 
				{
					numLIs = this.getElementsByTagName('li').length;
					this.getElementsByTagName('iframe')[0].style.height = (LINEHEIGHT_C * numLIs) + 'px';
					this.getElementsByTagName('iframe')[0].style.width = IFRAMEWIDTH_C;
					this.getElementsByTagName('iframe')[0].style.display = 'block';
				}
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
				
				if(this.parentNode.className == 'nav') {
					this.getElementsByTagName('iframe')[0].style.display = 'none';
				}
			}
		}
	}
	
	// IE spefic onload functions
	function ieInit() {
		sfHover();
		temp = getElementsByClassName(document, 'nav');
			for(var i=0; i<temp.length; i++){
				sfHover2(temp[i]);
			}
	}
	
	function init() {
		// Trys
		try { checkHeight(); }		catch(e) { }
		try { alternate();    }     catch(e) { }
		try { userTextSize(); }     catch(e) { }
		/* Tab initialization */
			allTabs = getElementsByClassName(document, 'anchors');
			for(k=0; k < allTabs.length; k++) {
				if(allTabs[k].parentNode.getElementsByTagName('div').length != 0) {
					if(allTabs[k].id) {
						$.tabs(allTabs[k].parentNode.id, parseInt(allTabs[k].id));
					} else {
						$.tabs(allTabs[k].parentNode.id);
					}
				}
			}

	}
	
	function fisherYates ( myArray ) {
		var i = myArray.length;
		if ( i == 0 ) return false;
		while ( --i ) {
			var j = Math.floor( Math.random() * ( i + 1 ) );
			var tempi = myArray[i];
			var tempj = myArray[j];
			myArray[i] = tempj;
			myArray[j] = tempi;
		}
		return myArray;
	}

/* resize margin-bottom for main */

var orig_margin = 10;
var body_height;
function checkHeight()
{
	body_height = document.body.clientHeight;
	// alert(body_height);
	changeHeight();
}



function changeHeight()
{
	if(!document.getElementById('noFooterStretch')) {
	// body_height = document.body.clientHeight;
	browser_height = document.documentElement.clientHeight;
	if (current_font_size == "large") {
		diff = browser_height - body_height - height_increment;
	}
	else {
		
		diff = browser_height - body_height;
	}
	
	divs = document.getElementsByTagName('div');
	for(var i=0; i<divs.length; i++){
		if(divs[i].id.search(/id[0-9]{5}/) != -1){
			//alert(divs[i].id);\
			nodeId = divs[i].id;
		}
	}
	
//	el = document.getElementById(nodeId);
	el = document.getElementById('main');
	el.style.offsetHeight = "100%";
	el.style.cssFloat = "left";
	el.style.styleFloat = "left";
	
	if (el.style.paddingBottom == "") {
		orig_paddingBottom = 0;
		//alert("orig_paddingBottom is  is null");
	}	
	else {
		orig_paddingBottom = parseInt(el.style.paddingBottom);
		//alert("paddingBottom is not null: " + parseInt(el.style.paddingBottom));
	}
	/*
	el = document.getElementById("main");
	
	
		if (BrowserDetect.browser == 'Explorer') {
			diff = browser_height - body_height -25;
			if (diff > 0) {
				el.style.padding = "0  0 " + diff + "px 0";
			}
			else {
				el.style.padding = "0 0 0 0";
			}
		}
		if (BrowserDetect.browser == 'Firefox') {
			diff = browser_height - body_height - 17;
			
			if (diff > 0) {
				el.style.padding = "0  0 " + diff + "px 0";
			}
			else {
				el.style.padding = "0 0 0 0";
			}
		}
		
		*/
		
		
		if (diff > 0) {
				new_paddingBottom =  diff;
		}
		else {
				new_paddingBottom = 0;
				
		}
		el.style.paddingBottom = new_paddingBottom + "px";
} else {
	return false;
}
} 

	function getElementsByClassName(node, classname)
	{
		var a = [];
		var re = new RegExp('\\b' + classname + '\\b');
		var els = node.getElementsByTagName("*");
		for(var i=0,j=els.length; i<j; i++)
			if(re.test(els[i].className))a.push(els[i]);
		return a;
	}


// Used for alternating/highlighting tables  
// when the page loads it sees how each table is tagged and then gives
// it the appropriate highlighting/alternating colors...
// for example: 
// 			table class='tableLines' id='tableShade' = alternating tr colors
//			table class='tableLines' id='tableHighlight' = mouseover highlighting of trs
//			table class='tableLines' id='' = no tr colors, no highlighting
//			table class='tableAllLines' id='tableShade' = alternating tr colors
//			table class='tableAllLines' id='tableHighlight' = mouseover highlighting of trs
function alternate()
	{
		var dataTables = getDataTables();
		if(dataTables.length > 0) {
			numDataTables = dataTables.length;
			
			for(var i=0; i < numDataTables; i++) {
				if(dataTables[i].id == 'tableShade') {
					var regOrder = 1;
					trs = dataTables[i].getElementsByTagName('tr');
					numTrs = trs.length;
					for(var j=0; j < numTrs; j++) {
						//if(j != 0) {
							if(trs[j].getElementsByTagName('th').length > 0) {
								if((j%2) == 1) {
									regOrder = 1;
								} else if ((j%2) == 0) {
									regOrder = 0;
								}
							}
							if(regOrder == 0) {
								((j%2) == 0) ? trs[j].className += ' odd' : trs[j].className += ' even';
							} else {
								((j%2) == 0) ? trs[j].className += ' even' : trs[j].className += ' odd';
							}
						//}
					}
				} else if (dataTables[i].id == 'tableHighlight') {
					trs = dataTables[i].getElementsByTagName('tr');
					numTrs = trs.length;
					for(var j=0; j < numTrs; j++) {
						trs[j].onmouseover = function(){
							if(this.className == 'even' || this.className == 'odd' || this.className == '') {
								this.className = "even";
							}
						}
						trs[j].onmouseout = function(){
							if(this.className == 'even' || this.className == 'odd' || this.className == '') {
								this.className = "odd";
							}
						}
					}
				}
			}
		}
	}	
	// Returns an array of all the data tables
	function getDataTables() {
		var tableLines = getElementsByClassName(document, 'tableLines');
		var tableAllLines = getElementsByClassName(document, 'tableAllLines');
		if(tableLines.length == 0 && tableAllLines.length == 0) {
			return false;
		} else {
			var allDataTables = tableLines.concat(tableAllLines);
			return allDataTables;
		}
	}


var change_font_size = 0;
var new_body_height;
var height_increment = 0;
var current_font_size = "small";

function compute_height_increment() {
	if (change_font_size == 0) {
		new_body_height = document.body.clientHeight;
		height_increment = new_body_height - current_body_height;
		// alert(height_increment);
		change_font_size = 1;
	}
}
// Toggles Font-Size and Line-Height on content pages.
	function changeLabel(toggle){
		if(document.getElementById("puText")){
			// Number of <li> tags in the document, as well as an array containing references
			var LI_length = document.getElementById("columnMain").getElementsByTagName("li").length;
			var LI_arr = document.getElementById("columnMain").getElementsByTagName("li");
			
			// Number of <p> tags in the document, with an array of references
			var P_length = document.getElementById("columnMain").getElementsByTagName("p").length;
			var P_arr = document.getElementById("columnMain").getElementsByTagName("p");
			
			// Toggles the Text Size Icon and resizes text
			if(toggle == 'large'){
				if (change_font_size == 0) {
					current_body_height = document.body.clientHeight;
				}
				current_font_size = "large";
				
				document.getElementById("puText").className = "iconTextReduce";
				document.getElementById("puText").innerHTML = "smaller type";
				document.getElementById("puText").href = "javascript:changeLabel('small');";
				// Change all <li>s lineHeight to greater percentage
					for(k = 0; k < LI_length; k++){ 
						//if(LI_arr[k].className == 'anchors') {
						
							LI_arr[k].style.lineHeight = "150%" 
							LI_arr[k].style.fontSize = "110%" 
						//}
					}
				// Change all <p>s lineHeight to greater percentage
					for(j = 0; j < P_length; j++){ 
						P_arr[j].style.lineHeight = "150%" 
						P_arr[j].style.fontSize = "110%" 
					}
				createCookie('textSize', 'large', 30);
				// added temp YC
				compute_height_increment();
				changeHeight();
				
				
				} 
			else {
				current_font_size = "small";
				document.getElementById("puText").className = "iconTextEnlarge";
				document.getElementById("puText").innerHTML = "larger type";
				document.getElementById("puText").href = "javascript:changeLabel('large');";
				document.getElementById("columnMain").style.fontSize = "";
				// Change all <li>s back to default lineHeight
					for(k = 0; k < LI_length; k++){ 
						LI_arr[k].style.lineHeight = ""; 
						LI_arr[k].style.fontSize= ""; 
					}
				// Change all <p>s back to default lineHeight
					for(j = 0; j < P_length; j++){ 
						P_arr[j].style.lineHeight = ""; 
						P_arr[j].style.fontSize = ""; 
					}
					createCookie('textSize', 'small', 30);
				changeHeight();
				}
		}
	}

// Used to set a cookie with the user's font-size preference
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 var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
	//alert('Cookie\n' + name + '\ncreated with a value ' + value);
}

// Returns the cookie value
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;
}

// Used onLoad to set document text size
function userTextSize(){
	size = readCookie('textSize'); 
	changeLabel(size);
}


// Select Box Links

function selectLinks(targ,selObj,restore){
	//alert('hi');
	//selObj.options[selObj.selectedIndex].value += "&cmty=" + community;
	//alert(selObj.options[selObj.selectedIndex].value);
	ddvalue = (selObj.options[selObj.selectedIndex].value)
	
	if (ddvalue == '') {
		return }
	else {
	if (targ=="self") {
		window.open(selObj.options[selObj.selectedIndex].value);
 }
	else {	
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value + "'");
	if (restore) selObj.selectedIndex = 0;
	}
	}
}

// Added: YC
// Purpose: To go to a specific location (i.e. named tag) in the same page using a drop-down (the
// select tag).
// "sel" is the select object.
// Set the value of the first entry to an empty string.

function processOptions(sel) {
	var loc = sel.options[sel.selectedIndex].value;
	if (loc != "") {
		document.location = loc;
	}
}

//estudio popup window

var newwindow = '';

function popitup(url)
{
	if (!newwindow.closed && newwindow.location)
	{
		newwindow.location.href = url;
	}
	else
	{
		newwindow=window.open(url,'name','height=600,width=600,scrollbars=yes');
		if (!newwindow.opener) newwindow.opener = self;
	}
	if (window.focus) {newwindow.focus()}
	return false;
}


//--><!]]>

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 isValidEmail(sText) {
    var reEmail = /^(?:\w+\.?)*\w+@(?:\w+\.?)*\w+$/;
    return reEmail.test(sText);
}

function LTrim(str)
        /***
                PURPOSE: Remove leading blanks from our string.
                IN: str - the string we want to LTrim

                RETVAL: An LTrimmed string!
        ***/
{
                var whitespace = new String(" \t\n\r");

                var s = new String(str);

                if (whitespace.indexOf(s.charAt(0)) != -1) {
                    // We have a string with leading blank(s)...

                    var j=0, i = s.length;

                    // Iterate from the far left of string until we
                    // don't have any more whitespace...
                    while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
                        j++;


                    // Get the substring from the first non-whitespace
                    // character to the end of the string...
                    s = s.substring(j, i);
                }

                return s;
}

function addDomFunction(fn, dependencies)
{
  var counter = 0, collections = {}, timer = setInterval(function()
  {
    var ready = false;
    counter++;

    if (typeof document.getElementsByTagName != 'undefined'
        && (document.getElementsByTagName('body')[0] || document.body))
    {
      ready = true;

      if (typeof dependencies == 'object')
      {
        for (var i in dependencies)
        {
          if (dependencies[i] == 'id' && !document.getElementById(i))
          {
            ready = false;
            break;
          }
          else if (dependencies[i] == 'tag')
          {
            var len = document.getElementsByTagName(i).length;
            if (typeof collections[i] == 'undefined' || collections[i] != len || len < 1)
            {
              collections[i] = len;
              ready = false;
              break;
            }
          }
        }
      }
      if (ready)
      {
        clearInterval(timer);
        fn();
      }
    }

    if (counter >= 40)
    {
      clearInterval(timer);
    }

  }, 250);
}
