function byid(id){
	return document.getElementById(id);
}
function NSS_getPageSize() {
	var xScroll, yScroll;
// <![CDATA[ 		
	if (window.innerHeight && window.scrollMaxY) {
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else {
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth;
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}
	if(xScroll < windowWidth){
		pageWidth = xScroll;
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

function NSS_getPageScroll() {
	var xScroll, yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {	
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;
	}
	arrayPageScroll = new Array(xScroll,yScroll)
	return arrayPageScroll;
}

function alerta(mesaj,width,height) {
	NSS_win('alerta','',mesaj,width,height,true)
}
function close_alerta() {
	NSS_winClose('alerta');
}

function NSS_win(id,caption,mesaj,width,height,closebtn) {
	if (!byid('NSS_winover_'+id)) {
		var over_div=document.createElement('DIV');
		over_div.id='NSS_winover_'+id;
		over_div.className='NSS_winover';
		document.body.appendChild(over_div);
	}
	if (!byid('NSS_win_'+id)) {
		var alerta_div=document.createElement('DIV');
		alerta_div.id='NSS_win_'+id;
		alerta_div.className='NSS_win';
		document.body.appendChild(alerta_div);
	}
	if (width==null) width=360;
	if (height==null) height=200;
	var page_size=NSS_getPageSize();
	var over_div=byid('NSS_winover_'+id);
	var alerta_div=byid('NSS_win_'+id);
	over_div.style.display='block';
	over_div.style.width=page_size[0]+'px';
	over_div.style.height=page_size[1]+'px';
	over_div.NSS_win_id=id;
	over_div.onclick=function () {NSS_winClose(this.NSS_win_id);return false;};
	var page_scroll=NSS_getPageScroll();
	alerta_div.style.display='block';
	alerta_div.style.width=width+'px';
	alerta_div.style.left=(page_size[0]-width-20)/2+'px';
	var top_top=(page_size[3]-height)/2+page_scroll[1];
	if (top_top<1) top_top=1;
	alerta_div.style.top=top_top+'px';
	alerta_div.innerHTML=(caption?unescape('%3Cdiv%20class%3D%22NSS_win_caption%22%20style%3D%22width%3A')+(width-60)+unescape('px%3B%22%3E%3Cspan%3E')+caption+unescape('%3C/span%3E%3C/div%3E'):'')+unescape('%3Ca%20class%3D%22NSS_win_close%22%20href%3D%22%23%22%20onclick%3D%22NSS_winClose%28%27')+id+unescape('%27%29%3Breturn%20false%3B%22%3Ex%3C/a%3E%3Cdiv%20class%3D%22NSS_win_content%22%20id%3D%22NSS_win_content_')+id+'">'+mesaj+unescape('%3C/div%3E');
}

function NSS_winClose(id) {
	var over_div=byid('NSS_winover_'+id);
	var alerta_div=byid('NSS_win_'+id);
	over_div.parentNode.removeChild(over_div);
	alerta_div.parentNode.removeChild(alerta_div);
}
