function changeDefaultValue(sender, default_value, change_value)
{
	if (sender.value == default_value) sender.value = change_value;
}

function insertBeforeAfter(class_name)
{
	var obj = document.getElementsByTagName('*'),
		target_class = " " + class_name + " ",
		curr_class_name = null,
		element = null,
		before, 
		after,
		cnt_before, 
		cnt_after;
	
	for (var i = 0; i < obj.length; i++)
	{
		element = obj[i];
		curr_class_name = " " + element.className + " ";
		if (curr_class_name.indexOf(target_class) > -1)
		{
			before = document.createElement('span');
			before.className = 'before';
			cnt_before = document.createElement('span');
			
			after = document.createElement('span');
			after.className = 'after';
			
			cnt_after = document.createElement('span');
			cnt_before.className = cnt_after.className = 'bef_aft_cnt';
			
			before.appendChild(cnt_before);
			after.appendChild(cnt_after);
			
			element.insertBefore(before, element.firstChild);
			element.appendChild(after);
		}
	}
}

var DOMEvent = function()
{
	var EventColl = [];
	var counter = 0;
	
	function DOMEvent()
	{
		var self = this;
		
		this.addEvent = function(oElement, handler, callback, capture)
		{
			if (oElement.addEventListener)
			{
				oElement.addEventListener(handler, callback, capture);
			}
			else if(oElement.attachEvent)
			{
				var prop = [handler, callback].join("");
				if (oElement[prop]) return;
				
				if (!EventColl[oElement._eventid])
				{
					oElement._eventid = counter++;
					EventColl[oElement._eventid] = {'oElement' : oElement};
				}
				EventColl[oElement._eventid][prop] = [handler, callback];
				
				oElement[prop] = function()
				{
					callback.call(oElement, event);
				}
				oElement.attachEvent('on' + handler, oElement[prop]);
			}
		}
		
		this.removeEvent = function(oElement, handler, callback, capture)
		{
			if (oElement.removeEventListener)
			{
				oElement.removeEventListener(handler, callback, capture);
			}
			else if (oElement.detachEvent)
			{
				var prop = [handler, callback].join("");
				if (oElement[prop])
				{
					oElement.detachEvent('on' + handler, oElement[prop]);
					oElement[prop] = null;
					EventColl[oElement._eventid][prop] = null;
				}
			}
		}
		
		function breakEventLeak()
		{
			var curr = null;
			var j = null;
			for (var i = 0, len = EventColl.length; i < len; i++)
			{
				curr = EventColl[i];
				for (j in curr)
				{
					if (j != 'oElement')
					{
						self.removeEvent(curr.oElement, curr[j][0], curr[j][1]);
					}
				}
				curr.oElement._eventid = null;
			}
			EventColl = null;
			counter = null;
		}
		if (window.attachEvent) window.attachEvent('onunload', breakEventLeak);
	}
	return new DOMEvent();
}();

DOMEvent.preventDefault = function(event)
{
	event.returnValue = false;
	if (event.preventDefault)
	{
		event.preventDefault();
	}
}

DOMEvent.stopPropagation = function(event)
{
	if (event.stopPropagation)
	{
		event.stopPropagation();
		return;
	}
	event.cancelBubble = true;
}

var DocViewport = function()
{	
	var root = document.documentElement,
		COMPAT_SAFARI_LTE3 = !document.compatMode && window.innerHeight >=0 && !(root.offsetHeight === window.innerHeight),
		OPERA_LT_9_5 = window.opera && +window.opera.version() < 9.5,
		COMPAT = (document.compatMode == 'CSS1Compat' || COMPAT_SAFARI_LTE3) && !OPERA_LT_9_5;
	
	return {
		getDimensions : function()
		{
			return {
				'width' : this.getWidth(),
				'height' : this.getHeight()
			}
		},
		
		getWidth : function() 
		{
			return COMPAT ? root.clientWidth : (document.body && document.body.clientWidth);
		}, /*
			return number or null;
			Null if browser in quirks mode when document body not completed loaded or Browser Opera 8 or IE lt 6  
		*/
		
		getHeight : function()
		{
			return COMPAT ? root.clientHeight : (document.body && document.body.clientHeight);
		}, /*
			return number or null;
			Null if browser in quirks mode when document body not completed loaded or Browser Opera 8 or IE lt 6  
		*/
		getScrollY : function()
		{
			return window.scrollY || (root||document.body)['scrollTop'];
		},  /*
			return number of scroll from top to bottom
		*/
		getScrollX : function()
		{
			return window.scrollX || (root||document.body)['scrollLeft'];
		}  /*
			return number of scroll from left to right
		*/
	}
}();

/*Tabs Menu*/
/*
	var tabs_menu = new TabsMenu({
	'tabs_root_id' : 'tabs_menu', - holder id for tabs
	'tabs_tag_name' : 'a', - tabs tag name
	'active_tab_index' : 0, - default active tab, if no set 0 is defaul
	'change_event' : 'mouseover' - event chnage tabs, default is click
	'onChange' : tabChanger, - change callback pointer to function
	'next_button_id' : 'tabs_menu_next', - id for next button 
	'prev_button_id' : 'tabs_menu_prev' - id for previous button
	'active_class' : 'active_tab'  - set active tab class name
	'default_class' : 'default_tab_class' - set default class tab
	'animation_direction' : 'ASCENDING/DESCENDING',
	'animation_delay' : 1000 - delay animation  ms
	});
	
	setActiveTab(index) - set active tab
	nextTab() - next tab
	prevTab - prev tab
	startAnimation - start animation
	stioAnimation - stop animation
*/
function TabsMenu(properties) {
	var default_class = properties.default_class || '',
		active_class = default_class + ' ' + (properties.active_class || 'active_tab'),
		curr_index = properties.active_tab_index || 0,
		tabs_holder = document.getElementById(properties.tabs_root_id),
		tabs = tabs_holder.getElementsByTagName(properties.tabs_tag_name),
		change_event = properties.change_event || 'click',
		onChange = properties.onChange || changeTab,
		delay_animation = properties.delay_animation,
		timer = null,
		self = this;
	
	this.setActiveTab = function(new_index)
	{
		if (new_index < 0 || new_index >= tabs.length) return; 
		
		if (onChange)
		{
			onChange(properties.tabs_root_id, new_index, curr_index, properties.tabs_tag_name); 
		}
		
		tabs[curr_index].className = default_class;
		tabs[new_index].className = active_class;
		curr_index = new_index;
	}
	
	this.nextTab = function()
	{
		var curr = curr_index;
		self.setActiveTab((++curr >= tabs.length ? 0 : curr)); 
	}
	
	this.prevTab = function()
	{
		var curr = curr_index;
		self.setActiveTab((--curr < 0 ? tabs.length - 1 : curr));
	}
	var animation_direction = (properties.animation_direction === 'DESCENDING' ? this.prevTab : this.nextTab);
	this.startAnimation = function()
	{
		if (typeof delay_animation === 'number' && delay_animation > 0)
		{
			timer = setInterval(animation_direction, delay_animation);
		}
	}
	
	this.stopAnimation = function()
	{
		clearInterval(timer);
	}
	
	for (var i = 0, len = tabs.length; i < len; i++)
	{
		DOMEvent.addEvent(tabs[i], change_event, 
			(function(index){
				return function(e){self.setActiveTab(index); DOMEvent.preventDefault(e);}
			})(i), false);
	}
	var button_obj = null;
	if (button_obj = document.getElementById(properties.prev_button_id))
	{
		DOMEvent.addEvent(button_obj, change_event, function(e){self.prevTab(); DOMEvent.preventDefault(e);}, false);
	}
	if (button_obj = document.getElementById(properties.next_button_id))
	{
		DOMEvent.addEvent(button_obj, change_event, function(e){self.nextTab(); DOMEvent.preventDefault(e);}, false);
	}
	
	this.setActiveTab(curr_index);
	this.startAnimation();
	
	function changeTab(root_id, new_index, old_index)
	{
		var obj;
		if (obj = document.getElementById(root_id + '_' + old_index))
		{
			obj.style.display = 'none';
		}
		if (obj = document.getElementById(root_id + '_' + new_index))
		{
			obj.style.display = 'block';
		}
		
		if (change_event == 'mouseover')
		{
			try {
				ObserverDropDown.hideDropDown();
			}catch(e){}
		}
	}
}

function tabChanger(root_id, new_index, old_index)
{
	var obj;
	if (obj = document.getElementById(root_id + '_' + old_index))
	{
		obj.style.display = 'none';
	}
	if (obj = document.getElementById(root_id + '_' + new_index))
	{
		obj.style.display = 'block';
	}
}

function setOldIndex(sender)
{
	sender.oldSelectedIndex = sender.selectedIndex;
}

function changeHiddenContent(sender, display_str)
{
	var old_cnt = document.getElementById(sender.options[sender.oldSelectedIndex].value),
		new_cnt = document.getElementById(sender.options[sender.selectedIndex].value);
	old_cnt.style.display = 'none';
	new_cnt.style.display = '' + display_str;
}

function showHideAllTeam(select_obj, link_obj, show_hide)
{
	var select_obj = document.getElementById(select_obj),
		id = select_obj.options[select_obj[(show_hide ? 'selectedIndex' : 'oldSelectedIndex')]].value,
		display = (show_hide ? 'block' : ''),
		vis = (show_hide ? 'hidden' : 'visible');
		
	document.getElementById(link_obj).style.visibility = vis; 
	document.getElementById(id).getElementsByTagName('p')[0].style.display = display;
}


function updateFileField(sender)
{
	var obj = document.getElementById(sender.name);
	obj.innerHTML = sender.value;
}

/*INCREASE DECREASE FONT*/
function IncreaseDecreaseTxt(options)
{
	var root = document.getElementById(options.content_id),
		increaser = document.getElementById(options.increaser),
		decreaser = document.getElementById(options.decreaser),
		step = options.step || 1,
		max = options.max_size || 20,
		min = options.min_size || 9,
		def_size = options.def_size || 12,
		def_butt_class = options.def_butt_class || '';
	
	this.setDefaultSize = function()
	{
		def_size = options.def_size;
		increaseDecrease(0);
	}
	
	this.increase = function()
	{
		increaseDecrease(step);
	}
	
	this.decrease = function()
	{
		increaseDecrease(-step);
	}
	
	function increaseDecrease(step)
	{
		var curr_size = def_size + step;
		if (curr_size >= min && curr_size <= max)
		{
			root.style.fontSize = curr_size + 'px';
			def_size = curr_size;
		}
		increaser.className = def_butt_class + ' zoom_in' + (curr_size >= max ? '_disable' : '');
		decreaser.className = def_butt_class + ' zoom_out' + (curr_size <= min ? '_disable' : '');
	}
	
	DOMEvent.addEvent(increaser, 'click', function(){increaseDecrease(step)}, false);
	DOMEvent.addEvent(decreaser, 'click', function(){increaseDecrease(-step)}, false);
	increaseDecrease(0);
}
/*END INCREASE DECREASE FONT*/

/*Element Object
  Extend DOM Element */
function Element(element)
{
	this.self = typeof element === 'string' ?
				document.createElement(element) :
				element;
	this.style = this.self.style;
}

Element.prototype = {
	exec : function(method, args)
	{
		var el_method = null;
		if (!args)
		{
			args = [];
		}
		else if (!args.join)
		{
			args = [args];
		}
		
		if ((el_method = this[method]) instanceof Function)
		{
			return el_method.apply(this, args);
		}
		if ((el_method = this.self[method]) instanceof Function)
		{
			return el_method.apply(this.self, args);
		}
		if (typeof el_method == 'object')
		{
			try {
				return Function.prototype.apply.call(el_method, this.self, args);
			}catch(e){}
		}
	},
	setStyle : function(prop, value)
	{
		this.style[prop] = value;
	},
	show : function()
	{
		this.style.display = 'block';
		return this;
	},
	hide : function()
	{
		this.style.display = 'none';
		return this;
	},
	hidden : function()
	{
		this.style.visibility = 'hidden';
		return this;
	},
	visible : function()
	{
		this.style.visibility = 'visible';
		return this;
	},
	centeringInViewport : function()
	{
		var body_dimension = DocViewport.getDimensions();
		this.style.left = DocViewport.getScrollX() + Math.max(Math.round((body_dimension.width - this.self.offsetWidth) / 2), 0) + 'px';
		this.style.top = DocViewport.getScrollY() + Math.max(Math.round((body_dimension.height - this.self.offsetHeight) / 2), 0) + 'px';
	}
}

Element.get = function(str_el)
{
	var element = document.getElementById(str_el);
	if (!element)
	{
		throw new Error('Element is not exist');
	}
	return new Element(element);
}
