// BROWSER DETECTION

var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;

if (checkIt('konqueror'))
{
	browser = "Konqueror";
	OS = "Linux";
}
else if (checkIt('safari')) browser = "Safari"
else if (checkIt('omniweb')) browser = "OmniWeb"
else if (checkIt('opera')) browser = "Opera"
else if (checkIt('webtv')) browser = "WebTV";
else if (checkIt('icab')) browser = "iCab"
else if (checkIt('msie')) browser = "Internet Explorer"
else if (checkIt('firefox')) browser = "Firefox"
else if (!checkIt('compatible'))
{
	browser = "Netscape Navigator"
	version = detect.charAt(8);
}
else browser = "An unknown browser";

if (!version) version = detect.charAt(place + thestring.length);

if (!OS)
{
	if (checkIt('linux')) OS = "Linux";
	else if (checkIt('x11')) OS = "Unix";
	else if (checkIt('mac')) OS = "Mac"
	else if (checkIt('win')) OS = "Windows"
	else OS = "an unknown operating system";
}

function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

/////////////////////////////////////////////////////////

function setStatusBar(msgStr) { self.status = msgStr; }

var popUpWin=0;
function popUpWindow(URLStr, width, height) {
  if(popUpWin) {
    if(!popUpWin.closed) popUpWin.close();
  }
  
  var vx = getViewportX();
  var vy = getViewportY();
  var vw = getViewportWidth();
  var vh = getViewportHeight();
  
  if( !((OS=="Windows") && (browser=="Internet Explorer")) )
	vy += 60;
  
  //alert('vx:'+vx+'|vy:'+vy+'|vw:'+vw+'|vh:'+vh);
  
  if( (vx==null) || (vy==null) || (vw==null) || (vh==null) ) {
	vx = 0;
	vy = 0;
	vw = self.screen.width;
	vh = self.screen.height;
  }
  
  var left = Math.floor(vx + ((vw - width) / 2));
  var top = Math.floor(vy + ((vh - height) / 2));
  //alert('left:'+left+'|top:'+top);
  
  popUpWin = open(URLStr, 'popUpWin', 
	'toolbar=no,location=no,directories=no,status=no,statusbar=no,menubar=no,scrollbar=no,scroll=no,resizable=no,copyhistory=no,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
  //popUpWin.screenLeft = left;
  //popUpWin.screenTop = top;
}

function getViewportX() {
	if(self.screenLeft!=window.undefined) return self.screenLeft;
	if(self.screenX!=window.undefined) return self.screenX;
	return null;	
}
function getViewportY() {
	if(self.screenTop!=window.undefined) return self.screenTop;
	if(self.screenY!=window.undefined) return self.screenY;
	return null;
}
function getViewportHeight() {
	if (self.innerHeight!=window.undefined) return self.innerHeight;
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
	if (document.body) return document.body.clientHeight; 
	return null; 
}
function getViewportWidth() {
	if (self.innerWidth!=window.undefined) return self.innerWidth; 
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
	if (document.body) return document.body.clientWidth; 
	return null; 
}

/**
 * COMMON DHTML FUNCTIONS
 * These are handy functions I use all the time.
 *
 * By Seth Banks (webmaster at subimage dot com)
 * http://www.subimage.com/
 *
 * Up to date code can be found at http://www.subimage.com/dhtml/
 *
 * This code is free for you to use anywhere, just keep this comment block.
 */

/**
 * X-browser event handler attachment and detachment
 *
 * @argument obj - the object to attach event to
 * @argument evType - name of the event - DONT ADD "on", pass only "mouseover", etc
 * @argument fn - function to call
 */
function addEvent(obj, evType, fn){
 if (obj.addEventListener){
    obj.addEventListener(evType, fn, true);
    return true;
 } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
 } else {
    return false;
 }
}
function removeEvent(obj, evType, fn, useCapture){
  if (obj.removeEventListener){
    obj.removeEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.detachEvent){
    var r = obj.detachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be removed");
  }
}

////////////////////////////////////////////////////////////

function tieTo(elementId) {
	var elem = document.getElementById(elementId);
	if( (event.which && event.which == 13) || (event.keyCode && event.keyCode == 13) ) {
		elem.click();
		return false;
	} else {
		return true;
	}
}

function toUpper(elem) {
	elem.value = elem.value.toUpperCase();
}

function setFormAction(formId,url) {
	var theForm = document.getElementById(formId);
	if( theForm ) {
		theForm.action = url;
	}
}