function add_bookmark()
{
	var title = document.title;
	var url = document.location;

	if(window.sidebar) // Firefox
	{
		window.sidebar.addPanel(title, url,'');
	}
	else if(window.opera)//Opera
	{
		var a = document.createElement("A");
		a.rel = "sidebar";
		a.target = "_search";
		a.title = title;
		a.href = url;
		a.click();
	}
	else if(document.all) //IE
	{
		window.external.AddFavorite(url, title);
	}
}

var popup_on_complete = null;
var hover_box;

function create_blocking_element()
{
	window.scroll(0, 0);

	var blocking_div = document.createElement('div');
	blocking_div.setAttribute('id', 'blockingdiv');
	blocking_div.style.backgroundColor = '#000000';
	blocking_div.style.opacity = 0.50;
	blocking_div.style.filter = 'alpha(opacity=50)';
	blocking_div.style.position = 'absolute';
	document.documentElement.style.overflow = 'hidden';
	blocking_div.style.width = '100%';
	blocking_div.style.height = '100%';

	blocking_div.style.top = '0px';
	blocking_div.style.left = '0px';

	blocking_div.style.zIndex = 1001;

	document.body.appendChild(blocking_div);
}


function popup_detail(on_complete_function)
{
	var width = '420px';
	var height = '120px';

	create_blocking_element();

	hover_box = document.createElement('div');
	hover_box.setAttribute('id', 'hover_box');
	hover_box.style.width = width;
	hover_box.style.height = height;
	hover_box.style.position = 'absolute';
	hover_box.style.top = '15px';
	hover_box.style.left = '35%';
	hover_box.style.border = '0 none';
	hover_box.style.backgroundColor = '#FFFFFF';

	hover_box.style.zIndex = 1002;

	var title_bar = document.createElement('table');

	var title_body = document.createElement('tbody');
	var title_row = document.createElement('tr');
	var title_cell = document.createElement('td');
	title_bar.setAttribute('id', 'hover_title');

	hover_box.appendChild(title_bar);
	title_bar.appendChild(title_body);
	title_body.appendChild(title_row);
	title_row.appendChild(title_cell);

	title_cell.setAttribute('align', 'right');
	title_cell.style.height = '20px';
	title_cell.style.width = '100%';
	title_cell.style.background = '#eaeaeb';
	title_cell.style.padding = '2px';
	title_cell.style.paddingRight = '4px';
	title_cell.innerHTML = '<a href="#" onclick="popup_detail_complete();" style="text-decoration: none; color: #666666; font-size: 11px;">Close</a> ';
	title_bar.style.width = '100%';
	title_bar.setAttribute('cellspacing', '0');
	title_bar.setAttribute('cellpadding', '0');
	title_bar.style.borderCollapse = 'collapse';

	var content_row = document.createElement('tr');
	title_body.appendChild(content_row);
	var content_td = document.createElement('td');
	content_td.style.padding = '10px';
	content_td.innerHTML = '<h2><img src="http://www.murdoch.edu.au/_image/Widgets/icon_envelope.gif/" style="vertical-align: middle; padding-right: 10px;"/>Join our mailing list</h2><p>Tell us who you are and we can make sure we keep you up to date with the most helpful information. Are you a <a href="http://www.murdoch.edu.au/Future-students/Ask-for-information/">domestic</a> or an <a href="http://www.murdoch.edu.au/International-students/Ask-for-information/">international</a> student?</p>';
	content_row.appendChild(content_td);

	document.body.appendChild(hover_box);

	popup_on_complete = on_complete_function;
}

function popup_detail_complete()
{
	var hover_box = document.getElementById('hover_box');
	hover_box.parentNode.removeChild(hover_box);

	var blocking_el = document.getElementById('blockingdiv');
	blocking_el.parentNode.removeChild(blocking_el);

	document.documentElement.style.overflow = 'auto';
}

function popup_tisc_helppack_form()
{
	create_blocking_element();

	var hover_box = document.createElement('div');
	hover_box.id = 'hover_box';
	hover_box.style.top = '10%';
	hover_box.style.left = '10%';
	hover_box.style.position = 'absolute';
	hover_box.style.border = '0 none';
	hover_box.style.backgroundColor = '#FFFFFF';

	hover_box.style.zIndex = 1002;

	hover_box.innerHTML = '<table cellspacing="0" cellpadding="0" id="hover_title" style="width: 700px; border-collapse: collapse;"><tbody><tr><td align="right" style="padding: 2px 4px 2px 2px; background: rgb(234, 234, 235) none repeat scroll 0% 0%; height: 20px; width: 100%;"><a style="text-decoration: none; color: rgb(102, 102, 102); font-size: 11px;" onclick="popup_detail_complete();" href="#">Close</a> </td></tr><tr><td id="hover_iframe_content_td" style="height: 100%; padding: 10px;"><iframe frameborder="0" src="/TISC-Hover/?course_url=' + escape(document.location.href) + '" style="width: 100%; height: 100%;" id="tiscHoverIframe"></iframe></td></tr></tbody></table>';

	document.body.appendChild(hover_box);
}

// Resizing related functions
if( typeof addLoadEvent != "undefined" )
{
	addLoadEvent(onload_fontSize);
}


function onload_fontSize()
{
	fontSize = getCookie('fontSize');

	if( fontSize != null )
	{
		changeFontsize(parseInt(fontSize), '');
	}
}


function getCookie( name )
{
	var cname		= name + "=";

	var dc		= document.cookie;

	if( dc.length > 0 )
	{
		begin = dc.indexOf(cname);

		if( begin != -1 )
		{
			begin += cname.length;

			end = dc.indexOf(";", begin);

			if( end == -1 )
			{
				end = dc.length;
			}

			return unescape(dc.substring(begin, end));
		}
	}

	return null;
}


function setCookie( name, value, expires, path, domain, secure )
{
	document.cookie = name + "=" + escape(value) +
	((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
	((path == null) ? "" : "; path=" + path) +
	((domain == null) ? "" : "; domain=" + domain) +
	((secure == null) ? "" : "; secure");
}	


function delCookie( name, path, domain )
{
	if( getCookie(name) )
	{
		document.cookie = name + "=" +
		((path == null) ? "" : "; path=" + path) +
		((domain == null) ? "" : "; domain=" + domain) +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}


var firstCall = true;

function resizeAnchors( parent, newFontSize )
{
	anchors = parent.getElementsByTagName('a');
	for( a=0; a < anchors.length; a++ )
	{
		anchor = anchors[a];
		anchor.style.fontSize = newFontSize + "px";
	}
}

function changeFooterFontSize( fSize )
{
	max_size = 16;
	if( fSize == "" )
	{
		return;
	}
	newFontSize = parseInt(fSize);
	if( newFontSize > max_size )
	{
		newFontSize = max_size;
	}

	footer_table = null;
	if( document.getElementsByTagName )
	{
		tables = document.getElementsByTagName('table');
		for( t=0; t < tables.length; t++ )
		{
			table = tables[t];
			if( table.className == 'footer_table')
			{
				footer_table = table;
				break;
			}
		}
		if( footer_table != null )
		{
			paragraphs = footer_table.getElementsByTagName('p');
			for( p=0; p < paragraphs.length; p++ )
			{
				paragraph = paragraphs[p];
				paragraph.style.fontSize = newFontSize + "px";
				resizeAnchors(paragraph, newFontSize);
			}
		}
	}
}

function find_nav_table( classname )
{
	top_nav = null;
	if( document.getElementsByTagName )
	{
		cells = document.getElementsByTagName('td');
		for( c=0; c < cells.length; c++ )
		{
			cell = cells[c];
			if( cell.className == classname )
			{
				top_nav = cell.getElementsByTagName('table')[0];
				break;
			}
		}
	}
	return top_nav;
}

function changeMenuFontSize( fSize )
{
	if( !document.getElementsByTagName )
	{
		return;
	}

	max_size = 16;
	if( fSize == "" )
	{
		return;
	}
	
	newFontSize = parseInt(fSize);
	if( newFontSize > max_size )
	{
		newFontSize = max_size;
	}

	// Change top nav font size
	top_nav_table = find_nav_table('nt_row');
	if( top_nav_table != null )
	{
		resizeAnchors(top_nav_table, newFontSize);
	}
	
	// Change the side nav.
	side_nav_table = find_nav_table('ns_row');
	if( side_nav_table != null )
	{
		resizeAnchors(side_nav_table, newFontSize);
	}
}

function changeFontsize( fSize, increment )
{
	var p_fontsize = null;
	
	// Is this the first call?
	if( firstCall )
	{
		firstCall = false;
		if( increment != "" )
		{
			changeFontsize('11', '');
		}
	}
	
	

	if( document.getElementsByTagName )
	{
		var tags = new Array ( "h1", "h2", "h3", "p", "li" );

		for( j=0; j < tags.length; j++ )
		{
			var cell 		= document.body;

			var getElement 	= cell.getElementsByTagName(tags[j]);

			var eachElement, currentFontSize, fontIncrease, newFontSize;

			for( i=0; i<getElement.length; i++ )
			{
				eachElement = getElement[i];
				
				// Skip Module Content
				if( eachElement.parentNode.className == "module_content" || eachElement.parentNode.parentNode.className == "module_content" )
				{
					continue
				}

				// Reset the new fontsize each time.
				newFontSize = null;

				if( false == isNaN(parseInt(increment)) )
				{
					currentFontSize		= parseInt(eachElement.style.fontSize);
					fontIncrease		= parseInt(increment);
					newFontSize			= currentFontSize + fontIncrease;
				}
				else if( parseInt(fSize) > 0  )
				{
					newFontSize = parseInt(fSize);
				}
				
				if( true == isNaN(newFontSize) )
				{
					continue;
				}

				if( tags[j] == "li" )
				{
					eachElement.style.lineHeight = Math.round(newFontSize * 1.2) + "px";
				}
				else
				{
					eachElement.style.lineHeight = Math.round(newFontSize * 1.5) + "px";
				}

				if( fSize != "" )
				{
					switch( tags[j] )
					{
						case "h1":
							newFontSize += 9;
							break;

						case "h2":
							newFontSize += 6;
							break;

						case "h3":
							newFontSize += 1;
							break;

						case "h4":
							newFontSize += 0;
							break;

						case "h5":
							newFontSize += 0;
							break;

						case "h6":
							newFontSize += 0;
							break;
					}
				}

				eachElement.style.fontSize = newFontSize + "px";
				
				// Only save the fontsize if the tag element is a p. All font sizes are based of this element.
				if( (eachElement.tagName.toLowerCase() == 'p') && (parseInt(newFontSize) > 0) )
				{
					p_fontsize = newFontSize;
					setCookie('fontSize', newFontSize);
				}
			}
		}
	}
	
	
	fontsize = null;
	if( parseInt(fSize) > 0 )
	{
		fontsize = fSize;
	}
	else if( p_fontsize != null )
	{
		fontsize = p_fontsize;
	}
	
	if( fontsize != null )
	{	
		changeMenuFontSize(fontsize);
		changeFooterFontSize(fontsize);
	}
}