/* Modified 090112.1555 */
/* Mactopia only*/

var defObj, myPop, fooBar, arrow, arrowShowAll; 	// Global vars
var IE, mac, win, Mz, Awk, NN;		// Global vars for browser types
var hiliteColor='#9F9F9F';		// Highlight color for mouseovers
var courseNavHilite='#FFFFFF';
var courseNavNoHilite='#EEEEEE';
var courseNavBorder='1px solid #999999';
var courseNavNoBorder='1px solid #EEEEEE';
var tOpen = uiArtFolder + 'triangle_open.gif';
var tClose = uiArtFolder + 'triangle_closed.gif';
var tTrans = uiArtFolder + 'triangle_transition.gif';
var cmdKey = uiArtFolder + 'cmd.gif';
var delxKey = uiArtFolder + 'delx.gif';
var CSect = 'sect_1';
var CNav = 'nav_1';
var usid;

var procSelected=false;			// Flag indicating a procedure has been selected

// Check the browser type using the userAgent property set the browser var and global var 'ua'
(navigator.userAgent.indexOf('MSIE') > -1)?IE=true:IE=false;
(navigator.userAgent.indexOf('Firefox') > -1)?Mz=true:Mz=false;
(navigator.userAgent.indexOf('AppleWebKit') > -1)?Awk=true:Awk=false;
(navigator.userAgent.indexOf('Netscape') > -1)?NN=true:NN=false;
(navigator.userAgent.indexOf('Windows') > -1)?win=true:win=false;
(navigator.platform.indexOf('MacPPC') > -1)?mac=true:mac=false;
(navigator.platform.indexOf('MacIntel') > -1)?mac=true:mac=false;
var ua;
if(NN) ua='NN';
if(IE) ua='IE';
if(Awk) 	ua='Awk';
if(Mz) ua='Mz'; 

// Set global arrays with style info for DIVs used in popup defs

if(IE){
	if(mac) { document.styleSheets[2].disabled = false;}
	else { document.styleSheets[1].disabled = false; }
}
else if (Mz || NN){
	document.styleSheets[1].disabled =  true;
	document.styleSheets[2].disabled =  true;
	if(mac){
		document.styleSheets[3].disabled =  false;
		document.styleSheets[4].disabled =  true;
	}
	else {
		document.styleSheets[3].disabled =  true;
		document.styleSheets[4].disabled =  false;
	}
}

	
// divStyle holds style properties for the enclosing DIV for the popup
var divStyle = ['position', 'border', 'width', 'cursor', 'marginTop' ];
	divStyle['position']='absolute';
	divStyle['border']='1px solid #999999';
	divStyle['width']='20em';
	divStyle['cursor']='default';
	switch (ua){
		case 'IE':
				divStyle['marginTop']='-.25em';
				break;
		default:
				divStyle['marginTop']='-1.5em';
	}
	
	
var oReq;
	
//onLoad event handler checks to see if there are expandos. If so we display 'Show All'
function init(){
	if(window.name == 'pfview')
	{
		DoPrintFriendlySetup();
	}

	EnableCourseNavs();

	if(IE){ 
		if(document.all.expando){
			document.all.showHideAll.innerHTML = showText;
			document.all.showHideTable.style.display='block';
		}
	}
	else{
		if(document.getElementsByName('expando').length > 0){
			document.getElementById('showHideAll').innerHTML = showText;
			document.getElementById('showHideTable').style.display='block';
		}
	}
	
	if(win){
		var nodeSet = document.getElementsByName('cmd');
		for (i=0; i < nodeSet.length; i++){
			if(Mz || NN){
				nodeSet[i].innerHTML = '<img src="' + cmdKey + '">';
			}
			else if(IE){
				nodeSet[i].innerHTML = '&#122';
			}
		}
		nodeSet = document.getElementsByName('delx');
		for (i=0; i < nodeSet.length; i++){
			if(Mz || NN){
				nodeSet[i].innerHTML = '<img src="' + delxKey + '">';
			}
			else if(IE){
				nodeSet[i].innerHTML = '&#214';
			}
		}
	}

	setTitlePadding();

	if(window.name == 'pfview')
	{
		return;
	}

	var loc = document.URL;
    loc = loc.split("?");
	var qstr;
	var dom = GetDomainForCookie(loc[0], true);
	var fulldom = GetDomainForCookie(loc[0], false);
	var path = "; path=/";
	var hasQueryId = false;

	if(loc.length > 1)
	{
		qstr = loc[1];
		logPageView(qstr, false);  //set this to true to pop up an alert with response text
		loc = loc[1].split("&");
		for(i=0; i < loc.length; i++)
		{
			var s = loc[i].split("=");

			//#############
			//081120: Modified lines for test
			if(s[0] == "quid"){
				document.cookie = "queryidguid=" + s[1] + dom + path;
				hasQueryId = true;
			}
			/*
			if(s[0] == "usid") {
				usid = s[1];
			}
			else if(s[0] == "quid"){
				document.cookie = "queryidguid=" + s[1] + dom + path;
				hasQueryId = true;
			}
			*/
			//###############
		}
	}

	if(!hasQueryId){
		DeleteCookie("queryidguid", dom);
	}
	
	ResetFeedbackForm();

	if(document.cookie.indexOf("apuserguid") != -1)
	{
		if(usid == null) { 
			usid = GetCookie("apuserguid");
			//usid = GetApuserguid(); 
		}
	}
	else { 
		if(usid == null) usid = altuserguid;
		var date = new Date();
		date.setTime(date.getTime()+(365*24*3600*1000));
		document.cookie = "apuserguid=" + usid + "; expires=" + date.toGMTString() + dom + path;
	}
}	

function DeleteCookie(cookieName, dom)
{
	if(document.cookie.indexOf(cookieName) != -1)
	{
		var cookieValue = GetCookie(cookieName);
		var date = new Date();
		date.setTime(date.getTime()-(365*24*3600*1000));
		document.cookie = cookieName + "=" + cookieValue + "; expires=" + date.toGMTString();
	}
}

function GetDomainForCookie(url, useSubDomain)
{
	var rval = "";
	if(url.indexOf("microsoft.com") > -1){
		if(useSubDomain){
			rval = "; domain=.microsoft.com";
		}
		else{
			rval ="; domain=mac.microsoft.com";
		}
	}
	return rval; 
}	

function setTitlePadding()
{
	if(null != document.getElementById('showHideTable')) {
		var factor = 2;
		if(locale.toLowerCase() == 'ja-jp') factor = 1;
		var show = showText.length;
		var hide= hideText.length;
		var len = (show > hide)?show:hide;
		var pad = (len / factor) + 2;
		var ttl = document.getElementById('mainttl');
		if(null != ttl){
			ttl.style.paddingRight = pad + "em";
		}
	}
}

function ResetFeedbackForm()
{
	var obj = document.getElementById('feedbackForm');
	if(obj != null){
		obj.reset();
		var nodeset = document.getElementsByTagName('TEXTAREA');
		for(var i = 0; i < nodeset.length; i++) {
			nodeset[i].value = "";
		}
	}
}

/*
function GetApuserguid() 
{
	var cookies = document.cookie;
	var apuserguid;
	cookies = cookies.split(';');
	for(var i = 0; i < cookies.length; i++)
	{
		if(cookies[i].indexOf("apuserguid=") == 0)
		{
			var str = cookies[i].split("=");
			if(str[1].length == 36) apuserguid = str[1];
			break;
		}
	}
	return apuserguid;
}
*/

function GetCookie(cookieName) 
{
	var cookieNameEq = cookieName + "=";
	var cookies = document.cookie;
	var rval = "";
	cookies = cookies.split(';');
	for(var i = 0; i < cookies.length; i++)
	{
		var c = cookies[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if(c.indexOf(cookieNameEq) == 0)
		{
			var str = c.split("=");
			if(str.length == 2){
				rval = str[1];
			}
			break;
		}
	}
	return rval;
}

function GetNewGuid() 
{
	var apuserguid;
	oReq = GetNewRequestObject(oReq);
	oReq.open("POST", "SearchO12.aspx?render=text", false);
	oReq.send();
	apuserguid = oReq.responseText;
	//alert(apuserguid);
	return apuserguid;
}

function GetNewRequestObject(req)
{
	if (window.XMLHttpRequest)
	{
	   req = new XMLHttpRequest();
	}
	else
	{
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return req;
}

function logPageView(qstr, flag)
{
    //flag = true;              // Un-comment for debug
	oReq = GetNewRequestObject(oReq);

	//###################
	//081120: New test line 
	qstr = qstr + "&usid=" + GetCookie("apuserguid");
	//###################

	qstr = qstr + "&rand=" + Math.round(Math.random() * 1000000).toString();
	if(oReq != null)
	{
		//alert(qstr);
		if(flag)	oReq.onreadystatechange = reportQcount;
		oReq.open("POST", "LogO12.aspx?" + qstr, true);
		oReq.send(qstr);
	}
}

function reportQcount()
{
	if(oReq.readyState == 4) alert("LogO12.aspx reports: \r" +  oReq.responseText);
}
	
// OnClick handler expands or collapses expando DIVs
function showHideBlock(obj, e, flag){
	if(e){
		if(!event){ var event=e; }
		// event.cancelBubble=true;  					// Stop event propogation (Commented out to fix bug #1281)
	}
	var targetObj=obj.nextSibling;  			// expando DIV is the next sibling of the DIV with the click handler
	while (targetObj.nodeName != 'DIV') {
		targetObj=targetObj.nextSibling;
	}
	obj=obj.childNodes[0];
	while(obj.nodeName!= 'IMG'){
		switch(obj.hasChildNodes()){
			case true: 
				obj=obj.childNodes[0];
				break;
			case false:
				obj=obj.nextSibling;
		}
	} 
	arrow=obj;
	if(flag){
		switch(flag){
			case 'show':
									targetObj.style.display='block';
									obj.src=tOpen;  
									return;
			case 'hide':
									targetObj.style.display='none';
									obj.src=tClose;
									return;
		}
	}
	else{
		if (targetObj.style.display=='none'){  	// If DIV is not displayed, show it
			targetObj.style.display='block';
			arrow.src=tTrans;
			setTimeout("arrow.src=tOpen", 50) 
		}
		else{
			targetObj.style.display='none'; 		// Otherwise DIV is displayed, so hide it
			arrow.src=tTrans;
			setTimeout("arrow.src=tClose", 50) 
		}
	}
}

// hilite is used with mouseover event on radio procedures 
function hilite(obj){
	//obj.style.textDecoration='underline';
	obj.style.borderBottom='1px solid '+ hiliteColor;   // dashed
	obj.style.color=hiliteColor;
}

// unhilite is used with mouseout events on radio procedures
function unhilite(obj){
	// if(!procSelected) return;
	// if(obj.childNodes[0].checked==true) obj.style.color=hiliteColor;
	// else obj.style.color=unHiliteColor;
	//obj.style.textDecoration='none';
	obj.style.borderBottom='0px solid #FFFFFF';
	obj.style.color='';
}

// expand function is for expanding definitions inline -- not currently used
function expand(objID){
	document.getElementById(objID).style.display='inline';
}

// collapse function is for hiding inline definitions -- not currently used
function collapse(objID){
	document.getElementById(objID).style.display='none';
}

// Hides any current definition popup -- click handler of BODY
function hide(){
	if(defObj) defObj.style.visibility='hidden';					// global defObj refers to DIV id="defDiv" -- Used only with Safari
	if(fooBar){																	// global fooBar refers to current dynamically inserted definition DIV used with other browsers
		fooBar.style.display='none';									// Hide the DIV
		fooBar.parentNode.removeChild(fooBar);				// Now remove it from the document
		fooBar=null;															// Reset the global
	
	}
}

// Stops event propagation to click handler of BODY
function cancel(e){
	if(!event) var event=e;													// stop event propagation to BODY
	else e=event;
	event.cancelBubble=true;
}

// Shows the popup definition -- click handler of SPAN holding term
// e is passed event, objID is the @id of the hidden definition span
function showDef(e, objID){
	if(!event) 
	{
		var event=e;
	}
	//else e=event;
	event.cancelBubble=true;  // stop event propagation to BODY

	var x, y, w;																			// vars for positioning popup DIV
	x1 = 240; 
	x2 = x1 + 25;
	if(NN || Mz) event.srcElement=event.target;
	
	//var htmlContent = '<div class="termdiv">'+ document.getElementById(objID).id +'</div>';   				// create content string for DIV

	if(!event.srcElement.innerHTML)	var htmlContent = event.srcElement.nodeValue;
	else var htmlContent = event.srcElement.innerHTML;
	//alert(htmlContent.length);
	if (htmlContent.length > 30){
		w = parseInt((((htmlContent.length - 30) *.5)  + 20));
		x1 = w * 12;
		x2 = x1 + 25;
		w = w + 'em';
	}
	var htmlContent = '<div class="termdiv">'+ htmlContent +'</div>';   				// create content string for DIV
	htmlContent += '<div class="termdefdiv">'+ document.getElementById(objID).innerHTML +'</div>'; 	

	switch (ua){																	// Different strokes for different folks
		case 'NN':
		case 'Mz':
		case 'IE':
				if(fooBar) fooBar.parentNode.removeChild(fooBar);		// If we've already got a def showing, remove it
				fooBar=null;																	// Reset global reference

				var foo=document.createElement('DIV');						// create a new DIV in document
				foo.innerHTML=htmlContent;
				fooBar=event.srcElement.parentNode.insertBefore(foo, event.srcElement);			// Insert the new definition DIV into the document
				fooBar.setAttribute('onclick', 'cancel(event)');				// Set the click event handler for the popup DIV so that it will not close if clicked

				for (param in divStyle) {												// Set the style properties for the popup DIV
					fooBar.style[param]=divStyle[param];
				}
				if(w) {
					fooBar.style.width = w;
				}

		        /////////////////////////////////////////////////////////////////////
                // This section updated 06/30/2008 to fix term popup in IE -- BEGIN
                x = e.clientX;			                                                    // Get the x location of the click event

                var ieOffset = document.getElementById('main').offsetLeft;

                if(x > (window.innerWidth - x1)) {	                                        // If x is too close to right window edge tweak it -- innerWidth is undef in IE
	            if((window.innerWidth - x1) < 25) {
		            x = 15;
	            }
	            else x = window.innerWidth - x2;
	            foo.style.left = x;
                }

                else if (x - ieOffset < 25) foo.style.left = 15;		                    // If x is too close to the left window edge, set it at a minimum position
                else foo.style.left = x - 25 - ieOffset;			                        // Otherwise just set the DIV 25px left of the event

                break;		
		        // This section updated 06/30/2008 to fix term popup in IE -- END
				/////////////////////////////////////////////////////////////////////
				
		case 'Awk':																			// If it's Safari (Apple WebKit), use the embedded defDiv
																									// 'cuz inserting a new DIV before the event source will cause a line permanent line break
				defObj = document.getElementById('defDiv');				// get the hidden DIV and set the global reference so we can hide it later
				var obj = defObj;															// set a local reference 
				x = event.x;																	// get the x location of the event
				if(x > (window.innerWidth - x1)){									// If x is too close to right window edge tweak it
					if((window.innerWidth - x1) < 25) {
						x = 15;
					}
					else x = window.innerWidth - x2;
				}
				else if(x < 25) x = 15;														// If x is too close to the left window edge, set it at a minimum position
				else x = x - 25;																// Otherwise just set the DIV 25px left of the event
				y=event.pageY-12;														// Get the y location of the event and adjust it
				obj=obj.style;
				obj.left=x;																	// Set the x location of the DIV
				obj.top=y;																	// Set the y location of the DIV
				if(w) obj.width = w;
				else obj.width = '';
				defObj.innerHTML=htmlContent;									// Insert content in definition DIV
				obj.visibility='visible';													// Show the DIV
				break;
	}
	if(event.target)
	{
		if(event.target.parentElement)
		{
			unhilite(event.target.parentElement);
		}
	}
	if(event.srcElement)
	{
		unhilite(event.srcElement);
	}
}

// Show the selected radio button procedurte in a multi-proc -- click handler of P holding procedure title and radio button
// Parameter obj is the event source
function showRadioProc (obj, e){
	if(!event) var event=e;																// stop event propagation to BODY
	else e=event;
	event.cancelBubble=true;
	if(procSelected) procSelected.checked = false;
																		// set flag indicating a proc has been selected
	var inputObj = obj.childNodes[0];
	while(inputObj.nodeName != 'INPUT'){
		inputObj=inputObj.nextSibling;
	}
	inputObj.checked=true;												// Select the radio button child of the event source
	procSelected = inputObj;
	
	var target=document.getElementById('contentDiv');					// set reference to empty DIV that will hold the displayed procedure
	obj = obj.parentNode.nextSibling;
	while(obj.nodeName != 'DIV'){
		obj = obj.nextSibling;
	}
	target.innerHTML=obj.innerHTML;		// Copy the content of the hidden procedure to DIV id="contentDiv"
	target.style.display='block';															// Display the DIV id="contentDiv"
	obj = document.getElementsByName('foo');								// Get the collection of radio buttons
//	for(i=0; i < obj.length; i++){															// Iterate the collection to gray out the text of unselected procedures
//		if(obj[i].checked) obj[i].parentElement.style.color='';
//		else obj[i].parentElement.style.color=unHiliteColor;
//	}
}

function showHideAll (srcObj){
	var obj = document.getElementById('showHideAll');
	var flag, nodeSet;
	unhilite(obj);
//	hflag=false;
	
	arrowShowAll=srcObj.childNodes[0];
	while(arrowShowAll.nodeName!= 'IMG'){
		switch(arrowShowAll.hasChildNodes()){
			case true: 
				arrowShowAll=arrowShowAll.childNodes[0];
				break;
			case false:
				arrowShowAll=arrowShowAll.nextSibling;
		}
	} 
	var str = obj.innerHTML;
	switch(IE){
		case true: 	nodeSet = document.all.expando;
							break;
		case false: 	nodeSet = document.getElementsByName('expando');
							break;
	}
	switch (str){
		case showText: 	obj.innerHTML=hideText;
								flag='show';
								arrowShowAll.src=tTrans;
								setTimeout("arrowShowAll.src=tOpen", 60) 
								break;
		case hideText: 	obj.innerHTML=showText;
								flag='hide';
								arrowShowAll.src=tTrans;
								setTimeout("arrowShowAll.src=tClose", 60) 
								break;
	}
	if(IE){
		 if(document.all.expando && !nodeSet.length){ 
			 showHideBlock(nodeSet, null, flag);
			 return;
		}
	}
	for(i=0; i<nodeSet.length; i++){
		showHideBlock(nodeSet[i], null, flag);
	}
}
function swaparrow(srcobj)
{	
	var flag = false;
	obj=srcobj.childNodes;
	for(i=0; i < obj.length; i++)
	{
		if(obj[i].nodeName)
		{
			if(obj[i].nodeName == 'IMG')
			{
				obj = obj[i];
				flag = true;
			}
		}
		if(flag) break;
	}
		
	if(obj.src.indexOf("course_arrow_r_disabled.gif") != -1)
	{
		obj.src = uiArtFolder + "/course_arrow_r.gif";
		srcobj.style.color = "#000000";
	}
	else if(obj.src.indexOf("course_arrow_l_disabled.gif") != -1)
	{
		obj.src = uiArtFolder + "/course_arrow_l.gif";
		srcobj.style.color = "#000000";
	}
	else if(obj.src.indexOf("course_arrow_r.gif") != -1)
	{
		obj.src = uiArtFolder + "/course_arrow_r_disabled.gif";
		srcobj.style.color = "";
	}
	else if(obj.src.indexOf("course_arrow_l.gif") != -1)
	{
		obj.src = uiArtFolder + "/course_arrow_l_disabled.gif";
		srcobj.style.color = "";
	}
}

function showSect(i, flag, srcObj)
{
	var srcDiv, targDiv, j;
	var srcNav, targNav;

	srcNav = CNav;

	if(srcObj != null){
		srcDiv = CSect;
		targDiv = "sect_" + i;
		//srcNav = CNav;
		targNav = "nav_" + i;
	}
	else{
		j = i;
		srcDiv = "sect_" + i;
		//srcNav = "nav_" + i;
	if(flag)	j--;
	else j++;
		targDiv = "sect_" + j;
		targNav = "nav_" + j;
	}
	CSect = targDiv;
	CNav = targNav;
	document.getElementById(srcDiv).style.display = '';
	document.getElementById(targDiv).style.display = 'block';
	window.scrollTo(0,0);
	document.getElementById(srcNav).style.border = courseNavNoBorder;
	document.getElementById(srcNav).style.backgroundColor = courseNavNoHilite;

	document.getElementById(targNav).style.border = courseNavBorder;
	document.getElementById(targNav).style.backgroundColor = courseNavHilite;
	if(document.getElementById(targNav).getAttribute('chapter') != null)
	{
		if(document.getElementById(targNav).getAttribute('chapter') != '')
		{
			var cnum = document.getElementById(targNav).getAttribute('chapter');
			var arrow = cnum + '_ar';
			if(document.getElementById(cnum).style.display != 'block')
			{
				expandNode(document.getElementById(arrow));
			}
		}
	}
	postback(i);
}

function postback(i)
{
	if(window.name == 'pfview')
	{
		return;
	}
	//alert("Posting log data for page change");
	var qstr = "MODE=pv&CTT=InContent";
	qstr = qstr + "&srcid=" + assetId;
	qstr = qstr + "&ep=5";
	qstr = qstr + "&locale=" + encodeURIComponent(locale);

	//###################
	//081120: New test line 
	qstr = qstr + "&usid=" + GetCookie("apuserguid");
	//qstr = qstr + "&usid=" + usid;
	//###################	

	if(clrver != null)
	{
		if(clrver != '')qstr = qstr + "&clr=" + clrver;
	} 
	var t;
	switch(n - i)
	{
		case -2: t = assetId + "#pfqr";
					 break;
		case -1: t = assetId + "#prnt";
					 break;
		case 0: t = assetId + "#fdbk";
					 break;
		case 1: t = assetId + "#qref";
					 break;
		case 2: t = assetId + "#quiz";
					 break;
		default: t = assetId + "#" + i + "-" + (n-3);
					 break;
	}

	qstr = qstr  + "&target=" + encodeURIComponent(t);	

	logPageView(qstr, false); //set this to true to pop up an alert with response text
}

function showAsPF(i)
{
    var url = document.URL; 
//    var folder = uiArtFolder;
    var newDoc = open(url, 'pfview');
	postback(i + 3);
//    var sectId = 'sect_' + i;
//    var pfvcontent = newDoc.document.getElementById(sectId);
//    var dropNode = newDoc.document.getElementById('qrPageHeading');
//    newDoc.document.getElementById(sectId).removeChild(dropNode);
//    alert('OK 602');
//    var contentDiv = newDoc.document.getElementById('coursecontent');
//    alert('OK 604');
//    newDoc.document.getElementById('main').replaceChild(pfvcontent, contentDiv);
//    alert('OK 607');
//    newDoc.document.getElementById('mootstyles').href = folder + 'mootpfv.css';
//    alert('OK 609');
}

function DoPrintFriendlySetup()
{
    var pfvcontent = document.getElementById(qrSectId);
    var dropNode = document.getElementById('qrPageHeading');
    pfvcontent.removeChild(dropNode);
    var contentDiv = document.getElementById('coursecontent');
    document.getElementById('main').replaceChild(pfvcontent, contentDiv);
    document.getElementById('mootstyles').href = uiArtFolder + 'mootpfv.css';
}

function expandNode(obj)
{
	arrow = getChild(obj, 'SPAN');
	arrow = getChild(arrow, 'IMG');
	
	obj = obj.parentNode.nextSibling;
	obj = getSibling(obj, 'TR');
	obj = getChild(obj, 'TD');
	obj = getChild(obj, 'DIV');
	
	if(obj.style.display == "none" || obj.style.display == ""){
		obj.style.display = "block";
		arrow.src = tTrans;
		setTimeout("arrow.src = tOpen", 50);
	}
	else{
		obj.style.display = "none";
		arrow.src = tTrans;
		setTimeout("arrow.src = tClose", 50);
	}
}

function getChild(obj, nname){
	obj = obj.firstChild;
	obj = getSibling(obj, nname);
	return obj;
}

function getSibling(obj, nname){
	while (obj.nodeName != nname){
		obj = obj.nextSibling;
	}
	return obj;
}

function doPrint(obj)
{
	//document.getElementById(CNav).style.borderColor = courseNavNoHilite;
	//document.getElementById(CNav).style.backgroundColor = courseNavNoBorder;
	//CNav = obj.id;
	//obj.style.borderColor = courseNavBorder;
	//obj.style.backgroundColor = courseNavHilite;
	//alert("Print functionality under development.");
	window.print();
	postback(n + 1);
}


// These functions specific to MOOT Courses

	function showAns(objID, groupID){
		var displayStyle = 'inline';
		if(Awk) displayStyle = 'block';
		var group = document.getElementsByName(groupID);

		for(i=0; i < group.length; i++){
			document.getElementById(groupID + (i + 1)).style.display = 'none'
			
		}
		document.getElementById(objID).style.display = displayStyle;
	}
	
	function selectRadio(objID, pos){
		document.getElementsByName(objID)[pos-1].click();
	}
	
	function doNothing(){}

// Extracted from MAML.macUA.xslt

function redirToLog(e)
{
	var alink, clrVersion, targid, qstr;
	if(e && e.currentTarget) alink = e.currentTarget;
	else
	{
		if(event.srcElement.nodeName != "A") alink = event.srcElement.parentNode;
		else alink = event.srcElement;
	}
	//alert(alink.nodeName);
	var redir = alink.getAttribute("logredir");
	var toExternal = false;
	(redir.indexOf("ToExternal") != -1) ? toExternal=true: toExternal=false;
	var href = alink.getAttribute("href");
	var url = href;
	var isLaunch = false;
	if(alink.getAttribute("isLaunch") == "true")
	{
		isLaunch = true;
	}
	if((clrMver == 99 && !toExternal) || isCourse || isLaunch)
	{
		var url = appPath + "UARedir.aspx";
	}
	if(clrMver >= 99)
	{
		clrVersion = alink.getAttribute("clrver");
		if(isLaunch)
		{
			clrVersion = clrVersion.replace("120", "99");
		}
	}
	targid = alink.getAttribute("targid");
							
	if ((url == null) || (url == ""))
	{
		return false;
	}
							
	qstr = "MODE=" + alink.getAttribute('MODE') + "&" + redir;
	qstr = qstr + "&srcid=" + assetId;
	qstr = qstr + "&ep=4";
	qstr = qstr + "&locale=" + encodeURIComponent(locale);

	//###################
	//081120: New test line 
	//qstr = qstr + "&usid=" + usid;
	//###################	

	if(clrver != null)
	{
		if(clrVersion != '')qstr = qstr + "&clr=" + clrVersion;
	} 
	if(targid != null)
	{
		if(targid != '') qstr = qstr + "&target=" + targid;
	}
	
	if(toExternal)
	{
		qstr = qstr + "&target=" + encodeURIComponent(href);
		//alert("qstr: " + qstr);
		logPageView(qstr, false);
		return true;
	} 
	globAlink = alink;
	globHref = href;
	alink.setAttribute("href", url + "?" + qstr);
	setTimeout(resetHref, 500);
	return true;
}

function resetHref()
{
	globAlink.setAttribute("href", globHref);
}

function redirToLog_Mactopia(e)
{
	var alink, clrVersion, targid, qstr;
	if(e && e.currentTarget) alink = e.currentTarget;
	else
	{
		if(event.srcElement.nodeName != "A") alink = event.srcElement.parentNode;
		else alink = event.srcElement;
	}
	//alert(alink.nodeName);
	var redir = alink.getAttribute("logredir");
	if (redir == null)
	{
	    return true;
	}
	var toExternal = false;
	(redir.indexOf("ToExternal") != -1) ? toExternal=true: toExternal=false;
	var href = alink.getAttribute("href");
	var url = href;
	var isLaunch = false;
	var isTargetBlank = false;
	if(alink.getAttribute("target") == "_blank")
	{
		isTargetBlank = true;
	}
	if(alink.getAttribute("isLaunch") == "true")
	{
		isLaunch = true;
	}
	if((clrMver == 99 && !toExternal) || isCourse || isLaunch)
	{
		//var url = appPath + "UARedir.aspx";
	}
	if(clrMver >= 99)
	{
		clrVersion = alink.getAttribute("clrver");
		if(isLaunch)
		{
			clrVersion = clrVersion.replace("120", "99");
		}
	}
	targid = alink.getAttribute("targid");
							
	if ((url == null) || (url == ""))
	{
		return false;
	}
							
	qstr = "MODE=" + alink.getAttribute('MODE') + "&" + redir;
	qstr = qstr + "&srcid=" + assetId;
	qstr = qstr + "&ep=4";
	qstr = qstr + "&locale=" + encodeURIComponent(locale);

	//###################
	//081120: New test line 
	//qstr = qstr + "&usid=" + usid;
	//###################		
	
	if(clrver != null)
	{
		if(clrVersion != '')qstr = qstr + "&clr=" + clrVersion;
	} 
	if(targid != null)
	{
		if(targid != '') qstr = qstr + "&target=" + targid;
	}
	
	if(toExternal)
	{
		qstr = qstr + "&target=" + encodeURIComponent(href);
		//alert("qstr: " + qstr);
		logPageView(qstr, false);
		return true;
	} 
	if (isTargetBlank && isLaunch)
	{
		alink.setAttribute("href", url + "?" + qstr);
	}
	else
	{
	    qstr = "&" + redir;

	//###################
	//081120: New test line 
	//qstr = qstr + "&usid=" + usid;
	//###################	

    alink.setAttribute("href", href + qstr);
	}
	globAlink = alink;
    globHref = href;
	setTimeout(resetHref, 500);
		
	return true;
}

function setAnchors()
{
	var aNodes = document.getElementsByTagName('A');
	
	for(i=0; i < aNodes.length; i++)
	{
		if(aNodes[i].attachEvent) aNodes[i].attachEvent("onclick", redirToLog_Mactopia);
		else aNodes[i].addEventListener("click", redirToLog_Mactopia, false);
	}
} 

/* Code for checking if user is online */
	// var soapEnvelope = '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><SOAP-ENV:Body><m:Ping xmlns:m="http://microsoft.com/AssistancePlatform/Search"><m:pingLevel>0</m:pingLevel></m:Ping></SOAP-ENV:Body></SOAP-ENV:Envelope>';

			  
	function PingWS()
	{
		 oReq = GetNewRequestObject(oReq);
		try
		{
			oReq.open("post", "PingWS.aspx", false);
			//oReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
			//oReq.setRequestHeader("SOAPAction", "http://microsoft.com/AssistancePlatform/Search/Ping");
			//oReq.send(soapEnvelope);
			oReq.send("");
			if(oReq.responseText.toLowerCase() == 'true')
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		catch(ex)
		{
			return false;
		}
	}

	function DisplayFeedbackError()
	{
		var fdbkDiv = document.getElementById('feedback');
		var fdbkErrorDiv = document.getElementById('feedbackError');
		if(null != fdbkDiv)
		{
			fdbkDiv.style.display = 'none';
		}
		if(null != fdbkErrorDiv)
		{
			fdbkErrorDiv.style.display = 'block';
		}
	}

	function EnableCourseNavs()
	{
		var nav1 = document.getElementById('firstNavTop');
		var nav2 = document.getElementById('firstNavBottom');
		if(nav1 != null) nav1.style.display = 'block';
		if(nav2 != null) nav2.style.display = 'block';
	}