var msgbox = document.getElementById("alertdiv");
var coverbox = document.getElementById("coverdiv");
var resizeInterval="";

function pageWidth() {return window.innerWidth || document.body.clientWidth;}
function pageHeight() {return self.innerHeight || document.height || window.innerHeight || document.body.clientHeight;} 
function pageOffsetY() {return window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;}

var Client = {
	viewportWidth: function() {
		return self.innerWidth || (document.documentElement.clientWidth || document.body.clientWidth);
	},
	viewportHeight: function() {
		return self.innerHeight || (document.documentElement.clientHeight || document.body.clientHeight);
	}
};
function getPageSizeWithScroll(){
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}
	return new Array(xWithScroll,yWithScroll);
}




function SizeCoverBox(){
	v1=getPageSizeWithScroll()[1];
	v2=Client.viewportHeight();
	if(v1<v2){
		coverbox.style.height=v2 +'px';
	}else{
		coverbox.style.height=v1 +'px';
	}
	center(msgbox);
}

function center(object){
	object.style.top=parseInt(Client.viewportHeight()/2-msgbox.offsetHeight/2+pageOffsetY())+"px";
	object.style.left=parseInt(Client.viewportWidth()/2-msgbox.offsetWidth/2)+"px";
}
function msgBox(message,msgid){
	closealert="<table><tr><td><b>New message from the webmaster</b></td><td align=right><a href='#' onclick='closeMsgBox(\""+msgid+"\");return false;'>Close</a></td></tr></table><hr style='border: 1px #AAAAAA solid'>";
	showMsgBox(closealert+message);
}
function showMsgBox(message){
	SizeCoverBox();
	resizeInterval=setInterval("SizeCoverBox();",200);
	msgbox.innerHTML="<img src='http://img.lynxy.com/imgs/logo/gnome3_75.png' style='float:left;position:relative;left:-5px;top:-5px;'>"+message;
	coverbox.style.display = 'block';
	msgbox.style.display="block";
	
	center(msgbox);
	setTimeout("center(msgbox);",20);
	setTimeout("center(msgbox);",100);
}
function closeMsgBox(msgid){
	hideMsgBox(resizeInterval);
	ajaxpack.getAjaxRequest("visitor_msg.php","delmsg="+msgid, dummySubAlert, "txt")
}
function hideMsgBox(){
	clearInterval(resizeInterval);
	coverbox.style.display="none";
	msgbox.style.display="none";
	msgbox.innerHTML='';
}
function dummySubAlert(){ }
