/*	Main page helper functions
*/
var loggedOn = false;
var loggedOnInt = 0;
var interval = 200;              		// Milliseconds between updates
var refreshOnWaitForClose = false;	// true if we want to refresh window on closing
var cancelMenuItem = 0;							// menu item to cancel on closing

	function Allowit() {
	  if (UserRef > 0)
	    return true
	  else {
        var msg = "";
    	msg  = "______________________________________________________\n\n"
    	msg += "Please login, or register if you have not yet done so.\n";
    	msg += "I like to keep track of who is using my utilities!.\n";
    	msg += "______________________________________________________\n\n";
		alert(msg);
		return false;
	  }
	}
	/* Function returns name of links file
	*/
	function LinksName() {
	  return "Favourites.js"
	}
	
	var scriptName;
	
	function initHome() {
		scriptName = document.location;
		setAtt ("menuItem_1", "href", scriptName);
	  if (UserRef > 0) {
			loggedOn = true;
			loggedOnInt = 1;
		}
		else {
			loggedOn = false;
			loggedOnInt = 0;
		};
		highlightMenuButton (1);
	}

/* stretches left content on resize to fill blank area */
function resizeStuff() {
	// var h = getEl("Debug05").innerHTML = getEl("centrecontent").offsetHeight;
	var h = getEl("centrecontent").offsetHeight;
	getEl("leftcontent").style.height = String(h-10) + "px";
	getEl("ldng").style.display = "none";
}

var baseWid1, baseWid2;
/* Set any required style values on loading - e.g. width of links style */
function setStyles() {
		baseWid1 = 12;
		baseWid2 = rightcontent.offsetWidth - (4 + 12 + 14+04) ;
		return;
	var s = getStyleSheetRule ("styleLinks", ".menItem")
	if (s) // subtract padding and width of left and right from container width
		// s.width = String(rightcontent.offsetWidth - (4 + 12 + 14)) + "px"
		baseWid1 = 12;
		baseWid2 = rightcontent.offsetWidth - (4 + 12 + 14+04) ;
}

function doLogin () {
	win=window.open('LinkMan/Login06.htm','Login','height=200,width=500,menubar=no,status=no');
	refreshOnWaitForClose = true;
	intervalID=window.setInterval('WaitForClose()', interval);
} // doLogin

function doLogout () {
	userdata.remove(); 
	location='Index.htm';
} // doLogout

function doRegister () {
	win=window.open('LinkMan/Register06.htm','Register','height=520,width=550,menubar=no,status=no');
	refreshOnWaitForClose = true;
	intervalID=window.setInterval('WaitForClose()', interval);
} // doRegister

function doEmail () {
	highlightMenuButton (6);		// highlihgt e-mail for the duration
	win=window.open('Email.htm','Email','height=470,width=690,menubar=no,status=no');
	refreshOnWaitForClose = false;
	cancelMenuItem = 6;
	intervalID=window.setInterval('WaitForClose()', interval);
}

	/* -- the following does not work - class is not a suitable attribute */
	function setSectionTits(n) {
	  var children = n.childNodes;
	  for (var i = 0; i < children.length; i++)
	  	with (children[i])
	  		if (id=="mainSectTit")
					innerHTML = "&nbsp;&nbsp;" + innerHTML + "&nbsp;&nbsp;"; 
	}
	/* */
function sendValE() {
	win=window.open('EmailVal.htm','Email','height=470,width=690,menubar=no,status=no');
	refreshOnWaitForClose = false;
	intervalID=window.setInterval('WaitForClose()', interval);
} // sendValE

function WaitForClose() {
	// Reload Index.htm if window closed
	if (win.closed) {
		clearInterval(intervalID);
		if (refreshOnWaitForClose)
			location='Index.htm';		// ** should replace by actual script name
		refreshOnWaitForClose = false;
		highlightMenuButton (6, true);
		cancelMenuItem = 0;
		return;
	}
} // WaitForClose

	function cancelMenu() {
		document.getElementById("linkmen").style.display = "none"
	}
	
	function highlightMenuButton (n, cancel) {
		var el = "menuImg_" + n;
		el = getEl (el);
		if (el) {
			if (cancel)
				el.style.border = "0";
			else
				el.style.border = "3px solid #669900";
		}
		// draw box round relevant menu button
	} // highlightMenuButton
