var	indicator_img_path = "/advisors/indicator.gif";
var LightBox = {
	opacity_level : 8,
	ibAttr : "rel",
	loadCancelled : false,
	lbox_w_height : 0,
	imgPreloader : null,
	indicator_img_html : null,	
	http : null,
	init: function(){
		LightBox.imgPreloader = new Image();
		LightBox.indicator_img_html = "<img name=\"lbox_indicator\" src=\""+indicator_img_path+"\" alt=\"Loading...\" style=\"width:128px;height:128px;\"/>";
		LightBox.http = LightBox.createRequestObject();
		document.onkeydown = function(e){   
			if (e == null) {
				keycode = event.keyCode;
			} else {
				keycode = e.which;
			}
			if(keycode == 27){
				LightBox.hideLbox();
				LightBox.hideIndicator();
				LightBox.loadCancelled = true;
			}
		};		
		var elem_wrapper = "lbox";	
		LightBox.createLbox(document.getElementsByTagName("body")[0]); //create our lbox
		//var docRoot = (document.all) ? document.all : document.getElementsByTagName("*");
		var docRoot = document.getElementsByTagName("a");
		var e;
		for (var i = 0; i < docRoot.length - 1; i++) {
			e = docRoot[i];
			if(e.getAttribute(LightBox.ibAttr)) {
				var t = e.getAttribute(LightBox.ibAttr);
				if ((t.indexOf("lbox") != -1)  ||  t.toLowerCase() == "lbox") { // check if this element is an iBox element
					e.onclick = function() { // rather assign an onclick event
						var t = this.getAttribute(LightBox.ibAttr);
						var params = LightBox.parseQuery(t.substr(5,999));
						var url = this.href;
						if(this.target != "") {url = this.target} 
						var title = this.title;
						if(LightBox.showLbox(url,title,params)) {
							LightBox.showBG();
							window.onscroll = LightBox.maintPos;
							window.onresize = LightBox.maintPos;
						}
						return false;
					}; 
				}
			}
		}
	},
	showBG : function() {
		var box_w = $id('lbox_w');
		box_w.style.opacity = 0;
		box_w.style.filter = 'alpha(opacity=0)';
		setBGOpacity = LightBox.setOpacity;
		for (var i=0;i<=LightBox.opacity_level;i++) {setTimeout("setLboxOpacity('lbox_w',"+i+")",70*i);} // from quirksmode.org
		box_w.style.display = "";
		var pagesize = new LightBox.getPageSize();
		var scrollPos = new LightBox.getScrollPos();
		var ua = navigator.userAgent;
		if(ua.indexOf("MSIE ") != -1) {box_w.style.width = pagesize.width+'px';} 
		/*else {box_w.style.width = pagesize.width-20+'px';}*/ // scrollbars removed! Hurray!
		box_w.style.height = pagesize.height+scrollPos.scrollY+'px';
	},
	hideBG : function() {
		var box_w = $id('lbox_w');
		box_w.style.display = "none";
	},
	showIndicator : function() {
		var lbox_p = $id('lbox_progress');
		lbox_p.style.display = "";
		LightBox.posToCenter(lbox_p);
		lbox_p.onclick = function() {LightBox.hideLbox();LightBox.hideIndicator();LightBox.loadCancelled = true;}
	},
	hideIndicator : function() {
		var lbox_p = $id('lbox_progress');
		lbox_p.style.display = "none";
		lbox_p.onclick = null;
	},
	createLbox : function(elem) {
		var strHTML = "<div id=\"lbox_w\" style=\"display:none;\"></div>";
		strHTML +=	"<div id=\"lbox_progress\" style=\"display:none;\">";
		strHTML +=  LightBox.indicator_img_html;
		strHTML +=  "</div>";
		strHTML +=	"<div id=\"lbox_wrapper\" style=\"display:none\">";
		strHTML +=	"<div id=\"lbox_content\"></div>";
		strHTML +=	"<div id=\"lbox_footer_wrapper\"><div id=\"lbox_close\" style=\"float:right;\">";
		strHTML +=	"<a id=\"lbox_close_a\" href=\"javascript:void(null);\" >close</a> or Esc Key</div>";
		strHTML +=  "<div id=\"lbox_footer\">&nbsp;</div></div></div></div>";
		var docBody = document.getElementsByTagName("body")[0];
		var lbox = document.createElement("div");
		lbox.setAttribute("id","lbox");
		lbox.style.display = '';
		lbox.innerHTML = strHTML;
		elem.appendChild(lbox);
	},
	showLbox : function(url,title,params) {
		var lbox = $id('lbox_wrapper');
		var lbox_type = 0;
		var lbox_footer = $id('lbox_footer');
		if(title != "") {lbox_footer.innerHTML = title;} else {lbox_footer.innerHTML = "&nbsp;";}
		var urlString = /\.jpg|\.jpeg|\.png|\.gif|\.html|\.htm|\.php|\.cfm|\.asp|\.aspx|\.jsp|\.jst|\.rb|\.rhtml|\.txt/g;
		var urlType = url.match(urlString);
		if(urlType == '.jpg' || urlType == '.jpeg' || urlType == '.png' || urlType == '.gif'){
			lbox_type = 1;
		} else if(url.indexOf("#") != -1) {
			lbox_type = 2;
		} else if(urlType=='.htm'||urlType=='.html'||urlType=='.php'||
				 urlType=='.asp'||urlType=='.aspx'||urlType=='.jsp'||
				 urlType=='.jst'||urlType=='.rb'||urlType=='.txt'||urlType=='.rhtml'||
				 urlType=='.cfm') {
			lbox_type = 3;
		} else {
			// override our lbox type if forced param exist
			if(params['type']) {
				lbox_type = parseInt(params['type']);
			}else{
				LightBox.hideLbox();return false;
			}
		}
		lbox_type = parseInt(lbox_type);
		switch(lbox_type) {
			case 1:
				LightBox.showIndicator();
				LightBox.imgPreloader = new Image();
				LightBox.imgPreloader.onload = function(){
					LightBox.imgPreloader = LightBox.resizeImageToScreen(LightBox.imgPreloader);
					LightBox.hideIndicator();
					var strHTML = "<img name=\"lbox_img\" src=\""+url+"\" style=\"width:"+LightBox.imgPreloader.width+"px;height:"+LightBox.imgPreloader.height+"px;border:0;cursor:hand;margin:0;padding:0;position:absolute;\"/>";
					if(LightBox.loadCancelled == false) {
						// set width and height
						lbox.style.height = LightBox.imgPreloader.height+'px';
						lbox.style.width = LightBox.imgPreloader.width+'px';
						lbox.style.display = "";
						lbox.style.visibility = "hidden";
						LightBox.posToCenter(lbox); 	
						lbox.style.visibility = "visible";
						LightBox.setIBoxContent(strHTML);
					}
				}
				LightBox.loadCancelled = false;
				LightBox.imgPreloader.src = url;
				break;
			case 2:
				var strHTML = "";
				if(params['height']) {
					lbox.style.height = params['height']+'px';
				}else {
					lbox.style.height = '280px';
				}
				if(params['width']) {
					lbox.style.width = params['width']+'px';
				}else {
					lbox.style.width = '450px';
				}
				lbox.style.display = "";
				lbox.style.visibility = "hidden";
				LightBox.posToCenter(lbox); 	
				lbox.style.visibility = "visible";
				$id('lbox_content').style.overflow = "auto";
				var elemSrcId = url.substr(url.indexOf("#") + 1,1000);
				var elemSrc = $id(elemSrcId);
				if(elemSrc) {strHTML = elemSrc.innerHTML;}
				LightBox.setIBoxContent(strHTML);
				break;
			case 3:
				LightBox.showIndicator();
	//			var ajax = new Core.Ajax();
	//			ajax.doGet(url,openWindow);
				LightBox.http.open('get',url,true);
				LightBox.http.onreadystatechange = function() {
					if(LightBox.http.readyState == 4){
						LightBox.hideIndicator();
						if(params['height']) {lbox.style.height = params['height']+'px';} 
						else {lbox.style.height = '280px';}
						if(params['width']) {lbox.style.width = params['width']+'px';} 
						else {lbox.style.width = '450px';}
						lbox.style.display = "";
						lbox.style.visibility = "hidden";
						LightBox.posToCenter(lbox); 	
						lbox.style.visibility = "visible";
						$id('lbox_content').style.overflow = "auto";
						var response = LightBox.http.responseText;
						LightBox.setIBoxContent(response);
					}
				}
				LightBox.http.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
				LightBox.http.send(null);
				break;
			default:
		} 
		lbox.style.opacity = 0;
		lbox.style.filter = 'alpha(opacity=0)';	
		var lbox_op_level = 10;
		setLboxOpacity = LightBox.setOpacity;
		for (var i=0;i<=lbox_op_level;i++) {setTimeout("setLboxOpacity('lbox_wrapper',"+i+")",30*i);}
		if(lbox_type == 2 || lbox_type == 3) {
			lbox.onclick = null;$id("lbox_close_a").onclick = function() {LightBox.hideLbox();}
		} else {
			//lbox.onclick = LightBox.hideLbox();$id("lbox_close_a").onclick = null;
			lbox.onclick = function() {LightBox.hideLbox();}
			$id("lbox_close_a").onclick = function() {LightBox.hideLbox();}
		}
		return true;
	},
	openWindow : function(str){
		LightBox.hideIndicator();
		if(params['height']) {
			lbox.style.height = params['height']+'px';
		}else {
			lbox.style.height = '280px';
		}
		if(params['width']) {
			lbox.style.width = params['width']+'px';
		}else {
			lbox.style.width = '450px';
		}
		lbox.style.display = "";
		lbox.style.visibility = "hidden";
		LightBox.posToCenter(lbox); 	
		lbox.style.visibility = "visible";
		$id('lbox_content').style.overflow = "auto";
		LightBox.setIBoxContent(str);
	},
	setOpacity : function (elemid,value){
		var e = $id(elemid);
		e.style.opacity = value/10;
		e.style.filter = 'alpha(opacity=' + value*10 + ')';
	},
	resizeImageToScreen : function(objImg) {
		var pagesize = new LightBox.getPageSize();
		var x = pagesize.width - 100;
		var y = pagesize.height - 100;
		if(objImg.width > x) { 
			objImg.height = objImg.height * (x/objImg.width); 
			objImg.width = x; 
			if(objImg.height > y) { 
				objImg.width = objImg.width * (y/objImg.height); 
				objImg.height = y; 
			}
		} else if(objImg.height > y) { 
			objImg.width = objImg.width * (y/objImg.height); 
			objImg.height = y; 
			if(objImg.width > x) { 
				objImg.height = objImg.height * (x/objImg.width); 
				objImg.width = x;
			}
		}
		return objImg;
	},
	maintPos : function() {
		var lbox = $id('lbox_wrapper');
		var box_w = $id('lbox_w');
		var pagesize = new LightBox.getPageSize();
		var scrollPos = new LightBox.getScrollPos();
		var ua = navigator.userAgent;
		if(ua.indexOf("MSIE ") != -1) {box_w.style.width = pagesize.width+'px';} 
		/*else {box_w.style.width = pagesize.width-20+'px';}*/
		if(ua.indexOf("Opera/9") != -1) {box_w.style.height = document.body.scrollHeight+'px';}
		else {box_w.style.height = pagesize.height+scrollPos.scrollY+'px';}
		// alternative 1
		//box_w.style.height = document.body.scrollHeight+50+'px';	
		LightBox.posToCenter(lbox);
	},
	hideLbox : function() {
		LightBox.hideBG();
		var lbox = $id('lbox_wrapper');
		lbox.style.display = "none";
		LightBox.clearLboxContent();
		window.onscroll = null;
	},
	posToCenter : function(elem) {
		var scrollPos = new LightBox.getScrollPos();
		var pageSize = new LightBox.getPageSize();
		var emSize = new LightBox.getElementSize(elem);
		var x = Math.round(pageSize.width/2) - (emSize.width /2) + scrollPos.scrollX;
		var y = Math.round(pageSize.height/2) - (emSize.height /2) + scrollPos.scrollY;	
		elem.style.left = x+'px';
		elem.style.top = y+'px';	
	},
	getScrollPos : function() {
		var docElem = document.documentElement;
		this.scrollX = self.pageXOffset || (docElem&&docElem.scrollLeft) || document.body.scrollLeft;
		this.scrollY = self.pageYOffset || (docElem&&docElem.scrollTop) || document.body.scrollTop;
	},
	getPageSize : function() {
		var docElem = document.documentElement
		this.width = self.innerWidth || (docElem&&docElem.clientWidth) || document.body.clientWidth;
		this.height = self.innerHeight || (docElem&&docElem.clientHeight) || document.body.clientHeight;
	},
	getElementSize : function(elem) {
		this.width = elem.offsetWidth ||  elem.style.pixelWidth;
		this.height = elem.offsetHeight || elem.style.pixelHeight;
	},
	setIBoxContent : function(str) {
		LightBox.clearLboxContent();
		var e = $id('lbox_content');
		e.style.overflow = "auto";
		e.innerHTML = str;
	},
	clearLboxContent : function() {
		var e = $id('lbox_content');
		e.innerHTML = "";
	},
	parseQuery : function(query) {
		var Params = new Object ();
		if (!query) return Params; 
		var Pairs = query.split(/[;&]/);
		for ( var i = 0; i < Pairs.length; i++ ) {
			var KeyVal = Pairs[i].split('=');
			if ( ! KeyVal || KeyVal.length != 2 ) continue;
			var key = unescape( KeyVal[0] );
			var val = unescape( KeyVal[1] );
			val = val.replace(/\+/g, ' ');
			Params[key] = val;
		}
		return Params;
	},
	createRequestObject : function() {
		var xmlhttp;
			/*@cc_on
		@if (@_jscript_version>= 5)
				try {xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
				} catch (e) {
						try {xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");}
						catch (E) {xmlhttp = false;}
				}
		@else
			xmlhttp = false;
		@end @*/
		if (!xmlhttp && typeof XMLHttpRequest != "undefined") {
				try {xmlhttp = new XMLHttpRequest();} catch (e) {xmlhttp = false;}
		}
		return xmlhttp;
	}
}
var Tab = {
	tabClass: "tabmenu",
	init: function(){
		var first = 1;
		var tabs = Core.getElementsByClass("tabmenu");
		for (var i = 0; i < tabs.length; i++){
			var folds = tabs[i].childNodes;
			for (var j = 0; j < folds.length; j++){
				if (folds[j].nodeType == 1){
					var foldLinks = folds[j].getElementsByTagName("a");
					var foldTitleLink = foldLinks[0];
					Core.addEventListener(foldTitleLink, "click", Tab.clickListener);
					for (var k = 1; k < foldLinks.length; k++){
						Core.addEventListener(foldLinks[k], "focus", Tab.focusListener);
					}
					Tab.collapse(foldTitleLink);
					if( first == 1){
						Core.addClass(foldTitleLink, "active-tab");
						Core.addClass( $id( Tab.tabID(foldTitleLink) ),'active-tab-body');
					}
					first = 0;
				}
			}
		}
	},
	collapse: function(fold){
		if( Core.hasClass(fold,"active-tab") ){
			Core.removeClass(fold, "active-tab");
			Core.removeClass( $id( Tab.tabID(fold) ),'active-tab-body');
			Core.addClass( $id( Tab.tabID(fold) ),'panel');
		}
	},
	collapseAll: function(tab){
		var tabs = Core.getElementsByClass("tabmenu");
		for (var i = 0; i < tabs.length; i++){
			var folds = tabs[i].childNodes;
			for (var j = 0; j < folds.length; j++){
				if (folds[j].nodeType == 1){
					var foldLinks = folds[j].getElementsByTagName("a");
					var foldTitleLink = foldLinks[0];
					Tab.collapse(foldTitleLink);
				}
			}
		}
	},
	expand: function(fold){
		Tab.collapseAll(fold.parentNode);
		Core.addClass(fold, "active-tab");
		Core.addClass( $id( Tab.tabID(fold) ),'active-tab-body');
		if( Tab.tabID(fold) == "tab1" ){
			$id("msgPanel").style.display = "none";
			$id("returnPanel").style.display = "none";
			$id("searchForm").style.display = "";
			$id("resultsPanel").style.display = "none";
			$id("buttonPanel").style.display = "none";
		}		
	},
	tabID : function(elm) {
		return elm.href.match(/#(\w.+)/)[1];
	},	
	clickListener: function(event){
		var fold = this;
		if (Core.hasClass( fold, "active-tab")){
//			Tab.collapse(fold);
		}else{
			Tab.expand(fold);
		}
		Core.preventDefault(event);
	},
	focusListener: function(event){
		var element = this;
		while (element.parentNode){
			if (element.parentNode.className == "tab"){
				Tab.expand(element);
				return;
			}
			element = element.parentNode;
		}
	}
}
var AdvisorsWidget = {
	currentRecord : 0,
	pagingSize : 50,
	recordCount : 0,
	previousPage : null,
	currentPage : null,
	nextPage : null,
	active : false,
	fadeIncr : 0,
	fadeDiv : null,
	statusInterval : 0,
	timera : null,
	init: function(){
/*	
		var newP = document.createElement("p");
		newP.setAttribute("id", "success");
		newP.appendChild(document.createTextNode("Testing the Advisors Widget."));
		$id("advisorsWidget").appendChild(newP);
*/		
	},
	style : function(){
		var style = "<style>\n";
		style += "#lbox_w{position: absolute;top: 0px;left: 0px;z-index:100;width: 100%;height: 100%;background-color: #000;margin:0;padding:0;filter:alpha(opacity=0);-moz-opacity: 0.0;opacity: 0.0;}\n";
		style += "#lbox_progress {margin:0;padding:0;position: absolute;z-index:105;}\n";
		style += "#lbox_wrapper {	position: absolute;top: 0px;left: 0px;z-index:1000;padding:10px;border:1px solid #CCC;width:300px;height:300px;	background-color:#999999;padding-bottom:30px;margin:0;}\n";
		style += "#lbox_content {	background-color:#FFFFFF;width:100%;height:100%;margin-bottom:5px;position:relative;top:0px;left:0px;border:1px solid #000;padding:2px;}\n";
		style += "#lbox_footer_wrapper {	position:relative;padding:0;margin:0;top:0px;left:0px;}\n";
		style += "img { behavior: url(images/iepngfix.htc);border:none;}\n";
		style += "#container, #top, #bottom, #footer{margin:0 auto;width:690px;}\n";
		style += "#top, #bottom{width:700px;height:10px !important;display:block !important;}\n";
		style += "#top{margin-top:10px;}\n";
		style += "#mainmenu {float:right;padding:0px;margin:0px; border-collapse:collapse;}\n";
		style += "#tabs {float:right;position: relative;list-style: none;margin-bottom:0px;padding-bottom:0px;}\n";
		style += "#tabs li {float: left;margin-bottom:0px;}\n";
		style += "#tabs a {float: left;padding: 5px 8px;margin-left: 1px;background-color: #B7A35E;text-decoration: none;color: #FFFFFF;border:1px #000 solid;margin-bottom:0px;border-collapse:collapse;}\n";
		style += "#tabs a.active-tab {background-color: #FFF;color: #000000;border:1px #000 outset;border-bottom:0px #fff solid;margin-bottom:0px;border-collapse:collapse;}\n";
		style += ".panel {display: none;background-color: #ffffff;padding: 1em;border:0px solid #000000;min-height:700px;margin-top:0px;}\n";
		style += ".panel.active-tab-body {display: block;margin:0px;}\n";
		style += ".tabform {float: left;clear: left;width: 100%;margin: 0 0 1.5em 0;padding: 0;}\n";
		style += ".tabform ol{padding: 1em 1em 0 1em;list-style: none;zoom: 1;}\n";
		style += ".tabform li{float: left;clear: left;width: 100%;padding-bottom: 1em;}\n";
		style += ".tabform label{float: left;width: 15em;margin-right: 1em;font-weight:400;}\n";
		style += ".submit{float: none;width: 15em;border: 0 none #000000;}\n";
		style += "#resultsDiv {padding:10px;border: 0px #ccc solid;border-collapse:collapse;font-size:10px;}\n";
		style += "#resultsDiv table {padding:10px;border: 1px #ccc solid;border-collapse:collapse;}\n";
		style += "#resultsDiv thead {padding:10px;border: 1px #ccc solid;border-collapse:collapse;}\n";
		style += "#resultsDiv thead th {padding:10px;border: 1px #ccc solid;border-collapse:collapse;font-size:10px;}\n";
		style += "#resultsDiv thead td {padding:10px;border: 1px #ccc solid;border-collapse:collapse;font-size:10px;}\n";
		style += "#resultsDiv tbody {padding:10px;border: 1px #ccc solid;border-collapse:collapse;}\n";
		style += "#resultsDiv tbody th {padding:10px;border: 1px #ccc solid;border-collapse:collapse;font-size:10px;}\n";
		style += "#resultsDiv tbody td {padding:10px;border: 1px #ccc solid;border-collapse:collapse;font-size:10px;}\n";
		style += "#resultsDiv th {padding:10px;border: 1px #ccc solid;border-collapse:collapse;font-size:10px;}\n";
		style += "#resultsDiv td{padding:10px;border: 1px #ccc solid;border-collapse:collapse;font-size:10px;}\n";
		style += ".buttons a, .buttons button{font-family:\"Lucida Grande\", Tahoma, Arial, sans-serif;float:left;margin:0 7px 0 0;text-decoration:none;background-color:#f5f5f5;border:1px solid #dedede;border-right:1px solid #bbb;border-bottom:1px solid #BFBFBF;padding:5px 10px 6px 10px;display:block;cursor:pointer;font-size:100%;line-height:130%;color:#333;font-weight:bold;-moz-border-radius:12px;-webkit-border-radius:12px;}\n";
		style += ".buttons button{width:auto;overflow:visible;font-weight:bold;padding:4px 10px 3px 7px; /* IE */}\n";
		style += ".buttons button[type]{width:auto;padding:4px 10px 5px 7px; /* Firefox */line-height:18px; /* Safari */}\n";
		style += "*:first-child+html .buttons button[type]{padding:4px 10px 3px 7px; /* IE7 */}\n";
		style += ".buttons button img, .buttons a img{margin:0 3px -3px 0 !important;width:16px;height:16px;}\n";
		style += ".buttons button:hover, .buttons a:hover{background-color:#dff4ff;border:1px solid #A7CEDF;color:#336699;}\n";
		style += ".buttons a:active{background-color:#6299c5;border:1px solid #6299c5;color:#fff;}\n";
		style += ".buttons button.positive, .buttons a.positive{color:#529214;}\n";
		style += ".buttons a.positive:hover, .buttons button.positive:hover{background-color:#E9EFD1;border:1px solid #AACF81;color:#529214;}\n";
		style += ".buttons a.positive:active{background-color:#529214;border:1px solid #529214;color:#fff;}\n";
		style += ".buttons a.negative, .buttons button.negative{color:#d12f19;}\n";
		style += ".buttons a.negative:hover, .buttons button.negative:hover{background:#fbe3e4;border:1px solid #EF959B;color:#d12f19;}\n";
		style += ".buttons a.negative:active{background-color:#d12f19;border:1px solid #d12f19;color:#fff;}\n";
		style += ".info .buttons{float:right;margin:6px 0 0 0;padding:0;}\n";
		style += ".info .buttons a{margin:0 0 0 7px;}\n";
		style += "input.btTxt{padding:0 7px;width:auto;overflow:visible;}\n";
		style += ".buttons{clear:both;margin-top:10px;}\n";
		style += ".buttons input{font-size:120%;margin-right: 5px;}\n";
		style += "</style>";
		return style;
	},
	tabMenu : function(){
		var menu = "<div id='mainmenu'>\n";
		menu += "<ul id='tabs' class='tabmenu'>\n";
		menu += "<li><a href='#tab1'>Find An Advisor</a></li>\n";
		menu += "<li><a href='#tab2'>Recommend an Advisor</a></li>\n";
		menu += "</ul>\n";
		menu += "</div>";
		menu += "<div style='height:0px;clear: both;'></div>\n";
		return menu;
	},
	openContainer: function(){
		var div = "";
//		div += "<div id=\"container\" style=\"padding:10px;\">\n";
//		div += "<img id=\"top\" src=\"images/top.png\" />\n";
		return div;
	},
	closeContainer: function(){
		var div = "";
//		div += "<img id=\"bottom\" src=\"images/bottom.png\" />\n";
//		div += "</div><!--container-->\n";
		return div;
	},
	tab1 : function(){
		var tab = "";
		tab += "<div class='panel' id='tab1'>\n";
		tab += "	<p>The following advisors have been recommended by members of our community, but the information about their backgrounds and performance has not been independently verified by WME.  This database is meant as an aid to help you to develop a short list of potential advisors but you should evaluate the advisors and make your own determination.  To assist you, we have assembled relevant articles and tools in our Selecting and Monitoring Advisors Information Center.</p>\n";
		tab += "	<p>If you are an advisor and wish to be listed, send an invitation to your clients asking them if they would be willing to sponsor and recommend you and direct them to the \"recommend an advisor\" page.</p>\n";
		tab += "	<p>Advisors with low ratings are excluded from the list.</p>\n";
		tab += "	<div id='msgPanel' style='display:none;'></div>\n";
		tab += "	<div id='returnPanel' style='display:none;'>Here are your search results, click on the advisor's name to see their full profile</div>\n";
		tab += "	<p><form id='searchForm' class='tabform'>\n";
		tab += "	<ol>\n";
		tab += "		<li><label for='type'>Type of Advisor:</label><select name='type' id='type'><option value=''>---</option><option value='0'>Accountant</option><option value='1' SELECTED>Wealth & Investment Advisors</option><option value='2'>Lawyer</option><option value='3'>Insurance</option><option value='4'>Trust Companies</option><option value='5'>Multi-Family Offices</option><option value='6'>Philanthropy Advisors</option></select>\n";
		tab += "		<li><label for='req'>Speciality Required:</label><select name='req' id='req'></select>\n";
//		tab += "		<li><label for='zip'>Geographic Preference:</label>";
//		tab += "		<small>City:</small> <input type='text' id='city' name='city' />&nbsp;";
//		tab += "		<small>State:</small> <input type='text' id='zip' name='zip' maxlength=2 size=2/>\n";";
		tab += "		<li><label for='zip'>State:</label> <input type='text' id='zip' name='zip' maxlength=2 size=2/>\n";
		tab += "		<li class='buttons'>\n";
		tab += "			<button class='positive' id='saveForm' type='submit'>Search</button>\n";
		tab += "		</li>";
		tab += "	</ol>\n";
		tab += "	</form><p>\n";
		tab += "	<div id='resultsPanel' style='display:none;'></div>\n";		
		tab += "	<div id='buttonPanel' style='display:none;'>\n";
		tab += "		<table width=100%>\n";
		tab += "		<tr>\n";
		tab += "			<td  class='buttons'><button class='positive' onclick='AdvisorsWidget.getPreviousPage(); return false;' id='previousLink'>Previous</button></td>\n";
		tab += "			<td><div id='currentRec'></div></td>\n";
		tab += "			<td  class='buttons'><button class='positive' onclick='AdvisorsWidget.getNextPage(); return false;' id='nextLink'>Next</button></td>\n";
		tab += "			<td  class='buttons'><button class='positive' onclick='AdvisorsWidget.newSearch(); return false;' id='nextLink'>New Search</button></td>\n";
		tab += "		</tr>\n";
		tab += "		</table>\n";
		tab += "	</div>\n";
		tab += "</div>\n";
		return tab;
	},
	tab2 : function(){
		var tab = "";
		tab += "<div class='panel' id='tab2'>\n";
		tab += "	<p id='adrecpara'>Do you have an advisor (or multiple advisors) who you would recommend (or recommend we exclude from our list?).  Please share your experiences with others in your community.</p>\n";
		tab += "	<form id='adrecForm' class='tabform'>\n";
		tab += "	<ol>\n";
		tab += "		<li><label for='adtype'>Type of Advisor:</label><select name='adtype' id='adtype'><option value=''>---</option><option value='0'>Accountant</option><option value='1' SELECTED>Wealth & Investment Advisors</option><option value='2'>Lawyer</option><option value='3'>Insurance</option><option value='4'>Trust Companies</option><option value='5'>Multi-Family Offices</option><option value='6'>Philanthropy Advisors</option></select>\n";
		tab += "		<li><label for='speciality'>Area of Speciality:</label><select name='speciality' id='speciality'></select>\n";
		tab += "		<li><label for='name'>Advisor's Name:</label><input type='text' id='name' name='name' />\n";
		tab += "		<li><label for='firm'>Advisor's Firm Name:</label><input type='text' id='firm' name='firm' />\n";
		tab += "		<li>Advisor's Location:<ol>\n";		
		tab += "		<li><label for='city'>Advisor's City:</label><input type='text' id='city' name='city' />\n";
		tab += "		<li><label for='state'>Advisor's State:</label><input type='text' id='state' name='state' />\n";
		tab += "		<li><label for='location'>Advisor's Zipcode:</label><input type='text' id='location' name='location' />\n";		
		tab += "		</ol></li>";
		tab += "		<li>Advisor's Contact Info:<ol>\n";
		tab += "		<li><label for='phone'>Advisor's Phone:</label><input type='text' id='phone' name='phone' />\n";
		tab += "		<li><label for='email'>Advisor's Email Address:</label><input type='text' id='email' name='email' />\n";		
		tab += "		</ol></li>";
		tab += "		<li><label for='certs'>Advisor's Certifications:</label><input type='text' id='certs' name='certs' />\n"
		tab += "		<li>If you are not the Advisor:<ol>\n";
		tab += "		<li><label for='rate'>How would you rate this advisor on a 1-5 scale?</label><select name='rate' id='rate'><option value='5'>5 - Outstanding</option><option value='4'>4- Very Good</option><option value='3'>3 - Good</option><option value='2'>2 - Fair</option><option value='1'>1 - Poor</option></select>\n";
		tab += "		<li><label for='email2'>Please enter your e-mail address so we can prevent multiple votes per member:</label><input type='text' id='email2' name='email2' />\n";
		tab += "		</ol></li>";
		tab += "	</ol>\n";
		tab += "	<p>(We will protect your privacy and not share your e-mail address with anyone).</p>\n";		
		tab += "	<div class='buttons'>\n";
		tab += "			<button class='positive' id='saveForm' type='submit'>Submit</button>\n";
		tab += "	</div>";
		tab += "	</form>\n";
		tab += "</div>\n";
		return tab;
	},
	setListeners : function(){
	    Core.addEventListener( $id("searchForm"), "submit", AdvisorsWidget.doSearch);
	    Core.addEventListener( $id("adrecForm"), "submit", AdvisorsWidget.newAdvisor);
		Core.addEventListener( $id("type"), "change", AdvisorsWidget.getArea);
		Core.addEventListener( $id("adtype"), "change", AdvisorsWidget.getArea2);
	},
	getArea : function(){
		var element = $id("type");
//		alert( element.value );
		if( element.value != "" ){
			var parameters = "cmd=area&type=" + element.value;
			var ajax = new Core.Ajax();
			ajax.doPost("/advisors/remote.php",  parameters, AdvisorsWidget.newArea);
		}
	},
	getArea2 : function(){
		var element = $id("adtype");
		if( element.value != "" ){
			var parameters = "cmd=area&type=" + element.value;
			var ajax = new Core.Ajax();
			ajax.doPost("/advisors/remote.php",  parameters, AdvisorsWidget.newArea2);
		}
	},
	newArea : function(str){
		currentList = Core.JSON.parse(str);
		AdvisorsWidget.drawSelect(currentList,$id("req"));
	},
	newArea2 : function(str){
		currentList = Core.JSON.parse(str);
		AdvisorsWidget.drawSelect(currentList,$id("speciality"));
	},
	drawSelect : function(list,selBox){
		if( selBox.length > 0 ){
			var i;
			for (i = selBox.length - 1; i>=0; i--) {
				selBox.remove(i);
			}
		}
		var result = document.createElement('option');
		result.setAttribute('value', 0);
		result.appendChild( document.createTextNode("Please select an area of speciality") );
		selBox.appendChild(result);
		for(i = 0; i < list['areas'].length; i++) {
			var result = document.createElement('option');
			result.setAttribute('value', list['areas'][i].id);
			result.appendChild( document.createTextNode(list['areas'][i].area) );
			selBox.appendChild(result);
		}
	},
	doSearch : function(event){
//		event.preventDefault();
		var form = $id("searchForm");
		AdvisorsWidget.getRecordCount();
		AdvisorsWidget.getTableData();
		AdvisorsWidget.displayMsg("Your search has been submitted..",500);
		form.style.display = "none";
		Core.preventDefault(event);
//		AdvisorsWidget.startStatusAnim("success");
	},
	getRecordCount : function(){
		var form = $id("searchForm");
		var parameters = "cmd=getRecordCount";
		var sparam = "";
		var formElements = [];
		var textareas = form.getElementsByTagName("textarea");
		for (var i = 0; i < textareas.length; i++){
			formElements[formElements.length] = textareas[i];
		}
		var selects = form.getElementsByTagName("select");
		for (var i = 0; i < selects.length; i++){
			formElements[formElements.length] = selects[i];
		}
		var inputs = form.getElementsByTagName("input");
		for (var i = 0; i < inputs.length; i++){
			var inputType = inputs[i].getAttribute("type");
			if (inputType == null || inputType == "text" || inputType == "hidden" || (typeof inputs[i].checked != "undefined" && inputs[i].checked == true)){
				formElements[formElements.length] = inputs[i];
			}
		}
		for (var i = 0; i < formElements.length; i++){
			var elementName = formElements[i].getAttribute("name");
			if (elementName != null && elementName != ""){
				parameters += "&" + elementName + "=" + encodeURIComponent(formElements[i].value);
			}
		}
		var ajax = new Core.Ajax();
		ajax.doGet( ("/advisors/remote.php?"+ parameters), function(str) {AdvisorsWidget.recordCount = str;} );
	},
	getTableData : function() {
		var form = $id("searchForm");
		var parameters = "cmd=search&current="+AdvisorsWidget.currentRecord+"&size="+AdvisorsWidget.pagingSize;
		var formElements = [];
		var textareas = form.getElementsByTagName("textarea");
		for (var i = 0; i < textareas.length; i++){
			formElements[formElements.length] = textareas[i];
		}
		var selects = form.getElementsByTagName("select");
		for (var i = 0; i < selects.length; i++){
			formElements[formElements.length] = selects[i];
		}
		var inputs = form.getElementsByTagName("input");
		for (var i = 0; i < inputs.length; i++){
			var inputType = inputs[i].getAttribute("type");
			if (inputType == null || inputType == "text" || inputType == "hidden" || (typeof inputs[i].checked != "undefined" && inputs[i].checked == true)){
				formElements[formElements.length] = inputs[i];
			}
		}
		for (var i = 0; i < formElements.length; i++){
			var elementName = formElements[i].getAttribute("name");
			if (elementName != null && elementName != ""){
				parameters += "&" + elementName + "=" + encodeURIComponent(formElements[i].value);
			}
		}
		var ajax = new Core.Ajax();
		ajax.doGet(("/advisors/remote.php?"+parameters), 
			function(str) {
				AdvisorsWidget.currentPage = Core.JSON.parse(str);
				AdvisorsWidget.searchResults();
				AdvisorsWidget.getNextData();
/*				
				setTimeout(
					function() {
						AdvisorsWidget.getNextData();
					}, 500
				);				
*/				
			}
		);
	},
	getNextData : function () {
		AdvisorsWidget.active = true;
		var form = $id("searchForm");
		var parameters = "cmd=search&current="+(AdvisorsWidget.currentRecord+AdvisorsWidget.pagingSize)+"&size="+AdvisorsWidget.pagingSize;
		var formElements = [];
		var textareas = form.getElementsByTagName("textarea");
		for (var i = 0; i < textareas.length; i++){
			formElements[formElements.length] = textareas[i];
		}
		var selects = form.getElementsByTagName("select");
		for (var i = 0; i < selects.length; i++){
			formElements[formElements.length] = selects[i];
		}
		var inputs = form.getElementsByTagName("input");
		for (var i = 0; i < inputs.length; i++){
			var inputType = inputs[i].getAttribute("type");
			if (inputType == null || inputType == "text" || inputType == "hidden" || (typeof inputs[i].checked != "undefined" && inputs[i].checked == true)){
				formElements[formElements.length] = inputs[i];
			}
		}
		for (var i = 0; i < formElements.length; i++){
			var elementName = formElements[i].getAttribute("name");
			if (elementName != null && elementName != ""){
				parameters += "&" + elementName + "=" + encodeURIComponent(formElements[i].value);
			}
		}
		var ajax = new Core.Ajax();
		ajax.doGet("/advisors/remote.php?"+parameters,
			function(str) {
				AdvisorsWidget.nextPage = Core.JSON.parse(str);//eval('(' + str + ')'); // Core.JSON.parse(str);
				AdvisorsWidget.active = false;
			}
		);
	},
	getPreviousData : function () {
		if((AdvisorsWidget.currentRecord - AdvisorsWidget.pagingSize) >= 0) {
			AdvisorsWidget.active = true;
			var form = $id("searchForm");
			var parameters = "cmd=search&current="+(AdvisorsWidget.currentRecord-AdvisorsWidget.pagingSize)+"&size="+AdvisorsWidget.pagingSize;
			var formElements = [];
			var textareas = form.getElementsByTagName("textarea");
			for (var i = 0; i < textareas.length; i++){
				formElements[formElements.length] = textareas[i];
			}
			var selects = form.getElementsByTagName("select");
			for (var i = 0; i < selects.length; i++){
				formElements[formElements.length] = selects[i];
			}
			var inputs = form.getElementsByTagName("input");
			for (var i = 0; i < inputs.length; i++){
				var inputType = inputs[i].getAttribute("type");
				if (inputType == null || inputType == "text" || inputType == "hidden" || (typeof inputs[i].checked != "undefined" && inputs[i].checked == true)){
					formElements[formElements.length] = inputs[i];
				}
			}
			for (var i = 0; i < formElements.length; i++){
				var elementName = formElements[i].getAttribute("name");
				if (elementName != null && elementName != ""){
					parameters += "&" + elementName + "=" + encodeURIComponent(formElements[i].value);
				}
			}
			var ajax = new Core.Ajax();
			ajax.doGet("/advisors/remote.php?"+parameters,
				function(str) {
					AdvisorsWidget.previousPage = Core.JSON.parse(str);
					AdvisorsWidget.active = false;
				}
			);
		}
	},
	getNextPage : function () {
		if(!AdvisorsWidget.active) {
			AdvisorsWidget.currentRecord += AdvisorsWidget.pagingSize;
			AdvisorsWidget.previousPage = AdvisorsWidget.currentPage;
			AdvisorsWidget.currentPage = AdvisorsWidget.nextPage;
			AdvisorsWidget.searchResults();
			AdvisorsWidget.getNextData();
		}
	},
	getPreviousPage : function () {
		if(!AdvisorsWidget.active) {
			AdvisorsWidget.currentRecord -= AdvisorsWidget.pagingSize;
			AdvisorsWidget.nextPage = AdvisorsWidget.currentPage;
			AdvisorsWidget.currentPage = AdvisorsWidget.previousPage;
			AdvisorsWidget.searchResults();
			AdvisorsWidget.getPreviousData();
		}
	},	
	removeKids : function(ele){
		var folds = ele.childNodes;
		for (var j = 0; j < folds.length; j++){
			ele.removeChild( folds[j] );
		}
	},
	searchResults : function(){
		$id("resultsPanel").style.display = ""; 	
//		AdvisorsWidget.removeKids( $id("resultsPanel") );
		while ($id("resultsPanel").firstChild) {
			$id("resultsPanel").removeChild($id("resultsPanel").firstChild);
		}
		var resp = AdvisorsWidget.currentPage;
		if( resp['advisors'] ){
			var results = document.createElement("div");
			results.setAttribute("id", "results");
			$id("returnPanel").style.display = "";
			var resultsDiv = document.createElement("div");
			var tbdy = document.createElement("tbody");
			var resultsTable = document.createElement("table");
			resultsDiv.setAttribute("id", "resultsDiv");
//			resultsTable.setAttribute("style", "border:1px solid #000000;");
			var tr = document.createElement("tr");
			var th = document.createElement("th");
			th.appendChild(document.createTextNode( "Name" ));
			tr.appendChild(th);
			var th = document.createElement("th");
			th.appendChild(document.createTextNode( "Firm" ));
			tr.appendChild(th);
			var th = document.createElement("th");
			th.appendChild(document.createTextNode( "City" ));
			tr.appendChild(th);
			var th = document.createElement("th");
			th.appendChild(document.createTextNode( "State" ));
			tr.appendChild(th);
			var th = document.createElement("th");
			th.appendChild(document.createTextNode( "Phone" ));
			tr.appendChild(th);
			tbdy.appendChild(tr);
			for(i = 0; i < resp['advisors'].length; i++) {
//				alert( resp['advisors'][i].name );
				var tr = document.createElement("tr");
				var td = document.createElement("td");
				var href = document.createElement("a");
				href.setAttribute("href", "/advisors/advisor.php?id=" + resp['advisors'][i].AdvisorID);
				href.setAttribute("rel", "lbox?width=600&height=600");
				href.setAttribute("title", "Profile of " + resp['advisors'][i].name);
				href.onclick = function() {
					var t = this.getAttribute(LightBox.ibAttr);
					var params = LightBox.parseQuery(t.substr(5,999));
					var url = this.href;
					if(this.target != "") {url = this.target} 
					var title = this.title;
					if(LightBox.showLbox(url,title,params)) {
						LightBox.showBG();
						window.onscroll = LightBox.maintPos;
						window.onresize = LightBox.maintPos;
					}
					return false;
				}; 			
				href.appendChild(document.createTextNode( resp['advisors'][i].name ) );
				td.appendChild(href );
				tr.appendChild(td);
				var td = document.createElement("td");
				td.appendChild(document.createTextNode( resp['advisors'][i].firm ) );
				tr.appendChild(td);
				var td = document.createElement("td");
				td.appendChild(document.createTextNode( resp['advisors'][i].city ) );
				tr.appendChild(td);
				var td = document.createElement("td");
				td.appendChild(document.createTextNode( resp['advisors'][i].state ) );
				tr.appendChild(td);
				var td = document.createElement("td");
				td.appendChild(document.createTextNode( resp['advisors'][i].phone ) );
				tr.appendChild(td);
				tbdy.appendChild(tr);
			}
			resultsTable.appendChild(tbdy);
			resultsDiv.appendChild(resultsTable);
			results.appendChild(resultsDiv);
			$id("resultsPanel").appendChild(results);			
//			alert(results.innerHTML);
			$id("buttonPanel").style.display="";
			// display page message
			while ($id("currentRec").firstChild) {
				$id("currentRec").removeChild($id("currentRec").firstChild);
			}
		    var newP = document.createElement("p");
		    newP.setAttribute("id", "page");
			var curPage = (AdvisorsWidget.currentRecord/AdvisorsWidget.pagingSize)+1;
			curPage = Math.ceil(curPage);
			var totalP = Math.ceil(AdvisorsWidget.recordCount/AdvisorsWidget.pagingSize);
		    newP.appendChild(document.createTextNode( "Viewing Page " + curPage + " of " + totalP ));
			$id("currentRec").appendChild(newP);
		}else{
			AdvisorsWidget.displayMsg("Your search returned no search results..",1000);
			$id("searchForm").style.display = "";
		}
	},
	displayMsg : function(msg,timer){
		while ($id("msgPanel").firstChild) {
			$id("msgPanel").removeChild($id("msgPanel").firstChild);
		}
		var newP = document.createElement("p");
		newP.setAttribute("id", "success");
		newP.appendChild( document.createTextNode(msg) );
		$id("msgPanel").appendChild(newP);
		$id("msgPanel").style.display = ""; 
		if( timer != 0 ){
			AdvisorsWidget.timera = setInterval(function() {$id("msgPanel").style.display="none";}, timer);
		}else{
			 clearInterval(AdvisorsWidget.timera);
		}
	},
	newAdvisor : function(event) {
		var form = $id("adrecForm");
		var parameters = "cmd=addnew";
		var formElements = [];
		var textareas = form.getElementsByTagName("textarea");
		for (var i = 0; i < textareas.length; i++){
			formElements[formElements.length] = textareas[i];
		}
		var selects = form.getElementsByTagName("select");
		for (var i = 0; i < selects.length; i++){
			formElements[formElements.length] = selects[i];
		}
		var inputs = form.getElementsByTagName("input");
		for (var i = 0; i < inputs.length; i++){
			var inputType = inputs[i].getAttribute("type");
			if (inputType == null || inputType == "text" || inputType == "hidden" || (typeof inputs[i].checked != "undefined" && inputs[i].checked == true)){
				formElements[formElements.length] = inputs[i];
			}
		}
		for (var i = 0; i < formElements.length; i++){
			var elementName = formElements[i].getAttribute("name");
			if (elementName != null && elementName != ""){
				parameters += "&" + elementName + "=" + encodeURIComponent(formElements[i].value);
			}
		}
		var ajax = new Core.Ajax();
		ajax.doPost("/advisors/remote.php",  parameters, AdvisorsWidget.advisorAdded);
		var newP = document.createElement("p");
		newP.setAttribute("id", "success");
		newP.appendChild(document.createTextNode("Your submission has been submitted.."));
		$id("adrecpara").style.display = "none";
		form.parentNode.replaceChild(newP, form);
		Core.preventDefault(event);
	},
	advisorAdded : function(str) {
//		alert( str );
		var newP = document.createElement("div");
		newP.setAttribute("id", "success2");
		newP.appendChild(document.createTextNode("Thank you for submitting this recommendation.  If you have other advisors you would like to recommend, please refresh this page."));
		$id("success").parentNode.replaceChild(newP, $id("success"));
	},
	startStatusAnim : function(elm) {
		AdvisorsWidget.fadeIncr = 0;
		AdvisorsWidget.fadeDiv = $id(elm);
		AdvisorsWidget.doStatusAnim();
		AdvisorsWidget.statusInterval = setInterval(AdvisorsWidget.doStatusAnim, 200);
	},
	newSearch : function(){
		$id("msgPanel").style.display = "none";
		$id("returnPanel").style.display = "none";
		$id("searchForm").style.display = "";
		$id("resultsPanel").style.display = "none";
		$id("buttonPanel").style.display = "none";
	},
	doStatusAnim : function() {
		var r = 235;
		var g = 235;
		var fadeDiv = null;
		fadeDiv = AdvisorsWidget.fadeDiv; // document.getElementById('main' + self.editId);
		if (AdvisorsWidget.fadeIncr < 20) {
			AdvisorsWidget.fadeIncr += 5;
		}else {
			AdvisorsWidget.fadeIncr = 20;
			AdvisorsWidget.stopReset();
		}
		r += AdvisorsWidget.fadeIncr;
		g += AdvisorsWidget.fadeIncr;
		fadeDiv.style.background = 'rgb(' + r + ', ' + g + ', 255)';
	},
	stopReset : function() {
		clearInterval(AdvisorsWidget.statusInterval);
	}
}
document.write( AdvisorsWidget.style() );
document.write( AdvisorsWidget.tabMenu() );
//document.write( AdvisorsWidget.openContainer() );
document.write( AdvisorsWidget.tab1() );
document.write( AdvisorsWidget.tab2() );
//document.write( AdvisorsWidget.closeContainer() );
AdvisorsWidget.setListeners();
AdvisorsWidget.getArea();
AdvisorsWidget.getArea2();
Core.start(Tab);
Core.start(LightBox);


