var domain = 'http://pub.nyu-nyu.com/dhtmlv3/';
var popWidth = 540;
var popHeight = 445;
var now = new Date();
var months = ['janvier', 'fevrier', 'mars', 'avril', 'mai', 'juin', 'juillet', 'aout', 'septembre', 'octobre', 'novembre', 'decembre'];
var windowName = 'Promos du ' + now.getDate() + ' ' + months[now.getMonth()];

var css = 	'<style type="text/css">' +
				'#pnn_dhtml_hv3_bkg{' +
					'width: ' + popWidth + 'px; height: ' + popHeight + 'px; background: no-repeat url("' + domain + 'img/background.png"); position: absolute; z-index: 999999; top: 0; left: 0;' +
				'}' +			
				'#pnn_dhtml_hv3 {' +
					'width: ' + popWidth + 'px; height: ' + popHeight + 'px;  position: absolute; z-index: 1000000; top: 0; left: 0;' +
				'}' +
				'#pnn_dhtml_hv3 * {' +
					'zoom: 100%; position: relative; z-index: 1;' +
				'}' +					
				'#pnn_dhtml_hv3 #pnn_dhtml_handle{' +
					'float: left; width: 470px; height: 22px; margin-top: 4px; text-indent: 15px; font: bold 18px/22px Arial; color: #000; cursor: move;' +
				'}' +				
				'#pnn_dhtml_hv3 #pnn_dhtml_close{' +
					'float: left; display: block; width: 57px; height: 20px; margin-top: 4px;' +
				'}' +
				'#pnn_dhtml_hv3 #pnn_dhtml_close span{' +
					'display: none;' +
				'}' +
				'#pnn_dhtml_hv3 #iframe{' +
					'margin: 68px 0 0 7px;' +
				'}' +
				'#pnn_dhtml_hv3 #iframe iframe{' +
					'border: 0; width: 526px; height: 370px;' +
				'}' +	
			'</style>';

var cookie = {
	SetCookie: function(name, value) {
		var argv=this.SetCookie.arguments;
		var argc=this.SetCookie.arguments.length;
		var expires=(argc > 2) ? argv[2] : null;
		var path=(argc > 3) ? argv[3] : null;
		var domain=(argc > 4) ? argv[4] : null;
		var secure=(argc > 5) ? argv[5] : false;
		document.cookie=name+"="+escape(value)+
			((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
			((path==null) ? "" : ("; path="+path))+
			((domain==null) ? "" : ("; domain="+domain))+
			((secure==true) ? "; secure" : "");
	},
	getCookieVal: function(offset) {
		var endstr=document.cookie.indexOf (";", offset);
		if (endstr==-1)
	      		endstr=document.cookie.length;
		return unescape(document.cookie.substring(offset, endstr));
	},
	GetCookie: function(name) {
		var arg=name+"=";
		var alen=arg.length;
		var clen=document.cookie.length;
		var i=0;
		while (i<clen) {
			var j=i+alen;
			if (document.cookie.substring(i, j)==arg)
	                        return this.getCookieVal (j);
	                i=document.cookie.indexOf(" ",i)+1;
	                        if (i==0) break;}
		return null;
	}
}

var dhtml = {
	init: function(elmnt) {
		this.popup = document.getElementById(elmnt);
		this.popup_bkg = document.getElementById(elmnt + '_bkg');
		this.addEvent(document.getElementById('pnn_dhtml_close'), dhtml.close, 'click');
		this.addEvent(document.getElementById('pnn_dhtml_handle'), dhtml.setDrag, 'mousedown');
		document.getElementById('pnn_dhtml_close').onclick = function() {return false;};
		window.onscroll = this.scroll;		
		this.center();
	},
	close: function() {
		dhtml.popup.style['display'] = 'none';
		dhtml.popup_bkg.style['display'] = 'none';
	},
	setDrag: function(e) {
		var e = window.event || e;
		dhtml.initMouseX = e.clientX;
		dhtml.initMouseY = e.clientY;
		dhtml.initX = dhtml.popup.offsetLeft;
		dhtml.initY = dhtml.popup.offsetTop;
		document.onmousemove = dhtml.move;
		document.onmouseup = function() {
			document.onmousemove = null;
			document.onmousedown = null;			
			dhtml.initX = dhtml.initY = dhtml.initMouseX = dhtml.initMouseY = 0;
		}
	},
	addEvent: function(target, functionref, tasktype){
		var tasktype=(window.addEventListener)? tasktype : "on"+tasktype;
		if (target.addEventListener) {
			target.addEventListener(tasktype, functionref, false);
		} else if (target.attachEvent) {
			target.attachEvent(tasktype, functionref);
		}
	},
	move: function(e) {		
		var e = window.event || e;
		dhtml.deltaX = e.clientX - dhtml.initMouseX;
		dhtml.deltaY = e.clientY - dhtml.initMouseY;
		dhtml.popup.style['top'] = dhtml.deltaY + dhtml.initY + 'px';
		dhtml.popup_bkg.style['top'] = dhtml.deltaY + dhtml.initY + 'px';
		dhtml.popup.style['left'] = dhtml.deltaX + dhtml.initX + 'px';
		dhtml.popup_bkg.style['left'] = dhtml.deltaX + dhtml.initX + 'px';			
		return false;		
	},
	center: function() {
		if (document.body.clientHeight) {
			y22 = document.body.clientHeight;			
			x22 = document.body.clientWidth;
		} else if (document.documentElement.clientHeight) {
			y22 = document.documentElement.clientHeight;
			x22 = document.documentElement.clientWidth;
		} else {
			y22 = window.outerHeight;
			x22 = window.outerWidth;
		}
		dhtml.popup.style['top'] = Math.round((y22-popHeight)/2) + 'px';
		dhtml.popup_bkg.style['top'] = Math.round((y22-popHeight)/2) + 'px';
		dhtml.popup.style['left'] = Math.round((x22-popWidth)/2) + 'px';
		dhtml.popup_bkg.style['left'] = Math.round((x22-popWidth)/2) + 'px';
	},
	scroll: function() {
		if (document.body.clientHeight) {
			var hauteur = document.body.scrollTop;
			var winHeight = document.body.clientHeight;
		} else if (document.documentElement.clientHeight) {
			var hauteur = document.documentElement.scrollTop;
			var winHeight = document.documentElement.clientHeight;
		} else {
			var hauteur = window.pageYOffset;
			var winHeight = window.innerHeight;
		}
		if(dhtml.popup.style['display'] != 'none') {		
			dhtml.popup.style['top'] = Math.round((winHeight-popHeight)/2) + hauteur + 'px';
			dhtml.popup_bkg.style['top'] = Math.round((winHeight-popHeight)/2) + hauteur + 'px';
		}
	}
}

if(cookie.GetCookie('deja1vu') !== "1") {
	document.write(css);
	document.write('<div id="pnn_dhtml_hv3_bkg"></div><div id="pnn_dhtml_hv3"><div id="pnn_dhtml_handle">' + windowName + '</div><a href="#" id="pnn_dhtml_close"><span>fermer</span></a><div id="iframe"><iframe src="' + domain + 'dhtml.php" frameborder="0" allowtransparency="1"></iframe></div></div>');
	dhtml.init('pnn_dhtml_hv3');
	cookie.SetCookie('deja1vu', "1");
	if (/MSIE (5\.5|6\.)/.test(navigator.userAgent)) {
		document.getElementById('pnn_dhtml_hv3_bkg').style['background'] = 'none';
		document.getElementById('pnn_dhtml_hv3_bkg').style['filter'] = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" +domain + "img/background.png', sizingMethod='scale')";
		document.getElementById('pnn_dhtml_hv3_bkg').style['z-index'] = 1;
	}
}