﻿
function goToPrevPage()
{
	var form = document.getElementById("ContactDataForm");
	form.action += "&PrevPage=true";
	form.submit();
}

function onAgreementChange()
{
	var submitButton = top.document.getElementById("SubmitContactButton");
	var agreementCheckBox = top.document.getElementById("AgreementCheckBox");
	if (submitButton != null && agreementCheckBox != null)
	{
		submitButton.disabled = !agreementCheckBox.checked;
	}
}


function SubmitContactData()
{
	var messageText = " should be filled in!";
	if (document.getElementById("Communication_email_1").value=="") {alert("\"Email\"" + messageText);return;}
	if (document.getElementById("FirstName").value=="") {alert("\"Navn\"" + messageText);return;}
	if (document.getElementById("LastName").value=="") {alert("\"Efternavn\"" + messageText);return;}
	if (document.getElementById("Addresse").value=="") {alert("\"Adresse\"" + messageText);return;}
	if (document.getElementById("PostalCode").value=="") {alert("\"Postnr.\"" + messageText);return;}
	if (document.getElementById("City").value=="") {alert("\"By\"" + messageText);return;}
	if (document.getElementById("WorkPhone").value=="") {alert("\"Telefon\"" + messageText);return;}

	if (!CheckEmail("Communication_email_1")) {alert("Please enter correct email!"); return;}

        document.getElementById("ContactDataForm").submit();
}

function CheckEmail(fieldId, warningText)
{
  var control = document.getElementById(fieldId);
  var email = control.value;

  // Check for allowed characters
  var disallowedChars = new Array(32, 38, 42, 43, 44, 47, 58, 59, 60, 61, 62, 63, 91, 92, 93, 124);
  var charIndex;
  for (charIndex = 0; charIndex < disallowedChars.length; charIndex++)
  {
    if (email.indexOf(String.fromCharCode(disallowedChars[charIndex])) > -1)
    {
      return false;
    }
  }
  // check for '@' character
  if (email.indexOf("@") < 1 || email.indexOf("@") > email.length - 2
	|| email.indexOf("@", email.indexOf("@") + 1) > -1)
  {
    return false;
  }
  return true;
}
