function schedule(objectID, functionCall, iteration)
{
	if (iteration == null)
	{
		iteration = 0;
	}
	
	if (objectID == "window")
	{
		var oldonload = window.onload;
		
		if (typeof window.onload != "function")
		{
			window.onload = functionCall;
		}
		else
		{
			window.onload = function()
			{
				oldonload();
				functionCall();
			}
		}
	}
	else if (document.getElementById(objectID))
	{
		functionCall();
	}
	else if (iteration < 300)
	{
		setTimeout(function(){schedule(objectID, functionCall, iteration + 1)}, 10);
	}
	
	return true;
};


function getElementsByClassName(oElm, strTagName, oClassNames)
{
    var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    var arrRegExpClassNames = new Array();
    if(typeof oClassNames == "object")
	{
        for(var i=0; i<oClassNames.length; i++)
		{
            arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"));
        }
    }
    else
	{
        arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
    }
    var oElement;
    var bMatchesAll;
    for(var j=0; j<arrElements.length; j++)
	{
        oElement = arrElements[j];
        bMatchesAll = true;
        for(var k=0; k<arrRegExpClassNames.length; k++)
		{
            if(!arrRegExpClassNames[k].test(oElement.className))
			{
                bMatchesAll = false;
                break;                      
            }
        }
        if(bMatchesAll)
		{
            arrReturnElements.push(oElement);
        }
    }
    return (arrReturnElements);
}


function openWith(url, width, height)
{
	var name = "window" + width + height;
	var features = "toolbar=no,location=yes,status=no,menubar=yes,scrollbars=yes,resizable=yes,width="+width+",height="+height;
	window.open(url, name, features);
	
	return false;
};

/* Create the new window */
function openInNewWindow(e) {
	var event;
	
	if (!e) event = window.event;
	else event = e;
	// Abort if a modifier key is pressed
	if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) {
		return true;
	}
	else {
		// Change "_blank" to something like "newWindow" to load all links in the same new window
	    var newWindow = window.open(this.getAttribute('href'), '_blank');
		if (newWindow) {
			if (newWindow.focus) {
				newWindow.focus();
			}
			return false;
		}
		return true;
	}
}

function openCCVPop(e) {
	var event;
	if (!e) event = window.event;
	else event = e;
	// Abort if a modifier key is pressed
	if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) {
		return true;
	}
	else {
		// Change "_blank" to something like "newWindow" to load all links in the same new window
	    var newWindow = window.open(this.getAttribute('href'), '_blank', 'width=464, height=495');
		if (newWindow) {
			if (newWindow.focus) {
				newWindow.focus();
			}
			return false;
		}
		return true;
	}
}

/*
Add the openInNewWindow function to the onclick event of links with a class name of "accessible-target"
*/
function getNewWindowLinks() {
	// Check that the browser is DOM compliant
	if (document.getElementById && document.createElement && document.appendChild) {
		// Change this to the text you want to use to alert the user that a new window will be opened
		var strNewWindowAlert = "Opens in a new window";
		var strCCV = "What is CCV?";
		// Find all links
		var links = document.getElementsByTagName('a');
		var objWarningText;
		var link;
		for (var i = 0; i < links.length; i++) {
			link = links[i];
			// Find all links with a class name of "non-html"
			if (/\baccessible\-target\b/.test(link.className)) {
				link.title = strNewWindowAlert;
				link.onclick = openInNewWindow;
			}
			else if (/\bccv\-popup\b/.test(link.className)) {
				link.title = strCCV;
				link.onclick = openCCVPop;
			}
		}
		objWarningText = null;
	}
}

schedule("window", getNewWindowLinks);



