function validatePresenceOf(title, value)
{ if (value.length < 1)
  { alert(title+" should not be blank.");
    return false; }
  else
    return true;
}

function validateSelectionOf(title, value)
{ if (!value)
  { alert("Please select a "+title+"." );
    return false; }
  return true;
}

function validateCheckOf(title, value)
{  if (!value) { 
		alert("Please check "+title+"." );
	    return false; } 
	return true;
}

function validateLengthOf(title, value, minLength)
{ if (value.length < minLength)
  { alert("The length of "+title+" should be at least "+minLength+" characters.");
    return false; }
  return true;
}

function validateConfirmationOf(title, value1, value2)
{if ( value1 != value2 )
  { alert( title+" does not match what you have typed earlier");
    return false; }
  return true;
}

function validate()
{ return (validateLengthOf("Full Name", $("account_user_name").value, 5) && 
          validatePresenceOf("Email", $("account_email").value) &&
		  validateConfirmationOf("Email", $("account_email").value, $("account_email_confirmation").value) && 
		  validatePresenceOf("Postal Code", $("account_zipcode").value) &&
		  validateLengthOf("Account Id", $("account_name").value, 5) && 
		  validateLengthOf("Password", $("account_user_password").value, 5) &&
		  validateConfirmationOf("Password", $("account_user_password").value, $("account_user_password_confirmation").value) && 
		  validateLengthOf("Company Name", $("account_company_name").value, 5) &&  
		  validateSelectionOf("Type of Retail Business", $("account_retailer_type_id").value) &&
		  validateCheckOf("I have read and agree to the Imonggo Terms of Service", $("account_eula").checked ) &&
		  confirm("Click Ok to create your free Imonggo account now. We will send an email to "+ $("account_email").value+" when your account is created.")
		 )
}

function toggleState()
{
	if ($("account_country").value == "US")  $("state_group").style.display = "";	    
	else $("state_group").style.display = "none";	
}

window.addEvent('domready', 
function() 
{	
	
	$('account_country').addEvent('change', function(e){
		toggleState();
	});

	$('signup_form').addEvent('submit', function(e) {
		if (!validate())
			e.stop();
	});
	
	
	toggleState();
			
} );		
