String.prototype.trim = function() { return this.replace(/\s+$|^\s+/g, ""); }

function lib_browser() {
	this.checkIt = function(arr) {
		for (var i=0;i<arr.length;i++) {
			if (navigator.userAgent.toLowerCase().match(new RegExp("("+arr[i]+")"))) {
				return RegExp.$1;
			}
		}
	}
	this.OS = this.checkIt(["linux", "x11", "mac", "win"]);
	this.name = this.checkIt(["opera", "gecko", "msie[^;]*"]);
	this.opera = (this.name=="opera") ? 1 : 0;
	this.gecko = (this.name=="gecko") ? 1 : 0;
	this.ie = (this.name.match(/msie/) && !this.opera) ? 1 : 0;
	this.getById = function(id) { return document.getElementById(id); }
	this.getByName = function(name) { return document.getElementsByName(name); }
	this.getByTagName = function (tagName) { return document.getElementsByTagName(tagName); }
	this.addSource = function(source, url, r) {
		switch (source) {
			case "script":
				url = '<script type="text/javascript" language="JavaScript" src="'+url+'"></script>\n';
			break;
			case "style":
				url = '<style type="text/css">@import "'+url+'";</style>\n';
			break;
		}

		if (r) return url;
		else document.write(url);
	}
	this.addEvent = function(obj, e, fun) {
		if (window.addEventListener) obj.addEventListener(e, fun, true);
		else if (window.attachEvent) obj.attachEvent("on"+e, fun);
		else {
			var tmp = (obj["on"+e]) ? obj["on"+e] : new Function();
			obj["on"+e] = function () { tmp(); fun(); };
		}
	}
	this.removeEvent = function(obj, e, fun) {
		if (window.removeEventListener) obj.removeEventListener(e, fun, true);
		else if (window.detachEvent) obj.detachEvent("on"+e, fun);
	}
	this.addClass = function(obj, className) {
		var i, arr;
		arr = obj.className.split(" ");
		
		for (i=0;i<arr.length;i++) {
			if (arr[i] == className) return;
		}
		
		arr[i] = className;
		
		obj.className = arr.join(" ");
	}
	this.removeClass = function(obj, className) {
		var i, arr1, arr2;
		arr1 = obj.className.split(" ");
		arr2 = [];
		
		for (i=0;i<arr1.length;i++) {
			if (arr1[i] != className) arr2[arr2.length] = arr1[i];
		}
		
		if (arr2.length != arr1.length) obj.className = arr2.join(" ");
	}	
	this.screen = function(property, obj) {
		if (!obj) obj = window;

		switch(property) {
		case "x": 	return obj.screen.width;
		case "y": 	return obj.screen.height;
		case "x2":	return (p.bw.ns4) ? obj.innerWidth : obj.document.body.clientWidth;
		case "y2":	return (p.bw.ns4) ? obj.innerHeight : obj.document.body.clientHeight;
		}
	}
	this.screenFindPosX = function(obj) {
		var currLeft = 0;
		if (obj.offsetParent) {
			while (obj.offsetParent) {
				currLeft += obj.offsetLeft;
				obj = obj.offsetParent;
			}
		} else if (obj.x) currLeft += obj.x;
		return currLeft;
	}
	this.screenFindPosY = function(obj) {
		var currTop = 0;
		if (obj.offsetParent) {
			while (obj.offsetParent) {
				currTop += obj.offsetTop;
				obj = obj.offsetParent;
			}
		} else if (obj.y) currTop += obj.y;
		return currTop;
	}
	this.scan = function(obj) {
        var url = "/ktn/scripts/popups/scan_object.html";
        var parameters = [0,1,0,1,1,400,600];
	
        if (p.bw.ie) {
            toLink(url, parameters).dialogObject = obj;
        } else {
            var objWindow = toLink("", parameters);
        
            objWindow.dialogObject = obj;
        
            objWindow.location.href = url;
        }    
    }
	this.msg = function(msg) { if (msg) alert(msg); }
}

function lib_keys(e) {
	if (!e) e = window.event;
	return (p.bw.ns4) ? e.which : e.keyCode;
}

function cookieSet(name, value, parameters) {
	var attributes = ["expires","path","domain"];
	var arr = [name + "=" + escape(value)];

	for (var i=0;i<parameters.length;i++) {
		if (parameters[i] != null && parameters[i] != undefined) {
            if (parameters[i]) {
                if (attributes[i] == "expires") {
                    var expDate = new Date();
                    expDate.setTime(expDate.getTime() + (parameters[i]*24*3600*1000));
                    parameters[i] = expDate.toGMTString();
                }
                
                arr[arr.length] = attributes[i] + "=" + parameters[i];
            }
        }
	}
	document.cookie = arr.join(";");
}

function cookieGet(name) {
		document.cookie.match(new RegExp(name + "=([^;]*);?", "gi"));
		return unescape(RegExp.$1);
}

function scriptcode(obj) { p.bw.getById(obj).onclick(); }

function scriptperson(person, properties) {
	try {
		writeSametimeLink(person[0], person[1], properties[0], properties[1]);
	} catch(e) {
    	document.write(person[1]);
	}
}

function toLink(link) {
	if (!arguments[1]) location.href = link;
	else {
		try {
			if (arguments[1].location) {
				arguments[1].location.href = link;
				return;
			}
		} catch(e) {}

		var attributes = ["location","toolbar","status","scrollbars","resizable","width","height","top","left"];

		if (arguments[1]) {
			for (var i=0;i<arguments[1].length;i++) {
				arguments[1][i] = attributes[i]+"="+arguments[1][i];
			}
		}
		return window.open((link || ""), "", arguments[1].join(","));
	}
}

if (typeof(p)!="object") var p = {};
p.bw = new lib_browser();
