/**
 * MEAB, Basic site javascript
 * @author(Jonas Reinhardt <jonas@reinhardt.nu>)
 * @created(2001)
 *
 * $Id$
 *
 * 2001-11/jr, created
 * 2008-01-14/jr, updated
 *
 */

/*** COOKIE - FUNKTIONER ***/
// Create a cookie with the specified name and value.
// The cookie expires after 9 weeks
function SetCookie(sName, sValue) {
 var dExpires = new Date();
 var dWeeks = 1000*60*60*24*7*9;
 dExpires.setTime(dExpires.getTime()+dWeeks);
 document.cookie = sName + "=" + escape(sValue) + "; path=/; expires=" + dExpires.toGMTString();
}

// Retrieve the value of the cookie with the specified name.
function GetCookie(sName) {
 // cookies are separated by semicolons
 var aCookie = document.cookie.split("; ");
 for (var i=0; i < aCookie.length; i++) {
  // a name/value pair (a crumb) is separated by an equal sign
  var aCrumb = aCookie[i].split("=");
  if (sName == aCrumb[0]) { return unescape(aCrumb[1]); }
 }
 // a cookie with the requested name does not exist
 return null;
}

// Delete the cookie with the specified name.
function DelCookie(sName) {
 document.cookie = sName + "=" + escape(sValue) + "; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
}


/*** GLOBALA VARS ***/
var loc;

// Sätt locale = language, från 1. Cookie, 2. language, 3. browser language
loc = GetCookie('loc');
if (loc===null) {
 loc = navigator.language;
 if ((loc!="sv") && (loc!="en") && (loc!="de")) { loc = navigator.browserLanguage; }
 if ((loc!="sv") && (loc!="en") && (loc!="de")) { loc = "en"; }
}

/*** HJÄLP - FUNKTIONER ***/


// Kort form för att retunera Element ID
function el(id) { return document.getElementById(id); }
// Kort form för att retunera Element ID.value
function elv(id) { 
  var E=el(id);
  if(E) { return E.value; } else { return ""; }
}

// Visar datum på formen yyyy-mm-dd dag
function ShowDate() {
 var days, d, s;
 if (loc=="sv") { days = ["sö", "må", "ti", "on","to", "fr", "lö"]; }
 else { days = ["Sun", "Mon", "Tue", "Wed","Thu", "Fri", "Sat"]; }
 dd = new Date();
 y = dd.getYear();
 m = dd.getMonth()+1;
 d = dd.getDate();
 s = y+"-";
 if (m<10) { s+="0"+m+"-"; } else { s+=m+"-"; }
 if (d<10) { s+="0"+d+" "; } else { s+=d+" "; }
 s += days[dd.getDay()];
 return(s);
}




/*** HEADER - FADE - FUNKTIONER ***/

// kan byta ut filter mot opacity för bättre funktionalitet med firefox
// http://www.brainerror.net/scripts_js_blendtrans.php 
function opacity(id, opacStart, opacEnd, millisec) {
//speed for each frame
 var speed = Math.round(millisec / 100);
 var timer = 0;
 var i;
//determine the direction for the blending, if start and end are the same nothing happens
 if(opacStart > opacEnd) {
  for(i=opacStart; i>=opacEnd; i--) {
   setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
   timer++;
  }
 } else if(opacStart < opacEnd) {
  for(i=opacStart; i<=opacEnd; i++) {
   setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
   timer++;
  }
 }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
 var object = el(id).style;
 object.opacity = (opacity / 100);
 object.MozOpacity = (opacity / 100);
 object.KhtmlOpacity = (opacity / 100);
 object.filter = "alpha(opacity=" + opacity + ")";
} 

// byter till opacity headereffect för även IE
function HeaderEffect() {
 var O=el("he");  
 if(O) {
  changeOpac(0, "he");
  O.style.visibility="visible";
  opacity("he",0,100,900);
  O.style.visibility="visible";
 }
}

