// <script>
  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);
    }
  };

// ---
/*
	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=\"//:\"><\/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;
  }
  return true;
}
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;
  return true;
}
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;
  return true;
}
function chkLogin(el){
  if(el.usr.value<=0){
    alert("Du må skrive inn ditt brukernavn!");
    el.usr.focus();
    return false;
  }
  if(el.pas.value<=0){
    alert("Du må skrive inn ditt passord!");
    el.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;
}
/*
  Will remove all illegal characters
*/
function _forcedecimal(suppliedValue){
  var valid_chars = "1234567890.,";
  var newValue = '';
  for (var i=0; i<suppliedValue.length; i++) {
    if (valid_chars.indexOf(suppliedValue.charAt(i)) < 0) {
    } else {
      if(suppliedValue.charAt(i) == ','){
        newValue = newValue.toString() + '.';
      } else {
        newValue = newValue.toString() + suppliedValue.charAt(i).toString();
      }
    }
  }
  return newValue;
}
function _forcedecimal_norsk(suppliedValue){
  var valid_chars = "1234567890.,";
  var newValue = '';
  for (var i=0; i<suppliedValue.length; i++) {
    if (valid_chars.indexOf(suppliedValue.charAt(i)) < 0) {
    } else {
      newValue = newValue.toString() + suppliedValue.charAt(i).toString();
    }
  }
  return newValue;
}

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 = '';
  }
  if(el.value = 'Your email here'){
    el.value = '';
  }
}

function chkPurchase(el){
  // This function is not in use at the moment, should validate
  // that the number entered in the input field infact in numeric.
  return true;
}

/*
  Usage: 
  if(isValid.decimal(check_value)){ passed }
  if(isValid.currency(check_value)){ passed }
*/
var isValid = (function(){
  var integerTest = /^\d+$/;
  //    var decimalTest = /^\d+\.?\,?\d*$/;
  var decimalTest = /^(-|\d)\d+\.?\,?\d*$/;

  var currencyTest = /^\d+\.\d\d$/;
  return {
    integer: function(n){
      return integerTest.test(n);
    },
    decimal: function(n){
      return decimalTest.test(n);
    },
    currency: function(n){
      return currencyTest.test(n);
    }
  };
})();


        function display_with_tax_correction(amount){
          var switches_7 = EWS_switches_7;
          var tax = EWS_tax;
          var taxmode = EWS_taxmode;
          var display_with_tax = EWS_display_with_tax;

          if(switches_7){
            if(!taxmode){
              if(display_with_tax){
                amount =  amount * ((tax / 100) + 1);
              } else {
                amount = amount;
              }
            } else {
              if(display_with_tax){
                amount = amount;
              } else {
                amount = amount - (amount - (amount / ((tax / 100) + 1)));
              }
            }
          } else {
            amount = amount;
          }
          return amount;
        }

        function CURRENCY(amount,mode){


          var tax_correction = EWS_tax_correction;
          var currency = EWS_currency;
          var space = EWS_space;

          var decimal_length = EWS_decimal_length;
          var dec_point = EWS_dec_point;
          var thousands_sep = EWS_thousands_sep;

          amount = amount / (currency['rate'] / 1000);

          if(tax_correction)
            amount = number_format(display_with_tax_correction(amount),decimal_length,dec_point,thousands_sep);
            else
            amount = number_format(amount,decimal_length,dec_point,thousands_sep);
          switch(mode){
            case 1:
            case 2:
              if(currency['direction'] == 'left')
                var o = '$.100';
                else
                var o = '100.$';
                break;
            case 3:
              if(currency['direction'] == 'left')
                var o = '%now% $.100';
                else
                var o = '%now% 100.$';
                break;
            case 4:
              if(currency['direction'] == 'left')
                var o = '%before% <DEL><STRIKE>$.100</STRIKE></DEL>';
                else
                var o = '%before% <DEL><STRIKE>100.$</STRIKE></DEL>';
                break;
            case 5:
              if(currency['direction'] == 'left')
                var o = '%veiledende_price% $.100';
                else
                var o = '%veiledende_price% 100.$';
                break;
            case 6:
              if(currency['direction'] == 'left')
                var o = '%our_price% $.100';
                else
                var o = '%our_price% 100.$';
                break;
            case 7:
              if(currency['direction'] == 'left')
                var o = '%you_save% $.100';
                else
                var o = '%you_save% 100.$';
                break;
            default:
                var o = '100';
          }
          var symbols = ['$','','£'];
          if(!in_array(currency['symbol'],symbols)){
            var symbl = currency['symbol'] + ' ';
            var symbr = ' ' + currency['symbol'];
          } else {
            var symbl = currency['symbol'];
            var symbr = currency['symbol'];
          }

          o = str_replace('%you_save%',_you_save,o);
          o = str_replace('%our_price%',_our_price,o);
          o = str_replace('%veiledende_price%',_veiledende_price,o);
          o = str_replace('%before%',_before,o);
          o = str_replace('%now%',_now,o);
          o = str_replace('.$',symbr,o);
          o = str_replace('$.',symbl,o);
          o = str_replace('100',amount,o);
         return str_replace(' ',space,o);
        }

/* 
  Will round up a number to closest interval after a determined minimum
*/
function sw_round_interval(val,min,interval){
  if(val < min)
    return parseFloat(number_format( min, 2, '.', '' ));
  tmp_float = val / interval;
  tmp_int = Math.floor(tmp_float);

  if( (tmp_float - tmp_int) > 0){
    return parseFloat(number_format( (tmp_int+1) * parseFloat(interval), 2, '.', '' ));
  } else {
    return parseFloat(number_format( val, 2, '.', '' ));
  }
}


/* 
 * More info at: http://phpjs.org
 * 
 * This is version: 3.09
 * php.js is copyright 2010 Kevin van Zonneveld.
 * 
 * Portions copyright Brett Zamir (http://brett-zamir.me), Kevin van Zonneveld
 * (http://kevin.vanzonneveld.net), Onno Marsman, Theriault, Michael White
 * (http://getsprink.com), Waldo Malqui Silva, Paulo Ricardo F. Santos, Jack,
 * Jonas Raoni Soares Silva (http://www.jsfromhell.com), Philip Peterson,
 * Legaev Andrey, Ates Goral (http://magnetiq.com), Alex, Ratheous, Martijn
 * Wieringa, Nate, Philippe Baumann, lmeyrick
 * (https://sourceforge.net/projects/bcmath-js/), Enrique Gonzalez,
 * Webtoolkit.info (http://www.webtoolkit.info/), Jani Hartikainen, travc, Ole
 * Vrijenhoek, Ash Searle (http://hexmen.com/blog/), Carlos R. L. Rodrigues
 * (http://www.jsfromhell.com), d3x,
 * http://stackoverflow.com/questions/57803/how-to-convert-decimal-to-hex-in-javascript,
 * pilus, stag019, WebDevHobo (http://webdevhobo.blogspot.com/), Michael
 * Grier, Erkekjetter, T.Wild, Andrea Giammarchi
 * (http://webreflection.blogspot.com), marrtins, GeekFG
 * (http://geekfg.blogspot.com), Johnny Mast (http://www.phpvrouwen.nl),
 * gorthaur, Michael White, majak, Steve Hilder, Oleg Eremeev, Martin
 * (http://www.erlenwiese.de/), gettimeofday, Joris, Steven Levithan
 * (http://blog.stevenlevithan.com), Tim de Koning (http://www.kingsquare.nl),
 * KELAN, Arpad Ray (mailto:arpad@php.net), Breaking Par Consulting Inc
 * (http://www.breakingpar.com/bkp/home.nsf/0/87256B280015193F87256CFB006C45F7),
 * Josh Fraser
 * (http://onlineaspect.com/2007/06/08/auto-detect-a-time-zone-with-javascript/),
 * Chris, Marc Palau, Public Domain (http://www.json.org/json2.js), saulius,
 * Aman Gupta, Pellentesque Malesuada, Mailfaker (http://www.weedem.fr/), Caio
 * Ariede (http://caioariede.com), Thunder.m, Alfonso Jimenez
 * (http://www.alfonsojimenez.com), AJ, mdsjack (http://www.mdsjack.bo.it),
 * Lars Fischer, Kankrelune (http://www.webfaktory.info/), Felix Geisendoerfer
 * (http://www.debuggable.com/felix), Tyler Akins (http://rumkin.com), Mirek
 * Slugen, Robin, Karol Kowalski, Paul Smith, Sakimori, David, noname, Marco,
 * Douglas Crockford (http://javascript.crockford.com), Scott Cariss,
 * class_exists, marc andreu, Steve Clay, Francois, nobbler, David James,
 * Arno, madipta, Fox, mktime, ger, Nathan, felix, Frank Forte, Slawomir
 * Kaniecki, john (http://www.jd-tech.net), Nick Kolosov (http://sammy.ru),
 * Mateusz "loonquawl" Zalega, ReverseSyntax, nord_ua, T. Wild, Thiago Mata
 * (http://thiagomata.blog.com), Linuxworld, lmeyrick
 * (https://sourceforge.net/projects/bcmath-js/this.), Jon Hohle, Pyerre,
 * MeEtc (http://yass.meetcweb.com), Peter-Paul Koch
 * (http://www.quirksmode.org/js/beat.html), T0bsn, Soren Hansen, djmix,
 * Lincoln Ramsay, Sanjoy Roy, sankai, Denny Wardhana, 0m3r, Subhasis Deb,
 * Bayron Guevara, paulo kuong, duncan, Gilbert, Brad Touesnard, Tim Wiel,
 * Marc Jansen, Francesco, Stoyan Kyosev (http://www.svest.org/), J A R, Paul,
 * Ole Vrijenhoek (http://www.nervous.nl/), Raphael (Ao RUDLER), kenneth, Hyam
 * Singer (http://www.impact-computing.com/), LH, JB, JT, Thomas Beaucourt
 * (http://www.webapp.fr), David Randall, Bryan Elliott, date, Ozh, Eugene
 * Bulkin (http://doubleaw.com/), Der Simon
 * (http://innerdom.sourceforge.net/), echo is bad, XoraX
 * (http://www.xorax.info), Matt Bradley, Itsacon (http://www.itsacon.net/),
 * Saulo Vallory, Kristof Coomans (SCK-CEN Belgian Nucleair Research Centre),
 * Pierre-Luc Paour, Kirk Strobeck, Martin Pool, Christoph, Daniel Esteban,
 * Artur Tchernychev, Wagner B. Soares, Valentina De Rosa, strftime, Jason
 * Wong (http://carrot.org/), Brant Messenger
 * (http://www.brantmessenger.com/), Rick Waldron, Bug?, Anton Ongson, Simon
 * Willison (http://simonwillison.net), Marco van Oort, Gabriel Paderni, Blues
 * (http://tech.bluesmoon.info/), Luke Godfrey, rezna, Mick@el, Tomasz
 * Wesolowski, Eric Nagel, Pul, Bobby Drake, uestla, Alan C, Ulrich, Yves
 * Sucaet, sowberry, Norman "zEh" Fuchs, hitwork, Zahlii, johnrembo, Nick
 * Callen, ejsanders, Aidan Lister (http://aidanlister.com/), Brian Tafoya
 * (http://www.premasolutions.com/), Philippe Jausions
 * (http://pear.php.net/user/jausions), Rob, Orlando, HKM, metjay, strcasecmp,
 * strcmp, Taras Bogach, jpfle, ChaosNo1, Alexander Ermolaev
 * (http://snippets.dzone.com/user/AlexanderErmolaev), dptr1988, kilops, Le
 * Torbi, James, DxGx, Pedro Tainha (http://www.pedrotainha.com), Philipp
 * Lenssen, penutbutterjelly, FGFEmperor, baris ozdil, Greg Frazier, Alexander
 * M Beedie, Tod Gentille, gabriel paderni, Yannoo, Maximusya, Atli ÃÃ³r,
 * daniel airton wermann (http://wermann.com.br), jakes, 3D-GRAF, Riddler
 * (http://www.frontierwebdev.com/), T.J. Leahy, Matteo, stensi, Billy, Jalal
 * Berrami, vlado houba, Victor, fearphage
 * (http://http/my.opera.com/fearphage/), Luis Salazar
 * (http://www.freaky-media.com/), FremyCompany, Tim de Koning, taith, Cord,
 * Manish, davook, Benjamin Lupton, Russell Walker (http://www.nbill.co.uk/),
 * Garagoth, Andrej Pavlovic, rem, Dino, Jamie Beck (http://www.terabit.ca/),
 * DtTvB (http://dt.in.th/2008-09-16.string-length-in-bytes.html), Michael,
 * Christian Doebler, setcookie, YUI Library:
 * http://developer.yahoo.com/yui/docs/YAHOO.util.DateLocale.html, Andreas,
 * Blues at http://hacks.bluesmoon.info/strftime/strftime.js, meo, Greenseed,
 * Luke Smith (http://lucassmith.name), Rival, Diogo Resende, Allan Jensen
 * (http://www.winternet.no), Howard Yeend, Kheang Hok Chin
 * (http://www.distantia.ca/), Jay Klehr, Leslie Hoare, mk.keck, Ben Bryan,
 * booeyOH, Amir Habibi (http://www.residence-mixte.com/), Cagri Ekin
 * 
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL KEVIN VAN ZONNEVELD BE LIABLE FOR ANY CLAIM, DAMAGES
 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */ 


// Compression: minified


function base64_decode(data){var b64="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";var o1,o2,o3,h1,h2,h3,h4,bits,i=0,ac=0,dec="",tmp_arr=[];if(!data){return data;}
data+='';do{h1=b64.indexOf(data.charAt(i++));h2=b64.indexOf(data.charAt(i++));h3=b64.indexOf(data.charAt(i++));h4=b64.indexOf(data.charAt(i++));bits=h1<<18|h2<<12|h3<<6|h4;o1=bits>>16&0xff;o2=bits>>8&0xff;o3=bits&0xff;if(h3==64){tmp_arr[ac++]=String.fromCharCode(o1);}else if(h4==64){tmp_arr[ac++]=String.fromCharCode(o1,o2);}else{tmp_arr[ac++]=String.fromCharCode(o1,o2,o3);}}while(i<data.length);dec=tmp_arr.join('');dec=this.utf8_decode(dec);return dec;}
function base64_encode(data){var b64="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";var o1,o2,o3,h1,h2,h3,h4,bits,i=0,ac=0,enc="",tmp_arr=[];if(!data){return data;}
data=this.utf8_encode(data+'');do{o1=data.charCodeAt(i++);o2=data.charCodeAt(i++);o3=data.charCodeAt(i++);bits=o1<<16|o2<<8|o3;h1=bits>>18&0x3f;h2=bits>>12&0x3f;h3=bits>>6&0x3f;h4=bits&0x3f;tmp_arr[ac++]=b64.charAt(h1)+b64.charAt(h2)+b64.charAt(h3)+b64.charAt(h4);}while(i<data.length);enc=tmp_arr.join('');switch(data.length%3){case 1:enc=enc.slice(0,-2)+'==';break;case 2:enc=enc.slice(0,-1)+'=';break;}
return enc;}
function in_array(needle,haystack,argStrict){var key='',strict=!!argStrict;if(strict){for(key in haystack){if(haystack[key]===needle){return true;}}}else{for(key in haystack){if(haystack[key]==needle){return true;}}}
return false;}
function is_array(mixed_var){var key='';var getFuncName=function(fn){var name=(/\W*function\s+([\w\$]+)\s*\(/).exec(fn);if(!name){return'(Anonymous)';}
return name[1];};if(!mixed_var){return false;}
this.php_js=this.php_js||{};this.php_js.ini=this.php_js.ini||{};if(typeof mixed_var==='object'){if(this.php_js.ini['phpjs.objectsAsArrays']&&((this.php_js.ini['phpjs.objectsAsArrays'].local_value.toLowerCase&&this.php_js.ini['phpjs.objectsAsArrays'].local_value.toLowerCase()==='off')||parseInt(this.php_js.ini['phpjs.objectsAsArrays'].local_value,10)===0)){return mixed_var.hasOwnProperty('length')&&!mixed_var.propertyIsEnumerable('length')&&getFuncName(mixed_var.constructor)!=='String';}
if(mixed_var.hasOwnProperty){for(key in mixed_var){if(false===mixed_var.hasOwnProperty(key)){return false;}}}
return true;}
return false;}
function ltrim(str,charlist){charlist=!charlist?' \\s\u00A0':(charlist+'').replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g,'$1');var re=new RegExp('^['+charlist+']+','g');return(str+'').replace(re,'');}
function number_format(number,decimals,dec_point,thousands_sep){var n=!isFinite(+number)?0:+number,prec=!isFinite(+decimals)?0:Math.abs(decimals),sep=(typeof thousands_sep==='undefined')?',':thousands_sep,dec=(typeof dec_point==='undefined')?'.':dec_point,s='',toFixedFix=function(n,prec){var k=Math.pow(10,prec);return''+Math.round(n*k)/k;};s=(prec?toFixedFix(n,prec):''+Math.round(n)).split('.');if(s[0].length>3){s[0]=s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g,sep);}
if((s[1]||'').length<prec){s[1]=s[1]||'';s[1]+=new Array(prec-s[1].length+1).join('0');}
return s.join(dec);}
function rawurldecode(str){return decodeURIComponent(str);}
function rawurlencode(str){str=(str+'').toString();return encodeURIComponent(str).replace(/!/g,'%21').replace(/'/g,'%27').replace(/\(/g,'%28').replace(/\)/g,'%29').replace(/\*/g,'%2A');}
function rtrim(str,charlist){charlist=!charlist?' \\s\u00A0':(charlist+'').replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g,'\\$1');var re=new RegExp('['+charlist+']+$','g');return(str+'').replace(re,'');}
function str_ireplace(search,replace,subject){var i,k='';var searchl=0;var reg;var escapeRegex=function(s){return s.replace(/([\\\^\$*+\[\]?{}.=!:(|)])/g,'\\$1');};search+='';searchl=search.length;if(!(replace instanceof Array)){replace=[replace];if(search instanceof Array){while(searchl>replace.length){replace[replace.length]=replace[0];}}}
if(!(search instanceof Array)){search=[search];}
while(search.length>replace.length){replace[replace.length]='';}
if(subject instanceof Array){for(k in subject){if(subject.hasOwnProperty(k)){subject[k]=str_ireplace(search,replace,subject[k]);}}
return subject;}
searchl=search.length;for(i=0;i<searchl;i++){reg=new RegExp(escapeRegex(search[i]),'gi');subject=subject.replace(reg,replace[i]);}
return subject;}
function str_replace(search,replace,subject,count){var i=0,j=0,temp='',repl='',sl=0,fl=0,f=[].concat(search),r=[].concat(replace),s=subject,ra=r instanceof Array,sa=s instanceof Array;s=[].concat(s);if(count){this.window[count]=0;}
for(i=0,sl=s.length;i<sl;i++){if(s[i]===''){continue;}
for(j=0,fl=f.length;j<fl;j++){temp=s[i]+'';repl=ra?(r[j]!==undefined?r[j]:''):r[0];s[i]=(temp).split(f[j]).join(repl);if(count&&s[i]!==temp){this.window[count]+=(temp.length-s[i].length)/f[j].length;}}}
return sa?s:s[0];}
function trim(str,charlist){var whitespace,l=0,i=0;str+='';if(!charlist){whitespace=" \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000";}else{charlist+='';whitespace=charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g,'$1');}
l=str.length;for(i=0;i<l;i++){if(whitespace.indexOf(str.charAt(i))===-1){str=str.substring(i);break;}}
l=str.length;for(i=l-1;i>=0;i--){if(whitespace.indexOf(str.charAt(i))===-1){str=str.substring(0,i+1);break;}}
return whitespace.indexOf(str.charAt(0))===-1?str:'';}
function urldecode(str){return decodeURIComponent(str.replace(/\+/g,'%20'));}
function urlencode(str){str=(str+'').toString();return encodeURIComponent(str).replace(/!/g,'%21').replace(/'/g,'%27').replace(/\(/g,'%28').replace(/\)/g,'%29').replace(/\*/g,'%2A').replace(/%20/g,'+');}
function utf8_decode(str_data){var tmp_arr=[],i=0,ac=0,c1=0,c2=0,c3=0;str_data+='';while(i<str_data.length){c1=str_data.charCodeAt(i);if(c1<128){tmp_arr[ac++]=String.fromCharCode(c1);i++;}else if((c1>191)&&(c1<224)){c2=str_data.charCodeAt(i+1);tmp_arr[ac++]=String.fromCharCode(((c1&31)<<6)|(c2&63));i+=2;}else{c2=str_data.charCodeAt(i+1);c3=str_data.charCodeAt(i+2);tmp_arr[ac++]=String.fromCharCode(((c1&15)<<12)|((c2&63)<<6)|(c3&63));i+=3;}}
return tmp_arr.join('');}
function utf8_encode(argString){var string=(argString+'');var utftext="";var start,end;var stringl=0;start=end=0;stringl=string.length;for(var n=0;n<stringl;n++){var c1=string.charCodeAt(n);var enc=null;if(c1<128){end++;}else if(c1>127&&c1<2048){enc=String.fromCharCode((c1>>6)|192)+String.fromCharCode((c1&63)|128);}else{enc=String.fromCharCode((c1>>12)|224)+String.fromCharCode(((c1>>6)&63)|128)+String.fromCharCode((c1&63)|128);}
if(enc!==null){if(end>start){utftext+=string.substring(start,end);}
utftext+=enc;start=end=n+1;}}
if(end>start){utftext+=string.substring(start,string.length);}
return utftext;}
	/************************************************************************************************************
	(C) www.dhtmlgoodies.com, October 2005
	
	This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.	
	
	Terms of use:
	You are free to use this script as long as the copyright message is kept intact. However, you may not
	redistribute, sell or repost it without our permission.
	
	Updated:
		
		March, 14th, 2006 - Create new tabs dynamically
		March, 15th, 2006 - Dynamically delete a tab
		
	Thank you!
	
	www.dhtmlgoodies.com
	Alf Magne Kalleland
	
	************************************************************************************************************/		
	var textPadding = 3; // Padding at the left of tab text - bigger value gives you wider tabs
	var strictDocType = true; 
	var tabView_maxNumberOfTabs = 6;	// Maximum number of tabs
	
	/* Don't change anything below here */
	var dhtmlgoodies_tabObj = new Array();
	var activeTabIndex = new Array();
	var MSIE = navigator.userAgent.indexOf('MSIE')>=0?true:false;
	
	var regExp = new RegExp(".*MSIE ([0-9]\.[0-9]).*","g");
	var navigatorVersion = navigator.userAgent.replace(regExp,'$1');
	
	var ajaxObjects = new Array();
	var tabView_countTabs = new Array();
	var tabViewHeight = new Array();
	var tabDivCounter = 0;
	var closeImageHeight = 8;	// Pixel height of close buttons
	var closeImageWidth = 8;	// Pixel height of close buttons
	
	
	function setPadding(obj,padding){
		var span = obj.getElementsByTagName('SPAN')[0];
		span.style.paddingLeft = padding + 'px';	
		span.style.paddingRight = padding + 'px';	
	}
	function showTab(parentId,tabIndex)
	{
		var parentId_div = parentId + "_";
		if(!document.getElementById('tabView' + parentId_div + tabIndex)){
			return;
		}
		if(activeTabIndex[parentId]>=0){
			if(activeTabIndex[parentId]==tabIndex){
				return;
			}
	
			var obj = document.getElementById('tabTab'+parentId_div + activeTabIndex[parentId]);
			
			obj.className='tabInactive';
			var img = obj.getElementsByTagName('IMG')[0];
			if(img.src.indexOf('tab_')==-1)img = obj.getElementsByTagName('IMG')[1];
			img.src = '/admin/images/js/tab-view/tab_right_inactive.gif';
			document.getElementById('tabView' + parentId_div + activeTabIndex[parentId]).style.display='none';
		}
		
		var thisObj = document.getElementById('tabTab'+ parentId_div +tabIndex);	
			
		thisObj.className='tabActive';
		var img = thisObj.getElementsByTagName('IMG')[0];
		if(img.src.indexOf('tab_')==-1)img = thisObj.getElementsByTagName('IMG')[1];
		img.src = '/admin/images/js/tab-view/tab_right_active.gif';
		
		document.getElementById('tabView' + parentId_div + tabIndex).style.display='block';
		activeTabIndex[parentId] = tabIndex;
		

		var parentObj = thisObj.parentNode;
		var aTab = parentObj.getElementsByTagName('DIV')[0];
		countObjects = 0;
		var startPos = 2;
		var previousObjectActive = false;
		while(aTab){
			if(aTab.tagName=='DIV'){
				if(previousObjectActive){
					previousObjectActive = false;
					startPos-=2;
				}
				if(aTab==thisObj){
					startPos-=2;
					previousObjectActive=true;
					setPadding(aTab,textPadding+1);
				}else{
					setPadding(aTab,textPadding);
				}
				
				aTab.style.left = startPos + 'px';
				countObjects++;
				startPos+=2;
			}			
			aTab = aTab.nextSibling;
		}
		
		return;
	}
	
	function tabClick()
	{
		var idArray = this.id.split('_');		
		showTab(this.parentNode.parentNode.id,idArray[idArray.length-1].replace(/[^0-9]/gi,''));
		
	}
	
	function rolloverTab()
	{
		if(this.className.indexOf('tabInactive')>=0){
			this.className='inactiveTabOver';
			var img = this.getElementsByTagName('IMG')[0];
			if(img.src.indexOf('tab_')<=0)img = this.getElementsByTagName('IMG')[1];
			img.src = '/admin/images/js/tab-view/tab_right_over.gif';
		}
		
	}
	function rolloutTab()
	{
		if(this.className ==  'inactiveTabOver'){
			this.className='tabInactive';
			var img = this.getElementsByTagName('IMG')[0];
			if(img.src.indexOf('tab_')<=0)img = this.getElementsByTagName('IMG')[1];
			img.src = '/admin/images/js/tab-view/tab_right_inactive.gif';
		}
		
	}
	
	function hoverTabViewCloseButton()
	{
		this.src = this.src.replace('close.gif','close_over.gif');
	}
	
	function stopHoverTabViewCloseButton()
	{
		this.src = this.src.replace('close_over.gif','close.gif');
	}
	
	function initTabs(mainContainerID,tabTitles,activeTab,width,height,closeButtonArray,additionalTab)
	{
		if(!closeButtonArray)closeButtonArray = new Array();
		
		if(!additionalTab || additionalTab=='undefined'){			
			dhtmlgoodies_tabObj[mainContainerID] = document.getElementById(mainContainerID);
			width = width + '';
			if(width.indexOf('%')<0)width= width + 'px';
			dhtmlgoodies_tabObj[mainContainerID].style.width = width;
if(height!==false){
			height = height + '';
			if(height.length>0){
				if(height.indexOf('%')<0)height= height + 'px';
				dhtmlgoodies_tabObj[mainContainerID].style.height = height;
			}
			

			tabViewHeight[mainContainerID] = height;
}
			var tabDiv = document.createElement('DIV');		
			var firstDiv = dhtmlgoodies_tabObj[mainContainerID].getElementsByTagName('DIV')[0];	
			
			dhtmlgoodies_tabObj[mainContainerID].insertBefore(tabDiv,firstDiv);	
			tabDiv.className = 'dhtmlgoodies_tabPane';			
			tabView_countTabs[mainContainerID] = 0;

		}else{
			var tabDiv = dhtmlgoodies_tabObj[mainContainerID].getElementsByTagName('DIV')[0];
			var firstDiv = dhtmlgoodies_tabObj[mainContainerID].getElementsByTagName('DIV')[1];
			height = tabViewHeight[mainContainerID];
			activeTab = tabView_countTabs[mainContainerID];		
	
			
		}
		
		
		
		for(var no=0;no<tabTitles.length;no++){
			var aTab = document.createElement('DIV');
			aTab.id = 'tabTab' + mainContainerID + "_" +  (no + tabView_countTabs[mainContainerID]);
			aTab.onmouseover = rolloverTab;
			aTab.onmouseout = rolloutTab;
			aTab.onclick = tabClick;
			aTab.className='tabInactive';
			tabDiv.appendChild(aTab);
			var span = document.createElement('SPAN');
			span.innerHTML = tabTitles[no];
			span.style.position = 'relative';
			aTab.appendChild(span);
			
			if(closeButtonArray[no]){
				var closeButton = document.createElement('IMG');
				closeButton.src = 'images/close.gif';
				closeButton.height = closeImageHeight + 'px';
				closeButton.width = closeImageHeight + 'px';
				closeButton.setAttribute('height',closeImageHeight);
				closeButton.setAttribute('width',closeImageHeight);
				closeButton.style.position='absolute';
				closeButton.style.top = '6px';
				closeButton.style.right = '0px';
				closeButton.onmouseover = hoverTabViewCloseButton;
				closeButton.onmouseout = stopHoverTabViewCloseButton;
				
				span.innerHTML = span.innerHTML + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';	
				
				var deleteTxt = span.innerHTML+'';

				closeButton.onclick = function(){ deleteTab(this.parentNode.innerHTML) };
				span.appendChild(closeButton);
			}
			
			var img = document.createElement('IMG');
			img.valign = 'bottom';
			img.src = '/admin/images/js/tab-view/tab_right_inactive.gif';
			// IE5.X FIX
			if((navigatorVersion && navigatorVersion<6) || (MSIE && !strictDocType)){
				img.style.styleFloat = 'none';
				img.style.position = 'relative';	
				img.style.top = '4px'
				span.style.paddingTop = '4px';
				aTab.style.cursor = 'hand';
			}	// End IE5.x FIX
			aTab.appendChild(img);
		}

		var tabs = dhtmlgoodies_tabObj[mainContainerID].getElementsByTagName('DIV');
		var divCounter = 0;
		for(var no=0;no<tabs.length;no++){
			if(tabs[no].className=='dgTab' && tabs[no].parentNode.id == mainContainerID){
				if(height.length>0)tabs[no].style.height = height;
				tabs[no].style.display='none';
				tabs[no].id = 'tabView' + mainContainerID + "_" + divCounter;
				divCounter++;
			}			
		}	
		tabView_countTabs[mainContainerID] = tabView_countTabs[mainContainerID] + tabTitles.length;	
		showTab(mainContainerID,activeTab);

		return activeTab;
	}	
	
	function showAjaxTabContent(ajaxIndex,parentId,tabId)
	{
		var obj = document.getElementById('tabView'+parentId + '_' + tabId);
		obj.innerHTML = ajaxObjects[ajaxIndex].response;		
	}
	
	function resetTabIds(parentId)
	{
		var tabTitleCounter = 0;
		var tabContentCounter = 0;
		
		
		var divs = dhtmlgoodies_tabObj[parentId].getElementsByTagName('DIV');

		
		for(var no=0;no<divs.length;no++){
			if(divs[no].className=='dgTab'){
				divs[no].id = 'tabView' + parentId + '_' + tabTitleCounter;
				tabTitleCounter++;
			}
			if(divs[no].id.indexOf('tabTab')>=0){
				divs[no].id = 'tabTab' + parentId + '_' + tabContentCounter;	
				tabContentCounter++;
			}	
			
				
		}
	
		tabView_countTabs[parentId] = tabContentCounter;
	}
	
	
	function createNewTab(parentId,tabTitle,tabContent,tabContentUrl,closeButton)
	{
		if(tabView_countTabs[parentId]>=tabView_maxNumberOfTabs)return;	// Maximum number of tabs reached - return
		var div = document.createElement('DIV');
		div.className = 'dgTab';
		dhtmlgoodies_tabObj[parentId].appendChild(div);		

		var tabId = initTabs(parentId,Array(tabTitle),0,'','',Array(closeButton),true);
		if(tabContent)div.innerHTML = tabContent;
		if(tabContentUrl){
			var ajaxIndex = ajaxObjects.length;
			ajaxObjects[ajaxIndex] = new sack();
			ajaxObjects[ajaxIndex].requestFile = tabContentUrl;	// Specifying which file to get

			ajaxObjects[ajaxIndex].onCompletion = function(){ showAjaxTabContent(ajaxIndex,parentId,tabId); };	// Specify function that will be executed after file has been found
			ajaxObjects[ajaxIndex].runAJAX();		// Execute AJAX function	

            /* New Protoype object
             var opt = {
              method: 'post',
              postBody: '',
              onSuccess: function(t) {
                div.innerHTML = t.responseText;
              },
              on404: function(t) {
                alert('Error 404: location "' + t.statusText + '" was not found.');
              },
              onFailure: function(t) {
                alert('Error ' + t.status + ' -- ' + t.statusText);
              }
            }
            new Ajax.Request(tabContentUrl, opt);
            */

		}
				
	}
	
	function getTabIndexByTitle(tabTitle)
	{
		var regExp = new RegExp("(.*?)&nbsp.*$","gi");
		tabTitle = tabTitle.replace(regExp,'$1');
		for(var prop in dhtmlgoodies_tabObj){
			var divs = dhtmlgoodies_tabObj[prop].getElementsByTagName('DIV');
			for(var no=0;no<divs.length;no++){
				if(divs[no].id.indexOf('tabTab')>=0){
					var span = divs[no].getElementsByTagName('SPAN')[0];
					var regExp2 = new RegExp("(.*?)&nbsp.*$","gi");
					var spanTitle = span.innerHTML.replace(regExp2,'$1');
					
					if(spanTitle == tabTitle){
						
						var tmpId = divs[no].id.split('_');						
						return Array(prop,tmpId[tmpId.length-1].replace(/[^0-9]/g,'')/1);
					}		
				}
			}
		}
		
		return -1;
		
	}
	
	/* Call this function if you want to display some content from external file in one of the tabs 
	Arguments: Title of tab and relative path to external file */
	
	function addAjaxContentToTab(tabTitle,tabContentUrl)
	{
		var index = getTabIndexByTitle(tabTitle);
		if(index!=-1){
			var ajaxIndex = ajaxObjects.length;
			
			tabId = index[1];
			parentId = index[0];
			
			
			ajaxObjects[ajaxIndex] = new sack();
			ajaxObjects[ajaxIndex].requestFile = tabContentUrl;	// Specifying which file to get

			ajaxObjects[ajaxIndex].onCompletion = function(){ showAjaxTabContent(ajaxIndex,parentId,tabId); };	// Specify function that will be executed after file has been found
			ajaxObjects[ajaxIndex].runAJAX();		// Execute AJAX function				
			
		}	
	}

	
	
	function deleteTab(tabLabel,tabIndex,parentId)
	{

		if(tabLabel){
			var index = getTabIndexByTitle(tabLabel);
			if(index!=-1){
				deleteTab(false,index[1],index[0]);
			}
			
		}else if(tabIndex>=0){
			if(document.getElementById('tabTab' + parentId + '_' + tabIndex)){
				var obj = document.getElementById('tabTab' + parentId + '_' + tabIndex);
				var id = obj.parentNode.parentNode.id;
				obj.parentNode.removeChild(obj);
				var obj2 = document.getElementById('tabView' + parentId + '_' + tabIndex);
				obj2.parentNode.removeChild(obj2);
				resetTabIds(parentId);
				activeTabIndex[parentId]=-1;
				showTab(parentId,'0');
			}			
		}
		

			
		
		
	}
	

