var allPopups = new Array();


var iPopup = function(_w,_h){
		if (!_w) _w = 90;
		if (!_h) _h = 200;
		this.x									= 0;
		this.y									= 0;
		this.width							= _w;
		this._defWidth					=_w;
		this.height							= _h;
		this._defHeight					=_h;
		this._pop							= null;
		this.show							= ipop_show;
		this.hide								= ipop_hide;
		this.visible							= false;
		this.linkedObject				= null;
		this._drawObject				= ipop_draw;
		this.setClassName			=ipop_setclassname;
		this.setContent					=ipop_setcontent;
		this.getContent					=ipop_getcontent;
		this.htmlContent				="";
		this.showLoading				=ipop_showLoading;
		this.setScrolling						=ipop_scrolling;
		this._scrolls					=false;
		this.setAutosize			=ipop_autosize;
		this._autosize				=false;
		this.move						=ipop_move;
		this.resize						=ipop_resize;
		this.scrolling					=ipop_onscrolling;
		this._timeoutscrolling =ipop_timeoutscrolling;
		this.objIndex					=allPopups.length;
		this.items						=new Array();
		this.selectedRow			=null;
		this.trigger					=null;

		allPopups[allPopups.length] = this;
}


function ipop_onscrolling(rowNo){
}

function ipop_show(left,top){
	
	if (typeof(top) == "object"){
		this.trigger = top;
	}	

	if(typeof(left) == "object"){
		this.linkedObject = left;
		left = i_getLeft(this.linkedObject);
		top = i_getTop(this.linkedObject)+parseInt(this.linkedObject.offsetHeight)-i_getDocScroll(SCROLL_TOP);
	}

	


	left =parseInt(left);
	top = parseInt(top)-5;

	this.x = left;
	this.y = top;
		
	if (this._pop == null){
		this._drawObject();
	}
	
	this._pop.style.visibility = "visible";
	this._pop.style.left = this.x+"px";
	this._pop.style.top = this.y+"px";
	this.visible = true;
	
	var _defwidth = this.x+this.width;
	var _defheight = this.y + this.height;
	
	if (_defwidth > i_getDocWidth()){
			this._pop.style.left = (i_getDocWidth()-this.width-20) + "px";
	}
	if (_defheight > i_getDocWidth()){
			this._pop.style.top = (i_getDocHeight()-this.height-20) + "px";
	}
	this.setScrolling(this._scrolls);

		if (this._autosize){
				var _container = this._pop.childNodes[4];
				if (parseInt(_container.scrollWidth)>parseInt(_container.style.width)){
					this.width = _container.scrollWidth+20;
					this._drawObject(true);
					this.setScrolling(this._scrolls);
				}
				
		}

}


function ipop_hide(){
	try{
	this._pop.style.visibility = "hidden";
	this.visible = false;
	}catch(E){
		
	}
}

function ipop_draw(redraw){
		var _pop = null;	
		if (redraw){
			_pop = this._pop;
			this.htmlContent = this.getContent();
		}else{
			_pop =document.createElement("DIV");
			_pop.style.position = "absolute";
		}

		if (this._className == null){
			_pop.style.border = "none";
			var _dis = "none";
			if (this._loading) _dis = "block";
			 _pop.innerHTML = "<div style='background-image:url(/images/shadow.png);width:"+(parseInt(this.width)-7)+"px;height:"+(parseInt(this.height)-7)+"px;float:left;'></div>"+
						"<div style='background-image:url(/images/shadow.png);background-position:right top;background-repeat:no-repeat;width:7px;height:"+(parseInt(this.height)-7)+"px;float:right'></div>"+
						"<div style='background-image:url(/images/shadow.png);float:left;background-position:left bottom;background-repeat:no-repeat;width:"+(parseInt(this.width)-7)+"px;height:7px;'></div>"+
						"<div style='background-image:url(/images/shadow.png);float:right;background-position:right bottom;background-repeat:no-repeat;width:7px;height:7px;'></div>"+
						"<div style='background-color:white;z-index:3000;position:absolute;left:3px;top:3px;width:"+(parseInt(this.width)-6)+"px;height:"+(parseInt(this.height)-8)+"px;'></div>"+
						"<div style='background-color:transparent;background-image:url(/images/75white.png);z-index:3000;position:absolute;left:4px;top:4px;width:"+(parseInt(this.width)-8)+"px;height:"+(parseInt(this.height)-8)+"px;display:"+_dis+";'><table class='simple_table' width='100%' height='100%'><tr><td align='center' valign='middle'><img src='/images/spinner.gif'/></td></tr></table></div>";
		}
		

		_pop.style.left = this.x+"px"; _pop.style.top = this.y+"px"; _pop.style.width = this.width+"px"; _pop.style.height = this.height+"px";
		if (!redraw){
				_pop.style.zIndex = 10000;
				_pop.style.visibility = "hidden";
				document.body.appendChild(_pop);
				_pop.className = this._className;
				this._pop = _pop;
		}

		if (this.htmlContent.length > 0){
			this.setContent(this.htmlContent);
		}
		

	}

function ipop_move(newl,newt){
	this._pop.style.left = newl+"px";
	this._pop.style.top = newt + "px";
	this.left = newl;
	this.top = newt;
}

function ipop_resize(neww,newh){
	this._pop.childNodes[0].style.width = (neww-7)+"px";
	this._pop.childNodes[0].style.height = (newh-7)+"px";
	this._pop.childNodes[1].style.height = (newh-7)+"px";
	this._pop.childNodes[2].style.width = (neww-7)+"px";
	this._pop.childNodes[4].style.width = (neww-8)+"px";
	this._pop.childNodes[4].style.height = (newh-8)+"px";
	this._pop.childNodes[5].style.width = (neww-8)+"px";
	this._pop.childNodes[5].style.height = (newh-8)+"px";
	this._pop.style.width = neww+"px";
	this._pop.style.height = newh+"px";
	this.width = neww;
	this.height = newh;
}

function ipop_setclassname(cn){
		this._className = cn;
}


function ipop_setcontent(html){
	this.htmlContent = html;
	
	var myobj = this;

	if (this._pop){
		var _myinner = this._pop.childNodes[4];
		_myinner.innerHTML = this.htmlContent;
		_myinner.onscroll = function(){
			if (myobj._timer){
				window.clearTimeout(myobj._timer);
			}
			myobj._scrollingValue  =this.scrollTop;
			myobj._timer = window.setTimeout("ipop_timeoutscrolling("+myobj.objIndex+")",40);
			
		}
	}
}

function ipop_getcontent(html){
	if (this._pop){
		var _myinner = this._pop.childNodes[4];
		 return _myinner.innerHTML;
	}
	return null;
}

function ipop_timeoutscrolling(index){
	var myobj = allPopups[index];
	myobj.scrolling(myobj._scrollingValue);
}

function ipop_scrolling(scrolls){
	this._scrolls = scrolls;
	if (this._pop){
	if (scrolls == true){
			var _myinner = this._pop.childNodes[4];
			_myinner.style.overflowY = "auto";
			_myinner.style.overflowX = "hidden";
		}else{
			var _myinner = this._pop.childNodes[4];
			_myinner.style.overflow = "hidden";
		}
	}
}


function ipop_showLoading(l){
	
	if (this._pop){
			if (l == true){
					this._pop.childNodes[5].style.display = "block";
			}else{
				this._pop.childNodes[5].style.display = "none";
			}
	}
	this._loading = l;
}

function ipop_autosize(asize){
	this._autosize = asize;
}
