var resObjekt;

if( navigator.appName.search('Microsoft') > -1) {

  //resObjekt = new ActiveXObject("Microsoft.XMLHTTP");
  resObjekt = new ActiveXObject("MSXML2.XMLHTTP");

} else {
  resObjekt = new XMLHttpRequest();
}

function ajax_request(request_methode, lnk) {
  resObjekt.open(request_methode, lnk, true);
  resObjekt.onreadystatechange = handleResponse;
  resObjekt.send(null);

}


function handleResponse() {

	if(resObjekt.readyState == 4) {
		resp_txt = resObjekt.responseText;
		// alert(resp_txt);
  		resp_arr = resp_txt.split("|");
  		if(resp_arr[0] == 'fehler') {
	    	alert(resp_arr[1]);
  		} else {
    		if(resp_arr[0] == 'js_navi') {
    			t = html_sicher(resp_arr[1]);
	    		document.getElementById("menu_oben_div").innerHTML = '<nobr>' + t + '</nobr>';
    		}
  		}
  	}

  	menu_links_pruefen();
}


function js_navi_aufbauen() {

	// alert(n);
	n2 = ajx_sicher(n);
	ajax_request('get', 'fileadmin/templates_mediadruckwerk/scripts/ajx.php?akt_page='+akt_page+'&js_navi=' + n2);
}

/**
 *
 * @access public
 * @return void
 **/
function menu_links_pruefen() {
	if(document.getElementById("td_navigation").innerHTML != "") {
		txt = document.getElementById("div_navigation").innerHTML;
		// alert("'" + txt + "'");
		if(txt.indexOf("<") == -1) {
			document.getElementById("td_navigation").innerHTML = "";
		}
	}
}

/**
 *
 * @access public
 * @return void
 **/
function ajx_sicher(txt) {
	i=0;
	while(txt.indexOf("?") != -1 && i<10)
	{
		txt = txt.replace("?","_FRAG_");
		i++;
	}
	i=0;
	while(txt.indexOf("&") != -1 && i<10)
	{
		txt = txt.replace("&","_UND_");
		i++;
	}

	i=0;
	while(txt.indexOf("ä") != -1 && i<10)
	{
		txt = txt.replace("ä", "_ae_");
		i++;
	}

	i=0;
	while(txt.indexOf("ö") != -1 && i<10)
	{
		txt = txt.replace("ö", "_oe_");
		i++;
	}

	i=0;
	while(txt.indexOf("ü") != -1 && i<10)
	{
		txt = txt.replace("ü", "_ue_");
		i++;
	}


	return txt;
}

/**
 *
 * @access public
 * @return void
 **/
function html_sicher(txt) {
	i=0;
	while(txt.indexOf("_FRAG_") != -1 && i<10)
	{
		txt = txt.replace("_FRAG_", "?");
		i++;
	}
	i=0;
	while(txt.indexOf("_UND_") != -1 && i<10)
	{
		txt = txt.replace("_UND_", "&");
		i++;
	}

	i=0;
	while(txt.indexOf("_ae_") != -1 && i<10)
	{
		txt = txt.replace("_ae_", "&auml;");
		i++;
	}

	i=0;
	while(txt.indexOf("_oe_") != -1 && i<10)
	{
		txt = txt.replace("_oe_", "&ouml;");
		i++;
	}

	i=0;
	while(txt.indexOf("_ue_") != -1 && i<10)
	{
		txt = txt.replace("_ue_", "&uuml;");
		i++;
	}


	return txt;
}

function getURLParam(strParamName){
	var strReturn = "";
	var strHref = window.location.href;
	if ( strHref.indexOf("?") > -1 ) {
	    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
	    var aQueryString = strQueryString.split("&");
    	for ( var iParam = 0; iParam < aQueryString.length; iParam++ ) {
      		if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ) {
        		var aParam = aQueryString[iParam].split("=");
        		strReturn = aParam[1];
        		break;
      		}
    	}
  	}
  	return strReturn;
}
