﻿// JScript File

// The Dialog object contrustor

Dialog = function (onSelected, onClose){
	// member variables
	this.activeDiv = null;
	this.timeout = null;
	this.onSelected = onSelected || null;
	this.onClose = onClose;// || null;
	this.dragging = false;
	this.hidden = true;
	this.isPopup = true;
    this.name="";
    this.title="";
    this.msg="";
    this.top=0;
    this.left=0;
    this.width=200;
    this.bgClass="";
    this.barClass="";
	// HTML elements
	this.table = null;
	this.element = null;
	this.tbody = null;			
};

// ** constants

/// "static", needed for event handlers.
Dialog._dlg = null;

/// detect a special case of "web browser"
Dialog.is_ie = ( /msie/i.test(navigator.userAgent) &&
		   !/opera/i.test(navigator.userAgent) );

Dialog.is_ie5 = ( Dialog.is_ie && /msie 5\.0/i.test(navigator.userAgent) );

Dialog.is_ie6 = ( Dialog.is_ie && /msie 6\.0/i.test(navigator.userAgent) );

/// detect Opera browser
Dialog.is_opera = /opera/i.test(navigator.userAgent);

/// detect KHTML-based browsers
Dialog.is_khtml = /Konqueror|Safari|KHTML/i.test(navigator.userAgent);

// BEGIN: UTILITY FUNCTIONS; beware that these might be moved into a separate
//        library, at some point.
Dialog.getAbsolutePos = function(el) {
	var SL = 0, ST = 0;
	var is_div = /^div$/i.test(el.tagName);
	if (is_div && el.scrollLeft)
		SL = el.scrollLeft;
	if (is_div && el.scrollTop)
		ST = el.scrollTop;
	var r = { x: el.offsetLeft - SL, y: el.offsetTop - ST };
	if (el.offsetParent) {
		var tmp = this.getAbsolutePos(el.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}
	return r;
};

Dialog.isRelated = function (el, evt) {
	var related = evt.relatedTarget;
	if (!related) {
		var type = evt.type;
		if (type == "mouseover") {
			related = evt.fromElement;
		} else if (type == "mouseout") {
			related = evt.toElement;
		}
	}
	while (related) {
		if (related == el) {
			return true;
		}
		related = related.parentNode;
	}
	return false;
};

Dialog.removeClass = function(el, className) {
	if (!(el && el.className)) {
		return;
	}
	var cls = el.className.split(" ");
	var ar = new Array();
	for (var i = cls.length; i > 0;) {
		if (cls[--i] != className) {
			ar[ar.length] = cls[i];
		}
	}
	el.className = ar.join(" ");
};

Dialog.addClass = function(el, className) {
	Dialog.removeClass(el, className);
	el.className += " " + className;
};

// FIXME: the following 2 functions totally suck, are useless and should be replaced immediately.
Dialog.getElement = function(ev) {
	var f = Dialog.is_ie ? window.event.srcElement : ev.currentTarget;
	while (f.nodeType != 1 || /^div$/i.test(f.tagName))
		f = f.parentNode;
	return f;
};

Dialog.getTargetElement = function(ev) {
	var f = Dialog.is_ie ? window.event.srcElement : ev.target;
	while (f.nodeType != 1)
		f = f.parentNode;
	return f;
};

Dialog.stopEvent = function(ev) {
	ev || (ev = window.event);
	if (Dialog.is_ie) {
		ev.cancelBubble = true;
		ev.returnValue = false;
	} else {
		ev.preventDefault();
		ev.stopPropagation();
	}
	return false;
};
Dialog.addEvent = function(el, evname, func) {
	if (el.attachEvent) { // IE
		el.attachEvent("on" + evname, func);
	} else if (el.addEventListener) { // Gecko / W3C
		el.addEventListener(evname, func, true);
	} else {
		el["on" + evname] = func;
	}
};

Dialog.removeEvent = function(el, evname, func) {
	if (el.detachEvent) { // IE
		el.detachEvent("on" + evname, func);
	} else if (el.removeEventListener) { // Gecko / W3C
		el.removeEventListener(evname, func, true);
	} else {
		el["on" + evname] = null;
	}
};

Dialog.createElement = function(type, parent) {
	var el = null;
	if (document.createElementNS) {
		// use the XHTML namespace; IE won't normally get here unless
		// _they_ "fix" the DOM2 implementation.
		el = document.createElementNS("http://www.w3.org/1999/xhtml", type);
	} else {
		el = document.createElement(type);
	}
	if (typeof parent != "undefined") {
		parent.appendChild(el);
	}
	return el;
};

// END: UTILITY FUNCTIONS

// event handlers

Dialog.tableMouseUp = function(ev) {
	var dlg = Dialog._dlg;
	if (!dlg) {
		return false;
	}
	if (dlg.timeout) {
		clearTimeout(dlg.timeout);
	}
	var el = dlg.activeDiv;
	var target = Dialog.getTargetElement(ev);
	if (!el) {
	    el=document.getElementById("dvTitle_" + dlg.name);
	    if(target.navtype==200){//button close
	        Dialog.cellClick(el.parentNode, ev);
		}
	}else{
	    ev || (ev = window.event);
	    if (target == el || target.parentNode == el) {
		    Dialog.cellClick(el, ev);
    	}
	}

	with (Dialog) {
		removeEvent(document, "mouseup", tableMouseUp);
		removeEvent(document, "mouseover", tableMouseOver);
		removeEvent(document, "mousemove", tableMouseOver);		
		//dlg._hideCombos();
		_dlg = null;
		return stopEvent(ev);
	}
	
};

Dialog.tableMouseOver = function (ev) {
	var dlg = Dialog._dlg;
	if (!dlg) {
		return;
	}
	var el = dlg.activeDiv;
	if (!el) {
		el=document.getElementById("dvTitle_" + dlg.name);
		dlg.activeDiv=el;
	}
	var target = Dialog.getTargetElement(ev);
	ev || (ev = window.event);
	if (el.navtype == 50 && target != el) {
		var pos = Dialog.getAbsolutePos(el);
		var w = el.offsetWidth;
		var x = ev.clientX;
		var dx;
		var decrease = true;
		if (x > pos.x + w) {
			dx = x - pos.x - w;
			decrease = false;
		} else
			dx = pos.x - x;

		if (dx < 0) dx = 0;
		var range = el._range;
		var current = el._current;
		var count = Math.floor(dx / 10) % range.length;
		for (var i = range.length; --i >= 0;)
			if (range[i] == current)
				break;
		while (count-- > 0)
			if (decrease) {
				if (--i < 0)
					i = range.length - 1;
			} else if ( ++i >= range.length )
				i = 0;
		var newval = range[i];
		el.innerHTML = newval;
	}
	return Dialog.stopEvent(ev);
};

Dialog.tableMouseDown = function (ev) {
	if (Dialog.getTargetElement(ev) == Dialog.getElement(ev)) {
		return Dialog.stopEvent(ev);
	}
};

Dialog.calDragIt = function (ev) {
    if(Dialog.is_ie6)
        return;
    
	var dlg = Dialog._dlg;
	if (!(dlg && dlg.dragging)) {
		return false;
	}
	var posX;
	var posY;
	if (Dialog.is_ie) {
	
		posY = window.event.clientY + document.body.scrollTop;
		posX = window.event.clientX + document.body.scrollLeft;
	} else {
		posX = ev.pageX;
		posY = ev.pageY;
	}
	dlg.hideShowCovered();
	if(document.getElementById("dlgdiv")!=null)
	document.getElementById("dlgdiv").className="dlgdiv";
	var st = dlg.element.style;
	st.left = (posX - dlg.xOffs) + "px";
	st.top = (posY - dlg.yOffs) + "px";
	return Dialog.stopEvent(ev);
};

Dialog.calDragEnd = function (ev) {
    if(Dialog.is_ie6)
        return;

	var dlg = Dialog._dlg;
	if (!dlg) {
		return false;
	}
	dlg.dragging = false;
	with (Dialog) {
		removeEvent(document, "mousemove", calDragIt);
		removeEvent(document, "mouseup", calDragEnd);
		tableMouseUp(ev);
	}	
	dlg.hideShowCovered();	
	
};

Dialog.titleMouseDown = function(ev) {
//SUALAI_SANG_CHUA TAI XONG,KEO DIALOG THI BI LOI
	var el = Dialog.getElement(ev);
	if(!el || el.dialog == null || el.dialog=="undefined") return;
	if(el.tagName.toLowerCase()=="font")
	    el=el.parentNode.parentNode;
	    //el=document.getElementById("dvTitle_" + this.name).parentNode;
	if (el.disabled) {
		return false;
	}
	var dlg = el.dialog;
	
	dlg.activeDiv = el;
	
	Dialog._dlg = dlg;
	if (el.navtype != 300) with (Dialog) {
		if (el.navtype == 50) {
			el._current = el.innerHTML;
			addEvent(document, "mousemove", tableMouseOver);
		} else
			addEvent(document, Dialog.is_ie5 ? "mousemove" : "mouseover", tableMouseOver);
		addEvent(document, "mouseup", tableMouseUp);
		
	} else if (dlg.isPopup) {
		dlg._dragStart(ev);
	}
		
	dlg.timeout = null;
	return Dialog.stopEvent(ev);
};

Dialog.titleMouseDblClick = function(ev) {
	Dialog.cellClick(Dialog.getElement(ev), ev || window.event);
	if (Dialog.is_ie) {
		document.selection.empty();
	}
};

Dialog.titleMouseOver = function(ev) {
	var el = Dialog.getElement(ev);
	if (Dialog.isRelated(el, ev) || Dialog._dlg || el.disabled) {
		return false;
	}
	return Dialog.stopEvent(ev);
};

Dialog.titleMouseOut = function(ev) {
	with (Dialog) {
		var el = getElement(ev);
		if (isRelated(el, ev) || _dlg || el.disabled)
			return false;
		return stopEvent(ev);
	}
};

Dialog.cellClick = function(el, ev) {
    var dlg = el.dialog;
    if(ev.srcElement.navtype*1  ==  200){
		dlg.callCloseHandler();
		//dlg.onClose();
    }
};
/**
 *  This function creates the dialog inside the given parent.
   Some properties need to be set before calling this function.
 */







Dialog.prototype.create = function () {
     
	if(this.create.arguments.length>0)
	{
		var oArg=this.create.arguments[0];
		if(oArg.name!=null)
		{
			this.name=oArg.name;
		}
		if(oArg.title!=null)
		{
			this.title=oArg.title;			
		}
		
		if(oArg.message!=null)
		{
			this.msg=oArg.message;
		}
		if(oArg.top!=null)
		{
			this.top=oArg.top;
		}
		
		if(oArg.left!=null)
		{
			this.left=oArg.left;
		}
		
		if(oArg.width!=null)
		{
			this.width=oArg.width;
		}
		if(oArg.bgclass!=null)
		{
			this.bgClass=oArg.bgclass ;
		}
		if(oArg.barclass!=null)
		{
			this.barClass=oArg.barclass;
		}
		
		// vhphuc: css for message box
		// Top
		if(oArg.TitleTopLeft_css!=null)
		{
			this.TitleTopLeft_css=oArg.TitleTopLeft_css;			
		}
		if(oArg.TitleTopCenter_css!=null)
		{
			this.TitleTopCenter_css=oArg.TitleTopCenter_css;			
		}
		if(oArg.TitleTopRight_css!=null)
		{
			this.TitleTopRight_css=oArg.TitleTopRight_css;			
		}
		// Middle
		if(oArg.TitleMiddleLeft_css!=null)
		{
			this.TitleMiddleLeft_css=oArg.TitleMiddleLeft_css;			
		}
		if(oArg.TitleMiddleCenter_css!=null)
		{
			this.TitleMiddleCenter_css=oArg.TitleMiddleCenter_css;			
		}
		if(oArg.TitleMiddleRight_css!=null)
		{
			this.TitleMiddleRight_css=oArg.TitleMiddleRight_css;			
		}
		// Bottom
		if(oArg.TitleBottomLeft_css!=null)
		{
			this.TitleBottomLeft_css=oArg.TitleBottomLeft_css;			
		}
		if(oArg.TitleBottomCenter1_css!=null)
		{
			this.TitleBottomCenter1_css=oArg.TitleBottomCenter1_css;			
		}
		if(oArg.TitleBottomCenter2_css!=null)
		{
			this.TitleBottomCenter2_css=oArg.TitleBottomCenter2_css;			
		}
		if(oArg.TitleBottomCenter3_css!=null)
		{
			this.TitleBottomCenter3_css=oArg.TitleBottomCenter3_css;			
		}
		if(oArg.TitleBottomRight_css!=null)
		{
			this.TitleBottomRight_css=oArg.TitleBottomRight_css;			
		}
		
    }
    
	var parent = null;
	parent = document.getElementsByTagName("body")[0];
	this.isPopup = true;
	
	var table = Dialog.createElement("table");
	this.table = table;
	table.cellSpacing = 0;
	table.cellPadding = 0;
	table.width="100%";
	table.border=0;
	table.dialog = this;
	Dialog.addEvent(table, "mousedown", Dialog.tableMouseDown);	
	var div = Dialog.createElement("div");
	div.id="dv" + this.name;
	div.name="dv" + this.name;
	div.style.zIndex=100;
	this.element = div;
	if (this.isPopup) {
		div.style.position = "absolute";
		div.style.width=this.width;
		//div.style.display = "none";
		div.style.visibility = "hidden";
	}
	div.appendChild(table);
	
	var thead = Dialog.createElement("thead", table);
	thead.style.width="100%";
	var cell = null;
	var row = null;

	var dlg = this;
	var hh = function (text, cs, navtype,barClass) {
		cell = Dialog.createElement("td", row);
		cell.colSpan = cs;
		cell.className = barClass;		
		
	    //cell.style.cursor = "move";
    	
		
		//if (navtype != 0 && Math.abs(navtype) <= 2)
		//	cell.className += " nav";
		
		cell.dialog = dlg;
		Dialog._add_evs(cell);		
		cell.navtype = navtype;
		//if(w>0) cell.width=w;
		//cell.unselectable='on';
		//var dvTitleId="dvTitle_" + dlg.name;
		//var imgCloseId="imgClose_" + dlg.name;
		cell.innerHTML = text;//"<div id='"+ dvTitleId +"' unselectable='on'>" + text + "</div>";
		//cell.innerHTML = "<div id='"+ dvTitleId +"' unselectable='on'><img id="+ imgCloseId +" navtype=200 align='right' width='14' height='14' style='cursor:pointer; MARGIN-RIGHT:2px; MARGIN-TOP: 3px' src='images/close.gif' title='Close' onclick='" + dlg.onClose + "' /><font class='"+ barClass +"'>&nbsp;" + text + "</font></div>";		
		//cell.childNodes[0].childNodes[0].dialog=dlg;		
		return cell;
	};
	
	/*  Top */
	row = Dialog.createElement("tr", thead);

	var title_length = 1;
	//(this.isPopup) && --title_length;
	hh("", 1, 400,this.TitleTopLeft_css).width="6px";

	var dvTitleId="dvTitle_" + dlg.name;
	var imgCloseId="imgClose_" + dlg.name;
	//cell.innerHTML = "<div id='"+ dvTitleId +"' unselectable='on'>" + text + "</div>";
	//Phuong add statrt---------------
	var tt;
	if(this.barClass != "cht_smile_bar")
	    tt= "<div  id='"+ dvTitleId +"' unselectable='on'><img id="+ imgCloseId +" navtype=200 align='right' width='14' height='14' style='cursor:pointer; MARGIN-RIGHT:2px; MARGIN-TOP: 3px' src='App_Themes/Normal/Images/dialog/close.gif' title='Close' onclick='" + this.onClose + "' /><font class='"+ this.barClass +"'>&nbsp;" + this.title + "</font></div>";		
	else
	    tt= "<div  id='"+ dvTitleId +"' unselectable='on'></div>";
	//Phuong add end---------------
	
	
	this.title = hh(tt, title_length, 300,this.TitleTopCenter_css);
//	this.title.className = this.barClass;
	if (this.isPopup) {
		this.title.style.cursor = "move";
	}
    hh("", 1, 400,this.TitleTopRight_css).width="8px";	
	
	
	/*  Middle  */
	row = Dialog.createElement("tr", thead);	
	row.style.width="100%";
	hh("", 1, 400,this.TitleMiddleLeft_css).width="5px";
	
	cell = Dialog.createElement("td", row);
	cell.className = this.TitleMiddleCenter_css;
	cell.colSpan=1;//5
	cell.innerHTML = this.msg;
	
	hh("", 1, 400,this.TitleMiddleRight_css).width="5px";
	

	/*  Bottom */
//	var _div = Dialog.createElement("div");
//	_div.style.width=this.width-24;
    row = Dialog.createElement("tr", thead);
	hh("", 1, 400,this.TitleBottomLeft_css).width="5px";
	
	cell = Dialog.createElement("td", row);
	var _table=Dialog.createElement("table", cell);
	
	_table.cellSpacing = 0;
	_table.cellPadding = 0;
	_table.width="100%";
	_table.border=0;	
	var _thead = Dialog.createElement("thead", _table);
	_thead.style.width="100%";
	var _row=Dialog.createElement("tr", _thead);
	var _cell=Dialog.createElement("td", _row);
	
	_cell.className=this.TitleBottomCenter1_css;
	_cell.colSpan=1;
	
	_cell=Dialog.createElement("td", _row);	
	_cell.className=this.TitleBottomCenter2_css;
	_cell.colSpan=1;
    _cell.innerHTML="";
    _cell.style.cursor = "move";
	_cell.dialog = dlg;
	Dialog._add_evs(_cell);		
	_cell.navtype = 300;
		

	_cell=Dialog.createElement("td", _row);
	_cell.className=this.TitleBottomCenter3_css;
	_cell.colSpan=1;
    _cell.innerHTML="";

	hh("", 1, 400,this.TitleBottomRight_css).width="14px";
		
	var tbody = Dialog.createElement("tbody", table);
	this.tbody = tbody;
	
	parent.appendChild(this.element);
};	














 
 /*
Dialog.prototype.create = function () {
     
	if(this.create.arguments.length>0)
	{
		var oArg=this.create.arguments[0];
		if(oArg.name!=null)
		{
			this.name=oArg.name;
		}
		if(oArg.title!=null)
		{
			this.title=oArg.title;			
		}
		
		if(oArg.message!=null)
		{
			this.msg=oArg.message;
		}
		if(oArg.top!=null)
		{
			this.top=oArg.top;
		}
		
		if(oArg.left!=null)
		{
			this.left=oArg.left;
		}
		
		if(oArg.width!=null)
		{
			this.width=oArg.width;
		}
		if(oArg.bgclass!=null)
		{
			this.bgClass=oArg.bgclass ;
		}
		if(oArg.barclass!=null)
		{
			this.barClass=oArg.barclass;
		}
		
    }
    
	var parent = null;
	parent = document.getElementsByTagName("body")[0];
	this.isPopup = true;
	
	var table = Dialog.createElement("table");
	this.table = table;
	table.cellSpacing = 0;
	table.cellPadding = 1;
	table.dialog = this;
	Dialog.addEvent(table, "mousedown", Dialog.tableMouseDown);	
	var div = Dialog.createElement("div");
	div.id="dv" + this.name;
	div.name="dv" + this.name;
	div.style.zIndex=100;
	this.element = div;
	if (this.isPopup) {
		div.style.position = "absolute";
		div.style.width=this.width;
		//div.style.display = "none";
		div.style.visibility = "hidden";
	}
	div.appendChild(table);
	
	var thead = Dialog.createElement("thead", table);
	var cell = null;
	var row = null;

	var dlg = this;
	var hh = function (text, cs, navtype,barClass) {
		cell = Dialog.createElement("td", row);
		cell.colSpan = cs;
		cell.className = barClass;
		
		if (navtype != 0 && Math.abs(navtype) <= 2)
			cell.className += " nav";
		
		cell.dialog = dlg;
		Dialog._add_evs(cell);		
		cell.navtype = navtype;
		cell.unselectable='on';
		var dvTitleId="dvTitle_" + dlg.name;
		var imgCloseId="imgClose_" + dlg.name;
		
		cell.innerHTML = "<div id='"+ dvTitleId +"' unselectable='on'><img id="+ imgCloseId +" navtype=200 align='right' width='14' height='14' style='cursor:pointer; MARGIN-RIGHT:2px; MARGIN-TOP: 3px' src='images/mtd/close.gif' title='Close' onclick='" + dlg.onClose + "' /><font class='"+ barClass +"'>&nbsp;" + text + "</font></div>";		
		cell.childNodes[0].childNodes[0].dialog=dlg;		
		return cell;
	};
	
	row = Dialog.createElement("tr", thead);
	
	var title_length = 6;
	(this.isPopup) && --title_length;
	this.title = hh(this.title, title_length, 300,this.barClass);
	this.title.className = this.barClass;
	if (this.isPopup) {
		this.title.style.cursor = "move";
	}
	//alert(this.title.innerHTML);
	row = Dialog.createElement("tr", thead);
	row.className = this.bgClass;
	cell = Dialog.createElement("td", row);
	cell.className = this.barClass;
	cell.colSpan=5;
	cell.innerHTML = this.msg;
	
	var tbody = Dialog.createElement("tbody", table);
	this.tbody = tbody;
	
	parent.appendChild(this.element);

};

*/


/** Calls the second user handler (closeHandler). */
Dialog.prototype.callCloseHandler = function () {
	/*
	if (this.onClose) {
		this.onClose(this);
	}
	this.hideShowCovered();
	*/
	this.hide();
	
};

/** Removes the dialog object from the DOM tree and destroys it. */
Dialog.prototype.destroy = function () {
	var el = this.element.parentNode;
	el.removeChild(this.element);
	Dialog._dlg = null;
};

/**
 *  Moves the dialog element to a different section in the DOM tree (changes
 *  its parent).
 */
Dialog.prototype.reparent = function (new_parent) {
	var el = this.element;
	el.parentNode.removeChild(el);
	new_parent.appendChild(el);
};

/** Shows the dialog. */
Dialog.prototype.show = function () {
    if(this.hidden == false) return;
    
    this.element.style.visibility='visible';
	//this.element.style.display = "";
	this.hidden = false;
	this.hideShowCovered();
};

/**
 *  Hides the Dialog.
 */
Dialog.prototype.hide = function () {
    if(this.hidden==true) return;
	//this.element.style.display = "none";
	this.element.style.visibility = "hidden";
	this.hidden = true;
	this.hideShowCovered();
	
	this.destroy();
};

/**
 *  Shows the Dialog at a given absolute position (beware that, depending on
 *  the Dialog element style -- position property -- this might be relative
 *  to the parent's containing rectangle).
 */
Dialog.prototype.showAt = function (x, y) {
	var s = this.element.style;
	s.left = x + "px";
	s.top = y + "px";
	this.show();	
};

/** Shows the Dialog near a given element. */
Dialog.prototype.showAtElement = function (el, opts) {
	var self = this;
	var p = Dialog.getAbsolutePos(el);
	if (!opts || typeof opts != "string") {
		this.showAt(p.x, p.y + el.offsetHeight);
		return true;
	}
	function fixPosition(box) {
		if (box.x < 0)
			box.x = 0;
		if (box.y < 0)
			box.y = 0;
		var cp = document.createElement("div");
		var s = cp.style;
		s.position = "absolute";
		s.right = s.bottom = s.width = s.height = "0px";
		document.body.appendChild(cp);
		var br = Dialog.getAbsolutePos(cp);		
		document.body.removeChild(cp);
		
		if (Dialog.is_ie) {
			br.y += document.body.scrollTop;
			br.x += document.body.scrollLeft;
		} else {
			br.y += window.scrollY;
			br.x += window.scrollX;
		}
		var tmp = box.x + box.width - br.x;
		if (tmp > 0) box.x -= tmp;
		tmp = box.y + box.height - br.y;
		if (tmp > 0) box.y -= tmp;
	};
	//this.element.style.display = "block";
	Dialog.continuation_for_the_fucking_khtml_browser = function() {
		var w = self.element.offsetWidth;
		var h = self.element.offsetHeight;
		//self.element.style.display = "none";
		var valign = opts.substr(0, 1);
		var halign = "l";
		if (opts.length > 1) {
			halign = opts.substr(1, 1);
		}
		// vertical alignment
		switch (valign) {
		    case "T": p.y -= h; break;
		    case "B": p.y += el.offsetHeight; break;
		    case "C": p.y += (el.offsetHeight - h) / 2; break;
		    case "t": p.y += el.offsetHeight - h; break;
		    case "b": break; // already there
		}
		// horizontal alignment
		switch (halign) {
		    case "L": p.x -= w; break;
		    case "R": p.x += el.offsetWidth; break;
		    case "C": p.x += (el.offsetWidth - w) / 2; break;
		    case "l": p.x += el.offsetWidth - w; break;
		    case "r": break; // already there
		}
		p.width = w;
		p.height = h + 40;
		//self.monthsCombo.style.display = "none";
		fixPosition(p);
		self.showAt(p.x, p.y);
	};
	if (Dialog.is_khtml)
		setTimeout("Dialog.continuation_for_the_fucking_khtml_browser()", 10);
	else
		Dialog.continuation_for_the_fucking_khtml_browser();
};

Dialog.prototype.hideShowCovered = function () {
    
	if (!Dialog.is_ie && !Dialog.is_opera)
		return;
	function getVisib(obj){
		var value = obj.style.visibility;
		if (!value) {
			if (document.defaultView && typeof (document.defaultView.getComputedStyle) == "function") { // Gecko, W3C
				if (!Dialog.is_khtml)
					value = document.defaultView.
						getComputedStyle(obj, "").getPropertyValue("visibility");
				else
					value = '';
			} else if (obj.currentStyle) { // IE
				value = obj.currentStyle.visibility;
			} else
				value = '';
		}
		return value;
	};

	//var tags = new Array("applet", "iframe", "select");
	var tags = new Array("applet", "select","object");
	var el = this.element;

	var p = Dialog.getAbsolutePos(el);
	var EX1 = p.x;
	var EX2 = el.offsetWidth + EX1;
	var EY1 = p.y;
	var EY2 = el.offsetHeight + EY1;

	for (var k = tags.length; k > 0; ) {
		var ar = document.getElementsByTagName(tags[--k]);
		var cc = null;

		for (var i = ar.length; i > 0;) {
			cc = ar[--i];
            if(!cc.allowuse){
			    p = Dialog.getAbsolutePos(cc);
			    var CX1 = p.x;
			    var CX2 = cc.offsetWidth + CX1;
			    var CY1 = p.y;
			    var CY2 = cc.offsetHeight + CY1;

			    if (this.hidden || (CX1 > EX2) || (CX2 < EX1) || (CY1 > EY2) || (CY2 < EY1)) {
				    if (!cc.__msh_save_visibility) {
					    cc.__msh_save_visibility = getVisib(cc);
				    }
				    cc.style.visibility = cc.__msh_save_visibility;
			    } else {
				    if (!cc.__msh_save_visibility) {
					    cc.__msh_save_visibility = getVisib(cc);
				    }
				    cc.style.visibility = "hidden";
			    }
			}
		}
	}
};

/** Internal function.  Starts dragging the element. */
Dialog.prototype._dragStart = function (ev) {
    if(Dialog.is_ie6)
        return;

	if (this.dragging) {
		return;
	}
	this.dragging = true;
	var posX;
	var posY;
	if (Dialog.is_ie) {
		posY = window.event.clientY + document.body.scrollTop;
		posX = window.event.clientX + document.body.scrollLeft;
	} else {	    	    
		posY = ev.clientY + window.scrollY;
		posX = ev.clientX + window.scrollX;		
	}
	var st = this.element.style;	
	this.xOffs = posX - parseInt(st.left);
	this.yOffs = posY - parseInt(st.top);	
	with (Dialog) {	
		addEvent(document, "mousemove", calDragIt);
		addEvent(document, "mouseup", calDragEnd);	
	}
	
};

/** Internal -- adds a set of events to make some element behave like a button. */
Dialog._add_evs = function(el) {

	with (Dialog) {
	
		addEvent(el, "mouseover", titleMouseOver);
		addEvent(el, "mousedown", titleMouseDown);
		addEvent(el, "mouseout", titleMouseOut);
		if (is_ie) {
			addEvent(el, "dblclick", titleMouseDblClick);
			el.setAttribute("unselectable", true);
		}
		
	}
};
