function Popup(cim,tartalom){

	this.ie  = document.all;
	this.nn6 = document.getElementById&&!document.all;
	this.userAgent = navigator.userAgent.toLowerCase();
	this.alpha = false;
	this.opacity = 0;
	this.scroll = true;
	this.x = 0;
	this.y = 0;
	this.x_obj = 0;
	this.y_obj = 0;
	this.droptag = null;
	this.droptag_iframe = document.getElementById("iframe_prompt");
	this.hatter = null;
	this.promtWidth = 440,
	this.promtHeight = 100;
	this.cim = cim;
	this.tartalom = tartalom;
	this.tx = 0;
	this.ty = 0;
}

Popup.prototype.open = function () {
	if(this.droptag == null){
		this.__create(this.promtWidth,this.promtHeight);
	}
	
	this.droptag.style.display = "block";
	var promptbekero = document.getElementById('promptbekero');
	var promptcim= document.getElementById('promptcim');
	
	promptcim.innerHTML = this.cim;
	promptbekero.innerHTML = this.tartalom;
	this.setPosition();
}

Popup.prototype.setPosition = function(){
	this.x_obj = this.promtWidth;
	this.y_obj = this.droptag.offsetHeight;
	var scrollpoz = this.getScrollPoz();
	this.x = (document.documentElement.clientWidth-this.x_obj)/2;
	this.y=( ((document.documentElement.clientHeight-this.y_obj)/2) + scrollpoz.y );
	this.droptag.style.top = String(this.y)+'px';
	this.droptag.style.left = String(this.x)+'px';
	if ( this.userAgent.indexOf("opera") < 0 && this.userAgent.indexOf("firefox") < 0 ) {
		this.droptag_iframe.style.width = String(this.droptag.offsetWidth)+'px';
		this.droptag_iframe.style.height = String(this.droptag.offsetHeight)+'px';
		this.droptag_iframe.style.left = this.droptag.style.left;
		this.droptag_iframe.style.top = this.droptag.style.top;
		this.droptag_iframe.style.display = "block";
	}
	if ( !this.scroll ) {
		document.documentElement.style.overflow = 'hidden';
	}
	if ( document.body.parentNode != null && document.getElementById('hatter') != null && this.alpha ) {
		if ( this.hatter.style.opacity != null || this.hatter.style.filter != null ) {
			this.hatter.style.display = "block";
			this.hatter.style.width = String(document.documentElement.clientWidth)+'px';
			this.hatter.style.height = String(document.documentElement.clientHeight)+'px';
		}
	}
}

Popup.prototype.loadContent = function(content){
	this.tartalom = content;
	document.getElementById('promptbekero').innerHTML = this.tartalom;
	//meretezes
	var prompt = document.getElementById('prompt');
	var drList = document.getElementById('drList');
	//alert(prompt+" "+drList);
	if(prompt && drList){
		//alert(drList.offsetWidth);
		prompt.style.width = String(drList.offsetWidth+20)+'px';
	}
	this.setPosition();
}	

Popup.prototype.refreshContent = function(){
	document.getElementById('promptbekero').innerHTML = this.tartalom;
}

Popup.prototype.loadTitle = function(title){
	this.cim = title;
	document.getElementById('promptcim').innerHTML = this.cim;
}	

Popup.prototype.refreshTitle = function(){
	document.getElementById('promptcim').innerHTML = this.cim;
}

Popup.prototype.removeContent = function(){
	document.getElementById('promptcim').innerHTML = '';
}

Popup.prototype.close = function () {
	this.removeContent();
	this.droptag.style.display = "none";
	if ( this.userAgent.indexOf("opera") < 0 && this.userAgent.indexOf("firefox") < 0 ) {
		this.droptag_iframe.style.display = "none";
	}
	if ( document.body.parentNode != null && document.getElementById('hatter') != null && this.alpha ) {
		this.hatter.style.display = "none";
	}
	if ( !this.scroll ) {
		if ( this.userAgent.indexOf("opera") >= 0 ) {
			document.documentElement.style.overflow = 'auto';
		} else {
			document.documentElement.style.overflow = '';
		}
	}
}
	
Popup.prototype.__create = function(width,height){
	var body = document.body;
	var pup = document.createElement('div');
	var puptartalom = this.__createPopup(this.title,this.tartalom);
	pup.appendChild(puptartalom);
	var pupBackground = document.createElement('div');
	var pupIframe = document.createElement('iframe');
	
	pup.id = 'prompt';
	pup.style.position = 'absolute';
	pup.style.display = 'none';
	pup.style.width = width+'px';
	pup.style.height = height+'px';
	pup.style.zIndex = 1000;
	pup.style.padding = '0px';
	pup.style.filter = 'shadow(color:gray strength:2, direction:135)';
	
	pupBackground.id = 'hatter';
	pupBackground.style.position = 'absolute';
	pupBackground.style.top = '0px';
	pupBackground.style.left = '0px';
	pupBackground.style.zIndex = 998;
	/*pupBackground.style.opacity = Number(this.opacity / 100);
	pupBackground.style.mozOpacity = Number(this.opacity / 100);
	pupBackground.style.khtmlOpacity = Number(this.opacity / 100);
	pupBackground.style.filter = 'alpha(opacity='+String(this.opacity)+')';
	pupBackground.style.backgroundColor = '#000000';*/
	
	pupIframe.id = 'iframe_prompt';
	pupIframe.src = 'javascript:false';
	pupIframe.style.zIndex = 999; 
	pupIframe.style.width = width+'px';
	pupIframe.style.display = 'none'; 
	pupIframe.style.position = 'absolute';
	
	body.appendChild(pupIframe);
	body.appendChild(pupBackground);
	body.appendChild(pup);
	
	this.droptag_iframe = document.getElementById('iframe_prompt');
	this.droptag = document.getElementById('prompt');
	this.hatter = document.getElementById('hatter');
	this.__setEventListener();
}
	
Popup.prototype.__createPopup = function(title,tartalom){
	//maga a tabla
	var p = document.createElement('table');
	p.style.width = '100%';
	p.style.height = '100%';
	p.className = 'popup';
	p.style.border = '1px solid #666666';
	var tbody = p.appendChild(document.createElement('tbody'));
	//elsosor a cim
	var trElso = tbody.appendChild(document.createElement('tr'));
	var tdElso = trElso.appendChild(document.createElement('td'));
	tdElso.id = 'promptmover';
	tdElso.className = 'popupTitle';
	tdElso.style.height = '20px';
	tdElso.style.cursor = 'move';
	tdElso.borderBottom = '1px solid #666666';
	
	var titleTable = tdElso.appendChild(document.createElement('table'));
	var titleTbody = titleTable.appendChild(document.createElement('tbody'));
	titleTable.style.width = '100%';
	titleTable.style.border = '0px';
	var titleTr = titleTbody.appendChild(document.createElement('tr'));
	var titleElsoTd = titleTr.appendChild(document.createElement('td'));
	var titleMasodikTd = titleTr.appendChild(document.createElement('td'));
	var titleBezaroGomb = titleMasodikTd.appendChild(document.createElement('img'));
	
	titleElsoTd.id = 'promptcim';
	titleElsoTd.style.color = '#FFFFFF';
	
	titleElsoTd.style.fontWeight = 'bold';
	titleElsoTd.style.textAlign = 'center';
	titleElsoTd.style.verticalAlign = 'middle';
	
	titleMasodikTd.style.width = '20px';
	
	titleBezaroGomb.src = 'http://pba.hu/images/common/x.gif';
	titleBezaroGomb.id = 'closegif';
	titleBezaroGomb.style.cursor = 'pointer';
	
	//masodik sor a tartalomresz
	var trMasodik = tbody.appendChild(document.createElement('tr'));
	var tdMasodik = trMasodik.appendChild(document.createElement('td'));
	tdMasodik.id = 'promptbekero';
	return p;
}
	
Popup.prototype.getScrollPoz = function () {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return {
		x:scrOfX,
		y:scrOfY
  };
}
	
Popup.prototype.helyez = function () {
	var scrollpoz = this.getScrollPoz();
	if (this.droptag.style.display == "block") {
		this.y = ( ((document.documentElement.clientHeight-this.y_obj)/2) + scrollpoz.y );
		this.droptag.style.top = String( this.y )+'px';
	}
	if ( this.hatter != null && this.alpha ) {
		this.hatter.style.top = String(scrollpoz.y)+'px';
	}
	if (this.droptag_iframe.style.display == "block") {
		if ( this.userAgent.indexOf("opera") < 0 && this.userAgent.indexOf("firefox") < 0 ) {
			this.droptag_iframe.style.top = this.droptag.style.top;
		}
	}
}
	
Popup.prototype.movemouse = function (e) {
	if(!this.nn6){
    	e = event;
    }
    
  	var scrollpoz = this.getScrollPoz();
    leftx = this.tx + e.clientX - this.x;
    topy  = this.ty + e.clientY - this.y;
	this.droptag.style.left = String( Math.min (Math.max(leftx, scrollpoz.x), (document.documentElement.clientWidth - this.droptag.offsetWidth) )) +'px';
	this.droptag.style.top = String( Math.min (Math.max(topy, scrollpoz.y), (document.documentElement.clientHeight - this.droptag.offsetHeight + scrollpoz.y) )) +'px';
	if ( this.userAgent.indexOf("opera") < 0 && this.userAgent.indexOf("firefox") < 0 ) {
		this.droptag_iframe.style.left = this.droptag.style.left;
		this.droptag_iframe.style.top = this.droptag.style.top;
	}
}
	
Popup.prototype.selectmouse = function (e) {
	var myThis = this;
    if(!this.nn6){
    	e = event;
    }
    
    this.tx = parseInt(this.droptag.style.left+0);
    this.ty = parseInt(this.droptag.style.top+0);
    this.x = e.clientX;
    this.y = e.clientY;
    document.onmousemove = function(e){
		myThis.movemouse(e);
	}
	document.onmouseup = function() { 
		document.onmousemove = null;
	}
}

Popup.prototype.setAlpha = function(opacity){
	this.alpha = true;
	this.opacity = opacity;
}

Popup.prototype.setScroll = function(scroll){
	this.scroll = scroll;
}
	
Popup.prototype.__setEventListener = function(){
	var myThis = this;
	var myElem = document.getElementById('promptmover');
	myElem.onmousedown= function(e){
		myThis.selectmouse(e);
	}
	document.getElementById('closegif').onclick = function(){
		myThis.close();
	}
	window.onscroll = function() {
		myThis.helyez();
	}
}

