/*--
	Created By Chris Robinson
	Date: 07/21/05
--*/

/*--This is the Glossary Term Pop Up Code Start--*/
var x = 0;
var y = 0;
var no_data_box = "no_data";
var openedBoxes = new Array();

if(document.getElementById && document.all) {
	var isIE = true;
}else {
	var isNS = true;
}
function init() {
	document.onmouseup = mouseUp
	if (isNS) document.captureEvents(Event.MOUSEUP)
	hideCapSum();
	externalLinks();
	tryingToOpenResource();
}

function tryingToOpenResource() {
	var url = document.URL;
	if(url.indexOf("#") != -1) {
		var which = url.substring(url.indexOf("#") + 1);
		var id = which.substring(which.indexOf("_") + 1);
		//alert(which + " " + id);
		openResource(which, id, false);
	}
}


function hideCapSum() {
	if(getRoot("capSum")) {
		var root = getRoot("capSum");
		var flag = 0;
		if(root) {
			for(var i=0;i<root.childNodes.length; i++) {
				if(root.childNodes[i].nodeName == "P") {
					flag++;
					if(flag > 1) root.childNodes[i].style.display = "none";
				}
			}
		}
	}
}
function mouseUp(e) {
	x = (isNS)? e.pageX : event.x+(document.body.scrollLeft)
	y = (isNS)? e.pageY - 25 : event.y+(document.body.scrollTop)
	return true;
}
function closePopUps(selected) {
	for(var l = 1; l <= openedBoxes.length; l++) {
		var open = getRoot(openedBoxes[l-1]);
		if(openedBoxes[l-1] != selected) {
			open.style.display = "none";
		}
	}
}
function pop_open_help(id) {
	var root = getRoot(id);
	root.style.display = "block";
	root.style.top = (y + 40) + "px";
	root.style.left = (x - 340) + "px";
}
function close_pop_up_help(id) {
	//alert("this shouldnt be getting called");
	var root = getRoot(id);
	if(root) {
		root.style.display = "none";
	}
}
function pop_open(id) {
	var root = getRoot(id);
	if(root) {
		openedBoxes.push(id);
		closePopUps(id);
		root.style.display = "block";
		if(id != "postTestPopUpCont" && id != "AskAuthorPopupLayer") {
			if(getRoot(arguments[1]) && isIE) {
				var newRoot = getRoot(arguments[1]);
				//alert();
				y = newRoot.offsetTop
				x = newRoot.offsetLeft
				while((newRoot = newRoot.offsetParent) != null ) {
					y += newRoot.offsetTop
					x += newRoot.offsetLeft
				}
				x = x - 240;
			}else {
				y = y + 10;
				if(isNS) {
					y = y + 10;
				}
			}
			root.style.top = (y + 20) + "px";
			root.style.left = (x) + "px";
		}
	}
}
function close_pop_up(id) {
	var root = getRoot(id);
	root.style.display = "none";
}
var focusFlag = 0;
function clearFormValue(formVar) {
	if(focusFlag == 0) {
		formVar.value="";
		focusFlag++;
	}
}
function getRoot(id) {
	if(document.getElementById(id)) {
		return document.getElementById(id);
	}
}
/*--This is the Glossary Term Pop Up Code End--*/

/*--This is the Resource Library Code Start--*/
function resoruceRollEffect(whichResource, state) {
	 root = getRoot(whichResource, true);
	 if(state && root.className != "active") {
	 	root.className = "over";
	 }else if(state == false && root.className != "active") {
	 	root.className = "";
	 }
}
function openResource(whichResource, info) {
	root = getRoot(whichResource, true);
	if(root.className != "active") {
		root.className = "active";
		document.getElementById(info).style.display = "block";
	}else {
		if(arguments[2]) {
			root.className = "";
			document.getElementById(info).style.display = "none";
		}
	}
}

function longerTitle(which) {

	//if the element has a title attribute
	if(which.title) {
		//dynamically create an element to present the tool tip
		var div = document.createElement('div');
		//set the id of the new attribute
		div.setAttribute('id', "openTitle");
		//make a text node for the new element and set that text to be the title attribute
		var newText = document.createTextNode(which.title);
		//clear the title so the generic browser tool tip does not show
		which.title = "";
		//add the text node to our element
		div.appendChild(newText);
		//add our element to the body of the page
		
		//which.parentNode.parentNode.parentNode.parentNode.parentNode.appendChild(div);
		document.body.appendChild(div);
		
		var newRoot = which;
		y = newRoot.offsetTop;
		x = newRoot.offsetLeft;

		while((newRoot = newRoot.offsetParent) != null )
		{
			y += newRoot.offsetTop
			x += newRoot.offsetLeft
		}
		
		div.style.left = (x + 10) + "px";
		div.style.top = (y + 15) + "px";
		
		//If userEmail div is more than one line, move tooltip down for IE
		if(document.all && (getRoot("userEmail").offsetHeight > 15))
		{
			div.style.top = (y + 27) + "px";
		}

		div.style.width = "auto";
		div.style.textDecoration = "none";
		//set the position of the element with the mouse location
		div.style.position = "absolute";
		div.style.color = "#333";
		//the scrollable table has some adverse affects on the mouse location
		//so this check, if the pop is part of a table it will position it based on the cell
		//else it will position off of the mouse
		//getRoot("openTitle", true).style.top = "162px";
		//getRoot("openTitle", true).style.right = "24px";

	}

}
function killTitle(which) {
	//if the element exists
	if(getRoot("openTitle", true)) {
		//set the title of the element back to what it was with the text we put in the pop up element for reuse
		which.title = getRoot("openTitle", true).childNodes[0].nodeValue;
		//remove our dynamically created element
		//which.parentNode.parentNode.parentNode.parentNode.parentNode.removeChild(getRoot("openTitle", true));
		document.body.removeChild(getRoot("openTitle", true));

	}
}

/* functions to capture form values if needed */
var capture_recommend = false;
var capture_author = false;



function sync_forms(){
    /* only do this for real browsers */
    if(!document.getElementById){ return; }

    var login_form = document.getElementById("loginForm");
    var reg_form = document.getElementById("registerForm");
    var rec_form = document.getElementById("recommendColleagueForm");
    var field_list = ["content","subjectTitle","recipientsEmail","mailLastName","mailFirstName","loginEmail"];
    if(rec_form && login_form){
        for(var i=0; i<field_list.length; i++)
        {
            login_form[field_list[i]].value = rec_form[field_list[i]].value;
            reg_form[field_list[i]].value = rec_form[field_list[i]].value;
        }
    }
}

function externalLinks()
{
	if (!document.getElementsByTagName) return;
	var allLinks = document.getElementsByTagName("a");
	for(var f=0; f<allLinks.length; f++)
	{
		if(allLinks[f].getAttribute("target") == "external")
		{
			allLinks[f].onclick = newWin;
		}
	}
}

function newWin()
{
	window.open(this.href, null, "height=600, width=800, location=1, menubar=1, resizable=1, scrollbars=1, status=1, titlebar=1, toolbar=1");
	return false;
}
