jQuery.metadata.setType("attr", "validate");
jQuery.noConflict();
jQuery(document).ready(function($){
//$(document).ready(function() {
//--------------------------
setInterval("checkAnchor()", 300);

/*
$.validator.setDefaults({
    submitHandler: function() {
        //alert("Thank you!");
        $("#enquiriesForm input#isOK").val('1');
        $("#enquiriesForm").submit();
    }
});
*/

            //$("#step1A").hide();
            //$("#step1B").show();


$.validator.setDefaults({
    submitHandler: function() {
        if($("#goToInterests").val() == 1) {
            $("#step1A").hide();
            $("#step1B").show();
            $("#goToInterests").val('');
            //also change the mandatory text - update: not doing now
            //$("#rgclubMandatoryText").text('* Membership discounts apply');
            //alert("Thank you!");
        } else {
                        form.submit();
        }
    }
});

$("input").click(function() {
    $(this).select();
});

/*
$("#hearabout").change(function() {
    var value=$(this).val();
    if(value==$("#hearabout option:last-child").val()) {
        $("#otherRow").show();
        $("#otherCell").html('<input type="text" name="other" id="other" value="'+$("#otherCell").attr("title")+'" class="txt required" onClick="this.select()" />');
    } else {
        $("#otherRow").hide();
        $("#otherCell").html('');
    }
});
*/

$("#rg-appForm").validate({
    rules: {
        title:          "required",
        firstname:      "required",
        lastname:       "required",
        email: {
            required: true,
            email: true
        },
        phone: {
            required: true,
            minlength: 4
        },
        country: {
            required: true
        },
        postcode: {
            required: true,
            minlength: 3
        },
        address1: {
            required: true
        },
        city: {
            required: true
        },
        dob_date: {
            required: true
        },
        dob_month: {
            required: true
        },
        dob_year: {
            required: true
        },
        subscription: {
            required:   true
        }
        /*
        hearabout: {
            required: true
        },
        */
        //terms:          "required",
        //legal:          "required"
        
        //photo:          "required"
    },
    messages: {
        title:          "X",
        firstname:      "X",
        lastname:       "X",
        email:          "X",
        country:        "X",
        postcode:       "X",
        address1:       "X",
        city:           "X",
        phone:          "X",
        //legal:          "",
        //terms:          "",
        hearabout:      "X",
        dob_date:       "",
        dob_month:      "",
        dob_year:       "X",
        other:          ""
    }
    
});


//--------------------------
});

var currentAnchor = null;
//Function which chek if there are anchor changes, if there are, sends the ajax petition
function checkAnchor(){
    var hash = document.location.hash;
    if(currentAnchor != hash){
        currentAnchor = hash;
        jQuery(".pages").hide();
        if(!currentAnchor) {
            //jQuery("#default").show();
            //show first div
            jQuery(".pages:first").show();
        } else {
            jQuery(currentAnchor).show();
        }
    }
}


function ajaxFileUpload(what) {
    jQuery(".loading").hide();
    //jQuery("#loading-"+what)
    jQuery(".loading")
    .ajaxStart(function(){
        jQuery(this).show();
    })
    .ajaxComplete(function(){
        jQuery(this).hide();
    });

    jQuery.ajaxFileUpload
    (
        {
            url:'/ajax/ajaxfileupload.php?&el='+what,
            secureuri:false,
            fileElementId:what,
            dataType: 'json',
            success: function (data, status)
            {
                if(typeof(data.error) != 'undefined')
                {
                    if(data.error != '')
                    {
                        alert(data.error);
                    }else
                    {
                        alert(data.msg);
                        jQuery("#"+what+"__uploaded").val("1");
                    }
                }
            },
            error: function (data, status, e)
            {
                alert(e);
            }
        }
    )

    return false;
}

