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;
	}
}

/*
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";
		// 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 (/\bexternal\-link\b/.test(link.className)) {
				link.title = strNewWindowAlert;
				link.onclick = openInNewWindow;
			}
		}
		objWarningText = null;
	}
}

function printPage() { 
	if (window.print) { 
		window.print() ; 
	} else { 
		var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>'; 
		document.body.insertAdjacentHTML('beforeEnd', WebBrowser); 
		WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box WebBrowser1.outerHTML = ""; 
	} 
}

function enableJSClass()
{
	document.body.className = "jsEnabled";
}

function GoToBankingUrl(href)
{
	var name = "hbsbanking";
	var newWindowHeight = screen.availHeight - 80;
    var newWindowWidth = screen.availWidth - 18;
	var features = "left=0,top=0,toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width="+newWindowWidth+",height="+newWindowHeight;
	window.open(href, name, features);
}

function DimSubmitButton(elemId, validationGroup)
{
    //TODO: set a proper class for the element
    //document.getElementById(elemId).className = "test";
	
	if(Page_ClientValidate(validationGroup))
	{
		var t = setTimeout("DimSubmitButtonDisable('" + elemId + "')",500)
	}
	
    return true;
}

function DimSubmitButtonDisable(elemId)
{
    document.getElementById(elemId).disabled = true;

    return true;
}

schedule("window", getNewWindowLinks);
