function register(options)
{
    var self = this;
    self.idSuffix = options["id"];
    self.travelCoachRoleID = "2";
    self.collegeCoachRoleID = "4";

    self.selector = "div#registerDiv" + self.idSuffix ;

    self.accountTypes = options["accountTypes"];

    self.init = function()
    {
       $(self.selector).ready(function(){

           $(self.selector).dialog({
                modal:true,
                autoOpen: false,
                width:590,
                buttons: {
                    "Close": function() {$(this).dialog("close");}
                    }
           });

           jQuery.validator.addMethod("hoster", function(value, element ) {
		var val = $(element).attr("retValue")
		
		return (typeof val != 'undefined' && val != null && val != "");
            }, "Select organization or create new one");

            jQuery.validator.addMethod("password_again", function(value, element ) {
		return value == $(self.selector + " div#firstStep input[name=password]").val();
            }, "Passowrd doesn't match");

            jQuery.validator.addMethod("email_again", function(value, element ) {
		return value == $(self.selector + " div#firstStep input[name=email]").val();
            }, "Emails doesn't match");

           $(self.selector + " #theForm").formwizard({
                //form wizard settings
                //inAnimation: '',
                historyEnabled : false,//true,
                formPluginEnabled: true,
                validationEnabled : true},
                {
                  //validation settings
                  errorPlacement: function(error, element) {
                     error.appendTo( element.parents("td").next("td") );
                   }
                },
                {
                  // form plugin settings
                  dataType: 'jsonp', //dataType: 'jsonp',
                  success: self.submitSuccessFake,
                  beforeSubmit: self.beforeSubmit
                }
              );

        });
    }

    self.open = function()
    {
        $(self.selector + " #theForm").formwizard("reset");
        $(self.selector + " select[name=roleID]").val($(self.selector + " select[name=roleID] option:first").val());
        self.roleSelectOnchnage();
        $(self.selector).dialog("open");
    }

    self.beforeSubmit = function(arr, $form, options)
    {       
        for(var i in arr)
        {
            switch(arr[i].name)
            {
                case "hosterID":
                    switch($(self.selector + " select[name=roleID]").val())
                    {
                        case self.travelCoachRoleID:
                            arr[i].value = $(self.selector + " div#organizationSelect input[name=hosterID]").attr("retValue");
                            break;
                        case self.collegeCoachRoleID:
                            arr[i].value = $(self.selector + " div#collegeSelect input[name=hosterID]").attr("retValue");;
                            break;
                    }                    
                    break;
            }
        }
    }

    self.submitSuccessFake = function()
    {}

    self.submitSuccess = function(data, status)
    {
        if(data && data.status == "success")
        {
            switch(data.step)
            {
                case "firstStep":
                     $(self.selector + " #theForm").formwizard("show",$(self.selector + " div#firstStep input.link").val());

                     $(self.selector + " #theForm div#payment input[name=b_email]").val($(self.selector + " #theForm div#firstStep input[name=email]").val());
                     $(self.selector + " #theForm div#payment input[name=b_first_name]").val($(self.selector + " #theForm div#firstStep input[name=firstName]").val());
                     $(self.selector + " #theForm div#payment input[name=b_last_name]").val($(self.selector + " #theForm div#firstStep input[name=lastName]").val());
                    break;                
                case "payment":
                    jAlert("Payment Successful, your subscription ID is " + data["subscriptionID"], "Message", self.finishRegistration);
                    break;
                case "accountTypeSelect":
                default:
                   self.finishRegistration();
                break;
            }
        }
        else
        {
            jAlert(data?data.message:"Error occured", "Error");
        }
    }

    self.finishRegistration = function()
    {
        $(self.selector).dialog("close");

        switch($(self.selector + " select[name=roleID]").val())
        {

            case self.travelCoachRoleID:
                jAlert("Thank you for registering with us. A message was sent to the e-mail address"+
                        "that you provided. Please check your e-mail now and follow the link that it"+
                        "contains for confirmation purposes. We need to make sure that you are indeed"+
                        "a travel coach and we will e-mail you when the PW Staff approves your"+
                        "account. Until then, if you are trying to register for an event, you will be"+
                        "able to login now using the e-mail and password that you provided to"+
                        "complete any event registration that you need.", "Message");
                break;
            case  self.collegeCoachRoleID:
               jAlert("Thank you for registering with us. A message was sent to the e-mail address"+
                       "that you provided. Please check your e-mail now and follow the link that it"+
                       "contains for confirmation purposes. We need to make sure that you are indeed"+
                       "a college coach and we will e-mail you when the PW Staff approves your"+
                       "account.", "Message");
               break;
            default:
                jAlert("Thank you for registering with us. A message was sent to the e-mail address"+
                        "that you provided. Please check your e-mail now and follow the link that it"+
                        "contains for confirmation purposes.", "Message");
            break;
        }
    }

    self.roleSelectOnchnage = function()
    {
        switch($(self.selector + " select[name=roleID]").val())
        {
            case self.travelCoachRoleID:
                $(self.selector + " div#firstStep input.link").val("organizationSelect");
                break;
            case self.collegeCoachRoleID:
                 $(self.selector + " div#firstStep input.link").val("collegeSelect");
                break;
            default:
                $(self.selector + " div#firstStep input.link").val("accountTypeSelect");
                break;
        }
    }

    self.onAccountTypeSelect = function(obj)
    {
        switch(obj.value.toString())
        {
            case "1": //Free
                $(self.selector + " div#accountTypeSelect input.link").val("lastStep");
                $(self.selector + " div#accountTypeSelect").addClass("submit_step");
                $(self.selector + " #theForm").formwizard("show","#accountTypeSelect");
                break;
            case "2": //Silver
                $(self.selector + " div#accountTypeSelect input.link").val("payment");
                $(self.selector + " div#accountTypeSelect").removeClass("submit_step");
                $(self.selector + " #theForm").formwizard("show","#accountTypeSelect");
                
                $(self.selector + " div#payment select[name=subscription_interval]").html(
                    "<option value='1'>$" + self.accountTypes[2].month_price + "/month</option>"+
                    "<option value='12'>$" + self.accountTypes[2].year_price + "/year</option>");
                break;
            case "3": //Gold
                $(self.selector + " div#accountTypeSelect input.link").val("payment");
                $(self.selector + " div#accountTypeSelect").removeClass("submit_step");
                $(self.selector + " #theForm").formwizard("show","#accountTypeSelect");

                $(self.selector + " div#payment select[name=subscription_interval]").html(
                    "<option value='1'>$" + self.accountTypes[3].month_price + "/month</option>"+
                    "<option value='12'>$" + self.accountTypes[3].year_price + "/year</option>");
                break;
            default: //Free
                $(self.selector + " div#accountTypeSelect input.link").val("lastStep");
                $(self.selector + " div#accountTypeSelect").removeClass("submit_step");
                $(self.selector + " #theForm").formwizard("show","#accountTypeSelect");

                $(self.selector + " div#payment span[id=price]").text("");
                break;
        }
    }

    self.setValues = function(data)
    {
        fillForm(self.selector + " div#firstStep input", data);
    }


    self.init();
}
