/* 
Zawartosc tego dokumentu jest chronina prawami autorskimi i
 nie moze byc kopiowana ani wykorzystywana do wlasnych celow. 
Jesli chcesz wykorzystac zawartosc tego skryptu skataktuj sie 
z wlascicielem.
                                          www.flusso.pl                                          */

Loader = function(object){
	this.loader       = ('Loader'    in object)?object['Loader']     :null;
	this.background   = ('Background'in object)?object['Background'] :null;
	
	if(this.loader){ 
	    this.loader.setCenterExplorer();
	    Loader.setFullSize(this.background);
		this.addEvent();
		}
	return this;
}

Loader.prototype.clear = function(){
	var self = this;
		self.loader.remove();
		self.background.remove();
};

Loader.prototype.addEvent = function(){
	var self = this;
		MyEvent.add(window,"scroll",function(e){  if(self.loader)self.loader.setCenterExplorer();}); // podczas urzycia sowaka ustawienie loadera na srodku przegladarki
		MyEvent.add(window,"resize",function(e){  if(self.loader)self.loader.setCenterExplorer();}); //podczas rozszezania ustawinie loaderan a srodku przegladarki
        
		MyEvent.add(window,"resize",function(e){  if(self.background)Loader.setFullSize(self.background)});	
		
		MyEvent.add(window,"scroll",function(e){	//poprawienie beledu wystepujacego w IE ze scroll'em;	
			if(self.background&&Explorer.IE){
				self.background.setMyAttributes({top:"0px",left:"0px",width:"0px",height:"0px"});
				if(!document.body.getSize)flusso_Abstract.extend(document.body)
				var ScrollPosition = document.body.getScroll();
				ScrollPosition[0] += document.body.clientWidth;
				ScrollPosition[1] += document.body.clientHeight;
				self.background.setMyAttributes({width:ScrollPosition[0]+"px",height:ScrollPosition[1]+"px"});
			}	
		});
}



Loader.init = function(str){
    
	var LO   = Loader.createLoader(str);
    var BG   = Loader.createBackGround();
	
		BG.insertTo(document.body);
		LO.insertTo(document.body);
		
	var lo = new Loader({ Background : BG,
						  Loader	 : LO});	
	return lo;
} 

Loader.setFullSize = function(element){
	var FullSizeDocument = null,ScrollPosition = null;
		if((!document.body.getSize)||(!document.body.getScroll))flusso_Abstract.extend(document.body);
		element.setMyAttributes({top:"0px",left:"0px",width:"0px",height:"0px"});
	    FullSizeDocument = document.body.getSize();
		ScrollPosition = document.body.getScroll();
		//poprawienie beledu wystepujacego w IE ,bledu zwiaznego ze scroll'em
		if(Explorer.IE){
			FullSizeDocument[0] = document.body.clientWidth;
			FullSizeDocument[1] = document.body.clientHeight;	
			element.setMyAttributes({left:ScrollPosition[0]+"px",top:ScrollPosition[1]+"px"});
		}
	    element.setMyAttributes({width:FullSizeDocument[0]+"px",height:FullSizeDocument[1]+"px"});
}

Loader.createBackGround = function(){
	var BackGround = Element.createFromStr("<div id='"+Loader.BG+"' style='position:absolute;top:0;left:0;'></div>");
		BackGround.setOpacity(0.6);
	return BackGround;
};	

Loader.createLoader = function(str){
	var Load = Element.createFromStr("<div id='"+Loader.LD+"' style='position:absolute;'>"+(str||"Proszę czekać...")+"</div>");
	return Load;
};

Loader.LD = "div_loader"        //id urzywane przez loader
Loader.BG = "div_background"    //div background;


DialogBox = function(){};

DialogBox.init = function(object){
	var target,text,TAK =DialogBox.textYES, NIE = DialogBox.textNO;
	var background = Element.getByID(Loader.BG);
	
	
	if('event' in object){
	    MyEvent.clear(object['event']);
	    target = MyEvent.getTarget(object['event']);
		target = (target.nodeName == 'IMG')?target.getParent():target;
	}
	if(background&&background.getMyAttribute("dispaly")!='none' )return false;
	
	if('button1' in object) TAK = object['button1'];
	if('button2' in object) NIE = object['button2'];
	
	if('text' in object){
	    if(target) text = "<p class='information_content'>"+object['text']+"</p><p class='confirm_menu'><a id='"+DialogBox.idYES+"' href='"+target.href+"' >"+TAK+"</a><a id='"+DialogBox.idNO+"' href='#'>"+NIE+"</a></p>";
	}
	
	var oldId = Loader.LD;
	    Loader.LD = DialogBox.id;
	var load   = Loader.init(text);
      
	var a_no = Element.getByID(DialogBox.idNO);
	var a_yes = Element.getByID(DialogBox.idYES);
	
	MyEvent.add(a_yes,"click",function(e){  load.clear();   Loader.init();});
	MyEvent.add(a_no,"click",function(e) {MyEvent.clear(e);  load.clear();});
	
	document.onkeypress = function(evt){
		var keynum = window.event?window.event.keyCode:(evt.which)?evt.which:evt.keyCode;
		
		if(keynum == 13){
			document.onkeypress = function(){}
			load.clear();  
			Loader.init();
			location.href = target.href;
		}else if(keynum == 27){
			document.onkeypress = function(){}
			load.clear();
		}
	}
	
	Loader.LD = oldId;
}

DialogBox.init2 = function(object){
	var target,text,TAK =DialogBox.textYES, NIE = DialogBox.textNO;
	var background = Element.getByID(Loader.BG);
	
	if('event' in object){
	    MyEvent.clear(object['event']);
	    target = MyEvent.getTarget(object['event']);
	}
	
	if(background&&background.getMyAttribute("dispaly")!='none' )return false;
	
	if('button1' in object) TAK = object['button1'];
	if('button2' in object) NIE = object['button2'];
	
	if('text' in object){
	    if(target) text = "<p class='information_content'>"+object['text']+"</p><p class='confirm_menu'><a id='"+DialogBox.idYES+"' href='#' >"+TAK+"</a><a id='"+DialogBox.idNO+"' href='#'>"+NIE+"</a></p>";
	}
	
	var oldId = Loader.LD;
	    Loader.LD = DialogBox.id;
	var load   = Loader.init(text);
      
	var a_no = Element.getByID(DialogBox.idNO);
	var a_yes = Element.getByID(DialogBox.idYES);
	
	MyEvent.add(a_yes,"click",function(e){  load.clear(); target.submit();  Loader.init();});
	MyEvent.add(a_no,"click",function(e) {MyEvent.clear(e);  load.clear();});
	
	document.onkeypress = function(evt){
		var keynum = window.event?window.event.keyCode:(evt.which)?evt.which:evt.keyCode;
		
		if(keynum == 13){
			document.onkeypress = function(){}
			load.clear();  
			Loader.init();
			target.submit(); 
		}else if(keynum == 27){
			document.onkeypress = function(){}
			load.clear();
		}
		
	}
	
	Loader.LD = oldId;
}


DialogBox.textYES = "TAK";
DialogBox.textNO  = "NIE";
DialogBox.idYES   = "yes";
DialogBox.idNO    = "no";
DialogBox.id      = "confirm_box";