


function Disquiter() {
	
	this.opacity=.75;
	this.overlay=true;
	this.img = '_js/img/zangenbansmann.jpg';
	this.img_width = 425;
	this.img_height = 280;
	
	this.init = function() {
		
		
		this.ck = new CookieManager();
		var cookie_val = this.ck.getValue('disquiter');
		if(!cookie_val) {
			cookie_val = 1;
		} else cookie_val++;
		this.ck.save('disquiter',cookie_val,1800,'/',false,false);
		var cookie_val = this.ck.getValue('disquiter');
		if(cookie_val > 3) return false;
		var bd = Ext.getBody();
		ww = this.getWindowWith();
		wh = this.getWindowHeight();
		st = this.docScrollTop();
		bodyheight = st+wh;		

	   this.overlay = Ext.DomHelper.append(document.body, {
			id: 'cover-disq'
		}, true);
		
		var viewSize = this.getViewSize();
		this.overlay.setStyle({
			width: viewSize[0] + 'px',
			height: viewSize[1] + 'px',
			position: 'absolute',
			top: 0,
			left: 0,
			zIndex: 9999,
			backgroundColor: '#000000',
			padding: 0,
			margin: 0,		
			display:'none'
		});	
		
		this.overlay.setOpacity(this.opacity);
		this.overlay.setStyle('display','block');
		
		
		var tpl = this.tpl();
		var bd = Ext.getBody();
		this.disquiter = bd.createChild({tag:"div", style:"display:none;position:absolute;z-index:10000;",id:'disquiter'});
		this.disquiter.insertHtml('beforeEnd',tpl);
		//this.disquiter = Ext.get('disquiter');
		var styles = {
			top: ((bodyheight/2) - (this.img_height/2) -50) + 'px',
			left: ((ww/2) - (this.img_width/2)) + 'px',
			display:'block',
			width:this.img_width,
			position:'absolute'
		};
		this.disquiter.setStyle(styles);
		
	}
	
	this.getWindowWith = function() {
		var w;
		
		if(window
			&& window.innerWidth
			&& window.innerWidth > 0
		) {
			w = window.innerWidth;
		} 
		else if(document
			&& document.documentElement
			&& document.documentElement.clientWidth
			&& document.documentElement.clientWidth > 0
		) {
			w = document.documentElement.clientWidth;
		}
		else if(document
			&& document.body
			&& document.body.clientWidth
			&& document.body.clientWidth > 0
		) {
			w = document.body.clientWidth;
		}

		return w;
	}

	this.getWindowHeight = function() {
		
		var h;
		
		if(window
			&& window.innerHeight
			&& window.innerHeight > 0
		) {
			h = window.innerHeight;
		} 
		else if(document
			&& document.documentElement
			&& document.documentElement.clientHeight
			&& document.documentElement.clientHeight > 0
		) {
			h = document.documentElement.clientHeight;
		} else if(document
			&& document.body
			&& document.body.clientHeight
			&& document.body.clientHeight > 0
		) {
			h = document.body.clientHeight;
		} else if(document
			&& document.body
			&& document.body.offsetHeight
			&& document.body.offsetHeight > 0
		) {
			h = document.body.offsetHeight;
		}
		
		return h;	
	}

    this.docScrollTop = function() {
      if ( window.pageYOffset ) {
         return window.pageYOffset;
      } else if ( document.documentElement && document.documentElement.scrollTop ) {
         return document.documentElement.scrollTop;
      } else if ( document.body ) {
         //alert(document.body.scrollTop);
        return document.body.scrollTop;
      } else {
         return 0;
   		}
   }
   
   this.close = function() {
   		this.disquiter = Ext.get('disquiter');
   		this.disquiter.setStyle('display','none');
   		var cover = Ext.get('cover-disq');
   		cover.setStyle('display','none');   	
   }	
   
   this.tpl = function() {
   	
   		var tpl = '';
   		//tpl += '<div id="disquiter" style="display:none;position:absolute;z-index:10000;">';
   		tpl += '<div class="close-disq" style="cursor:pointer;position:absolute;z-index:10001;right:-10px;top:-10px;"><img src="_js/img/closebox.png" id="closeimg-disq" onclick="DQ.close();" class="close-disq" /></div>';
   		tpl += '<img style="border:none;" border="0" usemap="#mail" src="'+this.img+'" width="'+this.img_width+'" height="'+this.img_height+'" />';
   		//tpl += '</div>';
   		tpl += '<map name="mail"><area shape="rect" coords="179,195,314,205" href="mailto:presse@zangen-bansmann.de" alt="E-Mail" title="E-Mail"></map>';
   		tpl += '';
   		
   		return tpl;
   	
   }

        this.getViewSize = function() {
            return [Ext.lib.Dom.getViewWidth(true), Ext.lib.Dom.getViewHeight(true)];
        }

	/*this.getViewSize = function() {
		//DebugDump(Ext.lib.Dom,'Ext.lib.Dom '+Ext.lib.Dom.getViewWidth(true)+' / '+Ext.lib.Dom.getDocumentWidth()+' / '+Ext.lib.Dom.getViewportWidth());
		//DebugDump(Ext.getBody(),'Ext.getBody() '+Ext.getBody().getWidth()+' / '+Ext.getBody().getX());
		// changed from Ext.lib.Dom.getViewWidth(true) to Ext.getBody().getWidth(), cause scrollbars are not included in getViewWidth
		var viewSize = [
			Math.max(Ext.lib.Dom.getViewWidth(), Ext.lib.Dom.getDocumentWidth()),
			Math.max(Ext.lib.Dom.getViewHeight(), Ext.lib.Dom.getDocumentHeight())
		];
		//return viewSize;
		return [Ext.getBody().getWidth(), Ext.lib.Dom.getViewHeight(true)];
	}*/
}

var DQ = new Disquiter();
//window.onload = DQ.init;

//---------------------------------------------------------------------------------------
function CookieManager(cookiename) { // safari doesn´t like to call this class Cookie...

	this.name = cookiename;

	//---------------------------------------------------------------------------------------
	this.save = function(cookiename,value,days_valid,path,domain,secure) {

		if (!cookiename) {
			cookiename = this.name;
		}
		
		var d = new Date();
		var d = new Date(d.getTime() +1000*60*60*24*days_valid); 
		//document.cookie = cookiename + '=' + escape(value) + ";expires=" + d.toGMTString()+';';

		document.cookie = cookiename + "=" + escape(value) +
			(";expires=" + d.toGMTString()) +
			((path) ? "; path=" + path : "") +
			((domain) ? "; domain=" + domain : "") +
			((secure) ? "; secure" : "");

	}

	//---------------------------------------------------------------------------------------
	this.getValue = function(cookiename) {
		
		//Get cookie code by Shelley Powers
		
		if (!cookiename) {
			cookiename = this.name;
		}
		
		var search = cookiename + "=";
		
		if (document.cookie.length > 0) {
			offset = document.cookie.indexOf(search);
			// if cookie exists
			if (offset != -1) { 
				offset += search.length;
				// set index of beginning of value
				end = document.cookie.indexOf(";", offset);
				// set index of end of cookie value
				if (end == -1) end = document.cookie.length;
				return parseInt(unescape(document.cookie.substring(offset, end)));
			}
		}
		return null;
	}	

	this.del = function(cookiename,path,domain) {

		if (!cookiename) {
			cookiename = this.name;
		}
		
		if(this.getValue(cookiename)) {
			document.cookie = cookiename + "=" +
			  ((path) ? "; path=" + path : "") +
			  ((domain) ? "; domain=" + domain : "") +
			  "; expires=Thu, 01-Jan-70 00:00:01 GMT";		
		}
		
	}

}
