/******************************************************************************* 
 * @(#)js/systemDetection.js
 *  Rev:         C
 *  Created:     Fri. November 18, 2005, 12:00:00
 *  Author:      media-roayal
 *  mailto:      support@media-royal.com
 *
 *  Copyright by "media-royal.com"
 *
 *  The copyright to the computer program(s) herein
 *  is the property of "media-royal.com", Germany.
 *  The program(s) may be used and/or copied only with
 *  the written permissions of "media-royal.com"
 *  or in accordance with the terms and conditions
 *  stipulated  in the agreement/contract under which
 *  the  program(s) have been supplied.
 *
 * CopyrightVersion 1.0
 *
 ********************************************************************************
 *
 * @author  Daniel Beckert
 * @version 1.0, Fri, 2005-11-18
 * @since   
 *
 *******************************************************************************/
 
 var debugMode = new Boolean();
 debugMode = false;
 var debugMsgID = new Number(0);
 var debugCue = new Array();
 var debugMsg = new String("");
 debugMsg += "::::: Tracer ::::::::::::::::::::::::::::::::::::::::::::::::\n";
 debugMsg += "\n";
 debugMsg += "\n";
 
 var browserName = new String();
 var browserVersion = new Array();
 var browserPlugins = new Array()
 var screenWidth = new Number();
 var screenHeight = new Number();

 var runtimeMode = new String();
 var documentPathDepth = new Number(-1);
 var topPath = new String();



//----------------------------------------------------------------------------------------------------



/*
 * Do the functions to set the system variables
 *
 */
 getTopPath();
 

//----------------------------------------------------------------------------------------------------



/**
 * This function sets the browsername to work with 
 * the right browsersetting in other scripts
 *
 */
 function setBrowserName(){
	/**
	 * If the browser is an netscape compatible browser
	 * uses the "vendor" param to get the browsername
	 * That is usefull to know if the browser is "Netscape Navigator", "Firefox" or "Mozilla"
	 *
	 */
	 if(navigator.vendor != null || navigator.vendor != undefined){
		 browserName = navigator.vendor.toLowerCase();
	 }//--> end if
	 else{
	 	 switch(navigator.appName){
	 	 	 case "Microsoft Internet Explorer":
		 	 	 browserName = "msie";
		 	 	 break;
		 	 case "Safarie":
		 	 	 browserName = "safarie";
		 	 	 break;
		 	 default:
		 	 	 browserName = navigator.appName.toString();
		 	 	 break; 
	 	 }//--> end switch
	 }//--> end else
	 trace(this, "   function \"getBrowserName()\" called:\n value=\""+browserName)+"\"";
	 return browserName;
 }//--> end setBrowserName()
 
 
/**
 * This function returns the browsername 
 *
 * @return browserName:String;
 *
 */
 function getBrowserName(){
	 trace(this, "   function \"getBrowserName()\" called ");
	 return (browserName == null || browserName.length == 0) ? setBrowserName() : browserName;
 }//--> end getBrowserName()
 
 
 
//----------------------------------------------------------------------------------------------------



/**
 * This function sets the browserversion to work with 
 * the right browsersetting in other scripts
 *
 */
 function setBrowserVersion(){
	 browserVersion[0] = navigator.appVersion.substring(0,1);
	 browserVersion[1] = navigator.appVersion.substring(2,3);
	 trace(this, "   function \"setBrowserVersion()\" called:\n value=\""+browserVersion.toString()+"\"");
	 return browserVersion;
 }//--> end setBrowserVersion()
 
 
 
/**
 * This function returns the browserversion 
 *
 * @return browserVersion:Array;
 *
 */ 
 function getBrowserVersion(){
	 trace(this, "   function \"getBrowserVersion()\" called ");
	 return (browserVersion == null || browserVersion.length == 0) ? setBrowserVersion() : browserVersion;
 }//--> end getBrowserName() 
 
 
 
//----------------------------------------------------------------------------------------------------



/**
 * This function sets the runtimeMode to work with 
 * the right setting
 *
 */
 function setRuntimeMode(){
	 switch(document.URL.substring(0,5)){
		 case "file:":
		 	 runtimeMode = "system";
			 break;
		 case "http:":
		 	runtimeMode = (document.URL.substring(0,16) == "http://localhost") ? "localhost" : "web";
			break;
		 default:
		 	 runtimeMode = (document.URL.substring(0,16) == "http://localhost") ? "localhost" : "web";
			 break;
	 }//--> end switcht();
	 trace(this, "   function \"setRuntimeMode()\" called:\n value=\""+runtimeMode+"\n");
	 return runtimeMode;
 }//--> end setRuntimeMode;
 
 
 
/**
 * This function returns the runtimeMode 
 *
 * @return runtimeMode:String;
 *
 */ 
 function getRuntimeMode(){
	 trace(this, "   function \"getRuntimeMode()\" called ");
	 return (runtimeMode == null || runtimeMode.length == 0) ? setRuntimeMode() : runtimeMode;
 }//--> end setRuntimeMode; 



//----------------------------------------------------------------------------------------------------



/**
 * This function sets the document depth relative to the root;
 * the right browsersetting in other scripts
 *
 */
 function setDocumentPathDepth(pathDepth){
    if(pathDepth){
    }//--> end if
    else{
	  
       var documentRoot = new String();
       var tempArray = new Array();
	  
       switch(getRuntimeMode()){
          case "system":
			 documentRoot = document.URL.substring(document.URL.indexOf("miditonal2_1"), document.URL.length);
			 tempArray = documentRoot.split("/");
			 documentPathDepth = (tempArray.length != 0) ? tempArray.length-3 : tempArray.length;
			 delete tempArray;
		 	 break;
          case "localhost":
			 documentRoot = document.URL.substring(document.URL.indexOf("miditonal2_1"), document.URL.length);
			 tempArray = documentRoot.split("/");
			 documentPathDepth = (tempArray.length != 0) ? tempArray.length-2 : tempArray.length;
			 delete tempArray;
		 	 break;
          case "web":
			 documentRoot = document.URL.substring(document.URL.indexOf("miditonal"), document.URL.length);
			 tempArray = documentRoot.split("/");
			 documentPathDepth = (tempArray.length != 0) ? tempArray.length-2 : tempArray.length;
			 delete tempArray;
		 	 break;
          default:
			 documentRoot = document.URL.substring(document.URL.indexOf("miditonal"), document.URL.length);
			 tempArray = documentRoot.split("/");
			 documentPathDepth = (tempArray.length != 0) ? tempArray.length-2 : tempArray.length;
			 delete tempArray;
		 	 break;	 
       }//--> end switch
	 delete documentRoot;
	 delete tempArray;
       }//--> end else
	 trace(this, "   function \"setDocumentPathDepth()\" called:\n value=\""+documentPathDepth+"\"");
	 return documentPathDepth;
 }//--> end setDocumentDepth()
 
 
 
/**
 * This function returns the documentPathDepth 
 *
 * @return documentPathDepth:Number;
 *
 */ 
 function getDocumentPathDepth(){
	 trace(this, "   function \"getDocumentPathDepth()\" called");
	 return (documentPathDepth == null || documentPathDepth < 0) ? setDocumentPathDepth() : documentPathDepth;
 }//--> end getDocumentPathDepth; 
 
 
 
//----------------------------------------------------------------------------------------------------



/**
 * This function sets the topPath dynamicly
 *
 */ 
 function setTopPath(){
	 topPath += "./";
	 for (var i = 0; i<getDocumentPathDepth(); i++){
		 topPath += "../";
	 }//--> end for
	 trace(this, "   function \"setTopPath()\" called:\n value=\""+ topPath+"\"");
	 return topPath;
 }//--> end setTopPath
 
 
 
/**
 * This function returns the topPath
 *
 * @return topPath:String;
 *
 */ 
 function getTopPath(){
	 trace(this, "   function \"getTopPath()\" called");
	 return (topPath == null || topPath.length == 0) ? setTopPath() : topPath;
	 
 }//--> end setRuntimeMode; 
 

//----------------------------------------------------------------------------------------------------

/**
 *
 *
 *
 */
 function trace(caller, msg){
	 if(debugMode){
		 var cueMsg = new String();
		 cueMsg += "-------------------------------------------------------------\n";
		 cueMsg += "   Message-ID:\n"+(debugMsgID+1)+"\n\n";
		 cueMsg += "   Window:\n"+document.URL+"\n\n";
		 cueMsg += "   Caller:\n"+caller+"\n\n";
		 cueMsg += "-------------------------------------------------------------\n\n";
		 cueMsg += "   Message\n"+msg+"\n\n";
		 cueMsg += "-------------------------------------------------------------\n\n\n";
		 debugCue[debugMsgID] = cueMsg;
		 alert(debugCue[debugMsgID]);
		 debugMsgID ++;		 
	 }//--> end if
	 
 }//--> end trace();
 


/********************************************************************************
 * EOF
 *******************************************************************************/
