//<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);
  }
};
/*************************************
*    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 findObj(n, d) { //v4.0
  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=findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}
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);
 }
}

