<!--

function checkPasswords(form) {
	if ((form.password.value != '') && (form.passwordConfirmation.value != '' ))
	{
		if (form.password.value != form.passwordConfirmation.value)
		{
			alert('Your passwords do not match.');
			form.passwordConfirmation.value = '';
			form.passwordConfirmation.focus();
			return false;
		} else {
			return true;
		}
	}
}

function checkRegistrationCodeForm(form) {
	if (	
		trim(form.registrationCodePart1.value).length < 4 ||
		trim(form.registrationCodePart2.value).length < 4 ||
		trim(form.registrationCodePart3.value).length < 4 ||
		trim(form.registrationCodePart4.value).length < 4
	) 
	{
		alert('The product code is incomplete.');
		return false;
	} else {
		return true;
	}
}

function checkRequiredInputField(input, message) {
  if (trim(input.value).length == 0) {
		alert(message);
		return false;
	} else {
		return true;
	}
}

function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1, s.length);
  }
  while (s.substring(s.length - 1, s.length) == ' ') {
    s = s.substring(0, s.length - 1);
  }
  return s;
}

function checkECardPersonalisationForm(form) {

	if (form.recipientName != undefined && form.recipientNameID != undefined) { 

		if (trim(form.recipientName.value).length == 0 && form.recipientNameID.value == '') {
			alert('Please enter the name of the person the eCard is to be sent to,\nor choose a name from the list.');
			return false;
		}

	} else {

		if (form.recipientName != undefined && trim(form.recipientName.value).length == 0) {
			alert('Please enter the name of the person the eCard is to be sent to.');
			return false;
		}

		if (form.recipientNameID != undefined && form.recipientNameID.value == '') {
			alert('Please choose who the card is for.');
			return false;
		}

	}

	if (trim(form.recipientEmail.value).length == 0) {
		alert('Please enter the email address of the person the eCard is to be sent to.');
		return false;
	}

	if (validateEmail(trim(form.recipientEmail.value)) == false) {
		alert('The email address of the person the eCard is to be sent to is invalid.');
		return false;
	}

	if (form.messageID.value == '') {
		alert('Please choose a message.');
		return false;
	}

	if (form.signOffID != undefined && form.signOffID.value == '') {
		alert('Please choose how you would like to sign off.');
		return false;
	}

	if (form.signOff != undefined && form.signOff.value.length == 0) {
		alert('Please enter your party details.');
		return false;
	}

	if (trim(form.senderName.value).length == 0) {
		alert('Please enter your name.');
		return false;
	}

	if (trim(form.senderEmail.value).length == 0) {
		alert('Please enter your email address.');
		return false;
	}

	if (validateEmail(trim(form.senderEmail.value)) == false) {
		alert('Your email address is invalid.');
		return false;
	}

	return true;
}

function validateEmail(addr) {

	if (addr == '') {
	   // email address is mandatory
	   return false;
	}

	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
	   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
	      // email address contains invalid characters 
	      return false;
	   }
	}

	for (i=0; i<addr.length; i++) {
	   if (addr.charCodeAt(i)>127) {
	      // email address contains non ascii characters
	      return false;
	   }
	}

	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
	   // email address must contain an @
	   return false;
	}

	if (atPos == 0) {
	   // email address must not start with @
	   return false;
	}

	if (addr.indexOf('@', atPos + 1) > - 1) {
	   // email address must contain only one @
	   return false;
	}

	if (addr.indexOf('.', atPos) == -1) {
	   // email address must contain a period in the domain name
	   return false;
	}

	if (addr.indexOf('@.',0) != -1) {
	   // period must not immediately follow @ in email address
	   return false;
	}

	if (addr.indexOf('.@',0) != -1){
	   // period must not immediately precede @ in email address
	   return false;
	}

	if (addr.indexOf('..',0) != -1) {
	   // two periods must not be adjacent in email address
	   return false;
	}

	return true;
}

function openWindow(width, height, url) {
	var helpWin = window.open(url, '', 'height=' + height + ', width=' + width + ', toolbar=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no');
	helpWin.resizeTo(width + 2, height + 30);
	helpWin.moveTo(100, 100);
	helpWin.focus();
}

//-->
