function msgBox(_obj,_msg) {	
	$('#msgbox').append(_msg);
	
	var _pos = $(_obj).offset();
	$('#msgbox').css('top',_pos.top);
	$('#msgbox').css('left',_pos.left+($(_obj).width() / 2));
	
	$('#msgbox').fadeIn("slow");
}

function alertMsg(obj,msg) {
	alert(msg);
	try {
		obj.focus();
	} catch(e) {}
}

function checkUsername(obj) {
	var _val = obj.value;
	if (_val == '') {
		alert('Username is required..');
		return;
	}
	
	$.ajax({
		url: "/verify.php",
		data:"val="+_val,
		async: false,
		success: function(html){
			if (html == 1) {
				alertMsg(obj,'it has been registered');
			} else {
				alertMsg(obj,'it can be registered');
			}
		}
	});
}

function checkRegform(theform) {	
	if (theform['firstname'].value == '') {
		alertMsg(theform['firstname'],'First name is required');
		return false;
	}
	
	if (theform['lastname'].value == '') {
		alertMsg(theform['lastname'],'Last name is required');
		return false;
	}
	
	if (theform['abn_no'].value == '') {
		alertMsg(theform['abn_no'],'ABN NO is required');
		return false;
	}
	
	var _pat = /^([\w\.-]{1,31})@([\w-]+(\.[\w-]+)+)$/;
	if (!_pat.test(theform['email'].value)) {
		alertMsg(theform['email'],'Email is wrong');
		return false;
	}
	
	if (theform['phone'].value == '') {
		alertMsg(theform['phone'],'Daytime phone number is required');
		return false;
	}
	if (theform['address'].value == '') {
		alertMsg(theform['address'],'Address is required');
		return false;
	}
	
	if (theform['country'].value == '') {
		alertMsg(theform['country'],'Country is required');
		return false;
	}
	
	if (theform['city'].value == '') {
		alertMsg(theform['city'],'City is required');
		return false;
	}
	
	if (theform['state'].value == '') {
		alertMsg(theform['state'],'State is required');
		return false;
	}
	
	if (theform['country'].value == '') {
		alertMsg(theform['country'],'Please select your country');
		return false;
	}
	
	if (theform['zip'].value == '') {
		alertMsg(theform['zip'],'Zip is required');
		return false;
	}
	
	var _pat2 = /^[a-zA-Z0-9][\w\-\.]{3,31}$/;
	if (!_pat2.test(theform['username'].value)) {
		alertMsg(theform['username'],'Username is wrong');
		return false;
	}
	
	
	
	var _pat3 = /^.{4,}$/;
	if (!_pat2.test(theform['password'].value)) {
		alertMsg(theform['password'],'Password is wrong');
		return false;
	}
	
	if (theform['password'].value != theform['password_cfm'].value) {
		alertMsg(theform['password_cfm'],'Verify Password is wrong');
		return false;
	}
	
	return true;
}