function createRequestObject()
{
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

var http = createRequestObject();

function handleResponse()
{
    if(http.readyState == 4)
	{
        var response = http.responseText;
    }
	return response;
}

function MinimizeElement(ElementID, ParentID)
{
	abg = new Image(); // active background
	abg.src = "images/table_head_right.gif";
	ibg = new Image(); // inactive background
	ibg.src = "images/table_head_right_up.gif";

	if(document.getElementById(ElementID).style.display == "none")
	{
		document.getElementById(ElementID).style.display='block';
		document.getElementById(ParentID).style.backgroundImage = "url(" + ibg.src + ")";
	}else{
		document.getElementById(ElementID).style.display='none';
		document.getElementById(ParentID).style.backgroundImage = "url(" + abg.src + ")";
	}
}

function ShowFullArticle(ElementID, ParentID, NewsID)
{
	abg = new Image(); // active bg
	abg.src = "images/icon_arrow_up.gif";
	ibg = new Image(); // inactive background
	ibg.src = "images/icon_arrow_right.gif";
	
	if(document.getElementById(ParentID).style.display == 'block')
	{
		document.getElementById(ParentID).style.display='none';
		document.getElementById(ElementID).style.backgroundImage = "url(" + ibg.src + ")";		
	}else{
		document.getElementById(ParentID).style.display='block';
		document.getElementById(ElementID).style.backgroundImage = "url(" + abg.src + ")";
	}
	
	// Ajaxabfrage
	var req = new XMLHttpRequest();
	var rand = Math.random(1000);
	http.open('GET', 'ajaxshowarticle.php?id='+NewsID+"&rand="+rand, false); 
	http.send(null);
	document.getElementById(ParentID).innerHTML = handleResponse();
}

function CheckLogin()
{
	var ErrorMsg;
	ErrorMsg = "";
	if(document.getElementById("username").value == "")
	{
		ErrorMsg = ErrorMsg + "Bitte geben Sie Ihren Benutzername ein.\n";
	}
	
	if(document.getElementById("password").value == "")
	{
		ErrorMsg = ErrorMsg + "Bitte geben Sie ein Passwort ein.";
	}
	
	if(ErrorMsg != "")
	{
		alert(ErrorMsg);
	}else{
		document.getElementById("loginbox").submit();
	}
}

function MarkArticle(articleid)
{
	window.setTimeout(function () { UnMarkArticle(articleid); },1000);
	document.getElementById("newscontainer"+articleid).style.backgroundColor = "#F7F7F7";
	document.getElementById("newscontainer"+articleid).style.border = "1px solid #EAEAEA";
}

function UnMarkArticle(articleid)
{
	document.getElementById("newscontainer"+articleid).style.backgroundColor = "#ffffff";
	document.getElementById("newscontainer"+articleid).style.border = "1px solid #ffffff";	
}

function MarkService(serviceid)
{
	window.setTimeout(function () { UnMarkArticle(serviceid); },1000);
	document.getElementById("servicecontainer"+serviceid).style.backgroundColor = "#F7F7F7";
	document.getElementById("servicecontainer"+serviceid).style.border = "1px solid #EAEAEA";
}

function UnMarkService(serviceid)
{
	document.getElementById("servicecontainer"+serviceid).style.backgroundColor = "#ffffff";
	document.getElementById("servicecontainer"+serviceid).style.border = "1px solid #ffffff";	
}

// UTF Kodieren der PostDaten
function encode_utf8(rohtext)
{
	// dient der Normalisierung des Zeilenumbruchs
	rohtext = rohtext.replace(/\r\n/g,"\n");
	var utftext = "";
	for(var n=0; n<rohtext.length; n++)
	{
		// ermitteln des Unicodes des  aktuellen Zeichens
		var c=rohtext.charCodeAt(n);
		// alle Zeichen von 0-127 => 1byte
		if (c<128)
		utftext += String.fromCharCode(c);
		// alle Zeichen von 127 bis 2047 => 2byte
		else if((c>127) && (c<2048))
		{
			utftext += String.fromCharCode((c>>6)|192);
			utftext += String.fromCharCode((c&63)|128);
		}
		// alle Zeichen von 2048 bis 66536 => 3byte
		else {
			utftext += String.fromCharCode((c>>12)|224);
			utftext += String.fromCharCode(((c>>6)&63)|128);
			utftext += String.fromCharCode((c&63)|128);
		}
	}
return utftext;
}

function decode_utf8(utftext)
{
	var plaintext = ""; var i=0; var c=c1=c2=0;
	// while-Schleife, weil einige Zeichen uebersprungen werden
	while(i<utftext.length)
	{
		c = utftext.charCodeAt(i);
		if (c<128)
		{
			plaintext += String.fromCharCode(c);
			i++;
		}
		else if((c>191) && (c<224))
		{
			c2 = utftext.charCodeAt(i+1);
			plaintext += String.fromCharCode(((c&31)<<6) | (c2&63));
			i+=2;
		}
		else {
			c2 = utftext.charCodeAt(i+1); c3 = utftext.charCodeAt(i+2);
			plaintext += String.fromCharCode(((c&15)<<12) | ((c2&63)<<6) | (c3&63));
			i+=3;
		}
	}
return plaintext;
}

function ShowImprint()
{
  args = 'width=125,height=380';
  window.open("http://www.nh-deutschland.de/impressum.htm",'',args)
}

function ShowConditions()
{
  args = 'width=125,height=300';
  window.open("http://www.nh-deutschland.de/buchungsbedingungen.htm",'',args)
}

function ShowDisclaimer()
{
  args = 'width=125,height=500,scrollbars=yes';
  window.open("http://www.nh-deutschland.de/nutzungsbedingungen.htm",'',args)
}

function ShowDataSecurity()
{
  args = 'width=125,height=500,scrollbars=yes';
  window.open("http://www.nh-deutschland.de/datenschutzbestimmungen.htm",'',args)
}

function Showagb()
{
  args = 'width=525,height=500,scrollbars=yes';
  window.open("http://www.nh-deutschland.de/agb.htm",'',args)
}

function LoadMarker(X,Y,TextID,Text,PepID)
{
	var Text;
	var left = X;
	var top = Y;
	new_id = TextID;
		
	new_tr = document.createElement("div");
	new_tr.setAttribute('id', new_id);
	document.getElementById(PepID).appendChild(new_tr);
	
	document.getElementById(new_id).style.position = "absolute";
	document.getElementById(new_id).style.left = X-0 + "px";
	document.getElementById(new_id).style.top = Y-5 + "px";
	document.getElementById(new_id).innerHTML = "<div style=\"display:block;\">" + Text + "</div>";
}
