function err(msg){
//    document.getElementById('msg').innerHTML = new String(msg);
	alert(msg);
	return false;
}

function login1(form)
{
	var username=new String(form.username.value);
	var pw=new String(form.password.value);
	if(username.length==0)
	    return err("you must enter username");
	else{
		for(i=0;i<username.length;i++)
			if((username.charCodeAt(i)>='a'.charCodeAt(0) && username.charCodeAt(i)<='z'.charCodeAt(0)) || (username.charCodeAt(i)>='0'.charCodeAt(0) && username.charCodeAt(i)<='9'.charCodeAt(0)) || username.charCodeAt(i)=='_'.charCodeAt(0)){ 
			}else
			    return err("invalid username");
	}
	if(pw.length == 0)
	    return err("Please insert your password");
	else if (pw.length > 8)
	    return err("Your password musn't be greater than 8 characters");
	else if (pw.length < 6)
	    return err("Your password must be at least 6 characters");
	return true;
}	 
//----------------------------------used in register.php --------------------
function isValidPasswd(pw){
  if(pw.length == 0)
    return err("Please choose a password.");
  else if (pw.length > 12)
    return err("Your password must be no greater than 8 characters.");
  else if (pw.length < 6)
    return err("Your password must be at least 6 characters.");
  return true;
}

function register1(form)
{
	var username=new String(form.username.value);
//	var company=new String(form.company.value);
//	var position=new String(form.position.value);	
	var email=new String(form.email.value);
	var pw=new String(form.password.value);
	var cpw=new String(form.cpassword.value);
//	var spamkey=new String(form.spamkey.value);	
	if(username.length==0) return err("you must enter username");
	if(email.length==0) return err("you must enter your email address");
//	if(company.length==0) return err("you must enter your company");
//	if(position.length==0) return err("you must enter your position");
	if(isValidPasswd(pw)){
		if(pw.length==cpw.length){
			for(i=0;i<pw.length;i++)
				if(pw.charCodeAt(i)!=cpw.charCodeAt(i))
					return err("password and confirm password don't match");
		}else return err("password and confirm password don't match");
//		if(spamkey.length==0) return err("you must enter the key displayed on image");
	}else
		return false;
	return true;
}

function new_pass1(form)
{
	var opw=new String(form.opassword.value);
	var pw=new String(form.password.value);
	var cpw=new String(form.cpassword.value);
//	var spamkey=new String(form.spamkey.value);	
	if(opw.length==0) return err("enter your old password");
//	if(company.length==0) return err("you must enter your company");
//	if(position.length==0) return err("you must enter your position");
	if(isValidPasswd(pw)){
		if(pw.length==cpw.length){
			for(i=0;i<pw.length;i++)
				if(pw.charCodeAt(i)!=cpw.charCodeAt(i))
					return err("password and confirm password don't match");
		}else return err("password and confirm password don't match");
//		if(spamkey.length==0) return err("you must enter the key displayed on image");
	}else
		return false;
	return true;
}

