//generic
var _neutralPath="LivePage/PicFiles/";
var _targetedPath="LivePage/";
var _cgifUrlPath=_neutralPath+"c.gif";
var _welcomePage="welcome.asp";
var _moreHelpPage="welcome.asp";  
//Ê×Ò³ÓÒ²à

var _faqKeyword="topiclist_menu.asp";

var _omniImgKey="msnportal";
var _cuSessionPlaceholder = "{s}";
var _winWidth=550;
var _winHeight=570;
var _srchDispInc=5;
var _thinSvc="go.asp";
var _commSvc="do.asp";
var _commVisitUrl;var _appPath;var _env;
//user-specific
var _fmt;var _guid;var _layout;var _querytype;var _query;var v4;
//market-specific
var _mkt;var _tlHelpHead;var _tlCommHead;var _tlFaqHead;var _tlTocHead;
var _queryDefault;var _progressText;var _viewMoreText;
//project-specific
var _commId = "";


/*******************************/
/***** Colmid (CM) Object *****/
/*******************************/
function CM() {}
CM.mouseover = function(p_o) {p_o.style.backgroundColor = "#549FE3";}
CM.mouseout = function(p_o) {p_o.style.backgroundColor = "#FFFFFF";}
CM.mousedown = function(p_ev) {
	p_ev = (p_ev) ? p_ev : event;
	CM.ismousedown = true;
	CM.currpos = p_ev.clientX;
	CM.currLeftW = CM.getCurrLeftW();
	CM.currSrchW = CM.getCurrSrchW();
	document.body.style.cursor = 'e-resize';
	return false;
}
CM.mouseup = function() {
	CM.ismousedown = false;
	document.body.style.cursor = 'auto';
	CM.currLeftW = parseInt(document.getElementById("colleft").style.width);
	CM.currSrchW = parseInt(document.getElementById("helpquery").style.width);
	return false;
}
CM.mousemove = function(p_ev) {
	if (CM.ismousedown) {
		p_ev = (p_ev) ? p_ev : event;
		var newpos = p_ev.clientX;
		var pxmoved = parseInt(newpos - CM.currpos);
		pxmoved = (IsRTL()) ?  -pxmoved : pxmoved;
		var newLeftW = parseInt(CM.currLeftW + pxmoved);
		var newRightW = GetWinWidth() - newLeftW - CM.rightWAdj;
		//TL.display('',newRightW)//DEBUG
		if (newLeftW >= CM.minLeft && newRightW >= CM.minRight) {
			document.getElementById("colleft").style.width = newLeftW + 'px';
			document.getElementById("helpquery").style.width = CM.currSrchW + pxmoved + 'px';
		}
		return false
	} else return true;
}
CM.setMinLeft = function() {
	CM.minLeft = parseInt(document.getElementById("colleft").style.width);
}
CM.getCurrRightW = function() {
	return GetWinWidth() - CM.getCurrLeftW() - CM.rightWAdj;
}
CM.getCurrLeftW = function() {
	if (CM.currLeftW == 0) CM.currLeftW = parseInt(document.getElementById("colleft").style.width);
	return CM.currLeftW;
}
CM.getCurrSrchW = function() {
	if (CM.currSrchW == 0) CM.currSrchW = parseInt(document.getElementById("helpquery").style.width);
	return CM.currSrchW;
}
CM.ismousedown;
CM.currpos;
CM.currLeftW = 0;
CM.currSrchW = 0;
CM.minLeft;
CM.minRight = 300;
CM.rightWAdj = 21;//8+8+5
/***** End Colmid (CM) Object *****/

/***********************************/
/***** Community (Comm) Object *****/
/***********************************/
function Comm() {}
Comm.exists = function() {return (_commId != "");}
Comm.showNavLink = function(){
	if (Comm.exists()) {
		document.getElementById('gotocomm').style.display = 'inline';
		Comm.navLinkHidden = false;
	}
}
Comm.hideNavLink = function() {
	document.getElementById('gotocomm').style.display = 'none';
	Comm.navLinkHidden = true;
}
Comm.goToSite = function(p_dest,p_id) {
	//TODO: Is p_dest needed?
	//p_dest: b=board, t=thread, p=post
	//p_id: the board, thread, or post id(s)
	MapLog.UserSentToCommunity();//omniture
	var url = location.protocol + "//" + _commVisitUrl + "?tid=" + p_id;
	if (IsHC()) {//open community within this frame
		location.href = url;
	} else {//open community in new window
		OpenNewWin(url,"commwin","");
	}
	return false;
}
Comm.navLinkHidden = true;
/***** End Community (Comm) Object *****/

/*******************************/
/***** FAQ Object *****/
/*******************************/
function FAQ() {}
FAQ.showFAQ = function() {
	if (FAQ.cache == null) {
	//alert("2");
		FAQ.getFAQ();
	} else {
		
	//alert("1");
		FAQ.display(FAQ.cache);
	}
	return false;
}
FAQ.getFAQ = function() {
	//alert(_faqKeyword);
	var url = Svc.getHelpUrl("","keyword",_faqKeyword,v4);
	//alert(url);
	Req.makeRequest(url,FAQ.busyReq,"tlhelplinks",FAQ.successCallback,FAQ.errorCallback,"");
}
FAQ.successCallback = function(p_req,p_pass) {
	var contents = "";
	var aFaq = Svc.getResultsArray(p_req.responseText);
	if (aFaq.length == 1) {//search error; return error text
		contents = aFaq[0];
	} else {//there are FAQ(s)
		contents += "<ul>";
		for (i = 0; i < aFaq.length; i += 2) {
			contents += TL.createHelpLink(aFaq[i],aFaq[i+1],"faq"+i);
		}
		contents += "</ul>";
		FAQ.cache = contents;
		if (aFaq.length == 2) HT.show(aFaq[0]);//single FAQ, so display the topic
	}
	FAQ.display(contents);
}
FAQ.errorCallback = function(p_req,p_pass) {
	FAQ.display(Req.getErrorHtml(p_req));
}

FAQ.display = function(p_Faq) {
	MapLog.FaqListPresented();//Omniture
	CommTL.hide();//hide any community search results
	TL.display(p_Faq,_tlFaqHead);
	FAQ.hideNavLink();
	TOC.showNavLink();
	SizeContents();
}
FAQ.hideNavLink = function() {
	document.getElementById('faqnav').style.display = 'none';
}
FAQ.showNavLink = function() {
	document.getElementById('faqnav').style.display = '';
}
FAQ.clearCache = function() {
	FAQ.cache = null;
}
FAQ.busyReq = false;
FAQ.cache = null;
/***** End FAQ Object *****/

/*******************************/
/***** Feedback (FB) Object *****/
/*******************************/
function FB() {}
FB.submitRating = function(r) {
	FB.currentRating = r;
	MapLog.RatingsSubmitted(TH.getCurrentTopic(),TH.getCurrentProject(),r);//omniture
	FB.showVerbatim();
	return false;
}
FB.showRating = function() {
	if (FB.ratingHidden && FB.thanksHidden && Comm.navLinkHidden) {
		document.getElementById('topicrating').style.display = 'inline';
		FB.ratingHidden = false;
	}
}
FB.hideRating = function() {
	if (!FB.ratingHidden) {
		document.getElementById('topicrating').style.display = 'none';
		FB.ratingHidden = true;
	}
}
FB.showThanks = function() {
	if (FB.thanksHidden && FB.ratingHidden && Comm.navLinkHidden) {
		document.getElementById('fdbckthanks').style.display = 'inline';
		FB.thanksHidden = false;
	}
}
FB.hideThanks = function() {
	if (!FB.thanksHidden) {
		document.getElementById('fdbckthanks').style.display = 'none';
		FB.thanksHidden = true;
	}
}
FB.hideVerbatim = function() {
	document.getElementById('topicfdbck').style.display = 'none';
	FB.verbatimHidden = true;
	FB.clearVerbatim();
	TF.show();
	FB.hideRating();
	FB.showThanks();
	SizeContents();
	return false;
}
FB.showVerbatim = function() {
	TF.hide();
	document.getElementById('fdbckimg').src = FB.getImg(FB.currentRating,true);
	document.getElementById('topicfdbck').style.display = '';
	FB.verbatimHidden = false;
	SizeContents();
	document.getElementById('fdbckarea').focus();
}
FB.clearVerbatim = function() {
	document.getElementById('fdbckarea').value = '';
}
FB.reset = function() {
	Comm.hideNavLink();
	FB.hideVerbatim();
	FB.hideThanks();
	FB.showRating();
}
FB.submitVerbatim = function() {
	var feed = ScrubInput(document.getElementById('fdbckarea').value);
	if (feed.length > 0) MapLog.FeedbackSubmitted(TH.getCurrentTopic(),TH.getCurrentProject(),feed,FB.currentRating);//Omniture
	FB.hideVerbatim();
	return false;
}
FB.getImg = function(p_idx,p_bFocus) {
	if (p_bFocus) p_idx += 3;
	return _neutralPath + FB.images[p_idx];
}
FB.evalKeyUp = function(p_el) {
	var chars = p_el.value;
	if (chars.length > 900) p_el.value = chars.substring(0,900);
}
FB.currentRating;
FB.images = new Array('rate0dk.gif','rate1dk.gif','rate2dk.gif','rate0lt.gif','rate1lt.gif','rate2lt.gif');
FB.ratingHidden = false;
FB.thanksHidden = false;
FB.verbatimHidden = true;
FB.colAdjust = 7.6;
/***** End Feedback (FB) Object *****/

/*********************************/
/***** HelpTopic (HT) Object *****/
/*********************************/
function HT() {}
HT.show = function(p_topic) {
	HT.load(p_topic,null,true,true); //get the topic content and display it
}
HT.load = function(p_topic,p_proj,p_bHist,p_bFoot) {
	//p_proj in non null if called from TopicHistory
	var proj = (p_proj != null && p_proj != "") ? p_proj : Proj.getCurrentProject();
	var url = Svc.getHelpUrl(proj,"topic",p_topic,"");
	var pass = p_topic + "," + proj + "," + p_bHist + "," + p_bFoot;
	Req.makeRequest(url,HT.busyReq,"topiccontents",HT.successCallback,HT.errorCallback,pass);
}
HT.successCallback = function(p_req,p_pass) {
	var params = p_pass.split(",");
	var topic = params[0];
	var proj = params[1];
	var bHist = (params[2] == "true");
	var bFoot = (params[3] == "true");
	FB.reset();
	if (bFoot) {TF.show();} else {TF.hide();}
	if (bHist) TH.addTopic(topic);
	HT.display(p_req.responseText,topic,false);
	if (topic == _moreHelpPage) MapLog.GetMoreHelp(proj);//Omniture
	else MapLog.SelfCareArticleViewed(topic,proj);//Omniture
}
HT.errorCallback = function(p_req,p_pass) {
	var params = p_pass.split(",");
	var topic = params[0];
	var proj = params[1];
	HT.display(Req.getErrorHtml(p_req),topic,true);
	MapLog.SelfCareArticleError(topic,proj);//Omniture
}
HT.display = function(p_html,p_topic,p_error) {
	if (p_error && p_topic.toLowerCase() != _welcomePage) {
		HT.showWelcome();
	} else {
		var tc = document.getElementById("topiccontents");
		tc.innerHTML = p_html;
		topicOnLoad();
		HT.setCurrent(p_topic);
	}
}
HT.showWelcome = function() {
	HT.load(_welcomePage,null,false,false);
	return false;
}
HT.showMoreHelp = function() {
	HT.load(_moreHelpPage,null,true,false);
	return false;
}
HT.getCurrentTopicProject = function() {
	if (HT.current == _welcomePage) return Proj.getCurrentProject();
	else return TH.getCurrentProject();
}
HT.setCurrent = function(p_name) {
	HT.previous = HT.current;
	HT.current = p_name;
}
HT.busyReq = false;
HT.current = "";
HT.previous = "";
/***** End HelpTopic (HT) Object *****/

/**************************************/
/***** CommunityTopic (CT) Object *****/
/**************************************/
function CT() {}
CT.load = function(p_threadId,p_title,p_bHist) {
	var url = Svc.getCommUrl("GetThreadPosts",p_threadId);
	var pass = p_threadId + "," + p_title + "," + p_bHist;
	Req.makeRequest(url,CT.busyReq,"topiccontents",CT.successCallback,CT.errorCallback,pass);
	
}
CT.successCallback = function(p_req,p_pass) {
	var params = p_pass.split(",");
	var threadId = params[0];
	var threadNm = params[1];
	var bHist = (params[2] == "true");
	MapLog.CommunityThreadViewed(threadId,"",threadNm);//Omniture
	CT.display(p_req.responseText);
	FB.reset();
	FB.hideRating();
	Comm.showNavLink();
	TF.show();
	if (bHist) TH.addThread(threadNm,threadId);//add thread to history
	HT.setCurrent(threadID);
}
CT.errorCallback = function(p_req,p_pass) {
	var params = p_pass.split(",");
	var proj = params[1];
	//MapLog.SelfCareArticleViewed("",proj,"errorPage");//Omniture
	CT.display(Req.getErrorHtml(p_req));
}
CT.display = function(p_html) {
	document.getElementById("topiccontents").innerHTML = p_html;
}
CT.busyReq = false;
/***** End CommunityTopic (CT) Object *****/

/*******************************/
/***** Print Object *****/
/*******************************/
function Print() {}
Print.show = function() {
	if (Print.hidden) {
		document.getElementById("print").style.display = "";
		Print.hidden = false;
	}
}
Print.hide = function() {
	if (!Print.hidden) {
		document.getElementById("print").style.display = "none";
		Print.hidden = true;
	}
}
Print.print = function() {
	if (document.images){//disable omniture log image
		var imgs = document.images;
		if (typeof(imgs) == "object" && imgs != null){
			for (var i = imgs.length - 1; i >= 0; i--){
				if (imgs[i].src.indexOf(_omniImgKey) != -1){
					imgs[i].src = _cgifUrlPath;
					break;
				}
			}
		}
	}
	var idssimg = document.getElementById("idss");
	if (idssimg != null) idssimg.src = _cgifUrlPath;//disable idss c.gif
	window.print();//Print topic currently displayed
	//Omniture
	if (HT.current.toLowerCase() == _welcomePage)//welcome page not in history, so handle separately
		MapLog.SelfCareArticlePrinted(_welcomePage,Proj.getCurrentProject());
	else if (TH.isTopic())
		MapLog.SelfCareArticlePrinted(TH.getCurrentTopic(),TH.getCurrentProject());
	else
		MapLog.CommunityThreadPrinted(TH.getCurrentThreadId(),TH.getCurrentThreadTitle());
	return false;
}
Print.hidden = false;
/***** End Print Object *****/

/*******************************/
/***** Project (Proj) Object *****/
/*******************************/
function Proj() {}
Proj.getCurrentProject = function() {
	if (Proj.currentProject == null) {
		Proj.currentProject = Proj.getSelectedProject();
	}
	return Proj.currentProject;
}
Proj.getSelectedProject = function() {
	var prods = document.getElementById('projsel');
	return prods.options[prods.selectedIndex].value;
}
Proj.onChange = function() {
	Search.showDefaultText();
	Proj.currentProject = Proj.getSelectedProject();
	FAQ.clearCache();
	TOC.clearCache();
	Proj.getNewSettings();
	HT.showWelcome();//overwritten if only one FAQ
	FAQ.getFAQ();
}
Proj.getNewSettings = function() {
	//use thinservice.aspx?market=<mkt>&project=<prj> to get "community board id(s)"
	var url = Svc.getHelpUrl("","","","");
	Req.makeRequest(url,Proj.busyReq,"",Proj.successCallback,Proj.errorCallback);
}
Proj.successCallback = function(p_req,p_pass) {
	//response has a single "string" with the community board id(s)
	var text = p_req.responseText;
	_commId = text.substring(1,text.length-1);
}
Proj.errorCallback = function(p_req,p_pass) {
	//error in request; set _commId to blank
	_commId = "";
}
Proj.currentProject = null;
Proj.busyReq = false;
/***** End Project (Proj) Object *****/

/*******************************/
/***** Request (Req) Object *****/
/*******************************/
function Req() {}
Req.makeRequest = function(p_url,p_busyReq,p_progId,p_successCallBack,p_errorCallBack,p_pass) {
	//p_url: the web service url
	//p_busyReq: is a request for this object currently in progress?
	//p_progId: element id where progress HTML should be shown
	//p_successCallBack: callback function for successful response
	//p_errorCallBack: callback function for erroneous response
	//p_pass: string of params to pass to callback functions
	if (p_busyReq) return;
	var req = Req.getRequest();
	if (req != null) {
		p_busyReq = true;
		Req.showProgress(p_progId);
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				p_busyReq = false;
				window.clearTimeout(toId);
				if (req.status == 200) {
					p_successCallBack(req,p_pass);
				} else {
					p_errorCallBack(req,p_pass);
				}
			}
		}
		req.open("GET", p_url, true);
		req.send(null);
		var toId = window.setTimeout( function() {if (p_busyReq) req.abort();}, Req.timeout );
	}
}
Req.getRequest = function() {
	var xmlHttp;
	try { xmlHttp = new ActiveXObject("MSXML2.XMLHTTP"); return xmlHttp; } catch (e) {}
	try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); return xmlHttp; } catch (e) {}
	try { xmlHttp = new XMLHttpRequest(); return xmlHttp; } catch(e) {}
	return null;
}
Req.showProgress = function(p_id) {
	if (p_id != "") document.getElementById(p_id).innerHTML = Req.getProgressHtml();
}
Req.getProgressHtml = function() {
	return "<p class='progress'><img src='"+_neutralPath+"hig_progcircle_animated.gif' align='middle' width='16' height='16' alt='" + _progressText + "'/> " + _progressText + "</p>";
}
Req.getErrorHtml = function(p_req) {
	//TODO: implement accepted way to handle request error
	return "<p>" + "(" + p_req.status + ") " + p_req.statusText + "</p>"
}
Req.timeout = 5000;//5 seconds
/***** End Request (Req) Object *****/

/*******************************/
/***** Search Object *****/
/*******************************/
function Search() {}
Search.doSearch = function() {
	//Submit request for MAP help search using the query terms the user typed in the input box.
	var oInput = document.getElementById('helpquery');
	if ( oInput ) {
		var q = oInput.value;
		if (q != _queryDefault) { //ensure no search for default text
			q = ScrubInput(q);
			tmp = q.replace( / /g, "" ); // remove spaces to check query length
			q = ( encodeURIComponent() ) ? encodeURIComponent(q) : escape(q); //escape() for IE5.0 and earlier
			if ( tmp.length > 0 ) {//the query is not empty, so get the results
				Search.getResults('search',q);
				if (Comm.exists()) CommSearch.doSearch();//community search
			} else {// the query is empty; return focus to the input box
				oInput.focus();
			}
		}
	}
	return false;
}
Search.doSearchViaEnter = function(p_ev)  {
	// Submit the Help Search when the user presses the Enter key
	// while focus is in the Help Search input box.
	p_ev = (p_ev) ? p_ev : event;
	var target = (p_ev.target) ? p_ev.target : p_ev.scrElement;
	var charCode = (p_ev.charCode) ? p_ev.charCode : ((p_ev.which) ? p_ev.which : p_ev.keyCode);
	if (charCode == 13 || charCode == 3){Search.doSearch();}
	return false;
}
Search.getResults = function(p_qt,p_q) {
	Search.clearCache();
	var url = Svc.getHelpUrl("",p_qt,p_q,v4);
	var pass = p_qt + "," + p_q;
	Req.makeRequest(url,Search.busyReq,"tlhelplinks",Search.successCallback,Search.errorCallback,pass);
}
Search.successCallback = function(p_req,p_pass) {
	var params = p_pass.split(",");
	var qt = params[0];
	var q = params[1];
	var aResults = Svc.getResultsArray(p_req.responseText);
	var len = aResults.length;
	if (len == 1) {
		if (qt == "keyword") {
			//Show FAQ instead
			FAQ.showFAQ();
		} else {
			//there was a search error; return the error text
			MapLog.SearchExecuted(qt,q,"");//Omniture
			Search.displayResults("<p>" + aResults[0] + "</p>"); 
		}
	} else {
		//there are search results
		var count = len*0.5;
		Search.aNames = new Array(count);
		Search.aTitles = new Array(count);
		var idx = 0;
		for (i = 0; i < len; i += 2) {
			Search.aNames[idx] = aResults[i];
			Search.aTitles[idx] = aResults[i+1];
			idx++;
		}
		MapLog.SearchExecuted(qt,q,count);//Omniture
		Search.renderResults(qt);
	}
}
Search.errorCallback = function(p_req,p_pass) {
	var params = p_pass.split(",");
	var qt = params[0];
	var q = params[1];
	MapLog.SearchExecuted(qt,q,"");//Omniture
	Search.displayResults(Req.getErrorHtml(p_req));
}
Search.renderResults = function(p_qt) {
	if (Search.aNames.length == 1 && Search.aNames[0] == '') {
		if (p_qt == "keyword") {
			//zero hits for keyword search
			FAQ.showFAQ();
		} else {
			//there was a search error or zero hits for user search
			//so display the error text that is in the title element
			Search.displayResults(Search.aTitles[0]);
		}
	} else {
		//there are search results
		Search.displayResults(Search.createLinks(0));
		if (Search.aNames.length == 1) {//TODO: add && Comm.results == 0
			//only one result, so show the topic
			HT.show(Search.aNames[0]);
			if (p_qt == "keyword") FAQ.showFAQ();
		}
	}
}
Search.createLinks = function(p_start) {
	var html = "<ul>";
	var max;
	if (!Comm.exists()) {
		max = Search.aNames.length;
	} else {
		max = (p_start == 0) ? _srchDispInc : Search.aNames.length;
		if (max > Search.aNames.length) max = Search.aNames.length;
	}
	for (var i = 0; i < max; i++) {
		html += TL.createHelpLink(Search.aNames[i],Search.aTitles[i],"sr"+i);
	}
	html += "</ul>";
	Search.helpLinks = html;//cache the topic links
	if (Search.aNames.length > max) html += Search.createMoreLink(max);//user can chose to view more
	return html;
}
Search.createMoreLink = function(p_start) {
	return "<div id='viewmorehelp'><a href='#sml' onclick='Search.viewMore(" + p_start + ")'>" + _viewMoreText + "</a></div>";
}
Search.displayResults = function(p_html) {
	var num = (Search.aNames != null) ? Search.aNames.length : 0;
	var head = _tlHelpHead + " (" + num + ")";
	TL.display(p_html,head);
	FAQ.showNavLink();
	TOC.showNavLink();
	SizeContents();
}
Search.viewMore = function(p_start) {
	Search.displayResults(Search.createLinks(p_start));
}
Search.focus = function(oInput) {
	var val = oInput.value;
	if (val == _queryDefault) oInput.value = '';//remove the default text if it is present
	oInput.select();
}
Search.blur = function(oInput) {
	var val = oInput.value;
	if (val == null || val.length == 0) oInput.value = _queryDefault;
}
Search.showDefaultText = function() {
	document.getElementById('helpquery').value = _queryDefault;
}
Search.clearCache = function() {
	Search.aNames = null;
	Search.aTitles = null;
	Search.helpLinks = "";
}
Search.busyReq = false;
Search.aNames = null;
Search.aTitles = null;
Search.helpLinks = "";
/***** End Search Object *****/

/*******************************/
/***** Community Search Object: Omar 2/1/06 *****/
/*******************************/
function CommSearch() {}
CommSearch.doSearch = function() {
	//Submit request for MAP help search using the query terms the user typed in the input box.
	var oInput = document.getElementById('helpquery');
	if ( oInput ) {
		var q = oInput.value;
		if (q != _queryDefault) { //ensure no search for default text
			tmp = q.replace( / /g, "" ); // remove spaces to check query length
			try {q = encodeURIComponent(q);} catch(ex) {q = escape(q);} 
			if ( tmp.length > 0 ) {
				//the query is not empty, so get the results
				CommSearch.getResults('SearchThreads',q);
			} 
		}
	}
	return false;
}
CommSearch.getResults = function(p_qt,p_q) {
	CommSearch.clearCache();
	var url = Svc.getCommUrl(p_qt,p_q);
	var pass = p_qt + "," + p_q;
	Req.makeRequest(url,CommSearch.busyReq,"",CommSearch.successCallback,CommSearch.errorCallback,pass);
}
CommSearch.successCallback = function(p_req,p_pass) {
	var params = p_pass.split(",");
	var qt = params[0];
	var q = params[1];
	var aResults = Svc.getResultsArray(p_req.responseText);
	var len = aResults.length;
	if (len == 1) {
		//there was a search error; return the error text
		Search.displayResults("<p>" + aResults[0] + "</p>");
	} else {
		//there are search results
		var count = len*0.5;
		CommSearch.aThreadIds = new Array(count);
		CommSearch.aTitles = new Array(count);
		var idx = 0;
		for (i = 0; i < len; i += 2) {
			CommSearch.aThreadIds[idx] = aResults[i];
			CommSearch.aTitles[idx] = aResults[i+1];
			idx++;
		}
		CommSearch.renderResults(qt);
	}
}
CommSearch.errorCallback = function(p_req,p_pass) {
	var params = p_pass.split(",");
	var qt = params[0];
	var q = params[1];
	MapLog.SearchExecuted(qt,q,"");//Omniture
	CommSearch.displayResults(Req.getErrorHtml(p_req));
}
CommSearch.renderResults = function(p_qt) {
	if (CommSearch.aThreadIds.length == 1 && CommSearch.aThread[0] == '') {
			//there was a search error or zero hits for user search
			//so display the error text that is in the title element
			CommSearch.displayResults("No results from Community");
			//Omar:Todo recieve loaclized message from Server cached on JS var
	} else {
		//there are search results
		CommSearch.displayResults(CommSearch.createLinks(0));
	}
}
CommSearch.createLinks = function(p_start) {
	var html = "<ul>";
	var max;
	max = (p_start == 0) ? _srchDispInc : CommSearch.aThreadIds.length;
	if (max > CommSearch.aThreadIds.length) max = CommSearch.aThreadIds.length;
	for (var i = 0; i < max; i++) {
		html += CommTL.createThreadLink(CommSearch.aThreadIds[i],CommSearch.aTitles[i]);
	}
	html += "</ul>";
	CommSearch.Links = html;//cache the topic links
	if (CommSearch.aThreadIds.length > max) html += CommSearch.createMoreLink(max);//user can chose to view more
	return html;
}
CommSearch.createMoreLink = function(p_start) {
	return "<div id='viewmorecomm'><a href='#cml' onclick='CommSearch.viewMore(" + p_start + ")'>" + _viewMoreText + "</a><div>";
}
CommSearch.displayResults = function(p_html) {
	var num = (CommSearch.aThreadIds != null) ? CommSearch.aThreadIds.length : 0;
	var head = _tlCommHead + " (" + num + ")";
	CommTL.display(p_html,head);
}
CommSearch.viewMore = function(p_start) {
	CommSearch.displayResults(CommSearch.createLinks(p_start));
}
CommSearch.clearCache = function() {
	CommSearch.aThreadIds = null;
	CommSearch.aTitles = null;
	CommSearch.Links = "";
}
CommSearch.busyReq = false;
CommSearch.aThreadIds = null;
CommSearch.aTitles = null;
CommSearch.Links = "";
/***** End Community Search Object *****/

/*******************************/
/***** Service (Svc) Object *****/
/*******************************/
function Svc() {}
Svc.getHelpUrl = function(p_prj,p_qt,p_q,p_f) {
	
	var prj = (p_prj.length > 0) ? p_prj : Proj.getCurrentProject();
		//alert(p_q);
	var url = _appPath + "" + _thinSvc + "?project=" + prj + "&mkt=" + _mkt;
		//var url = _appPath + "/" 
	if (p_qt.length > 0 && p_q.length > 0) {
		url += "&querytype=" + p_qt + "&query=" + p_q;
		//url += p_q;
		if (p_f.length > 0) url += "&filter=" + p_f;
	}
	return url;
}
Svc.getCommUrl = function(p_api,p_q){
	
	//alert("getcomm");
     var url = _appPath + "/" + _commSvc + "?api=" + p_api + "&mkt=" + _mkt + "&query=" + p_q;
     //Omar TODO: add other vars to the request.
     return url;
}
Svc.getResultsArray = function(p_str) {
	//parse search results (comma-delimited, double-quoted strings)
	var str = p_str.substring(1,p_str.length-1);
	return str.split('","');
}
/***** End Service (Svc) Object *****/

/*******************************/
/***** TOC Object *****/
/*******************************/
function TOC() {}
TOC.showTOC = function() {
	if (TOC.cache == null) {
		TOC.getTOC();
	} else {
		MapLog.TocListPresented(TOC.fileName,Proj.getCurrentProject(),"");//Omniture
		TOC.display(TOC.cache);
	}
	return false;
}
TOC.getTOC = function() {
	var url = Svc.getHelpUrl("","topic","topiclist_left.asp","");
	Req.makeRequest(url,TOC.busyReq,"tlhelplinks",TOC.successCallback,TOC.errorCallback,"");
}
TOC.successCallback = function(p_req,p_pass) {
	var contents = p_req.responseText;
	var idx = contents.indexOf("]");
	TOC.fileName = contents.substring(1,idx);//cache TOC file name
	contents = contents.substring(idx+1,contents.length);
	MapLog.TocListPresented(TOC.fileName,Proj.getCurrentProject(),"");//Omniture
	TOC.cache = contents;//cache TOC
	TOC.display(contents);
}
TOC.errorCallback = function(p_req,p_pass) {
	TOC.display(Req.getErrorHtml(p_req));
	MapLog.TocListPresented("",Proj.getCurrentProject(),"errorPage");//Omniture
}
TOC.display = function(p_toc) {
	CommTL.hide();//hide any community search results
	TL.display(p_toc,_tlTocHead);
	TOC.reopenBooks();
	TOC.hideNavLink();
	FAQ.showNavLink();
	SizeContents();
}
TOC.hideNavLink = function() {
	document.getElementById('tocnav').style.display = 'none';
}
TOC.showNavLink = function() {
	document.getElementById('tocnav').style.display = '';
}
TOC.reopenBooks = function() {
	if (TOC.openBooks != "") {
		var str = TOC.openBooks.substring(1,TOC.openBooks.length);
		var arr = str.split(",");
		for (var i = 0; i < arr.length; i++) {
			TOC.toggleBook(arr[i]);
		}
	}
}
TOC.toggleBook = function(p_bkid) {
	toggleElementDisplay(p_bkid,'block');//in wltopic.js
	TOC.toggleImg('I'+p_bkid,'c');
}
TOC.bookClick = function(p_bkid) {
	TOC.toggleBook(p_bkid);
	if (TOC.openBooks.indexOf(p_bkid) == -1) {//add book to cache
		TOC.openBooks += "," + p_bkid;
	} else {//remove book from cache
		var bkstr = "," + p_bkid;
		var idx = TOC.openBooks.indexOf(bkstr);
		var str1 = TOC.openBooks.substring(0,idx);
		var str2 = TOC.openBooks.substring(idx+bkstr.length,TOC.openBooks.length);
		TOC.openBooks = str1 + str2;
	}
}
TOC.toggleImg = function(p_id,p_ev) {
	var elem = document.getElementById(p_id);
	if (elem != null) {
		var src = elem.src;
		var srcRoot = "";
		var imgName = src;
		var imgNewName;
		var idx = src.lastIndexOf("/");
		if (idx > -1) {
			srcRoot = src.substring(0,idx+1);
			imgName = src.substring(idx+1,src.length);
		}
		imgName = imgName.substring(0,imgName.length - 4);
		switch (imgName) {
			case "glyph_expand_rest":
				if (p_ev == 'r') imgNewName = 'glyph_expand_hover';
				else if (p_ev == 't') imgNewName = 'glyph_expand_rest';
				else imgNewName = 'glyph_collapse_rest';
				break;
			case "glyph_expand_hover":
				if (p_ev == 't') imgNewName = 'glyph_expand_rest';
				else imgNewName = 'glyph_collapse_rest';
				break;
			case "glyph_collapse_rest":
				if (p_ev == 'r') imgNewName = 'glyph_collapse_hover';
				else if (p_ev == 't') imgNewName = 'glyph_collapse_rest';
				else imgNewName = 'glyph_expand_rest';
				break;
			case "glyph_collapse_hover":
				if (p_ev == 't') imgNewName = 'glyph_collapse_rest';
				else imgNewName = 'glyph_expand_rest';
				break;
		}
		elem.src = srcRoot + imgNewName + '.gif';
	}
}
TOC.clearCache = function() {
	TOC.fileName = "";
	TOC.cache = null;
	TOC.openBooks = "";
}
TOC.fileName = "";
TOC.busyReq = false;
TOC.cache = null;
TOC.openBooks = "";
/***** End TOC Object *****/

/*******************************/
/***** TopicFooter (TF) Object *****/
/*******************************/
function TF() {}
TF.show = function() {
	document.getElementById('topicfooter').style.display = '';
}
TF.hide = function() {
	document.getElementById('topicfooter').style.display = 'none';
}
/***** End TopicFooter (TF) Object *****/

/*******************************/
/***** TopicHistory (TH) Object *****/
/*******************************/
function TH() {}
TH.next = function() {
	//Increment the TopicHistory array index by 1
	//and return the topic at the new array index
	var newIdx = TH.idx + 1;
	if (newIdx < TH.count()) {
		TH.idx = newIdx;
		TH.showControl(1); //show "previous" control
	}
	if (newIdx >= TH.count() - 1) {
		TH.hideControl(0); //hide "next" control
	}
	TH.showTopic();
	return false;
}
TH.previous = function() {
	//Decrement the TopicHistory array index by 1
	//and display the topic at the new array index
	var newIdx = TH.idx - 1;
	if (newIdx >= 0) {
		TH.idx = newIdx;
		TH.showControl(0); //show "next" control
	}
	if (newIdx <= 0) {
		TH.hideControl(1); //hide "previous" control
	}
	TH.showTopic();
	return false;
}
TH.showTopic = function() {
	if (TH.isTopic()) {
		var topic = TH.getCurrentTopic();
		var project = TH.getCurrentProject();
		var bShowFoot = (topic.toLowerCase() == _welcomePage) ? false : true;
		HT.load(topic,project,false,bShowFoot);
	} else {
		CT.load(TH.getCurrentThreadId(),TH.getCurrentThreadTitle(),false);
	}
}
TH.showControl = function(prev) {
	if (prev) { //show "previous" control
		document.getElementById('histprev').style.visibility = 'visible';
	} else { //show "next" control
		document.getElementById('histnext').style.visibility = 'visible';
	}
}
TH.hideControl = function(prev) {
	if (prev) { //hide "previous" control
		document.getElementById('histprev').style.visibility = 'hidden';
	} else { //hide "next" control
		document.getElementById('histnext').style.visibility = 'hidden';
	}
}
TH.addTopic = function(p_topic) {
	TH.add(1,p_topic,Proj.getCurrentProject());
}
TH.addThread = function(p_title,p_threadId) {
	TH.add(0,p_title,p_threadId);
}
TH.add = function(p_type,p_name,p_other) {
	//If this is the first topic or if this topic is not the current topic
	//then add the current topic info to the history arrays and point the index at this entry.
	if (TH.idx == -1 || TH.aNames[TH.idx] != p_name) {//add topic to history
		if (TH.idx == TH.count() - 1) {//idx at end of array, so add to end
			TH.aType = TH.aType.concat(p_type);
			TH.aNames = TH.aNames.concat(p_name);
			TH.aOther = TH.aOther.concat(p_other);
			TH.idx = TH.count() - 1;//point idx at new entry
		} else {//idx in interior of array; remove items after idx, then add to end
			//must create new, shorter arrays first with length idx + 1
			TH.idx = TH.idx + 1;
			TH.aType = TH.aType.slice(0,TH.idx);
			TH.aNames = TH.aNames.slice(0,TH.idx);
			TH.aOther = TH.aOther.slice(0,TH.idx);
			//add the new values to the last array idx
			TH.aType[TH.idx] = p_type;
			TH.aNames[TH.idx] = p_name;
			TH.aOther[TH.idx] = p_other;			
		}
		if (TH.idx > 0) TH.showControl(1); //show "previous" control
		TH.hideControl(0);//hide "next" control
	}
}
TH.count = function() {
	return TH.aNames.length;
}
TH.getCurrentTopic = function() {
	return (TH.idx >= 0) ? TH.aNames[TH.idx] : ""; //the current topic name
}
TH.getCurrentThreadTitle = function() {
	return (TH.idx >= 0) ? TH.aNames[TH.idx] : ""; //the current thread title
}
TH.getCurrentProject = function() {
	return (TH.idx >= 0) ? TH.aOther[TH.idx] : ""; //the current project name
}
TH.getCurrentThreadId = function() {
	return TH.aOther[TH.idx]; //the current thread id
}
TH.isTopic = function() {return (TH.idx >= 0 && TH.aType[TH.idx]);}
TH.aType = new Array();//1=topic; 0=community thread
TH.aNames = new Array();//topic name or thread title
TH.aOther = new Array();//topic project or thread Id
TH.idx = -1;
/***** End TopicHistory (TH) Object *****/

/**************************************/
/***** Help TopicList (TL) Object *****/
/**************************************/
function TL() {}
TL.display = function(p_html,p_head) {
	document.getElementById('tlhelphead').innerHTML = p_head;
	document.getElementById('tlhelplinks').innerHTML = p_html;
}
TL.createHelpLink = function(p_topic,p_title,p_href) {
	return "<li><a class='tlhelplink' href='#" + p_href + "' onclick=" + '"' + "return TL.clickLink('" + p_topic + "')" + '">' + p_title + "</a></li>";
}
TL.clickLink = function(p_topic) {
	HT.show(p_topic); //get the topic content and display it
	return false;
}
/***** End Help TopicList (TL) Object *****/

/*******************************************/
/***** Community TopicList (TL) Object *****/
/*******************************************/
function CommTL() {}
CommTL.display = function(p_html,p_head) {
    document.getElementById('tlcomm').style.display = "";
	document.getElementById('tlcommhead').innerHTML = p_head;
	document.getElementById('tlcommlinks').innerHTML = p_html;
}
CommTL.createThreadLink = function(p_threadId,p_name) {
	return "<li><a class='tlcommlink' href='#" + p_threadId + "' onclick=" + '"' + "return CommTL.clickLink('" + p_threadId + "','" + p_name + "')" + '">' + p_name + "</a></li>";
}
CommTL.clickLink = function(p_threadId,p_name) {
	CT.load(p_threadId,p_name,true);//show the thread
	return false;
}
CommTL.hide = function() {
    document.getElementById('tlcomm').style.display = "none";
}
/***** End TopicList (TL) Object *****/


//***********************************************************************************************
// CLASS:  Util.CookieHelper 
// Stolen from LiveControls and rebranded into ournamespace to avoid collisions.
//***********************************************************************************************
function Util() {}

Util.CookieHelper = 
{
    getCookie:function(name) 
	{  
	
		function valueAt(offset) 
	    {
		    var endstr = document.cookie.indexOf (";", offset);
		    if (endstr == -1)
		    {
			    endstr = document.cookie.length;
		    }
		    return unescape(document.cookie.substring(offset, endstr));
	    }
	    
		var arg = name + "=";  
		var alen = arg.length;  
		var clen = document.cookie.length;  
		var i = 0;  
		while (i < clen) 
		{
			var j = i + alen;    
			if (document.cookie.substring(i, j) == arg)
			{
				return valueAt(j);
			}
			i = document.cookie.indexOf(" ", i) + 1;    
			if (i == 0) 
			{
				break;
			}
		}  
		return null;
	},
	setCookie:function(name, value) 
	{  
		var expDays = 30;
		var exp = new Date(); 
		exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

		var argv = Util.CookieHelper.setCookie.arguments;  
		var argc = Util.CookieHelper.setCookie.arguments.length;  
		var expires = (argc > 2) ? argv[2] : exp;  
		var path = (argc > 3) ? argv[3] : null;  
		var domain = (argc > 4) ? argv[4] : null;  
		var secure = (argc > 5) ? argv[5] : false;  
		document.cookie = name + "=" + escape (value) + 
			((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
			((path == null) ? "" : ("; path=" + path)) +  
			((domain == null) ? "" : ("; domain=" + domain)) +    
			((secure == true) ? "; secure" : "");
	},
	deleteCookie:function(name)
	{
	    var exp = new Date(); 
		exp.setTime(exp.getTime() - (30*24*60*60*1000));
        Util.CookieHelper.setCookie(name,"",exp);
	}
	
};

/*******************************/
/***** Utility *****/
/*******************************/
function ScrubInput(p_s) {
	var arr = [/\t/g,/\r/g,/\n/g,/\?/g,/\(/g,/\)/g,/\</g,/\>/g,/\'/g,/\"/g]; //'
	for (var i=0;i<arr.length;i++){ p_s=p_s.replace(arr[i],' '); }
	return p_s;
}
function SizeContents() {
	//size the topiclist and topiccontents divs to enable correct vertical scrolling
	var leftColIds = ['projects','search','faqnav','tocnav'];
	var oTList = document.getElementById("topiclist");
	var rightColIds = ['topicheader','topicfooter','topicfdbck'];
	var oTopic = document.getElementById("topiccontents");
	var availHeight;
	var usedHeight = 0;
	var hFactor = 32;
	
	//get the height of the area that contains the document
	var currWinHeight;
	if (window.innerHeight) {//FireFox with correction for status bar at bottom of window
		currWinHeight = (!IsHC()) ? window.innerHeight - 22 : window.innerHeight - 10;
	} else if (document.documentElement.clientHeight) {//IE 7 with correction for address bar
		currWinHeight = (!IsHC()) ? document.documentElement.clientHeight - 24 : document.documentElement.clientHeight - 10;
	} else if (document.body.offsetHeight) {//IE 4+
		currWinHeight = (!IsHC()) ? document.body.offsetHeight - 5 : document.body.offsetHeight + 10;
	}
	
	// Size the topiclist div in the left column
	// 1st calculate the used height of the objects whose height does not change
	for (var i = 0; i < leftColIds.length; i++) {
		var oElem = document.getElementById(leftColIds[i]);
		if (oElem != null && typeof oElem == "object") {
			usedHeight += oElem.offsetHeight;
		}
		//alert("id:" + leftColIds[i] + "\n" + "elemHeight:" + oElem.offsetHeight);//DEBUG
	}
	// 2nd set the height of the topiclist div to the available height
	availHeight = currWinHeight - usedHeight - hFactor;
	if (availHeight >= 0) oTList.style.height = availHeight + "px";
	//alert("currWinHeight:" + currWinHeight + "\n" + "usedHeight:" + usedHeight + "\n" + "height:" + (currWinHeight - usedHeight - hFactor));//DEBUG
	
	// Size the topic div in the right column
	// 1st calculate the used height of the objects whose height does not change
	usedHeight = 0;
	for (var i = 0; i < rightColIds.length; i++) {
		var oElem = document.getElementById(rightColIds[i]);
		if (oElem != null && typeof oElem == "object") {
			usedHeight += oElem.offsetHeight;
		}
		//alert("id:" + rightColIds[i] + "\n" + "elemHeight:" + oElem.offsetHeight);//DEBUG
	}
	// 2nd set the height of the topic div to the available height
	availHeight = currWinHeight - usedHeight - hFactor - 1;
	
	//alert(currWinHeight);
	//alert(availHeight);
	if (IsIE7()) availHeight += 14;
	else if (IsFireFox()) availHeight += 17;
	if (availHeight >= 0) oTopic.style.height = availHeight + "px";
	//alert("currWinHeight:" + currWinHeight + "\n" + "usedHeight:" + usedHeight + "\n" + "height:" + (currWinHeight - usedHeight));//DEBUG
}
var _agent = navigator.userAgent;
function IsIE() {
	return 	(_agent.indexOf("MSIE ") > -1);
}
function IEVersion() {
	var idx = _agent.indexOf("MSIE ");
	return parseFloat(_agent.substring(idx + 5,_agent.indexOf(";",idx)))
}
function IsIE7() {
	return 	(IsIE() && IEVersion() >= 7.0);
}
function IsFireFox() {
	return (_agent.indexOf("Firefox") > -1);
}
function GetElemHeight(p_el) {
	if (p_el.innerHeight) return p_el.innerHeight;
	else if (p_el.clientHeight) return p_el.clientHeight;
	else return p_el.offsetHeight;
}
function GetWinHeight() {
	if (window.innerHeight) return window.innerHeight;
	else if (document.documentElement.clientHeight) return document.documentElement.clientHeight;
	else if (document.body.offsetHeight) return document.body.offsetHeight;
	else return _winHeight;
}
function GetWinWidth() {
	if (window.innerWidth) return window.innerWidth;
	else if (document.documentElement.clientWidth) return document.documentElement.clientWidth;
	else if (document.body.offsetWidth) return document.body.offsetWidth;
	else return _winWidth;
}
function rt(p_name) {//related topic link click
	HT.show(p_name);
	return false;
}
function st(p_name) {//TOC link click
	return TL.clickLink(p_name)
}
function ttb(p_bkid) {//TOC book click
	TOC.bookClick(p_bkid);
	return false;
}
function tti(p_id,p_ev) {//TOC image event
	TOC.toggleImg(p_id,p_ev)
}
function ShowMovie(p_file,p_features){
	if (p_features == null || p_features.length == 0) p_features = "width=640,height=480";
	OpenNewWin(GetContentUrlPath(p_file)+".htm","moviewin",p_features);
}
function GetContentUrlPath(p_file) {
	return _targetedPath + _mkt + "/" + HT.getCurrentTopicProject() + "/content/" + p_file;
}
function GoToSupport(p_url) {
	if (p_url.indexOf(_cuSessionPlaceholder) != -1) p_url = p_url.replace(_cuSessionPlaceholder,_guid);
	MapLog.UserSentToSupport();//omniture
	if (IsHC()) {
		try {top.location.href = p_url;}//open within the Tango frame
		catch(e){OpenNewWin(p_url,"supwin","");}//error so open in new window
	}
	else OpenNewWin(p_url,"supwin","");//open in new window
	return false;
}
function OpenNewWin(p_url,p_name,p_features) {
	var win = window.open(p_url,p_name,p_features);
	if (win != null && typeof win == 'object') win.focus();
}
function IsHC() {//Help Central?
	return (_fmt == 'b2');
}
function IsRTL() {//RTL language?
	return (document.body.dir == 'rtl');
}
function HandleOnLoad() {
	if (_querytype == 'topic') {
		if (_query.toLowerCase() == _welcomePage) HT.showWelcome();
		else HT.show(_query);
		FAQ.getFAQ();
	} else if (_querytype == 'keyword' || _querytype == 'search') {
		HT.showWelcome();
		//alert(_query.toLowerCase());
		if (_query.toLowerCase() == _faqKeyword) FAQ.showFAQ();
		else Search.getResults(_querytype,_query);
	}
	CM.setMinLeft();

	//Initialize the survey
	Survey.InitSurvey();

}
function HandleWinResize() {
	SizeContents();
}
function HandleOnBeforeUnload() {
    try
    {
    	Survey.ShowSurvey();
    	MapLog.UserClosesHelp();//Omniture
    }
    catch (e) {}
}
var cacheWinHeight = null;
/***** End Utility *****/

/***** Attach events *****/
window.onload = HandleOnLoad;
window.onresize = HandleWinResize;
window.onbeforeunload = HandleOnBeforeUnload;

/***** Survey Object *********/
function Survey() {}
Survey.InitSurvey = function() {
	Survey.project = Proj.getCurrentProject();
	Survey.market = (_mkt != null) ? _mkt.toLowerCase() : "";
	if (_querytype.toLowerCase() == "keyword") {
		Survey.keyword = _query;
	} else {
		Survey.keyword = "";
	}
	Survey.randNumMax = .01;
	Survey.markets = new Array("en-us");
	Survey.projects = new Array("messengerw11");
}

Survey.ShowSurvey = function() {
	if (Survey.IsSurveyProject()
		&& Survey.UserWasRandomlySelected()
		&& Survey.UserHasNotSeenSurvey()
		&& Survey.IsSurveyMarket())
    {
		Survey.LaunchSurveyWindow();
		Survey.SetCookie();	
    }
}

Survey.LaunchSurveyWindow = function() {
	//Launch the page
	var url = "https://www.msnfeedback.com/perseus/surveys/961278308/70c6c6ca.htm"
			   + "?keyword=" + Survey.keyword 
			   + "&product_ID=" + Survey.project 
			   + "&article_ID=" + Survey.GetTopic()
			   + "&session_ID=" + _guid;
	//alert("DEBUG TEST: URL: " + url);
	window.open(url, "", "height=285,width=300,scrollbars=yes");
}

Survey.GetTopic = function() {
	var topic = TH.getCurrentTopic() ;
	switch (topic)
	{
		case "":
			topic = "Welcome.htm";
			break;
		case "wlgmh.htm":
			topic = "GetMoreHelp";
			break;
	}
	return topic;
}

Survey.SetCookie = function() {
	//Set a cookie that won't expire for a year, so that the user won't see it again
	var exp = new Date(); 
	exp.setTime(exp.getTime() + (365*24*60*60*1000));
	Util.CookieHelper.setCookie("seenSurvey", "1", exp, "/");
}

Survey.UserWasRandomlySelected = function() {
	var n = Math.random();
	//alert("DEBUG TEST: Rand num: " + n);
	return (n < Survey.randNumMax);
}

Survey.UserHasNotSeenSurvey = function() {
	var seenSurvey = Util.CookieHelper.getCookie("seenSurvey");
	//alert("DEBUG TEST: Seen survey: " + seenSurvey);
	return ( seenSurvey == null) ? true : false;
}

Survey.IsSurveyProject = function() {
	if (Survey.project != null)
	{
		Survey.project = Survey.project.toLowerCase();
		for (var i=0; i < Survey.projects.length; i++) {
			if (Survey.project == Survey.projects[i].toLowerCase()) {
				return true;
			}
		}
	}
	//alert(Survey.project);
	return false;
}

Survey.IsSurveyMarket = function() {
	if (Survey.market != null)
	{
		for (var i=0; i < Survey.markets.length; i++) {
			if (Survey.market == Survey.markets[i].toLowerCase()) {
				return true;
			}
		}
	}
	//alert("DEBUG TEST: Survey.IsSurveyMarket returning false");
	return false;
}

Survey.market;
Survey.project;
Survey.keyword; 
Survey.randNumMax;
Survey.markets;
Survey.projects;


/***** End Survey Object *****/

/***** DHTML Code for Topics *****/
//	Note: Many functions are designed for templates that have subtopic_choice (STC) radio buttons.
var _STCCntxt = "";
var _CurrCntxt = "";
var	_aCntxtElems;
var	_aCntxtRelElems;
/* Functions called from content */
function ccTest(p_val) {
	//Conditional content test
	return (V4Has(p_val) || AgentHas(p_val));
}
function topicOnLoad() {
	if (ExistsForm("SubtopicChoiceForm")) {
		// set the classNames of the elements that have context
		// or are related ancestors of the context elements
		_aCntxtElems = new Array('INSTRUCTIONS','MORE_INFO','LINK');
		_aCntxtRelElems = new Array('LINKS');
		HideCntxtCntnt(); //hide elements with context
		ResetSTCForm(); //assure subtopic choice buttons are unchecked and context is nothing
	} else {
		//ShowCntxtCntnt()
	}
}
function clickedSubtopicChoice(strContext) {
	SetSTCCntxt( strContext );//remember context
	HideCntxtCntnt();//1st hide context content
	ShowCntxtCntnt();//2nd show context content dependent on new context
}
function clickedSubtopicChoiceText(p_cntxt,p_id) {
	oSubtopicChoice = getElementById(p_id);
	oSubtopicChoice.checked = true;
	clickedSubtopicChoice(p_cntxt);
}
function toggleDefinition(p_id) {
	//Legacy for bCentral
	if ( getStylePropertyById(p_id,'display')=='none') setStylePropertyById(p_id,'display','inline');
	else setStylePropertyById(p_id,'display','none');
}
function toggleTips(p_elid,p_imgid) {
	var oTipsImageElement = getElementById(p_imgid);
	if ( getStylePropertyById(p_elid,'display')=='none') {
		setStylePropertyById(p_elid,'display','block');
		if (oTipsImageElement != null) oTipsImageElement.src="LivePage/PicFiles/arrowbluedown.gif";
	} else {
		setStylePropertyById(p_elid,'display','none' );
		if (oTipsImageElement != null) oTipsImageElement.src="LivePage/PicFiles/arrowblueright.gif";
	}
}
function TakeMeThereMSN(p_url) {
	//assure that the protocol is correct (http: or https:)
	p_url = location.protocol + p_url.substring(p_url.indexOf(":") + 1);
	var sWName = (openername && openername != '') ? openername : "_helpext";
	window.open(p_url,sWName);
}
/*Internal Functions*/
function V4Has(p_val) {
	if (typeof p_val == 'string' && p_val != "" && typeof v4 == 'string' && v4 != "") {
		var aV4 = v4.split(',');
		var aValues = p_val.split(',');
		for(i = 0; i < aV4.length; i++) {
			for(j = 0; j < aValues.length; j++) {
				if (aV4[i] == aValues[j]) return true;
			}
		}
	}	
	return false;
}
function AgentHas(p_val) {
	if (typeof p_val == 'string') {
		if (p_val != "") {
			var aValues = p_val.split(',');
			for(j = 0; j < aValues.length; j++) {
				if (navigator.userAgent.indexOf(aValues[j]) != -1) return true;
			}
		}
	}	
	return false;
}
function ResetSTCForm() {
 	if ( ExistsForm("SubtopicChoiceForm") ) {
	 	//uncheck all SubtopicChoice radio elements
 		var oRadioGroup = document.forms["SubtopicChoiceForm"].SubtopicChoice;
 		for (var i = 0; i < oRadioGroup.length; i++) {
 			oRadioGroup[i].checked = false;
 		}
 		SetSTCCntxt("");//set subtopic_choice context to nothing
 	}
}
function SetCurrCntxt() {_CurrCntxt = GetSTCCntxt();}//Set current context
function SetSTCCntxt(p_cntxt) {_STCCntxt = p_cntxt;}//Set subtopic_choice context
function GetSTCCntxt() {return _STCCntxt;}//Get subtopic_choice context
function GetElemCntxt(p_el) {
	//The context is contained in the id attribute
	return (p_el.id) ? p_el.id : "";
}
function IsCntxtElem(p_el) {
	// Is p_el an element that uses the id attribute to indicate the context?
	for (var i=0; i < _aCntxtElems.length; i++)	{
		if (p_el.className == _aCntxtElems[i]) return true;
	}
	return false;
}
function IsCntxtRelElem(p_el) {
	// Is p_el an element whose display depends on a child elements context?
	for (var i=0; i < _aCntxtRelElems.length; i++) {
		if (p_el.className == _aCntxtRelElems[i]) return true;
	}
	return false;
}
function ShowCntxtCntnt() {
	// Display all elements appropriate for the context
	var e;
	var eLinks;
	//First, assure that current context is up-to-date
	SetCurrCntxt();
	if (document.all) {
		for (var i = 0; i != document.all.length; i++) {
			e = document.all[i];
			if (e.className == 'LINKS') eLinks = e;
			ShowCntntForCntxtElem(e,eLinks);
		}
	} else if (document.getElementsByTagName) {
		//elements with INSTRUCTIONS, MORE_INFO, LINKS className are <div> tags
		var elems = document.getElementsByTagName("div");
		for (var i = 0; i != elems.length; i++) {
			e = elems[i];
			if (e.className == 'LINKS') eLinks = e;
			ShowCntntForCntxtElem(e,eLinks);
		}
		//elements with LINK className are <a> tags
		elems = document.getElementsByTagName("a");
		for (var i = 0; i != elems.length; i++) {
			e = elems[i];
			ShowCntntForCntxtElem(e,eLinks);
		}
	}
}
function HasTheCntxt(strElementContext,strCurrentContext) {
	// Does element have current context?
	var aElemCntxt = strElementContext.split(",");
	for (var i = 0; i < aElemCntxt.length; i++) {
		if (aElemCntxt[i] == _CurrCntxt) return true;
	}
	return false;
}
function ShowCntntForCntxtElem(p_el,p_links) {
	if (IsCntxtElem(p_el))	{
		if (HasTheCntxt(GetElemCntxt(p_el),_CurrCntxt))	{
			if (p_el.className == 'LINK') setStylePropertyByElement( p_links, 'display', '' ); // display the related LINKS container
			if (p_el.className == 'SUBTOPIC_CHOICE') {
				var oSubtopicChoicesElement = getElementById('SUBTOPIC_CHOICES');
				if (oSubtopicChoicesElement != null) setStylePropertyByElement( oSubtopicChoicesElement, 'display', '' ); // display the related LINKS container
			}
			setStylePropertyByElement(p_el,'display','');
		} else {
			setStylePropertyByElement(p_el,'display','none');
		}
	}
}
function HideCntntForCntxtElem(p_el) {
	if ( (IsCntxtElem(p_el)) || (IsCntxtRelElem(p_el)) ) {
		setStylePropertyByElement( p_el, 'display', 'none' );
	}
}
function HideCntxtCntnt() {
	// Hide all elements that have context
	if (document.all) {
		for (var i = 0; i != document.all.length; i++) {
			HideCntntForCntxtElem(document.all[i]);
		}
	} else if (document.getElementsByTagName) {
		//elements with INSTRUCTIONS, MORE_INFO, LINKS className are <div> tags
		var elems = document.getElementsByTagName("div");
		for (var i = 0; i != elems.length; i++) {
			HideCntntForCntxtElem(elems[i]);
		}
		//elements with LINK className are <a> tags
		elems = document.getElementsByTagName("a");
		for (var i = 0; i != elems.length; i++) {
			HideCntntForCntxtElem(elems[i]);
		}
	}
}
/***** End Original Dynamic Help Code (Pane Help and HTML Help) *****/
/***** Generic Cross Browser Code *****/
function blur(p_el) {p_el.blur();}
function ExistsForm(p_name) {
	var form = document.forms[p_name];
    return (form != null && typeof form == "object");
}
function getElementById(p_id) {
    if (document.getElementById) return document.getElementById( p_id );
    else if (document.all) return document.all[p_id];
    else return null;
}
function getElementObject(p_el) {
	if (typeof p_el == "object") return p_el;
	else if (typeof p_el == "string") return getElementById( p_el );
}
function getStyleBySelector(p_sel) {
    if (!document.getElementById) return null;
    var sheets = document.styleSheets;
    var rules; var i; var j;
    //look through stylesheets in reverse order that they appear in the document
    for (i=sheets.length-1; i >= 0; i--) {
        rules = sheets[i].cssRules;
        for (j=0; j<rules.length; j++) {
            if (rules[j].type == CSSRule.STYLE_RULE && rules[j].selectorText == p_sel) {
                return rules[j].style;
            }   
        }
    }
    return null;
}
function getStylePropertyById(p_id,p_prop) {
    if (document.getElementById) {
        var oS = document.getElementById( p_id );
        if (oS != null) {
            oS = oS.style;
            if (oS[p_prop]) return oS[ p_prop ];
        }
        oS = getStyleBySelector( "#" + p_id );
        return (oS != null) ? oS[p_prop] : null;
    } else if (document.all) {
        return document.all[p_id].style[p_prop];
    } else {
		return "";
	}
}
function setStylePropertyById(p_id,p_prop,p_val) {
    if (document.getElementById) {
        var oS = document.getElementById(p_id);
        if (oS != null) {
            oS = oS.style;
            oS[p_prop] = p_val;
        }
    } else if (document.all) {
		if (document.all[p_id] != null)	document.all[p_id].style[p_prop] = p_val;
    } else {} //so Nav4 won't return error
}
function setStylePropertyByElement(p_el,p_prop,p_val ) {
    if (document.getElementById) {
        var oS = p_el;
        if (oS != null) {
            oS = oS.style;
            oS[p_prop] = p_val;
        }
    } else if (document.all) {
		if (p_el != null) p_el.style[p_prop] = p_val;
    } else {} //so Nav4 won't return error
}
function toggleElementDisplay(p_el,p_style) {
	// p_style = (none,block,inline)
	var id;
	if (typeof p_el == "object") id = p_el.id;
	else if (typeof p_el == "string") id = p_el;
	if ((id != "") && (id != null)) {
		if (getStylePropertyById(id,'display')=='none') setStylePropertyById(id,'display',p_style);
		else setStylePropertyById(id,'display','none');
	}
}
function toggleImg(p_el,p_img1,p_img2) {
	var e = getElementObject(p_el);
	if (e != null) {
		// p_img1 may be like PicFiles/arrowblueright.gif
		// so need to get only the image name and compare to image current displayed
		var indx = p_img1.lastIndexOf("/");
		var imgName = (indx != -1) ? p_img1.substring(indx + 1,p_img1.length) : p_img1;
		var strSrc = e.src;
		e.src = (strSrc.indexOf(imgName) > -1) ? e.src = p_img2 : e.src = p_img1;
	}
}
function changeImg(p_el,p_img) {
	var e = getElementObject(p_el);
	if (e != null) e.src = p_img;
}
/***** End Generic Cross-Browser Code *****/

