Hashtable.prototype.hash	 	= null;
Hashtable.prototype.keys		= null;
Hashtable.prototype.location	= null;

function Hashtable(){
	this.hash = new Array();
	this.keys = new Array();

	this.location = 0;
}

Hashtable.prototype.put = function (key, value){
	if (value == null)
		return;

	if (this.hash[key] == null)
		this.keys[this.keys.length] = key;

	this.hash[key] = value;
}

Hashtable.prototype.get = function (key){
		return this.hash[key];
}

Hashtable.prototype.remove = function (key){
	for (var i = 0; i < this.keys.length; i++){
		//did we found our key?
		if (key == this.keys[i]){
			//remove it from the hash
			this.hash[this.keys[i]] = null;
			//and throw away the key...
			this.keys.splice(i ,1);
			return;
		}
	}
}

Hashtable.prototype.size = function (){
    return this.keys.length;
}

Hashtable.prototype.next = function (){
	if (++this.location < this.keys.length)
		return true;
	else
		return false;
}

Hashtable.prototype.moveFirst = function (){
	try {
		this.location = -1;
	} catch(e) {}
}

Hashtable.prototype.moveLast = function (){
	try {
		this.location = this.keys.length - 1;
	} catch(e) {}
}

Hashtable.prototype.getKey = function (){
	try {
		return this.keys[this.location];
	} catch(e) {
		return null;
	}
}

Hashtable.prototype.getValue = function (){
	try {
		return this.hash[this.keys[this.location]];
	} catch(e) {
		return null;
	}
}

Hashtable.prototype.getKeyOfValue = function (value){
	for (var i = 0; i < this.keys.length; i++)
		if (this.hash[this.keys[i]] == value)
			return this.keys[i]
	return null;
}

Hashtable.prototype.toString = function (){

	try {
		var s = new Array(this.keys.length);
		s[s.length] = "{";

		for (var i = 0; i < this.keys.length; i++){
			s[s.length] = this.keys[i];
			s[s.length] = "=";
			var v = this.hash[this.keys[i]];
			if (v)
				s[s.length] = v.toString();
			else
				s[s.length] = "null";

			if (i != this.keys.length-1)
				s[s.length] = ", ";
		}
	} catch(e) {
		//do nothing here :-)
	}finally{
		s[s.length] = "}";
	}

	return s.join("");
}

Hashtable.prototype.add = function(ht){
	try {
		ht.moveFirst();
		while(ht.next()){
			var key = ht.getKey();
			//put the new value in both cases (exists or not).
			this.hash[key] = ht.getValue();
			//but if it is a new key also increase the key set
			if (this.get(key) != null){
				this.keys[this.keys.length] = key;
			}
		}
	} catch(e) {
	} finally {
		return this;
	}
};;var DialogHost = {
	emptyHTML : '/Js/Common/empty.html',
	defaultOptions : {
		width : 400,
		height : 200,
		modal : true,
		resizable : true,
		draggable : true,
		autoResize : true,
		title : "Page",
		overlay: {opacity: 0.2, background: "black"}
		},
	callbacks : new Hashtable(),
	dialogs : new Hashtable(),
	show : function (frName, url, options, callbackFunction){
		var frDialog = '#'+frName;
		if (this.dialogs.get(frName) == '1'){
			$(frDialog).dialog("open");
			if (options != null && options.title != null){
				$("#"+frName).data('title.dialog', options.title);
			}
		}
		else{
			var options = jQuery.extend(this.defaultOptions, options);
			$(frDialog).dialog(options);
			this.dialogs.put(frName, '1');
		}
		this.optimizeSize(frName, options.width, options.height);
		$(frDialog).attr("src", url);
		$(frDialog).css({'display' : 'block'});

		this.callbacks.put(frName, callbackFunction);
	},
	show2 : function (frName, url, options, callbackFunction){
		// create iframe:
		var div = document.getElementById("div"+frName);
		if (!div) {
			div = $(document.body)
			.append("<div id='div"+frName+"'></div>")
			.find('#div'+frName).get(0);
		}
		div.innerHTML = '<iframe id="'+frName+'" width="100%" height="100%" src="/Js/Common/empty.html" frameborder="0" scrolling="auto"></iframe>';
		// call main show method:

		var frDialog = '#div'+frName;
		var frFrame = '#'+frName;

		if (this.dialogs.get(frName) == '1'){
			$(frDialog).dialog("open");
			if (options != null && options.title != null){
				$("#"+frName).data('title.dialog', options.title);
			}
		}
		else{
			var options = jQuery.extend(this.defaultOptions, options);
			$(frDialog).dialog(options);
			this.dialogs.put(frName, '1');
		}
		this.optimizeSize(frName, options.width, options.height);
		$(frFrame).attr("src", url);
		$(frFrame).css({'display' : 'block'});
		$(frDialog).css('display','block');
		this.callbacks.put(frName, callbackFunction);
	},
	close : function (frName, res, url){
		var div = document.getElementById("div"+frName);
		if (div != null)
		{
			var frDialog = '#div'+frName;
			var frFrame = '#'+frName;
			this.fullScreen(frName, false);

			$(frFrame).attr("src", this.emptyHTML);
			var div = document.getElementById("div"+frName);
			if (div){
				$(div).children("iframe").attr("src", this.emptyHTML);
			}
		}
		else
		{
			var frDialog = '#'+frName;
			$(frDialog).attr("src", this.emptyHTML);
		}
		var callbackFunction = this.callbacks.get(frName);
		if ($.isFunction(callbackFunction)) callbackFunction(res, url);
		$(frDialog).dialog("close");
	},
	getElement: function(expr){
		return $(expr).get(0);
	},
	setHeight : function (frName, newHeight){
		$("#"+frName).height(newHeight + 20 + 14);//added 14px
		$("#"+frName).data('height.dialog', newHeight + 60 + 20); // 60 is height of title. 20 - bottom padding.
	},
	getHeight : function(frName){
		return $("#"+frName).height();
	},
	optimizeSize: function(frName, dlgW, dlgH){
		var screenW = screen.availWidth, screenH = screen.availHeight, frDialog = "#div" + frName;
		if (screenW <= dlgW || screenH <= dlgH){
			window.moveTo(0,0);
			window.resizeTo(screen.availWidth,screen.availHeight);
			var winW = $(window).width(), winH = $(window).elementHeight();
			var origH = dlgH, origW = dlgW;
			if (dlgW > winW) dlgW = winW;
			if (dlgH > winH) dlgH = winH;
			var dlg = $(frDialog).parents(".ui-dialog:first");
			if (dlg.length > 0){
				if (!dlg.data('normal.top')){
					dlg.data('normal.top', dlg.css('top')).data('normal.left', dlg.css('left'))
					.data('normal.width', dlg.width()).data('normal.height', dlg.height());
				}
				var frmH = dlgH - 30 - dlg.find('ui-dialog-titlebar').height();
				var frmW = dlgW;
				dlg.height(dlgH+'px').width(dlgW+'px').css('left','0px').css('top','0px')
				.find(frDialog+":first").height(frmH+'px').width(frmW+'px')
				.find('iframe').attr('scrolling','yes').attr('overflov','auto')
				.height(frmH+'px').width(frmW+'px');
			}
		}
	},
	fullScreen: function (frName, state){
		var o, h, w, l, t, frDialog = "#div" + frName;
		var dlg = $(frDialog).parents(".ui-dialog:first");
		if (dlg.length > 0){
			if (!dlg.data('normal.top')){
				dlg.data('normal.top', dlg.css('top')).data('normal.left', dlg.css('left'))
				.data('normal.width', dlg.width()).data('normal.height', dlg.height());
			}
			if (state){
				h = $(window).elementHeight() - dlg.find('ui-dialog-titlebar:first').height();
				w = $(window).width();
				l = 0;
				t = 0;
			}else{
				h = dlg.data('normal.height');
				w = dlg.data('normal.width');
				l = dlg.data('normal.left');
				t = dlg.data('normal.top');
			}
			dlg.find(frDialog+":first").height(h+'px').width(w+'px').end()
			.css("top", t).css("left", l).width(w+'px').height(h+'px');
		}
	},
	getMainWinData: function(){
		return {h: $(window).elementHeight(), w: $(window).width()};
	}
};
(function($){
 jQuery.fn.elementHeight = function() {
 	var elm = this.get(0);
  	var h = $(elm).height();
  	if (jQuery.browser.opera && elm == window) {
  		var t = $('html').get(0);
  		if (t && t.clientHeight) h = t.clientHeight;
  	}
    return h;
 };
})(jQuery);
;function processChars(s)
{
	s = new String(s);
	s = s.toLowerCase();
	s = s.replace(/[\s.,;:()]/g, '_');
	s = s.replace(/ö/ig, 'oe');
	s = s.replace(/ä/ig, 'ae');
	s = s.replace(/ü/ig, 'ue');
	s = s.replace(/ß/ig, 'ss');
	
	
	s = s.replace(/а/ig, 'a');
    s = s.replace(/б/ig, 'b');
    s = s.replace(/в/ig, 'v');
    s = s.replace(/г/ig, 'g');
    s = s.replace(/д/ig, 'd');
    s = s.replace(/е/ig, 'e');
    s = s.replace(/ё/ig, 'yo');
    s = s.replace(/ж/ig, 'zh');
    s = s.replace(/з/ig, 'z');
    s = s.replace(/и/ig, 'i');
    s = s.replace(/й/ig, 'j');
    s = s.replace(/к/ig, 'k');
    s = s.replace(/л/ig, 'l');
    s = s.replace(/м/ig, 'm');
    s = s.replace(/н/ig, 'n');
    s = s.replace(/о/ig, 'o');
    s = s.replace(/п/ig, 'p');
    s = s.replace(/р/ig, 'r');
    s = s.replace(/с/ig, 's');
    s = s.replace(/т/ig, 't');
    s = s.replace(/у/ig, 'u');
    s = s.replace(/ф/ig, 'f');
    s = s.replace(/х/ig, 'h');
    s = s.replace(/ц/ig, 'c');
    s = s.replace(/ч/ig, 'ch');
    s = s.replace(/ш/ig, 'sh');
    s = s.replace(/щ/ig, 'sch');
    s = s.replace(/ъ/ig, 'j');
    s = s.replace(/ы/ig, 'i');
    s = s.replace(/ь/ig, 'j');
    s = s.replace(/э/ig, 'e');
    s = s.replace(/ю/ig, 'yu');
    s = s.replace(/я/ig, 'ya');
	s = s.replace(/ї/ig, 'i');
	s = s.replace(/і/ig, 'i');
	s = s.replace(/є/ig, 'ye');
           
	
    s = s.replace(/[^a-z0-9_-]/ig, '');
    s = s.replace(/[_]{2,}/ig, '_');
    s = s.replace(/[-]{2,}/ig, '-');
    s = s.replace(/[_-]{2,}/ig, '-');
    s = s.replace(/[_-]*$/ig, '');

    return s;
};jQuery.extend({
	alertsUserOption : {
		btnOkText : 'Ok',
		btnCancelText : 'Cancel',
		winTitleText : 'Warning'
	},
	_alertsOptions : {
		//width : 400,
		//height : 200,
		modal : true,
		resizable : true,
		draggable : true,
		autoResize : true,
		autoOpen: false,
		title : "Warning",
		overlay: {opacity: 0.2, background: "black"}
	},
	_alertsHandler : null,
    _alertsTemplate : '<div style="display:none;" class="formWindow">'+
							'<div class="content" id="content">'+
								'<p style="overflow:auto"></p>'+
							'</div>'+
							'<div class="footer">'+
								'<form action="#">'+
									'<input class="btn_ok" type="button" value="Ok" />'+
									'<input class="btn_cancel" type="button" value="Cancel" />'+
								'</form>'+
							'</div>'+
						'</div>',
    alert : function(text, width, height, okFunc) {
    	if (!($._alertsHandler)){
    		$._alertsHandler = $($._alertsTemplate).attr('style','display:block').dialog($._alertsOptions);
    		$($._alertsHandler).find('.btn_ok').val($.alertsUserOption.btnOkText)
    		.end().find('.btn_cancel').val($.alertsUserOption.btnCancelText)
    		.end().parents('.ui-dialog-container').find('.ui-dialog-title').text($.alertsUserOption.winTitleText);
    		//.end().find('.ui-dialog-content').removeAttr('style');
    	}
    	$($._alertsHandler).find('p:first').html(text).attr('style', 'overflow:auto')
    	.end().find('.btn_ok').unbind().bind('click', function(){
    		if ($.isFunction(okFunc)) okFunc();
    		$($._alertsHandler).dialog('close');
    	})
    	.end().find('.btn_cancel').css('display', 'inline').unbind().bind('click',function(){
    		$($._alertsHandler).dialog('close');
    	})
    	.end().parents('.ui-dialog:first').width(width).height(height)
    	.find('.ui-dialog-title').text($.alertsUserOption.winTitleText);
		$($._alertsHandler).dialog('open');
    },
    confirm : function(text, width, height, okFunc) {
    	if (!($._alertsHandler)){
    		$._alertsHandler = $($._alertsTemplate).attr('style','display:block').dialog($._alertsOptions);
    		$($._alertsHandler).find('.btn_ok').val($.alertsUserOption.btnOkText)
    		.end().find('.btn_cancel').val($.alertsUserOption.btnCancelText)
    		.end().parents('.ui-dialog-container').find('.ui-dialog-title').text($.alertsUserOption.winTitleText);
    	}
    	$($._alertsHandler).find('p:first').html(text).attr('style', 'overflow:auto')
    	.end().find('.btn_ok').unbind().bind('click', function(){
    		if ($.isFunction(okFunc)) okFunc();
    		$($._alertsHandler).dialog('close');
    	})
    	.end().find('.btn_cancel').css('display', 'none')
		.end().parents('.ui-dialog:first').width(width).height(height)
    	.find('.ui-dialog-title').text($.alertsUserOption.winTitleText);
		$($._alertsHandler).dialog('open');
		var h = $($._alertsHandler).find('.content').parents('.ui-dialog-content').height();
		var f = $($._alertsHandler).find('.footer').height();
		$($._alertsHandler).find(".content p:first").height(h-f-40);
    }
});;