/*
   	Class: Lxc::Client::JS::Class::Config
   	A class that manages the different Views.
   
   	About: License
   	Link Exchange Script

	Copyright (C) 2007 Erk Nissen - info@link-exchange-script.de
	This program is distributed under the terms and conditions of the GPL

	You can modify the link to 'www.link-exchange-script.de', but you are
	not allowed to remove it, as long as you don't have the direct permission 
	from info@link-exchange-script.de

	DON'T REMOVE THIS NOTICE!!
*/

function classConfig(){
	// Wird auf true gesetzt sobald cfg gelesen
	var ready = false;

	var verbindung = http();
	
	/* 
	   Variable: php_path
	   The relative path to the php directory	
		*/	
	var php_path;
	
	/* 
	   Variable: lxc_rel_path
	   The relative path of lxc
	   
	   ACHTUNG: der Wert von rel_lxc_path wird per PHP in _head.php gesetzt!
	*/	
    var rel_path = rel_lxc_path; // Wird in head gesetzt!
	
	/* 
	   Variable: max_chars_titel
	   The maximum length of a entered Titel	
	*/		
	var max_chars_titel;
	
	/* 
	   Variable: max_chars_desc
	   The maximum length of a entered Description
	*/	
	var max_chars_desc;
	
	/* 
	   Variable: debug
	   Should be true to show additional information and use testig settigs
	*/	
	var debug;
	
	/* 
	   Variable: language
	   The default language of the Application
	*/	
	var language;
	

	// Konstuctor code
	serverRequest_configHolen();
	
	// GETTER Methoden
	this.getPhpPath = function(){		return php_path;	};
	this.getMaxCharsTitel = function(){	return max_chars_titel;	};
	this.getMaxCharsDesc = function(){	return max_chars_desc;	};
	this.getDebug = function(){			return debug;	};
	this.getLanguage = function(){		return language;	};
	this.getRelPath = function(){		return rel_path;	};
	

	function serverRequest_configHolen(){

		// TOD: Problem, hier ist der rel_path noch nicht bekannt
		verbindung.open("POST",rel_path+"config.php",true);
		verbindung.onreadystatechange = serverResponse_configHolen; // Keine () !!!
		verbindung.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		verbindung.send( "method=request" );
	}

	function serverResponse_configHolen(){
		if(verbindung.readyState == 4){
			var rueckgabe = verbindung.responseText;
			//alert(rueckgabe);
			// TODO: handle rueckgabe
			var cfgObjektArray = eval("("+ rueckgabe +")");
			
			for( var index in cfgObjektArray ){
			 	var cfgObjekt = cfgObjektArray[index];
			 	var key = cfgObjekt.k;
			 	var val = cfgObjekt.v;
		
				if( key == 'lxc_php_path' ){
					php_path = val;
				}else if( key == 'lxc_max_chars_titel' ){
					max_chars_titel = val;
				}else if( key == 'lxc_max_chars_desc' ){
					max_chars_desc = val;
				}else if( key == 'lxc_debug' ){
					debug = val;
				}else if( key == 'lxc_language' ){
					language = val;
				}
			}
			lxcConfigGeholt();
		}
	}
	
	function http(){
		var tmphttp;
		if(window.XMLHttpRequest){
			tmphttp = new XMLHttpRequest();
		} else if(window.ActiveXObject) {
			tmphttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		return tmphttp;
	}
	
}
