
var coding = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMabcdefghijklmnopqrstuvwxyzabcdefghijklm'
var today = new Date()
var expires = 'Tuesday, 31-Dec-2013 12:00:00 GMT'

var button = 0

function Validate()
{

  if (button != 3)
  {
    return true
  }

  if (document.Bestilling.organisation.value.length > 40) {
    alert( 'Organisation / Firma navnet må max. være 40 tegn (dette er en begrænsning i domænedatabaserne).' )
    document.Bestilling.organisation.focus()
    return false
  }

 if( document.Bestilling.name.value.length < 5 ) {
    alert( 'Husk at skrive navn!' )
    document.Bestilling.name.focus()
    return false
  }

  if( document.Bestilling.street.value.length < 4 ) {
    alert( 'Husk at skrive adresse!' )
    document.Bestilling.street.focus()
    return false
  }

  if( document.Bestilling.zipcode.value.length < 3 ) {
    alert( 'Husk at skrive postnummer!' )
    document.Bestilling.zipcode.focus()
    return false
  }

  if( document.Bestilling.city.value.length < 2 ) {
    alert( 'Husk at skrive by!' )
    document.Bestilling.city.focus()
    return false
  }


  if( document.Bestilling.country.value.length < 4 ) {
    alert( 'Husk at skrive land!' )
    document.Bestilling.country.focus()
    return false
  }

  if( document.Bestilling.phone.value.length < 8 ) {
    alert( 'Husk at skrive telefonnummer!' )
    document.Bestilling.phone.focus()
    return false
  }

  email = document.Bestilling.email.value

  if( email.length < 6 ) {
    alert( 'Husk at skrive en e-mail adresse!' )
    document.Bestilling.email.focus()
    return false
  }

  snaPos = email.indexOf("@")

  if (snaPos == -1) {
    alert( 'Husk et @ i din e-mail adresse!' )
    document.Bestilling.email.focus()
    return false
  }

  if (email.indexOf("@", snaPos+1) != -1) {
    alert( 'Kun et @ i din e-mail adresse!' )
    document.Bestilling.email.focus()
    return false
  }

  pPos = email.indexOf(".",snaPos+2)

  if (pPos == -1) {
    alert( "Der skal mindst være et punktum efter @'et i en e-mail adresse!" )
    document.Bestilling.email.focus()
    return false
  }

  if (pPos+3 > email.length) {
    alert( 'Husk enden på e-mail adressen!' )
    document.Bestilling.email.focus()
    return false
  }

  IsFirm = false
  if (document.Bestilling.organisation.value.length > 1) {
    IsFirm = true
  }

  CvrNotOK = false
  if (document.Bestilling.cvrnr.value.length < 8) {
    CvrNotOK = true
  }

  Domain = document.Bestilling.domain.value;

  if( Domain.length < 4 ) {
    alert( 'Husk at skrive domænenavn!' )
    document.Bestilling.domain.focus()
    return false
  }


  DomReg = false
  if (document.Bestilling.domservice[0].checked || document.Bestilling.domservice[1].checked) {
    DomReg = true
    if (document.Bestilling.domyears4.checked ) {
      if (Domain.indexOf(".dk", 0) < 0)
      {
        alert( 'Domænenavn indeholder ikke .dk og ekstra år til udløb for .dk kan derfor ikke vælges!' )
        document.Bestilling.domain.focus()
        return false
      }
    }

    comnetorg = 0
    if (Domain.indexOf(".com", 0) > 0)
    {
      comnetorg = 1
    }
    if (Domain.indexOf(".net", 0) > 0)
    {
      comnetorg = 1
    }
    if (Domain.indexOf(".org", 0) > 0)
    {
      comnetorg = 1
    }


    if ((document.Bestilling.domyears5.checked)) {
      if (comnetorg == 0)
      {
        alert( 'Domænenavn indeholder ikke .com / .net / .org og ekstra år til udløb for .com / .net / .org kan derfor ikke vælges!' )
        document.Bestilling.domain.focus()
        return false
      }
    }

    if ((document.Bestilling.domyears9.checked)) {
      if (comnetorg == 0)
      {
        alert( 'Domænenavn indeholder ikke .com / .net / .org og ekstra år til udløb for .com / .net / .org kan derfor ikke vælges!' )
        document.Bestilling.domain.focus()
        return false
      }
    }
  }

//  if( IsFirm && CvrNotOK &&  DomReg) {
//    alert( 'Når der angives firmanavn, skal vi bruge jeres CVR nummer til domæneansøgningen!')
//    document.Bestilling.cvrnr.focus()
//    return false
//
//  }

//  if( (document.Bestilling.partserklaering[0].checked == false) && DomReg) {
//    alert( 'Hvis der ikke erklæres, at domænenavnet ikke krænker tredjemands rettigheder, kan vi ikke registrere domænenavnet!' )
//    document.all.parterklaering.scrollIntoView()
//    return false
//  }

  return true;

}


function rot13(input) {
    if (!input) return ''
    for (var output = '',i=0;i<input.length;i++) {
        character = input.charAt(i)
        position = coding.indexOf(character)
        if (position > -1)
            character = coding.charAt(position + 13)
        output += character
    }
    return output
}

function Get_Cookie(name) {
    var start = document.cookie.indexOf(name+"=")
    var len = start+name.length+1
    if ((!start) && (name != document.cookie.substring(0,name.length))) return ""
    if (start == -1) return ""
    var end = document.cookie.indexOf(";",len)
    if (end == -1) end = document.cookie.length
    return unescape(document.cookie.substring(len,end))
}

function Set_Cookie(name,value,expires,path,domain,secure) {
    path = "/"
    document.cookie = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expires : "") +
        ( (path) ? ";path=" + path : "") +
        ( (domain) ? ";domain=" + domain : "") +
        ( (secure) ? ";secure" : "")
}

function set() {

    Set_Cookie("organisation",rot13(document.Bestilling.organisation.value), expires)
    Set_Cookie("cvrnr",rot13(document.Bestilling.cvrnr.value), expires)
    Set_Cookie("navn",rot13(document.Bestilling.name.value), expires)
    Set_Cookie("gade",rot13(document.Bestilling.street.value), expires)
    Set_Cookie("post",rot13(document.Bestilling.zipcode.value), expires)
    Set_Cookie("by",rot13(document.Bestilling.city.value), expires)
    Set_Cookie("land",rot13(document.Bestilling.country.value), expires)
    Set_Cookie("telefon",rot13(document.Bestilling.phone.value), expires)
    Set_Cookie("email",rot13(document.Bestilling.email.value), expires)
    Set_Cookie("ref",rot13(document.Bestilling.ref.value), expires)
    }

function get() {

   if ((document.Bestilling.name.value == "") && (is_nav4up || is_ie4up))
   {
     document.Bestilling.organisation.value=rot13(Get_Cookie("organisation"))
     document.Bestilling.cvrnr.value=rot13(Get_Cookie("cvrnr"))
     document.Bestilling.name.value=rot13(Get_Cookie("navn"))
     document.Bestilling.street.value=rot13(Get_Cookie("gade"))
     document.Bestilling.zipcode.value=rot13(Get_Cookie("post"))
     document.Bestilling.city.value=rot13(Get_Cookie("by"))
     document.Bestilling.country.value=rot13(Get_Cookie("land"))
     document.Bestilling.phone.value=rot13(Get_Cookie("telefon"))
     document.Bestilling.email.value=rot13(Get_Cookie("email"))
     document.Bestilling.ref.value=rot13(Get_Cookie("ref"))
     //if (document.Bestilling.country.value == "") { document.Bestilling.country.value = "Denmark" }
   }
}
