// JavaScript Document
var MyPopupClass = {
  create: function() {
    return function() {
      this.initialize.apply(this, arguments);
    }
  }
}

var IE_SaveContainer = null;
var IE_SaveContent = null;
var IE_SaveXmlhttp = null;
var MyPopup = MyPopupClass.create();

MyPopup.prototype = {
	initialize : function(varName,popContainer,popContent) {

		this.varName = varName;
		this.popContainer = popContainer;
		this.popContent = popContent;
		this.oldPopFile = null;

		document.getElementById(this.popContainer).style.display='none';

		this.xmlhttp=null
	},

	open : function(popFile)
	{

		if(this.oldPopFile == popFile)
		{
			this.close();
		}
		else
		{
			this.close();
			this.oldPopFile = popFile;

			if (window.ActiveXObject)
			{
				this.xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
				this.xmlhttp.onreadystatechange = this.IEhandleEvent;
				IE_SaveContainer = this.popContainer
				IE_SaveContent = this.popContent
				IE_SaveXmlhttp = this.xmlhttp;
			}
			else
			{
				this.xmlhttp=new XMLHttpRequest()
				this.xmlhttp.onreadystatechange = this;
			}

			if (this.xmlhttp!=null)
			{
				if(popFile.indexOf('?')>0)
					this.xmlhttp.open("GET",popFile+'&'+(Math.random()*1000),true);
				else
					this.xmlhttp.open("GET",popFile+'?'+(Math.random()*1000),true);
				this.xmlhttp.send(null);
			}
		}
	},
	close : function()
	{
		this.oldPopFile = null;
		document.getElementById(this.popContainer).style.display='none';
	},

	IEhandleEvent : function()
	{
		if (IE_SaveXmlhttp.readyState==4)
		{
			// if "OK"
			if (IE_SaveXmlhttp.status==200)
			{
				document.getElementById(IE_SaveContent).innerHTML=IE_SaveXmlhttp.responseText
				document.getElementById(IE_SaveContainer).style.display='';
				document.getElementById("parereaClientilor").style.display = "none";
				//aIfrPopup();
			}
		}
	},

	handleEvent : function()
	{
		// if xmlhttp shows "loaded"
		if (this.xmlhttp.readyState==4)
		{
			// if "OK"
			if (this.xmlhttp.status==200)
			{
				document.getElementById(this.popContent).innerHTML=this.xmlhttp.responseText
				document.getElementById(this.popContainer).style.display='';
				document.getElementById("parereaClientilor").style.display = "none";
				//aIfrPopup();
			}
			else
			{
				alert("Problem retrieving data:" + this.xmlhttp.statusText)
			}
		}
	}
}

