function clearField(defvalue,object) {
	
	if (object.value == defvalue) {
		object.value = '';
	}
}

var Fosta = {
	/**
	 * ustawia opacity dla elementu blokowego
	 * @param {Object} element
	 * @param {Object} value
	 */
	setOpacity : function(element, value) {
		if (navigator.appName.indexOf("Microsoft")!=-1 && parseInt(navigator.appVersion)>=4) {
			element.style["filter"] = "alpha(opacity="+(value)+")";
		} else {
			element.style.opacity = parseFloat(value/100);
		}		
	},
	/**
	 * Zmienia opacity dla elementu
	 * @param {Object} element
	 * @param {Object} change - zmiana opacity w procentach
	 */
	changeOpacity : function(element,change) {
		
		if (navigator.appName.indexOf("Microsoft")!=-1&&parseInt(navigator.appVersion)>=4) {			
			var opacity = parseFloat(element.filters.alpha.opacity);		
			opacity = opacity + change;
			element.filters.alpha.opacity = opacity;
		} else {
			change = parseFloat(change/100);
			
			var opacity = parseFloat(element.style.opacity);		
			opacity = opacity + change;
			element.style.opacity = opacity;
		}
	},
		
	/**
	 * Klasa pokazu slajdów
	 * @param {Object} blockId - id blocku ze slajdami
	 * @param {Object} time - czas przejscia
	 */
	SlideShow : function(blockId, time) {
		
		this.name     = blockId;
		this.box      = document.getElementById(blockId);
		this.elements = new Array();
		this.buttons  = new Array();
		this.time     = time;
		this.idx      = 0 ;
		this.count    = time;
		this.block    = false;
		this.isShade  = false;
		
		this.create = function() {	
			var nodes = this.box.childNodes;
			var k =0;
			for(var i = 0;i < nodes.length;i++) {
				if ( nodes[i].nodeType == 1 ) {
					if (k > 0) {	
						Fosta.setOpacity(nodes[i],0);
					} else {
						Fosta.setOpacity(nodes[i],100);		
					}
					k++;
					this.elements.push(nodes[i]);
				}
			}
			this.timer();
		},
		
		this.timer = function() {
			if (this.count == 0) {
				
				this.count = this.time;
				this.swap();	
			}
			this.count-=100;
		
			setTimeout(this.name + ".timer();",100);
		},
		
		this.shade = function(loop) {
			
			if (this.block) {
				this.block = false;
				this.isShade = false;
				return;
			}
			
			if (loop > 0) {
				Fosta.changeOpacity(this.elements[this.idx],-10);
				
				var tmp = this.idx + 1; if (tmp == this.elements.length) { tmp = 0; }
				
				Fosta.changeOpacity(this.elements[tmp],10);
				
				loop--;
				
				obj = this;
				
				var f = function() {
					obj.shade(loop);
				}		
				setTimeout(f,100);
			} else {
				this.buttons[this.idx].setAttribute('class','');
				this.isShade = false;
				this.idx++;	if (this.idx == this.elements.length) {	this.idx = 0; }
				
				this.buttons[this.idx].setAttribute('class','on');			
			}
		},
		
		this.swap = function() {
			this.shade(10);
			this.block = false;
			this.isShade = true;
		},
		
		this.setNumButtons = function() {
			var btns = document.createElement('div');
			btns.setAttribute('class','slide_but');
			
			for (var i=0;i<this.elements.length;i++) {
				var btn = document.createElement('a');
				btn.setAttribute('onclick',this.name + '.show(' + i + ');return false;');
				btn.setAttribute('href','');
				btn.innerHTML = (i+1);
				
				if (i == 0) {
					btn.setAttribute('class','on');
				}
				
				btns.appendChild(btn);
				this.buttons.push(btn);
			}

			this.box.appendChild(btns);
		},
		this.show = function(idx) {
			this.count = this.time;
			if (this.isShade) {
				this.block = true;
			}			
			for (var i = 0; i < this.elements.length; i++) {
				Fosta.setOpacity(this.elements[i], 0);
				this.buttons[i].setAttribute('class', '');
			}
			this.idx = idx;
			
			this.buttons[this.idx].setAttribute('class','on');
			Fosta.setOpacity(this.elements[this.idx],100);
		}
		
	}
};

Fosta.HidenBox = function (boxid, position, step, loops, state, time) {
	this.box = document.getElementById(boxid);
	this.step = step;
	this.time = time;
	this.loops = loops;
	this.position = position;
	this.state = state;
	this.loop = 0;
	this.img = null;
	
	this.setArrowImage = function(id) {
			this.img = document.getElementById(id);
	}
	
	this.change = function() {
		
		var value = 0;
		if (this.position == 'horizontal') {
			value = this.box.style.width;
			value = parseInt(value.substr(0, value.length - 2));
		} else if (this.position == 'vertical') {
			value = this.box.style.height;
			value = parseInt(value.substr(0, value.length - 2));
		}
		
		if (this.state == 'hide') {
			if (this.loop < this.loops ) {
				this.box.style.height = value+step+'px';
				this.loop++;
				setTimeout("hidenBox.change();",this.time);
			} else if (this.loop == this.loops){
				this.loop = 0;
				this.state = 'show';
				
				if (this.img != null) {
					this.img.src = "http://mlodyx.nazwa.pl/images/bar_up.gif";
				}
			} 
		} else if (this.state == 'show') {
			if (this.loop < this.loops ) {
				this.box.style.height = (value-step)+'px';
				this.loop++;
				setTimeout("hidenBox.change();",this.time);
			} else if (this.loop == this.loops){
				this.loop = 0;
				this.state = 'hide';
				
				if (this.img != null) {
					this.img.src = "http://mlodyx.nazwa.pl/images/bar_down.gif";
				}
			} 			
		}
	}
	
}

Fosta.VerticalPageSlider = function(blockId, idx) {
	this.elements = new Array();
	this.box = document.getElementById(blockId);
	this.idx = idx;
	this.loop = 0;
	this.heights = new Array();
	
	document.getElementById('osk'+this.idx).style.height = "auto";
		
	this.swap = function(idx,click) {
		
		var value = document.getElementById('osk' + this.idx).offsetHeight;
			
		document.getElementById('osk' + this.idx).style.height = (value - 40) + "px";
		
		var value2 = document.getElementById('osk'+idx).offsetHeight;
			
		document.getElementById('osk'+idx).style.height = (value2 + 40) + "px";
		
		if (value - 40 <= 30) {
			
			document.getElementById('osk' + this.idx).style.height = 30 + "px";
			
			document.getElementById('osk'+idx).style.height = "auto";
			this.idx = idx;
		} else {
			setTimeout("pageslider.swap(" + idx + ",false);", 40);
		}
	}

};

Fosta.SHL = function(box,tabs, num) {
	this.id  = tabs[num];	
	this.box = box;
	
	for (var i=0;i<tabs.length;i++) {
		
		if (document.getElementById('a' + tabs[i]) != null) {
			document.getElementById('a' + tabs[i]).setAttribute('onclick', this.box + '.swap(\'' + tabs[i] + '\');return false;');
		}
		document.getElementById(tabs[i]).style.display = 'none';
	}
	
	document.getElementById(this.id).style.display = "block";
	
	this.swap = function (id) {
		document.getElementById(this.id).style.display = "none";
		document.getElementById(id).style.display = "block";
		this.id = id;
	};
};

Fosta.PageBar= function(page) {
	this.page = page;
	
	this.swap = function(page) {
		document.getElementById('page'+this.page).style.display = 'none';
		this.page = page;
		document.getElementById('page'+this.page).style.display = 'inline';
	}
}

Fosta.showHide = function (id) {
	var box = document.getElementById(id);
	
	if (box.style.display == "none") {
		box.style.display = "inline";
	} else {
		box.style.display = "none";
	}
}


Fosta.Loader = {
	setLoader : function() {
		var html = '<div id="loader">Trwa ładowanie strony...proszę czekać</div>';		
		
		document.write(html);
		
	},
	
	setOpacity : function(element, value) {
		
		element = document.getElementById(element);
		
		if (navigator.appName.indexOf("Microsoft")!=-1 && parseInt(navigator.appVersion)>=4) {
			element.style["filter"] = "alpha(opacity="+(value*100)+")";
		} else {
			element.style.opacity = value;
		}
		
		value -= 0.1;
		
		if (value > 0) {
			setTimeout('Fosta.Loader.setOpacity(\'loader\',' + value + ')', 50);
		} else {
			document.getElementById('loader').innerHTML = '';
			document.getElementById('loader').style.zIndex = -1;
		}
	},
	
	onLoad : function() {
		
		//this.setOpacity('loader',1);
		
		
	}
	
};

Fosta.PageSlider = function(blockId) {
	this.elements = new Array();
	this.box = document.getElementById(blockId);
	this.idx = 0;
	this.loop = 0;
		
	this.create = function() {
		
		var nodes = this.box.childNodes;
		var k =0;
		for(var i = 0; i < nodes.length; i++) {
			if ( nodes[i].nodeType == 1 ) {
		
				if (k > 0) {
					nodes[i].style.zIndex = 10 + k;	
					nodes[i].style.left = (460 + 40 * k) + 'px';
				} else {
					nodes[i].style.zIndex = 10;	
					nodes[i].style.left = (40 * k) + 'px';
				}
				k++;
				this.elements.push(nodes[i]);
			}
		}
	};
	
	this.swap = function(idx,click) {
		if (click && this.loop != 0) {
			return false;
		}
		if (idx > this.idx) {
					
			for (var i = this.idx + 1; i <= idx; i++) {
				var left = this.elements[i].style.left;			
				left = parseInt(left.substr(0,left.length-2));			
				left -= 46;
				this.elements[i].style.left = left + 'px';
			}
			
			this.loop++;
			
			if (this.loop != 10) {
				setTimeout('pageslider.swap(' + idx + ',0);',50);
			} else {
				this.loop = 0;
				this.idx = idx;
			}
			
		} else if (idx < this.idx) {
			for (var i = idx + 1; i <= this.idx; i++) {
				var left = this.elements[i].style.left;			
				left = parseInt(left.substr(0,left.length-2));			
				left += 46;
				this.elements[i].style.left = left + 'px';
			}
			
			this.loop++;
			
			if (this.loop != 10) {
				setTimeout('pageslider.swap(' + idx + ');',50);
			} else {
				this.loop = 0;
				this.idx = idx;
			}
		}
	}

};



Fosta.Flash = {
	embed : function(width,height,file,flashvars) {	
		
		var html = '<object '+
			'classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '+
			'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0";' + 
			'width="'+width+'" height="'+height+'">'+
			'<param name="movie" value="'+file+'" />'+
			'<param name="quality" value="high" />'+
			'<param name="wmode" value="transparent" />'+
			'<param name="flashvars" value="'+flashvars+'" />	'+	
			'<param name="allowFullScreen" value="true" />' +
			'<embed src="'+file+'" quality="high" allowFullScreen="true" wmode="transparent" flashVars="'+flashvars+'"'+
			'   	pluginspage="http://www.macromedia.com/go/getflashplayer"; '+
			'	    type="application/x-shockwave-flash" width="'+width+'" height="'+height+'"></embed>'+
		' </object>';
		
		
		document.write(html);
	},
	getVersion : function () {
		
	}
};

Fosta.Navi = function(page, pages, box, pageName) {

	this.pageName = pageName;	
	this.boxName = box;
	this.box = document.getElementById(box);
	this.page = page;
	this.pages = pages;
	
	this.create = function() {
		var html = '<div class="navi" style="text-align:center;overflow:hidden;">';
		html += '<span style="float:right;width:130px;height:40px;">';
		if (this.page < this.pages) {
			html += '<a onclick="'+this.boxName+'.toPage('+(this.page+1)+');return false;" href="">nastepna strona &raquo;</a>'
		}
		html += '</span><span style="float:left;width:130px;height:40px;">';
		if (this.page > 1) {
			html += '<a onclick="'+this.boxName+'.toPage('+(this.page-1)+');return false;" href="">&laquo; poprzednia strona</a>'
		}
		html += '</span>';
		for (var i=0; i<this.pages; i++) {
			if (i + 1 != this.page) {
				document.getElementById(this.pageName + (i+1)).style.display = "none";
				html += '<a href="" onclick="'+this.boxName+'.toPage('+(i+1)+');return false;">' + (i + 1) + '</a>';
			} else {
				html += '<strong>' + (i + 1) + '</strong>';
			}
		}		
		
		html += '</div>';
				
		this.box.innerHTML = html;
	}
	
	this.toPage = function(page) {
		document.getElementById(this.pageName + this.page).style.display = "none";
		document.getElementById(this.pageName + page).style.display = "inline";
		this.page = page;
		this.create();
	}
	
}

Fosta.Adv = {
	put : function(advid) {
		new Ajax.Request('adv.php?id='+advid, {
			method: 'post',
			onSuccess: function(transport){			
				
				document.getElementById('adv'+advid).innerHTML = transport.responseText;
	    	},
	    	onFailure: function(){ 
			
			}
		});	
	}
};
Fosta.Cookie = {
	set : function(c_name,value,expiredays) {
		var exdate=new Date();
		exdate.setDate(exdate.getDate()+expiredays);
		document.cookie = c_name + "=" + Base64.encode(value) +
		((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
	},
	get : function(c_name) {
		if (document.cookie.length>0) {
			c_start=document.cookie.indexOf(c_name + "=");
			if (c_start!=-1) {
				c_start=c_start + c_name.length+1;
				c_end=document.cookie.indexOf(";",c_start);
				
				if (c_end == -1) {
					c_end = document.cookie.length;
				}
				return Base64.decode(document.cookie.substring(c_start,c_end));
			} else {
				return null;
			}
		}  
		return -1;
	}
}


Fosta.Wysiwyg = {
		
	create : function(areaid) {
		this.id = areaid;
		
		this.area = document.getElementById(areaid+'_area');
		this.preview = document.getElementById(areaid+'_preview');
			
		this.previewChange();
	},
	previewChange : function() {
			
		var value = this.area.value;
			
		value = value.replace(/\n/g,'<br/>');
			
		document.getElementById(this.id).value = value;
			
		this.preview.innerHTML = value;
			
	},
	getSelection : function() {
		this.area.focus();  
		
		var start = this.area.selectionStart;  
		var end = this.area.selectionEnd;  
		var selBef = this.area.value.substring(0,start);
		var selAft = this.area.value.substring(start);
		var sel = this.area.value.substring(start,end);
			
		return sel;
	},
	setB : function() {
		this.area.focus();  
			
		var start = this.area.selectionStart;  
		var end = this.area.selectionEnd;  
		var selBef = this.area.value.substring(0,start);
		var selAft = this.area.value.substring(end);
		var sel = this.area.value.substring(start,end);
			
		if (sel == null) {
				
		} else {
			this.area.value = selBef+"<b>"+sel+"</b>"+selAft;
		}
		this.previewChange();
	},
	setI : function() {
		this.area.focus();  
			
		var start = this.area.selectionStart;  
		var end = this.area.selectionEnd;  
		var selBef = this.area.value.substring(0,start);
		var selAft = this.area.value.substring(end);
		var sel = this.area.value.substring(start,end);
			
		if (sel == null) {
				
		} else {
			this.area.value = selBef+"<i>"+sel+"</i>"+selAft;
		}
		this.previewChange();		
	},
	setA : function() {
		var link = prompt("Podaj adres odnośnika");
			
		var start = this.area.selectionStart;  
		var end = this.area.selectionEnd;  
		var selBef = this.area.value.substring(0,start);
		var selAft = this.area.value.substring(end);
		var sel = this.area.value.substring(start,end);
			
		if (sel == null) {
			sel = prompt("Podaj nazwe odnośnika");
		} 
			
		this.area.value = selBef+"<a href=\""+link+"\">"+sel+"</a>"+selAft;
			
	},
	setH1 : function() {
		this.area.focus();  
			
		var start = this.area.selectionStart;  
		var end = this.area.selectionEnd;  
		var selBef = this.area.value.substring(0,start);
		var selAft = this.area.value.substring(end);
		var sel = this.area.value.substring(start,end);
			
		if (sel == null) {
			
		} else {
			this.area.value = selBef+"<h1>"+sel+"</h1>"+selAft;
		}
		this.previewChange();		
	},
	setH2 : function() {
		this.area.focus();  
			
		var start = this.area.selectionStart;  
		var end = this.area.selectionEnd;  
		var selBef = this.area.value.substring(0,start);
		var selAft = this.area.value.substring(end);
		var sel = this.area.value.substring(start,end);
			
		if (sel == null) {
				
		} else {
			this.area.value = selBef+"<h2>"+sel+"</h2>"+selAft;
		}
		this.previewChange();		
	},
	setH3 : function() {
		this.area.focus();  
			
		var start = this.area.selectionStart;  
		var end = this.area.selectionEnd;  
		var selBef = this.area.value.substring(0,start);
		var selAft = this.area.value.substring(end);
		var sel = this.area.value.substring(start,end);
			
		if (sel == null) {
			
		} else {
			this.area.value = selBef+"<h3>"+sel+"</h3>"+selAft;
		}
		this.previewChange();		
	},	
	setUL : function() {
			
	},
	setOL : function() {
			
	}			
};

var Base64 = {
		 
		// private property
		_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
	 
		// public method for encoding
		encode : function (input) {
			var output = "";
			var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
			var i = 0;
	 
			input = Base64._utf8_encode(input);
	 
			while (i < input.length) {
	 
				chr1 = input.charCodeAt(i++);
				chr2 = input.charCodeAt(i++);
				chr3 = input.charCodeAt(i++);
	 
				enc1 = chr1 >> 2;
				enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
				enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
				enc4 = chr3 & 63;
	 
				if (isNaN(chr2)) {
					enc3 = enc4 = 64;
				} else if (isNaN(chr3)) {
					enc4 = 64;
				}
	 
				output = output +
				this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
				this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
	 
			}
	 
			return output;
		},
	 
		// public method for decoding
		decode : function (input) {
			var output = "";
			var chr1, chr2, chr3;
			var enc1, enc2, enc3, enc4;
			var i = 0;
	 
			input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
	 
			while (i < input.length) {
	 
				enc1 = this._keyStr.indexOf(input.charAt(i++));
				enc2 = this._keyStr.indexOf(input.charAt(i++));
				enc3 = this._keyStr.indexOf(input.charAt(i++));
				enc4 = this._keyStr.indexOf(input.charAt(i++));
	 
				chr1 = (enc1 << 2) | (enc2 >> 4);
				chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
				chr3 = ((enc3 & 3) << 6) | enc4;
	 
				output = output + String.fromCharCode(chr1);
	 
				if (enc3 != 64) {
					output = output + String.fromCharCode(chr2);
				}
				if (enc4 != 64) {
					output = output + String.fromCharCode(chr3);
				}
	 
			}
	 
			output = Base64._utf8_decode(output);
	 
			return output;
	 
		},
	 
		// private method for UTF-8 encoding
		_utf8_encode : function (string) {
			string = string.replace(/\r\n/g,"\n");
			var utftext = "";
	 
			for (var n = 0; n < string.length; n++) {
	 
				var c = string.charCodeAt(n);
	 
				if (c < 128) {
					utftext += String.fromCharCode(c);
				}
				else if((c > 127) && (c < 2048)) {
					utftext += String.fromCharCode((c >> 6) | 192);
					utftext += String.fromCharCode((c & 63) | 128);
				}
				else {
					utftext += String.fromCharCode((c >> 12) | 224);
					utftext += String.fromCharCode(((c >> 6) & 63) | 128);
					utftext += String.fromCharCode((c & 63) | 128);
				}
	 
			}
	 
			return utftext;
		},
	 
		// private method for UTF-8 decoding
		_utf8_decode : function (utftext) {
			var string = "";
			var i = 0;
			var c = c1 = c2 = 0;
	 
			while ( i < utftext.length ) {
	 
				c = utftext.charCodeAt(i);
	 
				if (c < 128) {
					string += String.fromCharCode(c);
					i++;
				}
				else if((c > 191) && (c < 224)) {
					c2 = utftext.charCodeAt(i+1);
					string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
					i += 2;
				}
				else {
					c2 = utftext.charCodeAt(i+1);
					c3 = utftext.charCodeAt(i+2);
					string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
					i += 3;
				}
	 
			}
	 
			return string;
		}
	 
	}






	

