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;
} 

var site = getURLParam("site");
var site_id;

switch(site){
	default:
	case "home":
		site_id = 0;
	break;
	case "angebote":
		site_id = 1;
	break;
	case "ueberuns":
		site_id = 2;
	break;
	case "leistungsspektrum":
		site_id = 3;
	break;
	case "kontakt":
		site_id = 4;
	break;
	case "impressum":
		site_id = 5;
	break;
}

function btn_over(target){
	var get_id = target.slice(4,5);
	if(site_id != get_id){
		document.images[target].src = "images/"+target+"_over.gif";
	}
}
function btn_out(target){
	var get_id = target.slice(4,5);
	if(site_id != get_id){
		document.images[target].src = "images/"+target+".gif";
	}
}
function btn_set(){
	document.images["btn_"+site_id].src = "images/btn_"+site_id+"_act.gif";
}

function editor(divclassIE, height, width, content, css){
	var objIE = "document";
	var objMoz = "document.getElementById('myeditormoz').contentWindow.document";
	
	var focusMoz = "document.getElementById('myeditormoz').contentWindow.focus()";
	
	var BoldIE = objIE+".execCommand('Bold', false, null)";
	var BoldMoz =objMoz+".execCommand('Bold',false, null);"+focusMoz;
	var ItalicIE = objIE+".execCommand('Italic', false, null)";
	var ItalicMoz =objMoz+".execCommand('Italic',false, null);"+focusMoz;
	var UlineIE = objIE+".execCommand('Underline', false, null)";
	var UlineMoz =objMoz+".execCommand('Underline',false, null);"+focusMoz;
	var h1IE = objIE+".execCommand('FormatBlock', false, '<H1>')";
	var h1Moz =objMoz+".execCommand('FormatBlock',false, '<H1>');"+focusMoz;
	var h2IE = objIE+".execCommand('FormatBlock', false, '<H2>')";
	var h2Moz =objMoz+".execCommand('FormatBlock',false, '<H2>');"+focusMoz;
	var pIE = objIE+".execCommand('FormatBlock', false, '<p>')";
	var pMoz =objMoz+".execCommand('FormatBlock',false, '<p>');"+focusMoz;
	var LeftIE = objIE+".execCommand('JustifyLeft', false, null)";
	var LeftMoz =objMoz+".execCommand('JustifyLeft',false, null);"+focusMoz;
	var CenterIE = objIE+".execCommand('JustifyCenter', false, null)";
	var CenterMoz =objMoz+".execCommand('JustifyCenter',false, null);"+focusMoz;
	var RightIE = objIE+".execCommand('JustifyRight', false, null)";
	var RightMoz =objMoz+".execCommand('JustifyRight',false, null);"+focusMoz;
	var OListIE = objIE+".execCommand('InsertOrderedList', false, null)";
	var OListMoz =objMoz+".execCommand('InsertOrderedList',false, null);"+focusMoz;
	var UListIE = objIE+".execCommand('InsertUnorderedList', false, null)";
	var UListMoz =objMoz+".execCommand('InsertUnorderedList',false, null);"+focusMoz;
	var LinkIE = objIE+".execCommand('CreateLink', true, null)";
	var LinkMoz =objMoz+".execCommand('CreateLink', false, prompt('URL?','http://'));"+focusMoz;
	
	
	var editableIE = "<div id='myeditor' contentEditable style='padding:0px; height="+(height-40)+"; border-style:solid; border-width:1px;'>"+content+"</div>";
	var editableMoz = "<iframe id='myeditormoz' name='myeditor' height='"+height+"' width='"+width+"' frameborder='1' marginwidth='0' marginheight='0'></iframe>";
	
	if(((document.all) && (window.offscreenBuffering))){
		document.write(editableIE);
		document.write("<div align='left' style=\"padding-top: 10px\">");
		document.write("<img src=\"images/button-bold.gif\" onClick=\""+BoldIE+"\" style=\"cursor: pointer\">&nbsp;");
		document.write("<img src=\"images/button-italic.gif\" onClick=\""+ItalicIE+"\" style=\"cursor: pointer\">&nbsp;");
		document.write("<img src=\"images/button-underline.gif\" onClick=\""+UlineIE+"\" style=\"cursor: pointer\">&nbsp;");
		document.write("&nbsp;&nbsp;");
		document.write("<img src=\"images/button-h1.gif\" onClick=\""+h1IE+"\" style=\"cursor: pointer\">&nbsp;");
		document.write("<img src=\"images/button-h2.gif\" onClick=\""+h2IE+"\" style=\"cursor: pointer\">&nbsp;");
		document.write("<img src=\"images/button-p.gif\" onClick=\""+pIE+"\" style=\"cursor: pointer\">&nbsp;");
		document.write("&nbsp;&nbsp;");
		document.write("<img src=\"images/button-left.gif\" onClick=\""+LeftIE+"\" style=\"cursor: pointer\">&nbsp;");
		document.write("<img src=\"images/button-center.gif\" onClick=\""+CenterIE+"\" style=\"cursor: pointer\">&nbsp;");
		document.write("<img src=\"images/button-right.gif\" onClick=\""+RightIE+"\" style=\"cursor: pointer\">&nbsp;");
		document.write("&nbsp;&nbsp;");
		document.write("<img src=\"images/button-olist.gif\" onClick=\""+OListIE+"\" style=\"cursor: pointer\">&nbsp;");
		document.write("<img src=\"images/button-ulist.gif\" onClick=\""+UListIE+"\" style=\"cursor: pointer\">&nbsp;");
		document.write("&nbsp;&nbsp;");
		document.write("<img src=\"images/button-link.gif\" onClick=\""+LinkIE+"\" style=\"cursor: pointer\">&nbsp;");
		document.write("</div>");
		
	}else{
		document.open();
		document.write(editableMoz);
		document.getElementById('myeditormoz').contentWindow.document.designMode='On';
		document.getElementById('myeditormoz').contentWindow.document.open();
		document.getElementById('myeditormoz').contentWindow.document.write("<html><link href='css/iframe.css' rel='stylesheet' type='text/css'><body>");
		document.getElementById('myeditormoz').contentWindow.document.write(content);
		document.getElementById('myeditormoz').contentWindow.document.write("</body></html>");
		document.getElementById('myeditormoz').contentWindow.document.close();
		document.write("<div align='left' style=\"padding-top: 10px\">");
		document.write("<img src=\"images/button-bold.gif\" onClick=\""+BoldMoz+"\" style=\"cursor: pointer\">&nbsp;");
		document.write("<img src=\"images/button-italic.gif\" onClick=\""+ItalicMoz+"\" style=\"cursor: pointer\">&nbsp;");
		document.write("<img src=\"images/button-underline.gif\" onClick=\""+UlineMoz+"\" style=\"cursor: pointer\">&nbsp;");
		document.write("&nbsp;&nbsp;");
		document.write("<img src=\"images/button-h1.gif\" onClick=\""+h1Moz+"\" style=\"cursor: pointer\">&nbsp;");
		document.write("<img src=\"images/button-h2.gif\" onClick=\""+h2Moz+"\" style=\"cursor: pointer\">&nbsp;");
		document.write("<img src=\"images/button-p.gif\" onClick=\""+pMoz+"\" style=\"cursor: pointer\">&nbsp;");
		document.write("&nbsp;&nbsp;");
		document.write("<img src=\"images/button-left.gif\" onClick=\""+LeftMoz+"\" style=\"cursor: pointer\">&nbsp;");
		document.write("<img src=\"images/button-center.gif\" onClick=\""+CenterMoz+"\" style=\"cursor: pointer\">&nbsp;");
		document.write("<img src=\"images/button-right.gif\" onClick=\""+RightMoz+"\" style=\"cursor: pointer\">&nbsp;");
		document.write("&nbsp;&nbsp;");
		document.write("<img src=\"images/button-olist.gif\" onClick=\""+OListMoz+"\" style=\"cursor: pointer\">&nbsp;");
		document.write("<img src=\"images/button-ulist.gif\" onClick=\""+UListMoz+"\" style=\"cursor: pointer\">&nbsp;");
		document.write("&nbsp;&nbsp;");
		document.write("<img src=\"images/button-link.gif\" onClick=\""+LinkMoz+"\" style=\"cursor: pointer\">&nbsp;");
		document.write("<br>");
		document.write("</div>");
		document.close();
	}
	
}

function getEditorHTML(){
	
	if(((document.all) && (window.offscreenBuffering)))
		var obj = document.getElementById('myeditor').innerHTML;
	else
		var obj = document.getElementById('myeditormoz').contentWindow.document.body.innerHTML;
		
	return obj;
}

function makeComm(command ,param) {
	alert(document.getElementById("myeditor").contentWindow.document.queryCommandValue('FontSize'));
	if(command == 'FormatBlock' && document.getElementById("myeditor").contentWindow.document.queryCommandValue('FontSize') != null) param = '<p>';
	if(navigator.appName=='Netscape' && command=='CreateLink'){
		if(param=='') param=prompt('URL?','http://');
		if ((param != null) && (param != ""))
      		document.getElementById("myeditor").contentWindow.document.execCommand(command,false, param);		
	}else if(navigator.appName!='Netscape' && command=='CreateLink' && param==''){
		document.getElementById("myeditor").contentWindow.document.execCommand(command,true,null);
	}else{
		if (param=='')
			document.getElementById("myeditor").contentWindow.document.execCommand(command,false,null);
		else
			document.getElementById("myeditor").contentWindow.document.execCommand(command,false, param);
	}
	document.getElementById("myeditor").contentWindow.focus();	
}

var editormode=''; 

function switcheditor(sw){
	
	if(navigator.appName=='Netscape'){
		if(sw=='code' && editormode==''){
				var html = document.createTextNode(document.getElementById("myeditor").contentWindow.document.body.innerHTML);
				document.getElementById("myeditor").contentWindow.document.body.innerHTML = "";
				document.getElementById("myeditor").contentWindow.document.body.appendChild(html);
				document.getElementById("codeview").style.backgroundColor='#a0a0a0';
				document.getElementById("textview").style.backgroundColor='';
				for(var i=1;i<7;++i)
					document.getElementById("editb"+i).disabled=true;
				editormode='code';
		}
		else if(sw=='' && editormode=='code'){
				var html = document.getElementById("myeditor").contentWindow.document.body.ownerDocument.createRange();
				html.selectNodeContents(document.getElementById("myeditor").contentWindow.document.body);
				document.getElementById("myeditor").contentWindow.document.body.innerHTML = html.toString();
				document.getElementById("codeview").style.backgroundColor='';
				document.getElementById("textview").style.backgroundColor='#a0a0a0';
				for(var i=1;i<7;++i)
					document.getElementById("editb"+i).disabled=false;
				editormode='';
		}
	}
	else{
		if(sw=='code' && editormode==''){
				var iHTML = document.getElementById("myeditor").contentWindow.document.body.innerHTML;
				document.getElementById("myeditor").contentWindow.document.body.innerText = iHTML;
				document.getElementById("codeview").style.backgroundColor='#a0a0a0';
				document.getElementById("textview").style.backgroundColor='';
				for(var i=1;i<7;++i)
					document.getElementById("editb"+i).disabled=true;
				editormode='code';
		}
		else if(sw=='' && editormode=='code'){
				var iText = document.getElementById("myeditor").contentWindow.document.body.innerText;
				document.getElementById("myeditor").contentWindow.document.body.innerHTML = iText;
				document.getElementById("codeview").style.backgroundColor='';
				document.getElementById("textview").style.backgroundColor='#a0a0a0';
				for(var i=1;i<7;++i)
					document.getElementById("editb"+i).disabled=false;
				editormode='';
		}
	}
}

function uncheck(sel,inp) {
	if (sel.value == "new" ) {	
		inp.disabled = false;	
		
	}else{ 
		inp.disabled = true;
		
	}
	
}

function popup(url,width,height) {
if(((document.all) && (window.offscreenBuffering))){
 if(width>height)
 	fenster=window.open("include/popup.php?pic="+url, "quer", "width="+(width+2)+",height="+(height+2)+",resizable=no,scrollbars=no");
 else
 	fenster=window.open("include/popup.php?pic="+url, "hoch", "width="+(width+2)+",height="+(height+2)+",resizable=no,scrollbars=no");
 fenster.focus();
}else{
 if(width>height)
 	fenster=window.open("include/popup.php?pic="+url, "quer", "width="+(width+2)+",height="+(height+2)+",resizable=no,scrollbars=no");
 else
 	fenster=window.open("include/popup.php?pic="+url, "hoch", "width="+(width+2)+",height="+(height+2)+",resizable=no,scrollbars=no");
 fenster.focus();
}
 return false;
}


////////////////////////////////
//  Editor-Funktionen Anfang  //
////////////////////////////////

function init_content_editor(width, height){

	var editor_width = width;
	var editor_height = height;

	var textArea = document.getElementById('editor_textarea');
	textArea.style.width = editor_width + 'px';
	textArea.style.height = editor_height + 'px';
	
	var iframe = document.createElement('iframe');
	iframe.setAttribute('id', 'content_editor');
	iframe.style.width = editor_width + 'px';
	iframe.style.height = editor_height + 'px';
	
	textArea.style.display = 'none';
	textArea.parentNode.insertBefore(iframe, textArea);
	
	var editor = document.getElementById('content_editor').contentWindow.document;
	var iframeContent;
	iframeContent  = '<html>\n';
	iframeContent += '<head>\n';
	iframeContent += '<link href="css/iframe.css" rel="stylesheet" type="text/css">\n';
	iframeContent += '</head>\n';
	iframeContent += '<body leftmargin="1" topmargin="1" marginwidth="1" marginheight="1">\n';
	iframeContent += textArea.value;
	iframeContent += '</body>\n';
	iframeContent += '</html>';
	
	editor.open();
	editor.write(iframeContent);
	editor.close();	

	function init_designmode(){
		if(navigator.appName == 'Microsoft Internet Explorer'){
			editor.attachEvent('onkeypress', editorEvents);		
			editor.body.contentEditable = true;
		}else{
			editor.designMode = 'on';
		}
		
		textArea.form.onsubmit = function(){
			textArea.value = editor.body.innerHTML;
		}
	}
	
	window.setTimeout(init_designmode, 500);
}

function createLink() {
	var editor = document.getElementById('content_editor').contentWindow.document;
	if(navigator.appName == 'Microsoft Internet Explorer')
		editor.execCommand('CreateLink', true, null);
	else{
		var selectedRange = document.getElementById('content_editor').contentWindow.getSelection();
		if(url = prompt('URL?', 'http://'))
			editor.execCommand('CreateLink', false, url);	
	}
	focus_editor();	
}

function runCommand(theCommand, thebool, theparam) {
	var editor = document.getElementById('content_editor').contentWindow.document;
	editor.execCommand(theCommand, thebool, theparam);
	focus_editor();
}

function focus_editor(){
	if(navigator.appName == 'Opera')
		document.getElementById('content_editor').focus();
	else
		document.getElementById('content_editor').contentWindow.focus();
}

function editorEvents(evt){
	var keyCode = evt.keyCode ? evt.keyCode : evt.charCode;
	
	if (evt.type=='keypress' && keyCode==13){
		var editor = document.getElementById('content_editor');
		var selectedRange = editor.contentWindow.document.selection.createRange();
		var parentElement = selectedRange.parentElement();
		var tagName = parentElement.tagName;
		
		while((/^(a|abbr|acronym|b|bdo|big|cite|code|dfn|em|font|i|kbd|label|q|s|samp|select|small|span|strike|strong|sub|sup|textarea|tt|u|var)$/i.test(tagName)) && (tagName!='HTML')){
			parentElement = parentElement.parentElement;
			tagName = parentElement.tagName;
		}
		
		if (parentElement.tagName == 'P'||parentElement.tagName=='BODY'||parentElement.tagName=='HTML'||parentElement.tagName=='TD'||parentElement.tagName=='THEAD'||parentElement.tagName=='TFOOT'){
			selectedRange.pasteHTML('<br>');
			selectedRange.select();
			return false;
		}
	}
	
	return true;
}

////////////////////////////////
//  Editor-Funktionen Ende    //
////////////////////////////////


