// Basic js functions used throughout site for picture framing and page scrolling
TRACE = false;	// set false for production, turns on trace displays
//TRACE = true;	// set false for production, turns on trace displays
function scrollwindowup() {
	scrollBy (0,-25);
}
function scrollwindowdown() {
	scrollBy (0,1);
}
function returntotopofpage()	{	// not needed - left for legacy
	clearInterval(scrollup);
	scrollTo(0,0);
}
function picframe(image, caption) {
	if (caption) document.write('<table border=0 cellpadding=0 cellspacing=0><tr><td align="center">');
	document.write('<table border="3" bordercolor="#999900" bordercolordark="#996600" bordercolorlight="#CCCC00" bgcolor="#ff9900"><tr><td><table border="3" bordercolor="#FFFF00" bordercolordark="#FFCC00" bordercolorlight="#FFFF00"><tr><td>' + image + '</td></tr></table></td></tr></table>' );
	if (caption) document.write('<br><span class="caption">' + caption + '</span"</td></tr></table>' );
}
function picframePRE() {
	document.write('<table border="3" bordercolor="#999900" bordercolordark="#996600" bordercolorlight="#CCCC00" bgcolor="#ff9900"><tr><td><table border="3" bordercolor="#FFFF00" bordercolordark="#FFCC00" bordercolorlight="#FFFF00"><tr><td>');
}
function picframePOST() { 
	document.write('</td></tr></table></td></tr></table>' );
}
function picframegilt(image, alignment) {
	document.write('<table cellpadding="0" cellspacing="0" border="0" align="' + alignment + '">' );
	document.write('<tr><td width="29" height="29" background="http://middlepath.com.au/img/fr_tlcnr.gif"><img src="http://middlepath.com.au/img/spacer.gif" width="29" height="29"></td>	<td height="29" background="http://middlepath.com.au/img/fr_top.gif"></td>	<td width="29" height="29" background="http://middlepath.com.au/img/fr_trcnr.gif"><img src="http://middlepath.com.au/img/spacer.gif" width="29" height="29"></td></tr>' );
	document.write('<tr><td width="29" background="http://middlepath.com.au/img/fr_lft.gif"></td><td>' );
	document.write(image );
	document.write('</td><td width="29"  background="http://middlepath.com.au/img/fr_rgt.gif"></td></tr>' );
	document.write('<tr><td width="29" height="29"  background="http://middlepath.com.au/img/fr_blcnr.gif"><img src="http://middlepath.com.au/img/spacer.gif" width="29" height="29"></td><td height="29" background="http://middlepath.com.au/img/fr_btm.gif"></td><td width="29" height="29" background="http://middlepath.com.au/img/fr_brcnr.gif"><img src="http://middlepath.com.au/img/spacer.gif" width="29" height="29"></td></tr>' );
	document.write('</table>' );
}

function email_link(text,subject,body)	{// insert email link
	document.write ( '<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#109;&#112;&#64;&#109;&#105;&#100;&#100;&#108;&#101;&#112;&#97;&#116;&#104;&#46;&#99;&#111;&#109;&#46;&#97;&#117;' );
	document.write ( '?subject=' + subject + '&body=' + body + '">' + text + '</a>' ); 
}
//  insert workshop details in table once button clicked on workshop pages
function filldetails_old()	{
	document.all.datecell.innerHTML	= dates_vb[0] + "<br>" + dates_vb[1] + "<br>" + dates_vb[2];
	document.all.requirements.innerHTML	= requirements['vb'];	
	document.all.costcell.innerHTML	= "AUD$" + workshop_costs['vb'] + ":00";
}
// routines to return window size
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}

function getDocHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}


function  set_Scroll_Cell_Heights () {	//  MUST BE CALLED after page load to return valid values
//  sets scrolling heights of sidebars using transparent gif to force cell heights to height of document content
//  measures content height using element height of cell 	<td id="content_cell" valign="top"> at bottom of file pagetop.php 
//	weakness may be the erratic result returned by function getElementHeight for different browsers..........
	content_height = getElementHeight('content_cell')
	// set scrolling heights for side bars
	content_height =  getDocHeight() - 500;
	scrolling_height =  content_height;
	// now set scrolling cell fill height for left hand scroll column
	scrolling_height = content_height  - PromoBoxHeight ;	//  remove height consumed by promo boxes
	document.getElementById('left_scroll_cell').innerHTML = '<img src="http://middlepath.com.au/img/spacer.gif" width="150" height="' + scrolling_height + '" border="0">';

	// now set scrolling cell fill height for right hand scroll column
	scrolling_height =  content_height;
// share buttons have been replaced	if (ShareButtonsShowing) scrolling_height =  content_height - 300;
	document.getElementById('right_scroll_cell').innerHTML = '<img src="http://middlepath.com.au/img/spacer.gif" width="50" height="' + scrolling_height + '" border="0">';
	return;
}

function getElementHeight(Elem) {
	if(document.getElementById) {
		var elem = document.getElementById(Elem);
	} else if (document.all){
		var elem = document.all[Elem];
	}
	xPos = elem.offsetHeight;
	return xPos; 
}

/*
This section to pop up image via <div> with cursor at top left on mouseover of image (or whatever ) call is ShowContent ('div name');
Copyright 2006,2007 Bontrager Connection, LLC
 http://bontragerconnection.com/ and http://willmaster.com/
Version: July 28, 2007
*/
var cX = 0; var cY = 0; var rX = 0; var rY = 0;
function UpdateCursorPosition(e){ cX = e.pageX; cY = e.pageY;}
function UpdateCursorPositionDocAll(e){ cX = event.clientX; cY = event.clientY;}
if(document.all) { document.onmousemove = UpdateCursorPositionDocAll; }
else { document.onmousemove = UpdateCursorPosition; }
function AssignPosition(d) {
	if(self.pageYOffset) {
		rX = self.pageXOffset;
		rY = self.pageYOffset;
		}
	else if(document.documentElement && document.documentElement.scrollTop) {
		rX = document.documentElement.scrollLeft;
		rY = document.documentElement.scrollTop;
		}
	else if(document.body) {
		rX = document.body.scrollLeft;
		rY = document.body.scrollTop;
		}
	if(document.all) {
		cX += rX; 
		cY += rY;
		}
	d.style.left = (cX+10) + "px";
	d.style.top = (cY+10) + "px";
}
function HideContent(d) {
	if(d.length < 1) { return; }
	document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
	if(d.length < 1) { return; }
	var dd = document.getElementById(d);
	AssignPosition(dd);
	dd.style.display = "block";
}
function ReverseContentDisplay(d) {
	if(d.length < 1) { return; }
	var dd = document.getElementById(d);
	AssignPosition(dd);
	if(dd.style.display == "none") { dd.style.display = "block"; }
	else { dd.style.display = "none"; }
}


function convert (amount)    { //  pops up a fieba currency conversion window for AUD$amount wasin anu pages
	PopupWindow = window.open ('', 'fieba', 'toolbar=0,location=0,resizable=1,height=220,width=350')
	PopupWindow.focus()
	PopupWindow.location.href = "http://64.225.125.88:8080/fieba/preset.jsp?FI_from=USD" + "&FI_to=AUD&FI_inputAmount=" + amount
	return true;
}


