/**

	Copyrights (c) GatherWorks, Inc.

*/
	var webapp				= "omniview";
	var omniviewInstallPage = "gp/install.jsp";
	
	var serverIp			= null;
	var remoteGuid			= null;
	var	ov					= null;
	var myGuid				= null;
	
	var	disableRightClick	= false;
	
	//config
	var isAlwaysLogging		= true;
	
	var UNDEFINED			= "undefined";
	var OMNIVIEW_OBJECT		= "Presentation";
	var VERSION_OBJECT		= "GWVersionTracker";
	var GW_MISC				= "GW_MISC";

/************************************** HOOKING LOAD AND UNLOAD OF DOCUMENT ***********************************/
	//USE: <body onLoad="gw_init()" onUnload="gw_onunload()">
	//gw_onunloadHook();
	//gw_onloadHook();

	//gw_onresizeHook();
	
	var onLoad0			= new CALLBACK("onLoad0");	//use this one for stuff that must be initialized before everything else
	var onLoad			= new CALLBACK("onLoad");	//use this one for most onLoad operations
	var onLoad2			= new CALLBACK("onLoad2");	//use this one when you want things to happen at the last possible time
	var onBeforeunload	= new CALLBACK("onBeforeunload");
	var onUnload0		= new CALLBACK("onUnload0");	//do first
	var onUnload		= new CALLBACK("onUnload");	//most should use this one
	var onUnload2		= new CALLBACK("onUnload2");	// do onUnload0, then onUnload, then onUnload2
	var onResize		= new CALLBACK("onResize");
	var gw_init_once	= false;
	function gw_init() {
		if (gw_init_once) return;
		gw_init_once = true;
		if (gw_onload_watchdog!=null) clearInterval(gw_onload_watchdog);

		if (window.onunload!=null && window.onunload != gw_onunload) {
			//onUnload.add(window.onunload);
			window.onunload = gw_onunload;
			//error("Do not use onUnload in the body of your html page;  instead use onUnload.add(fn)");
		}

		if (window.onbeforeunload!=null && window.onbeforeunload != gw_onbeforeunload) {
			//onBeforeunload.add(window.onbeforeunload);
			window.onbeforeunload = gw_onbeforeunload;
			//error("Do not use onBeforeunload in the body of your html page;  instead use onBeforeunload.add(fn)");
		}
		
		addDiv(GW_MISC);

		onLoad0.doCallbacks();
		onLoad.doCallbacks();
		onLoad2.doCallbacks();
	}
	var gw_onload_watchdog = null;
	function gw_onload_watchdogCheckOnLoad() {		// if web page has an onload, then take it back
		if (window.onload != gw_init) {
			onLoad.add(window.onload);
			window.onload = gw_init;
			msg("Do not use onLoad in the body of your html page;  instead use onLoad.add(fn)");
		}
	}
	function gw_onloadHook() {
		try {
			window.onload = gw_init;
		} catch(err) {}
		if (window.addEventListener) {
			window.addEventListener("load", gw_init, false);
			return true;
		} else if (window.attachEvent) {
			var r = window.attachEvent("onload", gw_init);
			return r;
		} else {
			try {
				window.onload = gw_init;
			} catch(err) {}
			gw_onload_watchdog = setInterval("gw_onload_watchdogCheckOnLoad();",100);
		}
	}

	function gw_onresizeHook() {
		try {
			window.onresize = gw_resize;
		} catch(err) {}
		if (window.addEventListener) {
			window.addEventListener("resize", gw_resize, false);
			return true;
		} else if (window.attachEvent) {
			var r = window.attachEvent("resize", gw_resize);
			return r;
		}
	}
	function gw_resize() {
		onResize.doCallbacks();
	}

	function gw_onunloadHook() {
		if (window.addEventListener) {
			window.addEventListener("unload", gw_onunload, false);
			return true;
		} else if (window.attachEvent) {
			var r = window.attachEvent("onunload", gw_onunload);
			return r;
		} else {
			window.onunload = gw_onunload;
		}
	}
	function gw_onunload() {
		onUnload0.doCallbacks();
		onUnload.doCallbacks();
		onUnload2.doCallbacks();
	}
	onBeforeunload.notifyOnAdd(gw_onbeforeunloadHook);
	function gw_onbeforeunloadHookMute() {
		var temp = window.onbeforeunload;
		window.onbeforeunload = null;
		return temp;
	}
	function gw_onbeforeunloadHook() {
		try {
			window.onbeforeunload = gw_onbeforeunload;		//IE only
		} catch(err) {}
	}
	function gw_onbeforeunload() {
		return onBeforeunload.doCallbacksAppend();
	}

/************************************** GENERAL FUNCTIONS ***********************************/
	function isundefined(ob) {
		try {
			return typeof(ob)==UNDEFINED;
		} catch(err) {
			return true;
		}
	}
	
	function undefinedOrNull(ob) {
		try {
			return typeof(ob)==UNDEFINED || ob==null;
		} catch(err) {
			return true;
		}
	}

	function isdefined(ob) {
		try {
			return typeof(ob)!=UNDEFINED;
		} catch(err) {
			return false;
		}
	}
	
	function pushChildren(obj, a) {
			var ar = obj.childNodes;
			for (var i=0; i<ar.length; i++) {
				if (ar[i].nodeName.toLowerCase()=="input") {
					a.push(ar[i]);
				}
				if (ar[i].childNodes.length>0) pushChildren(ar[i], a);
			}
	}
	
	//http://www.opensourcetutorials.com/tutorials/Client-Side-Coding/JavaScript/javascript-document-object-model/page4.html
	function getChildren(obj) {
		if (document.all) return obj.all;
		if (document.getElementById) {
			var a = new Array();
			pushChildren(obj, a);
			/* firefox
			for (x in obj) {
				if (typeof(obj[x].nodeName)=="string") {
					a.push(obj[x]);
					//document.writeln(x + " = " + typeof(obj[x].nodeName) + "<br />");
				} else {
					break;
				}
			}
			*/
			return a;	//http://xulplanet.com/references/objref/HTMLInputElement.html
		}
	}
	
	
	function getObject(name) {
		if (document.all) return document.all(name);
		if (document.getElementById) return document.getElementById(name);
		if (document.layers) return document.layers(name);
		error(str_CouldNotFindObject+name);
		return null;
	}
	
	function getFrame(frameid) {
		return document.frames[frameid];
	}

	function getFieldType(field) {
		try {
			return field.nodeName.toLowerCase()
		} catch(err) { return null; }
	}
	
	function getField(name) {
		return oGetField(getObject(name));
	}
	function oGetField(obj) {
		try {
			if (getFieldType(obj)=="input" && obj.type=="checkbox") return obj.checked;
			return obj.value;
		} catch(err) {
			return "";
		}
	}
	function oSetField(obj, value) {
		try {
			if (getFieldType(obj)=="input" && obj.type=="checkbox") {
				obj.checked = (value=="true");
			} else {
				obj.value = value;
			}
		} catch(err) {
		}
	}
	
	function setField(o, value) {
		var obj	= getObject(o);
		try {
			if (getFieldType(obj)=="input" && obj.type=="checkbox") {
				obj.checked = (value=="true");
			} else {
				obj.value = value;
			}
		} catch(err) {
		}
	}
	
	function getIntField(name) {
		try {
			return parseInt(getObject(name).value);
		} catch(err) {
			return -1;
		}
	}
	
	function getTime() {
		return new Date().getTime();
	}
	
	function sleep(millis) {
		var d = new Date();
		while (true) {
			if (new Date() - d > millis) break;
		}
	}

	var gw_frameidCounter = 0;
	function addIframe(id, width, height) {
		if (typeof(width)==UNDEFINED) width = "0";
		if (typeof(height)==UNDEFINED) height = "0";
		var newIframe	= document.createElement("iframe");
		if (typeof(id)==UNDEFINED) id = "gw_frameid"+ gw_frameidCounter++;
		newIframe.setAttribute("id", id);
		newIframe.setAttribute("width", width);
		newIframe.setAttribute("height", height);
		document.body.appendChild(newIframe);
		if (width=="0" && height=="0") hideObject(id);
		return newIframe;
	}
	
	function addDiv(id) {
		var newDiv	= document.createElement("div");
		newDiv.setAttribute("id", id);
		try {
			document.body.appendChild(newDiv);
		} catch(err) {	
			return null;	//happens when document is not loaded yet (in firefox)
		}
		return newDiv;
	}
	
	function setRootPath(path)
	{
		if (path.endsWith("/")==false)
		{
			path	+= "/";
		}
		gw_rootPath = path;
	}
	var gw_rootPath		= null;
	var gw_sessionString	= "";
	function getRootPath()
	{
		if (gw_rootPath!=null)
		{
			return gw_rootPath;
		}
		var i, path = document.location.href;
		i = path.indexOf(";");
		if (i>0)
		{
			var temp	= path.substring(i);
			i = temp.indexOf("?");
			if (i>0)
			{
				temp	= temp.substring(0,i);
			}
			gw_sessionString	= temp;//includes ;
			path = path.substring(0, i);
		}
		path += "/";
		path = path.replace(/\\/g, "/");
		var count = 2;
		for (i = 8; i < path.length && count>0; i++) {
			if (path.charAt(i) == "/")
			{
				count--;
			}
		}
		gw_rootPath = path.substring(0, i-1);
		if (gw_rootPath.indexOf(webapp)==-1)
		{
			gw_rootPath = gw_rootPath.substring(0, gw_rootPath.lastIndexOf("/"));
		}
		gw_rootPath += "/";
		return gw_rootPath;	
	}
	
	function getHttpSessionId() {
		var temp = document.location.pathname;
		if (temp.substring(temp.length)=="#") temp = temp.substring(0, temp.length-1);
		var pos = temp.indexOf(";");
		if (pos==-1) {
			return "";
		} else {
			return temp.substring(pos);
		}
	}

	function getRootPathPort(newPort, removeApp) {
		var path	= getRootPath();
		var pos		= -1;

		var i;
		for (i = 7; i < path.length; i++) {
			if (path.charAt(i) == ":") pos=i;
			if (path.charAt(i) == "/") break;
		}
		if (pos==-1) pos = i;
		
		var temp = path.substring(0, pos)+":"+newPort+(removeApp?"/" : path.substring(i));
		return temp;
	}
	
	function showObject(object) {
		if (document.getElementById && document.getElementById(object) != null)
			 node = document.getElementById(object).style.visibility='visible';
		else if (document.layers && document.layers[object] != null)
			document.layers[object].visibility = 'visible';
		else if (document.all)
			document.all[object].style.visibility = 'visible';
	}
	
	function hideObject(object) {
		if (document.getElementById && document.getElementById(object) != null)
			 node = document.getElementById(object).style.visibility='hidden';
		else if (document.layers && document.layers[object] != null)
			document.layers[object].visibility = 'hidden';
		else if (document.all)
			 document.all[object].style.visibility = 'hidden';
	}
	
	// Apply a CSS style to a form element ("node"). Works in the
	// Netscape6 DOM and the MSIE DOM. The name of the stylesheet
	// property in CSS syntax ("property") is automatically converted
	// to the MSIE syntax when necessary. The value ("value") should
	// be in CSS syntax.
	function setStyle(node, property, value) {
		var ieproperty = "";
		for (var i = 0; i < property.length; i ++) {
			if (property.charAt(i) == "-" && i < property.length)
				ieproperty += property.charAt(++ i).toUpperCase();
			else
				ieproperty += property.charAt(i);
		}
		if (node.style) {
			if (node.style[ieproperty] != null)
				node.style[ieproperty] = value;
			else
				node.style = property + ': ' + value;
		}
	}

	function modalDialog(url, param, w, h) {
		if (param==null) param = new Object();
		try {
			var temp = window.showModalDialog(url, param, "help:0;center:1; dialogWidth:"+w+"px; dialogHeight:"+h+"px");
			if (temp!=null) return temp;
		} catch (err) { }
		msg("Please disable your popup blockers for this site");
	}
	
	function dialog(url, name, w, h, x, y, resizeable, scrollbars, menubar, location, toolbar, personalbar, status, fullscreen) {
		var opts = new Array;
		opts[opts.length] = "screenX=" + (x||400);
		opts[opts.length] = "screenY=" + (y||400);
		opts[opts.length] = "left=" + (x||400);
		opts[opts.length] = "top=" + (y||400);
		opts[opts.length] = "width=" + (w||400);
		opts[opts.length] = "height=" + (h||400);
		opts[opts.length] = "resizeable=" + ((resizeable) ? "yes" : "no");
		opts[opts.length] = "scrollbars=" + ((scrollbars) ? "yes" : "no");
		opts[opts.length] = "menubar=" + ((menubar) ? "yes" : "no");
		opts[opts.length] = "location=" + ((location) ? "yes" : "no");
		opts[opts.length] = "toolbar=" + ((toolbar) ? "yes" : "no");
		opts[opts.length] = "personalbar=" + ((personalbar) ? "yes" : "no");
		opts[opts.length] = "status=" + ((status) ? "yes" : "no");
		if (fullscreen) {
			opts[opts.length] = "fullscreen";	//IE only
		}
		if (name.indexOf(" ") != -1) {
			msg("No spaces allowed in the name of a window");
			return null;
		}
		var win = window.open(url, name, opts.join(","));
		if (win != null) {
			win.opener = this;
			win.focus();
		} else {
			msg("Please disable your popup blockers for this site");
		}
		return win;
	}

	//onKeyUp="ifEnter(event, init);" 
	function ifEnter(event, callback) {     
		var code = 0;
		if (typeof(event.which)!=UNDEFINED)
			code = event.which;
		else
			code = event.keyCode;
		if (code==13) callback();
	}

	function oSetHtml(obj, s) {
		obj.innerHTML = s;
	}
	
	function setHtml(obj, s) {
		var temp = getObject(obj);
		if (typeof(temp)==UNDEFINED) {
			msg("Invalid HTML object: "+obj);
		} else {
			oSetHtml(temp, s);
		}
	}
	
	function getHtml(obj) {
		var temp = getObject(obj);
		if (typeof(temp)==UNDEFINED) {
			msg("Invalid HTML object: "+obj);
			return ""; 
		} else {
			return temp.innerHTML;
		}
	}
	
	function setImage(img, file, alt) {
		var image = getObject(img);
		image.src = gw_rootPath+"images/"+file;
		image.alt = alt;
	}

	
/************************************** CALLBACK ENGINE ***********************************/
	function CALLBACK(name) {
		this.name					= name;
		this.myCallbacks			= new Array();
		this.notifyOnAddCallback	= null;
		CALLBACK.prototype.add = function(callback) {
			if (callback==null || typeof(callback)==UNDEFINED) {
				error(str_InvalidCallback);
				return;
			}
			//do not add twice
			for (i=0; i<this.myCallbacks.length; i++) {
				if (this.myCallbacks[i] == callback) return;
			}
			this.myCallbacks.push(callback);
			
			if (this.notifyOnAddCallback != null) this.notifyOnAddCallback(callback);
		}
		CALLBACK.prototype.doCallbacks = new Function('var args = new Array(), i;for(i=0;i<arguments.length;i++){args.push(arguments[i]);};	try { return this.doCallbacksNow(args); } catch(err) {}');
		CALLBACK.prototype.doCallbacksNow = function(args) {
			var i;
			for (i=0; i<this.myCallbacks.length; i++) {
				var callback = this.myCallbacks[i];
				callback(args);
			}
			return (this.myCallbacks.length>0);	// returns true if there are some callbacks
		}
		CALLBACK.prototype.doCallbacksLogicalAnd = function(defaultValue) {
			if (this.myCallbacks.length==0) return defaultValue;
			var i;
			var result = true;
			for (i=0; i<this.myCallbacks.length; i++) {
				var callback = this.myCallbacks[i];
				result &= callback();
			}
			return result;
		}
		CALLBACK.prototype.doCallbacksAppend = function() {
			var i;
			var result = "";
			for (i=0; i<this.myCallbacks.length; i++) {
				var callback = this.myCallbacks[i];
				result += callback();
			}
			return result;
		}
		CALLBACK.prototype.clear = function() {
			this.myCallbacks = new Array();
		}
		CALLBACK.prototype.notifyOnAdd = function(callback) {
			this.notifyOnAddCallback = callback;
		}
		CALLBACK.prototype.size = function() {
			return this.myCallbacks.length;
		}
	}
			
/************************************** CALLBACKS ***********************************/
	var onLog = new CALLBACK("onLog");
	function log(str) {
		str = new Date().getTime()+": "+str;
		if (onLog.size()==0) {
			setStatusBar(str);
		} else {
			onLog.doCallbacks(str, false);
		}
	}
	
	function clearLog() {
		onLog.doCallbacks("", true);
	}

	var logArea	= null;
	var logStr	= "";
	var showLogOnce = false;
	function showLog() {
		if (showLogOnce) return;
		showLogOnce = true;
		addIframe().outerHTML += '<h2>Log info below: </h2><span id=logArea style="width:100%;height:100;overflow:-moz-scrollbars-vertical;overflow-y: scroll;vertical-align:bottom"></span>';
		if (!isAlwaysLogging) onLog.add(addStringToLog);
		log("...show log now");
	}
	if (isAlwaysLogging) onLog.add(addStringToLog);
	function addStringToLog(args) {	//str, clear
		var str		= args[0];
		var clear	= args[1];

		if (clear) {
			logStr = "";
		} else {
			logStr += str + "<BR>";
	  	}

		if (logArea==null) logArea = getObject("logArea");
		if (logArea==null || typeof(logArea)==UNDEFINED) return;
		logArea.innerHTML	= logStr;
	  	logArea.scrollTop	= logArea.scrollHeight;	//scroll to the end
	}

	var TYPE_UNDEFINED	= 0;
	var TYPE_OBJECT		= 1;
	var TYPE_ARRAY		= 2;
	function getType(v) {
		if (typeof(v) == UNDEFINED || v=="") return TYPE_UNDEFINED;
		if (typeof(v.length) == UNDEFINED) return TYPE_OBJECT;
		return TYPE_ARRAY;
	}

	
	/*
function gw_frameless_createIFrame(frameID)
{
    if (!document.createElement)
    {
        return false;
    }
    
    if (navigator && 
        navigator.userAgent &&
        navigator.userAgent.indexOf("Gecko") > -1)
    {
      return gw_frameless_moz_createIFrame(frameID);
    }
    
    var IFrameDoc, IFrameObj, doc; 
    var iframeHTML = "\<iframe name=\""+ frameID +"\" id=\"" + frameID + "\" style=\"";
    if (gw__debug())
    {
        iframeHTML += "border:1px solid #000; width:150px; height:100px;";
    } else
    {
        iframeHTML += "border:none; width:0px; height:0px;";
    }
    iframeHTML += "\" src=\"" + gw_blank + "\" scrolling=\"no\"><" + "/iframe" + ">";
    document.body.innerHTML += iframeHTML;
    IFrameObj = document.getElementById(frameID);
    if (!IFrameObj.document)
    {
        IFrameObj.document = gw_frameless_findFrameDoc(IFrameObj);
    }
    return IFrameObj;
}

function gw_frameless_moz_createIFrame(frameID)
{
  var iframe = document.createElement("iframe");
  if (gw__debug())
  {
      iframe.setAttribute("style","border:1px solid #000; width:150px; height:100px;");
  } else
  {
      iframe.setAttribute("style","border:none; width:0px; height:0px;");
  }
  
  iframe.name = frameID;
  iframe.id = frameID;
  
  if (!iframe.document)
  {
        iframe.document = gw_frameless_findFrameDoc(iframe);
  }
  
  document.body.appendChild(iframe);
  iframe.setAttribute("src",gw_blank);
  
  return iframe;
}

function gw_frameless_findFrameDoc(obj)
{
    if (obj.contentDocument)
    {
        // For NS6
        return obj.contentDocument;   
    } else if (obj.contentWindow)
    {
        // For IE5.5 and IE6
        return obj.contentWindow.document;   
    } else if (obj.document)
    {
        // For IE5
         return obj.document;   
    } else
    {
        return false;
    }
}
	
	*/
	
/************************************** TABLE TOOLS ***********************************/
	function gw_html() {
		this.htmlString		= "";
		this.openTable		= false;
		this.openRow		= false;
		this.openCol		= false;
		this.tableHasHeader	= false;
		this.rowCount		= 0;
	
		gw_html.prototype.print = function(str) {
			this.htmlString += str;
			return this;
		}
	
		gw_html.prototype.printLink = function(str, url) {
			this.htmlString += '<a href=\''+url+'\'>'+str+'</a>';
			return this;
		}
	
		gw_html.prototype.println = function(str) {
			if (typeof(str)==UNDEFINED) str = "";
			this.htmlString += str + "<br />\n\r";
			return this;
		}
		
		gw_html.prototype.error = function(str) {
			this.htmlString += "<span class='error'>" + str + "</span><br />\n\r";
			return this;
		}
		
		gw_html.prototype.printpg = function(str) {
			this.htmlString += str + "<p />\n\r";
			return this;
		}
		
		gw_html.prototype.closeTable = function() {
			this.closeTags();
			return this;
		}
	
		
		gw_html.prototype.closeRow = function() {
			if (this.openCol) {
				this.htmlString += '</td>'; 
				this.openCol = false;
			}
			if (this.openRow) {
				this.htmlString += '</tr>';
				this.openRow = false;
				if (this.tableHasHeader) {
					this.tableHasHeader = false;
					this.htmlString += '</thead>';
				}
			}
		}
		
		gw_html.prototype.closeTags = function() {
			this.closeRow();
			if (this.openTable) {
				this.htmlString += '</table>';
				this.openTable = false;
			}
		}
	
		gw_html.prototype.newTable = function(withHeader) {
			this.closeTags();
			this.htmlString += '<table class="body" cellSpacing=0 cellPadding=0 width="100%" border=0>';
			if (withHeader) {
				this.tableHasHeader = true;
				this.htmlString += '<thead class="white">';
			}
			this.openTable	= true;
			this.rowCount	= 0;
			return this;
		}
	
		gw_html.prototype.newRow = function(height, width) {
			this.closeRow();
			this.htmlString += '<tr class="tableRow'+this.rowCount++%2+'"'+(height?pair("height",height):"")+(width?pair("width",width):"")+'>';
			this.openRow = true;
			return this;
		}
	
		gw_html.prototype.newCol = function(width, heigth, align, colspan ) {
			if (this.openCol) this.htmlString += '</td>';
			this.htmlString += '<td '+(this.tableHasHeader?"":"class=normalText ")+pair("width", width)+pair("height", heigth)+(colspan?pair("colspan",colspan):"")+pair("align", align)+'>';
			this.openCol = true;
			return this;
		}
	
		gw_html.prototype.newColStr = function(str, width, heigth, align, colspan ) {
			this.newCol(width, heigth, align, colspan);
			this.htmlString += "<span "+(this.tableHasHeader?"":"class=normalText ")+">"+str+"</span>";
			return this;
		}
	
		gw_html.prototype.input = function(name, value, className, max, len, style) {
			this.htmlString += '<input '+pair("name", name)+pair("value", value)+pair("id", name)+pair("maxlength", max)+pair("size", len)+pair("style", style)+'>';
			return this;
		}
	
		gw_html.prototype.addImage = function(name, filename, link, alt, visible) {
			var namestr = "";
			var style = " style=\"visibility:"+(typeof(visible)!=UNDEFINED && visible==false?"hidden;":"visible;")+"\"";
			if (name) namestr = "id=\""+name+"\" name=\""+name+"\"";
			
			var altstr = (alt!=null && alt!=""?" alt=\""+alt+"\" ":"");
			if (typeof(link)!=UNDEFINED && link!=null && link!="") {
				this.htmlString += "<a href='"+link+"'><image "+namestr+style+altstr+" border='0' src='"+filename+"' /></a>\n\r";
			} else {
				this.htmlString += "<image "+namestr+style+altstr+" border='0' src='"+filename+"' />\n\r";
			}
			return this;
		}
		
		gw_html.prototype.spanBegin = function(name, className, style) {
			this.htmlString += "<span "+pair("id", name)+pair("class", className)+(style?pair("style", style):"")+">";
			return this;
		}
		
		gw_html.prototype.spanEnd = function() {
			this.htmlString += "</span>";
			return this;
		}
	
		gw_html.prototype.icon = function(file, alt, action, id) {
			var actionStr = "";
			if (action) this.htmlString += '<a href="#" onclick="'+action+'(\''+id+'\')">';
			this.htmlString += '<img src="'+gw_rootPath+'images/'+file+'" alt="'+alt+'" width="16" height="16" border="0"/>';
			if (action) this.htmlString += '</a> '; else this.htmlString += ' ';
			return this;
		}
		
		gw_html.prototype.iconIf = function(condition, file, alt, action, id) {
			if (condition=="1" || condition==true) this.icon(file, alt, action, id); else this.iconNone();
			return this;
		}
		
		gw_html.prototype.iconNone = function() {
			this.htmlString += '<img src="'+gw_rootPath+'images/spacer.gif" width="16" height="16" border="0"/> ';
			return this;
		}
		
		gw_html.prototype.getHtml = function() {
			this.closeTags();
			//msg(this.htmlString);
			return this.htmlString;
		}
	}

	function pair(name, val) {
		if (typeof(val)==UNDEFINED || val==null) return "";
		return ' '+name+'="'+val+'" ';
	}

/************************************** AUTHENTICATION ***********************************/
	function isMe(userid) {
		return true;
	}
	
	
/************************************** FORMATTING ***********************************/
	function getTimeDescription(oldval) {
		var value = parseInt(oldval);
		if (value < 60) return value + " seconds";
		var seconds	= value % 60;
		var temp = (value - seconds) / 60;
		var minutes	= temp % 60;
		var hours = (temp - minutes) / 60;
		if (value < 3600) return minutes + " minutes, " + seconds + " seconds";
		return hours + " hours, " + minutes + " minutes, " + seconds + " seconds";
	}
	
	function yesNo(val) {
		return (val == 1 ? str_ButtonYes : str_ButtonNo);
	}
	
	function getDateFromDateTime(dateTime) {
		return dateTime.substring(0, dateTime.indexOf(" "));
	}
	
	function formatSizeStr(s) {
		var size = parseInt(s);
		if (size<1024) return size + "B";
		if (size<1024*1024) return Math.round(size/1024) + "KB";
		if (size<1024*1024*1024) return Math.round(size/1024/1024) + "MB";
		return Math.round(size/1024/1024/1024) + "GB";
	}
	
	function formatPrice(price) {
		if (price==0) return 0;
		var number	= '' + Math.round(price*100);
		var pos		= number.length - 2;
		var cents	= number.substring(pos);
		number		= number.substring(0, pos);
		if (number.length > 3) {
			var mod = number.length%3;
			var output = (mod > 0 ? (number.substring(0,mod)) : '');
			for (i=0 ; i < Math.floor(number.length/3) ; i++) {
				if ((mod ==0) && (i ==0))
					output+= number.substring(mod+3*i,mod+3*i+3);
				else
					output+= ',' + number.substring(mod+3*i,mod+3*i+3);
			}
			return (output);
		}
		return number+"."+cents;
	}

	function formatNumber(number) {
		number = '' + number
		if (number.length > 3) {
			var mod = number.length%3;
			var output = (mod > 0 ? (number.substring(0,mod)) : '');
			for (i=0 ; i < Math.floor(number.length/3) ; i++) {
				if ((mod ==0) && (i ==0))
					output+= number.substring(mod+3*i,mod+3*i+3);
				else
					output+= ',' + number.substring(mod+3*i,mod+3*i+3);
			}
			return (output);
		}
		return number;
	}

/************************************** GRAPHICS ***********************************/
	// preloads all images and set the default src
	function gw_init_graphics() {
		var imgs = document.images;
		for (var i=0; i<imgs.length; i++) {	//TODO: does this work for non-IE?
			var initname = "";
			try {
				for (var s in imgs[i]) {
					if (s=="src" || s.startsWith("status_")) {
						var name	= null;
						var alt		= "";
						var file	= imgs[i][s];
						if (file.endsWith("spacer.gif")) continue;
						if (s=="src") {
							if (typeof(imgs[i].init)!=UNDEFINED) name = imgs[i].init; else name	= "init";	//set the action name for the default graphic
							initname = name;
							alt		= imgs[i].alt;
							if (file.indexOf('pngfix.gif') != -1) file = imgs[i].realSrc;
							
							imgs[i].getState = new Function('return this.currentState;');
						} else {
							name	= s.substring(7);	//status_
							alt		= imgs[i]["alt_"+name];
						}
						if (typeof(alt)==UNDEFINED) alt = "";
						var altText = alt.replace(/<[^>]*>/g, "");
						preloadImage(file);
						imgs[i][name] = new Function('this.src="'+file+'"; this.alt="'+altText+'"; updateLinkedText(this, "'+name+'", "'+alt+'"); return "'+alt+'";');
						imgs[i].currentState = name;
					}
				}
				updateLinkedText(imgs[i], initname, imgs[i].alt);	//set initial text
			} catch(err) {}
		}
	}

	//can be optimized
	function preloadImage(i) {
		if (typeof(i)==UNDEFINED || i==null) return;
		var img = new Image(); 
		img.src=i;	//preloading image
	}
	
	function setStatus(status) {
		var img = getObject("statusimg");
		if (undefinedOrNull(img)) {
			msg("No statusimg");
			return;
		}
		if (undefinedOrNull(img[status])) {
			msg("Invalid status: "+status);
			return;
		}
		setHtml("status", img[status]());
	}
	
	function updateLinkedText(img, state, text) {
		img.currentState = state;
		if (typeof(img.linktext)!=UNDEFINED) {
			setHtml(img.linktext, text);
		}
	}
	
/************************************** COOKIES ***********************************/
	var cookieTimeout = new Date();
	fixDate(cookieTimeout);
	cookieTimeout.setTime(cookieTimeout.getTime() + 5 * 365 * 24 * 60 * 60 * 1000);
	
	function setCookie(name, value, expires, path, domain, secure) {
		//((path) ? "; path=" + path : "")
		var curCookie = name + "=" + escape(value) + "; expires=" + (expires ? expires.toGMTString() : cookieTimeout) +  "; path=" + (path ? path : "/") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
		document.cookie = curCookie;
	}
	
	function getCookie(name, defaultValue) {
		var dc = document.cookie;
		var prefix = name + "=";
		var tmp;
		var begin = dc.indexOf("; " + prefix);
		if (begin == -1) {
			begin = dc.indexOf(prefix);
			if (begin != 0) return "";
		} else {
			begin += 2;
		}
		var end = document.cookie.indexOf(";", begin);
		if (end == -1) end = dc.length;
		tmp = unescape(dc.substring(begin + prefix.length, end));
		if (tmp==null) {
			if (typeof(defaultValue)==UNDEFINED) return "";
			return defaultValue;
		}
		return tmp;
	}
	
	function deleteCookie(name, path, domain) {
		document.cookie = name + "=" +  "; path=" + (path ? path : "/") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
	
	function fixDate(date) {
		var base = new Date(0);
		var skew = base.getTime();
		if (skew > 0) date.setTime(date.getTime() - skew);
	}
	
	function getVar(v, defaultvalue) {
		var tmp = getCookie(v, null);
		if (tmp==null) {
			if (typeof(defaultvalue)!=UNDEFINED) {
				tmp = defaultvalue;
				setVar(v, tmp);
			}
		}	
		return tmp;
	}
	
	function setVar(t, val) {   // pass varname as a string and not the variable itself
		setCookie(t, val, cookieTimeout, "/");
	}

	function removeVar(t, val) {
		deleteCookie(t);
		//deleteCookie(t);	//just in case; saw double cookies on Fiona's laptop
	}

	
/************************************** PRINT UTILS ***********************************/
	//converts a span object into a printable object for logging purposes
	function createPrintObject(spanIdString) {
		var out = getObject(spanIdString);
		out.println = function(str) {
			if (typeof(str)==UNDEFINED) str = "";
			this.print(str+"<br />\r\n");
		}
		
		out.print = function(str) {
			if (typeof(str)==UNDEFINED) str = "";
			this.innerHTML += str;
		}
		
		out.error = function(str) {
			if (typeof(str)==UNDEFINED) str = "";
			this.innerHTML += "<span class='error'>" + str + "</span><br />\n\r";
		}
		
		out.clear = function() {
			this.innerHTML = "";
		}
		
		return out;
	}
	
	
/************************************** MISC UTILS ***********************************/
	var rndToday=new Date();
	var rndSeed=rndToday.getTime();
	
	function rnd() {
		rndSeed = (rndSeed*9301+49297) % 233280;
		return rndSeed/(233280.0);
	};
	
	function rand(number) {
		return Math.ceil(rnd()*number);
	};
	
	function setStatusBar(str) {
		window.status=str;
	}

	function p(name, value) {
		return "&"+name+"="+encodeURIComponent(value);
	}
	
	function enc(s) {
		return encodeURIComponent(s);
	}
	
	function pField(name, first) {
		return (isTrue(first)?"?":"&")+name+"="+encodeURIComponent(getField(name));
	}
	
	var isPopupBlockerEnabled = true;
	function getPopupblocker() {
		return isPopupBlockerEnabled;
	}
	function setPopupblocker(tf) {
		isPopupBlockerEnabled = tf;
	}
	
	function queryString(parm) {
		var querystringpassed = location.search.substring(1);
		if (!querystringpassed) return '';
		var startPos = 0 + querystringpassed.indexOf(parm + '=');
		while (startPos > -1) {
			startPos = startPos + parm.length + 1;
			var endPos = 0 + querystringpassed.indexOf('&',startPos);
			if (endPos == -1) endPos = querystringpassed.length;
			return unescape(querystringpassed.substring(startPos,endPos));
		}
		return '';
	}
	
	function getBrowserInfo() {
		return navigator.userAgent;
	}

	function isTrue(t) {
		if (undefinedOrNull(t)) return false;
		if (typeof(t)=="boolean") return t;
		if (typeof(t)=="string") return t.toUpperCase()=="TRUE";
		return false;
	}
	
	var KEY_CTRL	= 1;
	var KEY_ALT		= 2;
	var KEY_SHIFT	= 4;
	function isKeyPressed(event, key) {
		var ctrlPressed		= false;
		var altPressed		= false;
		var shiftPressed	= false;
		if (parseInt(navigator.appVersion)>3) {
			if (navigator.appName=="Netscape") {
				var mString =(e.modifiers+32).toString(2).substring(3,6);
				shiftPressed=(mString.charAt(0)=="1");
				ctrlPressed =(mString.charAt(1)=="1");
				altPressed  =(mString.charAt(2)=="1");
				//self.status="modifiers="+e.modifiers+" ("+mString+")"
			} else {
				shiftPressed=event.shiftKey;
				altPressed  =event.altKey;
				ctrlPressed =event.ctrlKey;
				//self.status="" +  "shiftKey="+event.shiftKey  +", altKey="  +event.altKey  +", ctrlKey=" +event.ctrlKey 
			}
		}
		
		if (key & KEY_CTRL	&& ctrlPressed)		return true;
		if (key & KEY_ALT	&& altPressed)		return true;
		if (key & KEY_SHIFT	&& shiftPressed)	return true;
	}

	onLoad.add(listenForKeys);
	function listenForKeys() {
		document.onkeypress =
			function (evt) {
				var c = document.layers ? evt.which 
						: document.all ? event.keyCode
						: evt.keyCode;
				if (c==7 && isKeyPressed((document.all?event : evt), KEY_CTRL+KEY_SHIFT)) ov.enterFullscreen();	//7==g
				if (c==11 && isKeyPressed((document.all?event : evt), KEY_CTRL+KEY_SHIFT)) {showLog(); ov.sizeDown(); }	//11==k
				return true;
			};
		
		//If you need for NN4 to capture keypresses in text fields/areas too add
		//if (document.layers) document.captureEvents(Event.KEYPRESS);
	}

	String.prototype.max = function(len) {
		if (this.length > len) return this.substring(0,len-3)+"..."; 
		return this;
	}

	/* (("Hello world!").endsWith("!")) */
	String.prototype.endsWith = function(sEnd) {
		return (this.substr(this.length-sEnd.length)==sEnd);
	}
	
	/* (("Hello world!").startsWith("H")) */
	String.prototype.startsWith = function(sStart) {
		return (this.indexOf(sStart)==0);
	}
	
	/* (("Hello world!  ").trim().replace(" ",".") */
	String.prototype.trim = function() {
		var b=0,e=this.length -1;
		while(this.substr(b,1) == " ") b++;
		while(this.substr(e,1) == " ") e--;
		return this.substring(b,e+1);
	}
	
	
	/* (("Hello world!").toCharArray().join("\n")) */
	String.prototype.toCharArray = function() {
		var arrRet = new Array();
		for(var i=0;i<this.length;i++) arrRet.push(this.substr(i,1));
		return arrRet;
	}
	
	
	/* (("Hello world!").reverse()); */
	String.prototype.reverse = function() {
		var a = new Array();
		for(var i=0;i<this.length;i++) a.push(this.substr(i,1));
		return a.reverse().join("");
	}
	
	
	/* (("first,second,third").split(",").indexOf("second")); */
	Array.prototype.indexOf = function() {
		if(arguments.length==1) {
			for(var i=0;i<this.length;i++) {
				if(this[i]==arguments[0]) return i;
			}
		}
		return -1;
	}
	
	/* var a = ("first,second,third").split(","); msg(a.length); a.clear(); msg(a.length); */
	Array.prototype.clear = function() {
		return this.splice(0,this.length);
	}
	
	/*var a = ("first,second,third").split(","); var b = a.copy; msg("a:" + a.length + "\nb:" + b.length); */
	Array.prototype.copy = function() {
		return this.slice(0,this.length);
	}
	
	/* msg((100).changeSystem(16)); */
	Number.prototype.changeSystem = function(iSystem) {
		if(typeof iSystem != "number") return "0";
		var arrIndex = new Array("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
		var arrValue = new Array();
		var intPower = 0;
		var intValue = this;
		var strRet   = "";
	
		if(iSystem>arrIndex.length) throw "Index out of range, max=" + arrIndex.length;
	
		while(intValue > Math.pow(iSystem,intPower)) intPower++;
	
		for(i=intPower;i>0;i--)	{
			arrValue[i] = arrIndex[Math.floor(intValue / Math.pow(iSystem,i))];
			intValue %= Math.pow(iSystem,i);
		}
		arrValue[i--] = arrIndex[intValue];
		strRet = arrValue.reverse().join("");
		if(strRet.substr(0,1)=="0") strRet = strRet.substr(1);
		return strRet;
	}

/************************************** WINDOW UTILS ***********************************/
	function getScreenWidth() {	//accomodates the windows tool bar
		return window.screen.availWidth;
	}
	
	function getScreenHeight() { //accomodates the windows tool bar
		return window.screen.availHeight;
	}
	
	
	var possibleScreenSize = [[640,480], [800,600], [1024,768], [1920,1200], [1280,1024], [1600,1200], [1152,864], [1280,768], [1280,960], [1280,800]];
	var minDelta = 10;
	function getActualScreenSize() {
		var x = window.screen.availWidth;
		var y = window.screen.availHeight;
		var min = 2000;
		var m = new Object();
		m.x = x;
		m.y = y;
		
		var i;
		for (i=0; i < possibleScreenSize.length; i++) {
			var temp = possibleScreenSize[i];
			if (temp[0] == x) {
				var delta = temp[1] - y;
				if (delta < min && delta > minDelta) {
					min = delta;
					m.x = temp[0];
					m.y = temp[1];
				}
			}
			if (temp[1] == y) {
				var delta = temp[0] - x;
				if (delta < min && delta > minDelta) {
					min = delta;
					m.x = temp[0];
					m.y = temp[1];
				}
			}
			
			if (min == 2000) {
				for (i=0; i < possibleScreenSize.length; i++) {
					var temp = possibleScreenSize[i];
					var delta = temp[1] - y;
					if (delta < min && delta > minDelta && x<=temp[0]) {
						min = delta;
						m.x = temp[0];
						m.y = temp[1];
					}
					var delta = temp[0] - x;
					if (delta < min && delta > minDelta && y<=temp[1]) {
						min = delta;
						m.x = temp[0];
						m.y = temp[1];
					}
				}
			}
		}
		
		return m;
	}
	
	function getActualScreenWidth() {
		return getActualScreenSize().x;
		//return ov.getScreenWidth();
	}
	
	function getActualScreenHeight() {
		return getActualScreenSize().y;
		//return ov.getScreenHeight();
	}
	
	function getWidth() {
		if (document.layers) {
		    return window.innerWidth;
		} else if (document.all) {
		    return document.body.clientWidth;
		}
		return 10;
	}

	function getHeight() {
		if (document.layers) {
		    return window.innerHeight;
		} else if (document.all) {
		    return document.body.clientHeight;
		}
		return 10;
	}
	
	function getStyleObject(objectId) {
	    // cross-browser function to get an object's style object given its
	    if(document.getElementById && document.getElementById(objectId)) {
			// W3C DOM
			return document.getElementById(objectId).style;
	    } else if (document.all && document.all(objectId)) {
			// MSIE 4 DOM
			return document.all(objectId).style;
	    } else if (document.layers && document.layers[objectId]) {
			// NN 4 DOM.. note: this won't find nested layers
			return document.layers[objectId];
	    } else {
			return false;
	    }
	} // getStyleObject
	
	function move(obj, x, y) {
		var div = getStyleObject(obj);
		if (document.layers) {
			 div.left = x;
			 div.top = y;
		} else {
			 div.left = x + "px";
			 div.top = y + "px";
		}
	}
	
/************************************** FILE UTILS ***********************************/
	//remote person is pushing file to me
	function downloadFile(skey, name, callGuid) {
		if (callGuid == ov.myCallGuid) return;
		ov.leaveFullscreen();
		xps.downloadFile(skey, "file:"+name);
	}

	function shareFiles() {
		dialog(getRootPath()+"include/files.jsp"+getHttpSessionId()+"?anon=false", "Files", 450, 300);	//asks for login again
		//modalDialog(getRootPath()+"include/files.jsp"+getHttpSessionId()+"?anon=false", null, 450, 320);
	}

	//let a guest upload a file to the owner of meeting
	function guestShareFiles() {
		//dialog(gw_rootPath+"include/fileSelect.jsp?anon=true", "Files", 450, 150);
		ov.leaveFullscreen();
		modalDialog(getRootPath()+"include/fileSelect.jsp"+getHttpSessionId()+"?anon=true&pin="+pin, null, 450, 165);
	}
	

/************************************** INSTALLER UTILS ***********************************/
	//possible installer components
	var REQUIRE_PRESENTER	= "presenter";
//	var REQUIRE_AUDIO		= "audio";
//	var REQUIRE_AUDIO_VIDEO	= "audio_video";

	var skipLicenseAgreement	= false;
	var installerRedirected		= false;
	function runInstaller() {
		if (ignoreInstaller || queryString("noinstall")=="true") {
			ignoreInstaller	= true;
			return;
		}
		if (!hasVerifiedRequiredInstallerComponents) {
			verifyRequiredInstallerComponents();
		}

		if (!document.location.pathname.endsWith("/install.jsp")) {	// not the installer
			log("starting installer");
			var install = "";
			for (var mod in missingRequiredComponent) {
				install += "&" + mod + "=true";
				if (mod==REQUIRE_PRESENTER) {
					//can the presenter module be installed???
					if (!ov.shouldInstallerTryToLoadPresenterModule()) {
						alert("Cannot load presenter module.  You need Windows 2000, XP or 2003 with Administrator rights");
						return;
					}
				}
			}
			if (installerRedirected == false) {
				setVar("gwOmniviewVersion", -1);
				var url = getRootPath() + omniviewInstallPage +getHttpSessionId()+ "?gw=rocks" + install + (skipLicenseAgreement?"&accept=true&skin=none":"");
				//url = "../../client/setup.exe";
				setTimeout('if(confirm("Installation of new or updated components required to continue.  If you see a yellow information bar at the top of the web page that says something about an ActiveX control click Cancel here, then click the information bar to allow the ActiveX control.  Otherwise, click OK here to continue to the installation page to install the new components."))document.location.href="'+url+'";', 10000);
				installerRedirected = true;
			}
		}
	}
	
	var requiredInstallerComponent	= new Object();
	var missingRequiredComponent	= new Object();
	function addRequiredInstallerComponent(comp) {
		log("new requirement: "+comp);
		requiredInstallerComponent[comp] = comp;
	}
	
	//addRequiredInstallerComponent(REQUIRE_PRESENTER);
	//addRequiredInstallerComponent(REQUIRE_AUDIO);
	
	// omniview must always be installed
	var hasVerifiedRequiredInstallerComponents = false;
	var isVerifyingRequiredInstallerComponents = false;
	function verifyRequiredInstallerComponents() {
		if (hasVerifiedRequiredInstallerComponents) return;	//we already did this - otherwise we will loop with runInstaller
		isVerifyingRequiredInstallerComponents = true;

		var hasMissingComponents = false;
		for (var mod in requiredInstallerComponent) {
			if (mod == REQUIRE_PRESENTER) {
				if (!ov.isDriverInstalled()) {
					missingRequiredComponent[REQUIRE_PRESENTER] = REQUIRE_PRESENTER; //failed, so add to list
					hasMissingComponents = true;
					log("missing component: REQUIRE_PRESENTER");
				}
			}
		}

		hasVerifiedRequiredInstallerComponents = true;
		if (hasMissingComponents) {
			runInstaller();	// there are missing components
		}
	}

	function installPresenterModuleNow() {
		ov.leaveFullscreen();
		modalDialog(getRootPath()+"include/loadpresentermodule.jsp", null, 380, 80);
	}

/************************************** 4cc UTILS ***********************************/
	function fourcc2int(fourcc) {
		var response = 0;
		for (var i=0; i<4; i++) {
			response += fourcc.charCodeAt(3-i) << (i*8);
		}
		return response;
	}
	
	function int2fourcc(val) {
		var response = "";
		for (var i=0; i<4; i++) {
			response = String.fromCharCode(val % 256) + response;
			val >>= 8;
		}
		return response;
	}
	
	
/************************************** MOUSE UTILS ***********************************/
	try {
		document.onmouseup=mouseClick;
		if (document.layers) window.captureEvents(Event.MOUSEUP);
		window.onmouseup=mouseClick;
		document.onmousedown=mouseClick;
		if (document.layers) window.captureEvents(Event.MOUSEDOWN);
		window.onmousedown=mouseClick;
		
		if (disableRightClick) {
			document.oncontextmenu=new Function("return false");		//disable right click
		}
	} catch(err) {
		//ignore
	}
	var onMouseClick = new CALLBACK("onMouseClick");
	var onNextMouseClick = new CALLBACK("onNextMouseClick");
	function mouseClick(e) {
		if (navigator.appName == 'Microsoft Internet Explorer') e = event;
		onMouseClick.doCallbacks(e);

		var mouseup = e.type=="mouseup";
		if (mouseup) {
			onNextMouseClick.doCallbacks(e);
			onNextMouseClick.clear();
		}

		if (disableRightClick) {
			//disable right click
			if ((navigator.appName == 'Netscape' && (e.which == 3 || e.which == 2)) || (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3))) return false;
		}
		return true;
	}


/************************************** PLUGIN TOOLS ***********************************/
	function getTool(name) {
		var pa = this;
		var tool	= new Object();
		while (true) {
			tool.base	= pa.getFrame("frame_"+name);
			if (typeof(tool.base)!=UNDEFINED || pa == pa.parent) break;
			pa = pa.parent;
		}
		if (typeof(tool.base)==UNDEFINED) {
			error(str_NoSuchToolFound+name);
			return null;
		}
		tool.pmenu	= tool.base.pmenu;
		return tool;
	}
	
	function enablePlugin(s_plugin, s_pluginShadow, s_pbody, width, height) {
		var plugin			= getObject(s_plugin);
		var pluginShadow	= getObject(s_pluginShadow);
		var pbody			= getObject(s_pbody);

		pbody.runtimeStyle.height = height-24;
		plugin.runtimeStyle.height = height-2;
		pluginShadow.runtimeStyle.visibility = 'visible';
	}
	
/************************************** AUDIO TOOLS ***********************************/
	function getAudioName(id) {
		return "gwaudio_"+id;
	}
	function createAudioObject(id, audioFile, volume) {
	/*
		var name	= getAudioName(id);
		var vol		= 100;
		if (typeof(volume)!=UNDEFINED) vol = volume;
		var s = '<OBJECT ID="'+name+'" classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" CODEBASE= "http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701"';
		s += 'width=0 height=0 standby="Loading Microsoft Windows Media Player components..." type="application/x-oleobject">';
		s += '<PARAM NAME="FileName"  VALUE="'+audioFile+'"><PARAM NAME="AutoStart" Value="false"><PARAM NAME="ShowStatusBar" Value="false"><PARAM NAME="Volume" VALUE='+vol+'>';
		s += '<embed src="'+audioFile+'" type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" Name='+name+' autostart=0 ShowStatusBar=0 Volume='+vol+'></embed>';
		s += '</OBJECT>';
		getObject(GW_MISC).outerHTML += s;
		*/
	}
	
	function playAudio(id) {
		try {
			getObject(getAudioName(id)).Play();
			log("playAudio:"+id);
		} catch(err) {
			errorIfDebugging("Invalid audio file");
		}
	}
	
/************************************** GATHER STATISTICS ***********************************/
	function doStatistics() {
		//nothing at this time
	}
	
	function logUse(info) {
		xps.usage(info, null);
	}
	
/************************************** DEBUGGING ***********************************/
	function debug() {
		//debugger;	//breaks Safari browser and NetScape
	}

	var isDebug = false;
	onLoad0.add(shouldWeDebug);
	function shouldWeDebug() {
		var d = queryString("debug");
		if (d=="true") {
			setVar("debug", "true");
			isDebug = true;
		} else if (d=="false") {
			setVar("debug", "");
		}
		if (getVar("debug")=="true") isDebug = true;
	}

	function error(s, isServerSide, errorType) {
		var t = (typeof(errorType)==UNDEFINED ? "" : errorType+" ");
		if (isServerSide==true) {
			msg("SERVER ERROR: "+t+s);
		} else {
			var m = "ERROR: "+t+s;
			if (isDebug) {
				if (confirm("Debug? "+m)) {
					debug();
				}
			} else {
				msg(m);
			}
		}
	}
	
	function errorIfDebugging(m, isServerSide, errorType) {
		if (isDebug) error(m, isServerSide, errorType);
	}
	
	// from try catch
	function errorC(err) {
		error(err.name + " (" + err.message + ")" );
	}
	
	function complain(m, isServerSide) {
		if (isServerSide==true) {
			msg("SERVER WARNING: "+m);
		} else {
			msg(str_WARNING+m);
		}
	}
	
	function info(m, isServerSide) {
		if (isServerSide==true) {
			msg("SERVER INFO: "+m);
		} else {
			msg(str_INFO+m);
		}
	}
	
	var AUDIO_MESSAGE = "AUDIO_MESSAGE";
	onLoad.add(_initMessages);
	function _initMessages() {
		//moved to omniview.js createAudioObject(AUDIO_MESSAGE, gw_rootPath+"include/sounds/message.wav", 150);
	}
	function msg(m) {
		popup.info(str_Information, m, null);
	}
	
//************************************************ CLIPBOARD ************************
	function setClipboard(meintext) {
		if (window.clipboardData) {
			window.clipboardData.setData("Text", meintext);	// IE
		} else if (window.netscape) { 
			var temp = netscape.security;
			temp.PrivilegeManager.enablePrivilege('UniversalXPConnect')
	
			var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
			if (!clip) return;
	   
			var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
			if (!trans) return;
	   
			trans.addDataFlavor('text/unicode');
	
			var str = new Object();
			var len = new Object();
	
			var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
			var copytext=meintext;
			str.data=copytext;
			trans.setTransferData("text/unicode",str,copytext.length*2);
			var clipid=Components.interfaces.nsIClipboard;
	   
			if (!clip) return false;
			clip.setData(trans,null,clipid.kGlobalClipboard);
		}
		//msg("Following info was copied to your clipboard:\n\n" + meintext);
		return false;
	}

	function getClipboard() {
		if (window.clipboardData) {
			return(window.clipboardData.getData('Text'));	// IE
		} else if (window.netscape) { 
			var temp = netscape.security;
			temp.PrivilegeManager.enablePrivilege('UniversalXPConnect')

			var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
			if (!clip) return;

			var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
			if (!trans) return;

			trans.addDataFlavor('text/unicode');
			clip.getData(trans,clip.kGlobalClipboard);

			var str = new Object();
			var len = new Object();

			try { trans.getTransferData('text/unicode',str,len); } catch(error) { return; }

			if (str) {
				if (Components.interfaces.nsISupportsWString) str=str.value.QueryInterface(Components.interfaces.nsISupportsWString);
				else if (Components.interfaces.nsISupportsString) str=str.value.QueryInterface(Components.interfaces.nsISupportsString);
				else str = null;
			}
	
			if (str) return(str.data.substring(0,len.value / 2));
		}
		return;
	}

//************************************************ MESSAGEBOX ************************
	function isQuit() {
		try {
			if (applicationId=="ihets") return true;
		} catch(err) {
		}
		return false;
	}

	POPUP = {
		getService : function() {
			this.popupdivname = "gwpopup";
			this.div		= null;
			this.callback	= null;
			this.data		= null;
			this.x			= -1;
			this.y			= -1;
			this.visible	= false;
			this.confirmQ	= false;
			this.ovx		= 1;
			this.ovy		= 1;
			
			this.OK		= str_ButtonOK;
			this.CANCEL	= str_ButtonCancel;
			this.CLOSE	= "close";

			this.init = function(msg) {
				if (this.callback!=null) {
					this.callback(this.CLOSE, this.data);	//previous popup still open and will be closed - call callback
				}
				this.callback	= null;
				this.data		= null;
				this.confirmQ	= false;

				msg=""+msg;
				
				var temp = 60 + msg.length * 6;
				if (temp<60) temp = 60;
				if (temp>350) temp = 350;
				this.x = temp;
				this.y = 60+(msg.length/4);
			}
			
			this.info = function(title, msg, callback, data) {
				if (isQuit()) return;
				this.init(msg);
				this.update(this.getHtml(title, msg, this.getButtons(this.OK)), callback, data);
			}
			
			this.ask = function(title, msg, callback, data, option1, option2) {
				if (isQuit()) return;
				this.init(msg);
				this.update(this.getHtml(title, msg, this.getButtons(option1, option2)), callback, data);
			}
			
			this.confirm = function(title, msg, callback, data) {
				if (isQuit()) return;
				this.init(msg);
				this.confirmQ = true;
				this.update(this.getHtml(title, msg, this.getButtons(str_ButtonYes, str_ButtonNo)), callback, data);
			}
			
			this.getButtonText = function(button) {
				return '&nbsp;&nbsp;<input type="button" class="popupbutton" value=" '+button+' " onclick="popup.processClick(\''+button+'\')" />';
			}
			
			this.getButtons = function(button1, button2) {
				var buttons = '<div style="position:absolute; bottom:6px; right:6px;">';
				buttons += this.getButtonText(button1);
				if (typeof(button2)!=UNDEFINED) buttons += this.getButtonText(button2);
				buttons += '</div>';
				return buttons;
			}

			this.getHtml = function(title, msg, buttons) {
				var closebox	= '<div style="position:absolute; right:3px; cursor:pointer;"><img src="'+gw_rootPath+'images/close.gif" border="0" onclick="popup.processClick(\''+this.CLOSE+'\')"/></div>';
				var html = '<div class="popuptitle">'+title+'</div>';	//title bar
				html += '<div class="popupbody">'+msg+buttons+'</div>';
				
				return '<div id="popupbox" name="popupbox" class="popupbox" style="top:120px; left:350px; width:'+this.x+'px; height:'+this.y+'px; ">' + html + '</div>';	//wrap it
			}
			
			this.update = function(html, callback, data)  {
				if (this.div == null) this.div = addDiv(this.popupdivname);
				if (this.div == null) return;	//error at the beginning (FireFox body not loaded yet)
				if (typeof(callback)!=UNDEFINED) this.callback = callback;
				if (typeof(data)!=UNDEFINED) this.data = data;
				this.div.innerHTML = html;
				if (ov!=null && ov.isInited) {
					this.ovx = vb_getWidth();
					this.ovy = vb_getHeight();
					ov.setSize(0, 0);
				}
				this.browserResized(true);
				playAudio(AUDIO_MESSAGE);
				this.show();
			}
			
			this.show = function() {
				showObject("popupbox");
				this.visible = true;
				window.focus();
				this.browserResized(true);
			}
			this.hide = function() {
				hideObject("popupbox");
				this.visible = false;
			}
			
			this.processClick = function(button) {
				this.hide();
				if (ov!=null && ov.isInited) ov.setSize(this.ovx, this.ovy);
				if (this.callback != null) {
					if (!this.confirmQ || button==str_ButtonYes) this.callback(this.data, button);	//confirm==yes or something else
					this.callback = null;
				}
			}
			
			this.browserResized = function(force) {	//no this as is called also when browser is resized
				if (typeof(force)==UNDEFINED && !popup.visible) return;
				var left = (getWidth() - popup.x) / 2;
				var top = (getHeight() - popup.y) / 2;
				if (top>150) top = 150;
				move("popupbox", Math.floor(left), Math.floor(top));
			}
			
			return this;
		}
	}
	var popup = POPUP.getService();
	onResize.add(popup.browserResized);


//************************************************ URL MANAGEMENT ************************
	//getCurrentUrl().setBase("index.jsp").setParam("newrep", newrep).setParam("TEMPtemp", temp).setParam("PAGEvar", forpage).setAnchor("123").goToUrl();
	
	URL_OBJECT	= {
		getUrlObject : function() {
			this.qs			= document.location.search;
			this.base		= document.location.pathname;
			this.previd		= null;
			this.anchor		= "";

			if (this.qs.substring(0,1)=='?') this.qs=this.qs.substring(1);
			this.oqs	= this.qs;	//original querystring
			this.ohref	= document.location.href;
			
			this.setFromField	= function(name) {
				this.setParam(name, getField(name));
				return this;
			}
			
			this.stripParams	= function(type) {	//remove this param if in querystring and then add it; also strip TEMP variables
				var newqs	= "";
				var	temp	= this.qs;
				
				while (true) {
					var pos1	= temp.indexOf("=");
					if (pos1==-1) break;
					var pos2	= temp.indexOf("&");
					if (pos2==-1) pos2 += temp.length;	//last one
					
					var strip	= false;
					var name1	= temp.substring(0, pos1);
					if (typeof(name)!=UNDEFINED) {
						if (type==0 && name1.substring(0,4)=="TEMP") strip = true;	//strips of temp vars at the beginning
						if (type==0 && name1=="id") this.setId(temp.substring(pos1+1, pos2));
						if (type==1 && name1.substring(0,4)=="PAGE") strip = true;		//if base changes, then strip of PAGE variables
						if (!strip) newqs	+= temp.substring(0, pos2+1);
					}
					
					temp	= temp.substring(pos2+1);
				}
				
				newqs	+= temp;
				
				if (newqs!="" && newqs.substring(newqs.length-1)!="&") {
					newqs	+= "&";
				}
				
				this.qs	= newqs;
				
				return this;
			}

			this.setParam	= function(name, value) {	//remove this param if in querystring and then add it; also strip TEMP variables
				var newqs	= "";
				var	temp	= this.qs;
				
				while (true) {
					var pos1	= temp.indexOf("=");
					if (pos1==-1) break;
					var pos2	= temp.indexOf("&");
					if (pos2==-1) pos2 += temp.length;	//last one
					
					var name1	= temp.substring(0, pos1);
					if (name1!=name) { //replace previous value if existed
						newqs	+= temp.substring(0, pos2+1);
					}
					
					temp	= temp.substring(pos2+1);
				}
				
				newqs	+= temp;
				
				if (newqs!="" && newqs.substring(newqs.length-1)!="&") {
					newqs	+= "&";
				}
				
				if (typeof(name)!=UNDEFINED && name!=null) {
					newqs	+= name+"="+encodeURIComponent(value);
				}
				
				this.qs	= newqs;
				
				return this;
			}

			this.addTempField	= function(field, value) {
				var v	= null;
				if (typeof(value)==UNDEFINED) {
					v	= getField(field);
				} else {
					v	= value;
				}
				this.setParam("TEMP"+field, v);
				return this;
			}
			
			this.setBase	= function(base) {
				if (this.base != base) {
					this.stripParams(1);
				}
				this.base	= base;
				return this;
			}
			
			this.setPrevId	= function(previd) {
				this.previd	= previd;
				return this;
			}
			
			this.setId	= function(id) {
				this.setPrevId(id);
				this.setParam("id", id);
				return this;
			}
			
			this.print	= function() {
				alert(this.getUrl());
				return this;
			}
			
			this.setAnchor	= function(anchor) {
				this.anchor	= "#"+anchor;
				return this;
			}
			
			this.goToUrl	= function() {
				var url = this.getUrl();
				//alert(url);
				//document.location.replace(url);
				document.location.href=url;
			}
			
			this.refresh	= function() {
				this.setParam("rrandom", getTime());
				this.goToUrl();
			}
			
			this.getUrl	= function() {
				if (this.previd!=null) {
					this.setParam("previd", this.previd).setAnchor(this.previd);
				}
				
				this.setParam("rrandom", getTime());
				
				if (this.qs!="" && this.qs.substring(this.qs.length-1)=="&") {
					this.qs	= this.qs.substring(0, this.qs.length-1);		//remove & at the end
				}
				
				if (this.anchor=="") {
					var pos	= this.ohref.indexOf("#");
					if (pos>-1) this.anchor	= this.ohref.substring(pos);
				}
				
				var url	= this.base+"?"+this.qs+this.anchor;
				return url;
			}
			
			//strip temp variables only once at the beginning
			this.stripParams(0);
			
			return this;
		}
	}
	
	function getCurrentUrl() {
		return URL_OBJECT.getUrlObject();
	}
	
	function goToUrl(base, id) {
		var	t	= getCurrentUrl().setBase(base);
		if (typeof(id)!=UNDEFINED) t.setId(id);
		t.goToUrl();
	}

	//onKeyUp="characterCount(this,255);"
	function characterCount(field, maxchars) {
		if (field.value.length > maxchars) {
			field.value = field.value.substring(0, maxchars);
			alert("Error: You are only allowed to enter up to "+maxchars+" characters.");
		}
		return false;
	}
		
	//limit textbox to CTRL-C
	//onKeyUp="limitToCopy(event);" 
	function limitToCopy(event) {
		var code = 0;
		if (typeof(event.which)!=UNDEFINED)
			code = event.which;
		else
			code = event.keyCode;
			
		//17=CTRL
		//67=C
		if (code==17) return true;	//CTRL key
		if (isKeyPressed(event, KEY_CTRL)) {	//CTRL is still being held in
			if (code==67) return true;	//C	(copy text to clipboard)
			if (code==65) return true;	//A	(select all)
		}
		return false;
	}

	var othercolor = "#ff8888";
	function toggle(id)
	{
		var row = getObject("row"+id);
		var color = row.style.backgroundColor;
		if (color == othercolor)
		{
			row.style.backgroundColor	= "#ffffff";
		}
		else
		{
			row.style.backgroundColor	= othercolor;
			othercolor					= row.style.backgroundColor;	//firefox changes it to rgb(r,g,b)
		}
	}

function checkForEnter(event,callback)
{
	if (event.keyCode==13) callback();
}

function refresh() {
	getCurrentUrl().refresh();
}
