function Popup(title, url, width, height, x, y){
	var _this = this;
	this.id = Popup.counter++;
	Popup.topZ++;
	var BORDER_WIDTH = 5;
	var TITLE_HEIGHT = 20;
	var BGCOLOR = "#EEEEEE";
	
	var titleElementId 	= "TITLE_BAR" + this.id;
	var closeElementId 	= "BUT_CLOSE" + this.id;
	var holderElementId 	= "TABLE" + this.id;
	var iframeElementId 	= "IFRAME" + this.id;
	var resizerElementId = "R" + this.id;
	var minElementId 		= "BUT_MIN" + this.id;
	this.holder = null;
	this.top = 0;
	this.left = 0;
	this.width = width;
	this.height = height;
	this.minimized = false;
	
	init();
	
	function createLayer(){
		var html = "<table cellpadding=" + BORDER_WIDTH + " cellspacing=0 border=0 bgcolor=" + BGCOLOR + " onselectstart='return false' ondragstart='return false'>";
		html += "<tr><td id=" + titleElementId + " style='font-family:verdana;font-size:11;' >";
		html += "<img id=" + closeElementId + " style='float:right;margin:0 2 0 2;width:15;height:14' src='/simgs/close.gif'>";
		html += "<img id=" + minElementId + " style='float:right;border:0;margin:0 2 0 2;width:15;height:14' src='/simgs/minimize.gif'>";
		html += title;
		html += "</td></tr>";
		html += "<tr id=" + resizerElementId + " ><td height=100 style='padding-top:0'>";
		html += "<iframe id=" + iframeElementId + " src=" + url + " style='width:" + (width - 2 * BORDER_WIDTH) + ";height:" + (height - TITLE_HEIGHT - 3 * BORDER_WIDTH) + ";border-width:1;border-style:solid;border-color:#999999' FRAMEBORDER=NO></iframe>";
		html += "</td></tr>";
		return html;
	}
	
	function setEvents(){
		document.getElementById(closeElementId).onclick = function(){
			_this.holder.parentNode.removeChild( _this.holder);
		}
		document.getElementById(minElementId).onclick = function(){
			toggle();
		}
		document.getElementById(titleElementId).ondblclick = function(){
			toggle();
		}
	}
	
	function toggle(){
		if(!_this.minimized){
			_this.minimized = true;
			document.getElementById(minElementId).src = "/simgs/maximize.gif";
			document.getElementById(resizerElementId).style.display = "none";
			document.getElementById(titleElementId).style.width = _this.width;
			_this.holder.style.height = TITLE_HEIGHT + BORDER_WIDTH;
		}
		else{
			_this.minimized = false;
			document.getElementById(minElementId).src = "/simgs/minimize.gif";
			if(document.all)
				document.getElementById(resizerElementId).style.display = "block";
			else
				document.getElementById(resizerElementId).style.display = "table-row";
			document.getElementById(titleElementId).style.width = "";
			_this.holder.style.height = _this.height - 3;
		}	
	}
	
	function draggable( obj,parentElmnt){
		var oldX, oldY, dx, dy, newXVal, newYVal;

		obj.onmousedown = function(e){
			Popup.topZ += 2;
			_this.mouseProtector.style.zIndex = Popup.topZ - 1;
			_this.mouseProtector.style.display	= "block";
			parentElmnt.style.zIndex = Popup.topZ;
			e = e || event;
			oldX = e.clientX;
			oldY = e.clientY;

			if(document.all){
				//event.cancelBubble = true;
				event.returnValue = false;
			}
			else{
				//e.stopPropagation();
				e.preventDefault();
			}
			
			document.onmousemove = function(e){
				document.getElementById(iframeElementId).style.visibility = "hidden";
			   e = e || event;
			   dx = e.clientX - oldX;
			   dy = e.clientY - oldY;
				
				_this.left += dx;
				_this.top += dy;
				
				newXVal = parseInt(parentElmnt.style.left) + dx;
				newYVal = parseInt(parentElmnt.style.top) + dy;
	
	   		parentElmnt.style.left = newXVal;
	   		parentElmnt.style.top = newYVal;
	
			   oldX = e.clientX;
			   oldY = e.clientY;
			   
			};
			
			document.onmouseup = function(){
				_this.mouseProtector.style.display	= "none";
				document.onmousemove = null;
				document.onmouseup = null;
				document.getElementById(iframeElementId).style.visibility = "visible";
				//document.getElementById(iframeElementId).style.display = "inline";
			};
		};
		return obj;
	}
	
	function resizable( obj, objectsToResize, parentElmnt){
		var oldX, oldY, dx, dy, newXVal, newYVal;

		obj.onmousedown = function(e){
			Popup.topZ += 2;
			_this.mouseProtector.style.zIndex = Popup.topZ - 1;
			_this.mouseProtector.style.display	= "block";
			parentElmnt.style.zIndex = Popup.topZ;
			e = e || event;
			oldX = e.clientX;
			oldY = e.clientY;

			if(document.all){
				event.cancelBubble = true;
				event.returnValue = false;
			}
			else{
				e.stopPropagation();
				e.preventDefault();
			}
			
			
			//document.getElementById(iframeElementId).style.display = "none";
			
			document.onmousemove = function(e){
				document.getElementById(iframeElementId).style.visibility = "hidden";
			   e = e || event;
			   dx = e.clientX - oldX;
			   dy = e.clientY - oldY;
			   
				_this.width += dx;
				_this.height += dy;
				
				objectsToResize.style.width = parseInt(objectsToResize.style.width) + dx;
	   		objectsToResize.style.height = parseInt(objectsToResize.style.height) + dy;
	
				_this.holder.style.width = parseInt(_this.holder.style.width) + dx;
				_this.holder.style.height = parseInt(_this.holder.style.height) + dy;
	
			   oldX = e.clientX;
			   oldY = e.clientY;
			   
			};
			
			document.onmouseup = function(){
				_this.mouseProtector.style.display	= "none";
				document.onmousemove = null;
				document.onmouseup = null;
				document.getElementById(iframeElementId).style.visibility = "visible";
				//document.getElementById(iframeElementId).style.display = "inline";
			};
		};
		return obj;
	}
	
	function init(){
		_this.mouseProtector = document.createElement("DIV");
		_this.mouseProtector.style.top		= 0;
		_this.mouseProtector.style.left		= 0;
		_this.mouseProtector.style.position	= "absolute";
		_this.mouseProtector.style.width		= "100%";
		_this.mouseProtector.style.height	= "100%";
		_this.mouseProtector.style.zIndex	= Popup.topZ;
		_this.mouseProtector.style.display	= "none";
		document.body.appendChild(_this.mouseProtector);

		_this.holder = document.createElement("DIV");
		_this.holder.id = holderElementId;
		document.body.appendChild( _this.holder);
		_this.holder.innerHTML = createLayer();
		_this.holder.style.borderWidth = 1;
		_this.holder.style.borderStyle = "solid";
		_this.holder.style.borderColor = "#222222";
		_this.holder.style.width = width + 2 + 2 * parseInt(_this.holder.style.borderWidth);
		_this.holder.style.height = height - 3;
		_this.holder.style.position= "absolute";
		_this.holder.style.top = y + document.body.scrollTop;
		_this.holder.style.left = x+ document.body.scrollLeft;
		_this.holder.style.zIndex = Popup.topZ;
		_this.top = y;
		_this.left = x;
		draggable(document.getElementById(titleElementId), _this.holder);
		setEvents();
		resizable(document.getElementById(resizerElementId), document.getElementById(iframeElementId), _this.holder)
	}
}

Popup.counter = 0;
Popup.topZ = 1;
Popup.win = [];

function openPopup(title, url, width, height, e){
	e = e || window.event;
	if(e)
		Popup.win[Popup.win.length] = new Popup(title, url, width, height, e.clientX, e.clientY);
	else
		Popup.win[Popup.win.length] = new Popup(title, url, width, height, 100, 100);
}

function pagePrint(){
	var printDialog = window.open("about:blank");
	var pageStyle = '<link href=/css/styles_print.css rel=stylesheet>';
	var pageContent;
	if(document.getElementById('contentHolder')){
		pageContent = document.getElementById('contentHolder').innerHTML;
	}
	else if(document.getElementById('content')){
		pageContent = document.getElementById('content').innerHTML;
	}
	if(printDialog && pageContent){
		setTimeout(function(){printDialog.document.write( pageStyle + pageContent);printDialog.document.close()}, 500);
	}
}

function _openLiveChat(){
	openPopup("SysMaster Chat Client", "http://support.sysmaster.com:8080/chat/chat.htm?refid=sales.sysmaster.com", 578, 434, null);
}

function openLiveChat(){
	openPopup("SysMaster Chat Client", "http://support.sysmaster.com:8080/chat/chatAll.htm?refid=sales.sysmaster.com", 578, 434, null);
	if(window.urchinTracker)
		urchinTracker('/webchat/visitor_initiate');
}

function contactPage(){
	location = "/company/contact_us.php";
}

window.onload = function(){
	if(document.getElementById("bookmarksHolder"))
		BM = new Bookmarker( document.getElementById("bookmarksHolder"));
	
	if(document.getElementById("auxBarZoomin")) new Tooltip( document.getElementById("auxBarZoomin"));
	if(document.getElementById("auxBarZoomout")) new Tooltip( document.getElementById("auxBarZoomout"));
	if(document.getElementById("auxBarChat")) new Tooltip( document.getElementById("auxBarChat"));
	if(document.getElementById("auxBarBookmark")) new Tooltip( document.getElementById("auxBarBookmark"));
	if(document.getElementById("auxBarPrint")) new Tooltip( document.getElementById("auxBarPrint"));
	if(document.getElementById("auxBarContactUs")) new Tooltip( document.getElementById("auxBarContactUs"));
	
	new Menu(q, Menu.HORIZONTAL, [document.getElementById("qlinks")]);
	if(window.opera)
		document.form1.s.style.height = "15px";
		
		
	window.onscroll = document.body.onscroll = function(){
		for(var i=0; i < Popup.win.length; i++){
			Popup.win[i].holder.style.top = Popup.win[i].top + document.body.scrollTop;
			Popup.win[i].holder.style.left = Popup.win[i].left + document.body.scrollLeft;
		}
	}
}