var mSessionId = "";
var mCollectionLine = "";
var msie = false;
var mSavedListRSN = 0;

if (navigator.userAgent.toLowerCase().indexOf("msie") > 0)
{
	yearDiff = 0;
	msie = true;
}

function SessionId()
{
	return mSessionId;
}

function GetSessionId()
{
	return SessionId();
}

function CollectionLine()
{
	return mCollectionLine;
}

function SendAjaxCommand(url)
{
	var oScript = document.createElement("script");
	oScript.src = url;
	document.body.appendChild(oScript);
}

function HelpButtonClick(str)
{
	url = "/resource_files/" + str;
	win = window.open(url);
}

function ShowSavedListActions(e, rsn)
{
	if (!e)
	{
		if (typeof window.event!= "undefined")
			e = window.event;
		else if (typeof window.Event!="undefined")
			e = window.Event;
	}
	
	var mouseX = 0;
	var mouseY = 0;
	if (typeof e.pageX!="undefined")
	{
		mouseX = e.pageX;
		mouseY = e.pageY;
	}
	else
	{
		mouseX = e.clientX + document.body.scrollLeft;
		mouseY = e.clientY + document.body.scrollTop;
	}
	mSavedListRSN = rsn;
	
	var div = document.getElementById("mOnlySavedListActionDiv");

	div.style.left = mouseX-25 + "px";
	div.style.top = mouseY-25 + "px";
	div.style.visibility = "visible";
	div.style.display = "block";
}

function SavedListsMouseOutFunc(e)
{
	if (!e)
	{
		if (window.event)
			e = window.event;
		else if (window.Event)
			e = window.Event;
	}

	var mouseX = 0;
	var mouseY = 0;
	if (typeof e.pageX!="undefined")
	{
		mouseX = e.pageX;
		mouseY = e.pageY;
	}
	else
	{
		mouseX = e.clientX + document.body.scrollLeft;
		mouseY = e.clientY + document.body.scrollTop;
	}

	var divLeft = mOnlySavedListActionDiv.offsetLeft;
	var divTop  = mOnlySavedListActionDiv.offsetTop;
	var divRight = mOnlySavedListActionDiv.offsetLeft + mOnlySavedListActionDiv.offsetWidth;
	var divBottom = mOnlySavedListActionDiv.offsetTop + mOnlySavedListActionDiv.offsetHeight;

	if (mouseX < divLeft || mouseX > divRight || mouseY < divTop || mouseY > divBottom)
		HideTestDialog();
}

function HideTestDialog()
{
	if (mOnlySavedListActionDiv)
	{
		mOnlySavedListActionDiv.style.visibility = "hidden";
		mOnlySavedListActionDiv.style.display = "none";
	}
}

function AddDialogLink(name,url,savedListName)
{
	var html = "<a href=\"javascript:SavedListLink('" + url + "','" + savedListName + "')\">" + name + "</a><br/>";
	mOnlySavedListActionDiv.innerHTML += html;
}

function AddDialogDivider(name)
{
	var html = "<div style='font-size:15>&nbsp;&nbsp;<U>" + name + "</U></div>";
	mOnlySavedListActionDiv.innerHTML += html;
}

function AddDialogText(name)
{
	var html = name + "<br/>";
	mOnlySavedListActionDiv.innerHTML += html;
}

function SavedListLink(url, savedListName)
{
	if (mSavedListRSN == -1)
	{
		url += "&addPageToBasket=true"+ "&savedListActionList=" + savedListName;
	}
	else
	{
		url += "&addToBasket=" + mSavedListRSN + "&savedListActionList=" + savedListName;
	}
	mSavedListRSN = 0;
	window.location = url;
}

function GetNewListName()
{
	var newName = prompt("Please enter the name of the list");
	if (newName.length)
	{
		window.location = location + "&newlistname=" + newName;
	}
}

function HandleResultsClick(whatToDo, actionListName)
{
	//variables
	var frm = document.getElementById("ResultButtonsForm");
	
	switch(whatToDo)
	{
		case "renameList":
		{
			var renameName = prompt("Please enter the name of the list");
			if (renameName.length)
			{
				frm.renameList.value = 'true';
				frm.savedListActionList.value = actionListName;
				frm.renameListName.value = renameName;
				frm.submit();
			}
		} break;  

		case "removeList":
			frm.removeList.value = 'true';
			frm.savedListActionList.value = actionListName;
			frm.submit();
			break;
		
		case "printList":
			parent.openPopupMenu("/print/", "&savedListActionList="+actionListName);		
			break;
	}
}

function IncrementCapstoneCnt() {
    var url = "/ajax/incrementcapstonecnt.js";
    url += "?sessionid=" + GetSessionId();
    SendAjaxCommand(url);
}

function HideCapstoneLibImg(hideImg) {
    
    if(document.getElementById("capstone_img") != null && document.getElementById("capstone_img") != undefined)
    {    
        if (hideImg) {
            var rNavPanel = document.getElementById("right_nav_panel");
            var capstoneLibUrl = document.getElementById("capstone_img_url");
            rNavPanel.removeChild(capstoneLibUrl);
            
        }
    }
}

