//<script>
function $(o) {
  if (typeof(o) == "string")
    return document.getElementById(o)
    else
    return o;
};
function applyStyleString (obj,str) {
  if(document.all && !window.opera) {
    obj.style.setAttribute("cssText",str);
  } else {
    obj.setAttribute("style",str);
  }
};

// ---
/*
	ELO - Encapsulated Load Object, by Robert Nyman, http://www.robertnyman.com
	Inspired and influenced by Dean Edwards, Matthias Miller, and John Resig: http://dean.edwards.name/weblog/2006/06/again/
*/
var ELO = {
	loaded : false,
	timer : null,
	functionsToCallOnload : [], // Type in functions as strings here. e.g. "myFunction()"
	init : function (){
		if(ELO.loaded) return;
		ELO.loaded = true;
		ELO.load();
	},
	
	load : function (){
		if(this.timer){
			clearInterval(this.timer);
		}
		for(var i=0; i<this.functionsToCallOnload.length; i++){
			try{
				eval(this.functionsToCallOnload[i]);
			}
			catch(e){
				// Handle error here
			}
		}
	}
};
// ---
/* Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
	if(document.getElementById){
		document.write("<script id=\"ieScriptLoad\" defer src=\"javascript:void(0)\"><\/script>");
	    document.getElementById("ieScriptLoad").onreadystatechange = function() {
	        if (this.readyState == "complete") {
	            ELO.init();
	        }
	    };
	}
/*@end @*/
// ---
/* Mozilla/Opera 9 */
if (document.addEventListener) {
	document.addEventListener("DOMContentLoaded", ELO.init, false);
}
// ---
/* Safari */
if(navigator.userAgent.search(/WebKit/i) != -1){
    ELO.timer = setInterval(function (){
		if(document.readyState.search(/loaded|complete/i) != -1) {
			ELO.init();
		}
	}, 10);
}
// ---
/* Other web browsers */
window.onload = ELO.init;
// ---

/*************************************
*    Script : swPOP 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 swPOP(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 validateNR(theform,felt) {
  var valid="1234567890";
  string = theform.value;
  for (var i=0; i<string.length; i++) {
    if (valid.indexOf(string.charAt(i)) < 0) {
      alert(felt+' inneholder ugyldige tegn!');
      theform.value='';
      theform.focus();
      return false;
    }
  }
  return false;
} 
function cartDelete(id,navn,qu){
  if(id=="0"){
    alert("Det har skjedd en feil, ingen vare er valgt!");
    return false;
  }
  if (confirm("Er du sikker på at du vil slette\nvaren " + navn + "?")) {
    location.href='storefront.php?' + qu + '&action=cartDelete&id=' + id;
  }
}
function cartSubtract(id,navn,qu){
  if(id=="0"){
    alert("Det har skjedd en feil, ingen vare er valgt!");
    return false;
  }
  location.href='storefront.php?' + qu + '&action=cartSubtract&id=' + id;
}
function cartAdd(id,navn,qu){
  if(id=="0"){
    alert("Det har skjedd en feil, ingen vare er valgt!");
    return false;
  }
  location.href='storefront.php?' + qu + '&action=cartAdd&id=' + id;
}
function chkLogin(theform){
  if(theform.usr.value<=0){
    alert("Du må skrive inn ditt brukernavn!");
    theform.usr.focus();
    return false;
  }
  if(theform.pas.value<=0){
    alert("Du må skrive inn ditt passord!");
    theform.pas.focus();
    return false;
  }
}
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
}
function sf_search_chk(mode){
  if(mode){
    if (document.sf_search.q.value<=0){
      alert("Søkefeltet er tomt!");
      document.sf_search.q.focus();
      return false;
    } else if (document.sf_search.q.value.length<=2){
      alert("Søkeordet er for kort.\nDu må søke på minst 3 tegn.");
      document.sf_search.q.focus();
      return false;
    } else {
      return true;
    }
  } else {
    if (document.sf_search.q.value<=0){
      alert("Søkefeltet er tomt!");
      document.sf_search.q.focus();
    } else if (document.sf_search.q.value.length<=2){
      alert("Søkeordet er for kort.\nDu må søke på minst 3 tegn.");
      document.sf_search.q.focus();
    } else {
      document.sf_search.submit();
    }
  }
}
function sf_search_inline_chk(){
  if (document.sf_search_inline.q.value<=0){
    alert("Søkefeltet er tomt!");
    document.sf_search_inline.q.focus();
    return false;
  } else if (document.sf_search_inline.q.value.length<=2){
    alert("Søkeordet er for kort.\nDu må søke på minst 3 tegn.");
    document.sf_search_inline.q.focus();
    return false;
  } else {
    return true;
  }
}
function _forcenumber(myString) {
  var pattern = /\W|\D/gi;
  var newString = myString.replace(pattern,"")
  return newString;
}
function _removeWhiteSpace(myString){
  return myString.replace(/ {2,}/g,' ').replace(/[\n\r]*/g,'');
}
// redefining default features
var _POPUP_FEATURES = 'location=0,statusbar=0,menubar=0,width=500,height=400';
/*
listen('load', window, function() {
	listen('click', 'popup-listen', event_popup );
	listen('click', 'popup-feat'  , event_popup_features('location=0,statusbar=1,menubar=1,width=190,height=300') );
	//mlisten('click', getElementsByClass('popup','a'), event_popup );
});
*/

function urlencode(d,e) {
 if (typeof(encodeURIComponent) == 'function') {
  if (e) return encodeURI(d);
  else return encodeURIComponent(d);
 } else {
  return escape(d);
 }
}

function remove_nl_text(el){
  if(el.value = 'Din e-post adresse her'){
    el.value = '';
  }
}

