// JavaScript Document


function newWindow(link) {
  var bookWindow;
  bookWindow = window.open(link, "new1", "width=500,height=600,scrollbars,resizable");
  if (bookWindow.open) {
    bookWindow.close;
  }
  bookWindow.focus();
}

function checkform ( form )
{

   if (form.SurName.value == "") {
   alert( "Please enter a surname or name." );
   form.SurName.focus();
	// if the browser is Netscape 6 or IE
	if(document.all || document.getElementByID){
	// change the color of text field
	form.SurName.style.background = "yellow";
  }
    return false ;
  }
	var illegalChars=/^[0-9A-Za-z]+$/;
	
  // allow only letters, numbers
    if (!illegalChars.test(form.SurName.value)) {
    alert( "You must enter only letters or numbers for your name." );
		form.SurName.focus();
		if(document.all || document.getElementByID){
		// change the color of text field
		form.SurName.style.background = "yellow";
    } 
		 return false ;
  }

	
if (form.DOBDay.value == "-1") {
    alert( "Please enter the day you were born." );
    form.DOBDay.focus();
	if(document.all || document.getElementByID){
	// change the color of text field
	form.DOBDay.style.background = "yellow";
  }
    return false ;
  }  
		if (form.DOBMonth.value == "-1") {
    alert( "Please enter the month you were born." );
    form.DOBMonth.focus();
	if(document.all || document.getElementByID){
	// change the color of text field
	form.DOBMonth.style.background = "yellow";
  }
    return false ;
  }
    
   if (form.DOBYear.value == "-1") {
    alert( "Please enter the year you were born." );
    form.DOBYear.focus();
	if(document.all || document.getElementByID){
	// change the color of text field
	form.DOBYear.style.background = "yellow";
  }
    return false ;
  }
	
// check the email address is in the correct format (name@domain.tld). Part written by PerlScriptsJavaScripts.com

if(!check_email(form.Email.value)){
alert("Please enter a valid e-mail address..");
form.Email.focus(); 
// if the browser is Netscape 6 or IE
if(document.all || document.getElementByID){
// change the color of text field
form.Email.style.background = "yellow";
}
// make sure the form is not submitted
return false;
}


   if (form.Password.value == "") {
    alert( "Please enter a password." );
    form.Password.focus();
    if(document.all || document.getElementByID){
	// change the color of text field
	form.Password.style.background = "yellow";
  }
	return false ;
  }
	    if (!illegalChars.test(form.Password.value)) {
    alert( "You must enter only letters or numbers for your password." );
		form.Password.focus();
		if(document.all || document.getElementByID){
		// change the color of text field
		form.Password.style.background = "yellow";
    } 
		 return false ;
  }
	 if (form.Password.value.length <5) {
    alert( "Please enter a password that is at least 5 characters long" );
    form.Password.focus();
	if(document.all || document.getElementByID){
	// change the color of text field
	form.Password.style.background = "yellow";
  }
      return false ;
  }
    if (form.Password.value.length >20) {
    alert( "Please enter a Password that is under 20 characters long." );
    form.Password.focus();
	if(document.all || document.getElementByID){
	// change the color of text field
	form.Password.style.background = "yellow";
  }
    return false ;
  }
	if (form.Password2.value == "") {
    alert( "Please repeat your password." );
    form.Password2.focus();
    if(document.all || document.getElementByID){
	// change the color of text field
	form.Password2.style.background = "yellow";
  }
	return false ;
  }

    if (form.Password.value != form.Password2.value)
    {
        alert('Please make sure your passwords match.');
        return false;
    } 
  if (form.Disclaim.checked== false) {
    alert( "Please read the disclaimer and tick the box." );
    form.Disclaim.focus();
    if(document.all || document.getElementByID){
	// change the color of text field
	form.Disclaim.style.background = "yellow";
  }
	return false ;
  }
    
   
	{

  AddUser.SubmitButton.disabled=true;
  SubmitForm(this.form);
  return true;

}
  
}

// Email Validation. Written by PerlScriptsJavaScripts.com

function check_email(e) {
ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";

for(i=0; i < e.length ;i++){
if(ok.indexOf(e.charAt(i))<0){ 
return (false);
}	
} 

if (document.images) {
re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
if (!e.match(re) && e.match(re_two)) {
return (-1);		
} 

}

}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function prepareInputsForHints() {
	var inputs = document.getElementsByTagName("input");
	for (var i=0; i<inputs.length; i++){
		// test to see if the hint span exists first
		if (inputs[i].parentNode.getElementsByTagName("span")[0]) {
			// the span exists!  on focus, show the hint
			inputs[i].onfocus = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
			}
			// when the cursor moves away from the field, hide the hint
			inputs[i].onblur = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "none";
			}
		}
	}
	// repeat the same tests as above for selects
	var selects = document.getElementsByTagName("select");
	for (var k=0; k<selects.length; k++){
		if (selects[k].parentNode.getElementsByTagName("span")[0]) {
			selects[k].onfocus = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
			}
			selects[k].onblur = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "none";
			}
		}
	}
}
addLoadEvent(prepareInputsForHints);

