SupportForm = Class.create();

SupportForm.prototype = {

    form   : null,

    initialize : function(form)
    {
        this.form = $(form);
        this.form.observe('submit', this.onSubmit.bind(this));
        this.setFocus();
    },

    setFocus : function()
    {
     	if($('full_name').getValue().strip().empty()){
			$('full_name').focus();	
		}else if($('email').getValue().strip().empty()){
			$('email').focus();
		}else if($('subject').getValue().strip().empty()){
			$('subject').focus();
		}else if($('question').getValue().strip().empty()){
			$('question').focus();
		}
    },

    showAlert : function(val)
    {
        alert(val);
		this.setFocus();		
    },
	
	isEmail:function(v){
		return /^[a-z0-9,!\#\$%&'\*\+/=\?\^_`\{\|}~-]+(\.[a-z0-9,!#\$%&'\*\+/=\?\^_`\{\|}~-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,})/i.test(v);
	},
    onSubmit : function(e)
    {
        Event.stop(e);  
		var email = '';
		if($('sr').getValue().strip() == 0){
			alert("Please select a  Support Regarding.");
			$('sr').focus();
			return false;
		}				
		if($('full_name').getValue().strip().empty()){
			this.showAlert('Please enter a Full Name.');
			return false;
		}
		email = $('email').getValue().strip();
		if(email.empty()){
			this.showAlert('Please enter a email address.')
			return false;
		}
		
		if(!this.isEmail(email)){
			$('email').value = '';
			this.showAlert('Please enter a valid email address. For example johndoe@domain.com.')
			return false;
		}
		if($('subject').getValue().strip().empty()){
			this.showAlert('Please enter a Subject.');
			return false;
		}
		
		if($('question').getValue().strip().empty()){
			this.showAlert('Please enter a Question.');
			return false;
		}
		
		
		this.form.submit();
    }
};

