function doUnique() { var date = new Date() ; return date.getTime() ; }
function clearConteyner(div){var Elements = $(div).childElements();for(var index = 0; index < Elements.length; ++index){var item=Elements[index];item.remove();} }
function addTextNode(l,d) {var n = document.createTextNode(d); 	l.appendChild(n);}
function getPageSize(){var a,yScroll;if(window.innerHeight&&window.scrollMaxY){a=window.innerWidth+window.scrollMaxX;yScroll=window.innerHeight+window.scrollMaxY}else if(document.body.scrollHeight>document.body.offsetHeight){a=document.body.scrollWidth;yScroll=document.body.scrollHeight}else{a=document.body.offsetWidth;yScroll=document.body.offsetHeight}var b,windowHeight;if(self.innerHeight){if(document.documentElement.clientWidth){b=document.documentElement.clientWidth}else{b=self.innerWidth}windowHeight=self.innerHeight}else if(document.documentElement&&document.documentElement.clientHeight){b=document.documentElement.clientWidth;windowHeight=document.documentElement.clientHeight}else if(document.body){b=document.body.clientWidth;windowHeight=document.body.clientHeight}if(yScroll<windowHeight){pageHeight=windowHeight}else{pageHeight=yScroll}if(a<b){pageWidth=a}else{pageWidth=b}var c=new Array(pageWidth,pageHeight);return c}
var pageDim,pageW,pageH,dv,topNav,lmenu;
dv = $('cnts');

var Overlay = {
	Show: function(){
	if(Prototype.Browser.IE){
	var objBody = $$('body')[0];
	objBody.appendChild(Builder.node('div',{id:'overlay',style:'position: absolute; top: 0; left: 0; z-index: 90; width:100%;height:100%;'}));
	new Effect.Appear('overlay', { duration: 0.2, from: 0.0, to: 0.8 });
	} else {
	    var objBody = $$('body')[0];
		objBody.appendChild(Builder.node('div',{id:'overlay',style:'position: absolute; top: 0; left: 0; z-index: 90; background-color: #000;width:'+pageW+'px;height:'+pageH+'px'}));
		new Effect.Appear('overlay', { duration: 0.2, from: 0.0, to: 0.8 });
		}
	},
	Hide: function(){

    new Effect.Fade('overlay', { duration: 0.2, from: 0.8, to: 0.0 });
    setTimeout(function(){ $('overlay').remove(); },300);
	},
	Correct: function(){
    pageDim = getPageSize();
	pageW = pageDim[0];
	pageH = pageDim[1];
    $('overlay').setStyle({ "width":pageW+'px',"height":pageH+'px' });
    }

}

var nn = doUnique();
var Message = {
	n : nn,
	Alert: function(data)
	{
        Overlay.Show();
		var w = 300;
		var e1 = Builder.node('div',{id:'alert_'+nn, style:"border:1px solid #fff;position:absolute;z-index:91;width:300px; height:auto; background:#FFF;" },
			[
			Builder.node('div',{id:'c'+nn,style:'padding:2px;color:#999;position: absolute;width:286px;float:left;background:#FEE;'},'Message:'),
			Builder.node('div',{id:'t'+nn,style:'cursor:pointer;padding:2px;color:#fff;font-weight:bold;text-align:center;position:relative;margin-left:286px;width:10px;background:#f00;'},'X'),
			Builder.node('br'),
			Builder.node('div',{id:'txt'+nn,style:'padding:2px;color:#999;text-align:center;position:relative;width:296px;background:#fff;'},data),
			Builder.node('br'),
			Builder.node('input',{id:'bt'+nn, value:'OK', align:'center', type:'button',style:'padding:2px;color:#999;text-align:center;margin-left:100px;margin-bottom:10px;width:100px;background:#fff;' })
			]
	    );
		$('cnts').appendChild(e1);
	    $('t'+nn).observe('click',(function(){ this.Hide();  }).bind(this));
	    $('overlay').observe('click',(function(){ this.Hide();  }).bind(this));
	    $('bt'+nn).observe('click',(function(){ this.Hide();  }).bind(this));
		var arrayPageScroll = document.viewport.getScrollOffsets();
	    e1.style.top = arrayPageScroll[1] + (document.viewport.getHeight() / 10)+150+'px';
		e1.style.left=(pageW-w)/2+'px';
	},
	Div: function(title,data,w,callback)
	{
		Overlay.Show();
		var retdata = data;
		if(w==null || w=='undefined') var w = 340;
        if(callback=='updateGRayonData') { w = w+50; var h = '400px;overflow:auto'; } else { var h = 'auto'; }
		if(callback==null || callback=='undefined') { var callback = false; }


		var e1 = Builder.node('div',{id:'alert_'+nn, style:"border:1px solid #000000;position:absolute;z-index:91;width:"+w+"px; height:auto; background:#FFFFFF;" });
		if(Prototype.Browser.IE)
		{
		e1.appendChild(new Element('div',{id:'c'+nn,style:'font-weight:bold;padding:2px 2px 2px 5px;color:#fff;position: relative;width:'+(w-14)+'px;float:left;background:#F2743F;'}).update(title));
		e1.appendChild(new Element('div',{id:'t'+nn,style:'cursor:pointer;padding:2px;color:#fff;font-weight:bold;text-align:center;position:absolute;margin-left:'+(0)+'px;width:10px;background:#f00;'}).update('X'));
		} else {
		e1.appendChild(new Element('div',{id:'c'+nn,style:'font-weight:bold;padding:2px 2px 2px 5px;color:#fff;position: relative;width:'+(w-14)+'px;float:left;background:#F2743F;'}).update(title));
		e1.appendChild(new Element('div',{id:'t'+nn,style:'cursor:pointer;padding:2px;color:#fff;font-weight:bold;text-align:center;position:absolute;margin-left:'+(w-14)+'px;width:10px;background:#f00;'}).update('X'));
		}
		e1.appendChild(new Element('br'));
		e1.appendChild(new Element('div',{id:'txt'+nn,style:'padding:2px;color:#999;overflow:auto;height:'+h+';text-align:center;position:relative;width:'+(w-4)+'px;background:#fff;'}).update(data));
		e1.appendChild(new Element('br'));
		e1.appendChild(new Element('input',{id:'bt'+nn, value:'ОК', align:'center', type:'button',style:'padding:2px;color:#999;text-align:center;margin-left:'+(w/3)+'px;margin-bottom:10px;width:'+(w/3)+'px;background:#fff;'}));

		$('cnts').appendChild(e1);
	    $('t'+nn).observe('click',(function(){ this.Hide();  }).bind(this));
	    $('overlay').observe('click',(function(){ this.Hide();  }).bind(this));
	    $('bt'+nn).observe('click',(function(){
	    eval( callback + '();' );
	    this.Hide();
	    }).bind(this));
		var arrayPageScroll = document.viewport.getScrollOffsets();
	    e1.style.top = arrayPageScroll[1] + (document.viewport.getHeight() / 10)+100+'px';
		e1.style.left=(pageW-w)/2+'px';
	},
	ShowMetro: function(dv)
	{
        Overlay.Show();
        $(dv).show();
        var w = 500;
        $(dv).setStyle({"border":"1px solid #000","position":"absolute","zIndex":"95","width":w+"px", "height":"480px", "background":"#FFF","padding":"5px","textAlign":'center',"paddingTop":"15px"});
        var arrayPageScroll = document.viewport.getScrollOffsets();
	    $(dv).style.top = arrayPageScroll[1] + (document.viewport.getHeight() / 10)+'px';
		$(dv).style.left=(pageW-w)/2+'px';
		$('overlay').observe('click',(function(){ Overlay.Hide(); $(dv).hide();  }).bind(this));
	},
	Hide: function()
	{
		$('alert_'+nn).remove();
		Overlay.Hide();
	}
}

 /*
document.observe('dom:loaded', function () { //! -- if dom:loaded
pageDim = getPageSize();
pageW = pageDim[0];
pageH = pageDim[1];
}); // -- if dom:loaded

*/
