
/***************************************************************
 ** toggle chart
 ***************************************************************/
function toggleChart(i) {
	var url = "togglechart.action?chartid=" + i;
	var xmlHttp = getXmlHttpObject();
	if (xmlHttp) {
		xmlHttp.open("POST", url, true);
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
		xmlHttp.onreadystatechange = function () {
		};
		xmlHttp.send("null");
	} else {
		//no toggling for charts possible since browser does not support ajax 
	}
}

/***************************************************************
** toggle navigation
***************************************************************/
function toggleNavigation(i) {
	var url = "togglenavigation.action?navigationid=" + i;
	var xmlHttp = getXmlHttpObject();
	if (xmlHttp) {
		xmlHttp.open("POST", url, true);
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
		xmlHttp.onreadystatechange = function () {
		};
		xmlHttp.send("null");
	} else {
		//no toggling for Navigations possible since browser does not support ajax 
	}
}


function toggleAdvertiseNavigation(i) {
	var url = "toggleAdvertiseNavigation.action?advertiseid=" + i;
	var xmlHttp = getXmlHttpObject();
	if (xmlHttp) {
		xmlHttp.open("POST", url, true);
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
		xmlHttp.onreadystatechange = function () {
		};
		xmlHttp.send("null");
	} else {
		//no toggling for Navigations possible since browser does not support ajax 
	}
}


/***************************************************************
** toggle navigation
***************************************************************/
function toggleServiceNavigation(code) {
	var url = "toggleServiceNavigation.action?serviceid=" + code;
	var xmlHttp = getXmlHttpObject();
	if (xmlHttp) {
		xmlHttp.open("POST", url, true);
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
		xmlHttp.onreadystatechange = function () {
		};
		xmlHttp.send("null");
	} else {
		//no toggling for Navigations possible since browser does not support ajax 
	}
}


/***************************************************************
** toggle filialen navigation
***************************************************************/
function toggleTrader() {
	if (document.getElementById("left-navig-2")){
		if (document.getElementById("left-navig-2").style.display == 'none'){
			document.getElementById("left-navig-2").style.display = 'block';
		} else {
			document.getElementById("left-navig-2").style.display = 'none';
		}
	}
}

/***************************************************************
 ** location search
 ***************************************************************/
function AjaxTransport(targetElementID) {
	this.elementID = targetElementID;
	this.getXMLHTTP = function (url) {
		var xmlHttp = getXmlHttpObject();
		if (xmlHttp) {
			xmlHttp.open("POST", url, true);
			xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
			xmlHttp.onreadystatechange = function () {
				if (xmlHttp.readyState == 4) { //Complete
					var oldElement = document.getElementById(targetElementID);
					if (oldElement) {
						var responseText = xmlHttp.responseText;
						if (responseText.indexOf("Exception") > -1) {
							window.location = "index.action";
						} 
						else {
							var parentElement = oldElement.parentNode;
								//parentElement.innerHTML = responseText;
							oldElement.innerHTML = responseText;
						}
					}
					initHideBox();
				}
				
			};
			return xmlHttp;
		} else {	
			//no dynamic location search since browser does not support ajax
		}
	};
	this.send = function (postURL, postValue) {
		this.getXMLHTTP(postURL).send(postValue);
	};
}
function ajaxSubmit(formID, elementID, originalFormAction, ajaxFormAction) {
	var form = document.getElementById(formID);
	if (typeof encodeURIComponent == "function") {
		var postValue = "";
		var postURL = form.action;
		postURL = postURL.replace(originalFormAction, ajaxFormAction);
		for (i = 0; i < form.elements.length; i++) {
			if (form.elements[i].value != '') {
				postValue += encodeURIComponent(form.elements[i].name);
				postValue += "=";
				postValue += encodeURIComponent(form.elements[i].value);
			}
		}
		if (new AjaxTransport(elementID).send(postURL, postValue) == false) {
			//regular request in case of error within js
			form.submit();
		}
	} else {
		//regular request in case of browser does not support ajax
		form.submit();
	}
}
/***************************************************************
 ** ajax helper
 ***************************************************************/
function getXmlHttpObject() {
	var xmlHttp = false;
	// Internet Explorer
	try {
		xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (e) {
		try {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e) {
			xmlHttp = false;
		}
	}          
	// Mozilla, Opera und Safari
	if (!xmlHttp && typeof XMLHttpRequest != "undefined") {
		xmlHttp = new XMLHttpRequest();
	}
	return xmlHttp;
}

function popup(w, h, site) {
	x = screen.availWidth / 2 - w / 2;
	y = screen.availHeight / 2 - h / 2;
	var popupWindow = window.open("", "", "width=" + w + ",height=" + h + ",left=" + x + ",top=" + y + ",screenX=" + x + ",screenY=" + y);
	popupWindow.document.write(site);
}

