
	window.addEvent('domready', function() 
	{				
	 	new smallPopups();
	});

	function isArray(obj) {

		if (obj != null)
		{
    		return obj.constructor == Array;
    	} else { return false; }

	}
				
	function markAll( container_id ) 
	{
    	var rows = document.getElementById(container_id).getElementsByTagName('input');
    	var checkbox;

    	for ( var i = 1; i < rows.length; i++ )
    	{

	        checkbox = rows[i];

    		if ( checkbox && checkbox.type == 'checkbox' )
    		{
    			if ( checkbox.disabled == false ) 
				{
                	checkbox.checked = true;
            	}
        	}
    	}
		return true;
	}

	function unMarkAll( container_id )
	{
		var rows = document.getElementById(container_id).getElementsByTagName('input');
    	var checkbox;

		for ( var i = 1; i < rows.length; i++ )
		{

			checkbox = rows[i];

			if ( checkbox && checkbox.type == 'checkbox' )
			{
            	checkbox.checked = false;
        	}
    	}
		return true;
	}
	
// array-like enumeration
if (!Array.forEach) { // mozilla already supports this
	Array.forEach = function(array, block, context) {
		for (var i = 0; i < array.length; i++) {
			block.call(context, array[i], i, array);
		}
	};
} 

// generic enumeration
Function.prototype.forEach = function(object, block, context) {
	for (var key in object) {
		if (typeof this.prototype[key] == "undefined") {
			block.call(context, object[key], key, object);
		}
	}
};

// character enumeration
String.forEach = function(string, block, context) {
	Array.forEach(string.split(""), function(chr, index) {
		block.call(context, chr, index, string);
	});
};

// globally resolve forEach enumeration
var forEach = function(object, block, context) {
	if (object) {
		var resolve = Object; // default
		if (object instanceof Function) {
			// functions have a "length" property
			resolve = Function;
		} else if (object.forEach instanceof Function) {
			// the object implements a custom forEach method so use that
			object.forEach(block, context);
			return;
		} else if (typeof object == "string") {
			// the object is a string
			resolve = String;
		} else if (typeof object.length == "number") {
			// the object is array-like
			resolve = Array;
		}
		resolve.forEach(object, block, context);
	}
};



		function trim(str, chars) {
 		   return ltrim(rtrim(str, chars), chars);
		}
		function ltrim(str, chars) {
    		chars = chars || "\\s";
    		return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
		}
		function rtrim(str, chars) {
    		chars = chars || "\\s";
    		return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
		}		


	function highlight(el, dura, startColor, endColor, restoreColor)
					{
						//dura = dura * 1000;
						//el.set('tween', {duration: 1000, transition: Fx.Transitions.Cubic.easeOut});
						
						//if (startColor == '') { startColor = el.getStyle('background-color'); }
						//if (restoreColor == '') { restoreColor = el.getStyle('background-color'); }
						//if (endColor == '') { endColor = '#FFFFFF'; }
						//var sCol = new Color(startColor);
						//var eCol = new Color(endColor);
						//el.tween('background-color', startColor);
						if (el.highlight)
						{
							el.highlight(startColor);
						}
					}



	/******************************************************************************************* 
	 * 14.05.08 omega
	 * 
	 * ajax livevalidation functions
	 **/
						
	/*
	 * element - element for validation
	 * validationName - from validators dir
	 * after - id of element after which the hidden div is inserted
	 * afterMsg - id of element after which the true/false msg is inserted
	 * errorOK - true msg
	 * error - false msg
	 */

	function addAjaxValidator(element, validatorName, after, afterMsg, errorOK, error)
	{	
		/*
	 	 * add a hidden div with label and input for ajax validation result
	 	 */
		id = element.id;
		elementId = id;
							
		tmp = '<label class="red" for="'+elementId+'_ajaxResult" id="label_'+elementId+'_ajaxResult">ajax</label><input class="regText" type="text" name="'+elementId+'_ajaxResult" id="'+elementId+'_ajaxResult" value="1" />';
		var nE = new Element('div', { 'class': 'hidden' } );
		nE.innerHTML = tmp;
		tmpE = $(after).getParent();
		tmpE.insertBefore(nE,$(after));	

		window.validators[elementId+'_ajaxResult'] = new LiveValidation(elementId+'_ajaxResult', {insertAfterWhatNode: afterMsg, validMessage: errorOK, wait: 500});
       	window.validators[elementId+'_ajaxResult'].add(Validate.Custom, { against: function (value, args){ if (value != '0') { return true; } else { return false; } }, failureMessage: error});
       	window.validators[id].add(Validate.Custom, { against: function (value, args){ ajaxValidate(element, validatorName, id); if ($(id+'_ajaxResult').value != '0') { return true; } else { return false; } }, failureMessage: error});
	}
	/*
	 * gets the result from ajax to the hidden input
	 *
	 * id - input id	 
	 */
	function ajaxCallback(result, id)
	{
		if (result != '-') {
			$(id + '_ajaxResult').value = result;
		}
		window.validators[id + '_ajaxResult'].validate();
		$(id).className = $(id+'_ajaxResult').className;
		$('label_'+id).className = $('label_'+id+'_ajaxResult').className;
		$(id).removeClass('ajaxLoader');
	}
	/* element - element (input) for validation
	 * validatorName - from validators directory
	 * postVarName - a name for the post variable in which the value will be sent
	 */
	function ajaxValidate(element,validatorName,postVarName) 
	{
		value = element.value;
		ajaxValidator(value, element.id, validatorName, postVarName);
		element.addClass('ajaxLoader');
	}
	// main ajax request	
	function ajaxValidator(value, id, validatorName, postVarName, params)
	{						
		window.callbackId = id;
		window.postValue = value;
		var req = new Request({url: "/ajaxvalidator-" + validatorName + "-" + postVarName, method: 'post', data: postVarName+'='+value, autoCancel: true,
		onComplete: function(wynik)
		{
			ajaxCallback(wynik, window.callbackId);
		},
		onFailure: function() 
		{
			ajaxCallback('-', window.callbackId);
		},
			onException: function(headerName, value) 
		{
			ajaxCallback('0', window.callbackId);
		},
		onCancel: function()
		{
			ajaxCallback(window.postValue, window.callbackId);
		}
		}).send();
	}



/* small Popups*/

var smallPopups = new Class({
	className: 'popup',
	offsetX: -35,
	offsetY: 80,
	text: 'no information',
	divId: 'popUp',
	popUpNode: null,
	effectIn: null,
	effectOut: null,
	initialize: function(){
		this.initPopUp();
		nodes = document.getElements('.' + this.className);
		for(z = 0; z < nodes.length; z++) {
			nodes[z].addEvent('mouseover',  this.popupOpen.bindWithEvent(this, nodes[z]));
			nodes[z].addEvent('mouseout',  this.popupClose.bindWithEvent(this));
		}
		this.effectIn = new Fx.Morph($(this.divId), {duration: 500, link: 'cancel'});
		$(this.divId).setStyle('opacity', 0);
		this.effectOut = new Fx.Morph($(this.divId), {duration: 100, link: 'chain'});
	},
	initPopUp: function (){
		//this.text = node.getAttribute('title');
		var dive = document.createElement('div');
		dive.setAttribute('id', this.divId + 'e');
		// content div
		var divContent = document.createElement('div');
		divContent.setAttribute('id', this.divId + 'Content');
		var textNode = document.createTextNode(this.text);
    	divContent.appendChild(textNode);
		// foot
		var divFoot = document.createElement('div');
		divFoot.setAttribute('id', this.divId + 'Foot');
		
		dive.appendChild(divContent);
		
		// div
		var div = document.createElement('div');
		div.setAttribute('id', this.divId);
		
		div.appendChild(dive);
		div.appendChild(divFoot);
		//div.style.display = 'none';
		document.body.appendChild(div);
		this.popUpNode = $(this.divId);
	},
	popupOpen: function(t, node){
		var xy = this.getXY(node);
		$(this.divId + 'Content').innerHTML=node.getAttribute('alt');
		//$(this.divId).style.display='block';
		
		
		$(this.divId).style.left=(xy.x - this.offsetX) + "px";
		$(this.divId).style.top=(xy.y - this.offsetY) + "px";
		this.effectIn.start({opacity: [0,1]});
	},
	popupClose: function(t){
		this.effectIn.start({opacity: [1,0]});
	},
	getXY: function(obj){
		  var curleft = 0;
		  var curtop = obj.offsetHeight + 5;
		  var border;
		  if (obj.offsetParent)
		  {
		    do
		    {
		      // XXX: If the element is position: relative we have to add borderWidth
		      /*if (getStyle(obj, 'position') == 'relative')
		      {
		        if (border = _pub.getStyle(obj, 'border-top-width')) curtop += parseInt(border);
		        if (border = _pub.getStyle(obj, 'border-left-width')) curleft += parseInt(border);
		      }*/
		      curleft += obj.offsetLeft;
		      curtop += obj.offsetTop;
		    }
		    while (obj = obj.offsetParent)
		  }
		  else if (obj.x)
		  {
		    curleft += obj.x;
		    curtop += obj.y;
		  }
		  return {'x': curleft, 'y': curtop};
	}
});

/*******************************************************************************************
 * Js Tab Changer
 */


var jsTab = new Class({
    initialize: function(root, callback)
	{
		var root = '#' + root;
		el = $$(root + ' > .jsLinks > ul > li > a');

		el.each(function(item, index){ 
			item.addEvent('click', function() 
			{  
				if(!item.hasClass('selected'))
				{
					$$(root + ' > .jsLinks > ul > li > a').removeClass('selected');
					item.addClass('selected');
					
					$$(root + ' > .jsBox').addClass('hidden');
					
					url = item.get('href');
					var sub = url.substring(url.indexOf("#")+1);
					$$('#jsBox' + sub).removeClass('hidden');
					
					callback.call(this, root, sub);
				}
				return false;
			});
		});
    }
});

/*******************************************************************************************
 * Js Dynamic photos Scaler with slider
 */

var jsPhotoScaler = new Class({
        options: {
                mySlider: null,
                myKnob: null,
                myImgs: null,
				mySlide: null,
				imgs: new Array(50),
				imgWidth: new Array(50),
				imgHeight: new Array(50),
				dHeight: new Array(60, 97, 200),
				startPosition: 40,
				stepsCounter: 205,
				setBorderSize: null,
				minBorderSize: null,
				setSpan: false,
				boxMode: false,
				boxStartWidth: 0
        },
        initialize: function(options){
				var self = this;
                this.setOptions(options);
				this.initSlider();
				this.initImg();
				this.setSpan(true)
				if (Browser.Engine.trident4) {
					self.scalePhoto(self.options.mySlide.step);
					self.setSpan();
					window.addEvent('resize', function()
					{
						self.setSpan();
					});
					
				}
        },
		initImg : function(){
				var self = this;
				$$( self.options.myImgs ).each(function(img, index) {
							if (!img) return;
							//img.height = 97;
							img.addEvent('load', function(){
								self.options.imgs[index] = img;
								self.options.imgWidth[index] = img.width;
								self.options.imgHeight[index] = img.height;
								img.removeEvents('load');
								//self.scalePhoto(self.options.mySlide.step);
								//self.setSpan();
							});
							self.options.imgs[index] = img;
							self.options.imgWidth[index] = img.width;
							self.options.imgHeight[index] = img.height;
				});
		},
		initSlider: function(){
				var self = this;
				
				self.options.mySlide = new Slider( $( self.options.mySlider ), $( self.options.myKnob ), {
					steps: 50,
					range: [0, self.options.stepsCounter],
					onChange: function(step){
						self.scalePhoto(step); 
						self.setSpan();
					}
				}).set(self.options.startPosition);
		},
		setSpan: function(start)
		{
				var self = this;
				if(!this.options.setSpan) return;
					
				self.options.imgs.each(function(img, index){
	
					if (!img) return ;

					mainDiv = img.getParent().getParent();
					nameDiv = img.getParent().getNext();
					

					if ((self.options.boxMode)&&(start)) 
					{
						var nW = self.options.boxStartWidth;
						var cur = mainDiv.getStyle('width').toInt(); 
						if (cur < self.options.boxStartWidth)
						{
							mainDiv.setStyle('width', self.options.boxStartWidth + 10);
						}
						
					}
					else
					{
						
						var nW = (mainDiv.getStyle('width').toInt() + 2);
					}
					
					//console.log(mainDiv.className,' ',nW);
					var pos = mainDiv.getPosition();

					if (nameDiv)
					{
						span = nameDiv.getFirst();
						span.setStyle('width', nW + 'px');

						var pos2 = nameDiv.getPosition();
						if (Browser.Engine.trident) {
							span.setStyle('left', (pos.x + 5) + 'px');
						}
						
						if (Browser.Engine.trident4) {
							span.setStyle('top', (pos2.y) + 'px');
							span.setStyle('margin-left', (nW - 48) + 'px');
						}
				
						cityDiv = nameDiv.getNext();
						pos2 = cityDiv.getPosition();
						span = cityDiv.getFirst();
						span.setStyle('width', nW + 'px');
						if (Browser.Engine.trident) {
							span.setStyle('left', (pos.x + 5) + 'px');
						}
						if (Browser.Engine.trident4) {
							span.setStyle('top', (pos2.y) + 'px');
							span.setStyle('margin-left', (nW - 48) + 'px');
						}
					}
				});

		},
		scalePhoto: function(step){
				var self = this; var current = 0;
				
				var proc = (step / self.options.startPosition) * 100;
				var chng = (-100) + proc;
				chng = chng / 2;
				proc = 100 + chng;

				self.options.imgs.each(function(img, index){

					if (!img) return;
					//var newHeight = Math.round(self.options.dHeight[current] + (self.options.dHeight[current + 1] - self.options.dHeight[current]) * proc);
					//var newWidth = Math.round(newHeight * self.options.imgRatio[index]);
					
					var newHeight = Math.round((proc * self.options.imgHeight[index]) / 100);
					var newWidth = Math.round((proc * self.options.imgWidth[index]) / 100);
					
					for (var i = self.options.dHeight.length - 1; i >= 0; i--) {
						if (newHeight > ( self.options.dHeight[i] )) {
							current = i;
							break;
						}
					}
					current = parseInt(current);

					img.setStyle('height', newHeight + 'px');
					img.setStyle('width', newWidth + 'px');
					
					if (Browser.Engine.trident4) {
						el = img.getParent().getParent();
						el.setStyle('width', (newWidth + 5) + 'px');
					}
					
					if (self.options.setBorderSize == true) {
						el = img.getParent().getParent();
						if (self.options.boxMode)
						{
							newWidth = Math.round(((proc * self.options.boxStartWidth) / 100));
						} 
						if (el) {
							plus = 5;
							if (Browser.Engine.trident5) { plus = 5; }
							if (newWidth + 5 > self.options.minBorderSize) {
								el.setStyle('max-width', (newWidth + plus) + 'px');
								el.setStyle('min-width', (newWidth + plus) + 'px');
								//if ((Browser.Engine.trident4) || (Browser.Engine.presto)) {
									el.setStyle('width', (newWidth + plus) + 'px');
								//}
							}
							else {
								el.setStyle('max-width', self.options.minBorderSize + 'px');
								el.setStyle('min-width', self.options.minBorderSize + 'px');
								//if ((Browser.Engine.trident4)||(Browser.Engine.presto))
								el.setStyle('width', self.options.minBorderSize + 'px');
							}
							
						}
					}

					var oldSrc = img.get('src');
					var pos = oldSrc.lastIndexOf('_') + 1;
					var newSrc = oldSrc.substring(0, pos) + (current + 1) + oldSrc.substring(pos + 1);
					
					img.set('src', newSrc);
				});

		}
});

jsPhotoScaler.implement(new Options);

/*******************************************************************************************
 * Js Dynamic photos Scaler SecondEdition with slider
 */

var jsPhotoScalerSe = new Class({
        options: {
	        mySlider: null,
	        myKnob: null,
	        myImgs: null,
			mySlide: null,
			imgs: new Array(50),
			imgRatio: new Array(50),
			startPosition: 31,
			stepsCounter: 100,
			steps: new Array(0, 31, 67, 100),
			dHeight: new Array(60, 97, 200, 300)
        },
        initialize: function(options){
            this.setOptions(options);
			this.initImg();
			this.initSlider();
        },
		initImg : function(){
			var self = this;
			$$( self.options.myImgs ).each(function(img, index){
				/*self.options.imgRatio[index] = 1.00;*/
				
				img.addEvent('load', function ()
		        {
					self.options.imgRatio[index] = img.width/img.height;
		        });
				self.options.imgs[index] = img;
			});
		},
		initSlider: function(){
			var self = this;
			
			self.options.mySlide = new Slider( $( self.options.mySlider ), $( self.options.myKnob ), {
				steps: 100,
				wheel: true,
				range: [0, self.options.stepsCounter],
				onChange: function(step){ self.scalePhoto(step); }
			}).set(self.options.startPosition);
		},
		scalePhoto: function(step){
				var self = this; var current = 0;
							
				for(var i = self.options.steps.length - 1; i >= 0; i--)
				{
					if( step > self.options.steps[i])
					{
						current = i;
						break;
					}
				}
				
				current = parseInt(current);
				var proc = (step - self.options.steps[current]) / (self.options.steps[current + 1] - self.options.steps[current]);
		
				self.options.imgs.each(function(img, index){

					if (!img) return;
					
					var newHeight = Math.round(self.options.dHeight[current] + (self.options.dHeight[current + 1] - self.options.dHeight[current]) * proc);
					var newWidth = Math.round(newHeight * self.options.imgRatio[index]);

					img.setStyle('height', newHeight + 'px');
					img.setStyle('width', newWidth + 'px');
					
					var oldSrc = img.get('src');
					var pos = oldSrc.lastIndexOf('_') + 1;
					var newSrc = oldSrc.substring(0, pos) + (current + 1) + oldSrc.substring(pos + 1);
					
					img.set('src', newSrc);
				});
		}
});

jsPhotoScalerSe.implement(new Options);

/*******************************************************************************************
 * Js Movie thumbs viewer ( from YouTube)
 */

var jsMovieThumb = new Class({
		options: {
				timer: false,
				currentImg: 0,
				delay: 600
		},
        initialize: function(root){

				var self = this;
				
				$$(root).each(function(item, index) {
					item.addEvent('mouseenter', function (){
						var id = item.id;
						self.options.timer = true;
						self.options.currentImg = item.id;
						setTimeout(function() { self.animateThumb(id) }, self.options.delay);
					});
					item.addEvent('mouseleave', function (){
						self.options.timer = false;
						self.options.currentImg = 0;
					});
				});
        },
		animateThumb: function(id){
			img = $(id);
			
			var oldSrc = img.get('src');
			var pos = oldSrc.lastIndexOf('.') - 1;
			var oldNr =  parseInt( oldSrc.substring(pos, pos + 1) );
			
			if(oldNr > 2) oldNr = 0;
			var newSrc = oldSrc.substring(0, pos) + (oldNr + 1) + oldSrc.substring(pos + 1);
			
			img.set("src", newSrc);
			
			var self = this;
			if (self.options.timer == true && self.options.currentImg == id) {
				setTimeout(function() { self.animateThumb(id) }, self.options.delay);
			}
			else {
				newSrc = oldSrc.substring(0, pos) + 1 + oldSrc.substring(pos + 1);
				img.set("src", newSrc);
			}
		}
});

jsMovieThumb.implement(new Options);


// set's the screen to 'wait for operation complete' mode
function setYouGotNewMail(type)
{
	if (!window.orgDisplays)
	{
		window.orgDisplays = new Array();
	}
	if (type == 1)
	{
		if (Browser.Engine.trident)
		{
			ele = $$('select');
			var ind = 0;
			ele.each(function(item, index)
			{
				ind++;
				window.orgDisplays[ind] = item.getStyle('display'); 
				item.setStyle('display', 'none');
				
//				item.disabled = 'true';
			});
		}
		if (!$('TB_overlay'))
		{
			new Element('div').setProperty('id', 'TB_overlay').injectInside(document.body);
		}
		$('TB_overlay').setProperty('class', 'NewMailOverlay');
		$('TB_overlay').setOpacity(0);
		$("TB_overlay").setStyles({"height": '0px', "width": '0px'});
	//	pageSize = getPageSize();
		var scroll = window.getScrollSize();
		// opera
		if (Browser.Engine.presto)
		{
			
		}

		$("TB_overlay").setStyles({"height": scroll.y +'px', "width": scroll.x +'px'});
//		$("TB_overlay").setStyles({"height": window.getScrollHeight()+'px', "width": window.getScrollWidth()+'px'});

		if (!$('TB_load'))
		{
			new Element('div').setProperty('id', 'TB_load').injectInside(document.body);
		}
		
		$('TB_load').setProperty('class', 'NewMailLoad');
		$('TB_load').setStyle('opacity', '1');
		if (!$('TB_shadow'))
		{
			new Element('div').setProperty('id', 'TB_shadow').injectInside(document.body);
		}
		$('TB_shadow').setProperty('class', 'NewMailLoadBack');
		$('TB_shadow').setStyle('opacity', '0.4');
				
		$('TB_load').innerHTML = 	'<div class="NewMailLoadProg"><img src="' + window.staticServer + 'img/sendMailSmall.gif" style="margin-left: auto; margin-right: auto; text-align: center;" /><br />' +
									'<div class="NewMailLoadText">' + window.newMailMsg1 + '<br/><a href="/profile/mailbox-inbox">' + window.newMailMsg2 + '</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a style="cursor: pointer;" onclick="javascript:setYouGotNewMail(0);">' + window.newMailMsg3 + '</a></div></div>';
		if ($("TB_load")) { $("TB_load").setStyles({left: (window.getScrollLeft() + (window.getWidth() - 140)/2)+'px', top: (window.getScrollTop() + ((window.getHeight()-37)/2))+'px',display:"block"}); }
		if ($("TB_shadow")) { $("TB_shadow").setStyles({left: ((window.getScrollLeft() + (window.getWidth() - 140)/2)+5)+'px', top: ((window.getScrollTop() + ((window.getHeight()-37)/2)) + 5)+'px',display:"block"}); }
						
		new Fx.Tween('TB_overlay', {property: 'opacity', duration: 400, transition: Fx.Transitions.Sine.easeInOut}).start(0,0.6);
		window.operationN = 1;
	}
	else
	{
		new Fx.Tween('TB_load', { property: 'opacity', duration: 400, transition: Fx.Transitions.Sine.easeInOut }).start(0.0);
		new Fx.Tween('TB_shadow', { property: 'opacity', duration: 400, transition: Fx.Transitions.Sine.easeInOut }).start(0.0);			
		var tbl = new Fx.Tween('TB_overlay', { property: 'opacity', duration: 400, transition: Fx.Transitions.Sine.easeInOut });
		tbl.start(0.6, 0.0).chain(
    		function(){ if ($('TB_overlay')) {
				$('TB_overlay').dispose();
			} }
		);			

		if (Browser.Engine.trident)
		{
			ele = $(document.body).getElements('select');
			var ind = 0;
			ele.each(function(item, index)
			{
	//			item.disabled = 'false';
				ind++;
				item.setStyle('display',window.orgDisplays[ind]);
			});
		}
		window.operationN = 0;
	}
}









