/// <symmary>
/// LinkPopup is a generic Pop-Up Window function, replacing PopWindow for accessiblity concerns and cleaning code
/// Parameters are passed to the function instead of including them in the function.
/// URL parameter is replaced with "src", which references the link in the DOM, and uses the specified URL
/// Problems? Direct them to Tom Patros.
/// </summary>
function LinkPopup(src,width,height,xdistance,ydistance,resize,scroll) {
    //alert('pat');
	var OpenString = "'" + 'toolbar=0,'
	+ 'location=0,'
	+ 'directories=0,'
	+ 'status=0,'
	+ 'menubar=0,'
	+ 'scrollbars=' + scroll + ','
	+ 'resizable=' + resize + ','
	+ 'width=' + width + ','
	+ 'height=' + height + ','
	+ 'left=' + xdistance + ','
	+ 'top=' + ydistance + ','
	+ 'screenX=' + xdistance + ','
	+ 'screenY=' + ydistance + "'";
	
	var theWindow = window.open(src.getAttribute('href'),"_blank",OpenString)
	theWindow.focus();
	return theWindow;
}

/// <symmary>
/// Creates a new window
/// </summary>
function NewWindow(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable, menubar=yes'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

/// <symmary>
/// Creates a new search window
/// </summary>
function PopItSearch(filename, h, w) {
    popup = window.open(filename,"popDialog","height="+h+",width="+w+",scrollbars=yes")
}

/// <symmary>
/// Determines if the brwoser is FireFox 
/// </summary>
function IsFirefox() {
    return navigator.userAgent.toLowerCase().indexOf("firefox") > -1;
}

/// <symmary>
/// Determines if the brwoser is IE
/// </summary>
function IsIE() {
    return navigator.userAgent.toLowerCase().indexOf("msie") > -1;
}

/// <symmary>
/// Determines if the brwoser is Google Chrome
/// </summary>
function IsChrome() {
    return navigator.userAgent.toLowerCase().indexOf("chrome") > -1;
}

/// <symmary>
/// Synchronizes 2 tables side by side to make sure their row height match.
/// Used for the compare feature wich has a static left titles section and a right scrollable region
/// implemented using 2 side by side tables
/// WAS t2.rows[i].cells[0].style.width=t1.rows[i].cells[0].offsetWidth+'px'; */
/// WAS t1.rows[i].cells[0].style.height=t2.rows[i].cells[0].offsetHeight-5+'px' */
/// </summary>
function EqualiseTables(t1,t2){
	for(var i=0;i<t1.rows.length;i++) {
	    var delta = 10;
		if (IsFirefox()) {
		    delta = 0;
    	}
		t1.rows[i].cells[0].style.height=t2.rows[i].cells[0].offsetHeight-delta + 'px'
	}
}

/// <symmary>
/// LifeSciences specific version call to the EqualiseTables script.
/// THIS VERSION IS CHROME SAFE (the Chrome implementation of JavaScript does not trigger with the Register \Script thang! ;-(
/// Used for the compare feature wich has a static left titles section and a right scrollable region
/// </summary>
function EqualiseCompareTables() { 
    EqualiseTables(document.getElementById('comparetitles'),document.getElementById('comparedetails'));
}

/// <symmary>
/// Attaches the supplied function to the OnLoad page event 
/// THIS VERSION IS CHROME SAFE (the Chrome implementation of JavaScript does not trigger with the Register \Script thang! ;-(
/// Thanks JC for the script!
/// </symmary>
function AddPageEvent(ftn){
    if (window.addEventListener) {
        window.addEventListener("load", ftn, false);
    }
    if (window.attachEvent) {
        window.attachEvent("onload", ftn); 
    }
}

/****************************************************************
 * <summary>
 * Used to toggle Tree Node Visibility
 * </summary>
 ***************************************************************/
function toggleTreeNode(oid) {
    var element = document.getElementById("div" + oid);
    if (element != undefined) {
        var display = document.getElementById("div" + oid).style.display;
    	if ((display == undefined) || (display=="") || (display=="block") || (display == "inline")) {
            document.getElementById("div" + oid).style.display="none";
            document.getElementById("img" + oid).src = "/LifeSciences/Styles/images/tree/expand.gif";
        } else {
            document.getElementById("div" + oid).style.display="block";
            document.getElementById("img" + oid).src = "/LifeSciences/Styles/images/tree/collapse.gif";
        }
    }
}


/****************************************************************
 * <summary>
 * Used to toggle Tree Node Visibility
 * </summary>
 ***************************************************************/
function toggleNode(oid) {
    var element = document.getElementById(oid);
    if (element != undefined) {
        var display = document.getElementById(oid).style.display;
    	if ((display == undefined) || (display=="") || (display=="block") || (display == "inline")) {
            document.getElementById(oid).style.display="none";
        } else {
            document.getElementById(oid).style.display="block";
        }
    }
}

