var nnk={};

nnk.box=function(){
	var u,w,h,cl, m,b,c, f=0;
	return {

//Parametry
	boxWidth : 30,
	boxHeight : 80,
	boxPadding : 10,
	boxBgcolor : "#ffffff",
	boxBorder : "5px solid #61a200",
	maskOpacity : 20,
	maskBgcolor : "#ffffff",


		show:function(u){
			if(!f){
				m=document.createElement('div'); m.id='mask'; document.body.appendChild(m);
				cl=document.createElement('a'); cl.id='cl'; cl.href='#close'; document.body.appendChild(cl);
				b=document.createElement('div'); b.id='box'; document.body.appendChild(b);
				m.onclick=nnk.box.hide;
				cl.onclick=nnk.box.hide;
				
				this.boxStyle('loading');
				this.getContent(u)
			}
		},

		boxStyle:function( st ){
			
		// for mask
			m.style.opacity=this.maskOpacity/100; m.style.filter='alpha(opacity='+this.maskOpacity+')';
			m.style.width = this.page(0)+'px'; 
			m.style.height = this.page(1)+'px';
			m.style.position = "absolute";
			m.style.display = "block";
			m.style.top = "0px";
			m.style.left = "0px";
			m.style.backgroundColor = this.maskBgcolor;
			m.style.zIndex = "1000";
			

			switch(st){

				case"loading":
				// For box
					b.style.position = "absolute";
					b.style.display = "block";
					b.style.top = "40%";
					b.style.left = "45%";
					b.style.width = "120px";
					b.style.height = "50px";
					b.style.padding = this.boxPadding + "px";
					b.style.margin = "0px";
					b.style.zIndex = m.style.zIndex+100;
					b.style.overflow = "auto";
					b.style.border = this.boxBorder;
					b.style.background = this.boxBgcolor+" url(\'/thumbs/wait.gif\') no-repeat 50% 50%";
					break;

				default:
					cl.style.top=((100-this.boxHeight)/2)+"%"
					cl.style.left=(((100-this.boxWidth)/2)+this.boxWidth)+"%";
					cl.style.display = "block";
					
				// For box
					b.style.position = "absolute";
					b.style.display = "block";
					b.style.top =  ((100-this.boxHeight)/2)+"%";
					b.style.left = ((100-this.boxWidth)/2)+"%";
					b.style.width = this.boxWidth + "%";
					b.style.height = this.boxHeight + "%";
					b.style.padding = this.boxPadding + "px";
					b.style.margin = "0px";
					b.style.zIndex = m.style.zIndex+100;
					b.style.overflow = "auto";
					b.style.border = this.boxBorder;
					b.style.background = this.boxBgcolor+" ";
					break;
			}
		},

		sendForm:function(oForm){
			var aParams = new Array();
			for(var i = 0; i < oForm.elements.length; i++) {
				if(oForm.elements[i].type == "checkbox"){
					if(!oForm.elements[i].checked) 
						continue;
				}
				var sParam = encodeURIComponent(oForm.elements[i].name);
				sParam += "=";
				sParam += encodeURIComponent(oForm.elements[i].value);
				aParams.push(sParam);
			}
			this.getContent(oForm.action, aParams.join("&"))
		},

		getContent:function(u, cBody){
			var oXmlHttp = window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject('Microsoft.XMLHTTP');
			oXmlHttp.onreadystatechange=function(){
				if(oXmlHttp.readyState==4&&oXmlHttp.status==200){
					nnk.box.fill(oXmlHttp.responseText);
				}
			};
			oXmlHttp.open('POST',u,1); 
			oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			oXmlHttp.send((cBody) ? cBody : null)
		},

		fill:function(content){
			this.boxStyle();
			b.innerHTML = content; 
		},

		hide:function(){
			m.style.display='none';
			b.style.display='none';
			cl.style.display='none';
		},

		pos:function(){ //align center
			var pwidth=(self.innerWidth||document.documentElement.clientWidth||document.body.clientWidth);
			var pheight=(self.innerHeight||document.documentElement.clientHeight||document.body.clientHeight);
			var dwidth=Math.max(Math.max(b.scrollWidth,b.scrollWidth),Math.max(b.clientWidth,b.clientWidth));
			var dheight=Math.max(Math.max(b.scrollHeight,b.scrollHeight),Math.max(b.clientHeight,b.clientHeight));
			b.style.left=((pwidth/2)-(dwidth/2))+'px';
			b.style.top=((pheight/2)-(dheight/2))+'px';
		},

		page:function(d){
			var b=document.body, e=document.documentElement;
			return d?Math.max(Math.max(b.scrollHeight,e.scrollHeight),Math.max(b.clientHeight,e.clientHeight)):
			Math.max(Math.max(b.scrollWidth,e.scrollWidth),Math.max(b.clientWidth,e.clientWidth))
		}
	}
}();

nnk.mes=function(){
	return {
		ahref:function(){
			if (!document.getElementsByTagName){ return; }
			var anchors = document.getElementsByTagName("a");
			for (var i=0; i<anchors.length; i++){
				var anchor = anchors[i];
				anchor.onclick = (anchor.getAttribute("alert")) ? function(){alert(this.getAttribute("alert")); return false;} : anchor.onclick;
				anchor.onclick = (anchor.getAttribute("confirm")) ? function(){return confirm(this.getAttribute("confirm"));} : anchor.onclick;
			}
			/*
			var anchors = document.getElementsByTagName("input");
			for (var i=0; i<anchors.length; i++){
				var anchor = anchors[i];
				anchor.onkeypress = (anchor.getAttribute("mask")) ? function(e){alert(this.nodeName.toLowerCase()); return nnk.inp.mask(e)} : anchor.onkeypress;

			}*/
		}
	}
}();
/*
nnk.inp=function(){
	return {
		mask:function(e){
			var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
			
			//alert("mes: "+this.nodeName.toLowerCase());
			return true;
		}
	}
}();*/

