var searchControl = false;
var siteSearch = false;

function searchComplete(result){
	var contentDiv = document.getElementById('searchResults');
    contentDiv.innerHTML = '';	// Loop through our results, printing them to the page.
    var results = siteSearch.results;
	if (results.length > 0) {
		for (var i = 0; i < results.length; i++) {
			// For each result write it's title and image to the screen
			var result = results[i];
			results[i].visibleUrl = results[i].unescapedUrl;
			var resultDiv = document.createElement('div');
				resultDiv.className = 'result';
				var titleDiv = document.createElement('div');
					titleDiv.className = 'title';
					var titleLink = document.createElement('a');
						titleLink.setAttribute('href', result.url);
						titleLink.innerHTML = result.title;
				titleDiv.appendChild(titleLink);
				var excerptDiv = document.createElement('div');
					excerptDiv.className = 'excerpt';
					excerptDiv.innerHTML = result.content;
				var urlDiv = document.createElement('div');
					urlDiv.className = 'url';
					urlDiv.innerHTML = result.unescapedUrl;
			resultDiv.appendChild(titleDiv);
			resultDiv.appendChild(excerptDiv);
			resultDiv.appendChild(urlDiv);
			contentDiv.appendChild(resultDiv);
		}
		var cursor = siteSearch.cursor;
		var curPage = cursor.currentPageIndex; // check what page the app is on
		var resultsCountString = 'Results <strong>' + (curPage*8+1) + '-' + (curPage*8+8) + '</strong> for <strong>' + document.getElementById('headerTopSearchFormText').value + '</strong>';
		document.getElementById('resultsCountString').innerHTML = resultsCountString;
		var pagesDiv = document.createElement('div');
		pagesDiv.setAttribute('id', 'searchPagination');
		if (curPage > 0) {
			var link = document.createElement('a');
			link.href = 'javascript:siteSearch.gotoPage('+(curPage-1)+');';
			link.className = 'strong';
			link.innerHTML = 'Previous';
			pagesDiv.appendChild(link);
		}
		for (var i = 0; i < cursor.pages.length; i++) {
			var page = cursor.pages[i];
			if (curPage == i) { // if we are on the curPage, then don't make a link
				var label = document.createElement('span');
				label.appendChild(document.createTextNode(page.label));
				pagesDiv.appendChild(label);
			} else {
			  // If we aren't on the current page, then we want a link to this page.
			  // So we create a link that calls the gotoPage() method on the searcher.
			  var link = document.createElement('a');
			  link.href = 'javascript:siteSearch.gotoPage('+i+');';
			  link.innerHTML = page.label;
			  pagesDiv.appendChild(link);
			}
		}
		if (curPage < cursor.pages.length-1) {
			var link = document.createElement('a');
			link.href = 'javascript:siteSearch.gotoPage('+(curPage+1)+');';
			link.className = 'strong';
			link.innerHTML = 'Next';
			pagesDiv.appendChild(link);
		}
		contentDiv.appendChild(pagesDiv);
	} else {
		var resultsCountString = 'Nothing found for <strong>' + document.getElementById('headerTopSearchFormText').value + '</strong>';
		document.getElementById('resultsCountString').innerHTML = resultsCountString;
		contentDiv.innerHTML = 'No results found for your search.';
	}
	window.location.assign('#search_top');
}

function initSearch() {
	document.forms['headerTopSearchForm'].onsubmit = function() {
		searchControl.execute(document.getElementById('headerTopSearchFormText').value);
		return false;
	}
	// Create a search control
	searchControl = new google.search.SearchControl();
	var options = new google.search.SearcherOptions();
	options.setExpandMode(google.search.SearchControl.EXPAND_MODE_OPEN);
	//options.setRoot(document.getElementById("searchResults"));
	var cseId = "001839272841361024981:yhlcvgrbp-m";
	siteSearch = new google.search.WebSearch();
	siteSearch.setSiteRestriction(cseId);
	siteSearch.setNoHtmlGeneration()
	searchControl.setResultSetSize(google.search.Search.LARGE_RESULTSET);
	searchControl.addSearcher(siteSearch, options);

	searchControl.draw(document.getElementById("searchControl"));
	searchControl.setNoResultsString("No results found for your search.");
	searchControl.setSearchCompleteCallback(this, searchComplete, null);

	// execute an inital search
	var searchParam = getUserParam('search');
	if (searchParam) {
		document.getElementById('headerTopSearchFormText').value = searchParam;
		searchControl.execute(searchParam);
	} else {
		searchControl.execute("Financial Engines");
	}
}

function getUserParam(name) {
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return false;
  else
    return results[1];
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return {x: curleft, y: curtop};
}

shuffle = function(o) {
	for (var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
	return o;
};

Array.prototype.inArray = function (value) {
	var i;
	for (i=0; i < this.length; i++) {
		if (this[i] === value) {
			return true;
		}
	}
	return false;
};

function getStyle(oElm, strCssRule){
	var strValue = "";
	if(document.defaultView && document.defaultView.getComputedStyle){
		strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
	}
	else if(oElm.currentStyle){
		strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
			return p1.toUpperCase();
		});
		strValue = oElm.currentStyle[strCssRule];
	}
	return strValue;
}

function isIe(){
	var isIE6RE = new RegExp("MSIE");
	return isIE6RE.test(navigator.userAgent);
}

function isIe6(){
	var isIE6RE = new RegExp("MSIE 6");
	return isIE6RE.test(navigator.userAgent);
}

function $(id) { return document.getElementById(id); }

function intval(num, fund){
    num = parseInt(num, fund);
    if (isNaN(num)) {
        return 0;
    } else {
        return num;
    }
}

function getArrowsBack(){
	var arrows = getElementsByClassName('content','teaserArrow');
	if (arrows == null) { return false; }
	for (var i = 0; i < arrows.length; i++) {
		arrows[i].style.bottom = "4px";
	}
}

function getElementsByClassName(parent, className) {
	if (typeof(parent) == 'string'){parent = $(parent);}
	if (parent == null) {return null;}
	var children = parent.childNodes;
	var matched_elements = new Array();
	for (var i = 0; i < children.length; i++) {
		if (children[i].className && children[i].className.match(new RegExp(className+"\\b"))) {
			matched_elements[matched_elements.length] = children[i];
		}
		var child_matched_elements = getElementsByClassName(children[i], className);
		if (child_matched_elements != null) {
			for (var k = 0; k < child_matched_elements.length; k++) {
				matched_elements[matched_elements.length] = child_matched_elements[k];
			}
		}
	}
	return matched_elements;
}

function adjustItemsHeight(rowItem, itemClass, spacerClass){
    var maxHeight = 0;
    if (typeof(rowItem) == 'string'){rowItem = $(rowItem);}
    var items = getElementsByClassName(rowItem, itemClass);
    if (items != null) {
    	for (var i = 0; i < items.length; i++) {
			var elementHeight = intval(items[i].offsetHeight);
			maxHeight = (maxHeight > elementHeight)?maxHeight:elementHeight;
    	}
    	for (var i = 0; i < items.length; i++) {
    		var element = items[i];
			if (spacerClass) {
				var heightToSet = maxHeight - intval(element.offsetHeight);
				var spacers = getElementsByClassName(element, spacerClass);
				if (spacers != null && spacers[0]) {
					spacers[0].style.height = heightToSet+"px";
				}
			} else {
				var heightToSet = maxHeight - intval(getStyle(element,'padding-top'), 10) - intval(getStyle(element,'padding-bottom'), 10) - intval(getStyle(element,'border-top-width'), 10) - intval(getStyle(element,'border-bottom-width'), 10);
				element.style.height = heightToSet+"px";
			}
    	}
    }
}

function addHoverClassName(element, className) {
	if (typeof(element) == "string") { element = $(element); }
	if (typeof(element) != null) {
		addEvent(element,'mouseover', function(){toggleClassName(element, className);});
		addEvent(element,'mouseout', function(){toggleClassName(element, className);});
	}
}

function toggleClassName(element, className) {
	if (element.className && element.className.match(new RegExp(className+"\\b"))!=null) {
		element.className=element.className.replace(new RegExp(className+"\\b"), "");
	} else {
		element.className=element.className.replace(new RegExp(className+"\\b"), "");
		element.className+=" "+className;
	}
}

function addEvent(obj, type, fn) {
	if (obj.addEventListener) {
		obj.addEventListener(type, fn, false);
		EventCache.add(obj, type, fn);
	}
	else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn](window.event); }
		obj.attachEvent("on"+type, obj[type+fn]);
		EventCache.add(obj, type, fn);
	}
	else {
		obj["on"+type] = obj["e"+type+fn];
	}
}

var EventCache = function() {
	var listEvents = [];
	return {
		listEvents : listEvents,
		add : function(node, sEventName, fHandler) {
			listEvents.push(arguments);
		},
		flush : function() {
			var i, item;
			for(i = listEvents.length - 1; i >= 0; i = i - 1) {
				item = listEvents[i];
				if(item[0].removeEventListener) {
					item[0].removeEventListener(item[1], item[2], item[3]);
				};
				if(item[1].substring(0, 2) != "on") {
					item[1] = "on" + item[1];
				};
				if(item[0].detachEvent) {
					item[0].detachEvent(item[1], item[2]);
				};
				item[0][item[1]] = null;
			};
		}
	};
}();

var Tooltips = {
	xCord : 0,								// @Number: x pixel value of current cursor position
	yCord : 0,								// @Number: y pixel value of current cursor position
	tipElements : ['abbr','acronym'],	// @Array: Allowable elements that can have the toolTip
	obj : Object,							// @Element: That of which you're hovering over
	tip : Object,							// @Element: The actual toolTip itself
	active : 0,								// @Number: 0: Not Active || 1: Active
	init : function() {
		if (!document.getElementById ||
			!document.createElement ||
			!document.getElementsByTagName) {
			return;
		}
		var i,j;

		/* Begin: Tooltip Creation */
		var div_tip = document.createElement("div");
		div_tip.id = "toolTip";

		var div_tip_top = document.createElement("div");
		div_tip_top.className = "top";
		var div_tip_bottom = document.createElement("div");
		div_tip_bottom.className = "bottom";
		var div_tip_content = document.createElement("div");
		div_tip_content.className = "content";

		var div_tip_content_h3 = document.createElement("h3");
		div_tip_content_h3.id = "toolTipTitle";
		div_tip_content_h3.appendChild(document.createTextNode(""));

		var div_tip_content_p = document.createElement("p");
		div_tip_content_p.id = "toolTipContent";
		div_tip_content_p.appendChild(document.createTextNode(""));

		div_tip_content.appendChild(div_tip_content_h3);
		div_tip_content.appendChild(div_tip_content_p);

		div_tip.appendChild(div_tip_top);
		div_tip.appendChild(div_tip_content);
		div_tip.appendChild(div_tip_bottom);

		this.tip = div_tip;
		/* End: Tooltip Creation */

		document.getElementsByTagName('body')[0].appendChild(this.tip);
		this.tip.style.top = '0';
		this.tip.style.visibility = 'hidden';
		var tipLen = this.tipElements.length;
		for (i=0; i<tipLen; i++) {
			var current = document.getElementsByTagName(this.tipElements[i]);
			var curLen = current.length;
			for (j=0; j<curLen; j++) {
				addEvent(current[j],'mouseover',this.tipOver);
				addEvent(current[j],'mouseout',this.tipOut);
				current[j].setAttribute('tip',current[j].title);
				current[j].removeAttribute('title');
			}
		}
	},
	updateXY : function(e) {
		if (document.captureEvents) {
			Tooltips.xCord = e.pageX;
			Tooltips.yCord = e.pageY;
		} else if (window.event.clientX) {
			Tooltips.xCord = window.event.clientX+document.documentElement.scrollLeft;
			Tooltips.yCord = window.event.clientY+document.documentElement.scrollTop;
		}
	},
	tipOut: function() {
		if (window.tID) {
			clearTimeout(tID);
		}
		if (window.opacityID) {
			clearTimeout(opacityID);
		}
		Tooltips.tip.style.visibility = 'hidden';
	},
	checkNode : function() {
		var trueObj = this.obj;
		if (this.tipElements.inArray(trueObj.nodeName.toLowerCase())) {
			return trueObj;
		} else {
			return trueObj.parentNode;
		}
	},
	tipOver : function(e) {
		Tooltips.obj = this;
		tID = window.setTimeout("Tooltips.tipShow()", 500);
		Tooltips.updateXY(e);
	},
	tipShow : function() {
		var scrX = Number(this.xCord);
		var scrY = Number(this.yCord);
		/*
		var lt = parseInt(scrX+10);
		*/
		var tp = parseInt(scrY-10);
		var lt = parseInt(scrX);
		var anch = this.checkNode();
		var addy = '';
		var access = '';
		if (anch.nodeName.toLowerCase() == 'a') {
			addy = (anch.href.length > 25 ? anch.href.toString().substring(0,25)+"..." : anch.href);
			var access = (anch.accessKey ? ' <span>['+anch.accessKey+']</span> ' : '');
		} else {
			addy = anch.firstChild.nodeValue;
		}

		document.getElementById("toolTipTitle").innerHTML = addy;
		document.getElementById("toolTipContent").innerHTML = anch.getAttribute('tip');

		this.tip.className = anch.className;
		this.tip.style.left = (lt - (this.tip.clientWidth/2)) + 'px';
		this.tip.style.top = tp - this.tip.clientHeight + 'px';
		this.tip.style.visibility = 'visible';
	},
	tipFade: function(opac) {
		var passed = parseInt(opac);
		var newOpac = parseInt(passed+10);
		if (newOpac < 80) {
			this.tip.style.opacity = '.'+newOpac;
			this.tip.style.filter = "alpha(opacity:"+newOpac+")";
			opacityID = window.setTimeout("Tooltips.tipFade('"+newOpac+"')",20);
		} else {
			this.tip.style.opacity = '.80';
			this.tip.style.filter = "alpha(opacity:80)";
		}
	}
};

function hideYearTabs () {
	var isSelectedRE = new RegExp("selected\\b");
	var linksCollection = $("prYearsBlocks").getElementsByTagName("a");
	for (var i = 0; i < linksCollection.length; i++) {
		var currentLink = linksCollection[i];
		if (currentLink.rel != "") {
			if (!isSelectedRE.test(currentLink.className)) {
				$(currentLink.rel).style.display = "none";
			}
		}
	}
}

function hideTeamTabs () {
	var isSelectedRE = new RegExp("selected\\b");
	var linksCollection = $("wrwTabs").getElementsByTagName("a");
	for (var i = 0; i < linksCollection.length; i++) {
		var currentLink = linksCollection[i];
		if (currentLink.rel != "") {
			if (!isSelectedRE.test(currentLink.className)) {
				$(currentLink.rel).style.display = "none";
			}
		}
	}
}

function displayYearTab(linkObj) {
	var linksCollection = $("prYearsBlocks").getElementsByTagName("a");
	for (var i = 0; i < linksCollection.length; i++) {
		var currentLink = linksCollection[i];
		if (currentLink.rel != "") {
			$(currentLink.rel).style.display = "none";
			currentLink.className = currentLink.className.replace(new RegExp("selected\\b"), "");
		}
	}
	$(linkObj.rel).style.display = "block";
	linkObj.className += "selected";
	$("hPressReleases").className = linkObj.rel;
}

function displayTab(containerID, headerID, linkObj) {
	var linksCollection = $(containerID).getElementsByTagName("a");
	for (var i = 0; i < linksCollection.length; i++) {
		var currentLink = linksCollection[i];
		if (currentLink.rel != "") {
			$(currentLink.rel).style.display = "none";
			currentLink.className = currentLink.className.replace(new RegExp("selected\\b"), "");
		}
	}
	$(linkObj.rel).style.display = "block";
	linkObj.className += "selected";
	$(headerID).className = linkObj.rel;
}

function pressAttachHovers(id) {
	var events = getElementsByClassName(id, "event");
	for (var i = 0; i < events.length; i++) {
		var current_event = events[i];
		switch (current_event.className) {
			case "event first":
			case "event last":
			case "event":
				current_event.onmouseover = function() {
					this.className += " selected";
				}
				current_event.onmouseout = function() {
					this.className = this.className.replace(new RegExp(" selected\\b"), "");
				}
				current_event.onclick = function() {
					var divCollection = this.getElementsByTagName("div");
					for (var i = 0; i < divCollection.length; i++) {
						if (divCollection[i].className == "description") {
							var links_collection = divCollection[i].getElementsByTagName("a");
							if (links_collection[0] && links_collection[0].href != "#") {
								switch (links_collection[0].target) {
									case "_blank": window.open(links_collection[0].href); break;
									case "": window.location = links_collection[0].href; break;
								}
							}
						}
					}
				}
				break;
		}
	}
}

function readmore(sectionID, pid, action) {
	var parentElement = $(sectionID);
	var tabs = $("HWDITabs").getElementsByTagName("div");
	var dt_elements = $("HWDITabs").getElementsByTagName("dt");
	var dd_elements = $("HWDITabs").getElementsByTagName("dd");

	var isTabRE = new RegExp("\\s?tab\\s?")
	var isSelectedRE = new RegExp("\\s?selected\\s?");
	
	/* Begin: Close all Tabs */
	for (var i = 0; i < tabs.length; i++) {
		var current_element = tabs[i];
		if (isTabRE.test(current_element.className)) {
			current_element.className = current_element.className.replace(isSelectedRE, "");
			//current_element.className = current_element.className.replace(new RegExp("\\s?hover\\s?"), "");
		}
	}
	
	for (var i = 0; i < dt_elements.length; i++) dt_elements[i].style.display = "block";
	for (var i = 0; i < dd_elements.length; i++) dd_elements[i].style.display = "none";
	/* End: Close all Tabs */

	/* Begin: Show/Hide Defenition Term */
	var dt_elements = $(pid).getElementsByTagName("dt");
	for (var i = 0; i < dt_elements.length; i++) {
		var current_dt_element = dt_elements[i];
		switch (action) {
			case "show": current_dt_element.style.display = "none"; break;
			case "hide": current_dt_element.style.display = "block"; break;
		}
	}
	/* End: Show/Hide Defenition Term */
	
	/* Begin: Show/Hide Defenition Description */
	var dd_elements = $(pid).getElementsByTagName("dd");
	for (var i = 0; i < dd_elements.length; i++) {
		var current_dd_element = dd_elements[i];
		switch (action) {
			case "show": current_dd_element.style.display = "block"; break;
			case "hide": current_dd_element.style.display = "none"; break;
		}
	}
	/* End: Show/Hide Defenition Description */
	
	if ($(pid) && action == "show") {
		$(pid).className += " selected";
	}
}

function hwdiAttachHovers(id) {
	var tabs = getElementsByClassName(id, "tab");
	var isTabRE = new RegExp("tab\\b")
	for (var i = 0; i < tabs.length; i++) {
		var current_tab = tabs[i];
		if (isTabRE.test(current_tab.className)) {
			current_tab.onmouseover = function() {
				var isOpenedTabRE = new RegExp(" selected\\b")
				if (!isOpenedTabRE.test(this.className)) {
					this.className += " hover";
				}
			}
			current_tab.onmouseout = function() {
				this.className = this.className.replace(new RegExp("\\s?hover\\s?"), "");
			}
			current_tab.onclick = function() {
				this.className = this.className.replace(new RegExp("\\s?hover\\s?"), "");
				var isOpenedTabRE = new RegExp("\\s?selected\\s?")
				if (!isOpenedTabRE.test(this.className)) { //if tab is closed
					switch (this.id) {
						case "HWDITabsStep1Tab": readmore("section1", "HWDITabsStep1Tab", "show"); break;
						case "HWDITabsStep2Tab": readmore("section2", "HWDITabsStep2Tab", "show"); break;
						case "HWDITabsStep3Tab": readmore("section3", "HWDITabsStep3Tab", "show"); break;
						case "HWDITabsStep4Tab": readmore("section4", "HWDITabsStep4Tab", "show"); break;
						case "HWDITabsStep5Tab": readmore("section5", "HWDITabsStep5Tab", "show"); break;
					}
				} else { //if tab is opened
					switch (this.id) {
						case "HWDITabsStep1Tab": readmore("section1", "HWDITabsStep1Tab", "hide"); break;
						case "HWDITabsStep2Tab": readmore("section2", "HWDITabsStep2Tab", "hide"); break;
						case "HWDITabsStep3Tab": readmore("section3", "HWDITabsStep3Tab", "hide"); break;
						case "HWDITabsStep4Tab": readmore("section4", "HWDITabsStep4Tab", "hide"); break;
						case "HWDITabsStep5Tab": readmore("section5", "HWDITabsStep5Tab", "hide"); break;
					}
				}
			}
		}
	}
}


/* FAQ */
function faqAttachHovers(id) {
	var tabs = getElementsByClassName(id, "tab");
	var isTabRE = new RegExp("\\s?tab\\s?")
	for (var i = 0; i < tabs.length; i++) {
		var current_tab = tabs[i];
		if (isTabRE.test(current_tab.className)) {
			current_tab.onmouseover = function() {
				var isOpenedTabRE = new RegExp(" selected\\b")
				if (!isOpenedTabRE.test(this.className)) {


					this.className += " hover";
				}
			}
			current_tab.onmouseout = function() {
				this.className = this.className.replace(new RegExp("\\s?hover\\s?"), "");
			}
			current_tab.onclick = function() {
				this.className = this.className.replace(new RegExp("\\s?hover\\s?"), "");
				var isOpenedTabRE = new RegExp("\\s?selected\\s?")
				if (!isOpenedTabRE.test(this.className)) { //if tab is closed
					this.className += " selected";
				} else { //if tab is opened
					this.className = this.className.replace(new RegExp("\\s?selected"), "");
				}
				return false;
			}
		}
	}
	
	var divElements = getElementsByClassName(id, "hideAnswer");
	for (var divElementID = 0; divElementID < divElements.length; divElementID++) {
		var divElement = divElements[divElementID];
		var linkElement = divElement.firstChild;
		linkElement.onclick = function() {
			divElement.className = divElement.className.replace(new RegExp("\\s?selected"), "");
			return false;
		}
	}
}
/* FAQ */

// Fade In / Fade Out Home Page Images
function RHP(url) {
	/* Begin: Please modify delays */
	RHP.prototype.DisplayOptionFadeIn = 500;
	RHP.prototype.DisplayOptionShow = 4000;
	RHP.prototype.DisplayOptionFadeOut = 500;
	/* End: Please modify delays */
	
	RHP.prototype.DisplayOptionStep = 5;
	RHP.prototype.maxImagesCount = 3;
	
	RHP.prototype.isOver = false;
	RHP.prototype.DisplayOptionCurrentOpacity = 100;	
	
	RHP.prototype.sponsorsULPos = findPos($("sponsorsLogos"));
	RHP.prototype.sponsorsUL = {width: $("sponsorsLogos").clientWidth, height: $("sponsorsLogos").clientHeight};

	RHP.prototype.xmlhttp = null;
	RHP.prototype.response = null;
	RHP.prototype.construct(url);
}
RHP.prototype.mousemove = function(e) {
	if (isIe()) {
		tempX = event.clientX;
		tempY = event.clientY;
	} else {
		tempX = e.pageX;
		tempY = e.pageY;
	}

	if ((tempX >= RHP.prototype.sponsorsULPos.x) && (tempX <= (RHP.prototype.sponsorsULPos.x + RHP.prototype.sponsorsUL.width)) && (tempY >= RHP.prototype.sponsorsULPos.y) && (tempY <= (RHP.prototype.sponsorsULPos.y + RHP.prototype.sponsorsUL.height))) {
		RHP.prototype.isOver = true;
	} else {
		RHP.prototype.isOver = false;
	}
}
RHP.prototype.construct = function (url) {
	if (!isIe()) {
		window.captureEvents(Event.MOUSEMOVE);	
		window.onmousemove = RHP.prototype.mousemove;
	} else {
		document.onmousemove = RHP.prototype.mousemove;		
	}

	if (window.XMLHttpRequest) {
		RHP.prototype.xmlhttp = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		RHP.prototype.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}

	if (RHP.prototype.xmlhttp != null) {
		RHP.prototype.xmlhttp.onreadystatechange = RHP.prototype.onchangestate;
		RHP.prototype.xmlhttp.open("GET", url, true);
		RHP.prototype.xmlhttp.send(null);
	}
}
RHP.prototype.onchangestate = function () {
	if (RHP.prototype.xmlhttp.readyState == 4 && RHP.prototype.xmlhttp.status == 200) {
		RHP.prototype.response = RHP.prototype.xmlhttp.responseXML;
		window.setTimeout(RHP.prototype.fadeOut, RHP.prototype.DisplayOptionShow);
	}
}
RHP.prototype.fadeIn = function () {
	RHP.prototype.DisplayOptionCurrentOpacity += RHP.prototype.DisplayOptionStep;
	$("sponsorsLogos").style.filter = "alpha(opacity='" + RHP.prototype.DisplayOptionCurrentOpacity + "');";
	$("sponsorsLogos").style.opacity = RHP.prototype.DisplayOptionCurrentOpacity/100;
	
	if (RHP.prototype.DisplayOptionCurrentOpacity < 100) {
		window.setTimeout(RHP.prototype.fadeIn, RHP.prototype.DisplayOptionFadeIn/(100/RHP.prototype.DisplayOptionStep));
	} else {
		window.setTimeout(RHP.prototype.fadeOut, RHP.prototype.DisplayOptionShow);
	}
}
RHP.prototype.fadeOut = function () {
	if (!RHP.prototype.isOver) {
		RHP.prototype.DisplayOptionCurrentOpacity -= RHP.prototype.DisplayOptionStep;
		$("sponsorsLogos").style.filter = "alpha(opacity='" + RHP.prototype.DisplayOptionCurrentOpacity + "');";
		$("sponsorsLogos").style.opacity = RHP.prototype.DisplayOptionCurrentOpacity/100;
		if (RHP.prototype.DisplayOptionCurrentOpacity > 0) {
			window.setTimeout(RHP.prototype.fadeOut, RHP.prototype.DisplayOptionFadeIn/(100/RHP.prototype.DisplayOptionStep));
		} else {
			RHP.prototype.fillUL();
			RHP.prototype.fadeIn();
		}
	} else {
		$("sponsorsLogos").style.filter = "alpha(opacity='100');";
		$("sponsorsLogos").style.opacity = 1.0;
		window.setTimeout(RHP.prototype.fadeOut, RHP.prototype.DisplayOptionShow);
	}
}
RHP.prototype.fillUL = function () {
	var images = new Array();
	/* Begin: Sorting Images */
	var recievedItems = RHP.prototype.response.getElementsByTagName("image");
	for (var i = 0; i < recievedItems.length; i++) {
		var currentImage = recievedItems[i];
		var currentImageSrc = currentImage.getElementsByTagName("src").item(0).firstChild.data;
		var currentImageUrl = currentImage.getElementsByTagName("url").item(0).firstChild.data;
		images.push(currentImageSrc);
	}
	shuffle(images);
	/* End: Sorting Images */

	var currentLIItems = $("sponsorsLogos").getElementsByTagName("li");
	for (var j = 0; j < RHP.prototype.maxImagesCount; j++) {
		for (var i = 0; i < recievedItems.length; i++) {
			var currentImage = recievedItems[i];
			var currentImageSrc = currentImage.getElementsByTagName("src").item(0).firstChild.data;
			var currentUrl = currentImage.getElementsByTagName("url").item(0).firstChild.data;
			if (currentImageSrc == images[j]) {
				var currentLinkObj = currentLIItems.item(j).firstChild;
				var currentImageObj = currentLinkObj.firstChild;
				
				var newImage = document.createElement("img");
				newImage.src = currentImageSrc;
				
				currentLinkObj.href = currentUrl;
				
				currentLinkObj.removeChild(currentImageObj);
				currentLinkObj.appendChild(newImage);
			}
		}
	}
}

function displayJeremyTab(linkObj) {
	var linksObjects = $("HWHJeremyTabs").getElementsByTagName("a");
	for (var i = 0; i < linksObjects.length; i++) {
		linksObjects[i].parentNode.className = linksObjects[i].parentNode.className.replace(new RegExp("\\s?selected"), "");
	}
	
	var tabs = getElementsByClassName("jRightColTabs", "tab");
	for (var i = 0; i < tabs.length; i++) {
		tabs[i].style.display = "none";
	}
	
	$(linkObj.rel).style.display = "block";
	linkObj.parentNode.className += " selected";
}

function createOverlayDiv() {
	var overlayDiv = document.createElement('div');
	overlayDiv.setAttribute('id','modalMaskDiv');
	overlayDiv.className = 'commonModalMask';
	if (isIe6()) {
		overlayDiv.style.width = (document.documentElement.clientWidth > document.body.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth) + 'px';
		overlayDiv.style.height = (document.documentElement.clientHeight > document.body.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight) + 'px';
		overlayIframe = document.createElement('iframe');
		overlayIframe.setAttribute('id','modalIframe');
		overlayIframe.style.width = (document.documentElement.clientWidth > document.body.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth) + 'px';
		overlayIframe.style.height = (document.documentElement.clientHeight > document.body.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight) + 'px';
		overlayDiv.appendChild(overlayIframe);
	}
	document.body.appendChild(overlayDiv);
	if (isIe6()) {
		addEvent(window, 'resize', function(){if($('modalMaskDiv')){$('modalMaskDiv').style.width = (document.documentElement.clientWidth > document.body.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth) + 'px'; $('modalMaskDiv').style.height = (document.documentElement.clientHeight > document.body.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight) + 'px';}});
	}
	return false;
}

function removeOverlayDiv() {
	document.body.removeChild($('modalMaskDiv'));
	return false;
}

function centerElement(element){
	if (element) {
		if (window.pageYOffset) {
			var top = window.pageYOffset;
		} else {
			var top = window.document.documentElement.scrollTop;
		}
		if (window.pageXOffset) {
			var left = window.pageXOffset;
		} else {
			var left = window.document.documentElement.scrollLeft;

		}
		element.style.top = Math.round(intval(top) + intval(document.documentElement.clientHeight)/2) + 'px';
		element.style.left = Math.round(intval(left) + intval(document.documentElement.clientWidth)/2) + 'px';
		if (isIe6()) {
			var width = document.documentElement.offsetWidth > document.body.offsetWidth ? document.documentElement.offsetWidth : document.body.offsetWidth;
			var height = document.documentElement.offsetHeight > document.body.offsetHeight ? document.documentElement.offsetHeight : document.body.offsetHeight
						+ (element.offsetHeight > document.documentElement.offsetHeight ? (element.offsetHeight - document.documentElement.offsetHeight)/2 : 0);
			if ($('modalMaskDiv')) {
				$('modalMaskDiv').style.width =  width + 'px';
				$('modalMaskDiv').style.height =  height + 'px';
			}
			if ($('modalIframe')) {
				$('modalIframe').style.width = width + 'px';
				$('modalIframe').style.height = height + 'px';
			}
		}
	}
	return false;
}

function createPopup(divToShow, closePopupClass) {
	if (typeof(divToShow) == 'string') {divToShow = $(divToShow);}
	if (!divToShow) { return false; }
	if (!closePopupClass) { closePopupClass = 'closePopup'; }
	var closingElements = getElementsByClassName(divToShow, closePopupClass);
	if (closingElements != null && closingElements.length > 0) {
		createOverlayDiv();
		for (var i = 0; i < closingElements.length; i++) {
			closingElements[i].onclick = function(){
				toggleClassName(divToShow, 'overlayPopupVisible');
				removeOverlayDiv();
				return false;
			}
		}
		toggleClassName(divToShow, 'overlayPopupVisible');
		divToShow.style.marginTop = '-' + Math.round(intval(divToShow.offsetHeight)/2) + 'px';
		divToShow.style.marginLeft = '-' + Math.round(intval(divToShow.offsetWidth)/2) + 'px';
		centerElement(divToShow);
		addEvent(window, 'resize', function(){ centerElement(divToShow) });
	}
	return false;
}

function processExternalLinks(){
	var externalLinks = getElementsByClassName(document.body, 'externalLink');
	if (externalLinks != null) {
		for (var i = 0; i < externalLinks.length; i++) {
			var externalLinkHref = externalLinks[i].href;
			externalLinks[i].onclick = function(evt){
				evt = evt || event;
				target = evt.target || evt.srcElement;
				while (target.tagName.toUpperCase() != 'A') {
					target = target.parentNode;
				}
				$('jumpPopupExtLink').href = target.href;
				return createPopup('jumpPopup');
			};
		}
	}
}

/*
 This class using some externally defined functions like toggleClassName, getElementsByClassName,  addEvent
*/

function feedbackFormValidator(){
	feedbackFormValidator.prototype.errorTimeout = {};
	feedbackFormValidator.prototype.checkField = function(field, reason) {
		var doValidate = false;
		for (i in feedbackFormValidator.prototype.fields[field]['validate']) {
			doValidate = doValidate || feedbackFormValidator.prototype.fields[field]['validate'][i][reason];
		}
		if (!doValidate) { return false; }
		if (!reason) { reason = 'onsubmit'; }
		feedbackFormValidator.prototype.fields[field]['isValid'] = true;
		if (feedbackFormValidator.prototype.fields[field]['validate']['maxChars'][reason]) {
			feedbackFormValidator.prototype.fields[field]['isValid'] = ($(field).value.length < intval(feedbackFormValidator.prototype.fields[field]['maxChars'])) && feedbackFormValidator.prototype.fields[field]['isValid'];
		}
		if (feedbackFormValidator.prototype.fields[field]['validate']['regEx'][reason]) {
			if(feedbackFormValidator.prototype.fields[field]['regExModificators']){
				var regExpObj = new RegExp(feedbackFormValidator.prototype.fields[field]['regEx'], feedbackFormValidator.prototype.fields[field]['regExModificators']);
			} else {
				var regExpObj = new RegExp(feedbackFormValidator.prototype.fields[field]['regEx']);
			}
			var regExpRes = $(field).value.match(regExpObj) != null;
			feedbackFormValidator.prototype.fields[field]['isValid'] = regExpRes && feedbackFormValidator.prototype.fields[field]['isValid'];
		}
		var parent = $(field).parentNode;
		while(parent.className.match(new RegExp("fieldHandler\\b")) == null) {
			parent = parent.parentNode;
		}
		if ((parent.className.match(new RegExp("error\\b")) == null) != feedbackFormValidator.prototype.fields[field]['isValid']) {
			if (feedbackFormValidator.prototype.errorTimeout[field]) {
				window.clearTimeout(feedbackFormValidator.prototype.errorTimeout[field]);
			}
			feedbackFormValidator.prototype.errorTimeout[field] = window.setTimeout(function(){toggleClassName(parent, 'error')},100);
		}
		feedbackFormValidator.prototype.isValid = feedbackFormValidator.prototype.isValid &&  feedbackFormValidator.prototype.fields[field]['isValid'];
	}
	
	feedbackFormValidator.prototype.checkFields = function(field) {
		feedbackFormValidator.prototype.isValid = true;
		for (field in feedbackFormValidator.prototype.fields) {
			feedbackFormValidator.prototype.checkField(field, 'onsubmit');
		}
		return feedbackFormValidator.prototype.isValid;
	}
	
	feedbackFormValidator.prototype.submit = function() {
		if (feedbackFormValidator.prototype.checkFields()) {
			feedbackFormValidator.prototype.form.submit();
		} else {
			return false;
		}
	};
	
	feedbackFormValidator.prototype.resetWarnings = function() {
		var fieldHandlers = getElementsByClassName(feedbackFormValidator.prototype.form,'fieldHandler');
		for (var i = 0; i < fieldHandlers.length; i++) {
			fieldHandlers[i].className=fieldHandlers[i].className.replace(new RegExp('error'+"\\b"), "");
		}
	}

	feedbackFormValidator.prototype.resetFields = function() {
		feedbackFormValidator.prototype.form.reset();
	}
	
	feedbackFormValidator.prototype.initActions = function() {
		var closingButtons = getElementsByClassName($('feedbackPopup'),'closePopup');
		for (var i = 0; i < closingButtons.length; i++) {
			addEvent(closingButtons[i],'click',function(){window.setTimeout(feedbackFormValidator.prototype.resetFields,100);});
			addEvent(closingButtons[i],'click',function(){window.setTimeout(feedbackFormValidator.prototype.resetWarnings,100);});
		}
	}

	feedbackFormValidator.prototype.initFields = function() {
		for (field in feedbackFormValidator.prototype.fields) {
			/*Value is not setting for select fields*/
			$(field).value = feedbackFormValidator.prototype.fields[field]['value'];
			/*
			$(field).onblur =
				function(evt){
					evt = evt || event;
					target = evt.target || evt.srcElement;
					feedbackFormValidator.prototype.checkField(target.id, 'onblur');
				};
			$(field).onkeyup =
				function(evt){
					evt = evt || event;
					target = evt.target || evt.srcElement;
					feedbackFormValidator.prototype.checkField(target.id, 'onkeyup');
				};
			*/
			
			
			var parent = $(field);
			while(parent.className.match(new RegExp("fieldHandler\\b")) == null) {
				parent = parent.parentNode;
			}
			var errorField = document.createElement('div');
			errorField.className = 'errorfld';					
			var errorFieldTxt = document.createTextNode(feedbackFormValidator.prototype.fields[field]['message']);
			errorField.appendChild(errorFieldTxt);
			parent.appendChild(errorField);
			
		}
	}

	feedbackFormValidator.prototype.form = $('feedbackForm');
	feedbackFormValidator.prototype.fields = {
			'email': {
				'regEx' : '^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$',
				'value' : '',
				'maxChars' : 255,
				'validate' : {
					'maxChars' : { 'onblur' : false, 'onkeyup' : false, 'onsubmit' : false },
					'regEx' : { 'onblur' : false, 'onkeyup' : false, 'onsubmit' : true }
				},
				'message' : 'Please enter your Email'
			},
			'comments': {
				'regEx' : '^(.+)$',
				'regExModificators' : 'm',
				'maxChars' : 500,
				'value' : '',
				'validate' : {
					'maxChars' : { 'onblur' : false, 'onkeyup' : false, 'onsubmit' : true },
					'regEx' : { 'onblur' : false, 'onkeyup' : false, 'onsubmit' : true }
				},
				'message' : 'Please enter Comments less than 500 chars'
			}
	};
	
	feedbackFormValidator.prototype.initFields();
	feedbackFormValidator.prototype.initActions();
}

function validateDDownload(fldOBJ) {
	var fieldsToValidate = {
		"firstname": "Please enter your First Name.",
		"lastname": "Please enter your Last Name.",
		"company": "Please enter your Company.",
		"email": "Please enter valid E-Mail."
	}
	
	var rowDivs = $("ddownloadform").getElementsByTagName("div");
	var isRowRE = new RegExp("\\s?row\\s?")
	var emailValidationRE = new RegExp("^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$");
	
	if (!fldOBJ) {
		var isFormError = false;
		var errorMessage = "";
		for (var rowDivID = 0; rowDivID < rowDivs.length; rowDivID++) {
			var currentRowDiv = rowDivs[rowDivID];
			if (isRowRE.test(currentRowDiv.className)) {
				currentRowDiv.className = currentRowDiv.className.replace(new RegExp("\\s?error\\s?"), "");

				var error_divs = currentRowDiv.getElementsByTagName("div");
				for (var error_div_id = 0; error_div_id < error_divs.length; error_div_id++) {
					var error_div = error_divs[error_div_id];
					if (error_div.className == "errorfld") {
						error_div.parentNode.removeChild(error_div);
					}
				}
			}
		}
		
		for (var fieldToValidate in fieldsToValidate) {
			for (var rowDivID = 0; rowDivID < rowDivs.length; rowDivID++) {
				var currentRowDiv = rowDivs[rowDivID];
				if (isRowRE.test(currentRowDiv.className)) {
					var inputElements = currentRowDiv.getElementsByTagName("input");
					if (inputElements.length > 0) {
						var currentInputElement = inputElements[0];
						
						if (currentInputElement.id == fieldToValidate) {
							var isError = false;
							if (fieldToValidate == "email") {
								if (!(currentInputElement.value != "" && emailValidationRE.test(currentInputElement.value))) {
									isFormError = isError = true;
									errorMessage = fieldsToValidate[fieldToValidate];
								}
							} else {
								if (currentInputElement.value == "") {
									isFormError = isError = true;
									errorMessage = fieldsToValidate[fieldToValidate];
								}
							}

							if (isError) {
								currentRowDiv.className += " error";
								var childValueElements = currentRowDiv.getElementsByTagName("div");
								for (var childElementID = 0; childElementID < childValueElements.length; childElementID++) {
									var valueDiv = childValueElements[childElementID];
									if (valueDiv.className == "value") {
										var error_div = document.createElement("div");
										error_div.className = "errorfld";
										error_div.appendChild(document.createTextNode(errorMessage));
										valueDiv.parentNode.insertBefore(error_div, valueDiv.nextSibling);
										break;
									}
								}
							}
						}
					}
				}
			}
		}
		return !isFormError;
	} else {
		var valueDivElement = fldOBJ.parentNode;
		var currentRowDiv = valueDivElement.parentNode;
		
		currentRowDiv.className = currentRowDiv.className.replace(new RegExp("\\s?error\\s?"), "");
		var error_divs = currentRowDiv.getElementsByTagName("div");
		for (var error_div_id = 0; error_div_id < error_divs.length; error_div_id++) {
			var error_div = error_divs[error_div_id];
			if (error_div.className == "errorfld") {
				currentRowDiv.removeChild(error_div);
			}
		}

		var isError = false;
		var errorMessage = fieldsToValidate[fldOBJ.id]
		
		if (fldOBJ.id == "email") {
			if (!(fldOBJ.value != "" && emailValidationRE.test(fldOBJ.value))) {
				isError = true;
			}
		} else if (fieldsToValidate[fldOBJ.id] != undefined) {
			if (fldOBJ.value == "") {
				isError = true;
			}
		}

		if (isError) {
			currentRowDiv.className += " error";
			if (valueDivElement.className == "value") {
				var error_div = document.createElement("div");
				error_div.className = "errorfld";
				error_div.appendChild(document.createTextNode(errorMessage));
				currentRowDiv.insertBefore(error_div, valueDivElement.nextSibling);
			}
		}
		return !isError;
	}
}

function validateLoginForm(fldOBJ) {
	var fieldsToValidate = {
		"username": "Please enter your Login.",
		"passwd": "Please enter your Password.",
		"usernamepasswd": "Please enter your Login and Password."
	}
	
	var errorMessage = ""; var isError = false;
	
	if ($("username").value == "" && $("passwd").value == "") {
		isError = true; errorMessage = fieldsToValidate["usernamepasswd"];
	} else if ($("username").value == "") {
		isError = true; errorMessage = fieldsToValidate["username"];
	} else if ($("passwd").value == "") {
		isError = true; errorMessage = fieldsToValidate["passwd"];
	}
	
	/* Remove Error Messages */
	$("myoa").className = $("myoa").className.replace(new RegExp("\\s?error\\s?"), "")
	var isErrorRE = new RegExp("\\s?errormsg\\s?")
	var errorDivs = $("myoa").getElementsByTagName("div");
	for (var i = 0; i < errorDivs.length; i++) {
		var currentErrorDiv = errorDivs[i];
		if (isErrorRE.test(currentErrorDiv.className)) {
			$("myoa").removeChild(currentErrorDiv);
		}
	}
	
	if (isError) {
		$("myoa").className += " error";
		var error_div = document.createElement("div");
		error_div.className = "errormsg";
		error_div.appendChild(document.createTextNode(errorMessage));
		$("loginrow").parentNode.insertBefore(error_div, $("loginrow").nextSibling);
	}

	return !isError;
}

addEvent(window,'unload',EventCache.flush);
