function changePreview(itemNumber) {
	document.getElementById('infotable2').style.display = 'none';
	document.getElementById('infotable5').style.display = 'none';
	document.getElementById('infotable6').style.display = 'none';
	document.getElementById('infotable7').style.display = 'none';
	document.getElementById('infotable8').style.display = 'none';
	document.getElementById('infotable' + itemNumber).style.display = '';
	tds = document.getElementById('infotable').getElementsByTagName('TD');
	for(i=0;i<tds.length;i++) {
		if(tds[i].className == 'active menu') tds[i].className = 'menu';
	}
}

function captcha(){
document.getElementById('captch').style.display='block';
document.getElementById('captcha_form').focus();
}

function error(){
document.getElementById('errormsg').style.display='block';
document.getElementById('user_name').focus();
}

function validateEmailAdd(){
	if(document.getElementById('txt_email').value.length >0) {
		if(document.getElementById('txt_email').value.match(/^\w+(['\.\-\+]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/) == null){
			alert('Not a valid email address');
			txt_email.focus();
		}
	}
}

function validate_required(field,alerttxt)
{
with (field)
  {
  if (value==null||value=="")
	{
    	document.getElementById('errormsg').style.display	= 'block';
	document.getElementById('errormsg').innerHTML = alerttxt;
	return false;
	}
  else
    return true;
  }
}

function check()
{
	if(document.getElementById('txt_password1').value != document.getElementById('txt_password2').value)
	{
	document.getElementById('errormsg').style.display	=	'block';
	document.getElementById('errormsg').innerHTML	=	'Password not match';
	return false;
	}
	else{
		document.getElementById('errormsg').style.display	=	'none';
		 return true;
}
}

function validate_form(thisform)
{
with (thisform)
  {
	if (validate_required(txt_user_name,"Username must be filled out!")==false)
  		{txt_user_name.focus();return false;}
	else if (validate_required(txt_password1,"Password must be filled out!")==false)
  		{txt_password1.focus();return false;}
	else if (validate_required(txt_password2,"Confirm Password!")==false)
  		{txt_password2.focus();return false;}
	else if (validate_required(txt_email,"Email must be filled out!")==false)
  		{txt_email.focus();return false;}
	else if (validate_required(captcha_form,"Text Verification missing!")==false)
  		{captcha_form.focus();return false;}
	else if (ch_tnc.checked != 1)
  		{alert("Terms And Conditions must be accepted!");
		ch_tnc.focus();return false;}
	else if (check()==false)
  		{txt_password2.focus();return false;}
	else{
		thisform.submit();}
  }
}

function validate_login(thisform)
{
with (thisform)
  {
	if (validate_required(txt_user_name,"Username must be filled out!")==false)
  		{txt_user_name.focus();return false;}
	else if (validate_required(txt_password,"Password must be filled out!")==false)
  		{txt_password.focus();return false;}
	else
		return true;
 }
}

function subtlg(thisform){
	if(validate_login(thisform) != false)
	thisform.submit();
}

function trim(str) {
    return str.replace(/^[\s!@$%^+*#\\=?&\.\/]*|[!@$%^*#=+?\\&\/\.\s]*$|\n|\r|[&\/=!@#$%^+&\\\.]|\s/g,"");
}

function chkusername(){
	document.getElementById('txt_user_name').value = trim(document.getElementById('txt_user_name').value);
}
