
var FrontEnd = {

	_bookmarkUrl: 'http://cp/',
	_bookmarkTitle: 'Портал нашего города',
	_startPageError: 'Вы можете сделать страницу стартовой через настройки своего браузера',

	setBookmarkUrl: function(url)
	{
		this._bookmarkUrl = url;
	},

	setBookmarkTitle: function(title)
	{
		this._bookmarkTitle = title;
	},

	setStartPage: function(obj)
	{
		if (Prototype.Browser.IE && !Prototype.Browser.Opera) {
			obj.style.behavior='url(#default#homepage)';
			obj.setHomePage(this._bookmarkUrl);
			return true;
		} else {
			alert(this._startPageError);
			return false;
		}
		return false;
	},

	addbookmark: function()
	{
		if (Prototype.Browser.IE && !Prototype.Browser.Opera) {
			window.external.AddFavorite(this._bookmarkUrl, this._bookmarkTitle);
			return true;
		} else if (Prototype.Browser.Gecko) {  
			window.sidebar.addPanel(this._bookmarkTitle, this._bookmarkUrl, '');
			return true;
		} else if (Prototype.Browser.Opera) {
			var bookmarkLink = document.createElement('a');
			if(bookmarkLink) {
				bookmarkLink.setAttribute('rel', 'sidebar');
				bookmarkLink.setAttribute('href', this._bookmarkUrl);
				bookmarkLink.setAttribute('title', this._bookmarkTitle);
				bookmarkLink.click();
				return true;
			}
			return false;
		} else {
			alert(this._startPageError);
			return false;
		}
		return false;
	}
};


var ClockPrototype = Class.create();
  
ClockPrototype.prototype = {
	date: new Object(),
	clientDate: new Date(),
	initialize: function(timestamp) {
		this.clientDate = new Date();
		this._setTime(timestamp);
	},
	_setTime: function(timestamp) {
		this.date = new Date();
		this.date.setTime(timestamp);
		/* synchronizing client and server seconds because request timeout */
		this.date.setSeconds(this.clientDate.getSeconds());
		var remainSec = parseInt(60 - this.date.getSeconds());
		setTimeout(function(thisObj) {
			return function() {
			thisObj.updateClock();
		} } (this), remainSec*1000);
	},
	updateClock: function() {
		if($('clock') != null) {
			this.date.setMinutes(this.date.getMinutes()+1);
			var hours   = this.date.getHours();
			var minutes = this.date.getMinutes();
			if(minutes < 10) {
				minutes = '0' + minutes;
			}
			var time = hours + ":" + minutes;
			setTimeout(function(thisObj) {
				return function() {
				thisObj.updateClock();
			} } (this), 60000);
			$('clock').update(time);
		}
	}
};

/* must go away */
function ShowMenu(el,menuId) {
	m = document.getElementById(menuId);
	m.className += " menuactive";
	el.firstChild.className = "over";
}

function HideMenu(el,menuId) {
	m = document.getElementById(menuId);
	m.className = "menu";
	el.firstChild.className = "sub";
}
ar = new Array();
function show_(DI) {
	document.getElementById(DI).style.visibility="visible";
	ar[DI]=1;
}

function hide(DI) {
	if (ar[DI] == 0) {
		document.getElementById(DI).style.visibility="hidden";
	}
}

function hide1(DI) {
	ar[DI] = 0;
	st = DI.toString();
	proc = "hide('" + st + "')";
	setTimeout(proc,200);
}

function sl(DI) {
	ar[DI] = 1;
}

function sla(DI) {
	hide1(DI);
}

function setLanguage(langname) {
	 var argsObject = new Object();
	 argsObject["langname"] = langname;
	 makeCall('SiteConfigurator/GetLanguagesPanel', argsObject);
}

var TableHighLightProto = Class.create();

TableHighLightProto.prototype = {
	mouseoverListener: '',
	mouseoutListener: '',
	element: '',
	initialize: function() {
		var td = $$('table.table thead td.st_Sortable');
		for (var i = 0; i < td.length; ++i) {
			var el = td[i];
			if(!el.hasClassName('st_Sorted')) {
				this.addObserve(el);
			}
		}
		var bodyTd = $$('table.table tbody tr');
		for (var i = 0; i < bodyTd.length; ++i) {
			var el = bodyTd[i];
			 this.addObserve(el);
		}
	},
	addObserve: function(el) {
		var mouseoverListener = this.highlight.bindAsEventListener(el, el);
		var mouseoutListener  = this.unhighlight.bindAsEventListener(el, el);
		Element.observe(el, 'mouseover', mouseoverListener, false);
		Element.observe(el, 'mouseout', mouseoutListener, false);
	},
	highlight: function(e, el) {
		Element.addClassName(el, 'st_Over');
	},
	unhighlight: function(e, el) {
		Element.removeClassName(el, 'st_Over');
	}
}