
  function validateSocSecNumber(ssn)
  {
    if (CULTURE == null) return false;

    return validateSwitch(CULTURE, ssn);
  }

  function validateSocSecNumberByCulture(ssn, culture)
  {
    return validateSwitch(culture, ssn);
  }  

  function validateSSNByChosenNationality(ssn)
  {
    var culture, culturearray;
  
    if ($get('NationalitetDropDownList').value != '-1')
    {
      culture = $get('NationalitetDropDownList').value;
      culturearray = culture.split(",");
      return validateSwitch(culturearray[0], ssn);
    }
    return false;
  }

  function validateSwitch(culture, ssn)
  {
    var pn;

    switch (culture)
    {
        case 'sv-SE':
            pn = new ssn_swed(ssn);
            pn_sam = new ssn_swed_sam(ssn);

            if (pn.valid)
                return true;
            else if (pn_sam.valid)
                return true;
            else
                return false;
            break;
        
      case 'nb-NO':
        pn = new ssn_norw( ssn );

        if (pn.valid) 
          return true;
        else 
          return false;
        break;
        
      case 'da-DK':
        pn = new ssn_denm( ssn );
        if (pn.valid) 
          return true;
        else 
          return false;
        break;

    default:
        pn = new ssn_dateofbirth(ssn);
        if (pn.valid)
            return true;
        else
            return false;
        break;

      /*
      default: 
        if (ssn.toString().length >= 6) 
          return true;
        break;
      */
    }
    return false;
  }

  function ssn_swed(nr){
	  this.valid=false;
	  if(!nr.match(/^(\d{2})(\d{2})(\d{2})\-(\d{4})$/)){ return false; }
	  this.now=new Date(); this.nowFullYear=this.now.getFullYear()+""; this.nowCentury=this.nowFullYear.substring(0,2); this.nowShortYear=this.nowFullYear.substring(2,4);
	  this.year=RegExp.$1; this.month=RegExp.$2; this.day=RegExp.$3; this.controldigits=RegExp.$4;
	  this.fullYear=(this.year*1<=this.nowShortYear*1)?(this.nowCentury+this.year)*1:((this.nowCentury*1-1)+this.year)*1;
	  var months = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	  if(this.fullYear%400==0||this.fullYear%4==0&&this.fullYear%100!=0){ months[1]=29; }
	  if(this.month*1<1||this.month*1>12||this.day*1<1||this.day*1>months[this.month*1-1]){ return false; }
	  this.alldigits=this.year+this.month+this.day+this.controldigits;
	  var nn="";
	  for(var n=0;n<this.alldigits.length;n++){ nn+=((((n+1)%2)+1)*this.alldigits.substring(n,n+1)); }
	  this.checksum=0;
	  for(var n=0;n<nn.length;n++){ this.checksum+=nn.substring(n,n+1)*1; }
	  this.valid=(this.checksum%10==0)?true:false;
	  this.sex=parseInt(this.controldigits.substring(2,3))%2;
  }

  function ssn_swed_sam(nr) {
      this.valid = false;
      if (!nr.match(/^(\d{2})(\d{2})(\d{2})\-(\d{4})$/)) {
          return false;
      }
      this.now = new Date();
      this.nowFullYear = this.now.getFullYear() + "";
      this.nowCentury = this.nowFullYear.substring(0, 2);
      this.nowShortYear = this.nowFullYear.substring(2, 4);
      this.year = RegExp.$1;
      this.month = RegExp.$2;
      this.day = RegExp.$3;
      this.controldigits = RegExp.$4;
      this.fullYear = (this.year * 1 <= this.nowShortYear * 1) ? (this.nowCentury + this.year) * 1 : ((this.nowCentury * 1 - 1) + this.year) * 1;
      var months = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
      if (this.fullYear % 400 == 0 || this.fullYear % 4 == 0 && this.fullYear % 100 != 0) {
          months[1] = 29;
      }
      if (this.month * 1 < 1 || this.month * 1 > 12 || this.day * 1 < 1 || this.day * 1 > (months[this.month * 1 - 1] + 60)) {
          return false;
      }
      this.alldigits = this.year + this.month + this.day + this.controldigits;
      var nn = "";
      for (var n = 0; n < this.alldigits.length; n++) {
          nn += ((((n + 1) % 2) + 1) * this.alldigits.substring(n, n + 1));
      }
      this.checksum = 0;
      for (var n = 0; n < nn.length; n++) {
          this.checksum += nn.substring(n, n + 1) * 1;
      }
      this.valid = (this.checksum % 10 == 0) ? true : false;
      this.sex = parseInt(this.controldigits.substring(2, 3)) % 2;
  }

  function ssn_dateofbirth(nr) {
      this.valid = false;
      if (!nr.match(/^(\d{4})\-(\d{2})\-(\d{2})$/)) {
          return false;
      }

      this.year = RegExp.$1;
      this.month = RegExp.$2;
      this.day = RegExp.$3;

      var months = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
      if (this.fullYear % 400 == 0 || this.fullYear % 4 == 0 && this.fullYear % 100 != 0) {
          months[1] = 29;
      }

      if (this.month * 1 < 1 || this.month * 1 > 12 || this.day * 1 < 1 || this.day * 1 > (months[this.month * 1 - 1])) {
          return false;
      }
     
      this.valid = true;
  }


  function ssn_norw(nr){
	  this.valid = false;

	  if(!nr.match(/^(\d{2})(\d{2})(\d{2})(\d{5})$/)){ return false; }
    this.valid = true;
  }

  function ssn_denm(nr){
	  this.valid = false;

	  if(!nr.match(/^(\d{2})(\d{2})(\d{2})\-(\d{4})$/)){ return false; }
    this.valid = true;
  }

  function validateEmailAddress(email) 
  { 
    if (email.match(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i)) 
    {
      return true;
    }
    return false;
  } 

  function trim(str)
  {
    if(!str || typeof str != 'string')
      return null;

    return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
  }
