var cache=new Array();





var cover = function(){}

cover.prototype.elementToCover = null;
cover.prototype.DIVCover = undefined;
cover.prototype.objToCenter = undefined;
cover.prototype.objByCenter = undefined;
cover.prototype.aboutObject = undefined;
cover.prototype.coverOnClickBlock = false;
cover.prototype.cls = 'cover';
cover.prototype.zIndex = 1;



cover.prototype.show = function(){
		this.DIVCover =document.createElement("div");
		if(typeof this.aboutObject == "undefined"){
			this.DIVCover.style.width="100%";
			this.DIVCover.style.height=this.getWindowSize().height+"%";
			this.DIVCover.style.position="fixed";
			this.DIVCover.style.top="0px";
			this.DIVCover.style.left="0px";
		}else{
			this.DIVCover.style.width=this.aboutObject.offsetWidth+"px";
			this.DIVCover.style.height=this.aboutObject.offsetHeight+"px";
			this.DIVCover.style.position="absolute";
			this.DIVCover.style.top=this.findPos(this.aboutObject).top+"px";
			this.DIVCover.style.left=this.findPos(this.aboutObject).left+"px";
		}
//		this.DIVCover.style.zIndex=this.zIndex;
			var i=cache.length;
			this.DIVCover.onclick = function(){
				if(cache[i].coverOnClickBlock == false){
					cache[i].hide();
				}
			};
			cache.push(this);

		this.DIVCover.className = this.cls;
		document.body.appendChild(this.DIVCover);
}

cover.prototype.hide = function(){
	var el = this.DIVCover;
	el.parentNode.removeChild(el);
	this.DIVCover = null;
	window.onresize = null;

	this.objToCenter.style.display = 'none';

	return true;
}





cover.prototype.getWindowSize = function () {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }

  return {width:myWidth,height:myHeight};
}


cover.prototype.setCenterByObject = function () {
	this.objToCenter.style.display="block";
	if(typeof this.objByCenter == "undefined"){
		var elementWidth = this.objToCenter.offsetWidth;
		var elementHeight = this.objToCenter.offsetHeight;
		var elementByWidth = this.getWindowSize().width;
		var elementByHeight = this.getWindowSize().height;
		var elementByLeft = elementByTop = 0;
		this.objToCenter.style.position="fixed";

		var i=cache.length;
		window.onresize = function(){
			cache[i].hide();
			cache[i].show();
			cache[i].setCenterByObject(cache[i].objToCenter);
		};
		cache.push(this);

	}else{
		var elementWidth = this.objToCenter.offsetWidth;
		var elementHeight = this.objToCenter.offsetHeight;
		var elementByWidth = this.objByCenter.offsetWidth;
		var elementByHeight = this.objByCenter.offsetHeight;
		var elementByLeft = this.findPos(this.objByCenter).left;
		var elementByTop = this.findPos(this.objByCenter).top;
		this.objToCenter.style.position="absolute";
	}
	this.objToCenter.style.top=(elementByTop+elementByHeight/2 - elementHeight/2)+"px";
	this.objToCenter.style.left=(elementByLeft+elementByWidth/2 - elementWidth/2)+"px";


return true;
}



cover.prototype.findPos = function(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
			} while (obj = obj.offsetParent);
	}
	return {left:curleft,top:curtop};
}






var mainWindowCover = null;
/*
window.onload = function(){
mainWindowCover = new cover();
mainWindowCover.show();
	alert(mainWindowCover);
mainWindowCover.objToCenter = document.getElementById('regDialog');
//mainWindowCover.objByCenter = document.getElementById('userError');
mainWindowCover.setCenterByObject();
}
*/
