function getServerName()
{
    var str = window.location.protocol + '//' + window.location.hostname;
    return str;
}
function getHost()
{
	var server = getServerName();
	var path = location.pathname.toUpperCase();
	var host = "LOCAL";
	if(server.indexOf('.') > -1)
	{
		host = "LIVE";
		if(path.indexOf("DEMO") > -1)
		{
			host = "DEMO";
		}
		
	}
	return host;
}
function getQueryHash(qs) // just the query string with leading '?' removed or no argument for default
{
    var o = new Object();
    if (!qs) {
        qs = location.search.toString();
        qs = qs.substring(1, qs.length);
    }
    // Turn <plus> back to <space>
    // See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
    qs = qs.replace(/\+/g, ' ');
    var args = qs.split('&'); // parse out name/value pairs separated via &
    // split out each name=value pair
    for (var i = 0; i < args.length; i++) {
        var pair = args[i].split('=');
        var name = unescape(pair[0]);
        var value = (pair.length == 2) ? unescape(pair[1]) : name;
        o[name] = value;
    }
    return o;
}
function getOpener()
{
   var p = self;
   if(p.opener != null)
   {
    p = p.opener;
   }
   return p;
}
// gloabal constants
if(!window.Node)
    {
      var Node = {
        ELEMENT_NODE: 1,
        ATTRIBUTE_NODE: 2,
        TEXT_NODE: 3,
        COMMENT_NODE: 8,
        DOCUMENT_NODE: 9,
        COUMENT_FRAGMENT: 11
      }
}

/* This example is from the book _Ajax: The Definitive Guide_ by Anthony T. Holdener III.
 * Written by Anthony T. Holdener III.  Copyright (C) 2008 O'Reilly Media, Inc.
 * You may study, use, modify, and distribute this example for any purpose.
 * This example is provided WITHOUT WARRANTY either expressed or implied.
 */
/**
 * This method, _importNode, is a replacement for the DOM /document.importNode( )/
 * method. To ensure that any attribute events that are contained in the document
 * are fired when requested, it should go through this method instead. The standard
 * /importNode( )/ does not set the event handlers for events set as attributes in an
 * imported document, nor does it place style toward elements that should do such
 * things in the browser. An additional requirement is necessary for browsers like
 * Internet Explorer after the document has been imported - the /innerHTML/ of the
 * document where the import took place must be set equal to itself to invoke the
 * HTML Parse in the browser which will attach the event handlers.
 *
 * document.getElementById('myDiv').innerHTML = document.getElementById('myDiv').innerHTML;
 *
 * @param {Node} p_node The node to import into the main document,
 * @param {Boolean} p_allChildren The indicator of whether or not to include child
 * 		nodes in the import.
 * @return Returns a copy of the imported node, now as a part of the main document.
 * @type Node
 */
document._importNode = function(p_node, p_allChildren) {
	/* Find the node type to import */
	switch (p_node.nodeType) {
		case Node.ELEMENT_NODE:
			/* Create a new element */
			var newNode = document.createElement(p_node.nodeName);

			/* Does the node have any attributes to add? */
			if (p_node.attributes && p_node.attributes.length > 0)
				/* Add all of the attributes */
				for (var i = 0, il = p_node.attributes.length; i < il;)
					newNode.setAttribute(p_node.attributes[i].nodeName, p_node.getAttribute(p_node.attributes[i++].nodeName));
			/* Are we going after children too, and does the node have any? */
			if (p_allChildren && p_node.childNodes && p_node.childNodes.length > 0)
				/* Recursively get all of the child nodes */
				for (var i = 0, il = p_node.childNodes.length; i < il;)
					newNode.appendChild(document._importNode(p_node.childNodes[i++], p_allChildren));
			return newNode;
			break;
		case Node.TEXT_NODE:
		case Node.CDATA_SECTION_NODE:
		case Node.COMMENT_NODE:
			return document.createTextNode(p_node.nodeValue);
		break;
	}
};

/* This example is from the book _Ajax: The Definitive Guide_ by Anthony T. Holdener III.
 * Written by Anthony T. Holdener III.  Copyright (C) 2008 O'Reilly Media, Inc.
 * You may study, use, modify, and distribute this example for any purpose.
 * This example is provided WITHOUT WARRANTY either expressed or implied.
 */
/**
 * This function, openPageInDIV, makes an XMLHttpRequest to the passed /p_page/
 * parameter and the <body> of the page is then imported and appended into the
 * passed /p_div/ parameter. Using the custom document._importNode( ) method
 * ensures with most browsers that any attribute events that are contained in the
 * <body> will fire when called upon. For other browsers, like Internet Explorer,
 * setting the /p_div/'s /innerHTML/ equal to itself does the trick.
 *
 * @param {String} p_page The string filename of the page to get data from.
 * @param {String} p_div The string /id/ of the <div> element to put the data into.
 * @return Returns false, so that the <a> element will not attempt to leave the page.
 * @type Boolean
 */


function onKeyPressGeneric(e)
{
	var key = window.event ? e.keyCode : e.which;
	var keychar = String.fromCharCode(key);
	
}
function isValidDate(dateStr,t) 
{
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
	var matchArray = dateStr.match(datePat); // is the format ok?
	if (matchArray == null) 
	{
		alert("Date is not in a valid format.")
		return false;
	}
	month = matchArray[1]; // parse date into variables
	day = matchArray[3];
	year = matchArray[4];
	if (month < 1 || month > 12) 
	{ // check month range
		alert("Month must be between 1 and 12.");
		return false;
	}
	if (day < 1 || day > 31) 
	{
		alert("Day must be between 1 and 31.");
		return false;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) 
	{
		alert("Month "+month+" doesn't have 31 days!")
		t.focus();t.select();
		return false
	}
	if (month == 2) 
	{ // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap)) 
		{
		alert("February " + year + " doesn't have " + day + " days!");
		return false;
		}
	}
	return true;  // date is valid
}


 function featureAlert(e)
 {
 	//alert(e.screenX);
	var d = document.getElementById("features");
	if(d != null) return;
	d = document.createElement('DIV');
	d.innerHTML = 'Team or Site license required';
	d.style.position = "absolute";
	d.style.left = parseInt(e.clientX)+"px";
	d.style.top = parseInt(e.clientY)+"px";
	d.style.border = "1px";
	d.style.borderColor = "Black";
	d.style.borderStyle="solid";
	d.style.backgroundColor="White";
	d.id = "features";
	document.body.appendChild(d);
	setTimeout("featureDealert()",2000);
 }
 function featureDealert()
 {
 	var d = document.getElementById("features");
	document.body.removeChild(d);
 }
function LTrim(t)
{
	return t.replace(/^\s+/, '');
}
function RTrim(t)
{
	return t.replace(/\s+$/, '');
}
function Trim(t)
{
	return LTrim(LTrim(t));
}
function showIt(t,i) {
	var h = 'div'+i;
	var o = 'div'+i+'o';
	if (!t.checked) {
		
		if(true) {
			document.getElementById(h).style.display = "inline";
			document.getElementById(h).style.visibility= "visible";
			document.getElementById(o).style.display = "none";
			document.getElementById(o).style.visibility = "hidden";
		}
		else {
			document.getElementById(h).style.visibility="visible";
		}
	}
	else {
		if(true) {
			document.getElementById(h).style.display = "none";
			document.getElementById(h).style.visibility = "hidden";
			document.getElementById(o).style.display = "inline";
			document.getElementById(o).style.visibility = "visible";
		}
		else {
			document.getElementById(h).style.visibility="hidden";
		}
	}
	return true;
}
function hideItems() {
	t=arguments[0];
	var id = 'itemblock_'+t;
	if (arguments.length == 1) {
		if (document.getElementById(id).style.display == "none") {
			document.getElementById(id).style.display = "block";
			document.getElementById(id).style.visibility ="visible";
			id = 'f' + id;
			document.forms[0][id].value = 1;
		}
		else {
			document.getElementById(id).style.display = "none";
			document.getElementById(id).style.visibility ="hidden";
			id = 'f'+id;
			document.forms[0][id].value = 0;
		}
	}
	else {
		if (arguments[1] == 'showAll') {
			document.getElementById(id).style.display = "block";
			document.getElementById(id).style.visibility ="visible";
			id = 'f' + id;
			document.forms[0][id].value = 1;
		}
		else {
			document.getElementById(id).style.display = "none";
			document.getElementById(id).style.visibility ="hidden";
			id = 'f'+id;
			document.forms[0][id].value = 0;
		}
	}
}
function showHideBlocks(t) {
	for(var i=0; i< document.images.length;i++) 
	{
		if (document.images[i].name.indexOf("sh_") > -1 ) {
			var weid = document.images[i].name.split('_');
			hideItems(weid[1],t.value);
		}
	
	}
	return false;
}
var win1 = null;
var win2 = null;
var voewFB = null;
var winAss = null;
var winElement = null;
var winEmails = null;
var winProj = null;
var zoomWin = null;
var winPick = null;
var winSet = null;
function closeThem() {
	if(winHelp && !winHelp.closed) {winHelp.close();winHelp = null}
	if(win1 && !win1.closed) {win1.close();win1=null;}
	if(win2 && !win2.closed) {win2.close();win2=null;}
	if (winAss && !winAss.closed) {winAss.close();winAss=null;}
	if (winProj && !winProj.closed) {winProj.close();winProj = null;}
	if (winElement && !winElement.closed) {winElement.close(); winElement = null;}
	if (winEmails && !winEmails.closed) {winEmails.close();winEmails=null;}
	if (viewFB && !viewFB.closed) { viewFB.close();viewFB = null;}
	//alert(zoomWin == "undefined");
	if (zoomWin && !zoomWin.closed) {zoomWin.close();zoomWin=null;}
	if (winPick && !winPick.closed) {winPick.close();winPick=null;}
	//if (winSet) {winSet.close();winSet = null;}
	return true;
}
function showExpired(i) 
{
		if (i == 1) 
			alert('Trial period expired.\nComplete registration to extend your subscription\nPlease contact Waypoint if you decide NOT to subscribe.');
		if (i == 2)
			alert('Subscription expired.\nContact your Waypoint administrator or Subjective Metrics, Inc.');
}
function focusIt() {
		if(document.forms['instructor']) {
			for (var i=0;i<document.forms['instructor'].length;i++) {
				if (document.forms['instructor'][i].type == 'text') {
					document.forms['instructor'][i].focus();
					return;
				}
			}
		}
	}
function initAll() 
{
	document.all = (document.all) ? document.all : ((document.getElementsByTagName("*").length > 0) ?
	document.getElementsByTagName("*") : null)
}


// the following funtion is domain dependent
var win2 = null;
function help() 
{
	var w = screen.width> 800 ? 1000:800;
	var h = screen.height - 160;
	var path = "http://docs.subjectivemetrics.com/User/index.htm";
	if (arguments.length > 0)
	{
		//path += "?client_id="+arguments[0];
		var url = 'http://docs.subjectivemetrics.com/User/h_'+arguments[0]+'.htm';
		path = 'http://docs.subjectivemetrics.com/User/h_690550.htm';

	}
	// Andrew' new thingi - wiki - etci.
	path = 'http://www.waypointoutcomes.com/help/';
	if(win2) {win2.close()}
	win2=window.open(path,'help','width='+w+',height='+h+',left=0,top=10,resizable,scrollbars,menubar');
}
function showNotes() {
	var w = screen.width> 800 ? 1000:800;
	var h = screen.height - 160;
	var path = "showNotes.cfm";
	if(win2) {win2.close()}
	win2=window.open(path,'notes','width='+w+',height='+h+',left=0,top=10,resizable,scrollbars,menubar');
}
function turnAllOff()
{
	var mydivs = document.getElementsByTagName("div");
	for(i = 0; i<mydivs.length;i++)
	{
		if((mydivs[i].id.split("_")[0] == "CompDescr") || (mydivs[i].id.split("_")[0] == "ElementDescr"))
		{
			mydivs[i].innerHTML = "";
			mydivs[i].style.display = "none";
		
		}
	
	}
}
function showCompDescr(t,type_id,i,element_id,elementDivId,compDivId)
{
	var argsl = arguments.length;
	if(arguments.length > 3)
	{
		var d = document.getElementById(compDivId);
		var e = document.getElementById(elementDivId);
	}
	else
	{
		var d = document.getElementById("CompDescr_"+t.id.split('_')[1]);
		var e = document.getElementById("ElementDescr_"+t.id.split('_')[1]);
		var element_id = t.id.split('_')[1];
	}
	if(i> 0)
	{
		turnAllOff();
		try 
		{
		  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (ex) 
		{
		  try 
		  {
		    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		  } 
		  catch (e2) 
		  {
		    xmlHttp = false;
		  }
		}
		if (!xmlHttp && typeof XMLHttpRequest != 'undefined') 
		{
		  xmlHttp = new XMLHttpRequest();
		}

	    if(xmlHttp)
	    {
			// "<LI class='compList'>"+ 
			host = "LOCAL";
			var sURL = getServerName();
			var sPath = location.pathname;
			if(sURL.indexOf('.')> -1)
			{
				host = (sPath.toUpperCase().indexOf("DEMO") > -1) ? "DEMO" : "LIVE";
			}
			sURL += "/waypointNet/wpAPIs.aspx?action=GETELEMENTCOMPETENCYDESCRBYIDS&host="+host+"&comp_id="+type_id+"&element_id="+element_id;
			xmlHttp.open("GET",sURL,true);
			xmlHttp.onreadystatechange = function() 
	           {
	            if(xmlHttp.readyState == 4) 
	            {
	                myResponse = xmlHttp.responseText;
					        ds = myResponse.split("*****");
					        ds[0] = ds[0].replace(/&nbsp;$/,'').replace(/\n/g,'<br />');
					        if(ds[0].length > 0)
					        {
								if(!(argsl > 3))
								{
								e.style.display = "block";
								//e.innerHTML = 'Peter';
								e.innerHTML ="<LI class='compList'>"+ds[0]; //Safari doesn't allow this
								}
					        }
					        ds[1] = ds[1].replace(/&nbsp;$/,'').replace(/\n/g,'<br />');
					        if(ds[1].length > 0)
					        {
								d.style.display = "block";
								d.innerHTML = ds[1];
					        }
	            }
	           }
	          xmlHttp.send(null);
	     }
	 }
	 else
	 {
	 	turnAllOff();
	
	 }
}

