function SignupValidateData(objForm)
{
    if (Plugin_PreProcessForm(objForm))
    {
        if (!fSignupReadOnly)
        {
            var fRequired; 

            if ((objForm.Name != null) && (GetAttribute(objForm.Name, SIGNUP_SECTION_OPTION_Include) == "1"))
            {
                fRequired = GetAttribute(objForm.Name, SIGNUP_SECTION_OPTION_Required) == "1";
                CheckFLName(objForm.Name, !fRequired, "Name");
            }
            
            if ((objForm.FName != null) && (GetAttribute(objForm.FName, SIGNUP_SECTION_OPTION_Include) == "1"))
            {
                fRequired = GetAttribute(objForm.FName, SIGNUP_SECTION_OPTION_Required) == "1";
                CheckFLName(objForm.FName, !fRequired, "First Name");
                CheckFLName(objForm.LName, !fRequired, "Last Name");
            }
                        
            if ((objForm.Email != null) && (GetAttribute(objForm.Email, SIGNUP_SECTION_OPTION_Include) == "1"))
            {
                fRequired = GetAttribute(objForm.Email, SIGNUP_SECTION_OPTION_Required) == "1";
                if (CheckEmailValue(objForm.Email, !fRequired))
                    AddError("Email name is invalid");
            }
            
            if ((objForm.Phone1 != null) && (GetAttribute(objForm.Phone1, SIGNUP_SECTION_OPTION_Include) == "1"))
            { 
                fRequired = GetAttribute(objForm.Phone1, SIGNUP_SECTION_OPTION_Required);
                CheckStringValueMMEx(objForm.Phone1, fRequired, true, "Phone");
                CheckStringValueMM(objForm.Fax, fRequired, true);        
            }
                    
            if ((objForm.Company != null) && (GetAttribute(objForm.Company, SIGNUP_SECTION_OPTION_Include) == "1"))
            {
                fRequired = GetAttribute(objForm.Company, SIGNUP_SECTION_OPTION_Required);
                CheckStringValueMM(objForm.Company, fRequired, true);    
            }            
            
            if ((objForm.Address1 != null) && (GetAttribute(objForm.Address1, SIGNUP_SECTION_OPTION_Include) == "1"))
            {
                fRequired = GetAttribute(objForm.Address1, SIGNUP_SECTION_OPTION_Required) == "1";
                
                var fAddr1 = CheckStringValueMM(objForm.Address1, 0, true);
                var fAddr2 = CheckStringValueMM(objForm.Address2, 0, true);
                
                // Need at least 1 address field
                if (fRequired && (objForm.Address1.value == "") && (objForm.Address2.value == ""))
                {
                    SetClassName(objForm.Address1, false, false, true);
                    SetClassName(objForm.Address2, false, false, true);
                    AddError("Enter Address1 and/or Address2");
                }
                
                CheckStringValueMM(objForm.City, fRequired ? 1 : 0, true);
                CheckStringValueMM(objForm.Zip, fRequired ? 1 : 0, true);
                ValidateStateAndCountry(objForm, fRequired);
            }
            
            if ((objForm.ZipCode != null) && (GetAttribute(objForm.ZipCode, SIGNUP_SECTION_OPTION_Include) == "1"))
            {
                fRequired = GetAttribute(objForm.ZipCode, SIGNUP_SECTION_OPTION_Required) == "1";
                CheckStringValueMMEx(objForm.ZipCode, fRequired, true, "Zip Code");
            }

            if (objForm.Password != null)
            {
                if (GetAttribute(objForm.Password, SIGNUP_SECTION_OPTION_Include) == "1")
                {
                    Address_ValidatePassword(objForm);
                }
                else if (CheckStringValueMMEx(objForm.Password, 1, true, "Password"))
                {
                    AddError("Invalid Password");
                }
            }
            if ((objForm.BirthdayM != null) && (GetAttribute(objForm.BirthdayM, SIGNUP_SECTION_OPTION_Include) == "1"))
            {
                Address_ValidateBirthday(objForm);
            }
            
            Customize_CheckSelection();
        }            
    }
    
    return Plugin_SubmitForm();
}

function Signup_ShowSection(sSection, fShow)
{
    var i = 0;
    var objTR = objTR = document.getElementById("tr_" + sSection + i);
    
    if (objTR != null)
    {
        while (objTR = document.getElementById("tr_" + sSection + i++))
        {
            objTR.style.display = fShow ? "" : "none";
        }
    }
    else
    {
        objTR = document.getElementById("Signup-section-" + sSection);
        if (objTR != null)
            objTR.style.display = fShow ? "" : "none";
    }        
}

function Signup_SetControlAttributes(sSection, sOption, sValue)
{
    switch(sSection)
    {
        case SIGNUP_SECTION_Name1:
        {
            frmSignup.Name[sOption] = sValue;
            break;
        }
    
        case SIGNUP_SECTION_Name:
        {
            frmSignup.FName[sOption] = sValue;
            frmSignup.LName[sOption] = sValue;
            break;
        }

        case SIGNUP_SECTION_Email:
        {
            frmSignup.Email[sOption] = sValue;
            break;
        }
        
        case SIGNUP_SECTION_Phone:
        {
            frmSignup.Phone1[sOption] = sValue;
            frmSignup.Fax[sOption]    = sValue;
            break;
        }

        case SIGNUP_SECTION_Company:
        {
            frmSignup.Company[sOption] = sValue;
            break;
        }

        case SIGNUP_SECTION_Address:
        {
            frmSignup.Address1[sOption]  = sValue;
            frmSignup.Address2[sOption]  = sValue;
            frmSignup.City[sOption]      = sValue;
            frmSignup.StateID[sOption]   = sValue;
            frmSignup.Zip[sOption]       = sValue;
            frmSignup.CountryID[sOption] = sValue;
            break;
        }
        
        case SIGNUP_SECTION_ZipCode:
        {
            frmSignup.ZipCode[sOption] = sValue;
            break;
        }        
        
        case SIGNUP_SECTION_Birthday:
        {
            frmSignup.BirthdayM[sOption] = sValue;
            frmSignup.BirthdayD[sOption] = sValue;
            frmSignup.BirthdayY[sOption] = sValue;
            break;
        }        

        case SIGNUP_SECTION_Password:
        {
            frmSignup.Password[sOption]  = sValue;
            frmSignup.VPassword[sOption] = sValue;
            break;
        }        
    }            
}

function Signup_DoFieldOnClick(obj)
{
    var sSection = GetAttribute(obj, "Section");
    var objI     = Plugin_GetControl("Include_"  + sSection);
    var objR     = Plugin_GetControl("Required_" + sSection);
    
    if (obj == objR)
    {
        if (obj.checked)
            objI.checked = true;
    }
    else
    {
        if (!obj.checked && (sSection != "Password"))
            objR.checked = false;
    }
}

function Signup_OnFieldOption(obj)
{
    Signup_DoFieldOnClick(obj);
    
    var sSection = GetAttribute(obj, "Section");
    
    if (obj.checked)
    {
        var fChecked = false;
        
        obj = null;
        
        switch (sSection)
        {
            case SIGNUP_SECTION_Name1:
                obj = Plugin_GetControl("Include_" + SIGNUP_SECTION_Name);
                break;

            case SIGNUP_SECTION_Name:
                obj = Plugin_GetControl("Include_" + SIGNUP_SECTION_Name1);
                break;

            case SIGNUP_SECTION_Address:
                obj = Plugin_GetControl("Include_" + SIGNUP_SECTION_ZipCode);
                break;

            case SIGNUP_SECTION_ZipCode:
                obj = Plugin_GetControl("Include_" + SIGNUP_SECTION_Address);
                break;

            case SIGNUP_SECTION_Password:
                obj = Plugin_GetControl("Include_"  + SIGNUP_SECTION_Email);
                obj.disabled = true;
                obj = Plugin_GetControl("Required_"  + SIGNUP_SECTION_Email);
                obj.disabled = true;
                fChecked     = true;
                break;
        }
        
        if (obj != null)
        {
            obj.checked = fChecked;
            Signup_DoFieldOnClick(obj);
        }            
    }        
    else if (sSection == SIGNUP_SECTION_Password)
    {
        obj = Plugin_GetControl("Include_"  + SIGNUP_SECTION_Email);
        obj.disabled = false;
        obj = Plugin_GetControl("Required_"  + SIGNUP_SECTION_Email);
        obj.disabled = false;
    }
}

function Signup_Update(obj, fPreviewing)
{
    var sAttributes = GetAttribute(obj, "pAttributes");

    Plugin_Update(sAttributes, fPreviewing, false);
        
    //Plugin_ShowCaptionEx(sAttributes);
    //Plugin_ShowGroupsEx(sAttributes);
    //Plugin_SetSizeEx(sAttributes);
 
    if (sAttributes != "")
    {
        var rSections = sAttributes.split(';');
        var iSection;
        
        for (iSection = 0; iSection < rSections.length; iSection++)
        {
            var rSection = rSections[iSection].split(':');
            
            if (rSection[0] != SECTION_FORM)
            {
                var rOptions = rSection[1].split(',');
                var iOption;
            
                for (iOption = 0; iOption < rOptions.length; iOption++)
                {
                    var rOption = rOptions[iOption].split('=');
                    
                    if (fPreviewing)
                    {
                        Signup_SetControlAttributes(rSection[0], rOption[0], rOption[1]);
                    }
                    else
                    {
                        var objOption = Plugin_GetControl(rOption[0] + "_" + rSection[0]);
                        
                        if (objOption != null)
                        {
                            objOption.checked = rOption[1] == "1";
                        }
                    }                    
                    
                    if (rOption[0] == SIGNUP_SECTION_OPTION_Include)
                        Signup_ShowSection(rSection[0], rOption[1] == "1");
                }                              
            }                
        }
    }        
}

function Signup_GetAttributes()
{
    var sAttributes = Plugin_GetFormAttributes();
    var iSection;

    for (iSection = 0; iSection < rSIGNUP_SECTION.length; iSection++)
    {
        if (sAttributes != "")
            sAttributes += ";";
        sAttributes += rSIGNUP_SECTION[iSection][1] + ":";

        var iOption;
        var sOptions = "";
        
        for (iOption = 0; iOption < rSIGNUP_SECTION_OPTION.length; iOption++)
        {
            var objOption = Plugin_GetControl(rSIGNUP_SECTION_OPTION[iOption][1] + "_" + rSIGNUP_SECTION[iSection][1]);
            
            if (sOptions != "")
                sOptions += ",";
            sOptions += rSIGNUP_SECTION_OPTION[iOption][1] + "=" + (objOption.checked ? 1 : 0);
        }
        
        sAttributes += sOptions;
    }

    return sAttributes;
}

try
{
    if (fSignupInitSections)
        WindowOnload(signup_window_onload);
}
catch(e)
{
}

function signup_window_onload()
{
    Signup_ShowSection(SIGNUP_SECTION_Name1,    false);
    Signup_ShowSection(SIGNUP_SECTION_ZipCode,  false);
    Signup_ShowSection(SIGNUP_SECTION_Birthday, false);
    Signup_ShowSection(SIGNUP_SECTION_Password, false);
}