/**********************************************************************
	MAP Javascript
**********************************************************************/

var curSelNavId = "";
//var origContentsHeight = -1;

// size the contents div, required because this is the only part of the UI that allows vertical scroll bar
function sizecontents()
{
	var hFactor = 0.98, usedHeight = 0, availHeight = 0;
	var leftColDivIds = ['topnav','hlpsrchctrl','msnsrchctrl','logo'];
	var oContents = getElementById("contents");
	//var rightColDivIds = ['feedback','contactus','msnsrchctrl'];
	//var oTopic = getElementById("topiccontent");
	
	//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 = window.innerHeight - 22;
	} else { //IE
		currWinHeight = document.body.offsetHeight;
	}
	
	// if present, then size the contents div
	if (oContents != null && typeof oContents == "object")
	{
		// calculate the used height of the objects whose height does not change
		for (var i = 0; i < leftColDivIds.length; ++i)
		{
			var oElem = getElementById(leftColDivIds[i]);
			if (oElem != null && typeof oElem == "object")
			{
				usedHeight += oElem.offsetHeight;
			}
		}
		
		// calculate the available height
		availHeight = (currWinHeight - usedHeight);
			
		// set the height of the contents div to the available height
		oContents.style.height = availHeight + "px";
	}
}
// Actions to perform when the help search input box receives focus.
// Change the class name (color change).
// Either select the value or delete it if it is the default value.
function srchbxfocus( oInput )
{
	if (oInput.className == "srchin") {
		// this is the default state so change it
		oInput.className = "srchinf";
		oInput.value = "";
	} else {
		// this is the state with user query input
		oInput.select();
	}
}
// Submit request for MAP help search using the query terms the user typed in the input box.
function dohelpsearch( sID )
{
	oInput = getElementById( sID );
	if ( oInput && oInput.className == "srchinf" )
	{
		// the input element is found and it has had focus 
		// which means that the value is not the default text
		var userquery = oInput.value;
		tmp = userquery.replace( / /g, "" ); // remove spaces to check query length
                try{
                   userquery=encodeURIComponent(userquery);
                }
                catch(ex){
	    	   userquery=escape(userquery);
                } 
		if ( tmp.length > 0 ) {
                   
			// the query is not empty, so submit the encoded string
			location.href = getbaseurl() + "?querytype=search&query=" + userquery;
		} else {
			// the query is empty; return focus to the input box
			oInput.focus();
		}
	}
}
// Submit the Help Search when the user presses the Enter key
// while focus is in the Help Search input box.
function dohelpsearchviaenter( evt, sID )
{
	evt = (evt) ? evt : event;
	var target = (evt.target) ? evt.target : evt.scrElement;
	var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
	if (charCode == 13 || charCode == 3) dohelpsearch(sID);
}
// Show the All Help links page
function showallhelp( url )
{
	var props = "toolbar=0,status=0,menubar=0,scrollbars,width=230,resizable";
	var allWin = window.open( url, "_allhelp", props );
	allWin.focus();
}
// Get the base url string
function getbaseurl()
{
	return location.protocol + "//" + location.hostname + location.pathname;
}
// Display a topic
function showtopic(filename)
{
	location.href = getbaseurl() + "?querytype=topic&query=" + filename;
}
function SubmitFeedbackMAP( appname, market, filename )
{
	var W = screen.width * 0.75;
	var H = screen.availHeight - 125;
	var szChrome = "toolbar=0,status=0,menubar=0,width="+W+",height="+H+",left=50,top=50,resizable=1";
	var uSurvey;
	if (navigator.userAgent.indexOf("Mac") == -1) {
		uSurvey = "http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw;en;1142&P0=" + appname + "&P1=" + market;
	} else {
		uSurvey = "http://go.microsoft.com/fwlink/?LinkId=19867";
	}
	uSurvey += "&P2=" + filename + "&P3=&P4=&P5=no&P6=&P7=&P8=";
	window.open(uSurvey,"survey",szChrome);
}
//function dofeedback()
//{
	// get the user rating
//	var feedbackRating = "";
//	var radioIds = ['fdbckbtnyes','fdbckbtnmaybe','fdbckbtnno'];
//	for (var i = 0; i < radioIds.length; ++i)
//	{
//		var oElem = getElementById(radioIds[i]);
//		if (oElem != null && typeof oElem == "object")
//		{
//			if (oElem.checked)
//			{
//				feedbackRating = oElem.value;
//				break;
//			}
//		}
//	}

	// get the verbatim feedback text
//	var feedbackText = "";
//	oElem = getElementById('feedbacktxt');
//	if (oElem != null && typeof oElem == "object")
//	{
//		feedbackText = oElem.value;
//	}
	
//	alert(feedbackRating + " : " + feedbackText);
	
	// hide the feedback control
	//setStylePropertyById( 'feedbackctrl', 'visibility', 'hidden' );
//}

// Set the class name of the element to the selected version.
// If another element had previously been selected, set its class name 
// back to the non-selected version.
function navsel( oElement, sClassName, sClassNameSel )
{
	if (curSelNavId != "")
	{
		// deselect the previously selected nav element
		oElement0 = getElementById( curSelNavId );
		oElement0.className = sClassName;
	}
		
	// select the current element
	curSelNavId = oElement.id;
	oElement.className = sClassNameSel;
	
	//alert( curSelNavId ); //debug
}
/* XMLHTTP example code
 Set objXMLHTTP = Server.CreateObject("Microsoft.XMLHTTP")
 objXMLHTTP.Open "GET", aURL, False
 objXMLHTTP.Send
 returnedText = objXMLHTTP.responseText
*/
function historyback()
{
	window.history.back();
}
function historyforward()
{
	window.history.forward();
}

/**********************************************************************
	End MAP Javascript
**********************************************************************/

/**********************************************************************
	Original Dynamic Help Code (Pane Help and HTML Help)
**********************************************************************/

/**********************************************************************
	Note: Many functions are designed for PROC, PH_MEGA, TROU topics
	which have subtopic_choice radio buttons.
	
	Note: Cannot use less-than or greater-than symbols
	in the javascript or the XML parser will crash.
**********************************************************************/

// Global variables
var g_strSubtopicChoiceContext = ""
var g_strCurrentContext = ""
var g_arrContextElements
var g_arrContextRelatedElements

var g_arrV4

//Create the getV4 function, and then run it.
function getV4()
{
	if ( typeof v4 == 'string' )
	{
		g_arrV4 = v4.split(',');
	}
	else
	{
		g_arrV4 = new Array('');
	}
}
getV4(); //execute the function during page load

//Conditional content test
function ccTest( strValue )
{
	return ( v4Contains(strValue) || userAgentContains(strValue) );
}

function v4Contains( strValue )
{
	if ( typeof strValue == 'string' )
	{
		if ( strValue != "" )
		{
			//Handle possible multiple values
			var arrValues;
			arrValues = strValue.split(',');
			
			for( i = 0; i < g_arrV4.length; i++ )
			{
				for( j = 0; j < arrValues.length; j++ )
				{
					if ( g_arrV4[i] == arrValues[j] ) return true;
				}
			}
		}
	}	
	return false;
}

function userAgentContains( strValue )
{
	if ( typeof strValue == 'string' )
	{
		if ( strValue != "" )
		{
			//Handle possible multiple values
			var arrValues;
			arrValues = strValue.split(',');
			
			for( j = 0; j < arrValues.length; j++ )
			{
				if ( navigator.userAgent.indexOf( arrValues[j] ) != -1) return true;
			}
		}
	}	
	return false;
}

function onPageLoad( strTemplate )
{
	//Even though the page is supposed to be fully loaded before the onLoad event is triggered,
	//Nav6 will return false from the existsForm function unless there is a slight delay before
	//querying for the existence of the form.
	if (isIE4)
	{
		startPage(strTemplate)
	}
	else if (isNav6) 
	{
		var strNext = "startPage('" + strTemplate + "')"
		setTimeout(strNext,0) //Even though the delay is set to 0, this works?!
	}
}

function startPage( strTemplate )
{
	if ((strTemplate == 'PROC') || (strTemplate == 'TROU') || (strTemplate == 'PH_MEGA'))
	{
		if ( existsForm("SubtopicChoiceForm") )
		{
			// set the classNames of the elements that have context
			// or are related ancestors of the context elements
			g_arrContextElements = new Array('INSTRUCTIONS','MORE_INFO','LINK')
			g_arrContextRelatedElements = new Array('LINKS')

			hideContextContent() //hide any elements that have context
			resetSubtopicChoiceForm() //make sure the buttons are unchecked and the context is nothing
		}
		else
		{
			showContextContent()
		}
	}	
}
function resetSubtopicChoiceForm()
{
 	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
 		}
 		//set the subtopic_choice context to nothing
 		setSubtopicChoiceContext("")
 	}
}

function setCurrentContext()
{
	g_strCurrentContext = getSubtopicChoiceContext()
}

function setSubtopicChoiceContext( strContext )
{
	g_strSubtopicChoiceContext = strContext
}

function getSubtopicChoiceContext()
{
	return g_strSubtopicChoiceContext
}

function hasTheContext( strElementContext, strCurrentContext )
{
	// Does this element have the current context

	var arrElementContext = strElementContext.split(",")
	
	for (var i = 0; i < arrElementContext.length; i++)
	{
		if ( (arrElementContext[i] == g_strCurrentContext) )
		{
			return true
		}
	}
	return false
}
function getElementContext( oElement )
{
	//The context is contained in the id attribute
	var strContext = ( oElement.id ) ? oElement.id : ""
	return strContext
}
function clickedSubtopicChoice( strContext )
{
	setSubtopicChoiceContext( strContext ) // remember the context
	hideContextContent()  // first, hide all context content
	showContextContent()  // finally, show all context content dependent on the new context
}
function clickedSubtopicChoiceText( strContext, strID )
{
	oSubtopicChoice = getElementById( strID );
	oSubtopicChoice.checked = true;
	clickedSubtopicChoice( strContext );
}
function isContextElement( oElement )
{
	// Is oElement an element that uses the id attribute to indicate the context?
	for (var i=0; i < g_arrContextElements.length; i++)
	{
		if (oElement.className == g_arrContextElements[i])
		{
			return true
		}
	}
	return false
}
function isContextRelatedElement( oElement )
{
	// Is oElement an element whose display depends on a child elements context?
	for (var i=0; i < g_arrContextRelatedElements.length; i++)
	{
		if (oElement.className == g_arrContextRelatedElements[i])
		{
			return true
		}
	}
	return false
}
function showContentForContextElement(oElement,oLinksElement)
{
	if (isContextElement(oElement))
	{
		if (hasTheContext(getElementContext(oElement),g_strCurrentContext))
		{
			if (oElement.className == 'LINK')
			{
				setStylePropertyByElement( oLinksElement, 'display', '' ) // display the related LINKS container
			}
			if (oElement.className == 'SUBTOPIC_CHOICE')
			{
				var oSubtopicChoicesElement = getElementById('SUBTOPIC_CHOICES')
				if (oSubtopicChoicesElement != null)
				{
					setStylePropertyByElement( oSubtopicChoicesElement, 'display', '' ) // display the related LINKS container
				}
			}
			setStylePropertyByElement( oElement, 'display', '' ) // display the element
		}
		else
		{
			setStylePropertyByElement( oElement, 'display', 'none' ) // hide the element
		}
	}
}
function showContextContent()
{
	// Display all elements appropriate for the context
	var oElement
	var oLinksElement
	
	//First, make sure that the current context is up-to-date
	setCurrentContext()
	
	if (isIE4)
	{
		for (var i = 0; i != document.all.length; i++)
		{
			oElement = document.all[i]
			if (oElement.className == 'LINKS') 
			{
				oLinksElement = oElement
			}
			showContentForContextElement(oElement,oLinksElement)
		}
	}
	else if (isNav6)
	{
		var colElements
		//elements with INSTRUCTIONS, MORE_INFO, LINKS className are <div> tags
		colElements = document.getElementsByTagName("div")
		for (var i = 0; i != colElements.length; i++)
		{
			oElement = colElements[i]
			if (oElement.className == 'LINKS') 
			{
				oLinksElement = oElement
			}
			showContentForContextElement(oElement,oLinksElement)
		}
		//elements with LINK className are <a> tags
		colElements = document.getElementsByTagName("a")
		for (var i = 0; i != colElements.length; i++)
		{
			oElement = colElements[i]
			showContentForContextElement(oElement,oLinksElement)
		}
	}
}
function hideContentForContextElement(oElement)
{
	if ( (isContextElement(oElement)) || (isContextRelatedElement(oElement)) )
	{
		setStylePropertyByElement( oElement, 'display', 'none' ) // hide the element
	}
}

function hideContextContent()
{
	// Hide all elements that have context
	var oElement
	
	if (isIE4)
	{
		for (var i = 0; i != document.all.length; i++)
		{
			oElement = document.all[i]
			hideContentForContextElement(oElement)
		}
	}
	else if (isNav6)
	{
		var colElements
		//elements with INSTRUCTIONS, MORE_INFO, LINKS className are <div> tags
		colElements = document.getElementsByTagName("div")
		for (var i = 0; i != colElements.length; i++)
		{
			oElement = colElements[i]
			hideContentForContextElement(oElement)
		}
		//elements with LINK className are <a> tags
		colElements = document.getElementsByTagName("a")
		for (var i = 0; i != colElements.length; i++)
		{
			oElement = colElements[i]
			hideContentForContextElement(oElement)
		}
	}
}


//This is legacy for bCentral content
function toggleDefinition( strDefID )
{

	if (isIE4 || isNav6)
	{
		if ( getStylePropertyById( strDefID,'display')=='none' )
		{
			setStylePropertyById( strDefID, 'display', 'inline' ) //show the Term
			
		}
		else
		{
			setStylePropertyById( strDefID, 'display', 'none' ) //hide the Term
			
		}
	}
	else if (alert("You must be running IE4 or later, Netscape 6 or later to expand this content."))
		{}

}



function toggleTips( strTipsID, strTipsImageID )
{
	var oTipsImageElement = getElementById( strTipsImageID )
	
	if (isIE4 || isNav6)
	{
		if ( getStylePropertyById( strTipsID,'display')=='none' )
		{
			setStylePropertyById( strTipsID, 'display', 'block' ) //show the Tips
			if (oTipsImageElement != null)
			{
				//show the down arrow
				oTipsImageElement.src = "../resources/neutral/arrowbluedown.gif";
			}
		}
		else
		{
			setStylePropertyById( strTipsID, 'display', 'none' ) //hide the Tips
			if (oTipsImageElement != null)
			{
				//show the right arrow
				oTipsImageElement.src = "../resources/neutral/arrowblueright.gif";
			}
		}
	}
    else
	{}	//so Nav4 won't return error
}
function TakeMeThereMSN( pathURL )
{
	//assure that the protocol is correct (http: or https:)
	pathURL = location.protocol + pathURL.substring(pathURL.indexOf(":") + 1);
	var sWName = (openername && openername != '') ? openername : "_helpext";
	window.open(pathURL,sWName);
}
function toggleALTTOCImg( element, strEvent )
{
	// redirect to the ti function
	ti( element, strEvent )
}
function ti( element, strEvent )
{
	var oElement;
	oElement = getElementObject( element );
	
	if (oElement != null)
	{
		var strSrc = oElement.src;
		var intIndex = strSrc.lastIndexOf("/");
		var strSrcRoot = "";
		var strImgName = strSrc;
		var strNewImgName;
		if (intIndex >= 0) 
		{
			strSrcRoot = strSrc.substring(0,intIndex+1);
			strImgName = strSrc.substring(intIndex+1,strSrc.length);
		}
		strImgName = strImgName.substring(0,strImgName.length - 4);
		switch (strImgName)
		{
			case "question_icon":
				strNewImgName = 'question_icon_hover';
				break;
			case "question_icon_hover":
				strNewImgName = 'question_icon';
				break;
			case "widget_plus":
				if ( strEvent == 'r')
					strNewImgName = 'widget_plus_hvr';
				else if ( strEvent == 't')
					strNewImgName = 'widget_plus';
				else
					strNewImgName = 'widget_minus';
				break;
			case "widget_plus_hvr":
				if ( strEvent == 't')
					strNewImgName = 'widget_plus';
				else
					strNewImgName = 'widget_minus';
				break;
			case "widget_minus":
				if ( strEvent == 'r')
					strNewImgName = 'widget_minus_hvr';
				else if ( strEvent == 't')
					strNewImgName = 'widget_minus';
				else
					strNewImgName = 'widget_plus';
				break;
			case "widget_minus_hvr":
				if ( strEvent == 't')
					strNewImgName = 'widget_minus';
				else
					strNewImgName = 'widget_plus';
				break;
		}
		oElement.src = strSrcRoot + strNewImgName + '.gif';
	}
}
/**********************************************************************
	End Original Dynamic Help Code (Pane Help and HTML Help)
**********************************************************************/

/**********************************************************************
	Generic Cross Browser Code
**********************************************************************/

var isIE4 = false;
var isNav4 = false;
var isNav6 = false;

function setBrowser()
{
	//Simple browser sniffer
	if (document.all)
	{
		isIE4 = true
	}
	else if (document.layers)
	{
		isNav4 = true
	}
	else if (document.getElementById)
	{
		isNav6 = true //also true for IE5.5
	}
}

setBrowser(); // determine which browser we are using

function blur( oElement )
{
	oElement.blur()
}

function existsForm( name )
{
	var form = document.forms[name];
    if ( form != null && typeof form == "object" )
		return true
	else
		return false
}
function getElementById( strId )
{
    if (isNav6)
    {
        return document.getElementById( strId );
    }
    else if (isIE4)
    {
        return document.all[strId]
    }
    else
	{
		return null
	}
}
function getElementObject( element )
{
	var oElement = null;
	
	// get the element
	if (typeof element == "object")
	{
		oElement = element;
	}
	else if (typeof element == "string")
	{
		oElement = getElementById( element );
	}
	return oElement;	
}
function getStyleBySelector( selector )
{
    if (!isNav6)
    {
        return null;
    }
    var sheetList = document.styleSheets;
    var ruleList;
    var i, j;

    /* look through stylesheets in reverse order that
       they appear in the document */
    for (i=sheetList.length-1; i >= 0; i--)
    {
        ruleList = sheetList[i].cssRules;
        for (j=0; j<ruleList.length; j++)
        {
            if (ruleList[j].type == CSSRule.STYLE_RULE && ruleList[j].selectorText == selector)
            {
                return ruleList[j].style;
            }   
        }
    }
    return null;
}
function getStylePropertyById( strId, strProperty )
{
    if (isNav6)
    {
        var styleObject = document.getElementById( strId );
        if (styleObject != null)
        {
            styleObject = styleObject.style;
            if (styleObject[strProperty])
            {
                return styleObject[ strProperty ];
            }
        }
        styleObject = getStyleBySelector( "#" + strId );
        return (styleObject != null) ?
            styleObject[strProperty] :
            null;
    }
    else if (isIE4)
    {
        return document.all[strId].style[strProperty];
    }
    else
	{
		return ""
	}
}
function setStylePropertyById( strId, strProperty, strValue )
{
    if (isNav6)
    {
        var styleObject = document.getElementById( strId );
        if (styleObject != null)
        {
            styleObject = styleObject.style;
            styleObject[ strProperty ] = strValue;
        }
    }
    else if (isIE4)
    {
		if (document.all[strId] != null)
			document.all[strId].style[strProperty] = strValue;
    }
    else
	{}	//so Nav4 won't return error
}
function setStylePropertyByElement( oElement, strProperty, strValue )
{
    if (isNav6)
    {
        var styleObject = oElement;
        if (styleObject != null)
        {
            styleObject = styleObject.style;
            styleObject[ strProperty ] = strValue;
        }
    }
    else if (isIE4)
    {
		if (oElement != null)
			oElement.style[strProperty] = strValue;
    }
    else
	{}	//so Nav4 won't return error
}





function toggleElementDisplay( element, strStyle )
{
	// strStyle = (none,block,inline)
	var strID
	
	//get the element id
	if (typeof element == "object")
	{
		strID = element.id	
	}
	else if (typeof element == "string")
	{
		strID = element
	}
	
	if ((strID != "") && (strID != null))
	{
		if (isIE4 || isNav6)
		{
			if ( getStylePropertyById( strID,'display')=='none' )
			{
				setStylePropertyById( strID, 'display', strStyle ) //show the element
			}
			else
			{
				setStylePropertyById( strID, 'display', 'none' ) //hide the element
			}
		}
	}
}
function toggleImg( element, strImg1, strImg2 )
{
	var oElement;
	oElement = getElementObject( element );
	
	if (oElement != null)
	{
		// strImg1 may be like ../resources/neutral/arrowblueright.gif
		// so need to get only the image name and compare to image current displayed
		var indx = strImg1.lastIndexOf( "/" );
		var imgName = ( indx != -1) ? strImg1.substring( indx + 1, strImg1.length ) : strImg1;
		var strSrc = oElement.src;
		if ( strSrc.indexOf( imgName ) > -1 )
		{
			oElement.src = strImg2;
		}
		else
		{
			oElement.src = strImg1;
		}
	}
}
function changeImg( element, strImg )
{
	var oElement;
	oElement = getElementObject( element );
	
	if (oElement != null)
	{
		var strSrc = oElement.src;
			oElement.src = strImg;
	}
}

/**********************************************************************
	End Generic Cross-Browser Code
**********************************************************************/

