var logReader = null;  
            
/**
 * Funktion liefert eine GUI Komponente zurück.
 * 
 * @param String component, welche Komponente soll geldane werden.
 * @param int id, die ID einer Abhängigkeit in der DB.
 * @param String eventHandler, javascript funktions aufruf für einen/mehrere Event(s).
 * @param int width die Breite der GUI Komponente.
 * @param String lang_code, der Sprachcode, in welcher Sprache die Komponente geladen werden soll.
 * @param String selected, welcher Eintrag Selektiert sein soll, bei Textfelder der anzuzeigende Text. 
 */
function getAJAXComponent(component, id, width, eventHandler, lang_code, selected, editorId) {
    var invokeService = ajaxPath + 'ajax_gui_components.php?';
    
    if(component == null || component == "") {
    	alert("AJAX Error.");
    }else {
        invokeService += 'component='+ component;
        
        invokeService += '&id='+id;
        invokeService += '&width='+width;
        invokeService += '&eventHandler='+eventHandler;
        invokeService += '&lang_code=' + lang_code;
        invokeService += '&selected=' + selected;
        invokeService += '&editorId=' + editorId;
        
        ajax_loadContent(component, invokeService);
    }
}

/**
 * Funktion ändern den Aktiv Zustand eines Users.
 * @param int userId die Benutzerkennung.
 * @param int der Aktiv-Zustand des Benutzers.
 */
function changeUserState(userId, userMod) {
	var invokeService = ajaxPath  + 'ajax_gui_direct.php?';
	invokeService += 'function=enable_user';
	invokeService += '&id=' + userId;
	invokeService += '&mod_user=' + userMod;
	
	ajax_loadContent('user_state_'+userId, invokeService,'...'); 
}

/**
 * Funktion gibt den UserMapping Editor zurück, nur wenn eingeloggter benutzer
 * überhaupt editieren darf.
 * @param String divId Name des DIVs.
 * @param String lang_code Sprachcode für das Gui-Element.
 * @param int userId die Benutzer des zu editierenden Benutzers.
 * @param int campId die Id des gemappten Campingplatzes.
 * @param int editorId die ID des edittierenden Benutzers.
 */
function getUserMappingGui(divId, lang_code, userId, editorId, width) {
    var invokeService = ajaxPath + 'ajax_gui_components.php?';
    
    if(divId == null || divId== "") {
        alert("AJAX Error.");
    }else {
        invokeService += 'component='+ divId;   
        invokeService += '&lang_code=' + lang_code;
        invokeService += '&userId=' + userId;
        invokeService += '&editorId=' + editorId;
        invokeService += '&width=' + width;
        
        ajax_loadContent(divId, invokeService);
    }
}

/**
 * Funktion läs front end sparch liste. 
 */
function ajaxLoadLanguageList(content, language, userId, list, sort, direction) {
	var invokeService = ajaxPath + "ajax_gui_components.php?";
	if(language == null || language == "")
	   return;
	   
	invokeService += "editorId=" + userId;
    
    invokeService += "&component=" + list;
    invokeService += "&content=" + content;
    invokeService += "&language=" + language;
    invokeService += "&sort=" + sort;
    invokeService += "&direction=" + direction;
    
	ajax_loadContent(list, invokeService);
}

function editLangData(id, langCode, modUser, event, new_value) {
    var invokeService = ajaxPath + "ajax_gui_direct.php?";
    invokeService += "id=" + id;
    invokeService += "&langCode=" + langCode;    
    invokeService += "&mod_user=" + modUser;
    invokeService += "&component=" + 'edit_data_lang'; 
    invokeService += "&event=" + event;
    invokeService += "&new_value=" + new_value;
    
    ajax_loadContent('edit_data_lang', invokeService);	
}

// AJAX ENDE

/**
 * Funktion schaltet zwischen Zeilen Highlight und Zilen normal um.
 * @param Object obj Zeile die gefärbt werden soll.
 * @param String className der CSS Klassenname auf den gefärbt werden soll.
 */
function highlightTableRow(obj, className) {
	obj.className = className;
}

/**
 * Prüft ein Feld auf Gültigkeit. 
 * @return boolean TRUE wenn gültig, anderfalls FALSE.
 * @param String value Zu prüfender Wert.
 * @param String checkFor Auf was das feld geprüft werden soll.
 */
function validate(element, checkFor) {
    var result = false;
    var value = element.value;
    
    if('email' == checkFor) {
    	   splitted = value.split("@");
    	   
    	   if(splitted.length >= 2 && splitted[splitted.length-1] != null) {
    	   	  if(splitted[splitted.length-1].search(/.[.][a-zA-Z]{2,4}/) != -1)
    	   	       result = true;
    	   }
    }else if('url' == checkFor) {
        if(value.length > 0) {
            if(value.search(/[a-z0-9.-]{10,255}/) != -1)
                result = true;
                
            if(result == true) {
            	if(value.indexOf("http://") > 1)
                    result = false;
                else if(value.indexOf("http://") == -1)
                    element.value = "http://" + value;
            }
        }else
           result = true;
    
    }else if('distance' == checkFor) {
          
          if(value != null && value != '') {
              var distance = getFloatFromValue(value);
          
              if(distance != 'NaN' || distance != Number.NaN) {
              	var newValue = formatNumber(distance, ',', '', 1);

              	if(newValue != 'NaN') {
              	     element.value = newValue;
              	     result = true;
              	}
              }
          }else
            result = true;
    }else if('integer' == checkFor) {
          if(parseInt(value) > 0 && parseInt(value) != 'NaN' && parseInt(value) != Number.NaN)
                result = true;
    }else if('currency' == checkFor) {
        
        if(value != null && value != '') {
              var distance = getFloatFromValue(value);
          
              if(distance != 'NaN' || distance != Number.NaN) {
                var newValue = formatNumber(distance, ',', '', 2);

                if(newValue != 'NaN') {
                     element.value = newValue;
                     result = true;
                }
              }
          }else
            result = true;
    }else if('phone' == checkFor) { //nach DIN 5008
            if(value.length <= 15) {
    	       if(value.search(/[+]{0,1}[0-9]{1,}[-\]{0,1}[0-9]{1,}/) != -1) {
    	   	       result = true;  
    	       }
            }
    }else if('textonly' == checkFor) {
    	if(value.search(/[A-Za-zäÄöÖüÜß]{0,}/) != -1)
    	   result = true;
    } else {
    	result = true;
    }
    
    return result;
}

// Loading Information mit Ausblenden der restlichen Seite
function showLoading(loading_bar,loading_text){

	if(loading_bar == 'true'){
			 ausgabe = '<img src="/backoffice/pictures/allgemein/loader_bar.gif" width="220" height="19">';
	}
	ausgabe = ausgabe +'<br><br>' + loading_text;

	document.getElementById('loading_content').innerHTML = ausgabe;
	document.getElementById('loading_content').style.display = 'block';
	document.getElementById('loading').style.display = 'block';	
}
