
// Take user here after session timed out
timedouturl = "session-timed-out.html";
TimeOutValue = "02:00"
bTimeOutChanged = false;
StrTimeoutMsg = "";
nHasEventFired = 0;
var IsNewSearch = 0;
var HasBeenSearched = 0;

function CheckForSearchTerm(FormEl, strMsg) {
    var FrmImput = document.getElementById(FormEl);
    //var FrmFocus = document.getElementById("formMain");
    if (FrmImput.value == "") {
        if (FormEl != 'ctrlSearchbarSimple_textboxTerm') {
            alert(strMsg);
            //FrmImput.focus();
            return false;
        }
    }
    else {
        if (HasBeenSearched == 0) {
            HasBeenSearched = 1;
            IsNewSearch = 2;
            //FrmFocus.focus();
            return true;
        } else {
            //FrmFocus.focus();
            return false;
        }

    }
}





var addthis_config = { data_use_flash: false, services_compact: 'delicious, mailto, facebook, google, live, myspace, stumbleupon, twitter, more', services_exclude: 'print,email', data_track_clickback: false, ui_click: true }

var addthis_share = { templates: { twitter: 'check out {{url}} (Title: {{title}})'} }


function MakeAtLbVisible(atBid) {
    addthis.init();
    var browserName = navigator.appName;
    var chld = 'AtLbChild' + atBid
    var ChldEl = document.getElementById(chld);
    ChldEl.style.display = "block";
    ChldEl.focus();
    var frm = document.getElementById("formMain");
    if (browserName == "Netscape") {
        var clrtext = "MakeAtLbHidden('" + atBid + "');"
        frm.setAttribute("onmouseup", clrtext);
    } else {
        frm.onmouseup = function () { MakeAtLbHidden(atBid); };
    }
}

function MakeAtLbHidden(atBid) {
    var chld = 'AtLbChild' + atBid
    var ChldEl = document.getElementById(chld);
    ChldEl.style.display = "none";
    var browserName = navigator.appName;
    var frm = document.getElementById("formMain");
    if (browserName != "Netscape") {
        frm.detachEvent("onmouseup", MakeAtLbHidden);
    } else {
        frm.removeEventListener("onmouseup", MakeAtLbHidden, true);
    }
}





function ResetTimer() {
    bTimeOutChanged = true;
    //IsNewSearch = 1;
    //HasBeenSearched = 0;
    
}

function Minutes(data) {
    for (var i = 0; i < data.length; i++)
        if (data.substring(i, i + 1) == ":")
        break;
    return (data.substring(0, i));
}
function Seconds(data) {
    for (var i = 0; i < data.length; i++)
        if (data.substring(i, i + 1) == ":")
        break;
    return (data.substring(i + 1, data.length));
}
function DisplayTime(min, sec) {
    var disp;
    if (min <= 9) {
        disp = " 0";
    }
    else {
        disp = " ";
    }
    disp += min + ":";
    if (sec <= 9) {
        disp += "0" + sec;
    }
    else {
        disp += sec;
    }
    return (disp);
}
function CountDown() {
    sec--;
    if (sec == -1) { sec = 59; min--; }
    if (bTimeOutChanged == true) {
        //alert("Time out changed");
        min = 1 * Minutes(TimeOutValue);
        sec = 0 + Seconds(TimeOutValue);
        window.status = "";
        bTimeOutChanged = false;
    }
    if (min == 0) {
        window.status = StrTimeoutMsg + "  " + DisplayTime(min, sec);
    }

    if (min == 0 && sec == 0) {
        //alert("Your session has timed out.");
        window.location.href = timedouturl;
    }
    else {
        down = setTimeout("CountDown()", 1000);
    }
}
function timeInActivity(InactivityPeriod, DefaultURL, TimeoutMsg) {
    if (nHasEventFired == 0) {
        TimeOutValue = InactivityPeriod;
        timedouturl = DefaultURL;
        StrTimeoutMsg = TimeoutMsg;
        min = 1 * Minutes(TimeOutValue);
        sec = 0 + Seconds(TimeOutValue);
        nHasEventFired = 1;
        CountDown();
        
    }
}


function getHTTPObject() 
{
	var requester;

	try 
	{ 
		requester = new XMLHttpRequest(); 
	} 
	catch (error) 
	{ 
		try 
		{ 
			requester = new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
		catch (error) 
		{ 
			requester = false; 
		}
	}
	
	return requester;
}

function collapse(root)
{
	var nextSibling = getNextSibling(root);

	while (nextSibling != null)
	{
		if (nextSibling.className == "location")
			return;

		if (nextSibling.className == root.className)
			return;

		nextSibling.style.display = "none";
		nextSibling = getNextSibling(nextSibling);
	}				
}

function getNextSibling(startBrother)
{
    endBrother = startBrother.nextSibling;
    
    while (endBrother != null && endBrother.nodeType != 1)
    {
        endBrother = endBrother.nextSibling;
    }
    
    return endBrother;
}

function getCollectionIMGNode(root)
{
   var node = root;

   while (1)
   {
       node = node.firstChild;
       while (node != null && node.nodeName == "#text" || (node.nodeName == "IMG" && node.src.search("plus") == -1  && node.src.search("minus") == -1 ))
           node = node.nextSibling;
       
       if (node == null)
           break;
       
       if ((node.nodeName == "IMG") && ((node.src.search("plus") != -1 ) || (node.src.search("minus") != -1 )))
           break;
   }   
   
   return node;
}

function expand(root)
{
	var nextSibling = getNextSibling(root); 
	var pieceDisplay = "";

	while (nextSibling != null)
	{
		if (nextSibling.className == root.className)
			return;

		switch (nextSibling.className)
		{
		case "collection":
			nextSibling.style.display = "";
			var img = getCollectionIMGNode(nextSibling);
			if (img != null)
			{
				if (img.src.search("plus") == -1)
					pieceDisplay = "";
				else
					pieceDisplay = "none";								
			}
			break;
		case "piece":
			nextSibling.style.display = pieceDisplay;
			break;
		}

		nextSibling = getNextSibling(nextSibling); //nextSibling.nextSibling;
	}				
}

function doToggle(e, plus, minus, plusAlt, minusAlt)
{	
	var img;
    var element;
    
    if (e.srcElement)
        element = e.srcElement;
    else
        element = e.target;
    
	if (element.className == "group")
	{
		switch (element.nodeName)
		{
		case "A":
			img = element.firstChild;
			break;
		case "IMG":
			img = element;
			break;
		default:
			return;
		}
	}
	else
		return;

	var root = img.parentNode.parentNode.parentNode.parentNode;
	var display;
						
	if (img.src.search("plus") == -1)
	{
		img.src = plus;
		img.alt = plusAlt;
		collapse(root);
	}
	else
	{
		img.src = minus;
		img.alt = minusAlt;
		expand(root);
	}
}


