 // Variablen
activeBrowser = navigator.appName;
readyNext = false;

// --------------------------------------------------------------------------------------
// STRING
// --------------------------------------------------------------------------------------
function check_value(element) {
  element.value = element.value.replace(/(\")/g,"");
  element.value = element.value.replace(/(\&)/g,"");
  element.value = element.value.replace(/(\')/g,"");
  element.value = element.value.replace(/(\*)/g,"");
  element.value = element.value.replace(/(\#)/g,"");
  element.value = element.value.replace(/(\})/g,"");
  element.value = element.value.replace(/(\{)/g,"");
  element.value = element.value.replace(/(\>)/g,"");
  element.value = element.value.replace(/(\<)/g,"");
  element.value = element.value.replace(/(\`)/g,"");
  element.value = element.value.replace(/(\�)/g,"");
  element.value = element.value.replace(/(\|)/g,"");
  element.value = element.value.replace(/(\/)/g,"");
  element.value = element.value.replace(/(\%)/g,"");
}

// --------------------------------------------------------------------------------------
// AJAX FUNCTIONS
// --------------------------------------------------------------------------------------
var req1 = false;

function req1create() {

    req1 = false;

    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        req1 = new XMLHttpRequest();
        if (req1.overrideMimeType) {
            req1.overrideMimeType('text/xml');
            // zu dieser Zeile siehe weiter unten
        }
    } else if (window.ActiveXObject) { // IE
        try {
            req1 = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                req1 = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }

    if (!req1) {
        alert('Ende :( Fehler bei HTTPRequest.');
        return false;
    }
}


// --------------------------------------------------------------------------------------
// Speichern
// --------------------------------------------------------------------------------------
function sendForm(formular, actionfile, nextSite, strPosts) {
  req1create();
  if (strPosts != undefined){
	  strPosts = strPosts +"&control=true";	
  }
  
  else {
    var strPosts = "control=true";
  }
  
	if (formular != false) {
	  var numElements = formular.elements.length;  
		
		for (var i = 0; i < numElements; i++) {

			activeElement = formular.elements[i];
			
			if (activeElement.type != "radio" && activeElement.type != "checkbox" && activeElement.name != undefined && activeElement.type != "submit") {
			  
				// if (activeElement.name == "pseudo")
				  // check_value(activeElement);
				// activeElement.value.replace("dominic","");
				try {
          value = tinyMCE.get(activeElement.id).getContent();
        } catch(err) {
          value = activeElement.value;
        }
        //if(!value) value = activeElement.value;
        strPosts = strPosts + "&" + activeElement.name + "=" + escape(value);
			}  
			else {		  
				
				activeElementName = activeElement.name;
				
				if (activeElement.type == "radio")
				  activeElementName = activeElementName.substring(0,activeElement.name.length-2);
				
				if (activeElement.checked)
			    strPosts = strPosts + "&" + activeElementName + "=" + escape(activeElement.value);
				
			}
			
		} // for:i
	} // if:formular 		
   $.ajax({
      type: "POST",
      url: actionfile,
      data: strPosts,
      success: function(msg){
        if (msg.substring(0,1) == "1") {	
					if (nextSite == "reload") {
						document.location.reload();	      
					}
					else {			  
				    document.location = nextSite;
				  }
				}
				else if (formular != false) {
          unload_tinymce_editors();
				  formular.innerHTML = msg;
          setup_frameworks();
				}	
				else {
				  alert("Error: " + msg);
				}
      }
   });
	return false;
}


// --------------------------------------------------------------------------------------
function doAjax(strPosts,actionfile,targetElement,useControl) {

  //req1create();
  if(useControl == false) {
    var strPosts = "control=false&" + strPosts;
  }
  else {
	  var strPosts = "control=true&" + strPosts;	
	}
   $.ajax({
      type: "POST",
      url: actionfile,
      data: strPosts,
      success: function(msg){
        if (targetElement == "reload")
          document.location.reload();
        else {
          unload_tinymce_editors();
          targetElement.innerHTML = msg;
          setup_frameworks();
        }
      }
   });
	return false;
}


// --------------------------------------------------------------------------------------
function doAction(actionfile, nextSite,strPosts) {
  sendForm(false,actionfile,nextSite,strPosts);	
}


// --------------------------------------------------------------------------------------
function changeElement(element, file) {
  sendForm(false,file,element);	
}

// --------------------------------------------------------------------------------------
function saveImg(element, targetElement) {
	element.form.submit();
  document.getElementById(targetElement).innerHTML = "<img src=\"/images/loader.gif\" align=center style=margin:30px> Bitte warten...";
}