function createObject() {
  brws = navigator.appName;
  if(brws == "Microsoft Internet Explorer")
    rq = new ActiveXObject("Microsoft.XMLHTTP");
  else
    rq = new XMLHttpRequest();
  return rq;
}

function closeEdit() { 
  document.getElementById('transparent').style.display='none';
  document.getElementById('editorLayer').style.display='none';
}

function edit(id) {
	var objAjax = createObject();
	var sParameter = 'str_aktion=ausgabe&num_nlfdtext='+id;
	

	
	objAjax.open('POST', 'http://www.inforauschen.de/text.php', true);
	objAjax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	objAjax.setRequestHeader("Content-length", sParameter.length);
  objAjax.onreadystatechange = function() {
		if (objAjax.readyState == 4) {
			
      var objEditorLayer = document.getElementById('editorLayer');
			//document.getElementById('editorLayer').style.top = document.getElementById('editLayer_'+id).offsetTop+'px';
			//document.getElementById('editorLayer').style.left = document.getElementById('editLayer_'+id).offsetLeft+'px';						
			
			var nHeightWindow;
			var nWidthWindow;
			var nWidthtScroll;
			var nHeightScroll;
		  // Wenn gescrollt wurde, sonst ist es ziemlich Bugy
		  nWidthtScroll = ( typeof window.pageXOffset == 'undefined' )
		  ? document.body.scrollLeft
		  : window.pageXOffset;
		
		  nHeightScroll  = ( typeof window.pageYOffset == 'undefined' )
		  ? document.body.scrollTop
		  : window.pageYOffset;
		
		  if (window.innerHeight) {
		    nHeightWindow = window.innerHeight;
		    nWidthWindow  = window.innerWidth;
		  }
		  else if (document.body && document.body.offsetHeight) {
		    nHeightWindow = document.body.offsetHeight;
		    nWidthWindow  = document.body.offsetWidth;
		  }
		  
		  objEditorLayer.style.display='block';
		  objEditorLayer.style.left = ((nWidthWindow/2)-(objEditorLayer.offsetWidth/2)+nWidthtScroll)+'px';	
		  objEditorLayer.style.top =  ((nHeightWindow/2)-(objEditorLayer.offsetHeight/2)+nHeightScroll)+'px';		
			
			document.getElementById('transparent').style.display='block';
			document.getElementById('transparent').style.height=document.getElementsByTagName('body')[0].offsetHeight+'px';	
			document.getElementById('transparent').style.width=document.getElementsByTagName('body')[0].offsetWidth+'px';	
			
			document.getElementById('editor').value=objAjax.responseText;
			document.getElementById('num_nlfdtext').value=id;			
			
		}
  }
  objAjax.send(sParameter);	
}

function save() {
		
	var objAjax = createObject();

	var id = document.getElementById('num_nlfdtext').value;
	var sParameter = 'str_aktion=speichern&num_nlfdtext='+id+'&str_stext='+encodeURIComponent(document.getElementById('editor').value);
	
  
	closeEdit();
	
	
	
	objAjax.open('POST', 'http://www.inforauschen.de/text.php', true);
	objAjax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	objAjax.setRequestHeader("Content-length", sParameter.length);
  objAjax.onreadystatechange = function() {
		if (objAjax.readyState == 4) {
			if (objAjax.responseText==1) {
				document.getElementById('edit_'+id).innerHTML = document.getElementById('editor').value;
			}
			else {
				//alert('Speichern nicht erfolgreich');
			}
		}
  }
  objAjax.send(sParameter);		

  /*
	var url = '/proxy?url=' + encodeURIComponent('http://www.google.com/search?q=Prototype');
	// notice the use of a proxy to circumvent the Same Origin Policy.

	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
	    var notice = $('notice');
	    if (transport.responseText.match(/href="http:\/\/prototypejs.org/))
	      notice.update('Yeah! You are in the Top 10!').setStyle({ background: '#dfd' });
	    else
	      notice.update('Damn! You are beyond #10...').setStyle({ background: '#fdd' });
	  }
	});  
  */
}