var Main = {
	is_debug: false,
	showDebug: function(msg){
		if(this.is_debug == true){
			alert(msg);
		}
	},
	showAlert: function(text, handler, scope, no_mask){
		if(!this.alert_win){
			if(!no_mask) no_mask = false;
			this.alert_win = new Main.Window({"width": 350, "no_mask": no_mask});
		}
		var content = new Element("div", {"class": "confirm-win"});

		content.insert(new Element("div", {"class": "message1"}).update(text));


		var ok_btn = new Element("input", {"class": "big-btn", "type": "button"});
		ok_btn.setValue("Хорошо");
		ok_btn.observe("click", this.closeAlertWin.bind(this));
		content.insert(ok_btn);
		this.alert_win.addDomContent(content);
		this.alert_win.okhandler 	= handler;
		this.alert_win.scope		= scope;
		this.alert_win.show();
		ok_btn.focus();
	},
	closeAlertWin: function(){
		var w = this.alert_win;
		var f = null;
		if (w.okhandler) {
			f = w.okhandler;
		}
		if (typeof f == 'function') {
			if (w.scope) {
				f.apply(w.scope);
			} else {
				f();
			}
		}
		this.alert_win.hide();
	},
	showConfirm: function(text, okhandler, closehandler, scope){
		if(!this.win){
			this.win = new Main.Window({"width": 350});
		}
		var content = new Element("div", {"class": "confirm-win"});

		content.insert(new Element("div", {"class": "message1"}).update(text));


		var ok_btn = new Element("input", {"class": "big-btn", "type": "button"});
		ok_btn.setValue("Да");
		ok_btn.observe("click", this.closeConfirmWin.bind(this, true));
		content.insert(ok_btn);

		var cancel_btn = new Element("input", {"class": "btn", "type": "button"});
		cancel_btn.setValue("Нет");
		cancel_btn.observe("click", this.closeConfirmWin.bind(this));
		content.insert(cancel_btn);

		this.win.addDomContent(content);
		this.win.okhandler 	= okhandler;
		this.win.closehandler 	= closehandler;
		this.win.scope			= scope;
		this.win.show();
	},
	closeConfirmWin: function(el, btn){
		var w = this.win;
		var f = null;
		if (btn && w.okhandler) {
			f = w.okhandler;
		} else if (w.closehandler){
			f = w.closehandler;
		}
		if (typeof f == 'function') {
			if (w.scope) {
				f.apply(w.scope);
			} else {
				f();
			}
		}
		this.win.hide();
	},
	redirect: function(loc){
		document.location = loc;
	},
	apply: function(o, c, defaults){
	    if(defaults){
	        Main.apply(o, defaults);
	    }
	    if(o && c && typeof c == 'object'){
	        for(var p in c){
	            o[p] = c[p];
	        }
	    }
	    return o;
	},
	_mask_remover: function(el) {
    	if(el.mask_element_exist){
	    	el.mask_element_exist = null;
	    	el.mask_element.remove();
    	}
    },
	_loadMask: function(el, load){
		if(Prototype.Browser.IEVersion == 6){
			return false;
		}
		if(typeof el != "object"){
			el = $(el);
		}
		if(!el){
			Main.showDebug("FATAL - Element not found");
		}

		if(load){
			if(!el.mask_element_exist)	{
				el.setStyle({"position": "relative"});
				if(!this.mask_id){
					this.mask_id = 0;
				}else{
					this.mask_id++;
				}
				el.mask_element_exist = "mask_"+this.mask_id;
				var element_loader=new Element("div", {"id": el.mask_element_exist});
				el.mask_element = element_loader;

				var h = el.getHeight();
				var w = el.getWidth();
		        element_loader.setStyle({
		                'height':h+"px",
		                'width':w+"px",
		                'text-align':'center',
		                'background':'#EEEEEE',
		                'position'    :'absolute',
		                'top'        :'0px',
		                'left'        :'0px',
		                'filter'    :'alpha(opacity=10)',
		                '-moz-opacity':'0.5',
		                'opacity'    :'0.5',
		                'z-index'	: '1000'
		        });
		        h = h/2;
		        element_loader.update('<img style="margin: 0 auto; display: block; margin-top:'+(h)+'px;" src="'+js_url+'images/waiting.gif" alt="Load..." />');
		        el.insert(element_loader);
			}
			$(el.mask_element_exist).show();
		} else {
			$(el.mask_element_exist).hide();
		}
	},
	rList: [],
	onReady: function(fn, scope) {
		if (scope) {
			this.rList.push(fn.bind(scope));
		} else {
			this.rList.push(fn);
		};
	},
	_onPLoad: function() {
		for(var i=0; i<this.rList.length; i++) {
			this.rList[i]();
		}
	},
	// ----- Request Functionality ----------------
	request: function(url, params){

		if(!url || url == ""){
			Main.showAlert("FATAL - URL not found");
			return false;
		}

		function _onRequestComplete(jsonObj, response){
			if (jsonObj) {
				//var msg_text = null;
				//if (jsonObj.messages) {
				//	var m = jsonObj.messages;
				//	if (m instanceof Array) {
				//		msg_text = m.join("<br />");
				//	}
				//}

					if (jsonObj.is_error == true) {
							_internalOnFail(jsonObj, response);
					} else {
							_internalOnSuccess(jsonObj, response);
					}
			} else if(response){
				_internalOnSuccess(false, response);
			}else{
				var req_fail = "This request has failed.  Please try later.";
				Main.showDebug(req_fail, "Error",
					_internalOnFail( jsonObj, response)
				);
			}
		}

			function _internalOnSuccess(result, response) {
				if (!params ||  !params['onSuccess']) return false;
				var f = params['onSuccess'] ? params['onSuccess'] : null;
				if (f && typeof f == 'function') {
					if (params['scope']) {
						f.apply(params['scope'], arguments);
					} else {
						f(result, response);
					}
				}
			};

		function _internalOnFail(result, response) {
			if (!params || !params['onFail']) return false;
			var f = params['onFail'] ? params['onFail'] : null;
			if (f && typeof f == 'function') {
				if (params['fscope']) {
					f.apply(params['fscope'], arguments);
				} else {
					f(result, response);
				}
			}
		};

		var p = (params && params.parameters) ? params.parameters : null;
		var requestData = new Ajax.Request(url,{
		method: 'post',
		parameters: p,
			onComplete: function(transport, json) {
				if(transport.responseText == "LOGOUT"){
					document.location = "logout.php";
				}
				var js = false;
				if(json && json.is_json == true){
					eval("js=" + transport.responseText)
				}
				_onRequestComplete(js, transport.responseText);
			}
		})
	},
	btn: function(){
		var m_btns = document.getElementsByClassName('m_btn');
		for(var i=0; i < m_btns.length; i++){
			m_btns[i].observe("mouseover", function(ev){
				ev.target.className = "m_btn-over";
			});
			m_btns[i].observe("mouseout", function(ev){
				ev.target.className = "m_btn";
			});
		}
		var s_btns = document.getElementsByClassName('s_btn');
		for(var i=0; i < s_btns.length; i++){
			s_btns[i].observe("mouseover", function(ev){
				ev.target.className = "s_btn-over";
			});
			s_btns[i].observe("mouseout", function(ev){
				ev.target.className = "s_btn";
			});
		}
		var l_btns = document.getElementsByClassName('l_btn');
		for(var i=0; i < l_btns.length; i++){
			l_btns[i].observe("mouseover", function(ev){
				ev.target.className = "l_btn-over";
			});
			l_btns[i].observe("mouseout", function(ev){
				ev.target.className = "l_btn";
			});
		}

	},
	chache_states: {},
	onChangeCountry: function(c_selector, state_selector_id, mask_el) {
		var country_id = c_selector.value;

		var state_selector = $(state_selector_id);
		if(country_id == -1){
			var newOpt = new Option("Any","-1");
			state_selector.add(newOpt, null);
			return false;
		}
		if (state_selector) {
			if (this.chache_states && this.chache_states[country_id]) {
				this.updateStateSelector(state_selector, this.chache_states[country_id]);
			} else {
				this.current_state_selector = state_selector;
				this.current_mask_el = mask_el ? mask_el : null;
				if (this.current_mask_el) {
					Main._loadMask(this.current_mask_el, true);
				}
				Main.request("ajax_getstates_list.php", {
					parameters: {country_id: country_id},
					onSuccess: function(json, response){
						var list = null;
						if (json && json['country_id'] > 0) {
							if (json['data']) {
								list = json['data'];
							}
							this.chache_states[json['country_id']] = list;
						}
						this.updateStateSelector(this.current_state_selector, list);
						if (this.current_mask_el) {
							Main._loadMask(this.current_mask_el, false);
						}
					},
					scope: this
				});
			}
		}
	},

	updateStateSelector: function(selector, list) {
		if (!selector) return null;
		var l = [];
		if (list) {
			for(var i in list) {
				l.push({v: i, t: list[i]});
			}
		}

		if (l.length == 0) {
			selector.disabled = true;
			return true;
		}

		while(selector.options.length > 0) {
			selector.remove(0);
		}
		for(var i=0; i<l.length; i++) {
			var newOpt = new Option(l[i].t, l[i].v);
			try {
    			selector.add(newOpt, null);
  			}
			catch(ex) {
				selector.add(newOpt); // IE only
			}
		}
		selector.selectedIndex = 0;
	},
	preloadImages: function(arr){
		for(var i=0; i < arr.length; i++){
			$("preloader").insert(new Element("img", {"src": arr[i]}));
		}
	}
};

Main.ajaxForm = function(config) {
	Main.apply(this, config);
	this.init();
};

Main.ajaxForm.prototype = {

	form: null,

	inputErrorClass: 'field-invalid',

	divErrorClass: 'error',

	listeners: null,

	mask_element: null,

	hide_mask: true,

	init: function() {
		var f = $(this.form);
		if (!f) {
			Main.showDebug('FATAL - FORM element not found!!');
			return false;
		}
		if(!this.mask_element){
				this.mask_element = this.form;
		}

		f.onsubmit = this._onSubmit.bind(this);
		this.form = f;
		var m = this.form.elements;
		var map = {};
	},
	_onSubmit: function() {
		Main._loadMask(this.mask_element, true);
		Main.request(this.form.action,{
			parameters: this.form.serialize(true),
			onSuccess: function(json){
				this._onRequestComplete(json);
			},
			onFail: function(json){
				this._onRequestComplete(json);
			},
			scope: this,
			fscope: this
		})
		return false;
	},
	_onRequestComplete: function(jsonObj) {
		if (jsonObj) {
			var msg_text = null;
			if (jsonObj.messages) {
				var m = jsonObj.messages;
				if (m instanceof Array) {
					msg_text = m.join("<br />");
				} else if (jsonObj.is_error == true) {
					this._setupErrors(m);
				} else {
					this.resetErrors();
				}
			}
			if (msg_text) {
				if (jsonObj.is_error == true) {
					Main.showAlert(msg_text,
						this._internalOnFail.bind(this, jsonObj)
					);
					//this._internalOnFail(jsonObj);
				} else {
					this.resetErrors();
					Main.showAlert(msg_text,
						this._internalOnSuccess.bind(this, jsonObj)
					);
					//this._internalOnSuccess(jsonObj);
				}
			} else {
				if (jsonObj.is_error == true) {
					this._internalOnFail(jsonObj);
				} else {
					this._internalOnSuccess(jsonObj);
				}
			}
		} else {
			var req_fail = "Request is fail. Please, try later.";
			//Main.showAlert(req_fail, "Error",
			//	this._internalOnFail.bind(this, jsonObj)
			//);
			this._internalOnFail(jsonObj);
		}
		if(this.hide_mask){
			Main._loadMask(this.mask_element, false);
		}
	},

	_internalOnSuccess: function(result) {
		if (!this.listeners) return false;
		var f = this.listeners['onSuccess'] ? this.listeners['onSuccess'] : null;
		if (f && typeof f == 'function') {
			if (this.listeners['scope']) {
				f.apply(this.listeners['scope'], arguments);
			} else {
				f(result);
			}
		}
	},

	_internalOnFail: function(result) {
		if (!this.listeners) return false;
		var f = this.listeners['onFail'] ? this.listeners['onFail'] : null;
		if (f && typeof f == 'function') {
			if (this.listeners['scope']) {
				f.apply(this.listeners['scope'], arguments);
			} else {
				f(result);
			}
		}
	},

	_setFieldState: function(field, is_valid, mes) {
		if (!is_valid) {
			if (!field.error_div) {
				var p = field.parentNode;
				var d = document.createElement("div");
				d.className = this.divErrorClass;
				p.appendChild(d);
				field.error_div = d;
			} else {
				field.error_div.style.display = '';
			}
			field.error_div.innerHTML = mes;
			if(!field.is_invalid){
				field.begining_class = field.className;
				field.className += " "+this.inputErrorClass;
				field.is_invalid = true;
			}
		} else if(field.is_invalid) {
				field.is_invalid = false;
				field.error_div.style.display = 'none';
				field.className = field.begining_class;
		}
	},
	_getFieldsMap: function() {
		if (!this.fieldsMap) {
			var m = this.form.elements;
			var map = {};
			for(var i=0; i<m.length; i++) {
				if (m[i].tagName == 'FIELDSET'  || m[i].type == "reset" || m[i].type == "hidden" || m[i].type == "button" || m[i].type == "submit" || m[i].type == "image" || m[i].type == "radio") {
					continue;
				}
				var data_key = this.getFieldDataKey(m[i]);
				if (data_key) {
					if (map[data_key]) {
						Main.showDebug('already_set' + data_key);
					} else {
						map[data_key] = m[i];
						var error_div_id = m[i].getAttribute("error_div_id");
						if (error_div_id) {
							var error_div = document.getElementById(error_div_id);
							if (error_div) {
								m[i].error_div = error_div;
							}
						}
					}
				} else {
					Main.showDebug('Cant get ' + m[i].name + m[i].type);
				}
			}
			this.fieldsMap = map;
		}

		return this.fieldsMap;
	},
	getFieldDataKey: function(field) {
		var res = field.getAttribute("_dataIndex");
		if (!res) {
			res = field.name.replace(/(?:.*\[)(.*)(?:\])/, "$1");
		}
		return res;
	},

	resetErrors: function() {
		this._setupErrors({});
	},

	reset: function() {
		this.form.reset();
		this._setupErrors({});
	},

	_setupErrors: function(mesages){
		var m = this._getFieldsMap();
		for(var name in m) {
			if (mesages[name]) {
				this._setFieldState(m[name], false, mesages[name]);
			} else {
				this._setFieldState(m[name], true);
			}
		}
	},
	submit: function() {
		this._onSubmit();
	}
};

// *************************** Prototype  GRID **************************
/*
  		Example of use :

  	 	 var config = {
			url : "ajax_search_users.php",
			content_container: "search_users_box",
			mask_element: "mask_container",
			limit: public_num_rows,
			template: new Template('<div class="f_l userbox">' +
				'<a href="profile.php?user_id=#{user_id}"><div class="shadow"><div class="shadow_inner"><img src="#{picture}" alt="#{username}" /></div></div></a></div>')
		};
		new Main.grid(config);
 */


Main.grid = function (config) {
	Main.apply(this, config);
	this.init();
}

Main.grid.prototype = {
	limit: 10, // Count records on the one page is displaying
	mask_element: null, // Default mask element applyed to general content container. If set "none" then mask does not applyed
	url: null, //REQUIRED
	params: {}, // Additional parameters for AJAX REQUEST
	pager_container: null,
	content_container: null, //REQUIRED:  ID of content container
	template: null, // Required Prototype Template. Example new Template("<img src='#{picture}' alt="#{name}" />");
	no_records: "No Records to Display.",
	init_page: 0,
	init: function(){
		if(!this.url){
			Main.showDebug("FATAL - Url undefined!");
			return false;
		}
		this.params["limit"] = this.limit;

		this.content_container = $(this.content_container);

		if(!this.content_container){
			Main.showDebug("FATAL -  Content container undefined!");
			return false;
		}
		this.pager_container = $(this.pager_container);
		if(!this.template || typeof this.template != "object"){
			Main.showDebug("FATAL -  Template for Records not defined.<br> <a class='pointer' target='_blank' href='http://prototypejs.org/api/template'>See Doc</a>");
			return false;
		}
		this._loadGrid(this.init_page);
	},
	_loadGrid: function(page){

		this._mask(true);

		this.start = page*this.limit;
		this.page = page;
		this.params["start"] = this.start;

		Main.request(this.url, {
			parameters: this.params,
			onSuccess: function(json, response){
				if(!json){
					eval("json = " + response);
				}
				var records = "";
				if(json.total > 0){
					records = this._getAllRecords(json.data);
				} else {
					records = this.no_records;
				}
				this.content_container.update(records);
				if(this.pager_container){
					this.pager_container.update(this._getPager(json));
				} else {
					if(!this._internalPagerContainer){
						this._internalPagerContainer = new Element("div", {"class": "f_r"});
					}
					this.content_container.insert(this._internalPagerContainer);
					var dd =this._getPager(json);
					this._internalPagerContainer.update(dd);
				}
				this._mask(false);
			},
			scope: this
		});
	},
	_getAllRecords: function(data){
			var content = '';
			data.each(function(item){
					content += this.template.evaluate(item);
			}.bind(this))
			content += '<div class="clear"></div>';
			return content;
	},
	_getPager: function(d){
				var content = new Element("div");
				if(d.total > this.limit){
						var count_pages = Math.round(0.4+(d.total / this.limit));
						var a = {};
						if (this.start != 0){

								a = this._createPagerLinkWithListener(0, "<< First");
								content.insert(a);

							    a = this._createPagerLinkWithListener((parseInt(this.page)-1), "< Previous");
								content.insert(a);

						}
						for(var i = 0 ; i <count_pages; i++){
							if(this.page == i){
								content.insert(new Element('span', {"class": "active pager_link"}).update((i+1)));
							}else{
							    a = this._createPagerLinkWithListener(i, (i+1));
								content.insert(a);
							}
				 		}
				 	    if(this.page < (count_pages-1)){
						    a = this._createPagerLinkWithListener((parseInt(this.page)+1), "Next >");
							content.insert(a);

						    a = this._createPagerLinkWithListener((parseInt(count_pages)-1), "Last >>");
							content.insert(a);
				 	    }
				}
			return content;
	},
	_mask: function (show){
		if(this.mask_element != "none"){
			if(!this._ismask){
				this._ismask = this.mask_element;
			}
			if(this._ismask == null){
				this.mask_element = this.content_container;
			} else {
				this.mask_element = $(this.mask_element);
			}
			if(this.mask_element){
				Main._loadMask(this.mask_element, show);
			}
		}
	},
	_createPagerLinkWithListener: function(param, name){
			var a = new Element("a", {"class": "pointer pager_link"});
			a.update(name);
			a.observe("click", this._loadGrid.bind(this, [parseInt(param)]));
			return a;
	}
}

/****************************** Windows ************************************/
Main.Window = function(config) {
	Main.apply(this, config);
	this.init();
};

Main.Window.prototype = {
	noscroll: false,
	mask: null,
	width: 400,
	statictop: false,
	outerwidth: 460,
	no_mask: false,
	win_container: null,
	init: function(){
		this.outerwidth = this.width+60;
		this.win = new Element('div', {"class": "pop-up", "style": "display: none;"});
		this.win.setStyle({
			"width": this.outerwidth+"px"
		});

		var head = new Element('div', {"class": "pop-up-1"});
		head.insert(new Element('div', {"class": "pop-up-1-left"}));
		var head_center = new Element('div', {"class": "pop-up-1-center"});
		head_center.setStyle({"width": this.width+"px"});
		head.insert(head_center);
		head.insert(new Element('div', {"class": "pop-up-1-right"}));

		this.win.insert(head);

		this.content = new Element('div', {"class": "pop-up-2-center"});
		this.content.setStyle({"width": this.width+"px"});
		this.win.insert(new Element('div', {"class": "pop-up-2"}).insert(new Element('div', {"class": "pop-up-2-left"}).insert(new Element('div', {"class": "pop-up-2-right"}).insert(this.content))));

		var footer = new Element('div', {"class": "pop-up-3"});
		footer.insert(new Element('div', {"class": "pop-up-3-left"}));
		var footer_center = new Element('div', {"class": "pop-up-3-center"});
		footer_center.setStyle({"width": this.width+"px"});
		footer.insert(footer_center);
		footer.insert(new Element('div', {"class": "pop-up-3-right"}));

		this.win.insert(footer);
		if(!this.win_container){
			var b = $(document.body);
		}else{
			var b = this.win_container;
		}
			b.insert(this.win);

		var dim =  document.viewport.getScrollOffsets();
		if(!this.statictop){
			this.win.setStyle({"top": parseInt(dim.top+150)+"px"});
		}else{
			this.win.setStyle({"top": parseInt(this.statictop)+"px"});
		}
		if(!this.noscroll){
			Event.observe(window, 'scroll', this.documentScroll.bind(this));
		}
		if(!Main.Window.prototype.mask){

			if (window.innerHeight != undefined && window.scrollMaxY  != undefined) {// Firefox
				yWithScroll = window.innerHeight + window.scrollMaxY;
			}else if(window.innerHeight  && document.body.scrollHeight > document.body.offsetHeight){
				yWithScroll = (window.innerHeight >document.body.scrollHeight)?window.innerHeight:document.body.scrollHeight;
			} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
				yWithScroll = document.body.scrollHeight;
			} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
				yWithScroll = document.body.offsetHeight;
		  	}
		  	var h = document.viewport.getHeight();
			if(yWithScroll < h){
				yWithScroll = h;
			}
			Main.Window.prototype.mask = new Element('div', {"class": "black", "style": "display: none; height: "+parseInt(yWithScroll)+"px;"});
			b.insert(Main.Window.prototype.mask);
		}
	},
	documentScroll: function(){
		var dim =  document.viewport.getScrollOffsets();
		this.win.setStyle({"top": parseInt(dim.top+150)+"px"});
	},
	updateContent: function(c){
		this.content.update(c);
	},
	addDomContent: function(c){
		this.content.update("");
		this.content.insert(c);
	},
	show: function(){
		if(this.no_mask == false){
			Main.Window.prototype.mask.show();
		}
		this.win.show();
	},
	hide: function(){
		if(this.no_mask == false){
			Main.Window.prototype.mask.hide();
		}
		this.win.hide();
	},
	close: function(){
		if(this.no_mask == false){
			Main.Window.prototype.mask.remove();
		}
		this.win.remove();
	}
};

/********* Search Widget ****************/
Main.search = function(config){
	Main.apply(this, config);
	this.init();
}
Main.search.prototype = {
	form: {
		"class"  : "",
		"action" : "?",
		"method" : "get"
	},
	input : {
		"class" : "",
		"classOnFocus": "",
		"type"  : "text",
		"value" : "simply type what your are looking for here...",
		"name"	: "q"
	},
	button: {
		"type"  : "submit",
		"id" : "search_btn",
		"class" : "f_l",
		"value" : ""
	},
	hidden_inputs: [],
	init: function(){
		if(!this.id){
			Main.showDebug("Search Container not found. Setupt ID in the confing.");
			return false;
		}
		var search_form = new Element("form", this.form);
		this.search_field = new Element("input", this.input);

		this.search_field.observe("focus", function(){
			if(this.search_field.value == this.input.value){
				this.search_field.value = "";
			}
			this.search_field.className = this.input["class"]+" "+this.input["classOnFocus"];
		}.bind(this));

		this.search_field.observe("blur", function(){
			if(this.search_field.value == ""){
				this.search_field.value = this.input.value;
			}
			this.search_field.className = this.input["class"];
		}.bind(this));

		search_form.insert(this.search_field);

		search_form.observe("submit", function(ev){
			if(this.search_field.value == this.input.value){
				Main.showAlert("Введите ключевые слова для поиска.");
				ev.stop();
			}
		}.bind(this));
		for(var i=0; i < this.hidden_inputs.length; i++){
			search_form.insert(new Element("input", this.hidden_inputs[i]));
		}
		search_form.insert(new Element("input", this.button));
		var cont = $(this.id);
		if(cont){
			cont.insert(search_form);
		}
	}
}

//******************************** custom functionality *****************/
var Menu = {
	init: function(){
		/*$$(".left-menu").each(function(el){
			el = $(el);
			if(el.firstChild.className == "marker"){
				this._default = el;
			}
			var _el = $(el.firstChild);
			el.observe("mouseover", function(){
				this._default.firstChild.className = "no-marker";
				_el.className = "marker";
			}.bind(this));
			el.observe("mouseout", function(){
				_el.className = "no-marker";
				this._default.firstChild.className = "marker";
			}.bind(this));
		}.bind(this));*/

		/*this.frm = $("cse-search-box");
		if(this.frm){
			this.frm.observe("submit", function(){
				this.frm.action = js_url+'sitesearch/q/'+$("m-search-field").getValue();
				this.frm.submit();
			}.bind(this));
		}*/
		var Browser = {
		  Version: function() {
		    var version = 999; // we assume a sane browser
		    if (navigator.appVersion.indexOf("MSIE") != -1)
		      // bah, IE again, lets downgrade version number
		      version = parseFloat(navigator.appVersion.split("MSIE")[1]);
		    return version;
		  }
		}
		if(Prototype.Browser.IE && Browser.Version() == 6){
			if(confirm("ВНИМАЕНИЕ!!! Мы не поддерживаем морально устаревшие браузеры. Будьте современны, установите новый, современный браузер. Установить современный браузер от Google?")){
				Main.redirect("http://www.google.com/chrome/eula.html?hl=ru");
			}
		}
	}
};
Main.onReady(Menu.init, Menu);