var dwDir = '/registration';
var title = new Array('LOGIN', 'FORGOT PASSWORD', 'FREE TRIAL / FREE ACCESS', 'ADMIN LOGIN', 'CHANGE PASSWORD');
var img = new Array('dwLogin.gif', 'dwForgot.gif', 'dwRegister.gif', 'dwLogin.gif', 'dwSubmit.gif');
var current_id = '';
var button_id = '';
var current_trial = '';
var xmlhttp = false;

function dwGetHTTPReq(url, destinationid)
{
	if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); }
	else if (window.ActiveXObject) { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
	if (xmlhttp)
	{
		xmlhttp.open("GET", url+'&sid='+Math.random(), true);
		xmlhttp.onreadystatechange = function()
		{
			if (xmlhttp.readyState==4)
			{
				if (xmlhttp.status==200) { $(destinationid).innerHTML = xmlhttp.responseText; }
				else { $(destinationid).innerHTML = 'Fail'; }
			}
		}
		if (window.XMLHttpRequest) { xmlhttp.send(null); }
		else if (window.ActiveXObject) { xmlhttp.send(); }
	}
}
function submitForm(index)
{
	var s = BASE_URL+dwDir+'/dwsubmit.php?';
	switch(index)
	{
		case '0':
			s += '&f=0';
			s += '&email='+encodeURI($('email').value);
			s += '&password='+encodeURI($('password').value);
			s += '&key='+encodeURI($('key').value);
			break;
		case '1':
			s += '&f=1';
			s += '&email='+encodeURI($('email').value);
			s += '&key='+encodeURI($('key').value);
			break
		case '2':
			s += '&f=2';
			s += '&email='+encodeURI($('email').value);
			s += '&password='+encodeURI($('password').value);
			s += '&AP='+(($('AP').checked==true) ? 'Yes' : '');
			s += '&PP='+(($('PP').checked==true) ? 'Yes' : '');
			s += '&CC='+(($('CC').checked==true) ? 'Yes' : '');
			s += '&CT='+(($('CT').checked==true) ? 'Yes' : '');
			s += '&key='+encodeURI($('key').value);
			break;
		case '3':
			s += '&f=3';
			s += '&email='+encodeURI($('email').value);
			s += '&password='+encodeURI($('password').value);
			s += '&key='+encodeURI($('key').value);
			break;
		case '4':
			s += '&f=4';
			s += '&email='+encodeURI($('email').value);
			s += '&old_password='+encodeURI($('old_password').value);
			s += '&new_password='+encodeURI($('new_password').value);
			s += '&key='+encodeURI($('key').value);
			break;
	}
	dwGetHTTPReq(s, 'myPop1_content')
	$('myPop1_button').alt = '';
	$('myPop1_button').style.display='none';
	button_id = '';
}
function dwWindowDimension()
{
	var intW = 0;
	var intH = 0;
	if(self.innerWidth)
	{
		intW = window.innerWidth;
		intH = window.innerHeight;
	} 
	else
	{
		if(document.documentElement && document.documentElement.clientWidth)
		{
			intW = document.documentElement.clientWidth -20;
			intH = document.documentElement.clientHeight -20;
		}
		else
		{
			if(document.body && document.body.clientWidth)
			{
				intW = document.body.clientWidth -20;
				intH = document.body.clientHeight -20;
			}
		}
	}
	var retVal = new Array(intW, intH);
	return retVal;
}
function changeOpac(opacityValue, id)
{
	var object = $(id).style;
	if(object)
	{
		object.opacity = (opacityValue / 100);
		object.MozOpacity = (opacityValue / 100);
		object.KhtmlOpacity = (opacityValue / 100);
		object.filter = "alpha(opacity=" + opacityValue + ")";
	}
}
function setOpac(id, millisec)
{
	var counter = 150;
	var speed = Math.round(millisec / 100);
	var timer = 0;
	var i;
	if(0 > counter)
	{
		for(i = 0; i >= counter; i--)
		{
			setTimeout("changeOpac(" + i + ",'" + id + "')", (timer * speed));
			timer++;
		}
	}
	else if(0 < counter)
	{
		for(i = 0; i <= counter; i++)
		{
			setTimeout("changeOpac(" + i + ",'" + id + "')", (timer * speed));
			timer++;
		}
	}
}
function setFocus()
{
	if($(current_id)) $(current_id).focus();
	current_id = '';
}
function hideError(container_id, shadow_id)
{
	if($(container_id))
	{
		$(container_id).style.left='-99999px';
		$(container_id).style.top='-99999px';
	}
}
function dwHidePopup(container_id, shadow_id)
{
	if($(container_id))
	{
		$(container_id).style.left='-99999px';
		$(container_id).style.top='-99999px';
	}
}
function clsHidePopup()
{
	with(this)
	{
		container.style.left='-99999px';
		container.style.top='-99999px';
	}
}
function reArrangePopup(obj, posY, index)
{
	with(obj)
	{
		var dim = new Array();
		dim = dwWindowDimension();
		if(index == '2')
		{
			height = 620;
		}
		else if(index == '4')
		{
			height = 360;
		}
		else
		{
			height = 300;
		}
		container.style.height=(height-40)+'px';
		$(id+'_content').style.height = (height-110)+'px';
	}
}
function setAutocompleteOff()
{
	if($('key'))
	{
		$('key').setAttribute('autocomplete', 'off');
	}
	else
	{
		setTimeout('setAutocompleteOff()', 10);
	}
}
function showError(posX, posY, errMsg)
{
	with(this)
	{
		//changeOpac(0, id);
		var dim = new Array();
		dim = dwWindowDimension();
		var dwcontent = '';
		var topadjustment = (navigator.userAgent.indexOf('MSIE')!=-1) ? document.body.style.marginTop : 0;
		var leftadjustment = (navigator.userAgent.indexOf('MSIE')!=-1) ? document.body.style.marginLeft : 0;
		var adjustment = document.body.style.margin + 2;

		switch(posX)
		{
			case 'center':
				container.style.left=((dim[0]-width)/2)+'px';
				break;
			case 'left':
				container.style.left='0';
				break;
			case 'right':
				container.style.left=(dim[0]-width-shadowWidth-adjustment)+'px';
				break;
		}
		switch(posY)
		{
			case 'center':
				container.style.top=((dim[1]-height)/2)+'px';
				break;
			case 'top':
				container.style.top='0';
				break;
			case 'bottom':
				container.style.top=(dim[1]-height-shadowWidth-adjustment)+'px';
				break;
		}
	
		$(id+'_title').innerHTML = 'MESSAGE';
		$(id+'_content').innerHTML = (errMsg == '') ? 'Error Message Here' : errMsg;
		//setOpac(id, 700);
	}
}
function showPopup(posX, posY, index)
{
	with(this)
	{
		//changeOpac(0, id);
		reArrangePopup(this, posY, index);
		
		var dim = new Array();
		dim = dwWindowDimension();
		var dwcontent = new Array('dwcontent.php?f=login', 'dwcontent.php?f=forgot', 'dwcontent.php?f=register&selected='+current_trial, 'dwcontent.php?f=adminlogin', 'dwcontent.php?f=change');
		var topadjustment = (navigator.userAgent.indexOf('MSIE')!=-1) ? document.body.style.marginTop : 0;
		var leftadjustment = (navigator.userAgent.indexOf('MSIE')!=-1) ? document.body.style.marginLeft : 0;
		var adjustment = document.body.style.margin + 2;

		switch(posX)
		{
			case 'center':
				container.style.left=((dim[0]-width)/2)+'px';
				break;
			case 'left':
				container.style.left='0';
				break;
			case 'right':
				container.style.left=(dim[0]-width-shadowWidth-adjustment)+'px';
				break;
		}
		switch(posY)
		{
			case 'center':
				container.style.top=((dim[1]-height)/2)+'px';
				break;
			case 'top':
				container.style.top='0';
				break;
			case 'bottom':
				container.style.top=(dim[1]-height-shadowWidth-adjustment)+'px';
				break;
		}
	
		$(id+'_title').innerHTML = title[index];
		$(id+'_button').src = BASE_URL+dwDir+'/images/'+img[index];
		$(id+'_button').style.display='inline';
		button_id = id+'_button';
		
		switch(index)
		{
			case '0':
				$(id+'_button').onclick = function() { return validateLogin(); }
				break;
			case '1':
				$(id+'_button').onclick = function() { return validatePasswordRequest(); }
				break;
			case '2':
				$(id+'_button').onclick = function() { return validateRegister(); }
				break;
			case '3':
				$(id+'_button').onclick = function() { return validateAdminLogin(); }
				break;
			case '4':
				$(id+'_button').onclick = function() { return validateChangePassword(); }
				break;
		}
		
		$(id+'_content').innerHTML = '<img style="margin-top: 10px; float: right" src="'+BASE_URL+dwDir+'/images/dwLoading.gif" alt="Loading ..." \/>';
		dwGetHTTPReq(BASE_URL+dwDir+'/'+dwcontent[index], id+'_content');
		setAutocompleteOff();
		//setOpac(id, 400);
	}
}
function dwPopup(id, width, height, shadowWidth)
{
	this.id = id;
	this.width = width;
	this.height = height;
	this.shadowWidth = shadowWidth;
	this.showPopup = showPopup;
	this.hidePopup = clsHidePopup;
	this.showError = showError;
	this.hideError = hideError;
	this.shadow = null;
	this.container = null;
	var buttonMargin = (navigator.userAgent.indexOf('MSIE')!=-1 && document.title == 'turnitinSafely.com') ? '-10px -50px -10px -10px' : '-10px';
	var s = '';
	s += '<b class="bBlock"><b class="b1"><\/b><b class="b2"><\/b><b class="b3"><\/b><b class="b4"><\/b><\/b><div class="bContent"><b class="b5"><\/b><div style="width:'+(width-50)+'px; margin: 0 auto; padding:20px!important; text-align: left;">';
	if(id.indexOf('Err')!==-1)
	{
		s += '<img src="'+BASE_URL+dwDir+'/images/dwClose2.gif" alt="Close" style="cursor:pointer; margin: -10px; float:right" onclick="dwHidePopup(\''+id+'\',\''+id+'_shadow\'); setFocus()" \/>';
		s += '<div id="'+id+'_title" class="dwTitle"><\/div>';
		s += '<div id="'+id+'_content" style="height:'+(height-110)+'px; margin: 0 auto;"><\/div>';
	}
	else
	{
		s += '<img id="closeBtn" src="'+BASE_URL+dwDir+'/images/dwClose.gif" alt="Close" style="cursor:pointer; margin: '+buttonMargin+'; float:right" onclick="dwHidePopup(\''+id+'\',\''+id+'_shadow\')" \/>';
		s += '<div id="'+id+'_title" class="dwTitle"><\/div>';
		s += '<div id="'+id+'_content" style="width:'+(width-50)+'px; height:'+(height-110)+'px; margin: 0 auto;"><\/div>';
		s += '<div style="margin: 0; height: 29px; position: relative;"><input type="image" id="'+id+'_button" class="dwButton" src="'+BASE_URL+dwDir+'/images/blank.gif" alt="" style="display: none" \/><\/div><div id="result" style="position: relative"><\/div>';
	}
	s += '<\/div><\/div><b class="bBlock"><b class="b4"><\/b><b class="b3"><\/b><b class="b2"><\/b><b class="b1"><\/b><\/b>';
	this.innerHTML = s;
	with(this)
	{
		container = document.createElement('DIV');
		container.setAttribute('id', id);
		container.className='dwPopup';
		container.style.padding='0';
		container.style.width=width+'px';
		container.style.backgroundColor='transparent';
		container.style.position='absolute';
		container.style.top='-99999px';
		container.style.left='-99999px';
		container.style.zIndex=100;
		container.style.textAlign='center';
		container.innerHTML=innerHTML;

		if(!$(id)) document.body.appendChild(container);
	}
}
function setRegTarget()
{
	var btn = $('closeBtn');
	btn.removeAttribute('onClick');
	btn.onclick = function() { window.open(BASE_URL+'/my_applications.html', '_self'); }
}
function setCurrentTrial(trial)
{
	current_trial = trial;
}
function phoneMask(id)
{
	var p = $(id).value;
	if(p.length == 3) { $(id).value=p+'-'; }
	else if(p.length == 7) { $(id).value=p+'-'; }
}
function validateLogin()
{
	var i;
	var j;
	var ch;
	var OK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
	var OKs = OK.split('');
	var email = $('email');
	var semail = email.value;
	var password = $('password');
	var pwd = password.value;
	var pwds = pwd.split('');
	
	if(email.value=='') { myErr1.showError('center', 'center', 'Please fill in your "Email Address".'); current_id = 'email'; email.focus(); return false; }
	if(semail.search(/@/) == -1) { myErr1.showError('center', 'center', 'There is an error in your "Email Address".'); current_id = 'email'; email.focus(); return false; }
	if(semail.search(/\./) == -1) { myErr1.showError('center', 'center', 'There is an error in your "Email Address".'); current_id = 'email'; email.focus(); return false; }
	var emailArray = semail.split('.');
	if(emailArray[1].length < 2) { myErr1.showError('center', 'center', 'There is an error in your "Email Address".'); current_id = 'email'; email.focus(); return false; }
	if(emailArray[2] != undefined) { if(emailArray[2].length < 2) { myErr1.showError('center', 'center', 'There is an error in your "Email Address".'); current_id = 'email'; email.focus(); return false; }}
	if(pwd == '')
	{
		myErr1.showError('center', 'center', 'Please fill in your "Password".'); current_id = 'password'; password.focus(); return false;
	}
	else
	{
		var allValid = true;
		for (i = 0;  i < pwds.length;  i++)
		{
			ch = pwds[i];
			for (j = 0;  j < OKs.length;  j++)
			{
				if (ch == OKs[j]) break;
				if (j == OKs.length - 1)
				{
					allValid = false;
					break;
				}
			}
		}
		if(!allValid)
		{
			myErr1.showError('center', 'center', 'Please fill in A-Z, a-z, 0-9 and underscore only.');
			password.value = pwd.substring(0, pwds.length - 1);
			current_id = 'password';
			password.focus();
			return false;
		}
	}
	var key = $('key');
	if(key.value=='')
	{
		myErr1.showError('center', 'center', 'Please enter "Turing Number".');
		current_id = 'key';
		key.focus();
		return false;
	}
	else if(key.value.length !== 5)
	{
		myErr1.showError('center', 'center', 'You enter a wrong "Turing Number".');
		current_id = 'key';
		key.focus();
		return false;
	}
	else if(key.value.indexOf(" ")!==-1)
	{
		myErr1.showError('center', 'center', 'You enter a wrong "Turing Number".');
		current_id = 'key';
		key.focus();
		return false;
	}
	$(button_id).src=BASE_URL+dwDir+'/images/dwLoading.gif';
	dwGetHTTPReq(BASE_URL+dwDir+'/captcha.php?validate='+key.value+'&f=0', 'result');
	return true;
}
function validateChangePassword()
{
	var i;
	var j;
	var ch;
	var OK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
	var OKs = OK.split('');
	var email = $('email');
	var semail = email.value;
	var password = $('old_password');
	var pwd = password.value;
	var pwds = pwd.split('');
	var password2 = $('new_password');
	var pwd2 = password2.value;
	var pwds2 = pwd2.split('');
	
	if(email.value=='') { myErr1.showError('center', 'center', 'Please fill in your "Email Address".'); current_id = 'email'; email.focus(); return false; }
	if(semail.search(/@/) == -1) { myErr1.showError('center', 'center', 'There is an error in your "Email Address".'); current_id = 'email'; email.focus(); return false; }
	if(semail.search(/\./) == -1) { myErr1.showError('center', 'center', 'There is an error in your "Email Address".'); current_id = 'email'; email.focus(); return false; }
	var emailArray = semail.split('.');
	if(emailArray[1].length < 2) { myErr1.showError('center', 'center', 'There is an error in your "Email Address".'); current_id = 'email'; email.focus(); return false; }
	if(emailArray[2] != undefined) { if(emailArray[2].length < 2) { myErr1.showError('center', 'center', 'There is an error in your "Email Address".'); current_id = 'email'; email.focus(); return false; }}
	if(pwd == '')
	{
		myErr1.showError('center', 'center', 'Please fill in your "Old Password".'); current_id = 'old_password'; password.focus(); return false;
	}
	else
	{
		var allValid = true;
		for (i = 0;  i < pwds.length;  i++)
		{
			ch = pwds[i];
			for (j = 0;  j < OKs.length;  j++)
			{
				if (ch == OKs[j]) break;
				if (j == OKs.length - 1)
				{
					allValid = false;
					break;
				}
			}
		}
		if(!allValid)
		{
			myErr1.showError('center', 'center', 'Please fill in A-Z, a-z, 0-9 and underscore only.');
			password.value = pwd.substring(0, pwds.length - 1);
			current_id = 'old_password';
			password.focus();
			return false;
		}
	}
	if(pwd2 == '')
	{
		myErr1.showError('center', 'center', 'Please fill in your "New Password".'); current_id = 'new_password'; password2.focus(); return false;
	}
	else
	{
		var allValid = true;
		for (i = 0;  i < pwds2.length;  i++)
		{
			ch = pwds2[i];
			for (j = 0;  j < OKs.length;  j++)
			{
				if (ch == OKs[j]) break;
				if (j == OKs.length - 1)
				{
					allValid = false;
					break;
				}
			}
		}
		if(!allValid)
		{
			myErr1.showError('center', 'center', 'Please fill in A-Z, a-z, 0-9 and underscore only.');
			password2.value = pwd.substring(0, pwds2.length - 1);
			current_id = 'new_password';
			password2.focus();
			return false;
		}
	}
	var key = $('key');
	if(key.value=='')
	{
		myErr1.showError('center', 'center', 'Please enter "Turing Number".');
		current_id = 'key';
		key.focus();
		return false;
	}
	else if(key.value.length !== 5)
	{
		myErr1.showError('center', 'center', 'You enter a wrong "Turing Number".');
		current_id = 'key';
		key.focus();
		return false;
	}
	else if(key.value.indexOf(" ")!==-1)
	{
		myErr1.showError('center', 'center', 'You enter a wrong "Turing Number".');
		current_id = 'key';
		key.focus();
		return false;
	}
	$(button_id).src=BASE_URL+dwDir+'/images/dwLoading.gif';
	dwGetHTTPReq(BASE_URL+dwDir+'/captcha.php?validate='+key.value+'&f=4', 'result');
	return true;
}
function validateAdminLogin()
{
	var i;
	var j;
	var ch;
	var OK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
	var OKs = OK.split('');
	var email = $('email');
	var semail = email.value;
	var password = $('password');
	var pwd = password.value;
	var pwds = pwd.split('');
	
	if(email.value=='') { myErr1.showError('center', 'center', 'Please fill in your "Email Address".'); current_id = 'email'; email.focus(); return false; }
	if(semail.search(/@/) == -1) { myErr1.showError('center', 'center', 'There is an error in your "Email Address".'); current_id = 'email'; email.focus(); return false; }
	if(semail.search(/\./) == -1) { myErr1.showError('center', 'center', 'There is an error in your "Email Address".'); current_id = 'email'; email.focus(); return false; }
	var emailArray = semail.split('.');
	if(emailArray[1].length < 2) { myErr1.showError('center', 'center', 'There is an error in your "Email Address".'); current_id = 'email'; email.focus(); return false; }
	if(emailArray[2] != undefined) { if(emailArray[2].length < 2) { myErr1.showError('center', 'center', 'There is an error in your "Email Address".'); current_id = 'email'; email.focus(); return false; }}
	if(pwd == '')
	{
		myErr1.showError('center', 'center', 'Please fill in your "Password".'); current_id = 'password'; password.focus(); return false;
	}
	else
	{
		var allValid = true;
		for (i = 0;  i < pwds.length;  i++)
		{
			ch = pwds[i];
			for (j = 0;  j < OKs.length;  j++)
			{
				if (ch == OKs[j]) break;
				if (j == OKs.length - 1)
				{
					allValid = false;
					break;
				}
			}
		}
		if(!allValid)
		{
			myErr1.showError('center', 'center', 'Please fill in A-Z, a-z, 0-9 and underscore only.');
			password.value = pwd.substring(0, pwds.length - 1);
			current_id = 'password';
			password.focus();
			return false;
		}
	}
	var key = $('key');
	if(key.value=='')
	{
		myErr1.showError('center', 'center', 'Please enter "Turing Number".');
		current_id = 'key';
		key.focus();
		return false;
	}
	else if(key.value.length !== 5)
	{
		myErr1.showError('center', 'center', 'You enter a wrong "Turing Number".');
		current_id = 'key';
		key.focus();
		return false;
	}
	else if(key.value.indexOf(" ")!==-1)
	{
		myErr1.showError('center', 'center', 'You enter a wrong "Turing Number".');
		current_id = 'key';
		key.focus();
		return false;
	}
	$(button_id).src=BASE_URL+dwDir+'/images/dwLoading.gif';
	dwGetHTTPReq(BASE_URL+dwDir+'/captcha.php?validate='+key.value+'&f=3', 'result');
	return true;
}
function validatePasswordRequest()
{
	var email = $('email');
	var semail = email.value;
	var key = $('key');
	
	if(email.value=='') { myErr1.showError('center', 'center', 'Please fill in your \"Email Address\".'); current_id = 'email'; email.focus(); return false; }
	if(semail.search(/@/) == -1) { myErr1.showError('center', 'center', 'There is an error in your \"Email Address\".'); current_id = 'email'; email.focus(); return false; }
	if(semail.search(/\./) == -1) { myErr1.showError('center', 'center', 'There is an error in your \"Email Address\".'); current_id = 'email'; email.focus(); return false; }
	var emailArray = semail.split('.');
	if(emailArray[1].length < 2) { myErr1.showError('center', 'center', 'There is an error in your \"Email Address\".'); current_id = 'email'; email.focus(); return false; }
	if(emailArray[2] != undefined) { if(emailArray[2].length < 2) { myErr1.showError('center', 'center', 'There is an error in your \"Email Address\".'); current_id = 'email'; email.focus(); return false; }}

	if(key.value=='')
	{
		myErr1.showError('center', 'center', 'Please enter "Turing Number".');
		current_id = 'key';
		key.focus();
		return false;
	}
	else if(key.value.length !== 5)
	{
		myErr1.showError('center', 'center', 'You enter a wrong "Turing Number".');
		current_id = 'key';
		key.focus();
		return false;
	}
	else if(key.value.indexOf(" ")!==-1)
	{
		myErr1.showError('center', 'center', 'You enter a wrong "Turing Number".');
		current_id = 'key';
		key.focus();
		return false;
	}
	$(button_id).src=BASE_URL+dwDir+'/images/dwLoading.gif';
	dwGetHTTPReq(BASE_URL+dwDir+'/captcha.php?validate='+key.value+'&f=1', 'result');
	return true;
}
function validateRegister()
{
	var i;
	var j;
	var ch;
	var OK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
	var OKs = OK.split('');
	var email = $('email');
	var semail = email.value;
	var password = $('password');
	var pwd = password.value;
	var pwds = pwd.split('');
	
	var agree = $('agree');
	var key = $('key');
	
	if(email.value=='') { myErr1.showError('center', 'center', 'Please fill in your \"Email Address\".'); current_id = 'email'; email.focus(); return false; }
	if(semail.search(/@/) == -1) { myErr1.showError('center', 'center', 'There is an error in your \"Email Address\".'); current_id = 'email'; email.focus(); return false; }
	if(semail.search(/\./) == -1) { myErr1.showError('center', 'center', 'There is an error in your \"Email Address\".'); current_id = 'email'; email.focus(); return false; }
	var emailArray = semail.split('.');
	if(emailArray[1].length < 2) { myErr1.showError('center', 'center', 'There is an error in your \"Email Address\".'); current_id = 'email'; email.focus(); return false; }
	if(emailArray[2] != undefined) { if(emailArray[2].length < 2) { myErr1.showError('center', 'center', 'There is an error in your \"Email Address\".'); current_id = 'email'; email.focus(); return false; }}
	if(pwd == '')
	{
		myErr1.showError('center', 'center', 'Please fill in your "Password".'); current_id = 'password'; password.focus(); return false;
	}
	else
	{
		var allValid = true;
		for (i = 0;  i < pwds.length;  i++)
		{
			ch = pwds[i];
			for (j = 0;  j < OKs.length;  j++)
			{
				if (ch == OKs[j]) break;
				if (j == OKs.length - 1)
				{
					allValid = false;
					break;
				}
			}
		}
		if(!allValid)
		{
			myErr1.showError('center', 'center', 'Please fill in A-Z, a-z, 0-9 and underscore only.');
			password.value = pwd.substring(0, pwds.length - 1);
			current_id = 'password';
			password.focus();
			return false;
		}
	}
	
	if(agree.checked == false) { myErr1.showError('center', 'center', 'Please check the box above the Register button if you agree to the terms.'); current_id = 'agree'; agree.focus(); return false; }
	if(key.value=='')
	{
		myErr1.showError('center', 'center', 'Please enter "Turing Number".');
		current_id = 'key';
		key.focus();
		return false;
	}
	else if(key.value.length !== 5)
	{
		myErr1.showError('center', 'center', 'You enter a wrong "Turing Number".');
		current_id = 'key'; 
		key.focus();
		return false;
	}
	else if(key.value.indexOf(" ")!==-1)
	{
		myErr1.showError('center', 'center', 'You enter a wrong "Turing Number".');
		current_id = 'key';
		key.focus();
		return false;
	}
	$(button_id).src=BASE_URL+dwDir+'/images/dwLoading.gif';
	dwGetHTTPReq(BASE_URL+dwDir+'/captcha.php?validate='+key.value+'&f=2', 'result');
	return true;
}
function wrongKey(num)
{
	myErr1.showError('center', 'center', 'You enter an "Invalid Turing Number".');
	current_id = 'key';
	$('key').focus();
	$('myPop1_button').style.display='inline';
	$('myPop1_button').src=BASE_URL+dwDir+'/images/'+img[num];
	return false;
}
function dwDoNothing()
{
	return true;
}
function preLoad()
{
	if(!$('preload2'))
	{
		var preload = document.createElement('DIV');
		preload.setAttribute('id', 'preload2');
		preload.style.position='absolute';
		preload.style.width='100px';
		preload.style.height='100px';
		preload.style.left='-99999px';
		preload.style.top='-99999px';
		document.body.appendChild(preload);
		var s = '';
		s += '<img src="'+BASE_URL+dwDir+'/images/dwLogin.gif" alt="Login" \/>';
		s += '<img src="'+BASE_URL+dwDir+'/images/dwForgot.gif" alt="Forgot" \/>';
		s += '<img src="'+BASE_URL+dwDir+'/images/dwRegister.gif" alt="Register" \/>';
		s += '<img src="'+BASE_URL+dwDir+'/images/dwSubmit.gif" alt="Register" \/>';
		s += '<img src="'+BASE_URL+dwDir+'/images/dwLoading.gif" alt="Loading ..." \/>';
		s += '<img src="'+BASE_URL+dwDir+'/images/blank.gif" alt="." \/>';
		preload.innerHTML=s;
	}
}
function addComponent()
{
	var csscomponent = 'dwpopup';
	var cssiecomponent = 'dwpopupie';
	var objHead = document.getElementsByTagName("head");
	if (objHead[0])
	{
		try {
			if (!$(csscomponent))
			{
				var objCSS = document.createElement("link");
				objHead[0].appendChild(objCSS);
				objCSS.setAttribute("id", csscomponent);
				objCSS.setAttribute("rel", "stylesheet");
				objCSS.setAttribute("href", BASE_URL+dwDir+'/'+csscomponent+'.css');
				objCSS.setAttribute("type", "text/css");
			}
			if (!$(cssiecomponent) && navigator.userAgent.indexOf('MSIE')!=-1)
			{
				var objCSS = document.createElement("link");
				objHead[0].appendChild(objCSS);
				objCSS.setAttribute("id", cssiecomponent);
				objCSS.setAttribute("rel", "stylesheet");
				objCSS.setAttribute("href", BASE_URL+dwDir+'/'+cssiecomponent+'.css');
				objCSS.setAttribute("type", "text/css");
			}
		}
		catch(e)
		{
			setTimeout("addComponent()", 10);
		}
	}
}
function reloadThis()
{
	location.href=location.href;
}
function sleepOneSecond(s)
{
	$('second').innerHTML = s;
	setSecond((s-1)*1000);
}
function setSecond(secs)
{
	var s = secs/1000;
	if(s === 0)
	{
		setTimeout("reloadThis()", 1000);
	}
	else
	{
		setTimeout("sleepOneSecond("+s+")", 1000);
	}
}
function reloadPage(secs)
{
	setSecond(secs);
}
function hideAllError()
{
	hideError('myErr1', 'myErr1_shadow');
	setFocus();
}
addComponent();
document.onfocus = hideAllError;
//window.onerror = dwDoNothing;