//*** Copyright 1999 - 2007 Mark W. Pemburn.  All rights reserved
function browserDetect() {	
	var version = navigator.appVersion.charAt(0);
	var platform = navigator.platform;
	var agent = navigator.userAgent;
	var aParts;
	var nickname = "";
	
	this.isMac = false;
	this.isWin = false;
	this.isIE = false;
	this.isNetscape = false;
	this.version = version;
	this.minVersion = 0;
	this.name = navigator.appName;
	this.isSupported = false;
	this.OS = "";
	this.width = 0;
	this.height = 0;
	if (platform == "MacPPC") {
		this.isMac = true;
		this.nickname = "Mac";
	}
	if (platform == "Win32") {
		this.isWin = true;
		this.nickname = "Win";
	}
	switch (this.name) {
		case "Netscape" :
			this.isNetscape = true;
			this.handCursor = "pointer";
			this.minVersion = 5;
			this.nickname += "NS";
			this.width = window.innerWidth-16;
			this.height = window.innerHeight;
			if (eval(version) >= this.minVersion)
				this.isSupported = true;
			break;
		case "Microsoft Internet Explorer" : 
			this.isIE = true;
			this.handCursor = "hand";
			this.nickname += "IE";
				this.minVersion = 4;
			if (eval(version) >= this.minVersion)
				this.isSupported = true;
			this.width = document.body.offsetWidth-20;
			this.height = document.body.offsetHeight;
			break;
	}
	aParts = agent.substr(agent.indexOf("(")+1,agent.indexOf(")")-agent.indexOf("(")-1).split(";");
	for (var i=0; i<aParts.length; i++)
	{
		if (aParts[i] == " Windows NT 5.1")
			this.OS = "Windows XP";
	} 
} //*** browserDetect
function currencyFormatted(amount) {
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}

//*** expire hides the contents of a SPAN of class "expire" once the value in the "date" attribute has passed
function expire() {
	var spans = getElementsByClassName(document,"*","expire");
	var thisSpan;
	var expDate;
	var today = new Date();
	var testDate;
	var difference;
	var dayse;
	for (var i=0; i<spans.length; i++) {
		thisSpan = spans[i];
		if (thisSpan.className == "expire") {
			expDate = thisSpan.getAttribute("date");
			testDate = new Date(expDate);
			difference = testDate - today;
			days = Math.round(difference/(1000*60*60*24));
			if (days > 0) {
				thisSpan.style.visibility = "visible";
				thisSpan.style.display = "block";
			}
		}
	}
}


function setStyles(browserObj,tagString) {
	var tagArray;
	if (tagString != "")
		tagArray = tagString.split(",");
	else
		tagArray = new Array("DIV","SPAN","TABLE","TD","TR","SELECT","INPUT");
	if (browserObj.OS == "Windows XP")	{
		for (var i = 0; i < tagArray.length; i++) {
			setStyleByClass(tagArray[i],"BodyText","fontSize","9pt");
			setStyleByClass(tagArray[i],"BoldBodyText","fontSize","9pt");
			setStyleByClass(tagArray[i],"Title","fontSize","14pt");
			setStyleByClass(tagArray[i],"BigBold","fontSize","12pt");
			setStyleByClass(tagArray[i],"BoldEmphasis","fontSize","12pt");
		}
	}
}

function resizeThis(id, posLeft, posTop, widthOffset, heightOffset, brw) {
	var thisElement = document.getElementById(id);
	thisElement.style.position = "absolute";
	thisElement.style.left = posLeft;
	thisElement.style.top = posTop;
	if (widthOffset > 0)
		thisElement.style.width = brw.width - widthOffset;
	if (heightOffset > 0)
		thisElement.style.height = brw.height - heightOffset;
	thisElement.style.visibility = "visible";
}

function moveGIF(gifID, topPos, startPoint, endPoint) {
	var thisGIF = document.getElementById(gifID);
	var leftPos = startPoint;
	thisGIF.style.visibility = "visible";
	if (leftPos <= endPoint) {
		leftPos += 30;
		thisGIF.style.left = leftPos;
		thisGIF.style.top = topPos;
		setTimeout("moveGIF('" + gifID + "'," + topPos + "," + leftPos + "," + endPoint + ")",25);
	} else {
		return;
	}
}

function moveIMG(imgID, startTop, endTop, startLeft, endLeft, increment) {
	var thisIMG = document.getElementById(imgID);
	var topPos = startTop;
	var leftPos = startLeft;
	var moveMore = false;
	thisIMG.style.visibility = "visible";
	if (topPos <= endTop) {
		topPos += increment;
		moveMore = true;
	}
	if (leftPos <= endLeft) {
		leftPos += increment;
		moveMore = true;
	}
	if (moveMore) {
		thisIMG.style.top = topPos;
		thisIMG.style.left = leftPos;
		setTimeout("moveIMG('" + imgID + "'," + topPos + "," + endTop + "," + leftPos + "," + endLeft + "," + increment + ")",25);
	} else {
		return;
	}
}

//*** getElementsByClassName gets array of elements with a given tag name
function getElementsByClassName(oElm, strTagName, strClassName){	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);	var arrReturnElements = new Array();	strClassName = strClassName.replace(/-/g, "\-");	var oRegExp = new RegExp("(^|\s)" + strClassName + "(\s|$)");	var oElement;	for(var i=0; i<arrElements.length; i++){		oElement = arrElements[i];		if(oRegExp.test(oElement.className)){			arrReturnElements.push(oElement);		}	}	return (arrReturnElements)}

function getCtrlValue(CTRL) {
	if (CTRL == "")
		return;
	var thisCtrl = document.getElementById(CTRL);
	if (thisCtrl == null)
		thisCtrl = document.Query[CTRL];
	var CtlType = thisCtrl.type;
	var CtlVal = "";
	switch (CtlType)
	{		
		case "select-one" :
		case "select-multiple" :
			CtlVal = Trim(thisCtrl[thisCtrl.selectedIndex].value);
			break;
		default :
			CtlVal = Trim(thisCtrl.value);
			break;
	}
	return CtlVal;
}
function getInnerText(docObject) {
	return docObject.childNodes[0].nodeValue;
}
function setInnerText(docObject, text) {
	docObject.childNodes[0].nodeValue = text;
}
function Left(str, n) {
	if (n <= 0)
		return "";
	else if (n > String(str).length)
		return str;
	else
		return String(str).substring(0,n);
}
function Right(str, n) {
	if (n <= 0)
	   return "";
	else if (n > String(str).length)
	   return str;
	else {
	   var iLen = String(str).length;
	   return String(str).substring(iLen, iLen - n);
	}
}
function Trim(s) {
   	// Remove leading spaces and carriage returns
   	while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r')) { 
			s = s.substring(1,s.length); 
		}
	 
   	// Remove trailing spaces and carriage returns
 		while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r')) {
			s = s.substring(0,s.length-1); 
		}
	 
   	return s;
}
function getRealPos(obj,which) {
	objPos = 0;
	while (obj!=null) {
		objPos += obj["offset" + which];
		obj = obj.offsetParent;
	}
	return objPos;
}
function getX(obj) {
   return( obj.offsetParent==null ? obj.offsetLeft : obj.offsetLeft+getX(obj.offsetParent) );
}
function getY(obj) {
   return( obj.offsetParent==null ? obj.offsetTop : obj.offsetTop+getY(obj.offsetParent) );
}
function urlDecode(urlParam) {
	var outValue="";
	var pos;
	var foundName;
	var foundValue;
	var query=this.location.search.substring(1);
	if (query.length > 0){
		var params=query.split("&");
		for (var i=0 ; i<params.length ; i++){
			pos = params[i].indexOf("=");
			foundName = params[i].substring(0, pos);
			foundValue = params[i].substring(pos + 1);
			if (urlParam == foundName) {
				outValue = foundValue;
			}
		}
	}
	return outValue;
}
function preventBubbling(evt) {
	if (typeof evt.stopPropagation != 'undefined') {
   	evt.stopPropagation();
   }	else {
		event.cancelBubble = true;
	}
}
function getObject(id){
	if(document.layers)	return document.layers[id];  
	if(document.all)		return document.all[id];
}
//show/hide div with given ID
//vis may be true/false
function showDiv(id,vis) {
	var d;
	if(document.all) {
		d=document.all[id].style;
		d.visibility = vis ? "visible" : "hidden";
	}
	if(document.layers) {
		d=document.layers[id];
		d.visibility = vis ? "show" : "hide";
	}
}
// Moves Div with ID to x,y
function moveDiv(id,x,y){
	var d;
	if(document.layers) {
		d=document.layers[id];
		if(d){
			d.moveTo(x,y);
		}
	}
	if(document.all) {
		d=document.all[id];
		if(d){
			d.style.pixelLeft=x;
			d.style.pixelTop=y;
		}
	}
}
function isAlien(a) {
	return isObject(a) && typeof a.constructor != 'function';
}
function isArray(a) {
	return isObject(a) && a.constructor == Array;
}
function isBoolean(a) {
	return typeof a == 'boolean';
}
function isEmpty(o) {
	var i, v;
	if (isObject(o)) {
		for (i in o) {
			v = o[i];
			if (isUndefined(v) && isFunction(v)) {
				return false;
			}
		}
	}
	return true;
}
function isFunction(a) {
	return typeof a == 'function';
}
function isNull(a) {
	return typeof a == 'object' && !a;
}
function isNumber(a) {
	return typeof a == 'number' && isFinite(a);
}
function isObject(a) {
	return (a && typeof a == 'object') || isFunction(a);
}
function isString(a) {
	return typeof a == 'string';
}
function isUndefined(a) {
	return typeof a == 'undefined';
} 
function cancelEvent(e) {
	if (browser.isNetscape) {
   	e.stopPropagation();
   }	else {
		event.cancelBubble = true;
	}
}
function clearMsg(thisField) {
	thisField.value = "";
}

