var Registration = {
    isPreTeen:false,
    isTeenager:false,
    blankFieldErrorFlag:false,
    begin:function()
    {
        this.blankFieldErrorFlag=false;
        this.isPreTeen = false;
        this.isTeenager = false;
        // validate for empty fields
        var myVal = new Validate("registrationStep1Summary");
		myVal.isValidDate($("preMonth").value,$("preDay").value,$("preYear").value,"MDY","birthdateSpanError","Invalid Birthday.");
//		myVal.isEmpty("preFirstName","preFirstnameValidationError","Please enter a first name.");
//		myVal.isEmpty("preLastName","preLastnameValidationError","Please enter a last name.");
//		myVal.isEmpty("userComment","commentValidationError","Please enter a user comment.");
		if(!myVal.isValid())
		{
			myVal.yield(true);
			return;
		}
		
        // determine birthdate
        var month = $("preMonth").value;
        var day = $("preDay").value;
        var year = $("preYear").value;

        if(myVal.isPreTeen(month,day,year))
        {   
            // show stopper
            this.isPreTeen = true;
            Utility.swap("widgetRegistrationOptions","inelligibleAge");
            return;
        }
        if(myVal.isTeenager(month,day,year))
        {
            // flag it but proceed
			this.isTeenager = true;
        }
        // show next panel and carry over values
        Utility.swap("screen1","screen2");
        // pass along values
//        $("firstName").value = $("preFirstName").value;
//        $("lastName").value = $("preLastName").value;
        $("month").value = $("preMonth").value;
        $("day").value = $("preDay").value;
        $("year").value = $("preYear").value;
        $("month").disabled = true;
        $("day").disabled = true;
        $("year").disabled = true;
        if(this.isTeenager)
        {
            Utility.turnOn("parentEmailMandatory");
        }
        else
        {
            Utility.turnOff("parentEmailMandatory");
        }
        return;
    },
    submit:function()
    {
        myVal = new Validate("registrationStep2Summary");
		myVal.isEmpty("firstName","firstNameValidationSpan","First name is empty.");
		myVal.isEmpty("lastName","lastNameValidationSpan","Last name is empty.");
		myVal.isEmail("EmailAddressFinal","emailValidationSpan","Email is invalid.");
    myVal.isEmpty("desiredPassword","passwordValidationSpan","Password is empty.");
		myVal.isMatch("desiredPassword","desiredPasswordRepeat","passwordValidationSpan","Passwords do not match.");
		myVal.isReasonablePassword("desiredPassword","passwordValidationSpan","Password cannot contain punctuation and must be at least 5 characters.");
		myVal.isZipcode("zipCode","zipCodeValidationSpan","Invalid zipcode.");
		if(this.isTeenager)
        {
            myVal.isEmail("parentEmailAddress","parentEmailValidationSpan","Parent email is invalid");
        }
        if(myVal.isValid())
        {
            // start submission 
            var productID="";
            var curAction="";
            if(Dialog.productID!=null) { productID = Dialog.productID; }
            if(Dialog.curAction!=null) { curAction = Dialog.curAction; }
            var data =  "action=register" +
                        "&productID=" + productID +
                        "&commentOrigin=" + curAction +
                        "&firstName=" + $("firstName").value +
                        "&lastName=" + $("lastName").value +
                        "&emailAddress=" + $("EmailAddressFinal").value +
                        "&password=" + $("desiredPassword").value +
                        "&parentEmailAddress=" + $("parentEmailAddress").value +
                        "&mailingAddress=" + $("mailingAddress").value +
                        "&mailingCity=" + $("mailingCity").value + 
                        "&state=" + $("state").value +
                        "&userCountry=" + $("userCountry").value + 
                        "&userGender=" + $("userGender").value + 
                        "&childsBirthDate=" + $("childMonth").value + $("childDay").value + $("childYear").value + 
                        "&birthDate=" + $("preMonth").value + $("preDay").value + $("preYear").value + 
                        "&userComment=" + $("userComment").value +
                        "&zipcode=" + $("zipCode").value +
                        "&optin=" + $("optin").checked +
                        "&optinDisney=" +
                        "&status=";
//            $("register_button").disabled = true;
			Utility.turnOnInline("registrationResponsePanel");
            AjaxObject.startRequest("registerInline",data,"registrationResponsePanel");
            }
		else
		{
			myVal.yield(true);	
		}
    },
    registrationResultsSchema: {
            rowtag:"result_set" 
    },
    handleSuccess:function(o)
    {
        var loginResultXML = XML.parse(o.responseText);
        var xmlrows = loginResultXML.getElementsByTagName(this.registrationResultsSchema.rowtag);
        var xmlrow = xmlrows[0];
        var result = xmlrow.getElementsByTagName("result")[0];
        var error = xmlrow.getElementsByTagName("error")[0];
        var message = xmlrow.getElementsByTagName("message")[0];
        Utility.turnOff("registrationResponsePanel");
		if(error.firstChild.data == "false")
        {
            if(result.firstChild.data == "true")
            {
//                Utility.swap("registrationForm","finalScreen");
                Login.attempt('registration_inline');
                Utility.swap("screen2","screen1");
                Utility.swap("widgetInputContainer","widgetSubmitComment");
				Utility.turnOn("commentForm");
				$("commentValidationError").innerHTML = "REGISTRATION ACCEPTED - ENTER COMMENT TEXT BELOW";
            }
            else
            {
                document.getElementById("registrationStatusMessage").innerHTML = message.firstChild.data;
                document.getElementById("register_button").disabled = false;
            }
        }
    },
    closePanel:function()
    {
        alert("depricated");
        //YAHOO.generic.modal.win.hide();
    }
}