// register

$(document).ready( init_register );
function init_register() { 
	//$("#field_account_type").hover(function(){ $("#w_hint_account_type").fadeIn('normal');  },function(){ $("#w_hint_account_type").fadeOut('normal'); }); 
	if ($("#account_type").val()=='buyer') { $("#territory1, #territory2, #territory3").show(); } 
}
function check_form() {
	var error_msg = '';
	if (!$("#email").attr('value')) { error_msg += ' - please enter E-mail Address\n'; $("#email").focus(); } else {  if (!check_email( $('#email').attr('value'))) {	error_msg += ' - E-mail Address does not seem to be real\n'; $("#email").focus(); } }
	if ($("#email").attr('value')!=$("#remail").attr('value')) { if (!error_msg) { $("#remail").focus(); } error_msg += ' - E-mail Addresses do not match\n'; }
	if ($("#password").attr('value').length<8) { if (!error_msg) { $("#password").focus(); } error_msg += ' - please enter your new Password\n'; }
	if ($("#password").attr('value')!=$("#rpassword").attr('value')) { if (!error_msg) { $("#rpassword").focus(); } error_msg += ' - Passwords do not match\n'; }
	if (!$("#first_name").attr('value')) { if (!error_msg) { $("#first_name").focus(); } error_msg += ' - please enter First Name\n'; }
	if (!$("#last_name").attr('value')) { if (!error_msg) { $("#last_name").focus(); } error_msg += ' - please enter Last Name\n'; }
	if ($("#account_type").attr('value')=='buyer') {
		if (!$("#company").attr('value')) { if (!error_msg) { $("#company").focus(); } error_msg += ' - please enter Company Name\n'; }
		if ($("#territory").val()=='0') { if (!error_msg) { $("#territory").focus(); } error_msg += ' - please enter Territory you are buying for\n'; }
	}
	if (!$("#address").attr('value')) { if (!error_msg) { $("#address").focus(); } error_msg += ' - please enter Address\n'; }
	if (!$("#city").attr('value')) { if (!error_msg) { $("#city").focus(); } error_msg += ' - please enter City\n'; }
	if ($("#country").val()=='224'&&$("#state").val()=='0') { if (!error_msg) { $("#state").focus(); } error_msg += ' - please choose State\n'; }
	if (!$("#zip").attr('value')) { if (!error_msg) { $("#zip").focus(); } error_msg += ' - please enter Zip/Postal Code\n'; }
	if ($("#country").val()=='0') { if (!error_msg) { $("#country").focus(); } error_msg += ' - please choose Country\n'; }
	if (!$("#phone").attr('value')) { if (!error_msg) { $("#phone").focus(); } error_msg += ' - please enter Phone number\n'; }
	if ( error_msg ) { alert('Following errors occured: \n' + error_msg); } else { return true; }
	return false;
}
function _account_type_change() { if ($("#account_type").val()=='buyer') { $("#territory1, #territory2, #territory3").show(); } else { $("#territory1, #territory2, #territory3").hide(); } }