/*************************************
*    Script : easyCMS_POP v2.0       *
*    Author : Kim Steinhaug          *
*    Url    : www.steinhaug.com      *
*                                    *
*  --   --  --  --  --  --  --  --   *
* Usage :                            *
* swPOP('link','x','y','scrollbar'); *
*                                    *
* link 	    = Dokument url           *
* x    	    = Popup window X value   *
* y    	    = Popup window Y value   *
* scrollbar = 0, no                  *
*             1, yes                 *
**************************************/
  function easyCMS_POP(url,Xvalue,Yvalue,scroll) {
	var w = 480, h = 340;if (document.all || document.layers) { w = screen.availWidth;h = screen.availHeight; };
	var popW = Xvalue, popH = Yvalue;var leftPos = (w-popW)/2, topPos = (h-popH)/2;
	if (scroll) { i = open(url, "displayWindow","top="+topPos+",left="+leftPos+",width="+Xvalue+",height="+Yvalue+",status=no,toolbar=1,menubar=no,resize=no,dependent=yes,scrollbars=yes");} else { i = open(url, "displayWindow","top="+topPos+",left="+leftPos+",width="+Xvalue+",height="+Yvalue+",status=1,toolbar=1,menubar=0,resize=no,dependent=yes,scrollbars=no");};
  };
  function easyCMS_zoom(header,alt,url,Xvalue,Yvalue,scroll) {
	Xvalue = Number(Xvalue) + 20;
	Yvalue = Number(Yvalue) + 60;
	if (scroll) {
        i = open("", "EUindow","top=50,left=50,width="+Xvalue+",height="+Yvalue+",status=no,toolbar=no,menubar=no,resize=no,dependent=yes,scrollbars=yes");
	} else {
        i = open("", "EUindow","top=50,left=50,width="+Xvalue+",height="+Yvalue+",status=no,toolbar=no,menubar=no,resize=no,dependent=yes,scrollbars=no");
	};
    i.focus();
        i.document.open();
        i.document.write('<html>\n')
        i.document.write('<head>\n')
        i.document.write('<title>Easy CMS - ' + alt + '</title>\n')
        i.document.write('<style><!--\n')
        i.document.write('body { \n')
        i.document.write('margin : 0px 0px 0px 0px;\n')
        i.document.write('}\n')
        i.document.write('--></style>\n')
        i.document.write('<\head>\n')
        i.document.write('<body bgcolor="#ffffff" text="#000000">\n')
        i.document.write('<center>\n')
        i.document.write('<div style="font-size:14px; font-weight:bold; font-family:verdana,arial,sans-serif,helvetica;">',header,'</div><a href="javascript:window.close();"><img src="',url,'" border="2" style="border:2px solid white;" alt=""></a>\n')
        i.document.write('<div style="font-size:10px;font-family:verdana;color:#006;">' + alt + '</div>\n')
        i.document.write('<div style="font-size:10px;font-family:verdana;color:#999;">&copy; Easy CMS 2005</div></center>\n')
        i.document.write('</body>\n')
        i.document.write('</html>\n');
        i.document.close();
  };
  function $(o) {
    if (typeof(o) == "string")
      return document.getElementById(o)
      else
      return o;
  };
  function applyStyleString(el,str){
    if(document.all && !window.opera) {
      el.style.cssText = str;
      el.setAttribute("cssText",str);
    } else {
      el.setAttribute("style",str);
    }
  };
  // To cover IE 5.0's lack of the push method
  if(typeof Array.prototype.push != "function"){
      Array.prototype.push = ArrayPush;
      function ArrayPush(value){
          this[this.length] = value;
      }
  }

/* Underliggende kode tilhører SwitchMenu */
/* Slett alt under om den ikke brukes     */
/* Fjern kommentarblokk for å aktivere    */
/*
if (document.getElementById){
  document.write('<style type="text/css">\n')
  document.write('.submenu{display: none;}\n')
  document.write('</style>\n')
};
function SwitchMenu(obj){
  if(document.getElementById){
  var el = document.getElementById(obj);
  if(el){ // For ikke å åpne ikke eksisterende menyer!
  var ar = document.getElementById("CMSmenu").getElementsByTagName("span");
    if(el.style.display != "block"){
      for (var i=0; i<ar.length; i++){
        if (ar[i].className=="submenu")
        ar[i].style.display = "none";
          };
        el.style.display = "block";
        } else {
        el.style.display = "none";
      };
    };
  };
};
*/


/* Function : getElementsByClassName Deluxe Edition
   Author    : http://muffinresearch.co.uk/archives/2006/04/29/getelementsbyclassname-deluxe-edition/ 
   */
function getElementsByClassName(strClass, strTag, objContElm) {
  strTag = strTag || "*";
  objContElm = objContElm || document;
  var objColl = (strTag == '*' && document.all) ? document.all : objContElm.getElementsByTagName(strTag);
  var arr = new Array();
  var delim = strClass.indexOf('|') != -1  ? '|' : ' ';
  var arrClass = strClass.split(delim);
  for (i = 0, j = objColl.length; i < j; i++) {
    var arrObjClass = objColl[i].className.split(' ');
    if (delim == ' ' && arrClass.length > arrObjClass.length) continue;
    var c = 0;
    comparisonLoop:
    for (k = 0, l = arrObjClass.length; k < l; k++) {
      for (m = 0, n = arrClass.length; m < n; m++) {
        if (arrClass[m] == arrObjClass[k]) c++;
        if (( delim == '|' && c == 1) || (delim == ' ' && c == arrClass.length)) {
          arr.push(objColl[i]);
          break comparisonLoop;
        }
      }
    }
  }
  return arr;
}

/* Steinhaug Webdesign JS library for Easy CMS */
var swlib = { 
  fixhr_id : 'content',
  fixhr_class : 'hr',
  fixhref: function() {
  var elements = document.getElementsByTagName('a');
  var i;
    for ( i=0;i<elements.length;i++ ) {
      var re = new RegExp("#$");
      if (elements[i].getAttribute('href').match(re)) {
        elements[i].setAttribute('href','javascript:;');
      }
    }
  },
  fixhr: function(){
    if (!document.getElementsByTagName) return;
    var hr = document.getElementById(swlib.fixhr_id).getElementsByTagName('hr');
    for (var i=0; i<hr.length; i++) { 
      var newhr = hr[i]; 
      var wrapdiv = document.createElement('div');
      wrapdiv.className = swlib.fixhr_class;  
      newhr.parentNode.replaceChild(wrapdiv, newhr);  
      wrapdiv.appendChild(newhr);  
    } 
  },

  hasClass: function (obj) {
     var result = false;
     if (obj.getAttributeNode("class") != null) {
         result = obj.getAttributeNode("class").value;
     }
     return result;
  },

  setstripe: function (){
    els = getElementsByClassName('stripe','table');
    for (var i=0; i<els.length; i++){
      swlib.stripe(els[i]);
    }
  },
  stripe: function (table){
    var even = true;
    // if arguments are provided to specify the colours
    // of the even & odd rows, then use the them;
    // otherwise use the following defaults:
    var evenColor = arguments[1] ? arguments[1] : "#eff5fd";
    var oddColor = arguments[2] ? arguments[2] : "#dfecfd";
  
    if (! table) { return; }
    
    // by definition, tables can have more than one tbody
    // element, so we'll have to get the list of child
    // &lt;tbody&gt;s 
    var tbodies = table.getElementsByTagName("tbody");

    // and iterate through them...
    for (var h = 0; h < tbodies.length; h++) {
     // find all the &lt;tr&gt; elements... 
      var trs = tbodies[h].getElementsByTagName("tr");

      // ... and iterate through them
      for (var i = 0; i < trs.length; i++) {

        // avoid rows that have a class attribute
        // or backgroundColor style
//        if (! swlib.hasClass(trs[i]) &&
//            ! trs[i].style.backgroundColor) {
         if(! trs[i].style.backgroundColor) {		  

          // get all the cells in this row...
          var tds = trs[i].getElementsByTagName("td");
        
          // and iterate through them...
          for (var j = 0; j < tds.length; j++) {

            var mytd = tds[j];
            // avoid cells that have a class attribute
            // or backgroundColor style
            if (! swlib.hasClass(mytd) &&
                ! mytd.style.backgroundColor) {
        
              mytd.style.backgroundColor =
                even ? evenColor : oddColor;
            
            }
          }
        }
        // flip from odd to even, or vice-versa
        even =  ! even;
      }
    }
  },
  sethighlight: function (){
    els = getElementsByClassName('highlight','table');
    for (var i=0; i<els.length; i++){
      swlib.highlight(els[i]);
    }
  },
  highlight: function (table){
    if (! table) { return; }
    var tbodies = table.getElementsByTagName("tbody");
    for (var h = 0; h < tbodies.length; h++) {
      var trs = tbodies[h].getElementsByTagName("tr");
      for (var i = 0; i < trs.length; i++) {
        trs[i].onmouseover= function(e){
          this.className = 'highlight';
        };
        trs[i].onmouseout= function(e){
          this.className = '';
        };
      }
    }
  },
  overlay : function (){
      overlays = getElementsByClassName('ecms-overlay','span',$('CMSgallery'));
      for (var h = 0; h < overlays.length; h++){
        var overlay = overlays[h];
        // No Work: overlay.next().width || overlay.next('img').width
        // Works  : overlay.nextSibling.width
        applyStyleString($(overlay).up(0),'position:relative;display:block;width:' + overlay.nextSibling.width + 'px;height:' + overlay.nextSibling.height + 'px;');

        if (navigator.userAgent.indexOf('MSIE') > 0 && navigator.userAgent.indexOf('Opera') < 1) {
          s = 'width:' + overlay.getAttribute('x') + 'px; height:' + overlay.getAttribute('y') + 'px; '+
          'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader('+
          'src="' + overlay.getAttribute('src') + '", sizingMethod=\'scale\');';
        } else {
          s = 'width:' + overlay.getAttribute('x') + 'px; height:' + overlay.getAttribute('y') + ';';
          overlay.innerHTML = '<img src="' + overlay.getAttribute('src') + '" width="' + overlay.getAttribute('x') + '" height="' + overlay.getAttribute('y') + '">';
        }
        applyStyleString($(overlay),'position:absolute;top:0;left:0;display:block;' + s);
      }
    }
};
ELO.functionsToCallOnload.push("swlib.fixhref()");
ELO.functionsToCallOnload.push("swlib.setstripe()");
//swlib.fixhr_id = 'content';
//ELO.functionsToCallOnload.push("swlib.fixhr()"); // Do in document!

//ELO.functionsToCallOnload.push("swlib.sethighlight()");


/* Easy CMS JS-Class for gallery template #03. 
   (c) Steinhaug AS - www.steinhaug.com
   Automatic slideshow with start and stop button */
var swGallerySlideshow = {
  lang_start : 'START',
  lang_stop  : 'STOP',
  url_start  : '/index.php',
  url_next   : '',
  seconds    : 5,
  bgcol_active : '#990000',
  bgcol_deactivated : '#009900',
  img_anim   : '<img src="/images/timer-01.gif" width="16" height="16" alt="">',
  img_none   : '<img src="/images/spacer.gif" width="16" height="16" alt="">',
  active     : false,
  getVersion : function() {
    return 'v1.0';
  },
  toggle : function (el){
    if(this.active){
      this.deactivate(el);
    } else {
      this.activate(el);
    }
  },
  timersequence : function () {
    this.seconds = this.seconds - 1;
    if(this.seconds==0){
      clearTimeout(this.timer01);
      document.location.href = this.url_next;
//      alert('Complete');
    } else {
      self.status = this.seconds;
      this.timer01 = setTimeout('swGallerySlideshow.timersequence()',1000);
    }
  },
  activate : function (el) {
    this.active = true;
//    document.getElementById('swGallerySlideshow-button').value = this.lang_stop;
    document.getElementById('swGallerySlideshow-button').innerHTML = this.lang_stop;
    document.getElementById('swGallerySlideshow-anim').innerHTML = this.img_anim;
    this.applyStyleString(document.getElementById('swGallerySlideshow-button'),'background-color: ' + this.bgcol_active + ';')
    this.timer01 = setTimeout('swGallerySlideshow.timersequence()',1000);
  },
  deactivate : function (el) {
    this.active = false;
    clearTimeout(this.timer01);
//    document.getElementById('swGallerySlideshow-button').value = this.lang_start;
    document.getElementById('swGallerySlideshow-button').innerHTML = this.lang_start;
    document.getElementById('swGallerySlideshow-anim').innerHTML = this.img_none;
    this.applyStyleString(document.getElementById('swGallerySlideshow-button'),'background-color: ' + this.bgcol_deactivated + ';')
//    this.clearInnerHTML(document.getElementById('swGallerySlideshow-anim'));
  },
  clearInnerHTML : function (obj){
    while(obj.firstChild) obj.removeChild(obj.firstChild);
  },
  applyStyleString : function (obj,str) {
    if(document.all && !window.opera) {
      obj.style.setAttribute("cssText",str);
    } else {
      obj.setAttribute("style",str);
    }
  }
}

if (!SI) { var SI = new Object(); };
/******************************************************************************
 SI.Scroll module v1.0
 
 Based on and including code originally created by Travis Beckam of 
 http://www.squidfingers.com | http://www.podlob.com
 
 ******************************************************************************/
SI.Scroll = {
	yOffset			: 0,
	scrollLoop 		: false, 
	scrollInterval	: null,
    containername   : 'container',
	getWindowHeight	: function() {
		if (document.all) {  return (document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.clientHeight; }
		else { return window.innerHeight; }
		},
	getScrollLeft	: function() {
		if (document.all) { return (document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft; }
		else { return window.pageXOffset; }
		},
	getScrollTop	: function() {
		if (document.all) { return (document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop; }
		else { return window.pageYOffset; }
		},
	getElementYpos	: function(el) {
		var y = 0;
		while(el.offsetParent){
			y += el.offsetTop
			el = el.offsetParent;
			}
		return y;
		},
	to 				: function(id){
		if(this.scrollLoop){
			clearInterval(this.scrollInterval);
			this.scrollLoop = false;
			this.scrollInterval = null;
			}
		var container = document.getElementById(this.containername);
		var documentHeight = this.getElementYpos(container) + container.offsetHeight;
		var windowHeight = this.getWindowHeight()-this.yOffset;
		var ypos = this.getElementYpos(document.getElementById(id));
		if(ypos > documentHeight - windowHeight) ypos = documentHeight - windowHeight;
		this.scrollTo(0,ypos-this.yOffset);
		},
	scrollTo 		: function(x,y) {
		if(this.scrollLoop) {
			var left = this.getScrollLeft();
			var top = this.getScrollTop();
			if(Math.abs(left-x) <= 1 && Math.abs(top-y) <= 1) {
				window.scrollTo(x,y);
				clearInterval(this.scrollInterval);
				this.scrollLoop = false;
				this.scrollInterval = null;
				}
			else {
				window.scrollTo(left+(x-left)/2, top+(y-top)/2);
				}
			}
		else {
			this.scrollInterval = setInterval("SI.Scroll.scrollTo("+x+","+y+")",100);
			this.scrollLoop = true;
			}
		}
	};

/* Quick validation for the login form */
function chk_ecms_login(el){
  if(!el.usr.value.length){
    alert('Du har ikke oppgitt noen brukernavn!');
  }
  if(!el.pas.value.length){
    alert('Du har ikke oppgitt noen passord!');
  }
  return true;
}
function guestbookCheck(){}
function ValidateEmail(theinput){
  s=theinput.value
  if(s.search){
    return (s.search(new RegExp("^([-!#$%&'*+./0-9=?A-Z^_`a-z{|}~])+@([-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+\\.)+[a-zA-Z]{2,4}$","gi"))>=0)
  }
  if(s.indexOf){
    at_character=s.indexOf('@')
    if(at_character<=0 || at_character+4>s.length)
      return false
  }
  if(s.length<6)
    return false
    else
    return true
}

  var cookieNames = new Array();
  function Get_Cookie(name) { 
    var start = document.cookie.indexOf(name+"="); 
    var len = start+name.length+1; 
    if ((!start) && (name != document.cookie.substring(0,name.length))) return null; 
    if (start == -1) return null; 
    var end = document.cookie.indexOf(";",len); 
    if (end == -1) end = document.cookie.length; 
    return unescape(document.cookie.substring(len,end)); 
  } 
  function Set_Cookie(name,value,expires,path,domain,secure) { 
    expires = expires * 60*60*24*1000;
    var today = new Date();
    var expires_date = new Date( today.getTime() + (expires) );
    var cookieString = name + "=" +escape(value) + 
      ( (expires) ? ";expires=" + expires_date.toGMTString() : "") + 
      ( (path) ? ";path=" + path : "") + 
      ( (domain) ? ";domain=" + domain : "") + 
      ( (secure) ? ";secure" : ""); 
    document.cookie = cookieString; 
  }