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);
}


/* 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 (/\baccessible\-target\b/.test(link.className)) {
				link.title = strNewWindowAlert;
				link.onclick = openInNewWindow;
			}
		}
		objWarningText = null;
	}
}


function drawHeadline(date, time, symbol, headline, id) 
{
	var tablerow = document.createElement('tr');
	
	//create date cell
	var cellDate = document.createElement('td');
	cellDateText = document.createTextNode(date);
	cellDate.appendChild(cellDateText);
	
	//create time cell
	var cellTime = document.createElement('td');
	cellTimeText = document.createTextNode(time);
	cellTime.appendChild(cellTimeText);
	
	//create symbol cell
	var cellSymbol = document.createElement('td');
	cellSymbolText = document.createTextNode(symbol);
	cellSymbol.appendChild(cellSymbolText);
	
	//create headline cell
	var cellHeadline = document.createElement('td');
	var cellHeadlineLink = document.createElement('a');
	cellHeadlineLink.setAttribute('href', 'http://clients.weblink.com.au/clients/Devine/article.asp?id=' + id);
	cellHeadlineLink.setAttribute('class', 'accessible-target');	
	cellHeadlineLinkText = document.createTextNode(headline);
	cellHeadlineLink.appendChild(cellHeadlineLinkText);
	cellHeadline.appendChild(cellHeadlineLink);
	
	//Append created cells
	tablerow.appendChild(cellDate);
	tablerow.appendChild(cellTime);
	tablerow.appendChild(cellSymbol);
	tablerow.appendChild(cellHeadline);
	
	document.getElementById('investorInformation').getElementsByTagName('tbody')[0].appendChild(tablerow);
}


function getLocationToRoot()
{
	var currentUrl = location.href;
	var urlSplit = currentUrl.split("/");
	var path = "";
	var firstIndex = 0;
	var lastIndex = urlSplit.length - 1;
	var isLocal = false;
	
	if(urlSplit[3]=='devine_com_au_Dev') isLocal = true;
	if(urlSplit[2]=='www.devine.com.au' && urlSplit[3]=='concept') isLocal = true;
	
	if(location.protocol=='http:') {
		for(i=0; i<urlSplit.length; i++) 
		{
			if(urlSplit[i]!=location.protocol && urlSplit[i]!='') 
			{
				if(urlSplit[i]==location.host) firstIndex = (i+1);
			}
		}
	}
	
	var levels = lastIndex - firstIndex;
	if(isLocal) levels--;
	for(i=0; i<levels; i++) 
	{
		path = path + '../';
	}
	return path;
};

schedule("window", dropListNavigation);
function dropListNavigation()
{
	if(document.getElementById('selectAcommunity')) 
	{
		//var element = document.getElementById('selectAcommunity');
		var button = document.getElementById('selectAcommunity').getElementsByTagName('input')[0];
		
		attachEventListener(button, 'click', communitiesButtonClicked, false);
	}
};
function communitiesButtonClicked()
{
	var element = document.getElementById('selectAcommunity').getElementsByTagName('select')[0];	
	if(element[element.selectedIndex].value != "select") window.location = element[element.selectedIndex].value;
};


function initNinja()
{
	var stripeyParents = getElementsByClassName(document, "*", "stripey");
	
	for (i=0;i<stripeyParents.length;i++)
	{
		var tagName = stripeyParents[i].childNodes[0].nodeName;
		if(tagName == "#text") tagName = stripeyParents[i].childNodes[1].nodeName;		
		var childElements = stripeyParents[i].getElementsByTagName(tagName);
		
		for (var j = 1; j < childElements.length; j += 2)
		{
			if (childElements[j].className == "")
			{
				childElements[j].className = "alt";
			}
			else
			{
				childElements[j].className += " alt";
			}
		}
	}
	
	return true;
};

schedule("window", initNinja);
schedule("window", getNewWindowLinks);

//if(window.location.match("index.cfm?method=search.details&project=832328&state=vic")) window.location = "http://www.devine.com.au/emailouts/victoria/bro070921-mp/plan832342.pdf";