//Style Sheet Switcher version 1.1 Oct 10th, 2006
//Author: Dynamic Drive: http://www.dynamicdrive.com
//Usage terms: http://www.dynamicdrive.com/notice.htm

var manual_or_random="manual" //"manual" or "random"
var randomsetting="3 days" //"eachtime", "sessiononly", or "x days (replace x with desired integer)". Only applicable if mode is random.

//////No need to edit beyond here//////////////

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function maximizeWin()
{
	window.moveTo(0, 0);
	window.resizeTo(screen.width, screen.height);
}

var siteWin = null;

function launchSiteWin(URL, windowName, windowWidth, windowHeight, scrollbars)
{
	var xposition = 400;
	var yposition = 300;

    if ((parseInt(navigator.appVersion) >= 4 )) {
        xposition = (screen.width - windowWidth) / 2;
        yposition = (screen.height - windowHeight) / 2;
    }

	if (!scrollbars) var scrollbars = 0;

    var args = "width=" + windowWidth + ","
	    	+ "height=" + windowHeight + ","
	    	+ "location=0,"
		    + "menubar=0,"
		    + "scrollbars=" + scrollbars + ","
		    + "status=0,"
		    + "titlebar=0,"
		    + "hotkeys=0,"
		    + "screenx=" + xposition + ","  // NN Only
		    + "screeny=" + yposition + ","  // NN Only
		    + "left=" + xposition + ","     // IE Only
		    + "top=" + yposition;           // IE Only

	if (siteWin != null && !siteWin.closed) {
		siteWin.close();
	}
	siteWin = window.open(URL, windowName, args);

	siteWin.focus();
}

function getCookie(Name) { 
var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
if (document.cookie.match(re)) //if cookie found
return document.cookie.match(re)[0].split("=")[1] //return its value
return null
}

function setCookie(name, value, days) {
var expireDate = new Date()
//set "expstring" to either future or past date, to set or delete cookie, respectively
var expstring=(typeof days!="undefined")? expireDate.setDate(expireDate.getDate()+parseInt(days)) : expireDate.setDate(expireDate.getDate()-5)
document.cookie = name+"="+value+"; expires="+expireDate.toGMTString()+"; path=/";
}

function deleteCookie(name){
setCookie(name, "moot")
}


function setStylesheet(title, randomize){ //Main stylesheet switcher function. Second parameter if defined causes a random alternate stylesheet (including none) to be enabled
var i, cacheobj, altsheets=[""]
for(i=0; (cacheobj=document.getElementsByTagName("link")[i]); i++) {
if(cacheobj.getAttribute("rel").toLowerCase()=="alternate stylesheet" && cacheobj.getAttribute("title")) { //if this is an alternate stylesheet with title
cacheobj.disabled = true
altsheets.push(cacheobj) //store reference to alt stylesheets inside array
if(cacheobj.getAttribute("title") == title) //enable alternate stylesheet with title that matches parameter
cacheobj.disabled = false //enable chosen style sheet
}
}
if (typeof randomize!="undefined"){ //if second paramter is defined, randomly enable an alt style sheet (includes non)
var randomnumber=Math.floor(Math.random()*altsheets.length)
altsheets[randomnumber].disabled=false
}
return (typeof randomize!="undefined" && altsheets[randomnumber]!="")? altsheets[randomnumber].getAttribute("title") : "" //if in "random" mode, return "title" of randomly enabled alt stylesheet
}

function chooseStyle(styletitle, days){ //Interface function to switch style sheets plus save "title" attr of selected stylesheet to cookie
if (document.getElementById){
setStylesheet(styletitle)
setCookie("mysheet", styletitle, days)
}
}

function indicateSelected(element){ //Optional function that shows which style sheet is currently selected within group of radio buttons or select menu
if (selectedtitle!=null && (element.type==undefined || element.type=="select-one")){ //if element is a radio button or select menu
var element=(element.type=="select-one") ? element.options : element
for (var i=0; i<element.length; i++){
if (element[i].value==selectedtitle){ //if match found between form element value and cookie value
if (element[i].tagName=="OPTION") //if this is a select menu
element[i].selected=true
else //else if it's a radio button
element[i].checked=true
break
}
}
}
}

if (manual_or_random=="manual"){ //IF MANUAL MODE
var selectedtitle=getCookie("mysheet")
if (document.getElementById && selectedtitle!=null) //load user chosen style sheet from cookie if there is one stored
setStylesheet(selectedtitle)
}
else if (manual_or_random=="random"){ //IF AUTO RANDOM MODE
if (randomsetting=="eachtime")
setStylesheet("", "random")
else if (randomsetting=="sessiononly"){ //if "sessiononly" setting
if (getCookie("mysheet_s")==null) //if "mysheet_s" session cookie is empty
document.cookie="mysheet_s="+setStylesheet("", "random")+"; path=/" //activate random alt stylesheet while remembering its "title" value
else
setStylesheet(getCookie("mysheet_s")) //just activate random alt stylesheet stored in cookie
}
else if (randomsetting.search(/^[1-9]+ days/i)!=-1){ //if "x days" setting
if (getCookie("mysheet_r")==null || parseInt(getCookie("mysheet_r_days"))!=parseInt(randomsetting)){ //if "mysheet_r" cookie is empty or admin has changed number of days to persist in "x days" variable
setCookie("mysheet_r", setStylesheet("", "random"), parseInt(randomsetting)) //activate random alt stylesheet while remembering its "title" value
setCookie("mysheet_r_days", randomsetting, parseInt(randomsetting)) //Also remember the number of days to persist per the "x days" variable
}
else
setStylesheet(getCookie("mysheet_r")) //just activate random alt stylesheet stored in cookie
} 
}

function recommendsite(mytitle, myurl){
	launchSiteWin("/empfehlen.aspx?tit="+replaceUmlauts(mytitle, 0)+"&url="+myurl, "recWin", 600, 550, 1)
	// launchSiteWin("/comingsoon.html", "recWin", 500, 500, 1)
}

function replaceUmlauts(string, index){
    var anArray = new Array(2);
    anArray[0] = new Array("&", "Ö", "ö", "Ä", "ä", "Ü", "ü", "ß");
    anArray[1] = new Array("@amp;", "@Ouml;", "@ouml;", "@Auml;", "@auml;", "@Uuml;", "@uuml;", "@szlig;");
    
    for (var i=0; i<anArray[index].length; i++){
		myRegExp = new RegExp(anArray[index][i],"g");
		string = string.replace(myRegExp, anArray[(index==0?1:0)][i]);
	}
    return string;
}

/***********************************************
* Bookmark site script- © Dynamic Drive DHTML code library ([url]www.dynamicdrive.com[/url])
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at [url]http://www.dynamicdrive.com/[/url] for full source code
***********************************************/

function bookmarksite(title, url){
if (document.all)
window.external.AddFavorite(url, "La.KUMed: " + title);
else if (window.sidebar)
window.sidebar.addPanel("La.KUMed: " + title, url, "")
}

var PicWin = "undefined";

function ShowPic(Which, Orient) {
  if (PicWin == "undefined" || PicWin.closed == true) {
    if (Orient == 'preview') {
      PicWin = window.open(Which, "Pic_Win", "SCREENX=200,SCREENY=200,TOOLBAR=0,LOCATION=0,DIRECTORIES=0,STATUS=0,MENUBAR=0,SCROLLBARS=1,RESIZABLE=1,WIDTH=650,HEIGHT=650");
    }
    else {
    	if (Orient == 'info') {
      	PicWin = window.open(Which, "Pic_Win", "SCREENX=200,SCREENY=200,TOOLBAR=0,LOCATION=0,DIRECTORIES=0,STATUS=0,MENUBAR=0,SCROLLBARS=1,RESIZABLE=1,WIDTH=595,HEIGHT=550");
      }
      else {
      	PicWin = window.open(Which, "Pic_Win", "SCREENX=200,SCREENY=200,TOOLBAR=0,LOCATION=0,DIRECTORIES=0,STATUS=0,MENUBAR=0,SCROLLBARS=1,RESIZABLE=1,WIDTH=300,HEIGHT=250");
      }
    }
  }
  else {
    if (Orient == 'preview') {
      PicWin.resizeTo(650,650);
      }
    else {
    	if (Orient == 'info') {
      	PicWin.resizeTo(595,550);
    	}
      else {
      	PicWin.resizeTo(300,250);
    	}
    }
    PicWin.location.href=Which
    PicWin.focus();
  }
}


