//define the workspace
lgitp = new Object();
lgitp.librariesBasePath = './';
lgitp.librariesBaseLanguage = 'de';
lgitp.idsSeparator = ':';
lgitp.libraryParams = new Array();

//define workspaces
lto = new Object();
ltobm = new Object();


//get the base path looking at the init script (initLGITP)
$scripts = document.getElementsByTagName("script");
if($scripts!=null){
    for(var i=0; i<$scripts.length; i++){
        var currentMatch = new Array();
        if($scripts[i]!=null && $scripts[i].src && (currentMatch = $scripts[i].src.match(/initLGITP\.js(\?.*)?$/))){
            //define the language
            if(
                currentMatch[1]!=null 
                && currentMatch[1].match(/language\=(..)/) != null 
                && currentMatch[1].match(/language\=(..)/)[1] != null
            ){
            
                lgitp.librariesBaseLanguage = currentMatch[1].match(/language\=(..)/)[1];
            }

            lgitp.librariesBasePath = $scripts[i].src.replace(/initLGITP\.js(\?.*)?$/,'');
            break;
        }
    }    
}

//define the availability path
ltobm.calendarAvailabilityUrl = lgitp.librariesBasePath + "../" + "dynpack/common/calendarAvailabilityImproved.faces";
//ltobm.calendarAvailabilityUrl = lgitp.librariesBasePath + "../" + "pages/testAjax.php";



// ----------------------------------------------
// get element by class Id
// ----------------------------------------------
lgitp.getElementByClassId = function(classId){
    var ret;
	var found = document.getElementsByClassName(classId);
	if(found!=null && found.length==1){
	    ret = found[0];     
	} 
    
    return ret; 
}



// ---------------------------------------
// get the id components
// ---------------------------------------
lgitp.getIdConponents = function(id){
	var ret = new Array();
	
	//look for "resultsTable_"
	var pos = id.lastIndexOf(lgitp.idsSeparator);
	if(pos!=-1){
	    //get the parts
	    ret.prefix = id.substring(0, pos+1);
	    ret.id = id.substr(pos+1);
	}
	
	return ret;
}



// ----------------------------------------------
// file handler class
// ----------------------------------------------
var JavaScriptLibraryHandler = Class.create(lgitp.librariesBasePath);
JavaScriptLibraryHandler.prototype = {
	initialize:    function(path) {
	   this.path = path;
	},
	
	include:       function(fileName) {
	
	    // inserting via DOM fails in Safari 2.0, so brute force approach
	    document.write('<script type="text/javascript" src="'+this.path + fileName+'"></script>');
	
	
        /*	
		var script  = document.createElement('script');  
		script.src  = this.path + fileName;  
		//alert(script.src);
		
		script.type = 'text/javascript';  
		script.defer = true;  
		document.getElementsByTagName('head').item(0).appendChild(script);
		
		//get the parameters of the file
		var querystringMatches = fileName.match(/\?(.*)/);
		if(querystringMatches!=null && querystringMatches[1]!=null){
            var pairs = querystringMatches[1].split("&");
            if(pairs!=null){
                for(var i=0; i<pairs.length; i++){
                    var pair = pairs[i].split("="); 
                    //add the variable
                    lgitp.libraryParams[pair[0]] = pair[1];
                }
            }
		}
		*/
	},
	
	nada: ''
};

// ==================================================
// helper functions
// ==================================================

function doPrintPopup(source, params){
    if(params==null){
        params = "height=600,width=800,toolbar=no,menubar,no,scrollbars=yes";
    }

    popup = window.open(source, "popup", params);
    popup.focus();
}


var newWin;
function doOpenPopup(windowName, params) {
  if(params==null){
      params = "height=600,width=800,toolbar=no,menubar,no,scrollbars=yes";
  }
  
  newWin = window.open("", windowName, params);
  newWin.focus();
}


// ==================================================
// MAIN
// - init the Library handler
// ==================================================
lgitp.libraryHandler = new JavaScriptLibraryHandler(lgitp.librariesBasePath);


// --------------------------------------------------
// include common used libraries
// --------------------------------------------------
lgitp.libraryHandler.include('class/common/LanguageChooser.js');
lgitp.libraryHandler.include('class/common/HomeLinkHandler.js');