// JavaScript Document

	function checkPasswords(){
		password = $('newPassword');
        password2 = $('newPassword2');
        password_alert_span = $('password_alert');
        password_alert_text = document.createTextNode("Your passwords don't match.");

        if (password.value == password2.value){
			if (password_alert_span.firstChild != null){
            	rem = password_alert_span.firstChild;
                password_alert_span.removeChild(rem);
            }
            return "passmatch";
        }
        else{
        	if (password_alert_span.firstChild != null){
				
            	rem = password_alert_span.firstChild;
                password_alert_span.removeChild(rem);
            }
            password_alert_span.appendChild(password_alert_text);
            return 'passnomatch';
        }
        
    }
	
	
	
    
    function checkUserName(){
        user_name= $('user_name');
		if (navigator.appName=="Netscape"){
			user_name_alert = $('user_name_alert');
		}
      
        user_name_alert_text = document.createTextNode("That user name is not available.  Please choose another.");  
        new Ajax.Request(('/accounts/check_user_name?user_name='+$('user_name').value), {onSuccess: 
       		function(request){ 
				if(request.responseText=="in_use"){
					if (user_name_alert.firstChild != null){
              		 	user_name_alert.removeChild(user_name_alert.firstChild);
					}
                    user_name_alert.appendChild(user_name_alert_text);
					return "nogo"
                }
                else{
                	if (user_name_alert.firstChild != null){
            			rem = user_name_alert.firstChild;
              		 	user_name_alert.removeChild(rem);
            		}
					return "go"	
                }
             }});
    }
	
	
	
	
    
    function validateNewAccountForm(){
        if ($('first_name').value == ""){
       	 alert("Please enter your first name.")
       	 return false;
        }
		 if ($('last_name').value == ""){
       	 alert("Please enter your last name.")
       	 return false;
        }
		if ($('address').value == ""){
       	 alert("Please enter your address.")
       	 return false;
        }
		if ($('city').value == ""){
       	 alert("Please enter your city.")
       	 return false;
        }
		if ($('state').value == ""){
       	 alert("Please enter your state.")
       	 return false;
        }
		if ($('zip').value == ""){
       	 alert("Please enter your zip code.")
       	 return false;
        }
		if ($('phone').value == ""){
       	 alert("Please enter your phone number.")
       	 return false;
        }
		if ($('email').value == ""){
       	 alert("Please enter your email address.")
       	 return false;
        }
		if ($('userName').value == ""){
       	 alert("Please choose a user name.")
       	 return false;
        }

       	if ($('newPassword').value == ""){
       	 alert("Please choose a password.")
       	 return false;
        }

		if (checkPasswords() == "passnomatch"){
        	alert("The passwords you entered do not match.  Please fix this before proceeding.")
       	 return false;
        }       
		return true;	        
    }
	
	
