
function SubPage(name,url){
	this.name=name;
	this.spDelay=10;
	this.spDiff=(navigator.userAgent.toLowerCase().indexOf("msie",0)>=0)?10:5;
	this.spopacity=0;
	this.url=(url)?url:"inc/showData.php";
	this.xmlHttp=null;

	this.init=function(){
		var spbg,sp;

		if(this.isIE()) spbg=document.createElement('<div id="subpage_bg" onclick="'+this.name+'.hide();">');
		else {
			spbg=document.createElement('div');
			spbg.setAttribute('id','subpage_bg');
			spbg.setAttribute('onclick',this.name+'.hide();');
		}
		spbg.innerHTML       ="";
		spbg.style.display   = "none";
		spbg.style.position  = "absolute";
		spbg.style.width     = "100%";
		spbg.style.height    = "100%";
		spbg.style.top       = "0";
		spbg.style.left      = "0";
		spbg.style.background= "#C7A382";
		spbg.style.border    = "none";
		spbg.style.padding   = "0px";
		spbg.style.zIndex    = "99";
		spbg.style.overflow  = "auto";

		if(this.isIE()) sp=document.createElement('<div id="subpage" onclick="'+this.name+'.hide();">');
		else {
			sp=document.createElement('div');
			sp.setAttribute('id','subpage');
			sp.setAttribute('onclick',this.name+'.hide();');
		}
		sp.innerHTML       ="";
		sp.style.display   = "none";
		sp.style.position  = "absolute";
		sp.style.top       = "0px";
		sp.style.left      = "0px";
		sp.style.width     = "100%";
		sp.style.border    = "none";
		sp.style.padding   = "0px";
		sp.style.zIndex    = "100";
		sp.style.overflow  = "hidden";

		document.body.appendChild(spbg);
		document.body.appendChild(sp);

		document.subPage=this;
	}

	this.show=function(pg,par){
		this.showData(pg,par);
	}

	this.hide=function(){
		this.showOrHide("hide");
	}

	this.showOrHide=function(todo){
		var sp   = document.getElementById('subpage');
		var spbg = document.getElementById('subpage_bg')
		var winH;

		switch(todo){
		case "show":
			spbg.style.height=this.max(sp.offsetHeight,document.body.offsetHeight+20,window.innerHeight,document.documentElement.clientHeight)+'px';

			if(this.spopacity<100){
				spbg.style.display="block";
				sp.style.display="block";
				this.spopacity+=this.spDiff;
				if(this.spopacity<75) this.opacity('subpage_bg',this.spopacity);
				this.opacity('subpage',this.spopacity);
				setTimeout(this.name+'.showOrHide("show");',this.spDelay);
			}
			break;
		case "hide":
			if(this.spopacity>0){
				this.spopacity-=this.spDiff;
				if(this.spopacity<75) this.opacity('subpage_bg',this.spopacity);
				this.opacity('subpage',this.spopacity);
				setTimeout(this.name+'.showOrHide("hide");',this.spDelay);
			} else {
				sp.style.display="none";
				spbg.style.display="none";
			}
			break;
		}
	}

	this.opacity=function(element, value){
		if(typeof element=="string"){element=document.getElementById(element);}
		if(!element){return null}
		value=parseFloat(value);
		if(isNaN(value)){return null;}
		if(typeof element.style.opacity!="undefined"){
			if(value>1){value/=100;}
			element.style.opacity=value;
			return value;
		} else if(typeof element.style.filter!="undefined"){
			if(value<=1 && value>0){value*=100;}
			element.style.filter="alpha(opacity="+value+")";
			return value;
		}
		return null;
	}

	this.showData=function(pg,id){
		this.getXmlHttpObject();
		if (this.xmlHttp==null) {
			return;
		}

		var	url=this.url+"?pg="+pg+"&id="+id+"&rnd="+Math.random();
		this.xmlHttp.onreadystatechange=this.stateChanged;
		this.xmlHttp.open("GET",url,true);
		this.xmlHttp.send(null);
	}

	this.stateChanged=function(){
		if (document.subPage.xmlHttp.readyState==4){
			document.getElementById("subpage").innerHTML=document.subPage.xmlHttp.responseText;
			document.subPage.showOrHide("show");
		}
	}

	this.getXmlHttpObject=function(){
		try { this.xmlHttp=new XMLHttpRequest();
		} catch (e) {
			try { this.xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) { this.xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
		}
	}

	this.isIE=function(){
		return (this.strpos(navigator.userAgent.toLowerCase(),"msie",0)>0);
	}

	this.strpos=function( haystack, needle, offset){
	    var i = haystack.indexOf( needle, offset ); // returns -1
	    return i >= 0 ? i : false;
	}

	this.max=function(){
		var max=0;
		for (var i = 0; i < arguments.length; i++) if(arguments[i]>max) max=arguments[i];
		return max;
	}

	this.addInit(this.name);
}
