// Copyright (c) 2004 TheyerGFX Pty Ltd 
// www.theyergfx.com

// open a new window
function open_win( url ) {
	window.open( url );
}

// open a new window
function open_barewin( url, width, height ) {
	window.open( url, '_blank', 'toolbar=no, directories=no, location=no, status=no, menubar=no, resizable=yes, scrollbars=no, width=' + width + ', height=' + height );
	window.status = 'loading...';
}

// go back to the home page
function go_home() {
	window.location.replace( 'http://www.cellfield.com/main.htm' );
}

// draw the menus
function draw_main() {

	// menu
	draw_menu();
	draw_background( "page" );
	draw_end_of_page_menu();
}

// show a printable page
function printable_page() {
	var url, name, regexp;
	url = window.location.href;
	regexp = /.htm/i;
	name = url.replace(regexp,"_p.htm");
	window.open(name);
}

// open today tonight story
function today_tonight() {
	window.open('http://www.todaytonight.com.au/stories/556443.html');
}

// draw the menu
function draw_menu() {

	var		html;
	var		height;
	var		menu;

	// init
	height = 35;
	
	// menu code
	html = menu_start() + 
		   menu_item(  "home",		"main",			height ) +
		   menu_item(  "news",		"news",			height ) +
		   menu_item(  "faq",		"faq",			height ) +
		   menu_item(  "brochure",	"brochure",		height ) +
		   menu_item(  "science",	"science",		height ) +
		   menu_item(  "articles",	"articles",		height ) +
		   menu_item(  "about",		"about",		height ) +
		   menu_item(  "interstate","internat",		height ) +
		   menu_item(  "internat",	"internat",		height ) +
		   menu_item(  "testimonials","testimonials",height ) +
		   menu_item(  "rego",		"registration",	height ) +
		   // menu_item(  "tuition",	"tuition",		height ) +
		   menu_item(  "contact",	"contact",		height ) +
		   // menu_item(  "feedback",	"feedback",		height ) +
		   menu_item(  "links",		"links",		height ) +
		   menu_item(  "license",	"license",		height ) +
		   menu_end();

	// insert html
	menu = document.all.item("menu");
	if ( menu != null ) {
		// set background
		menu.background = "bar.gif";
		menu.style.backgroundRepeat = "no-repeat"; 
		menu.insertAdjacentHTML( "BeforeEnd", html );
	}
}

// start of a menu
function menu_start() {

	var opt;

	opt = "<TABLE cellPadding=0 cellSpacing=0 border=0>" +
	"<TR><TD height=40></TD></TR>" +
	"<TR><TD align=center><A HREF=\"javascript:go_home();\"><IMG border=0 src=\"logo_s.gif\"></TD></TR>" +
	"<TR><TD height=40></TD></TR>";

	return( opt );
}

// draw a menu item
function menu_item( name, ref, height ) {
	
	var opt;

	opt = "<TR height=" + height + "><TD vAlign=center align=center>" + 
	"<A HREF=\"" + ref + ".htm\">" +
	"<IMG style=\"display: none\" src=\"" + name + "_h.gif\">" + 
	"<IMG src=\"" +	name + ".gif\" border=0 onmousedown=\"highlight()\" onmouseout=\"normal()\" onmouseup=\"normal()\"></A></TD></TR>";

	return( opt );
}

// end of a menu
function menu_end() {

	var opt = "</TABLE>";

	return( opt );
}

// menu highlighted state 
function highlight() {
	if ( window.event.srcElement.tagName == "IMG" ) {
		var url, name, regexp;
		window.event.srcElement.hspace = 0;
		window.event.srcElement.vspace = 0;
		url = window.event.srcElement.src;
		regexp = /.gif/i;
		name = url.replace(regexp,"_h.gif");
		window.event.srcElement.src = name;
	}
}

// menu normal state 
function normal() {
	if ( window.event.srcElement.tagName == "IMG" ) {
		var url, name, regexp;
		window.event.srcElement.hspace = 0;
		window.event.srcElement.vspace = 0;
		url = window.event.srcElement.src;
		regexp = /_h.gif/i;
		name = url.replace(regexp,".gif");
		window.event.srcElement.src = name;
	}
}

// end of page menu
function draw_end_of_page_menu() {

	var		html;

	html = "<CENTER><PRE><FONT face=\"Arial\" size=3 color=\"#FFFFFF\"><P><A HREF=\"#\">Top of Page<A>           <A HREF=\"javascript:printable_page()\">Printer Friendly Page<A></P><BR>" +
	"<A HREF=\"main.htm\">Home<A>  <A HREF=\"news.htm\">News<A>  <A HREF=\"faq.htm\">FAQ<A>  <A HREF=\"brochure.htm\">Brochure<A>  <A HREF=\"science.htm\">The Science<A>  <A HREF=\"articles.htm\">Articles<A>  <A HREF=\"about.htm\">About us<A>  <A HREF=\"internat.htm\">Interstate<A><BR>" +
	"<A HREF=\"internat.htm\">International<A>  <A HREF=\"testimonials.htm\">Testimonials<A>  <A HREF=\"registration.htm\">Registration<A>  <A HREF=\"contact.htm\">Contact us<A>  <A HREF=\"links.htm\">Links<A>  <A HREF=\"license.htm\">Licensees<A>  </FONT></PRE>" +
	"</CENTER>"

	// insert html
	holder = document.all.item("foot");
	if ( holder != null ) {
		holder.insertAdjacentHTML( "BeforeEnd", html );
	}
}

// draw background
function draw_background( item ) {

	var		before;
	var		after;
	var		head_height;
	var		body_height;
	var		foot_height;
	var		page;
	var		end;

	// init
	page = document.all.item( item );
	if ( page == null ) return;

	// before
	before = "<TABLE width=100% cellPadding=0 cellSpacing=0>" +
	"<TR>" +
	"<TD><IMG src=graphics/top_left.gif border=0></TD>" + 
	"<TD width=100% background=graphics/top.gif></TD>" + 
	"<TD><IMG src=graphics/top_right.gif border=0></TD>" + 
	"</TR>" +
	"<TR>" +
	"<TD background=graphics/left.gif border=0></TD>" + 
	"<TD width=100%>" + page.outerHTML + 
	"</TD>" +
	"<TD background=graphics/right.gif border=0></TD>" + 
	"</TR>" +
	"<TD><IMG src=graphics/bottom_left.gif border=0></TD>" + 
	"<TD width=100% background=graphics/bottom.gif border=0></TD>" + 
	"<TD><IMG src=graphics/bottom_right.gif border=0></TD>" + 
	"</TR>" +
	"</TABLE>";

	// insert
	page.outerHTML = before;
	//page.insertAdjacentHTML( "AfterEnd", after );
	//page.insertAdjacentHTML( "BeforeBegin", before );
}

