function responseDummy(Resp) {
};

function openFeedbackDialog() {
	$('FeedbackFormPane').innerHTML = T("loading");
	showModalDialog("FeedbackDialog", T("feedback.title"), 500, 450);
	x_getEmptyFeedbackForm(showFeedbackDialog);
};

function showFeedbackDialog(resp) {
	updateID('FeedbackFormPane', resp);

	win.setContent('FeedbackDialog', true);
};

function hideFeedbackForm() {
	hideModalDialog();
};

function myAlert(text) {
	Dialog.alert(text, {width:300, height:100, okLabel: "OK"});
};

function getInnerText(el) {
  if(typeof el.innerText != "undefined") {
    return el.innerText;
  } else {
    return el.textContent;
   }
};

function getRadioValue(formname, elname) {
	var radiovalue;

	try {
		Form.getInputs(formname, 'radio').each(function(input) {
			if(input.name==elname && input.checked) {
				radiovalue=input.value
			};
		});

		return radiovalue;
	} catch(e) {
		alert(e);
		return false;
	}
};

function getCheckValue(elname) {
	if ($F(elname) == "on") {
		return 1;
	} else {
		return 0;
	}
};

function setToolTip(el, text) {
	$(el).onmouseover = 'return escape("' + text + '");';
};

function strikeThrough(obj) {
	obj.innerHTML = '<span style="text-decoration:line-through">' + obj.innerHTML + '</span>';
};

function addOnLoadEvent(func) {
	var oldonload = window.onload;

	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
};

function addOnClickEvent(obj, func) {
	var oldonclick = obj.onclick;

	if (typeof obj.onclick != 'function') {
		obj.onclick = func;
	} else {
		obj.onclick = function() {
			if (oldonclick) {
				oldonclick();
			}
			func();
		}
	}
};

function addOnChangeEvent(obj, func) {
	var oldonchange = obj.onchange;

	if (typeof obj.onchange != 'function') {
		obj.onchange = func;
	} else {
		obj.onchange = function() {
			if (oldonchange) {
				oldonchange();
			}
			func();
		}
	}
};

function addOnKeyUpEvent(obj, func) {
	var oldonkeyup = obj.onkeyup;

	if (typeof obj.onkeyup != 'function') {
		obj.onkeyup = func;
	} else {
		obj.onkeyup = function() {
			if (oldonkeyup) {
				oldonkeyup();
			}
			func();
		}
	}
};

function getCurHRefBase() {
	var href = window.location.href;
	var comp = href.split("/");

	comp.pop();

	return comp.join("/") + "/";
};

function JSDate2SQL(jsdate) {
	return jsdate.getFullYear() + '-' + (jsdate.getMonth()+1) + '-' + jsdate.getDate() +
	 			 ' ' + jsdate.getHours() + ':' + jsdate.getMinutes() + ':00';
};

function showModalDialog(name, caption, width, height, zindex) {
	if (arguments.length<3) width = 350;
	if (arguments.length<4) height = 220;
	win = new Window({className: "alphacube", title:caption, zIndex: zindex, minWidth:width, minHeight:height, resizable:true, minimizable:false, maximizable:false, destroyOnClose:false, recenterAuto:true}); 
	win.setContent(name, true);
	win.showCenter(true);
	resizeModalDialog();
};

function hideModalDialog(name) {
	win.close();
};

function resizeModalDialog() {
	win.updateWidth();
	win.updateHeight();
};

function bindOnClick(elID, funcName, obj) {
	if ($(elID)) addOnClickEvent($(elID), funcName.bind(obj));
};

function bindOnChange(elID, funcName, obj) {
	if ($(elID)) addOnChangeEvent($(elID), funcName.bind(obj));
};

function bindOnKeyUp(elID, funcName, obj) {
	if ($(elID)) addOnKeyUpEvent($(elID), funcName.bind(obj));
};

function bindOnReturn(elID, funcName, obj, evalcode) {
	if (arguments.length < 4) evalcode = "";
	if ($(elID)) $(elID).onkeypress = function(event) {
			var code = (event.which) ? event.which : event.keyCode;

			if (code == 13) {
				if (evalcode != "") {
					eval(evalcode);
				} else {
					funcName();
				}
			}
	}.bindAsEventListener(obj);
};

function exchangeMainPage(name) {
	$('Loading').show();
	x_getMainPage(name, exchangeMainPage_Resp);
};

function registerDynScripts(obj) {
	// execute any Javascript which has been sent
	scripts = obj.getElementsByTagName('script');
	for (i=0; i<scripts.length; i++) {
		eval(scripts[i].innerHTML);
	}
}

function exchangeMainPage_Resp(resp) {
	$('MainContentPane').innerHTML =
		'<img id="Loading" src="images/loading.gif" align="right" title="' + T('loading') + '..."/>' +
		resp;

	registerDynScripts($('MainContentPane'));
	setTitleBar();
	$('Loading').hide();
};

function updateID(id, resp) {
	if ($(id)) {
		$(id).innerHTML = unescape(resp);
		registerDynScripts($(id));
	}
};

function closeAllQuickEntry() {
	var list = document.getElementsByClassName('NewQuickEntry');

	for (i=0; i<list.length; i++) {
		list[i].hide();
	}
};

function MyTab(Caption, ID, Link, Pane, JSCode, ConObject) {
	this.Caption = Caption;
	this.ID = ID;
	this.Link = Link;
	this.Pane = Pane;
	this.JSCode = JSCode;
	this.ConObject = ConObject;
};

function MyTabs(VarName, Container) {
	this.VarName = VarName;
	this.Container = Container;
	this.Class = "CommandArea";
	this.MainMenuLink = false;
	this.DisplayType = 0;
	this.ActiveTab = 0;
	this.Tabs = new Array();
};

MyTabs.prototype.setActiveTab = function(tabIdx) {
	for (var i=0; i<this.Tabs.length; i++) {
		if (this.Tabs[i].Pane != "" && $(this.Tabs[i].Pane)) {
			$(this.Tabs[i].Pane).hide();
		}
		if (this.Tabs[i].ConObject != "" && $(this.Tabs[i].ConObject)) {
			$(this.Tabs[i].ConObject).hide();
		}

		if (this.Tabs[i].ID != "" && this.Tabs[i].ID == tabIdx) tabIdx = i;
	}

	this.ActiveTab = tabIdx;
	if (tabIdx >= 0) {
		this.ActiveTabKey = this.Tabs[tabIdx].ID;
		if ($(this.Tabs[tabIdx].Pane)) {
			$(this.Tabs[tabIdx].Pane).show();
		}
		if ($(this.Tabs[tabIdx].ConObject)) {
			$(this.Tabs[tabIdx].ConObject).show();
		}
		if (this.Tabs[tabIdx].JSCode != "") {
			eval(this.Tabs[tabIdx].JSCode);
		}
	}
	this.showTabs();
};

MyTabs.prototype.setNextTab = function() {
	this.setActiveTab(this.ActiveTab+1);
};

MyTabs.prototype.hideIfOne = function() {
	if (this.Tabs.length <= 1) {
		$(this.Container).innerHTML = '<div class="CommandArea2">&nbsp;</div>';
		if ($('MainMenuContent')) $('MainMenuContent').show();
	}
};

MyTabs.prototype.showTabs = function() {
	var ret = "";
	var onClickStr = "";

	if (this.DisplayType == 0) {
		if ($(this.Container)) {
			ret += '<div class="' + this.Class + ' tabstrip">';
			if (this.MainMenuLink) {
				if ($("MainMenuContent")) {
					$("MainMenuContent").hide();
					ret += '<div id="ShowMainMenuContent" style="float:left;vertical-align:middle">';
					ret += '<a href="#" onclick="$(\'ShowMainMenuContent\').hide();$(\'MainMenuContent\').show();">';
					ret += '<img src="images/up.gif" align="left" vspace="0" hspace="2"/> '+T('Mainmenu');
					ret += '</a></div>';
				}
			}
			ret += '<ul>&nbsp;';
			for (var i=0; i<this.Tabs.length; i++) {
				ret += '<li>';
				if (this.ActiveTab == i && (this.Tabs.length > 1 || this.Tabs[i].Link == "")) {
					ret += '<span class="selected">' + this.Tabs[i].Caption + "</span>";
				} else {
					onClickStr = '';
					if (this.Tabs[i].Link == "") {
						if (this.Tabs[i].Pane != "") {
							onClickStr += 'onClick="' + this.VarName + '.setActiveTab(' + i + ');';
							onClickStr += '"';
						} else {
							if (this.Tabs[i].JSCode != "") {
								onClickStr += 'onClick="' + this.Tabs[i].JSCode + ';"';
							}
						}

						ret += '<nobr><a href="#" id="' + this.Tabs[i].ID + '" ' + onClickStr + '>';
						ret += this.Tabs[i].Caption;
						ret += '</a></nobr>';
					} else {
						if (this.Tabs[i].JSCode != "") {
							onClickStr += 'onClick="' + this.Tabs[i].JSCode + '"';
						}

						ret += '<nobr><a href="' + this.Tabs[i].Link + '" id="' + this.Tabs[i].ID + '" ' + onClickStr + '>';
						ret += this.Tabs[i].Caption;
						ret += '</a></nobr>';
					}
				}
				ret += '</li>';
				ret += '<li class="spacer"> </li>';
			}
			ret += '</ul>';
			ret += '</div>';

			$(this.Container).innerHTML = ret;
		}
	} else {
		for (var i=0; i<this.Tabs.length; i++) {
			onClickStr = "$('" + this.Tabs[i].Pane + "').toggle();$('" + this.Tabs[i].ID + "_closedimg').toggle();$('" + this.Tabs[i].ID + "_openimg').toggle();";

			ret = '<div class="paragraph">';
			ret += '<h2 class="link" onclick="' + onClickStr + '">';
			if (this.ActiveTab == i) {
				ret += '<img id="' + this.Tabs[i].ID + '_closedimg" src="/images/bullet.png" style="display:none"/>';
				ret += '<img id="' + this.Tabs[i].ID + '_openimg" src="/images/bullet_down.png"/>';
			} else {
				ret += '<img id="' + this.Tabs[i].ID + '_closedimg" src="/images/bullet.png"/>';
				ret += '<img id="' + this.Tabs[i].ID + '_openimg" src="/images/bullet_down.png" style="display:none"/>';
			}
			ret += this.Tabs[i].Caption;
			ret += '</h2>';
			ret += '<div/>';

			if ($(this.Tabs[i].ID + '_menu')) $(this.Tabs[i].ID + '_menu').remove();
			var menu = document.createElement('div');
			menu.id = this.Tabs[i].ID + '_menu';
			menu.innerHTML = ret;

			$('EventEditPane').insertBefore(menu, $(this.Tabs[i].Pane));
		}
	}
};

MyTabs.prototype.addTab = function(Caption, ID, Link, Pane, JSCode, ConObject) {
	ID = (arguments.length >= 2) ? ID : "";
	Link = (arguments.length >= 3) ? Link : "";
	Pane = (arguments.length >= 4) ? Pane : "";
	JSCode = (arguments.length >= 5) ? JSCode : "";
	ConObject = (arguments.length >= 6) ? ConObject : "";

	this.Tabs[this.Tabs.length] = new MyTab(Caption, ID, Link, Pane, JSCode, ConObject);
};

function updateDynamics() {
	fdTableSort.init();
	tablePaginater.init();
};

function ieGallery(element, idx) {
	this.allItems = element.getElementsByClassName('imageElement');
	this.allItems.each(function(el) {
		var img = el.getElementsByClassName("full")[0];
		el.style.backgroundImage = "url('" + img.src + "')";
	});
	this.currentItem = 0;
	this.selectItem(idx);
};

ieGallery.prototype.selectItem = function(idx) {
	this.allItems[this.currentItem].style.display = "none";
	this.allItems[idx].style.display = "block";
	this.currentItem = idx;
};

ieGallery.prototype.prevItem = function() {
	var idx = this.currentItem;
	idx--;
	if( idx < 0 ) idx = this.allItems.length - 1;
	this.selectItem(idx);
};

ieGallery.prototype.nextItem = function() {
	var idx = this.currentItem;
	idx++;
	if( idx >= this.allItems.length ) idx = 0;
	this.selectItem(idx);
};

var FCKeditorLoaded = false;

function FCKeditor_OnComplete(editorInstance) {
  FCKeditorLoaded = true;
}

function switchEditors(ID) {
  if(!FCKeditorLoaded) {
    setTimeout('switchEditors(\'' + ID + '\')', 500);
    return;
  }
  DoSwitchEditors(document.getElementById(ID));
}

function DoSwitchEditors(oNode) {
  var i;
  for (i = 0; i < oNode.childNodes.length;i++) {
    childNode = oNode.childNodes.item(i);
    editor = FCKeditorAPI.GetInstance(childNode.name);
    if (editor && editor.EditorDocument && editor.EditMode == FCK_EDITMODE_WYSIWYG) {
      editor.SwitchEditMode();
      editor.SwitchEditMode();
    }
    DoSwitchEditors(childNode);
  }
}

function saveBookmark(text) {
	if (Prototype.Browser.IE) {
		window.external.addFavorite(location.href, text);
	} else {
		window.sidebar.addPanel(text, location.href, "");
	}
}

function loadScript(link, id) {
	if ($(id)) return false;

	var d = document.createElement('div');
	d.id = id;

	var a = document.createElement('script');
	a.setAttribute('type', 'text/javascript');
	a.setAttribute('src', link);
	d.appendChild(a);

	document.getElementsByTagName('body')[0].appendChild(d);
	/*registerDynScripts(d);*/
}

/** returns an Elements absolute screen position
*/
function getElementPosition(obj) {
	if (!obj) return false;
	
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function getRadioValue2(radioGroup) {
	var r = document.getElementsByName(radioGroup);
	for (var i=0; i<r.length; i++) {
		if (r[i].checked) return r[i].value;
	}
	return null;
}

String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
    return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
    return this.replace(/\s+$/,"");
}

