// This javascript loads the main sm04.ch Internet Homepage, 
// should a sub-page be loaded on its own (top frame)
// Written by : C.Dickmann, 19. July 2002
// It was originally a cookie based solution, which was changed to pass a variable.
// To prevent every page on the Internet from needing to be modified, only the functions 
// have been changed, with the same function calls
//***********************************************************************************************
// Global variable, to accomodate the original functions used during the old cookie solution
var locationName = "";
//***********************************************************************************************
// 
function setUrl()
{
	var minNav3 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) >= 3)
	var minIE4 = (navigator.appName.indexOf("Microsoft") >= 0 && parseInt(navigator.appVersion) >= 4)
	var minDOM = minNav3 || minIE4   // baseline DOM required for this function
	var isNav4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) == 4)
    var pageVal = "";                  // URL variable
	var argVal = "";                  // argument variable for sub-pages
	
	if (self == top || window.name != "contentframe") 
	   {
		// Don't do anything if running NN4 
		// so that the frame can be printed on its own
		if (isNav4 && window.innerWidth == 0)
		   {
			  return
		   }

        // Encode content of parameter "subPage" by replacing special characters = and &  
	  	if (location.search) 
		  {
		     var argArray = locationName.split('?');
             pageVal = argArray[0];
			 argVal = argArray[1].replace("=","~");
			 while(argVal.search("=") != -1)
 			    argVal = argVal.replace("=","~");
			 while(argVal.search("&") != -1)
 			    argVal = argVal.replace("&","-");
				
			 pageVal = pageVal + "&subPage=" + argVal;
		  }
		else
		  pageVal = locationName;  
  
	    // If the top or the left frame is loaded on it's own, do this
	    if ( locationName == "" )
           {
	 	      top.location.replace("http://www.lcbasel.ch")
		      return
	       }		
		   
	    if (minDOM) 
	      {
		      // Use replace() to keep current page out of history
		      top.location.replace("http://www.lcbasel.ch/index.html?content=" + pageVal);
		   } 
	   else
	      {
		     top.location.href = "http://www.lcbasel.ch/index.html?content=" +  pageVal;
		   }
	   }
}
//***********************************************************************************************
// loads the global variable with the URL of the sub-page
function writeCookie(locName)
{
  // Do nothing other than loading the global variable, left-over from previous solution with cookies
   locationName = locName;
}
//***********************************************************************************************
// checks if the URL has been set and loads either sub-page or 
// main welcome page into "contentframe"
function getSearchAsArray() {
	var minNav3 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) >= 3)
	var minIE4 = (navigator.appName.indexOf("Microsoft") >= 0 && parseInt(navigator.appVersion) >= 4)
	var minDOM = minNav3 || minIE4   // baseline DOM required for this function
	var results = new Array()
	if (minDOM) 
	  {
		var input = unescape(location.search.substr(1))
		if (input) 
		  {
			var srchArray = input.split("&")
			var tempArray = new Array()
			for (var i = 0; i < srchArray.length; i++) 
			  {
				tempArray = srchArray[i].split("=")
				results[tempArray[0]] = tempArray[1]
			  }
		  }
	  }
  return results
}
//***********************************************************************************************
// Restore the content of the frameset to display the appropriate page. 
// Parameter passe on by calling page
function restore() {

    var pageVal = "";
	var argVal = "";

	if (location.search) {
	  var srchArray = getSearchAsArray();

      // Decode content of parameter "subPage"	by changing back the replaced caracters = and &
	  if (srchArray["subPage"]) {
           argVal = srchArray["subPage"];
		   while(argVal.search("~") != -1)
			  argVal = argVal.replace("~","=");
		   while(argVal.search("-") != -1)
 			  argVal = argVal.replace("-","&");
        } 
   
	  if (srchArray["content"])  {
          pageVal = srchArray["content"];
		  
          // If there is subPage information, add as argument to URL
          if (srchArray["subPage"])
             pageVal = pageVal + "?" + argVal;
  	      top.contentframe.location.replace(pageVal);
        }
	}
 else
   {
      // if there is no information, load the standard homepage page
      top.contentframe.location.replace("_start.html");     	
   }	
}
//***********************************************************************************************
