var helps = new Array();
var helpsGlobal = new Array();
var _objectShow = new objectShow();

var setupSite = { 
    siteUrl: '',
    webServiceUrl: '',
    langId: 0,
	loaderImage: '',
	loaderLabel: '',
	feedsPage: '',
	feedsTab: ''
};

var bugreport = {
	send: function() {
		var serv = newService('bugreport');
		serv.setVars({ msg: $('#bugreportMsg').val(), url: window.location.href, type: $('input[name=bugreport]:checked').val() });
		$('#bugreportForm').css('display','none');
		$('#bugreportLoading').css('display','block');
		serv.call({ success: function(res, status) {
					$('#bugreportLoading').css('display','none');
					$('#bugreportSent').css('display','block');
					setTimeout('bugreport.reset()',6000);
				} });
	},
	reset: function() {
		$('#bugreportMsg').val('');
		$('#bugreportSent').css('display','none');
		$('#bugreportForm').css('display','block');
	}
};

var error = {
    err: null,
    
    showById: function(id, txt) {
        $("#ErrorMessage" + id).html(txt);
        this.err = $("#ErrorMessageContainer" + id);
        
        this.showErr();
    },
    
    show: function(txt) {
        $("#ErrorMessage").html(txt);
        this.err = $("#ErrorMessageContainer");
        
         this.showErr();
    },
    
    showErr: function() {
        this.err.css("display", "block");
    },
    
    hide: function() {
        if (this.err != null) {
            this.err.css("display", "none");
            this.err = null;
        }
    }
}

var alerts = {
	dataSrv: null,
	processing: false,
	alertsBar: null,
	alertsBarVal: null,
	alertsContent: null,
	menuMessage: null,
	menuMessageVal: null,
	menuApprovals: null,
	menuApprovalsVal: null,
	timer: null,
	loaderHtml: '',
	feedsProcessing: true,
	load: function() {
		this.dataSrv = newService('alerts');
		this.alertsBar = $('#personalAlertsBar');
		this.alertsBarVal = $('#personalAlertsBarVal');
		this.alertsContent = $('#personalAlerts');
		this.menuMessage = $('#menuNewMessage');
		this.menuMessageVal = $('#menuNewMessage span');
		this.menuApprovals = $('#menuNewApprovals');
		this.menuApprovalsVal = $('#menuNewApprovals span');
		this.get();
	},
	get: function() {
		if(this.processing == false) {
			this.processing = true;
			this.dataSrv.setVars({	profileId: profileId,
									feedsPage: setupSite.feedsPage,
									feedsTab: setupSite.feedsTab,
									p: ((typeof(feeds) != 'undefined') ? feeds.getPage() : 1),
									feedsProcessing: ((alerts.feedsProcessing == true) ? 1 : 0)
								});
			this.dataSrv.call({ dataType: 'xml',
								success: function(res, status) {
									alerts.loadContent(res);
								}
							});
		}
		this.timer = setTimeout("alerts.get()", 5000);
	},
	loadContent: function(res) {
		$('response', res).each(function() {
			var newMails = parseInt($('newmail', this).text(), 10);
			var newApprovals = parseInt($('newapprovals', this).text(), 10);
			var barValue = $('barValue', this).text();
			
			if(barValue != '') {
				alerts.alertsBar.removeClass('IAOff');
			}
			else {
				alerts.alertsBar.addClass('IAOff');
			}
			
			if(newMails > 0) {
				alerts.menuMessage.addClass('count');
				alerts.menuMessageVal.html(newMails);
			}
			else {
				alerts.menuMessage.removeClass('count');
				alerts.menuMessageVal.html('');
			}
			
			if(newApprovals > 0) {
				alerts.menuApprovals.addClass('count');
				alerts.menuApprovalsVal.html(newApprovals);
			}
			else {
				alerts.menuApprovals.removeClass('count');
				alerts.menuApprovalsVal.html('');
			}
			
			alerts.alertsBarVal.html(barValue);
			alerts.alertsContent.html($('content', this).text());
			
			if(alerts.feedsProcessing == true && $('feedscontentid', this).text() != '') {
				$('#'+$('feedscontentid', this).text()).html($('feedscontent', this).text());
			}
		});
		alerts.processing = false;
	},
	callBack: function() {},
	unset: function(id,url) {
		if(this.processing == false) {
			this.processing = true;
			if(url != null && url != '') {
				this.callBack = function() {
					location.href=url;
				}
				$('#alertMsg'+id).html($('#alertsLoader').html());
			}
			this.dataSrv.addVar('unsetid', id);
			this.dataSrv.call({ dataType: 'xml',
							success: function(res, status) {
								alerts.loadContent(res);
								alerts.callBack();
								alerts.callBack = function(){};
							}
						});
		}
	},
	del: function(id, tabId) {
		if(this.processing == false) {
			this.processing = true;
			this.callBack = function() { Tabs.set(tabId); };
			this.dataSrv.addVar('del', id);
			$('#alert'+id).addClass('QDisabled');
			$('#alertMsg'+id).addClass('QDisabled');
			this.dataSrv.call({ dataType: 'xml',
							success: function(res, status) {
								alerts.loadContent(res);
								alerts.callBack();
							}
						});
		}
	},
	tickleBack: function(id, refId) {
		this.unset(id);
		this.tickle(refId);
	},
	tickle: function(refId) {
		this.dataSrv.setVars({ cmd: 'tickle', profileId: profileId, refId: refId });
		this.dataSrv.call({ success: function(res, status) {
				if($('#tickleOff')) {
					$('#tickleOff').css('display','none');$('#tickleOn').css('display','block'); 
				}
			} });
	}
};

var progressBar = {
    img: null,
    content: null,
    container: null,
    
    setup: function(vars) {
        this.img = '<img src="' + vars.img + '" style="position: relative;bottom:-4px;margin-right:7px;"><span class="pink">' + vars.label + '</span>';    
    },
    
    show: function(container) {
        this.container = $('#' + container);
        this.content = this.container.html();
        this.container.html(this.img);
    },
    
    hide: function() {
       this.container.html(this.content);
    }
};

var error2 = {
    buff: '',
    params: null,
    
    show: function(p) {
        this.params = p;
        this.buff = $('#'  + p.containerId).html();
        $('#'  + p.containerId).html('<div class="error">' + p.msg + '</div>');
        $('#'  + p.containerId).css("display", "block");
    },
    
    hide: function() {
		if(this.params != null && this.params.containerId != null) {
			$('#'  + this.params.containerId).css("display", "none");
			$('#'  + this.params.containerId).html(this.buff);
		}
    }
}

var progressBar2 = {
    buff: '',
    params: null,
    show: function(p) {
        this.params = p;
        var info = p.info != null ? p.info : 'please wait...';
    
        this.buff = $('#' + p.containerId).html();
        $('#' + p.containerId).html('<div id="importDlgProcess" ' + (p.center != null && p.center != false ? 'class="message"' : '') + '><img src="/images/loader.gif" style="position: relative;bottom:-4px;margin-right:7px;"><span class="pink">' + info + '</span>');
        $('#' + p.containerId).css('display', 'block');
    },
    hide: function() {
        $('#' + this.params.containerId).html(this.buff);
        $('#' + this.params.containerId).css("display", "none");
    }
}

var comments = {
	processing: false,
	service: null,
    show: function(id) {
		var obj = $('#commentsList_'+id);
        if (obj.css('display') == 'none') {
            obj.css('display', 'block');
        }
        else {
            obj.css('display', 'none');
        }
    },
    post: function(id, isExpanded) {
		if(this.processing == false) {
			var obj = document.getElementById('commentsForm_'+id);
            var comments = $(obj).val();
            if(obj.defaultValue != comments && comments != '' && profileId != null) {
				this.processing = true;
                this.loadService();
				$('#commentsPostForm_'+id).html('<img src="'+setupSite.loaderImage+'" style="position: relative;bottom:-4px;margin-right:7px;"><span class="pink">'+setupSite.loaderLabel+'</span>');
				if(isExpanded != null) {
					this.service.addVar('expanded', 1);
				}
				this.service.setVars({ cmd: 'write', profileId: profileId, refId: id, comments: comments });
				this.service.call({ dataType: 'xml',
								success: function(res, status) {
									//alert(res);
									//return false;
									if(status == 'success') {
										$('response', res).each(function(){
										$('#cc'+id).html($('count', this).text());
											$('#comments'+id).html($('comments', this).text());
										});
									}
									comments.processing = false;
								}
							});
            }
        }
    },
	ttpost: function(id, type) {
		//if(this.processing == false) {
			this.processing = true;
			this.loadService();
			this.service.setVars({ cmd: 'write', profileId: profileId, type: type, refId: id, comments: '' });
			this.service.call({ dataType: 'xml',
							success: function(res, status) {
								   //alert(res);
								   //return false;
								   if(status == 'success') {
										$('response', res).each(function(){
											$('#cc'+id).html($('count', this).text());
											$('#comments'+id).html($('comments', this).text());
										});
										comments.processing = false;
									}
								}
							 });
		//}
	},
    del: function(refId, id, isExpanded) {
        this.loadService();
		if(isExpanded != null) {
			this.service.addVar('expanded', 1);
		}
		$('#commentsItem'+id).css('display','none');
		this.service.setVars({ cmd: 'del', refId: refId, id: id });
        this.service.call({ dataType: 'xml',
                        success: function(res, status) {
								//alert(res);
								//return false;
								//$('#comments' + refId).html(res);
								if (status == 'success') {
                                    $('response', res).each(function(){
										$('#cc'+refId).html($('count', this).text());
										$('#comments'+refId).html($('comments', this).text());
									});
								}
                            }
						});
    },
    loadService: function() {
		if(this.service == null) {
			this.service = new webService({ server: setupSite.webServiceUrl, service: 'comments', lang: setupSite.langId });
		}
    },
	reset: function(obj,resetVal) {
		resetDefault(obj);
		alerts.feedsProcessing = resetVal;
		if(resetVal == false) {
			obj.style.height = '50px';
		}
		this.processing = false;
	},
	expand: function(obj, blockId) {
		$('#'+blockId).css('display','block');
		$(obj).css('display','none');
	}
};

var simpleComments = {
	id: '',
	type: 16,
	
	focus: function(id) {
		this.id = id;
		$('#commentsText' + id).css('height', '50px');
		$('#commentsText' + id).html('');
	},
	
	post: function() {
		if (this.id != '') {
			var msg = $('#commentsText' + this.id).val();
			if (msg.length >= 3) {
				progressBar2.show( {containerId: 'commentsProgress'} );
				var service = newService('comments2', {type: this.type, cmd: 1, id: this.id, msg: msg});
				this.call(service)
				this.reset();
			}
		}
	},
	
	del: function(id, commentId) {
		progressBar2.show( {containerId: 'commentsProgress'} );
		var service = newService('comments2', {type: this.type, cmd: 2, id: id, commentId: commentId});
		this.call(service);
	},
	
	scroll: function() {
	
	},
	
	reset: function() {
		$('#commentsText' + this.id).css('height', '16px');
		$('#commentsText' + this.id).html('Write another comment');
		this.id = '';
	},
	
	call: function(service) {
		service.call( { success: function(res, status) {
									progressBar2.hide();
									$('#commentsList').html(res);
								 }
					} );
	}
};

var applications = {
	appId: null,
	processing: false,
	dataSrv: null,
	openObj: null,
	init: function() {
		if(this.processing == null) {
			this.processing = false;
		}
		if(this.dataSrv == null) {
			this.dataSrv = newService('applications');
		}
	},
	setOpen: function(id, val) {
		if(this.openObj == null) {
			this.openObj = new Array();
		}
		this.openObj[id] = val;
	},
	activate: function() {
		this.init();
		if(this.appId != null) {
			this.dataSrv.addVar('cmd',1);
			this.dataSrv.addVar('type','professional');
			this.dataSrv.addVar('appId',this.appId);
			if($('#settingsProfileId').length) {
				this.dataSrv.addVar('settingsProfileId',$('#settingsProfileId').val());
			}
			this.dataSrv.call({ success: function(res, status) { if(status == 'success') { modalDlg.close(); window.location.reload(); } }});
		}
	},
	disactivate: function() {
		this.init();
		if(this.appId != null) {
			this.dataSrv.addVar('cmd',2);
			this.dataSrv.addVar('type','professional');
			this.dataSrv.addVar('appId',this.appId);
			if($('#settingsProfileId').length) {
				this.dataSrv.addVar('settingsProfileId',$('#settingsProfileId').val());
			}
			this.dataSrv.call({ success: function(res, status) { if(status == 'success') { modalDlg.close(); window.location.reload(); } }});
		}
	},
	enable: function(id) {
		this.appId = id;
		modalDlg.open({ type: 'applications', requestId: this.appId, width: 475, openCallBack: function() {}, closeCallBack: function() {} });
	},
	disable: function(id) {
		this.appId = id;
		modalDlg.open({ type: 'applicationsdelete', requestId: this.appId, width: 475, openCallBack: function() {}, closeCallBack: function() {} });
	},
	changeStatus: function(id) { },
	saveView: function() {
		applications.init();
		if(applications.processing == false) {
			$('#ProLoader').css('display','block');
			applications.processing = true;
			
			var list = '';
			for (var id in this.openObj) {
				list += id.substr(4,3)+','+this.openObj[id]+'|';
			}
			
			applications.dataSrv.addVar('cmd',3);
			applications.dataSrv.addVar('list',list);
			applications.dataSrv.addVar('column1',$('#DragContainer1').sortable('toArray'));
			applications.dataSrv.addVar('column2',$('#DragContainer2').sortable('toArray'));
			applications.dataSrv.call({ success: function(res, status) { if(status == 'success') { 
					$('#ProLoader').css('display','none');
					if(applications.openObj != null) {
						applications.openObj.length = 0;
					}
					applications.processing = false;
				} }});
		}
	}
};

var favorites = {
	dataSrv: null,
	id: null,
	checkedItems: new Array(),
	save: function() {
		var err = $('#favoriteError');
		err.html('');
		err.css('display','none');
		
		if(this.dataSrv == null) {
			this.dataSrv = newService('favorites');
		}
		var dataStr = $('#favoritesName').val();
		if(dataStr.length == 0) {
			err.html('Favorite title can not be empty.');
			err.css('display','block');
		}
		else if(dataStr.length > 30) {
			err.html('Favorite title too long.');
			err.css('display','block');
		}
		else {
			var refId = $('#favoriteRefId').val();
			if(refId != 0) {
				this.dataSrv.addVar('cmd', 'edit');
				this.dataSrv.addVar('refId', refId);
			}
			else {
				this.dataSrv.addVar('cmd', 'add');
			}
			this.dataSrv.addVar('title', dataStr);
			this.dataSrv.addVar('type', $('#favoritesType').html());
			this.dataSrv.addVar('link', '/'+window.location.toString().replace(setupSite.siteUrl,''));
			this.dataSrv.addVar('showit', (($('#favoritesShowit').attr('checked')) ? 1 : 0));
			this.dataSrv.call({ dataType: 'xml', success: function(res, status) { favorites.result(res, refId); modalDlg.close(); } });
		}
	},
	open: function(id) {
		modalDlg.open({ type: 'favorites', requestId: id, width: 475, openCallBack: function() {
				if(id == 0) {
					var link = window.location.toString().replace(setupSite.siteUrl,'');
					$('#favoritesType').html(link.substr(0, link.indexOf('/')));
				}
			},
			closeCallBack: function() {}
		});
	},
	del: function(id) {
		this.id = id;
		confirmDlg.show({ txt: 'Are you sure you want to delete selected favorite?', callBackYes: function() { favorites.delProceed(); } });
	},
	delProceed: function() {
		var refId = this.id;
		if(this.dataSrv == null) {
			this.dataSrv = newService('favorites');
		}
		this.dataSrv.addVar('cmd', 'delete');
		this.dataSrv.addVar('refId', refId);
		this.dataSrv.call({ dataType: 'xml', success: function(res, status) { favorites.result(res, refId); } });
	},
	check: function(id, isChecked) {
		this.checkedItems[id] = isChecked;
	},
	getCheckedItems: function() {
		var valuesCheck = '';
		var valuesUnCkeck = '';
		for (var id in this.checkedItems) {
			if (this.checkedItems[id] != false) {
				valuesCheck += id+',';
			}
			else {
				valuesUnCkeck += id+',';
			}
		}
		return new Array(valuesCheck, valuesUnCkeck);
	},
	saveList: function() {
		if(this.dataSrv == null) {
			this.dataSrv = newService('favorites');
		}
		$('#favoriteLoading').css('display','block');
		var list = this.getCheckedItems();
		this.dataSrv.addVar('cmd', 'status');
		this.dataSrv.addVar('check', list[0]);
		this.dataSrv.addVar('uncheck', list[1]);
		this.dataSrv.call({ dataType: 'xml', success: function(res, status) { favorites.result(res,0); $('#favoriteLoading').css('display','none'); } });
	},
	result: function(res, refId) {
		$('response', res).each(function() {
			if(refId != 0 && $('#personalTab')) {
				$('#personalTab').html($('tab', this).text());
			}
			$('#favoriteLinks').html($('list', this).text());
		});
	},
	goto: function(url) {
		location.href = url;
	}
};

var modalDlg = {
	params: null,
	dataSrv: null,
	dlgService: 'dialogs',
	
	addVar: function(key, val) {
		this.service();
        this.dataSrv.addVar(key, val);
    },
	open: function(params) {
		this.close();
		
		this.params = params;
		this.params.progressBars = $('#modalDlgContent').html();
		$('#modalDlg').dialog({
			open: function() {
				if (params.content == null) {
					modalDlg.service();
					modalDlg.dataSrv.setVars({ 	cmd: 'load', type: params.type, 
												requestId: ((params.requestId != null) ? params.requestId : ''),
												profileId: ((params.profileId != null) ? params.profileId : '')
											});
					modalDlg.dataSrv.call({ success: function(res, status) {
						if(status == 'success') {
							$('#modalDlgContent').html(res);
							$('#modalDlg').dialog('option', 'position', 'center');
							
							if (params.openCallBack != null) {
								params.openCallBack();	
							}
						}
					}});
				}
				else {
					$('#modalDlgContent').html(params.content);
				}
			},
			width: params.width,
			autoOpen: false,
			draggable: false,
			modal: true,
			position: 'center',
			resizable: false,
			overlay: { backgroundColor: '#000', opacity: 0.85 }
		});

		$('#modalDlg').dialog('open');
	},
	close: function(res) {
		$('#modalDlg').dialog('close');
		$('#modalDlg').dialog('destroy');
		
		if (this.params != null) {
			$('#modalDlgContent').html(this.params.progressBars);
			if (this.params.closeCallBack != null) {
				this.params.closeCallBack(res);	
			}
		}
	},
	isOpen: function() {
		return $('#modalDlg').dialog('isOpen'); 
	},
	service: function() {
		if(this.dataSrv == null) {
			this.dataSrv = newService(this.dlgService);
		}
	},
	updateContent: function(content) {
		if(content == '') {
			$('#modalDlgContent').html(this.params.progressBars);
		}
		else {
			$('#modalDlgContent').html(content);
			$('#modalDlg').dialog('option', 'position', 'center');
		}
	}
};

function newService(service, vars) {
	var service = new webService({ server: setupSite.webServiceUrl, service: service, lang: setupSite.langId });
	service.setVars(vars);
	return service;
}

function webService(init) {
    var _init = init;
    var _vars = new Array();
	
	this.setVars = function(vars) {
		for (var indx in vars) {
            this.addVar(indx, vars[indx]);
        }
	}
    
    this.addVar = function(key, val) {
        _vars[_vars.length] = { k: key, v: val };
    }
    
    this.getUrl = function() {
        var res = "lang=" + _init.lang;
        
        for (var indx in _vars) {
            var obj = _vars[indx];
            res += "&" + obj.k + "=" + encodeURIComponent(obj.v);
        }
        return { url : _init.server + init.service + '.php', data : res };
    }
    
    this.call = function(params) {
        var urlData = this.getUrl();
        var dataType = typeof(params.dataType) != "undefined" ? params.dataType : "html";
        $.ajax( {  type: typeof(params.type) != "undefined" ? params.type : "POST",
                   async : typeof(params.async) != "undefined" ? params.async : true,
                   dataType : typeof(params.dataType) != "undefined" ? params.dataType : "html",
                   cache: false,
                   complete: function(res, txtStatus) {
                        if (res.status == 506) {
                            redirect(res.responseText);
                            return;
                        }
						if (params.xmlError == 'undefined' || params.xmlError == false) {
							dataType = res.status != 200 ? dataType = "html" : dataType; // errors return always in html format
						}
						if (params.dataType == 'xml' && res.responseXML != null && res.responseXML.parseError != null && res.responseXML.parseError.errorCode != 0) {
							alert(res.responseText);
						}
						params.success(dataType == "html" ? res.responseText : res.responseXML, res.status == 200 ? "success" : "error");
                   },
                   url: urlData.url,
                   data: urlData.data
                });
       // reset vars
       _vars = new Array();
    }
}

var dropDownCtrl = {
	ctrl: null, 
	
	show: function(id) {
		if (this.ctrl != null) {
			delete this.ctrl;
		}
		this.ctrl = new dropDown( {id: id, chooseFn: null} );
		this.ctrl.show();
	},
	
	sel: function(elm) {
		this.ctrl.selItem(elm);
	},
	
	get: function() {
		return this.ctrl.getSelItem();
	}
};

function dropDown(setup) {
    var _id = setup.id;
    var _over = false;
    var _oldClick = '';
    var _chooseFn = setup.chooseFn != null ? setup.chooseFn : function(){};
    var _selItem = { val: 0, name: '' };
	
	this.setDefItem = function(item) {
		this._selItem = item;
	}
    
    this.show = function() {
		_oldClick = $('body').attr('onclick');
		$('body').click(onClick);
		
        if ($('#'+_id+'Items').css('display') == 'block') {
            hide();
        }
        else {
			_over = true;
            $('#'+_id+'Items').fadeIn();
            $('#'+_id).hover(function() { _over = true; }, function() { _over = false; });
        }
    }
    
    this.hide = function() {
        hide();
    }
    
    this.selItem = function(elm, htmlVal) {
		var selItemObj = $('#'+_id+'SelItem');
		if(typeof(elm) == 'object' && htmlVal == null) {
			_selItem.val = (elm.getAttribute('value') != null) ? elm.getAttribute('value') : elm.getAttribute('id');
			_selItem.name = elm.innerHTML;
			selItemObj.html(_selItem.name);
			selItemObj.val(_selItem.val);
			hide();
		}
		else if (htmlVal != null && selItemObj.length) {
			_selItem.val = elm;
			selItemObj.html(htmlVal);
			selItemObj.val(_selItem.val);
		}
		else {
			return false;
		}
        
        if (_chooseFn != null) {
            _chooseFn(_selItem);
        }
    }
	
    this.getSelItem = function() {
        return _selItem;
    }
	
	this.reset = function() {
		this._selItem = { val: 0, name: '' };
	}
    
    function hide() {
        if ($('#'+_id).length) {
            _over = true; // false?
            $('#'+_id+'Items').fadeOut();
            $('#'+_id).hover(function(){}, function(){});
            $('body').attr('onclick', _oldClick);
        }
    }
    
    function onClick() {
        if (_over == false) {
            hide();
        }
    }
}

function sideMenu(setup) {
    var _id = setup.id;
	var _element = null;
	var _elementButton = null;
	var _elementOpen = null;
	var _elementOpenBlock = null;
	
    this.click = function() {	
		if (_element == null) {
            _element = $('#'+_id);
			_elementButton = $('#'+_id+'_Button');
            _elementOpen = $('#'+_id+'_Open');
            _elementOpenBlock = $('#'+_id+'_BlockOpen');
        }
		if(_elementButton.attr('class') == 'closed') {
			show();
		} 
		else {
			hide();
		}
	}
	function show() {
		_elementButton.attr('class','');
		_elementOpen.animate({ width: '133px' }, 'normal', function() {
				_elementOpen.css('height','auto');
				if(_elementOpenBlock.css('height') != '0px') {
					_elementOpenBlock.slideDown('normal', rightMenu.fit);
				}
			});
	}
	function hide() {
		_elementButton.attr('class','closed');
		if(_elementOpenBlock.css('height') == '0px') {
			_elementOpen.css('height','30px');
			_elementOpen.animate({ width: '30px' }, 'normal');
		}
		else {
			_elementOpenBlock.slideUp('normal', function() {
					_elementOpen.css('height', '30px');
					_elementOpen.animate({ width: '30px' }, 'normal', null, rightMenu.fit);
				});
		}
	}
}

var rightMenu = {
	tabsHolder: null,
	moveControls: null,
	processing: false,
	fit: function() {
		if(this.tabsHolder == null) {
			this.tabsHolder = $('#TabsHolder');
			this.moveControls = $('#Movecontrols');
		}
		this.tabsHolder.css('height', 'auto');
		var dh = this.tabsHolder.height();
		var bh;
		if (typeof window.innerHeight != 'undefined') {
			bh = window.innerHeight;
		}
		else if (typeof(document.documentElement) != 'undefined' && typeof(document.documentElement.clientHeight) != 'undefined' && document.documentElement.clientHeight != 0) {
			bh = document.documentElement.clientHeight;
		}
		bh=bh-180;

		if (dh > bh) {
			this.moveControls.css('display', 'block');
			this.tabsHolder.css('height', bh + 'px');
		}
		else {
			this.tabsHolder.scrollTop(0);
			this.moveControls.css('display', 'none');
			this.tabsHolder.css('height', 'auto');
		}
	},
	scroll: function(dy) {
		if(this.processing == false) {
			this.processing = true;
			this.tabsHolder.animate({scrollTop: this.tabsHolder.scrollTop()+dy}, 500, null, this.setProcessing);
		}
	},
	setProcessing: function() {
		rightMenu.processing = false;
	}
};

function showFooter() {
	if($("#FooterFullBar").is(":hidden")) {
		$("#Footer").css("height", "auto");
		$("#FooterFullBar").slideDown("normal", function() { 
			$("#FooterCopyrightLogo").css("display", "block"); 
			$("#FooterButtonHideStats").css("display", "block");
		});
	}
	else {
		$("#FooterCopyrightLogo").css("display", "none");
		$("#FooterButtonHideStats").css("display", "none");
		$("#FooterFullBar").slideUp("normal", function() { $("#Footer").css("height", "30px"); });
	}
}

function objectShow() {
    var _tmp = {bodyOnClick: '', over: true, objId: null, callBack: null};
    
    this.set = function(id, callBack) {
        if (_tmp.callBack != null) {
            clear();
        }
    
		_tmp.bodyOnClick = $("body").attr("onclick");
        $("body").click(this.click);
        _tmp.over = true;
	    _tmp.objId = id;
	    _tmp.callBack = callBack;
        $("#" + _tmp.objId).hover(function() { _tmp.over = true; }, function() { _tmp.over = false; });
    }
    
    this.click = function() {
		if (_tmp.over == false) {
			clear();
		}
    }
    
    function clear() {
        $("body").attr("onclick", _tmp.bodyOnClick);
        $("#" + _tmp.objId).hover(function(){}, function(){});
        try{
			_tmp.callBack();
		}
		catch(err){}
        _tmp.callBack = null;
    }
}

function helpLoader() {
	$('span[helpId],div[helpId],table[helpId],tr[helpId],td[helpId]').tooltip({
		track: true, delay: 300, showURL: false,
		bodyHandler: function() {
			var _helpId = this.getAttribute('helpId');
			if(typeof(helpsGlobal[_helpId]) != 'undefined') {
				var help = helpsGlobal[_helpId];
			}
			else {
				var help = (typeof(helps[_helpId]) != 'undefined') ? helps[_helpId] : _helpId;
			}
			$('#tooltipHelp').html(help);
   			return $('#tooltipBlock').html();
 		}
	});
}
    
function initFlash(params) {
    var so = new SWFObject(params.movie, 'WWfla', params.width, params.height, '9');
    so.addVariable('searchbar','false');
    so.addParam('wmode','transparent');
    so.addParam('allowfullscreen','true');
    so.addParam('allowscriptaccess','always');
	so.addParam('bgcolor','#000000');
    so.addParam('flashvars', params.flashvars);
    so.write(params.id);
}

function redirect(url) {
    window.location = url
}

function collapse(objId, parentObj) {
	var obj = $('#'+objId);
	if(obj.css('display') == 'none') {
		parentObj.className='active';
		obj.slideDown();
	}
	else {
		parentObj.className='';
		obj.slideUp();
	}
}

function getPressKeyCode(evt) {
	var code = (window.event) ? evt.keyCode : evt.which;
	return code;
}

var messageDlg = {
	params: {txt: '', callBack: null},
	
	show: function(params) {
		this.params = params;
		$('#messageDlgText').html(params.txt);
	
		$('#messageDlg').dialog( {
			width: 490,
			autoOpen: false,
			draggable: false,
			modal: true,
			position: 'center',
			resizable: false,
			overlay: { backgroundColor: '#000', opacity: 0.8 }} );
			
		$('#messageDlg').dialog('open');
	},
	
	ok: function() {
		this.close(this.params.callBack);
	},
	
	close: function(callBack) {
		$('#messageDlg').dialog('close');
		if (callBack) {
			callBack();
		}
	}
};

var confirmDlg = {
	params: {txt: '', callBackYes: null, callBackNo: null},
	
	show: function(params) {
		this.params = params;
		$('#condirmDlgText').html(params.txt);
	
		$('#confirmDlg').dialog( {
			width: 490,
			autoOpen: false,
			draggable: false,
			modal: true,
			position: 'center',
			resizable: false,
			overlay: { backgroundColor: '#000', opacity: 0.8 }} );
			
		$('#confirmDlg').dialog('open');
	},
	
	yes: function() {
		this.close(this.params.callBackYes);
	},
	
	no: function() {
		this.close(this.params.callBackNo);
	},
	
	close: function(callBack) {
		$('#confirmDlg').dialog('close');
		if (callBack) {
			callBack();
		}
	}
};

var historyUrl = {
	skipr: false,
	callBack: null,
	withoutTabs: false,
	defLink: '',
	
	init: function() {
		$.historyInit(this.loadPage);
	},
	
	setup: function(params) {
		historyUrl.skipr = true;
		historyUrl.callBack = params.callBack;
		this.defLink = params.defLink;
		if(params.withoutTabs == true) {
			this.withoutTabs = params.withoutTabs;	
		} else {
			this.withoutTabs = false;
		}
		
		var link = window.location.hash.replace(/^#\//, '');
		if (link != '') {
			window.location = '?' + link;
		} 
		else if (window.location.search.replace('?', '') == '') {
			//historyUrl.goto(this.defLink);
		}
		else {
			//historyUrl.goto(window.location.search.replace('?', ''));
		}
	},
	
	loadPage: function(link) {	
		if (historyUrl.callBack != null) {
			if (link != '') {
				historyUrl.callBack(historyUrl.getTabUrl());
			} 
			else {
				historyUrl.callBack(historyUrl.defLink);
			}
		}
		
	},
	
	goto: function(link) {
		link = '/' + link;
		$.historyLoad(link);
	},
	
	gotoPage: function(page) {
		var link = window.location.hash.replace(/^#\//, '');
		var res = link.match(/p=(.+)/);
		if (res != null && res.length == 2) {
			//var p = 'p=' + res[1];
			link = strReplace(link, 'p=' + res[1], 'p=' + page);
		}
		else {
			link += '&p=' + page;
		}
		
		var tabUrl = this.getTabUrl();
		if (tabUrl == '') {
			this.goto(this.defLink + link);
		}
		else {
			this.goto(link);
		}
	},
	
	getTabUrl: function() {
		var url = window.location.hash.replace(/^#\//, '');
		if (this.withoutTabs == false) {
			var pos = url.indexOf('&');
			if (pos != -1) {
				url = url.substring(0, pos);
			}
		}
		return url;
	},
	
	getPage: function() {
		var link = window.location.hash.replace(/^#/, '');
		var res = link.match(/p=(.+)/);
		if (res != null && res.length == 2) {
			return res[1];
		}
		return 1;
	}
};

function strReplace(haystack, needle, replacement) {
	var temp = haystack.split(needle);
	return temp.join(replacement);
}

var statusbar = {
	active: false,
	activeType: false,
	isText: 0,
	set: function(type,obj) {
		$('#posterror').css('display','none');
		
		if(type == 'text') {
			this.isText = 1;
		}
		else {
			this.isText = 0;
		}
		
		var selectedObj = $('#post'+((type == 'text') ? 'status' : type));		
		if(this.active == false) {
			this.active = $('#poststatus');
			if(profileId != null && profileId != '' && type != 'text') {
				this.isText = 1;
				this.activeType = 'text';
			}
			else {
				this.activeType = 'status';
			}
		}
		
		if(this.active == selectedObj) {
			return false;
		}
		$('#post'+this.activeType+'image').attr('src','/images/business-text-'+this.activeType+'.gif');
		$('#post'+this.activeType+'link').removeClass();
		this.active.css('display','none');
		
		$('#post'+type+'image').attr('src','/images/business-text-'+type+'-a.gif');
		$('#post'+type+'link').addClass('active');
		selectedObj.css('display','block');
		
		this.active = selectedObj;
		this.activeType = type;
	}
};

var space = {
	getMore: function() {
		modalDlg.open({ type: 'morespace', width: 400, openCallBack: function() {}, closeCallBack: function() {} });
	}
};

var tictac = 0;
function TicTac(id) {
	if (tictac == 0) {
		document.getElementById('Emotions'+id).style.display='block';
		document.getElementById('TicTac'+id).style.position='relative';
		tictac = 1;
	}
	else {
		document.getElementById('Emotions'+id).style.display='none';
		tictac = 0;
	}
}

function toBool(val) {
	return val ? 1 : 0;
}

function increaseNum(id) {
	var count = parseInt($('#' + id).html());
	$('#' + id).html(count+1);
}

function resetDefault(obj,color) {
	if (obj.value == obj.defaultValue) {
		obj.value = '';
		obj.style.color='#ffffff';
	}
	else if(obj.value == '') {
		obj.value = obj.defaultValue;
		obj.style.color=(color!=null) ? color : '#9f6679';
	}
}

var browse = {
	start: function() { },
	progress: function(loaded, total) { },
	complete: function(res) { },
	split: function(res) { return res.split('|'); }
}

var btn = {
	enable: function(id) {
		$('#' + id).removeClass('ButtonBlackDisabled');
		$('#' + id).addClass('ButtonBlack');
	},
	
	disable: function(id) {
		$('#' + id).removeClass('ButtonBlack');
		$('#' + id).addClass('ButtonBlackDisabled');
	},
	
	isEnable: function(id) {
		return $('#' + id).hasClass('ButtonBlack');
	}
}