//Login Module SCRIPT
function validate(){
  var js_email=document.getElementById("email").value;
  var apos=js_email.indexOf("@");
  var dotpos=js_email.lastIndexOf(".");
  var js_password = document.getElementById("password");
  if (apos<1 || dotpos-apos<2){alert("Please enter a valid email address"); return false;}
  if ((js_email.length <=5) || (js_email.length >30)) {alert("Please enter a valid email address"); return false;}
  if (js_password == null) {alert("Please enter a valid Password"); return false;}
  if (js_password.value.length < 5){alert("Please enter a valid Password2"); return false;}
  document.getElementById("gate").submit();
 }
 
function getDocHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}

function open_pop (element){
	document.getElementById('blanket').style.height = getDocHeight()+'px';
	document.getElementById('blanket').style.display = 'block';
	document.getElementById(element).style.display = 'block';
	}

function close_pop(){
	var popups = new Array();
	document.getElementById('blanket').style.display = 'none';
	popups = document.getElementById('popups').getElementsByTagName('div');
	for (i=0;i<popups.length;i++){popups[i].style.display = 'none';}
	}

function check_register(){
	var error = '';
	em1 = document.getElementById('email1');
	if (em1 == null || em1.value == ''){alert('Please enter a valid email address'); return false;}
	var atpos=em1.value.indexOf("@");
	var dotpos=em1.value.lastIndexOf(".");
	if (atpos<1 || dotpos<atpos+2 || dotpos+2>=em1.value.length){ alert("Not a valid e-mail address"); return false;}
	em2 = document.getElementById('email2');
	if (em2 == null || em1.value != em2.value){alert('Email address do not match'); return false;}
	
	pw1 = document.getElementById('password1');
	pw2 = document.getElementById('password2');
	if (pw1 == null || pw1.value == ''){alert('Please enter a password'); return false;}
	if (pw1.value.length <= 5 || pw1.value.length >= 15){alert('Password must be between 5 and 15 characters'); return false;}
	if (pw2 == null || pw1.value != pw2.value){alert('Passwords do not match'); return false;}

	fn = document.getElementById('forename');
	if (fn == null || fn.value == ''){alert('Please enter a Forename'); return false;}
	if (fn.value.length > 30){alert('Forename must be less than 30 characters'); return false;}
	fn.value =  fn.value.replace(/[^a-zA-Z 0-9]+/g,'');

	sn = document.getElementById('surname');
	if (sn == null || sn.value == ''){alert('Please enter a Surname'); return false;}
	if (sn.value.length > 30){alert('Surname must be less than 30 characters'); return false;}
	sn.value =  sn.value.replace(/[^a-zA-Z 0-9]+/g,'');

	cm = document.getElementById('company');
	if (cm == null || cm.value == ''){alert('Please enter your company'); return false;}

	cs = document.getElementById('course');
	if (cs == null || cs.value == 'no'){alert('Please Select a course'); return false;}
	
	document.forms["new_user"].submit();
	}
