
/* Cause anchors with the attribute rel="external" to open in a new
 * window and add descriptive text to the anchor title.
 * 
 * From: http://www.sitepoint.com/article/standards-compliant-world
 * with additions by Dave Fox
 */

var DEVELOPMENT_SERVER = "stage.jimmyfund.org";

function processExternalLinks () 
{
    if (!document.getElementsByTagName){
        return;
    }

    var anchors = document.getElementsByTagName("a");

    for (var i = 0; i < anchors.length; i++) {
        var anchor = anchors[i];
		var href = anchor.getAttribute("href");
		var rel = anchor.getAttribute("rel");

                if (document.domain && document.domain == DEVELOPMENT_SERVER &&
                    href && href.indexOf ("javascript:") == 0){
                        alert("This page contains a 'javascript:' psuedo URL!\n" + 
                              "The link with href \"" + href + "\"\n" +
                              "must be formatted properly for this message to go away.\n" +
                              "Please use proper URLs and onClick handlers for URL actions.");
                }

		if (href && (rel == "external" || rel == "dialog")){
			if (anchor.title){
				anchor.title += " (opens in a new window)";
			}
			else{
				if (rel == "dialog"){
					anchor.title = (anchor.innerText) ? anchor.innerText : anchor.text;
				}
				else{
					anchor.title = "Go to " + href;
				}
				anchor.title += " (opens in a new window)";
			}
			anchor.target = "_blank";
		}
    }
}

window.onload = processExternalLinks;

var DEFAULT_WINDOW_WIDTH = 640;
var DEFAULT_WINDOW_HEIGHT = 480;

function openWindow(url, width, height, decorationStr)
{
    if (width <= 0){
        width = DEFAULT_WINDOW_WIDTH;
    }

    if (height <= 0){
        height = DEFAULT_WINDOW_HEIGHT;
    }

    if (decorationStr){
        decorationStr += "," + "width=" + width + ",height=" + height;
    }
    else{
        decorationStr = "width=" + width + ",height=" + height;
    }

    newWindow = window.open(url, "newWindow", decorationStr);

    newWindow.opener = self;
    setTimeout("newWindow.focus();", 200);
}


function getElementById (element)
{
    if (document.getElementById) { 
        // DOM3 = IE5, NS6
	return document.getElementById(element);
    }
    else if (document.layers) { 
        // Netscape 4
	return document[element];
    }
    else { 
        // IE 4
	return document.all[element];
    }
}


/* Deprecated Functions - DO NOT USE FOR NEW PAGES */

function popWindow(url, height, width) 
{
    if (document.domain && document.domain == DEVELOPMENT_SERVER){
        alert("The popWindow() function is deprecated. Please use openWindow() instead");
        return;
    }
    openWindow(url, width, height, 
	       "toolbar=1,location=1,directories=0,status=0,menubar=1,scrollbars=1,resizable=1");
}

function popWindowMinimal(url, height, width) {
    if (document.domain && document.domain == DEVELOPMENT_SERVER){
        alert("The popWindowMinimal() function is deprecated. Please use openWindow() instead");
        return;
    }
    openWindow(url, width, height, 
	       "toolbar=1,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1");
}
	
function popWindowNoControls(url, height, width) {
    if (document.domain && document.domain == DEVELOPMENT_SERVER){
        alert("The popWindowNoControls() function is deprecated. Please use openWindow() instead");
    }
    openWindow(url, width, height, 
	       "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=auto,resizable=1");
}



