var emailSubmit = new Class({
            version: '1.0',

            defaultOptions: {
                formHandlerURL: 'http://ebm.cheetahmail.com/r/regf2',
                iframeId: 'registration'
            },

            initialize: function(options) {
                this.setOptions($merge(this.defaultOptions, options));
            },

            baseFormData: {
                'aid': '1385098083',
                'n': '1',
                'a': '1',
                'SOURCE': 'I'
            },

            isEmail: function(s) {
                //var isEmail_re       = /^\s*[\w\-\+_]+(\.[\w\-\+_]+)*\@[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*$/;
                //  +   this regexp maches weird addresses, such as: +SK++YLAMB@GMAIL+_.COM+
                var email_1_regexp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
                return String(s).search (email_1_regexp) != -1;
            },

            isNumber: function(s) {
                var isWhole_re       = /^\s*\d+\s*$/;
                return String(s).search (isWhole_re) != -1
            },

            showError: function(types){
                if (types.length == 0) {return;};
                var body = '<div id="qv_errors" style="background-color:white;"><h1>ERROR</h1><span id="custom-alert">';
                for (var i=0; i < types.length; i++) {
                    body+= types[i];
                    body+= '<br>';
                };
                body+='</span></div>';

                if (typeof errorPanel == 'undefined')
                {
                    errorPanel = new YAHOO.widget.Panel("error_panel", {
                        width:"350px",
                        fixedcenter: true,
                        constraintoviewport: true,
                        underlay:"none",
                        close:false,
                        visible:false,
                        underlay:"none",
                        draggable:false,
                        modal: true
                    });
                }

                errorPanel.setBody(body);

                errorPanel.render(document.getElementById('header'));
                errorPanel.show();

                var underlay = document.getElementById('error_panel_mask');
                if(underlay){
                    YAHOO.util.Event.addListener(underlay, "click", function(){errorPanel.hide();});
                }
            },

            submitForm: function(email, firstName, lastName, zip, birthMonth, birthDay, birthYear, cardholder, whichForm) {
                var types = new Array();
                if (!email || !firstName || email.match(/[\w\.\d]{3,250}\@[\w\.\d]{3,}/) == null){
                    if (!firstName){
                        types.push(nameAdventureError);
                    }
                    if (!email || email.match(/[\w\.\d]{3,250}\@[\w\.\d]{3,}/) == null){
                        types.push(emailAdventureError);
                    }
                    this.showError(types);
                    return;
                }
                if (!this.isEmail(email)) {
                    types.push(emailAdventureError);
                    this.showError(types);
                    return;
                }
                if (cardholder) cardholder = "y";

                if (birthMonth || birthDay){
                    if (!birthMonth || !birthDay){
                        alert("Please fill out all your birthday information.");
                        return;
                    }
                    if (birthMonth > 12 || !this.isNumber(birthMonth) || birthMonth.length < 2){
                        alert ("Your birthday month should be a number between 01 and 12.");
                        return;
                    }
                    if (birthDay > 31 || !this.isNumber(birthDay) || birthDay.length < 2){
                        alert ("Your birthday day should be a number between 01 and 31.");
                        return;
                    }

                }
                var data = {};
                var months = ['','January','February','March','April','May','June','July','August','September','October','November','December'];

                if(lastName || zip || birthMonth || birthDay || birthYear || cardholder) {
                    data = $merge({'email1': (email?email:""), 'email2': (email?email:""), 'FNAME': (firstName?firstName:""), 'LNAME': (lastName?lastName:""), 'ZIP': (zip?zip:""), 'BIRTH_MONTH': (birthMonth?months[parseInt(birthMonth)]:""), 'BIRTH_DAY': (birthDay?birthDay:""), 'BIRTH_YEAR': (birthYear?birthYear:""), 'CARDHOLDER': (cardholder?cardholder:"")}, this.baseFormData);

                    data.n = "2";
                }
                else {
                    data = $merge({'email': (email?email:""), 'FNAME': (firstName?firstName:"")}, this.baseFormData);
                }
                var sendMessage = function() {
                    scroll(0,0);
                    hide_selects();
                    msgViewPanel.show();
                }.bind(this);

                YAHOO.util.Event.removeListener(this.options.iframeId, "load");
                YAHOO.util.Event.addListener(this.options.iframeId, "load", sendMessage); 
                YAHOO.util.Dom.get(this.options.iframeId).src = this.options.formHandlerURL + "?" + Object.toQueryString(data);
                
                //old methods from mootols that got in conflict when somebody added jquery 
                //$(this.options.iframeId).removeEvent('load');
                //$(this.options.iframeId).addEvent('load', sendMessage);
                //$(this.options.iframeId).src = this.options.formHandlerURL + "?" + Object.toQueryString(data);
                
                //clean form
                if(whichForm == 'customer'){
                    document.getElementById('signup_first_name').value = "";
                    document.getElementById('signup_email').value = "";
                    document.getElementById('signup_last_name').value = "";
                    document.getElementById('signup_zip').value = "";
                    document.getElementById('signup_bday_month').value = "";
                    document.getElementById('signup_bday_day').value = "";
                    document.getElementById('signup_holder').checked = false;
                }
                else{
                    document.getElementById('first_name').value = "";
                    document.getElementById('email').value = "";
                }

            }
        });

        emailSubmit.implement(new Events, new Options);
