/* 
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                                          */


Object.extend  = function(Dest) {
						for (var Key in this) Dest[Key] = this[Key];
						return Dest;}
//////Point/////////
Point = function(x,y){
 this.x = x||0; 
 this.y = y||0;
 return this; 
 }
Point.prototype ={
     set : function(x,y){ //return void
			this.x = x||this.x;  
			this.y = y||this.y; },	
     get : function(){    //return Array
			return [this.x,this.y];},  
toString : function(){    //return String
			return this.x+","+this.y;}}
//////////////////////  
////struktura zawierajaca informacje o tm na jakiej aktualnie przegladarce pracujem
Explorer={
		IE :(navigator.appName.indexOf("Microsoft")+1)?true:false,
	 OPERA :(window.opera)?true:false,
		FF :(navigator.appName.indexOf("Netscape")+1)?true:false,
   getSize :function(){
				var Size = new Point();
					if (window.innerHeight||window.innerWidth){ 
						Size.set(window.innerWidth,window.innerHeight);}
					else {
					 var doc1 = document.documentElement;
					 var doc2 = document.body;
						//Size.set( document.documentElement.clientWidth,document.documentElement.clientHeight);
					
						Size.set(doc1.clientWidth||doc2.clientWidth,doc1.clientHeight||doc2.clientHeight);
						//for (var Key in document.body)alert(Key+" "+document.body[Key]);
						
					}
				return Size.get();
			}
}
////Struct Element/////
Element = {
create  : function(Struct){//styl do diva powinnien byc przypisany css'm
	              	  var ElemType =("type" in Struct)?document.createElement(Struct["type"].toLowerCase()):null;
					  if(ElemType==null)return;
					  if("attributes" in Struct){
					    for(var Key in Struct["attributes"]){
					       if("style" == Key) ElemType.style.cssText = "color:red;border:1px solid red;width:40px;height:30px;"; 			
						   else     		  ElemType[Key] = Struct.attributes[Key];
						   }  
						}
			          flusso_Abstract.extend(ElemType);    
			        return ElemType;},
					
createFromStr  : function(Str){//tworzy element HTML ze stringu

                    if(typeof Str != 'string')return false; 
                    var Div = document.createElement("div");
                        Div.innerHTML = Str;
                    return flusso_Abstract.extend(Div.childNodes[0]);} ,
					
getByID         : function(){
										var EArray = new Array(),Ids = (typeof arguments[0] != 'object')?arguments:arguments[0];
											for(var Key=0;Key<Ids.length;Key++)
												if(typeof Ids[Key] == 'string'){
													Ids[Key] = document.getElementById(Ids[Key]);
													if(Ids[Key]){
														flusso_Abstract.extend(Ids[Key]);
														EArray.push(Ids[Key]);
													}
												}	
											return (EArray.length == 1)?EArray[0]:(EArray.length>0)?EArray:null;
									},
									
disabled        : function(id){
				var element = Element.getByID(id);
				element.disabled = false;
			},
			
enabled        : function(id){
				var element = Element.getByID(id);
				element.disabled = true;
			}		
}


/////////////////////
var flusso_Abstract = {};
/////////////
flusso_Abstract.extend  = function(Dest) {
	for (var Key in this) Dest[Key] = this[Key];
return Dest;}
//////////////////////

flusso_Abstract.getHeight  = function(){
	var height = parseInt(this.getMyAttribute("height"));	
	return height = (isNaN(height))?this.offsetHeight:height;
};

flusso_Abstract.getWidth  = function(Styl){
	var width = parseInt(this.getMyAttribute("width"));	
	return width = (isNaN(width))?this.offsetWidth:width;
};

flusso_Abstract.getMyAttribute  = function(Styl){
	return (document.layers)?eval("this."+Styl):eval("this.style."+Styl);
};
					
flusso_Abstract.getMyAttributes = function(){
	var TabAttrib = [];
		for(var key=0;key<arguments.length;key++){
			arguments[key] = this.getMyAttribute(arguments[key]);
				tabAttrib.push(arguments[key]);
		}
return tabAttrib;
};
							
flusso_Abstract.setMyAttributes = function(struct){
	for(var key in struct)
		if(typeof struct[key] == 'string')
			(document.layers)?eval("this."+key+"='"+struct[key]+"'"):eval("this.style."+key+"='"+struct[key]+"'");
};
						
flusso_Abstract.getParent  = function(){
	return (this.parentNode)?flusso_Abstract.extend(this.parentNode):null;		 
};	
						
flusso_Abstract.getClass  = function(){          
	return this.getAttribute('class')||this.getAttribute('className')||"";
};

flusso_Abstract.insertClassName = function(name){
	this.setAttribute('class',name);
	this.setAttribute('className',name);
}
									
flusso_Abstract.addClassName  = function(name){
	this.insertClassName(this.getClass()+" "+name);	
};

flusso_Abstract.isClass = function(name){
	var Class = this.getClass();
	    Class = Class.match(new RegExp("\\b"+name+"\\b","g"));
	return (Class)?true:false;
}
								
flusso_Abstract.deleteClassName = function(name){	
	this.insertClassName(this.getClass().replace( new RegExp("\\b"+name+"\\b","g")," "));	
};	
									
flusso_Abstract.insertTo  = function(dest){ 
	dest.appendChild(this);
};

flusso_Abstract.insertBeforeFirst = function(dest){
	if(dest.firstChild) dest.insertBefore(this,dest.firstChild); 	
}
																	
flusso_Abstract.getByTagName  = function(tag){
	var elements = this.getElementsByTagName(tag);
		for(var key=0;key<elements.length;key++)
			flusso_Abstract.extend(elements[key]);		 
	return elements;
};

flusso_Abstract.findPosition = function(){
	var curleft = curtop = 0;
	var obj = this;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}
			
flusso_Abstract.remove = function(){
	if(this.parentNode)this.parentNode.removeChild(this);										
};
flusso_Abstract.removeAllChild = function(){
	while( this.hasChildNodes() ) { this.removeChild( this.lastChild ); }
}
flusso_Abstract.getSize  = function(){
	var Size = new Point();
	
		if(document.body == this && Explorer.FF)   {
			var ES  = Explorer.getSize();
			var SP  = document.body.getScroll();
			var width   = window.innerWidth + window.scrollMaxX; 
			var height  = window.innerHeight + window.scrollMaxY;
			
			    width  -=((ES[1]<height)?17:0);
     			height -=((ES[0]<width)?17:0);
			Size.set(width, height);
		}
	    else{
			Size.set(this.offsetWidth,this.offsetHeight);
			if(this.scrollWidth > this.offsetWidth)  Size.set(this.scrollWidth,Size.y);
			if(this.scrollHeight > this.offsetHeight)Size.set(Size.x,this.scrollHeight);
		}
return Size.get();
};
										
flusso_Abstract.setOpacity = function(opac){
	if(this.style.MozOpacity) this.style.MozOpacity = opac;
	else if	(this.style.filter!=null){
			this.style.filter="alpha(opacity="+(0)+")";
			this.style.filter="alpha(opacity="+(opac*100)+")";
	}
	else this.style.opacity = opac;
};

flusso_Abstract.setCenterElement = function(element){
	this.setCenterLeftElement(element);
	this.setCenterTopElement(element);
};	
										
										
flusso_Abstract.setCenterLeftElement = function(element){
		this.setMyAttributes({left:((element.getWidth()-this.offsetWidth)/2)+"px"});
};	
			
flusso_Abstract.setCenterTopElement = function(element){ 
		this.setMyAttributes({top:((element.getHeight()-this.offsetHeight)/2)+"px"});
};			

flusso_Abstract.setCenterExplorer = function(){
	this.setCenterTopExplorer();
	this.setCenterLeftExplorer();	  
};	

flusso_Abstract.setCenterTopExplorer = function(){
	var PositionScroll = null, Top = null;
	var ExplorerSize   = Explorer.getSize();
		if(!document.body.getScroll)flusso_Abstract.extend(document.body);
		PositionScroll = document.body.getScroll();
	    Top  = PositionScroll[1]+(ExplorerSize[1]-this.offsetHeight)/2;	
		this.setMyAttributes({top:Top+"px"});
};	

flusso_Abstract.setCenterLeftExplorer = function(){
    var PositionScroll = null, Left = null;
	var ExplorerSize   = Explorer.getSize();
	    if(!document.body.getScroll)flusso_Abstract.extend(document.body);
	    PositionScroll = document.body.getScroll();
	    Left = PositionScroll[0]+(ExplorerSize[0]-this.offsetWidth)/2;	
		this.setMyAttributes({left:Left+"px"});
};	

flusso_Abstract.setUpExplorer  = function(move){
	var PositionScroll = null;
		if(!document.body.getScroll)flusso_Abstract.extend(document.body);
	    PositionScroll= document.body.getScroll();		
		this.setMyAttributes({top:(PositionScroll[1]+move)+"px"});
};

flusso_Abstract.insertAfter = function(node, referenceNode) {
  this.insertBefore(node, referenceNode.nextSibling);
}
flusso_Abstract.setHiddenAllChild = function(){
    var	child = this.childNodes || [];
        for(var key=0;key<child.length;key++)
			flusso_Abstract.extend(child[key]).setMyAttributes({display:"none"}) ; 				
};

flusso_Abstract.setShowAllChild = function(){
    var	child = this.childNodes || [];
        for(var key=0;key<child.length;key++)
			flusso_Abstract.extend(child[key]).setMyAttributes({display:"block"}) ; 				
};

flusso_Abstract.getScroll = function(){
	var Scroll = new Point();
		if(this == document.body)
		    if(window.pageXOffset&&window.pageYOffset)Scroll.set(  window.pageXOffset , window.pageYOffset );
		    else{  
				var doc1 = document.documentElement;
				var doc2 = document.body;
				Scroll.set((doc1.scrollLeft || doc2.scrollLeft ), (doc1.scrollTop || doc2.scrollTop));
		    }
		else
			Scroll.set(this.scrollLeft,this.scrollTop);
		return Scroll.get();
};

/////////Event/////////////
MyEvent ={
add:function(object,event,func){
	if(object.addEventListener)object.addEventListener(event, func, false)
	else if(object.attachEvent)object.attachEvent("on"+event, func)
},

insert: function(object,event,func){
	object['on' + event] = func;
},
			
del:function(object,event,func){
	if(object.removeEventListener)object.removeEventListener(event,func,false)
	else  object.detachEvent(event,func);
},	
			
clear:function(e){
	e =	e || window.event;
	if (Explorer.IE) { e.cancelBubble = true; e.returnValue = false;} 
	else { e.preventDefault(); e.stopPropagation(); }
return false;
},		
	
getTarget:function(e){
	e = e||window.event;
	var Target = (e.srcElement||e.target);

	return flusso_Abstract.extend(Target);
},

getCursorPosition:function(e){
	e = e || window.event;
    var x =0,y=0;
    if (e.pageX || e.pageY) {
        x = e.pageX;
        y = e.pageY;
    } 
    else{ 
	
	var doc1 = document.documentElement;
    var doc2 = document.body;
        x = e.clientX + (doc1.scrollLeft || doc2.scrollLeft) - (doc1.clientLeft || 0);
        y = e.clientY + (doc1.scrollTop  || doc2.scrollTop)  - (doc1.clientTop  || 0);
	}
    return {x:x,y:y};
}		

}		
/////////////////////////
//struct thread
Thread ={
sleep: function(mS) {
        var stopTime = new Date().getTime() + mS;
        while (true) if (new Date().getTime() > stopTime)return; 
		}
}

Effects = function(id){

	this.element = (typeof id =='string')?Element.getByID(id):id;
	this.animation = [];


	
    return this;
} 
Effects.prototype={
    
    speed : 100,
	
	setSpeed : function(speed){
					var Self = this;
						Self.speed = speed;
					return this;
				},
	
	step  : 1,
	
	setStep : function(step){
					var Self = this;
						Self.step = step;
					return this;
				},
	
	time  : 1,
	
	
    start : function(){
		      var Self = this;
				Self.animation = new Array();
				Self.time  = 1;
				Self.step  = 1;
				Self.speed = 100;
				return this;
			},
	
	reSizeTo: function(width,height){  
		var Self = this;
		var  heightT = parseInt(Self.element.getMyAttribute("height"));
			 heightT = (isNaN(heightT))?Self.element.offsetHeight:heightT;
		var  widthT = parseInt(Self.element.getMyAttribute("width"));
			 widthT = (isNaN(widthT))?Self.element.offsetWidth:widthT;	 
		var Size = new Array(widthT,heightT);
			width  = (width ==null)?0:width-Size[0];
			height = (height==null)?0:height-Size[1];
	
			var Key=0;
			for(Key;Key<Math.abs(width);Key+=Self.step){
			    var kierunek = width/Math.abs(width);
				var	czas = Self.time+Self.speed;
		        
					Self.animation.push("setTimeout(function(){ Self.setWidthBy("+(Self.step*kierunek)+");},"+czas+");");

					if((Key+Self.step)>Math.abs(width)){   
						    czas = Self.time+Self.speed;
					    var krok = Math.abs(width)-Key;
					
						    Self.animation.push("setTimeout(function(){ Self.setWidthBy("+(krok*kierunek)+");},"+czas+");");
					}
					Self.time = czas;
					
			}
			
			if((Key+Self.step)>Math.abs(width)){   
						    czas = Self.time+Self.speed;
					    var krok = Math.abs(width)-Key;
					    if(krok!=0)
						    Self.animation.push("setTimeout(function(){ Self.setWidthBy("+(krok*kierunek)+");},"+czas+");");
					}
					Self.time = czas;
			
			
			
			var Key=0;
			for(Key;Key<Math.abs(height);Key+=Self.step){
			    var kierunek = height/Math.abs(height);
				var	czas = Self.time+Self.speed;
					Self.animation.push("setTimeout(function(){ Self.setHeightBy("+(Self.step*kierunek)+");},"+czas+");");
					Self.time =czas;
			}
			
			if((Key+Self.step)>Math.abs(height)){   
			            var kierunek = height/Math.abs(height);
							czas = Self.time+Self.speed;
					    var krok = Math.abs(height)-Key;
						if(krok!=0)
							Self.animation.push("setTimeout(function(){ Self.setHeightBy("+(krok*kierunek)+");},"+czas+");");
						Self.time = czas;	
					}
			
	   	return this;        
	},
	
	stop: function(){
	    var Self = this;
		
		Self.animation.push("setTimeout(function(){ Self.onfinish();},"+Self.time+");");
		
		var str="";
		    for(var Key=0;Key<Self.animation.length;Key++){
				str += Self.animation[Key];
				}
		    eval(str);
		  
			return this;
	},
	
	changeOpacity: function(p,k){
	    var Self = this;
	    var l = (k-p);
		var length = Math.abs(l*100);
			for(var Key=0;Key<length;Key+=Self.step){
			    var value = p+((Key/100)*(l/Math.abs(l)));
				var	czas = Self.time+Self.speed;
					Self.animation.push("setTimeout(function(){ Self.element.setOpacity("+value+");},"+czas+");");
				
				if((Key+Self.step)>length){   
						czas  = Self.time+Self.speed;
					    value = p+(((length-Key)/100)*(l/Math.abs(l)));
							Self.animation.push("setTimeout(function(){ Self.setHeightBy("+(value)+");},"+czas+");");
					}				
					Self.time =czas;
			}
		return this;
	},
	
	onfinish:function(){},
	
	addFunction : function(func){
					var Self = this;
					    Self.myFunction = func;
						Self.animation.push("setTimeout(function(){ Self.myFunction(); },"+Self.time+");");	
						return this;
					},
					
	myFunction : function(){},			
	
	setWidthBy :function(x){
		var width = parseInt(this.element.getMyAttribute("width"));
		    width = (isNaN(width))?this.element.offsetWidth+x:width+x;
		    width +=(width<=0)?width:0;
		    this.element.setMyAttributes({width:width+"px"});
		return this;
	},
	
	setHeightBy :function(y){
		var height = parseInt(this.element.getMyAttribute("height"));
		    height = (isNaN(height))?this.element.offsetHeight+y:height+y;
		    if(height<=0)return this;
					    this.element.setMyAttributes({height:height+"px"});
		return this;
	}
	
}

		
MyAjax = function(Url,Method,Type){
	
	this.Url 	      = Url;
	this.Method       = Method;
	this.Type    	  = Type;
	this.TempUrl 	  = null;
	this.TempMethod   = null;
	this.TempType 	  = null;
	this.Http_request = null;

	return  this;
}



MyAjax.prototype ={
	 send : function(Arguments){
	 var  HTTP_REQUEST_CLASS = {A0:"Msxml2.XMLHTTP.7.0",A1:"Msxml2.XMLHTTP.6.0",A2:"Msxml2.XMLHTTP.5.0",A3:"Msxml2.XMLHTTP.4.0",
							   A4:"Msxml2.XMLHTTP.3.0",A5:"Msxml2.XMLHTTP"    ,A6:"Microsoft.XMLHTTP"};
	 	if (window.XMLHttpRequest){
			Http_request = new XMLHttpRequest(); 
			if (Http_request.overrideMimeType) Http_request.overrideMimeType('text');} 
		else if (window.ActiveXObject) 
			for(var Key in HTTP_REQUEST_CLASS)
				try{ 
					Http_request = new ActiveXObject(HTTP_REQUEST_CLASS[Key]);
					break;
				}catch(e){}
		if(!Http_request) alert("Wyst?pil blad podczs tworzenia obiektu HTTP_REQUEST");
		
	 
	 
				var Self 	= this; 
				var Url 	= this.TempUrl || this.Url;
				var Method	= this.TempMethod || this.Method; 
				var Type    = (typeof this.TempType == 'boolean')?this.TempType:(typeof this.Type == 'boolean')?this.Type:true;
				var Args    = Self.setArguments(Arguments);
				//alert(Method);
				Method = Method.toUpperCase();
				
					if(Http_request.readyState==4||Http_request.readyState==0){
						
						if(Method == "GET"&&Args) Url +="?"+Args; 
						
						Http_request.onreadystatechange = function(){Self.getRequestText(Http_request);}
						//alert(Method+","+Url+","+Type);
						Http_request.open(Method, Url, Type); 
						
						if(Method == "POST") Self.setRequestHeaderPOST(Args); //dodanie naglowkow w przypadku wysylania metoda POST
						
						Http_request.send(Args);
						Self.clearTemp();
						
						if(!Type) 
							Self.compliteandcorectsyn(Http_request.responseText); 
						
					}else{
						setTimeout(function(){Self.send(Arguments);},1000);
					}
				return Http_request;
			},

setArguments : function(Struct){
				var Value = null;
				var TempArray = new Array();
					for(var Key in Struct){
						TempArray.push(Key+"="+Struct[Key]);
					}
					Value = TempArray.join("&");
				return Value;
			},			
	
setRequestHeaderPOST: function(Args){
				Http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    			Http_request.setRequestHeader("Content-length", (Args)?Args.length:0);
    			Http_request.setRequestHeader("Connection", "close"); 
			},
	
	
  clearTemp : function(){
				this.TempUrl = this.TempMethod = this.TempType = null;
				},
	
	setAttr : function(Url,Method,Type){
				this.TempUrl    = Url;
				this.TempMethod = Method;
				this.TempType   = Type;
				return this;
			},
			
getRequestText: function(){
					var Self = this;
						switch(Http_request.readyState){
							case 0:Self.uninitialized(Http_request);	break;//nie zinicjowany
							case 1:Self.loading(Http_request); 			break;//wczytywanie
							case 2:Self.loaded(Http_request); 			break;//wczytanie
							case 3:Self.interactive(Http_request); 		break;//interaktywny
							case 4:Self.complete(Http_request); 		break; 
						}
					},	
				
complete       :function(Request){
					var Self = this;
						if (Request.status == 200){
							Self.completeandcorect(Request.responseText);}
					},

		uninitialized : function(){},	
			  loading : function(){},	
			   loaded : function(){},
		  interactive : function(){},
	completeandcorect : function(){},				
 compliteandcorectsyn : function(){},		
			
fileExist : function(Path){//dziala tylo na plikach textowych ,php i html itd
				var Self = this;
				var Req = Self.setAttr(Path,"GET",false).send({});
	
					if(Req.status==200)return true;
					else return false;
				}	
}

Scroll={};
Scroll.moveToElem = function(elem){
	if(!elem) return;
	var pos = elem.findPosition();
	window.scrollTo(0,pos[1]);
}


SelectData ={
  init : function(object){
			this.select_od = null;
			this.select_do = null;
			this.list_options = [];
			var Self = this;

				if("sod" in object){
					if(typeof object['sod'] == 'string') Self.select_od = Element.getByID(object['sod']);
					else Self.select_od = object['sod'];
				}
	
				if("sdo" in object){
					if(typeof object['sdo'] == 'string')Self.select_do = Element.getByID(object['sdo']);
					else Self.select_do = object['sdo'];
					//Self.select_do.disabled = true;
				}
	
				if(!(Self.select_od && Self.select_do))return this;

				for(var key=0;key<Self.select_od.length;key++){
					Self.list_options.push(Self.select_od.options[key].text);
				}
	
				MyEvent.add(Self.select_od,'change',function(){
				  //  Self.select_do.disabled = false;
					var length = Self.select_od.options.selectedIndex;
						Self.select_do.options.length = 0;//czyszczenie calego selecta
						for(var key = 0;key<=length;key++){
							Self.select_do.options[Self.select_do.length]  =
									new Option(Self.select_od.options[key].text,Self.select_od.options[key].value);
						}});
		}
}


Extension = function(object){
	this.form       = ('Form'	      in object)?object['Form']         :null;
    this.type    	= ('Type'         in object)?object['Type']         :null;
    this.input    	= ('Input'        in object)?object['Input']        :null;
	
	if(this.form) this.addEvent();

}

Extension.prototype.addEvent = function(){
	var self = this;
	var tempfunction = Validator.isCorrect;
		
		Validator.isCorrect = function(){
		if(self.input.value =="") return true;
		if(Extension.check(self.input.value,self.type)) {return tempfunction();}
	    else{ 
			Validator.createInfoBox("UWAGA!",["Niewlasciwy typ pliku"],Validator.idDo); 
			return false;}
		}
			  

}

Extension.init = function(idinput,type){
	var input = (typeof idinput =='string')?Element.getByID(idinput):idinput;
	var form  = input.form;
    var type  = type;
	
	var ext = new Extension({Form  :form,
							 Input :input,
							 Type  : type
	});
};

Extension.check = function(file,type){
	if(typeof file != "string" &&typeof type != "string")return false;	
    var ext = file.split('.');
	    ext = ext[ext.length - 1].toLowerCase();
	var tak = false;
	
	switch(type.toLowerCase()){
		case 'graph': switch(ext){
						case 'jpg' : ;						
						case 'jpeg': ;
						case 'gif' : return true; 
					}  
					break;
		case 'doc': switch(ext){
						case 'doc': ;
						case 'pdf': ;
						case 'txt': ;
						case 'odt': return true;
				}
				
		
	}
	return false;	
	}
	
Extension.DOC = "doc";
Extension.JPG = "jpg";

Select = {};
Select.init = function(elem,id){
	if(!elem) return;
	switch(elem.value){
		case "1": Element.disabled(id); break;
		case "0": Element.enabled(id); Element.getByID(id).value='0'; break;
	}
}