﻿
  function UpdateSmsLength(event, textarea)
  {
    if(textarea.value.length > 120)
    {
      textarea.value = textarea.value.substring(0,120);
    }
    
    var messageContainerAdv = document.getElementById('SmsLengthWarningAdv');
    if(messageContainerAdv != null)
      messageContainerAdv.innerHTML = textarea.value.length + " af 120 karakterer brugt";

    var messageContainer = document.getElementById('SmsLengthWarning');
    if(messageContainer != null)
      messageContainer.innerHTML = textarea.value.length + " af 120 karakterer brugt";
  }

  /* SUPPORTING CLASSES */

  /* Offset class */

  function Offset(element)
  {
    this.X = 0;
    this.Y = 0;
    do
    {
      if(element.offsetLeft)
        this.X += element.offsetLeft;
      if(element.offsetTop)
        this.Y += element.offsetTop;
        
      element = element.offsetParent;
    }
    while(element && element.tagName.toLowerCase() != 'html');
  }
  
  Offset.prototype.getPixelsX = function()
  {
    return this.X+'px';
  }
  
  Offset.prototype.getPixelsY = function()
  {
    return this.Y+'px';
  }
  
  
  /* Date class */  
  
  Date.prototype.getDatePart = function()  
  {
    return new Date(this.getFullYear(), this.getMonth(), this.getDate());
  }
  
  Date.prototype.getMonthPart = function()  
  {
    return new Date(this.getFullYear(), this.getMonth(), 0);
  }

  Date.prototype.getWithMonth = function(month)  
  {
    return new Date(this.getFullYear(), month, 0);
  }
  
  Date.prototype.getWithDate = function(dayOfMonth)  
  {
    return new Date(this.getFullYear(), this.getMonth(), dayOfMonth);
  }  

  Date.prototype.getNumberOfDaysInMonth = function()  
  {
    // mic 05.08.2008: another way to get the number
    var d = new Date(this.getFullYear(), this.getMonth() + 2, 0); // nMonth is 0 thru 11
    return(d.getDate());
    //return 32 - new Date(this.getFullYear(), this.getMonth(), 32).getDate();
    //var lastDayInMonth	= new Date (new Date(this.getFullYear(), this.getMonth() + 1, 1)	- (24*60*60*1000));
		//return lastDayInMonth.getDate();
  }  
  
  Date.prototype.PadZero = function(num) 
  {
		return (num	< 10)? '0' + num : num ;
	}
  
  Date.prototype.format = function(format)
  {
		var sTmp = format;
		sTmp = sTmp.replace	("ddd",this.getDayName());
		sTmp = sTmp.replace	("dd",this.PadZero(this.getDate()));
		sTmp = sTmp.replace	("d",this.getDate());
		sTmp = sTmp.replace	("mmm",this.getMonthName());
		sTmp = sTmp.replace	("mm",this.PadZero(this.getMonth()+1));
		sTmp = sTmp.replace	("m",this.getMonth()+1);
		return sTmp.replace ("yyyy",this.getFullYear());
  }
  
  Date.prototype.getMonthName = function(month)
  {
    var monthNames = {0:"Januar",1:"Februar",2:"Marts",3:"April",4:"Maj",5:"Juni",6:"Juli",7:"August",8:"September",9:"Oktober",10:"November",11:"December"};
    return monthNames[month ? month : this.getMonth()];
  }
  
  Date.prototype.getDayName = function(day)
  {
    var dayNames = {1:"Man",2:"Tir",3:"Ons",4:"Tor",5:"Fre",6:"Lør",0:"Søn"};
    return dayNames[day==null ? this.getDay() : day];
  }
  
  Date.prototype.getWeekNumber = function()
  {
    var year = this.getFullYear();
    var month = this.getMonth() + 1;
    var day = this.getDate();

    var a = Math.floor((14-month) / 12);
    var y = year + 4800 - a;
    var m = month + 12 * a - 3;
    var b = Math.floor(y/4) - Math.floor(y/100) + Math.floor(y/400);
    var J = day + Math.floor((153 * m + 2) / 5) + 365 * y + b - 32045;
    var d4 = (((J + 31741 - (J % 7)) % 146097) % 36524) % 1461;
    var L = Math.floor(d4 / 1460);
    var d1 = ((d4 - L) % 365) + L;
    var week = Math.floor(d1/7) + 1;

    return week;
  }


