
Lang = new function()
{
   var _me = this;
   
   /* price formats                    */
   var _price_format = {
      'SEK'  : '% kr',
      'DKK'  : '% DKK',
      'EUR'  : '% €',
      'USD'  : '$ %',
      'HKD'  : 'HK$ %',
      'GBP'  : '£ %'
   };

   var _date_format = {
      'en_US'  : 'M j, Y',   // Jan 16, 2010
      'en_UK'  : 'M j, Y',
      'en_HK'  : 'Y M d',
      'zh_CN'  : 'Y M d',
      'zh_HK'  : 'd-m-y',
      'da_DK'  : 'd M Y',
      'sv_FI'  : 'Y M d',
      'sv_SE'  : 'Y M d'
   };

   var _time_format = {
      'en_US'  : 'g:i A',
      'en_UK'  : 'g:i A',
      'en_HK'  : 'g:i A',
      'zh_CN'  : 'g:i A',
      'zh_HK'  : 'g:i A',  // 3:03 AM
      'da_DK'  : 'H:i',
      'sv_FI'  : 'H:i',
      'sv_SE'  : 'H:i'
   };
   
   /* keep these private for safety   */
   var _lang     = 'da';
   var _currency = 'DKK';
   var _locale   = 'da_DK';
   var _data     = {"LBL_YES":"Ja","LBL_NO":"Nej","LBL_LIVEIT_BOX":"Live it box","TXT_LIVEIT_BOX":"Live it boxen","LBL_BOXNUMBER":"Boxnummer","LBL_SEC_CODE":"Sikkerhedskode","LBL_RELATED":"Relateret","TXT_CART_IS_EMPTY":"Indk\u00f8bskurven er tom","TXT_CART_SHOW":"Vis indk\u00f8bskurv","LBL_THANK_YOU":"Tak!","TXT_NEWSLETTER":"Din e-mail adresse er blevet registreret.","TXT_TELL_A_FRIEND":"Din besked er sendt!","ERR_GENERIC":"Ukendt fejl. Hvis problemet forts\u00e6tter er du velkommen til at kontakte vores kundeservice.","PRICE_DEC_SEPARATOR":",","PRICE_THD_SEPARATOR":".","LBL_TOTALS_VAT":"Heraf moms","LBL_TOTALS":"Total","LBL_TOTALS_ORDER":"Samlet ordre","LBL_TOTALS_DELIVERY":"Levering","LBL_TOTALS_PAYFEE":"Bet. afgift","LBL_LOGOUT":"Log ud","LBL_OK":"OK","LBL_SAVE":"Gem","LBL_CANCEL":"Annuller","LBL_CLOSE":"Luk","LBL_BACK":"Tilbage","LBL_FORW":"Frem","LBL_FIRST":"F\u00f8rste","LBL_PREV":"Forrige","LBL_NEXT":"N\u00e6ste","LBL_LAST":"Sidste","LBL_CONTINUE":"Forts\u00e6t","LBL_CONFIRM":"Bekr\u00e6ft","LBL_UNDO":"Fortryd","LBL_APPLY":"Ans\u00f8g","LBL_COMPLETE":"Udf\u00f8r","LBL_PRINT":"Print","LBL_SEARCH":"S\u00f8g","LBL_SEND":"Send","LBL_BOOK":"Book","LBL_MONTH_SHORT":"m\u00e5ned","LBL_NAME":"Navn","LBL_REFERENCE":"Navn","LBL_SSN_PERSON":"CPR-nr","LBL_SSN_COMPANY":"CVR-nr","LBL_COMPANY":"Virksomhed","LBL_PHONE":"Telefon","LBL_EMAIL":"E-mail","LBL_ZIP_CODE":"Postnr.","LBL_ADDRESS":"Adresse","LBL_CITY":"By","LBL_COUNTRY":"Land","LBL_PRODUCT":"Produkt","LBL_QTY":"Stk.","LBL_VALUE":"V\u00e6rdi","LBL_PCS":"Stk.","LBL_A_PRICE":"Enhedspris","LBL_SUM":"Totalpris","LBL_PAY_CARD":"Betalingskort","LBL_PAY_CASH":"Betal i butik","LBL_PAY_INVOICE":"Faktura","LBL_PAY_COD":"Cash On Delivery","LBL_WARNING":"Advarsel","LBL_ERROR":"Fejl","WARN_INVALID_QTY":"Der er ingen produkter i indk\u00f8bskurven","WARN_PRODUCT_NOT_FOUND":"Produktet kan ikke findes!","WARN_INVALID_CAMP_CODE":"Ugyldig kampagnekode.","WARN_INVALID_VALUE_GV":"Prisen skal v\u00e6re delelig med ti, og ikke mindre end 200 DKK.","WARN_STOCK_SOLDOUT":"This product is already sold out","WARN_STOCK_FEW_LEFT":"There is only {stockCount} products left","WARN_CHOOSE_CHOICEBOX":"Please choose a choice box first","TXT_DIALOG_ADD_CART":"<p>Produktet er blevet tilf\u00f8jet til din indk\u00f8bskurv.<\/p>\r\n<p>Du kan nu afslutte og g\u00e5 til \u201dkurven\u201d, eller forts\u00e6tte med at handle. Husk, at du altid kan se kurvens indhold, \u00f8verst i h\u00f8jre hj\u00f8rne.\u201d<\/p>","TTL_DIALOG_ADD_CART":"Vil du forts\u00e6tte med at handle?","BTN1_DIALOG_ADD_CART":"Forts\u00e6tte med at handle","BTN2_DIALOG_ADD_CART":"G\u00e5 til kassen"};
   
   /* make these fakes available      */
   this.lang     = 'da';
   this.currency = 'DKK';
   this.locale   = 'da_DK';
   this.timefmt  = _time_format[this.locale];
   this.datefmt  = _date_format[this.locale];
   
   /* add new strings to the data array */
   this.add = function(data)
   {
      if(typeof data != 'array' && typeof data != 'object') return false;
      
      for(var key in data)
      {
         _data[key] = data[key];
      }
   }
   
   function isset(name)
   {
      return (typeof name != 'undefined');
   }
   
   this.price = function(value, decimals, show_currency)
   {
      if(typeof value == 'undefined') value = 0.00;
      if(typeof decimals == 'undefined') decimals = 2;
      if(typeof show_currency == 'undefined') show_currency = true;
      
      var val = parseFloat(value);  // price
      var pre = parseInt(decimals); // precision
      
      if(isNaN(val) || isNaN(pre)) return 'n/a';
      
      var v1  = (isset(_data['PRICE_DEC_SEPARATOR']))? _data['PRICE_DEC_SEPARATOR'] : ',';
      var v2  = (isset(_data['PRICE_THD_SEPARATOR']))? _data['PRICE_THD_SEPARATOR'] : ' ';
      
      /* re-create number_format in JS, suck   */
      var int = parseInt(val);
      var buf = int.toString(); // default without thdsep
      
      if(v2 != '')
      {
         var t = Math.abs(int).toString();
         var p = 0;
         var d = t.length;
         
         buf = (int < 0)? '-' : '';
         
         while(true)
         {
            buf += t.charAt(p++);
            if(p >= t.length) break;
            if(--d % 3 != 0) continue;
            buf += v2;
            d = 3;
         }
      }
      
      if(pre) buf += v1 + Math.abs(val - int).toFixed(pre).substring(2);
      
      if(!show_currency) return buf;
      
      return _price_format[_currency].replace(/%/, buf);
   }
   
   this.date = function(date) {
      
      if(!(date instanceof Date)) date = new Date();
      
      return _me.phpDate(_me.datefmt, (date.getTime() / 1000));
   }
   
   this.time = function(date) {
      
      if(!(date instanceof Date)) date = new Date();
      
      return _me.phpDate(_me.timefmt, (date.getTime() / 1000));
   }

   this.dateTime = function(date) {
      
      if(!(date instanceof Date)) date = new Date();
      
      return _me.phpDate(_me.datefmt +' '+ _me.timefmt, (date.getTime() / 1000));
   }
      
   this.setLang = function(val)
   {
      if(location.search == '')
      {
         location = '?LANG='+ val;
      }
      else
      {
         var arr = location.search.split('&');
         var buf = '';
         
         for(var i in arr)
         {
            var pos = arr[i].indexOf('LANG=');
            if(pos == 0 || pos == 1) continue;
            
            buf += arr[i] +'&';
         }
         
         if(buf == '') buf = '?';
         location = buf +'LANG='+ val;
      }
      
      return false;
   }
   
   this.get = function(name)
   {
      if(!name) return false;
      if(name == 'lang') return _lang;
      if(name == 'currency') return _currency;
      if(name == 'locale') return _locale;
      
      if(isset(_data[name])) return _data[name];
      
      alert('uh-oh, missing text for tag:'+ name);
   }
   
   //alert(this.lang);
   
   this.phpDate = function(format, timestamp)
   {
       // http://kevin.vanzonneveld.net
       // See changelog at http://phpjs.org
       // alert(format, timestamp);
       var that = this,
           jsdate, f, formatChr = /\\?([a-z])/gi, formatChrCb,
           // Keep this here (works, but for code commented-out
           // below for file size reasons)
           //, tal= [],
           _pad = function (n, c) {
               if ((n = n + "").length < c) {
                   return new Array((++c) - n.length).join("0") + n;
               } else {
                   return n;
               }
           },
           txt_words = ["Sun", "Mon", "Tues", "Wednes", "Thurs", "Fri", "Satur",
                        "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
           txt_ordin = {
               1: "st",
               2: "nd",
               3: "rd",
               21: "st", 
               22: "nd",
               23: "rd",
               31: "st"
           };
       
       formatChrCb = function (t, s) {
           return f[t] ? f[t]() : s;
       };
       
       f = {
       // Day
           d: function () { // Day of month w/leading 0; 01..31
               return _pad(f.j(), 2);
           },
           D: function () { // Shorthand day name; Mon...Sun
               return f.l().slice(0, 3);
           },
           j: function () { // Day of month; 1..31
               return jsdate.getDate();
           },
           l: function () { // Full day name; Monday...Sunday
               return txt_words[f.w()] + 'day';
           },
           N: function () { // ISO-8601 day of week; 1[Mon]..7[Sun]
               return f.w() || 7;
           },
           S: function () { // Ordinal suffix for day of month; st, nd, rd, th
               return txt_ordin[f.j()] || 'th';
           },
           w: function () { // Day of week; 0[Sun]..6[Sat]
               return jsdate.getDay();
           },
           z: function () { // Day of year; 0..365
               var a = new Date(f.Y(), f.n() - 1, f.j()),
                   b = new Date(f.Y(), 0, 1);
               return Math.round((a - b) / 864e5) + 1;
           },
   
       // Week
           W: function () { // ISO-8601 week number
               var a = new Date(f.Y(), f.n() - 1, f.j() - f.N() + 3),
                   b = new Date(a.getFullYear(), 0, 4);
               return 1 + Math.round((a - b) / 864e5 / 7);
           },
   
       // Month
           F: function () { // Full month name; January...December
               return txt_words[6 + f.n()];
           },
           m: function () { // Month w/leading 0; 01...12
               return _pad(f.n(), 2);
           },
           M: function () { // Shorthand month name; Jan...Dec
               return f.F().slice(0, 3);
           },
           n: function () { // Month; 1...12
               return jsdate.getMonth() + 1;
           },
           t: function () { // Days in month; 28...31
               return (new Date(f.Y(), f.n(), 0)).getDate();
           },
   
       // Year
           L: function () { // Is leap year?; 0 or 1
               var y = f.Y(), a = y & 3, b = y % 4e2, c = y % 1e2;
               return 0 + (!a && (c || !b));
           },
           o: function () { // ISO-8601 year
               var n = f.n(), W = f.W(), Y = f.Y();
               return Y + (n === 12 && W < 9 ? -1 : n === 1 && W > 9);
           },
           Y: function () { // Full year; e.g. 1980...2010
               return jsdate.getFullYear();
           },
           y: function () { // Last two digits of year; 00...99
               return (f.Y() + "").slice(-2);
           },
   
       // Time
           a: function () { // am or pm
               return jsdate.getHours() > 11 ? "pm" : "am";
           },
           A: function () { // AM or PM
               return f.a().toUpperCase();
           },
           B: function () { // Swatch Internet time; 000..999
               var H = jsdate.getUTCHours() * 36e2, // Hours
                   i = jsdate.getUTCMinutes() * 60, // Minutes
                   s = jsdate.getUTCSeconds(); // Seconds
               return _pad(Math.floor((H + i + s + 36e2) / 86.4) % 1e3, 3);
           },
           g: function () { // 12-Hours; 1..12
               return f.G() % 12 || 12;
           },
           G: function () { // 24-Hours; 0..23
               return jsdate.getHours();
           },
           h: function () { // 12-Hours w/leading 0; 01..12
               return _pad(f.g(), 2);
           },
           H: function () { // 24-Hours w/leading 0; 00..23
               return _pad(f.G(), 2);
           },
           i: function () { // Minutes w/leading 0; 00..59
               return _pad(jsdate.getMinutes(), 2);
           },
           s: function () { // Seconds w/leading 0; 00..59
               return _pad(jsdate.getSeconds(), 2);
           },
           u: function () { // Microseconds; 000000-999000
               return _pad(jsdate.getMilliseconds() * 1000, 6);
           },
   
           // Timezone
           e: function () {
               return 'UTC';
           },
           
           I: function () { // DST observed?; 0 or 1
               // Compares Jan 1 minus Jan 1 UTC to Jul 1 minus Jul 1 UTC.
               // If they are not equal, then DST is observed.
               var a = new Date(f.Y(), 0), // Jan 1
                   c = Date.UTC(f.Y(), 0), // Jan 1 UTC
                   b = new Date(f.Y(), 6), // Jul 1
                   d = Date.UTC(f.Y(), 6); // Jul 1 UTC
               return 0 + ((a - c) !== (b - d));
           },
           O: function () { // Difference to GMT in hour format; e.g. +0200
               var a = jsdate.getTimezoneOffset();
               return (a > 0 ? "-" : "+") + _pad(Math.abs(a / 60 * 100), 4);
           },
           P: function () { // Difference to GMT w/colon; e.g. +02:00
               var O = f.O();
               return (O.substr(0, 3) + ":" + O.substr(3, 2));
           },
           T: function () { 
               return 'UTC';
           },
           Z: function () { // Timezone offset in seconds (-43200...50400)
               return -jsdate.getTimezoneOffset() * 60;
           },
   
           // Full Date/Time
           c: function () { // ISO-8601 date.
               return 'Y-m-d\\Th:i:sP'.replace(formatChr, formatChrCb);
           },
           r: function () { // RFC 2822
               return 'D, d M Y H:i:s O'.replace(formatChr, formatChrCb);
           },
           U: function () { // Seconds since UNIX epoch
               return Math.round(jsdate.getTime() / 1000);
           }
       };
       
       jsdate = (
          (typeof timestamp === 'undefined') ? new Date() :   // Not provided
          (timestamp instanceof Date) ? new Date(timestamp) : // JS Date()
           new Date(timestamp * 1000)                         // UNIX timestamp (auto-convert to int)
           );
       
       
       //alert(typeof format +' '+ format);
       
       return format.replace(formatChr, formatChrCb);
   }
}

var L = Lang.get;

/* eof */

