function Class(){};

Class.prototype.construct = function(){};

Class.extend = function(def){

    var classDef = function(){

        if (arguments[0] !== Class){

		this.construct.apply(this, arguments);
	};  
    };

    var proto = new this(Class);    
    var superClass = this.prototype;

    for (var n in def){

        var item = def[n];

        if (item instanceof Function){

		item.$ = superClass;

	} else classDef[n] = item;

        proto[n] = item;
    };

    classDef.prototype = proto;
    classDef.extend = this.extend;

    return classDef;
};

function getEventTarget(e){
		
    var e = e || window.event;

    var targ = e.target || e.srcElement;

    return targ;
};

//Функция для запросов ajax

function makeRequest(url, parameters, onComplete, obj){

    var http_request = false;

    try{

        http_request = new ActiveXObject("Msxml2.XMLHTTP");

    } catch (e1){
       
	try {
            http_request= new ActiveXObject("Microsoft.XMLHTTP");

        } catch (e2){

            http_request = new XMLHttpRequest();
        };
    };

    if (!http_request){

      alert('Cannot create XMLHTTP instance');

      return false;
    };

    completeListener = function(){

        if (http_request.readyState == 4){

            if (http_request.status == 200){

                onComplete(http_request, obj);
            };
        };
    };

    var salt = Math.random();

    http_request.onreadystatechange = completeListener;

    http_request.open('GET', url + "?" + parameters + "&salt=" + salt, true);
    http_request.send(null);
};

//определение типа броузера и ОС

var USER_DATA = {

    Browser:{

        KHTML: /Konqueror|KHTML/.test(navigator.userAgent) && !/Apple/.test(navigator.userAgent),
        Safari: /KHTML/.test(navigator.userAgent) && /Apple/.test(navigator.userAgent),
        Opera: !!window.opera, 
	MSIE: !!(window.attachEvent && !window.opera),
        Gecko: /Gecko/.test(navigator.userAgent) && !/Konqueror|KHTML/.test(navigator.userAgent)
    },

    OS:{

        Windows: navigator.platform.indexOf("Win") > -1,
        Mac: navigator.platform.indexOf("Mac") > -1,
        Linux: navigator.platform.indexOf("Linux") > -1
    }
};

//Дополнительная функция определения вхождения элемента в массив

Array.prototype.inArray = function (value){
      
	var i;
        for (i=0; i < this.length; i++){

                if (this[i] === value){

                        return true;
                };
        };

        return false;
};


//Определение позиции элемента

Number.prototype.NaN0=function(){return isNaN(this)?0:this;};

var IS_IE = USER_DATA['Browser'].MSIE;

function getPosition(e){

    var left = 0;
    var top  = 0; 

    while (e.offsetParent){

        left += e.offsetLeft + (e.currentStyle ? (parseInt(e.currentStyle.borderLeftWidth)).NaN0() : 0); 

        top  += e.offsetTop  + (e.currentStyle ? (parseInt(e.currentStyle.borderTopWidth)).NaN0() : 0);

        e = e.offsetParent;
    };

    left += e.offsetLeft + (e.currentStyle ? (parseInt(e.currentStyle.borderLeftWidth)).NaN0() : 0); 

    top  += e.offsetTop  + (e.currentStyle ? (parseInt(e.currentStyle.borderTopWidth)).NaN0(): 0);

    return {x:left, y:top};
};

function getAlignedPosition(e) {

    var left = 0;
    var top  = 0;

    while (e.offsetParent){

        left += e.offsetLeft + (e.currentStyle ? (parseInt(e.currentStyle.borderLeftWidth)).NaN0() : 0);

        top  += e.offsetTop  + (e.currentStyle ? (parseInt(e.currentStyle.borderTopWidth)).NaN0() : 0);

        e  = e.offsetParent;

        if(e.scrollLeft){

		left -= e.scrollLeft;
	};

        if(e.scrollTop){

		top  -= e.scrollTop;

	};
    };

    var docBody = document.documentElement ? document.documentElement : document.body;

    left += e.offsetLeft + (e.currentStyle ? (parseInt(e.currentStyle.borderLeftWidth)).NaN0() : 0) +
        (IS_IE ? (parseInt(docBody.scrollLeft)).NaN0() : 0) - (parseInt(docBody.clientLeft)).NaN0();

    top  += e.offsetTop  + (e.currentStyle ? (parseInt(e.currentStyle.borderTopWidth)).NaN0() : 0) +
        (IS_IE ? (parseInt(docBody.scrollTop)).NaN0() : 0) - (parseInt(docBody.clientTop)).NaN0();

    return {x:left, y:top};
};

//Поиск высоты элемента

function findOffsetHeight(e){

    var res = 0;

    while ((res == 0) && e.parentNode){

        e = e.parentNode;
        res = e.offsetHeight;
    };

    return res;
};

//Функции работы с атрибутами элемента 

var IS_SAFARI = USER_DATA['Browser'].Safari;
var NS_SYMB = '_';

function getElmAttr(elm, attrName, ns){ 

    var elmValue = null;

    try{
        elmValue = (elm.getAttribute
                    ? elm.getAttribute((ns ? (ns + NS_SYMB) : '')
                    + attrName) : null);

    } catch (e){ 

	return null; 
    }

    if (!elmValue && IS_SAFARI){

        elmValue = (elm.getAttributeNS
                    ? elm.getAttributeNS(ns, attrName)
                    : null);
    };

    return elmValue;
};

function setElmAttr(elm, attrName, value, ns){

    if (!IS_SAFARI || !ns){

        return (elm.setAttribute ? elm.setAttribute((ns ? (ns + NS_SYMB) : '') + attrName, value) : null);

    } else {

        return (elm.setAttributeNS
                    ? elm.setAttributeNS(ns, attrName, value)
                    : null);
    };
};

//Функция поиска элемента по Id

function $(elementId){

	if(document.layers){
	
		if(typeof this.elementId == "string"){
			
			return document.layers(elementId);

		} else {
			
			return elementId;
		};
	};
	
	if(document.all){

		if(typeof elementId == "string"){
			
			if(document.all(elementId) != null){
					
				return document.all(elementId);
					
			} else {

				return null;
			};
	
		} else { 
				
			return elementId;
		};
	};
		
	if(document.getElementById){

		if(typeof elementId == "string"){

			return document.getElementById(elementId);
			
		} else {

			return elementId;
		};
	};

	return null;
}

function show(element){

      element.style.display = 'block';
}

function hide(element){



	if (element.style.display != 'none'){

		element.style.display  = 'none';
	};
}

function fixPNG(element)
{
	if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent))
	{
		var src;
		
		if (element.tagName=='IMG')
		{
			if (/\.png$/.test(element.src))
			{
				src = element.src;
				element.src = "/img/site/blank.gif";
			}
		}
		else
		{
			src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i);
			if (src)
			{
				src = src[1];
				element.runtimeStyle.backgroundImage="none";
			}
		}
		
		if (src) element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='crop')";
	}
}var ChangeMenuAndBlock = Class.extend({

	construct:function(conteinerId, menuId, objectId, oldId, type){ 
	
		var obj = this;
		var conteiner = $(conteinerId);
		
		this.menuId = menuId;
		this.objectId = objectId;
		this.oldId = 0;

		this._change(oldId);


		if(type){

			conteiner.onmouseover = function(e){obj.change(e)};
		
		} else {

			conteiner.onclick = function(e){obj.change(e)};		
		}		
	},

	change:function(e){

		var target = getEventTarget(e);
		
		if(!target){

			return false;
		};

		var id;
				
		if(target.id.indexOf(this.menuId) == 0){


			id = target.id.substr(this.menuId.length, 10);

			if(!id){

				return false;
			};
		
 		} else {

			return false;
		};
		
		this._change(id);
	},

	_change:function(id){

		var menuEl;
		var objectEl;

		if(this.oldId > -1){

			menuEl = $(this.menuId+this.oldId);
			objectEl = $(this.objectId+this.oldId);

			menuEl.className = '';
			hide(objectEl);
		};

		menuEl = $(this.menuId+id);
		objectEl = $(this.objectId+id);

		menuEl.className = 'current';
		show(objectEl);

		this.oldId = id;				
	}
});var IS_OPERA = USER_DATA['Browser'].Opera;

var MenuScroll = Class.extend({

	construct:function(conteinerId, rootId, childId, parametrs){

		var obj = this;
		var conteiner = $(conteinerId);

		this.rootId = rootId;
		this.childId = childId;

		if(IS_OPERA){

			parametrs.ox -= 8;
			parametrs.oy -= 4;
		}

		this.parametrs = parametrs;

		this.oldId = -1;
		this.timer = null;

		conteiner.onmouseover = function(e){obj.show(e)};
		conteiner.onmouseout = function(){obj.hide()};
	},

	show:function(e){

		var target = this.target;

		if(this.timer != null){

			clearTimeout(this.timer);
		}

		target = getEventTarget(e);

		if(!target){

			return false;
		}

		var id = 0;

		if(target.id.indexOf(this.rootId) > -1){


			id = target.id.substr(this.rootId.length, 10);

			if(!id){

				return false;
			}
		
 		} else {

			return false;
		}


		if(this.oldId > -1){

			this._hideChild();
		}

		var rootEl = $(this.rootId + id);
		var childEl = $(this.childId + id);
		
		var left = 0;
		var top  = 0;

		var rootElPos = getPosition(rootEl);

		if(!this.parametrs.type){
		
			left = parseInt(rootEl.offsetWidth);
		
		} else {

			top = parseInt(rootEl.offsetHeight);
		}

		childEl.style.top = parseInt(rootElPos.y)  - 2 + top + this.parametrs.oy + 'px';
		childEl.style.left = parseInt(rootElPos.x) + left + this.parametrs.ox + 'px';
	
		rootEl.className = 'current';
		show(childEl);

		this.oldId = id * 1;
	},

	hide:function(){

		if(this.oldId > -1){
		
			var obj = this;			
	
			this.timer = setTimeout(function(){obj._hideChild()}, this.parametrs.delay);
		}
	},

	_hideChild:function(){

		var oldRootEl = $(this.rootId + this.oldId);
		var oldChildEl = $(this.childId + this.oldId);

		hide(oldChildEl);
		oldRootEl.className = '';
		
		this.oldId = -1;
	}
});var LineScroll = Class.extend({

	construct:function(conteinerId, lineId, parametrs){

		var obj = this;
		var conteiner = $(conteinerId);

		this.parametrs = parametrs;

		this.line = $(lineId);
		
		if(this.parametrs.type){

			this.line.style.top = this.parametrs.offset + 'px';
		
		} else {

			this.line.style.left = this.parametrs.offset + 'px';
		}

		this.offset = this.parametrs.size / 10;
		this.parametrs.size = (-1) * this.parametrs.size + this.parametrs.offset;
		
		this.interval = false;
		this.timer = null;
		this.stop_scroll = false;

		conteiner.onmouseover = function(){obj.stop()};
		conteiner.onmouseout = function(){obj.start()};

		this._scroll();
	},

	stop:function(){

		this.stop_scroll = true;

		if(this.timer){

			clearTimeout(this.timer);
		}

	},

	start:function(){

		this.stop_scroll = false;
		this._timer();
	},

	_scroll:function(){

		var obj = this;

		if(this.timer){

			clearTimeout(this.timer);
		}

		if(!this.interval){

			this.interval = setInterval(function(){obj._scroll()}, 1);
		}

		if(this.parametrs.type && (this.line.offsetTop >= this.parametrs.size)){
			
			this.line.style.top = this.line.offsetTop - this.offset + 'px';
			return;
					
		} else if(!this.parametrs.type && (this.line.offsetLeft >= this.parametrs.size)){
			
			this.line.style.left = this.line.offsetLeft - this.offset + 'px';
			return;
		}

		clearInterval(this.interval);
		this.interval = false;
	
		this._move();
	},

	_move:function(){

		if(!IS_IE){

			if(this.line.firstChild instanceof Text){
		
				this.line.removeChild(this.line.firstChild);
			}
		}

		var element = this.line.firstChild.cloneNode(true);

		this.line.removeChild(this.line.firstChild);
		this.line.appendChild(element);
		
		if(this.parametrs.type){

			this.line.style.top = this.parametrs.offset + 'px';
			
		} else {

			this.line.style.left = this.parametrs.offset + 'px';
		}

		
		if(!this.stop_scroll){

			this._timer();
		}
	},

	_timer:function(){

		var obj = this;
		
		this.timer = setTimeout(function(){obj._scroll()}, this.parametrs.delay);
	}
});var LineScrollWithMenu = Class.extend({

	construct:function(conteinerId, lineId, menuId, controlId, parametrs){
		
		var obj = this;
		var conteiner = $(conteinerId);
		var menu = $(menuId);	

		this.controlId = controlId;
		this.parametrs = parametrs;
		
		this.line = $(lineId);

		if(this.parametrs.type){

			this.line.style.top = this.parametrs.offset;
		
		} else {


			this.line.style.left = this.parametrs.offset;
		}

		
		this.offset = this.parametrs.size / 4;

		this.curr = 0;
		this.last = 0;
		this.stop_scroll = false;
		this.scroll_timer = false;
		this.activate_timer = false;
		this.show_timer = false;
		this.interval = false;

		menu.onmouseover = function(e){obj.show(e)}
		menu.onmouseout  = function(){obj.start()} 

		conteiner.onmouseover = function(){obj.stop()}
		conteiner.onmouseout  = function(){obj.start()} 

		this._scroll();
	},

	_scroll:function(){

		if(this.stop_scroll){

			return;
		}
	
		++this.curr;

		if(this.curr >= this.parametrs.count){

			this.curr = 0;
		}

		var obj = this;

		this.scroll_timer = setTimeout(function(){obj._move()}, this.parametrs.delay);			
	},

	show:function(e){

		this.stop();

		var target = getEventTarget(e);
		
		if(!target){

			return;
		}

		var id = 0;

		if(target.id.indexOf(this.controlId) > -1){


			id = target.id.substr(this.controlId.length, 10);

			if(!id){

				return;
			}
		
 		} else {

			return;
		}
	

		this.curr = id;

		if(this.last != this.curr){

			if(this.show_timer){

				clearTimeout(this.show_timer);
				this.show_timer = false;
			}

			var obj = this;

			this.show_timer = setTimeout(function(){obj._move()}, 400);
		}		
	},

	_move:function(){

		if(!this.interval){

			var obj = this;
	
			this.interval = setInterval(function(){obj._move()}, 10);
		}


		if(this.parametrs.type){

			if(this.curr > this.last && 
			   this.line.offsetTop > ((-1) * this.parametrs.size * this.curr + this.parametrs.offset)){

				this.line.style.top = this.line.offsetTop - this.offset + 'px';
				return;		

			} else if(this.curr < this.last && 
				  this.line.offsetTop < ((-1) * this.parametrs.size * this.curr + this.parametrs.offset)) {

				this.line.style.top = this.line.offsetTop + this.offset + 'px';
				return;			
			} 
		
		} else {


			if(this.curr > this.last && 
			   this.line.offsetLeft > ((-1) * this.parametrs.size * this.curr + this.parametrs.offset)){

				this.line.style.left = this.line.offsetLeft - this.offset + 'px';
				return;		

			} else if(this.curr < this.last && 
				  this.line.offsetLeft < ((-1) * this.parametrs.size * this.curr + this.parametrs.offset)) {

				this.line.style.left = this.line.offsetLeft + this.offset + 'px';
				return;			
			} 
		}

		clearInterval(this.interval);
		this.interval = false;

		this._changeControl();
		this.last = this.curr;

		if(!this.stop_scroll){

			this._scroll();
		}
	},

	_changeControl:function(){

		var control = $(this.controlId + this.last);
		control.className = '';			

		control = $(this.controlId + this.curr);
		control.className = 'current';
	},

	stop:function(){

		this.stop_scroll= true;

		if(this.scroll_timer){

			clearTimeout(this.scroll_timer);
			this.timer = false;
		}

		if(this.activate_timer){
		
			clearTimeout(this.activate_timer);
			this.activate_timer = false;
		}
	},

	start:function(){

		var obj = this;
		
		this.activate_timer = setTimeout(function(){obj._activate()}, this.parametrs.delay);
	},

	_activate:function(){

		this.stop_scroll = false;
		
		if(this.show_timer){
		
			clearTimeout(this.show_timer);
			this.show_timer = false;
		}

		this._move();
	}
});var InputChange = Class.extend({ 

	construct:function(elements){

		this.values = Array();
		this.changed = Array();

		var element;
		var obj = this;

		for(var i in elements){

			element = $(elements[i]);

			element.className = 'current';

			this.values[elements[i]] = element.value;			
			this.changed[elements[i]] = false;

			element.onfocus = function(e){obj.change(e)};
			element.onblur = function(e){obj.change(e)};
		}
	},

	change:function(e){

		var target = getEventTarget(e);

		if(!target){

			return;
		}

		if(!this.changed[target.id]){

			target.value = '';
			target.className = '';

			this.changed[target.id] = true;
		
		} else if(!target.value.match(/[^\s]/g)){
			
			target.value = this.values[target.id];
			target.className = 'current';
			
			this.changed[target.id] = false;
		}
	}
});var ChangeNewsBlock = Class.extend({

	construct:function(conteinerId, menuId, blockId, newsMenuId, newsId){
		
		var conteiner = $(conteinerId);
		var obj = this;

		this.menuId = menuId;
		this.blockId = blockId;
		this.newsMenuId = newsMenuId;	
		this.newsId = newsId;

		this.lastMId = 0;
		this.lastNId = '00';

		conteiner.onclick = function(e){obj.change(e)};
	},

	change:function(e){

		var target = getEventTarget(e);
		
		if(!target){

			return false;
		};

		var id;

		if(target.id.indexOf(this.menuId) == 0){

			id = target.id.substr(this.menuId.length, 10);

			if(!id){

				return;
			};


			var root = $(this.menuId + this.lastMId);
			var block = $(this.blockId + this.lastMId);
			
			hide(block);			
			root.className = '';

			block = $(this.blockId + id);
			show(block);
			target.className = 'current';

			var child = $(this.newsMenuId + this.lastNId);
			child.className = '';
			child = $(this.newsMenuId + this.lastMId + '0');
			child.className = 'current';

			var news = $(this.newsId + this.lastNId);
			hide(news);
			news = $(this.newsId + this.lastMId + '0');
			show(news);

			this.lastNId = id + '0';
			this.lastMId = id;
		
		} else if(target.id.indexOf(this.newsMenuId) == 0){	


			id = target.id.substr(this.newsMenuId.length, 10);

			if(!id){

				return;
			};

			var child = $(this.newsMenuId + this.lastNId);
			child.className = '';	

			var news = $(this.newsId + this.lastNId);
			hide(news);
			news = $(this.newsId + id);
			show(news);

			target.className = 'current';

			this.lastNId = id;
		}			

	}
});var MenuScrollDown = Class.extend({

	construct:function(conteinerId, controlId, contentId, blockId, parametrs){

		var obj = this;
		var conteiner = $(conteinerId);

		this.delay = parametrs.delay;
		this.controlId = controlId;
		this.contentId = contentId;
		this.blockId = blockId;

		this.last = 0;
		this.timer = null;

		conteiner.onmouseover = function(e){obj.show(e)};
	},

	show:function(e){
	
		if(this.timer){

			clearTimeout(this.timer);
			this.timer = null;
		}

		var target = getEventTarget(e);
		
		if(!target){

			return;
		}

		var id = 0;

		if(target.id.indexOf(this.controlId) > -1){


			id = target.id.substr(this.controlId.length, 10);

			if(!id){

				return;
			}
		
 		} else {

			return;
		}

		this._hide();

		var content = $(this.contentId + id);
		var block = $(this.blockId + id);

		show(block);
		content.className = 'current';

		this.last = id;		
	},

	hide:function(){

		var obj = this;

		this.timer = setTimeout(function(){obj._hide()}, this.delay);
	},

	_hide:function(){

		if(this.last >= 0){

			var content = $(this.contentId + this.last);
			var block = $(this.blockId + this.last);

			hide(block);
			content.className = '';
	
			this.last = -1;
		}
	}
});var CurrencyConverter = Class.extend({

	construct:function(formId, resultId){


		this.form = $(formId);

		var obj = this;
		this.form.convert.onclick = function(){obj.convert()};
		this.form.amount.onkeypress = function(){return obj.enterNumber(event)};
		this.resultId = resultId;

		this.dot = true;
	},

	convert:function(){


		makeRequest("/ajax/converter/", "from=" + this.form.from.value + 
						"&to=" + this.form.to.value + 
						"&amount=" + this.form.amount.value +
						"&ajax_check=" + this.form.ajax_check.value, this.show, this);
	
		this.form.from.disabled = true;
		this.form.to.disabled = true;
		this.form.amount.disabled = true;
		this.form.convert.disabled = true;
	},
	
	enterNumber:function(event){
	
		var charCode;

		if(event.charCode){
	
			charCode = event.charCode;

		} else if(event.keyCode){
	
			 charCode = event.keyCode;
	
		} else if(event.which){ 
	
			charCode = event.which;

		} else {

			charCode = 0;
		}


		if((charCode == 44 || charCode == 46) && 
		    this.form.amount.value != "" && 
		   (this.form.amount.value.indexOf(".") < 0 && this.form.amount.value.indexOf(",") < 0)){

			this.dot = false;

		} else {

			this.dot = true;
		}
	
		if(this.dot && (charCode > 31 && (charCode < 48 || charCode > 57))){

			return false;
		}
	},

	 
	show:function(result, obj){
		
		var conteiner = $(obj.resultId);
		var index = 0;

		obj.form.from.disabled = false;
		obj.form.to.disabled = false;
		obj.form.amount.disabled = false;
		obj.form.convert.disabled = false;

		arr = result.responseText.split("&");
		
		if(arr[0].indexOf("error") == 0){
		
			var value = "";
	
			index = arr[0].indexOf("=");
			value = arr[0].substr(index + 1, arr[0].length);
								
			conteiner.innerHTML = "<div class=\"error\">" + value + "</div>";
			show(conteiner);			

		} else {

			var value = Array();

			for(var i = 0; i < arr.length; i++){
			
				index = arr[i].indexOf("=");
				value[i] = arr[i].substr(index + 1, arr[i].length);				
			}

			conteiner.innerHTML = "<div class=\"action\">"+value[0] + "</div>";
			conteiner.innerHTML += value[1] + " <span>" + value[2] + "</span>";					

			show(conteiner);	
		}		
	}
});var ChengeBackground = Class.extend({

	construct:function(conteinerId){

		var obj = this;
		var conteiner = $(conteinerId);
		
		this.conteinerId = conteinerId;

		conteiner.onmouseover = function(e){obj.show(e)};
		conteiner.onmouseout = function(e){obj.hide(e)};
	},

	show:function(e){

		var target = this._getLi(e);
		
		if(target.tagName != "LI"){

			return;
		}

		target.className = 'current';
	},

	hide:function(e){

		var target = this._getLi(e);
		
		if(target.tagName != "LI"){

			return;
		}

		target.className = '';
	},


	_getLi:function(e){

		var target = getEventTarget(e);

		if(target.id == this.conteinerId){

			return false;
		
		}

		while(target.tagName != "LI"){

			target = target.parentNode;
			
		}		


		return target;
	}
});var cid = 0;

var AjaxList = Class.extend({

	construct:function(objName, conteiner){

		this.objName = objName;
		this.Elements = Array();
		
		this.Category  = $('CategoryID');
		this.Conteiner = $(conteiner);
		
		this.lastid = 0;
	},
	
	makeReq:function(cur_id, cid, obj){
	
		this._deleteElements(cur_id);
		
		this.Category.value = cid;

		if(cid != "0"){

			makeRequest("/ajax/list/", "cid=" + cid + "&ajax_check=" + ajax_check, this.addList, obj);
		}
	},

	addList:function(result, obj){

		if(result.responseText == "0"){
		
			return false;
		}
		
		obj.Category.value = "0";
		
		arr = result.responseText.split("|"); 
		
		arr_result = Array();
			
		for(i = 0; i < arr.length-1; i++){

			arr_elem = arr[i].split(":"); 
			arr_result[i] = arr_elem;
		}

		obj._addElement(arr_result);
		
	},
	
	_addElement:function(arr){
	
		this.lastid++;
		
		this.Elements[this.lastid] = document.createElement("<select onchange=\""+this.objName+".makeReq("+this.lastid+", this.value, catSel)\">");
		
		list_element = document.createElement("<option value=\"0\">");
		list_element.innerHTML =  "Р’С‹Р±РµСЂРёС‚Рµ РєР°С‚РµРіРѕСЂРёСЋ";
		
		this.Elements[this.lastid].appendChild(list_element);
		
		for(i=0; i < arr.length; i++){
		
			list_element = document.createElement("<option value=\""+arr[i][0]+"\">");
			list_element.innerHTML =  arr[i][1];
			
			this.Elements[this.lastid].appendChild(list_element);
		}
		
		this.Conteiner.appendChild(this.Elements[this.lastid]);
	},

	_deleteElements:function(cur_id){
	
		if(cur_id == this.lastid){
		
			return false;
		}		
		
		for(i=cur_id+1; i <= this.lastid; i++){
		
			this.Conteiner.removeChild(this.Elements[i]);
			this.Elements[i] = null;
		}
		
		this.lastid = cur_id;
	}
	
});var ChangeSearch = Class.extend({

	construct:function(conteinerId, menuId, objectId, glaryId, oldId, type){ 
	
		var obj = this;
		var conteiner = $(conteinerId);
		
		this.menuId = menuId;
		this.objectId = objectId;
		this.glaryId = glaryId;
		this.oldId = 0;

		this._change(oldId);


		if(type){

			conteiner.onmouseover = function(e){obj.change(e)};
		
		} else {

			conteiner.onclick = function(e){obj.change(e)};		
		}		
	},

	change:function(e){

		var target = getEventTarget(e);
		
		if(!target){

			return false;
		};

		var id;
				
		if(target.id.indexOf(this.menuId) == 0){


			id = target.id.substr(this.menuId.length, 10);

			if(!id){

				return false;
			};
		
 		} else {

			return false;
		};
		
		this._change(id);
	},

	_change:function(id){

		var menuEl;
		var objectEl;

		if(this.oldId > -1){

			menuEl = $(this.menuId+this.oldId);
			objectEl = $(this.objectId+this.oldId);
			glary = $(this.glaryId+this.oldId);

			menuEl.className = '';
			hide(objectEl);
			hide(glary);
		};

		menuEl = $(this.menuId+id);
		objectEl = $(this.objectId+id);
		glary = $(this.glaryId+id);

		menuEl.className = 'current';
		show(objectEl);
		show(glary);
		
		this.oldId = id;				
	}
});var ScrollSoc = Class.extend({

	construct:function(conteinerId, lineId, menuId, parametrs){
		
		var obj = this;
		var conteiner = $(conteinerId);
		var menu = $(menuId);	

		this.parametrs = parametrs;
		
		this.line = $(lineId);
		this.line.style.left = this.parametrs.offset;
		
		this.interval = null;
		
		this.offset = Math.floor(conteiner.offsetWidth / 6);

		menu.onclick  = function(e){obj.scroll(e)};

		this.counter = 0;
		this.conteiner_w = conteiner.offsetWidth;
	},

	scroll:function(e){

		if(this.interval){
			
			return;	
		}

		var target = getEventTarget(e);
		
		if(!target || target.id == this.menuId){

			return;
		}

		if((target.className == "r") && ((this.line.offsetWidth + this.line.offsetLeft) > this.conteiner_w)){
			
			this.counter--;
			this.move(1);			
		
		} else if((target.className == "l") && (this.line.offsetLeft < this.parametrs.offset)){
			
			this.counter++;
			this.move(0);	
		}
	},
	
	move:function(type){

		if(!type){
			
			
			if((this.counter*this.conteiner_w) <= parseInt(this.line.style.left)){
				
				clearInterval(this.interval);
				this.interval = null;
				
				this.line.style.left = this.line.offsetLeft - 2 + this.parametrs.offset + 'px';
				
				return;
			}

			this.line.style.left = this.line.offsetLeft + 1 + this.offset + 'px';
		
		} else {
			
			if((this.counter*this.conteiner_w) >= parseInt(this.line.style.left)){
				
				clearInterval(this.interval);
				this.interval = null;
				
				this.line.style.left = this.line.offsetLeft - 2 + this.parametrs.offset + 'px';

				return;
			}			
			
			
			
			this.line.style.left = this.line.offsetLeft - this.offset + 'px';	
		}
		
		if(!this.interval){
			
			var obj = this;
			
			this.interval = setInterval(function(){obj.move(type)}, 100);
		}
		
		
	}
});var ChangeSelect = Class.extend({

	construct:function(selectId, inputId, listId, valueId){ 
	
		var obj = this;
		var select = $(selectId);
			
		this.listId = listId;
		this.valueId = valueId;
		this.inputId = inputId;

		this.timer = null;

		select.onclick = function(e){obj.show(e)};	
		select.onmouseover = function(){obj.not_hide()};
		select.onmouseout = function(){obj.hide()};		
	},

	show:function(e){

		if(this.timer){
			
			clearTimeout(this.timer);
			this.timer = null;
		}

		var list = $(this.listId);

		if(list.style.display == 'none'){
			
			list.style.display = 'block';	
		
		} else {
			
			list.style.display = 'none';
			
			var target = getEventTarget(e);
			
			if(!target){
				
				return;	
			}
			
			if(target.tagName == "A" && target.className != "button"){
				
				var input = $(this.inputId);
				var value = $(this.valueId);
				
				input.innerText = target.innerText;
				value.value = target.id;
			}
		}		
	},
	
	not_hide:function(){
		
		if(this.timer){
			
			clearTimeout(this.timer);
			this.timer = null;
		}		
	},
	
	hide:function(){
		
		var obj = this;
		
		this.timer = setTimeout(function(){obj._hide()}, 500);	
	},
	
	_hide:function(){
		
		var list = $(this.listId);

		list.style.display = 'none';
		
		this.timer = null;
	}
});var SendForm = Class.extend({

	construct:function(formId, parametrs){
	
		this.form = $(formId);
		this.parametrs = parametrs;

		var obj = this;

		this.form.control.onclick = function(){obj.send()};	
	},

	send:function(){

		var query = "";

		for(var i = 0; i < this.form.elements.length; i++){

			query += this.form.elements[i].name+"="+this.form.elements[i].value+"&";		
			
			this.form.elements[i].disabled = true;
		}

		makeRequest(this.parametrs.url, query, this.result, this);
	},
	
	result:function(res, obj){

		var arr = res.responseText.split("\n");

		for(var i = 0; i < obj.form.elements.length; i++){

			obj.form.elements[i].disabled = false;

			if(arr[0] == 'OK' && (obj.form.elements[i].type == 'text' || obj.form.elements[i].type == 'password' || obj.form.elements[i].type == 'select'  || obj.form.elements[i].type == 'textarea')){

				obj.form.elements[i].value = "";
			}
		}

	
		if(obj.parametrs.output == 'alert'){
		
			var str = res.responseText.slice(arr[0].length + 1);		
	
			alert(str);
			
		} else if(obj.parametrs.output == 'id') {

			var str = res.responseText.slice(arr[0].length + 1);
			var conteiner = $(obj.parametrs.id);

			conteiner.innerHTML = str;
		
		} else {

			eval(obj.parametrs.method+"(arr)");
		}
	}
});var ChengeBackgroundForTable = Class.extend({

	construct:function(conteinerId){

		var obj = this;
		var conteiner = $(conteinerId);
		
		this.conteinerId = conteinerId;
		this.oldClassName = '';
		this.targetTAG = 'TR';

		conteiner.onmouseover = function(e){obj.show(e)};
		conteiner.onmouseout = function(e){obj.hide(e)};
	},

	show:function(e){

		var target = this._getTAG(e);

		if((target.tagName != this.targetTAG)||(target.className=='table-header')||(target.className=='table-footer')){

			return;
		}
		
		this.oldClassName = target.className;
		target.className = 'current';
	},

	hide:function(e){

		var target = this._getTAG(e);
		
		if((target.tagName != this.targetTAG)||(target.className=='table-header')||(target.className=='table-footer')){

			return;
		}

		target.className = this.oldClassName;
	},


	_getTAG:function(e){

		var target = getEventTarget(e);

		if(target.id == this.conteinerId){

			return false;
		
		}

		while(target.tagName != this.targetTAG){

			target = target.parentNode;
			
		}		

		return target;
	}
});var CheckBoxesControl = Class.extend({

	construct:function(formId, masterId){

		var obj = this;

		this.form = $(formId);
		this.masterId = masterId;
				

		this.form.onclick = function(e){obj.markAll(e)};
	},
	
	markAll:function(e){
		
		var target = getEventTarget(e);
		
		if(target.id == this.masterId && target.checked){
					
			for(i = 0; i < this.form.elements.length; i++){
				
				if(this.form.elements[i].type == 'checkbox'){
					this.form.elements[i].checked = true;
				}					
			}
		} else if (target.id == this.masterId && !target.checked) {
			
			for(i = 0; i < this.form.elements.length; i++){
				
				if(this.form.elements[i].type == 'checkbox'){
					this.form.elements[i].checked = false;
				}					
			}
		}
	}

});function message(mes, obj){

	alert(mes.responseText);
	
}

function alertMessage(mes, obj){

	obj.disabled = false;
	alert(mes.responseText);
}

function cartMessage(mes, obj){

	arr = mes.responseText.split("\n");

	if(arr[0] == "OK"){

		cart_obj = $('cart-count');
		cart_obj.innerText = cart_obj.innerText*1 + 1;
	}

	alert(arr[1]);
}

function bookmark(id, type){

	makeRequest("/ajax/bookmark/", "type=" + type + "&id=" + id + "&ajax_check=" + ajax_check, message);
}

function cart(id){

	makeRequest("/ajax/cart/", "id=" + id + "&ajax_check=" + ajax_check, cartMessage);

}

function changeAlert(id, select) {

	select.disabled = true;
	makeRequest("/ajax/change_alert/", "period=" + select.value + "&id=" + id + "&ajax_check=" + ajax_check, alertMessage, select);
}

function cCode(mes, obj){
	
	for(var i = 1; i< 4; i++ ){

		$('c_code'+i).innerHTML = "+" + mes.responseText;
	}
}

function changeCode(id){

	query = "id=" + id + "&ajax_check=" + ajax_check;

	makeRequest("/ajax/get_code/", query, cCode);
}

var MenuCloseOpen = Class.extend({

	construct:function(containerId, controlId, controlledId, params){

		var obj = this;
		var conteiner = $(containerId);

		this.containerId = containerId;
		this.controlId = controlId;
		this.controlledId = controlledId;
				
		this.oldControlled = params.oldId;
		this.active = params.active;						

		conteiner.onclick = function(e){obj.click(e)};
	},

	click:function(e){

		var target = getEventTarget(e);
		
		if(this.controlId == target.id.substr(0, this.controlId.length)){

			var id = target.id.substr(this.controlId.length);

			var old_c  = $(this.controlledId + this.oldControlled);
			
			if(id == this.oldControlled && old_c.style.display == 'block'){

				hide(old_c);
				if(this.active) $(this.controlId + id).className = '';
			
			} else if(id == this.oldControlled){

				show(old_c);
				if(this.active) $(this.controlledId + id).className = 'current';
			
			} else {

				if(this.active) $(this.controlId + id).className = 'current';
				if(this.active) $(this.controlId + this.oldControlled).className = '';
			
				hide(old_c);
				show($(this.controlledId + id));

				this.oldControlled = id;
			}			
		}
	}
});
