// scripts copyright by iWave P/L and Phil Barnard
// version: ntarc  180210

//-------------------------/ globals

var W3C = document.getElementById;
var isMac = /mac/i.test(navigator.platform);


//-------------------------/ NTARC specific

var str = "";

function calcTime() {
	var offset = 11;
	var d = new Date(); // create Date object for current location
	// convert to msec, add local time zone offset, get UTC time in msec
	var utc = d.getTime() + (d.getTimezoneOffset() * 60000);
	// create new Date object for Launceston using supplied offset
	var nd = new Date(utc + (3600000*offset));
	str = nd.toLocaleString();
	document.getElementById("daytime").innerHTML = str;
}


//------------------------/ key utilities

// extract pagename with extension from URL
// eg:  xtractFile(location.href) => "index.html"
function xtractFile(data){
            var m = data.match(/(.*)[\/\\]([^\/\\]+\.\w+)$/);
            // return m[1];  // pathname
            return m[2];  // filename with extension
}

// return key value in named cookie, or ""
function getCookKey(nm,ke){
	var re = new RegExp ("^"+nm+"=([^;]*).*|.+;\\s?"+nm+"=([^;]*).*|.*","i");
	var c = document.cookie.replace(re,"$1$2");  // extract the cookie
	if(!c) return "";
	re = new RegExp ("^"+ke+"=([^&]*).*|.+&\\s?"+ke+"=([^&]*).*|.*","i");
	return unescape(c.replace(re,"$1$2"));  // extract the key value
}

// get key value from search args 
function getSearchKey(ke){
	ke = ke.toLowerCase();
	start = location.search.toLowerCase().indexOf(ke+"=");
	if(start == -1) return "";
	end = location.search.toLowerCase().indexOf("&", start);
	if(end == -1) end = location.search.length;
	return unescape(location.search.substring(start+ke.length+1, end))
}

//------------------------/ string utilities

function badEmail(str){
	if(!str || /[\s#&^+]/.test(str)) return true;  // empty str or bad chars
	var parts = str.split("@");  // check for x@x structure
	if(parts.length != 2 || parts[0].length == 0 || parts[1].length == 0) return true;
	var dom = parts[1].split("."); // check domain for minimum of x.x structure
	if(dom.length < 2) return true;
	for(i in dom) if(dom[i].length < 1) return true;
	return false;  // false means the address is valid
}

//----------------------------/  other utilities


var popWinObj;
function popWin(url,w,h){
	// if(popWinObj && !popWinObj.closed) popWinObj.close();
	if(!w) w=800; if(!h) h=600;
	popWinObj = window.open(url,"","left=5,top=25,width="+ w +",height="+ h);
	//popWinObj = window.open(url,"","left=5,top=25,width="+ w +",height="+ h +",scrollbars=0,resizable=yes");
}

var popScrollWinObj;
function popScrollWin(url,w,h){
	if(popScrollWinObj && !popScrollWinObj.closed) popScrollWinObj.close();
	if(!w) w=800; if(!h) h=600;
	var features = "left=5,top=20,width="+w+",height="+h+",scrollbars=1,resizable=1";
	popScrollWinObj = window.open(url,"   ",features);
}



