// scripts copyright by iWave P/L and Phil Barnard
// version: iwave  280104


//-------------------------/ testing
var objList;
var nodeList;
var theParent;
function dump(obj) {
	objList = new Array(); nodeList = new Array();
	var result = "<div style='font-family:helvetica,arial; font-size:8pt'>", str="", cnt=0;
   	if(obj.parentNode){
		theParent = obj.parentNode;
		result += "<a style='color:blue; text-decoration:none' href=\"javascript:window.opener.dump(window.opener.theParent)\">Dump parent node: </a>&lt;" + theParent.nodeName + "&gt;<br><br>";
	}
	for (var i in obj) {
   		str = "<span style='color:darkgreen'>" + obj[i] + "</span>";  // by default we see the name of the child object
   		type = typeof obj[i];  // "object"
   		if(type == "object" && obj[i]){  // we have an object that is not null
   			objList[cnt] = obj[i];
   			str = "<a style='color:red; text-decoration:none' href=\"javascript:window.opener.dump(window.opener.objList[" + cnt + "])\">" + obj[i] + "</a>";
   			if(obj[i].parentNode){ // this object is a node
   				nodeList[cnt] = obj[i].parentNode;
   				str += " &nbsp; parent node: &lt;<a style='color:blue; text-decoration:none' href=\"javascript:window.opener.dump(window.opener.nodeList[" + cnt + "])\">" + obj[i].parentNode.nodeName + "</a>&gt;";
   			}
   			++cnt;
   		}
   		result += "." + i + " = " + str + "<br>";
   }
	var dumpWin = window.open('','Dump','width=550,height=400,scrollbars=1,status=1,resizable=1')
	dumpWin.document.write(result + "</div>");
	dumpWin.document.close();
}

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

var W3C = document.getElementById;
var IE = /Explorer/.test(navigator.appName);
var NN = /Netscape/.test(navigator.appName);
var isMac = /mac/i.test(navigator.platform);
var logging = false;

//-------------------------/ layer utilities

function move(id,t,l){
	document.getElementById(id).style.top = t; document.getElementById(id).style.left = l;
}

function show(id){
	document.getElementById(id).style.visibility="visible";
}

function hide(id){
	document.getElementById(id).style.visibility="hidden";
}

function dw(id,s){
	document.getElementById(id).innerHTML = s;
}

//------------------------/ cookie utilities

// 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
}

function toCurrency(n){
	n = (Math.round(n * 100) / 100).toString();
	n += /\./.test(n) ? "00" : ".00";
	return n.replace(/(\d*\.\d\d).*/,"$1");  // truncate to 2 chars after .
}

// for client-side string cleaning
var cleanJS = new RegExp("[\\\\<>\'\"]","g");
var cleanPath = new RegExp("[<>/\'\\\\:*?|\"]","g");
var cleanSQL = new RegExp("[%_*?]","g");
var cleanPass = new RegExp("[\'\\s]","g");
var cleanTXT = new RegExp("[\\\\<>\'\"\r\n\t]","g");

function check(str,re){
	return re.test(str); // return true if nasties found, else false
}

function clean(str,re){
	return str.replace(re,""); // replace nasties with empty string
}

function escapeQuotes(str){
	return str.replace(/([\'\"])/g,"\\$1");
}

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

function preload(){  // preload images;  preload("img/one.gif","two.gif","three.gif")
	var imgs = new Array();
	for (var i=0; i < preload.arguments; i++) {
		imgs[i] = new Image(); imgs[i].src = preload.arguments[i];
	}
}

// stores an image's top left co-ords in global vars T, L
var T,L;
function imgTL(imgName){
	var imgObj = document.images[imgName];
	if (document.all) {
		L = imgObj.offsetLeft; T = imgObj.offsetTop;
		leftEdge = imgObj.offsetParent; rightEdge = imgObj.offsetParent;
  		while (leftEdge) {
			L += leftEdge.offsetLeft; leftEdge = leftEdge.offsetParent;
		}
		while (rightEdge) {
			T += rightEdge.offsetTop; rightEdge = rightEdge.offsetParent;
		}
		if (/Mac/i.test(navigator.userAgent)) {
			T += 15; L += 10;
		} 
	}
	if (!document.all) T=imgObj.y; L=imgObj.x;
}

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);
}

//-------------------/ statistics


