// *******************************************************************************
// Filename     : ricLib.js

// Created      : 16.05.2007 15:49
// Created by   : Clemens Riccabona, Riccabona eSolutions, <clemens@riccabona.biz>

// Last Updated : 09.07.2009 12:00:00
// Updated by   : Clemens Riccabona, Riccabona eSolutions, <clemens@riccabona.biz>

// Version      : 4.2.6.0

// Comment      : Some basic settings, including all the CSS loading stuff and some other functions
// *******************************************************************************

// Variables for slimbox (probably obsolet)

var ricLoad = (window.ie ? 'load' : 'domready');
var curTime=new Date();

var pmkslimbox_page='<span style=\'font-size:0.8em;\'>&copy; 2007 by MountainStar</span><br />Bild<strong>';
var pmkslimbox_of='</strong>von<strong>';

// Inclusion of X-Browser CSS Files
// now also for multi domain/layout installations. Just declare var newCSSPath in header
// for second web. And make the cssfiles in this new folder.
if (typeof(newCSSPath) != 'undefined') {
  var cL_IE8CssFileName=newCSSPath+'/css/ie8.css';
  var cL_IE7CssFileName=newCSSPath+'/css/ie7.css';
  var cL_CssFileName='';
  var cL_OperaCssFileName=newCSSPath+'/css/op.css';
  var cL_IECssFileName=newCSSPath+'/css/ie4-6.css';
  var cL_IEMacCssFileName=newCSSPath+'/css/ie4-6.css';
  var cL_GeckoCssFileName=newCSSPath+'/css/ge.css';
  var cL_GeckoMacCssFileName=newCSSPath+'/css/ge.css';
  var cL_SafariCssFileName=newCSSPath+'/css/ge.css';
  var cL_OtherCssFileName=newCSSPath+'/css/ge.css';
} else {
  var cL_IE8CssFileName='/fileadmin/dev/css/ie8.css';
  var cL_IE7CssFileName='/fileadmin/dev/css/ie7.css';
  var cL_CssFileName='';
  var cL_OperaCssFileName='/fileadmin/dev/css/op.css';
  var cL_IECssFileName='/fileadmin/dev/css/ie4-6.css';
  var cL_IEMacCssFileName='/fileadmin/dev/css/ie4-6.css';
  var cL_GeckoCssFileName='/fileadmin/dev/css/ge.css';
  var cL_GeckoMacCssFileName='/fileadmin/dev/css/ge.css';
  var cL_SafariCssFileName='/fileadmin/dev/css/ge.css';
  var cL_OtherCssFileName='/fileadmin/dev/css/ge.css';
}

// var def in browserVars; add new ones in there; init setting: false
var browserVars='isIE5up,isIE55up,isIE6,isIE6up,isIE7,isIE7up,isIE8,isIE8up,isOpr,isOpr7up,isGecko,isSafari,isKhtml,isLinux,isMac'.split(',');for(var i=0;i<browserVars.length;i++){eval('var '+browserVars[i]+'=false;');}
var isDOM=document.getElementById ? true:false;
var isNN4=document.layers ? true:false;
var isIE4=document.all ? true:false;
var OprVersion=''; var GeckoVersion='';
if (isDOM&&isIE4){isIE5up=true; isIE4=false; isDOM=false;} else {isIE5up=false;}
if ((isIE5up)&&(navigator.appVersion.indexOf('MSIE 5.0')==-1)){isIE55up=true;}
if ((isIE55up)&&(navigator.appVersion.indexOf('MSIE 5.5')==-1)){isIE6up=true;}
if ((isIE6up)&&(navigator.appVersion.indexOf('MSIE 6')==-1)){isIE7up=true;}
if ((isIE7up)&&(navigator.appVersion.indexOf('MSIE 7')==-1)){isIE8up=true;}
if (isIE6up&&!isIE7up){isIE6=true;}
if ((isIE7up&&!isIE8up)){isIE7=true;}
if (isIE8up){isIE8=true;}
if (navigator.userAgent.indexOf('Opera')!=-1){isOpr=true;isDOM=false;isNN4=false;isIE4=false;isIE5up=false;isIE55up=false;isIE6=false;isIE6up=false;isIE7=false;isIE7up=false;}
if (navigator.userAgent.indexOf('Linux')!=-1) {isLinux=true;}
if (isOpr&&navigator.userAgent.indexOf('Opera 2')==-1&&navigator.userAgent.indexOf('Opera 3')==-1&&navigator.userAgent.indexOf('Opera 4')==-1&&navigator.userAgent.indexOf('Opera 5')==-1&&navigator.userAgent.indexOf('Opera 6')==-1){isOpr7up=true;}
if(isOpr&&(navigator.userAgent.indexOf('Opera/0')!=-1||navigator.userAgent.indexOf('Opera/1')!=-1||navigator.userAgent.indexOf('Opera/2')!=-1||navigator.userAgent.indexOf('Opera/3')!=-1||navigator.userAgent.indexOf('Opera/4')!=-1||navigator.userAgent.indexOf('Opera/5')!=-1||navigator.userAgent.indexOf('Opera/6')!=-1)){isOpr7up=false;}
if (navigator.userAgent.indexOf('Mac')!=-1){isMac=true;}
if (navigator.userAgent.indexOf('Gecko')!=-1){isGecko=true;isNN4=false;isIE4=false;isIE5up=false;isIE55up=false;isIE6=false;isIE6up=false;isIE7=false;isIE7up=false;}
if(navigator.userAgent.indexOf('Safari')!=-1){isSafari=true;isGecko=false;isNN4=false;isIE4=false;isIE5up=false;isIE55up=false;isIE6=false;isIE6up=false;isIE7=false;isIE7up=false;}
if(navigator.userAgent.indexOf('KHTML')!=-1||navigator.userAgent.indexOf('khtml')!=-1){isKhtml=true;isGecko=false;isNN4=false;isIE4=false;isIE5up=false;isIE55up=false;isIE6=false;isIE6up=false;isIE7=false;isIE7up=false;}
if (isGecko){GeckoVersion=navigator.userAgent.substring(navigator.userAgent.indexOf('rv:')+3,navigator.userAgent.indexOf('rv:')+6);}
if (isOpr){OprVersion=navigator.userAgent.substring(navigator.userAgent.indexOf('Opera')+6,navigator.userAgent.indexOf('Opera')+10);}
if(isIE5up&&!isIE55up){var undefined='undefined';} // define undefined on IE5.0

// output the inclusion link for the correct css file
var cssIncCode="<link rel=\"stylesheet\" type=\"text/css\" href=\"";
/*document.write(cssIncCode+cL_CssFileName+"\">");*/
if(!isMac) {
  if (isIE4||isIE5up) {
    if(!isIE7&&!isIE7up&&!isIE8&&!isIE8up){document.write(cssIncCode+cL_IECssFileName+"\">");}
    try{if(isIE7){document.write(cssIncCode+cL_IE7CssFileName+"\">");}}catch(error) {
      document.write(cssIncCode+cL_IECssFileName+"\">");
    }
    try{if(isIE8||isIE8up){document.write(cssIncCode+cL_IE8CssFileName+"\">");}}catch(error) {
      document.write(cssIncCode+cL_IECssFileName+"\">");
    }
  }
  else if (isGecko) {document.write(cssIncCode+cL_GeckoCssFileName+"\">");}
  else if (isOpr) {document.write(cssIncCode+cL_OperaCssFileName+"\">");}
  else {document.write(cssIncCode+cL_OtherCssFileName+"\">");}
} else if (isMac) {
  if (isGecko) {document.write(cssIncCode+cL_GeckoMacCssFileName+"\">");}
  else if (isOpr) {document.write(cssIncCode+cL_OperaCssFileName+"\">");}
  else if (isSafari) {document.write(cssIncCode+cL_SafariCssFileName+"\">");}
  else if (isIEMac) {document.write(cssIncCode+cL_IEMacCssFileName+"\">");}
  else {document.write(cssIncCode+cL_OtherCssFileName+"\">");}
}

if (isIE5up) { try { document.execCommand("BackgroundImageCache", false, true); } catch(error) { } }

//ric onload all
function ric_onload_all(funcCall){
if(window.ric_onloadHasDelayed==undefined||!window.ric_onloadHasDelayed){window.ric_onloadHasDelayed=0;}
if(document.body) { if(document.body.innerHTML) { var ihLength=Number(document.body.innerHTML.length);
   if(window.ihOldLength){var ihOldLength=Number(window.ihOldLength);}else{var ihOldLength=0;}
   if(ihLength>ihOldLength) { window.ihOldLength=ihLength; window.setTimeout("ric_onload_all('"+funcCall+"');",25);
    }else{ if(window.ric_onloadHasDelayed==0) { window.ric_onloadHasDelayed=1;
      window.setTimeout("ric_onload_all('"+funcCall+"');",1000);
      }else{ eval(funcCall); }
    }
   }else{ window.setTimeout("ric_onload_all('"+funcCall+"');",25); }
  }else{ window.setTimeout("ric_onload_all('"+funcCall+"');",25); }
}

// Function for superchallenging passwords (kb_feusersmd5)
function superchallenge_pass(form) {
  var pass = form.pass.value;
  if (pass) {
    var enc_pass = MD5(pass);
    var str = form.user.value+":"+enc_pass+":"+form.challenge.value;
    form.pass.value = MD5(str);
    return true;
  } else { return false; }
}

// TYPO3 hack for rggoogle - probably obsolete now
function openPic(url,winName,winParams) {
  var theWindow = window.open(url,winName,winParams);
  if (theWindow) {theWindow.focus();}
}

// Better changeBgColor function for layermenus
function changeBGcolor(id,color) {
  if (document.getElementsByName(id).length > "0") {
    var hypernavelems = document.getElementsByName(id);
    for(var i=0;i<hypernavelems.length;i++) {
      var testUrl = "fileadmin";
      if ( testUrl == color.substring(0,9) ) {
        hypernavelems[i].style.backgroundImage = "url(" + color + ")";
      } else {
        hypernavelems[i].style.background = color;
      }
    }
    return true;
  } else if (id && id != '' && document.getElementById && document.getElementById(id)) {
    var testUrl = "fileadmin";
    if ( testUrl == color.substring(0,9) ) {
      document.getElementById(id).style.backgroundImage = "url(" + color + ")";
    } else {
      document.getElementById(id).style.background = color;
    }
    return true;
  } else if (document.layers && document.layers[id]) {
    document.layers[id].bgColor = color;
    return true;
  }
}

// Correct IE Flash Bug
// not really necessary and sometimes gets mixed up with ufo and similar
function rewriteFlash() {
//  if(document.body&&document.body.innerHTML) {
//    var allEmb=document.getElementsByTagName('embed'); var nf=''; var html=''; eHtml='';
//    for(var i=0;i<allEmb.length;i++) {
//      window.ac_status++;
//      html='<iframe allowtransparency=true style="background-color:transparent;height:'+allEmb[i].offsetHeight+'px;width:'+allEmb[i].offsetWidth+'px;margin:0;padding:0;border:0;" id=ffr frameborder=0 framespacing=0 scrolling=no hspace=0 vspace=0 src=""></iframe>';
//      eHtml=allEmb[i].outerHTML; allEmb[i].outerHTML=html;
//      document.getElementById('ffr').contentWindow.document.write('<body style="background-color:transparent;border:0;margin:0;padding:0;">'+eHtml+'</body></html>');
//      document.getElementById('ffr').id=null;
//      }
//    } else {
//     window.setTimeout("rewriteFlash();",500);
//    }
}
// IE Alphachannel Bug
window.pn_status=0;
function clib_rpng(){
  if(isIE55up&&!isIE7up){
    if(document.body){
      if(document.body.innerHTML){
        var imgColl=document.getElementsByTagName('img');
        var thisImg='';var thisSrc='';var thisW=0; var thisH=0;
        for (var i=0;i<imgColl.length;i++){
          if(imgColl[i].src.toLowerCase().indexOf('.png')!=-1){
            thisSrc=imgColl[i].src;
            thisW=imgColl[i].offsetWidth;
            thisH=imgColl[i].offsetHeight;
            thisImg=imgColl[i];
            thisImg.src='/s.gif';
            thisImg.width=thisW; thisImg.height=thisH;
            thisImg.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+thisSrc+"',sizingMethod='scale')";
            window.pn_status++;
          }
        }window.pn_isActive=false;
      }else{window.setTimeout("clib_rpng();",1000);}
    }else {window.setTimeout("clib_rpng();",1000);}
  }
}

// CookieHelpers
function getCookie(check_name) {
  var a_all_cookies = document.cookie.split( ';' );
  var a_temp_cookie = '';
  var cookie_name = '';
  var cookie_value = '';
  var b_cookie_found = false;
  for(i=0;i<a_all_cookies.length;i++) {
    a_temp_cookie = a_all_cookies[i].split( '=' );
    cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
    if(cookie_name==check_name) {
      b_cookie_found=true;
      if(a_temp_cookie.length > 1) {
        cookie_value = unescape(a_temp_cookie[1].replace(/^\s+|\s+$/g, ''));
      }
      return cookie_value;
      break;
    }
    a_temp_cookie = null;
    cookie_name = '';
  }
  if(!b_cookie_found) { return ""; }
}
function setCookie(name, value, expires, path, domain, secure) {
  var today = new Date();
  today.setTime(today.getTime());
  if(expires) { expires = expires * 1000 * 60 * 60 * 24; }
  var expires_date = new Date(today.getTime() + (expires));
  document.cookie = name + "=" +escape(value) +
    ((expires) ? ";expires=" + expires_date.toGMTString() : "") + ((path) ? ";path=" + path : "") + ((domain) ? ";domain=" + domain : "") + ((secure) ? ";secure" : "");
}
function delCookie(name, path, domain) {
  if(getCookie(name)) {
    document.cookie = name + "=" + ((path) ? ";path=" + path : "") + ((domain) ? ";domain=" + domain : "" ) + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
  }
}
// strips given char from given string
function stripChar(words,character) {
  var spaces = words.length;
	for(var x = 1; x<spaces; ++x) {
    words = words.replace(character, "");
  }
  return words;
}
// set user defined stylesheet
function ricSetStyleSheet (ricStylePath) {
  if (ricStylePath == "") {
    ricStylePath = 'fileadmin/dev/css/default-user.css';
  }
  document.getElementById('ricfontsize').href = ricStylePath;
  setCookie('ricActStyle',ricStylePath,'','/',window.location.host);
}
