// Used in PostAjaxData
function getAjaxObject() {
   if (window.XMLHttpRequest) {
      return new XMLHttpRequest()
   } else {
      return new ActiveXObject("Microsoft.XMLHTTP");
   }
}
 
// The Ajax
function postAjaxData (callback, data, url, mode) {
   AJAX = getAjaxObject();
   AJAX.callbackfunc = callback;
   AJAX.onreadystatechange = function () {
      if (AJAX.readyState == 4){
         if (AJAX.status == 200) {
            AJAX.callbackfunc();
         } else {
            alert("Server error " + AJAX.status);
         }
      }
   }
   AJAX.open("POST", url, mode);
   var myType = "application/x-www-form-urlencoded; charset=UTF-8";
   AJAX.setRequestHeader("Content-Type", myType);
   AJAX.send(data);
   return AJAX;
}




// Meat and Potatoes
var AJAX;
function myCallback() {
	CloseEditor();
	document.location.reload(true);
   alert (AJAX.responseText);
}

function EditCallback()
{
	document.getElementById('editordiv').innerHTML = AJAX.responseText;
	//return AJAX.responseText;
	return AJAX;

}

function sendSomething (process, location, data) {
   AJAX = postAjaxData(myCallback, data, "dyn/dynprocess.php?location="+location+"&process="+process+"&data=", true);
}


function GetEditor(location) {
	//document.write("Dyn Java Function is "+location+" ...");
	AJAX = postAjaxData(EditCallback,0,'dyn/editor.php?location='+location, true);
	return AJAX.responseText;
}

function LoadEditor(location)
{
	
	// Create Pagewide Div overlay
	var tdiv = document.createElement('div');
	tdiv.setAttribute('id', 'trandiv');
	tdiv.style.width='100%';
	tdiv.style.height='100%';
	tdiv.style.opacity='0.4';
	tdiv.style.filter='alpha(opacity=40)';
	tdiv.style.position = "fixed";
	tdiv.style.top = '0';
	tdiv.style.left = '0';
	tdiv.style.background = "#333";
	document.body.appendChild(tdiv);
	
	var newdiv = document.createElement('div');
   	newdiv.setAttribute('id', 'editordiv');
  	newdiv.style.width = '100%';
	newdiv.style.height = '100%';
	newdiv.style.position = "fixed";
	newdiv.style.top = '0';
	newdiv.style.left = '0';
    newdiv.style.background = "";
	
	document.body.appendChild(newdiv);

	// Load editor into Div
	GetEditor(location);
	// Load Correct Data from location
}

function CloseEditor()
{
	tinyMCE.execCommand("mceRemoveControl", false, 'dyndata');

	tdiv = document.getElementById('trandiv');
	ediv = document.getElementById('editordiv');
	document.body.removeChild(tdiv);
	document.body.removeChild(ediv);
}

function ResetTiny()
{
	// used to be here
	tinyMCE.init({
        mode : "exact",
		elements : "dyndata",

        theme : "advanced",
        plugins : "emotions,spellchecker,advhr,insertdatetime,preview,advimage,ibrowser",
                
        // Theme options - button# indicated the row# only
        theme_advanced_buttons1 : "bold,italic,underline,|,justifyleft,justifycenter,justifyright,fontselect,fontsizeselect,formatselect",
        theme_advanced_buttons2 : "bullist,numlist,|,undo,redo,|,link,unlink,image,|,forecolor,backcolor,|,spellchecker,advhr,removeformat,|,charmap,emotions",
        theme_advanced_buttons3 : "ibrowser",      
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "bottom",
        theme_advanced_resizing : true
		});	
}
	
	// used to be here
	tinyMCE.init({
        mode : "exact",
		elements : "dyndata",

        theme : "advanced",
        plugins : "emotions,spellchecker,advhr,insertdatetime,preview,advimage,table",
                
        // Theme options - button# indicated the row# only
        theme_advanced_buttons1 : "bold,italic,underline,|,justifyleft,justifycenter,justifyright,fontselect,fontsizeselect,formatselect",
        theme_advanced_buttons2 : "bullist,numlist,|,undo,redo,|,link,unlink,image,|,forecolor,backcolor,|,spellchecker,advhr,removeformat,|,charmap,emotions",
        theme_advanced_buttons3 : "tablecontrols",      
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "bottom",
        theme_advanced_resizing : true
		});
