jQuery.metadata.setType("attr", "validate");

jQuery.noConflict();

function doOther(what) {
    id='#'+what;
    var value=jQuery(id).val();
    if(value==jQuery(id+" option:last-child").val()) {
        jQuery(id+"_otherRow").show();
        jQuery(id+"_otherCell").html('<input type="text" name="'+what+'_other" id="'+what+'_other" value="'+jQuery(id+"_otherCell").attr("title")+'" class="txt required" onClick="this.select()" />');
    } else {
        jQuery(id+"_otherRow").hide();
        jQuery(id+"_otherCell").html('');
    }
}

function setSelect(oSelect,val) {
    found=false;
    otherPos=false;
    for(i=0;i<oSelect.options.length;i++) {
        //record where Other is
        if(oSelect.options[i].value=='Other') {
            otherPos=i;
        }
        if(oSelect.options[i].value==val) {
            oSelect.selectedIndex=i;
            found=true;
        }
    }
    //set to Other if there is a value and is not found
    if(val.length>0 && !found && otherPos) {
        oSelect.selectedIndex=otherPos;
    }
}

jQuery(document).ready(function($){
//--------------------------
/*
$.validator.setDefaults({
    submitHandler: function() {
        //alert("Thank you!");
        $("#enquiriesForm input#isOK").val('1');
        $("#enquiriesForm").submit();
    }
});
*/

$("input").click(function() {
    //$(this).select();
});

$("#hear").change(function() {
    doOther("hear");
});

$("#industry").change(function() {
    doOther("industry");
});

$("#regForm").validate({
    rules: {
        title:          "required",
        firstname:      "required",
        lastname:       "required",
        gender:         "required",
        day:            "required",
        month:          "required",
        year:           "required",
        jobTitle:           "required",
        industry:           "required",
        email: {
            required:   true,
            email: true
        },
        confirmemail: {
            required: true,
            equalTo: "#email"
        },
        pass: {
            required:   true,
            minlength:  6
        },
        confirmpass: {
            required: true,
            equalTo: "#pass"
        },
        /*
        mobile: {
            required: true
        },
        */

        hear: {
            required: true
        },
        
        hear_extra:     "required",

        country: {
            required: true
        },
        postcode: {
            required: true
        },
        address1: {
            required: true
        },
        city: {
            required: true
        },
        /*
        county: {
            required: true
        },
        */

        terms:         "required"
    },
    messages: {
        title:          "X",
        firstname:      "X",
        lastname:       "X",
        gender:         "X",
        day:            "X",
        month:          "X",
        year:           "X",
        jobTitle:       "X",
        industry:       "X",
        email: {
            required:          "X",
            email:      "<br />Emails must be like user@domain.com"
        },
        confirmemail:    {
            required:          "X",
            equalTo:            "<br />Emails do not match"
        },
        pass:   {
            required:          "X",
            minlength:          "<br />Password must be at least 6 characters"
        },
        confirmpass:    {
            required:          "X",
            equalTo:            "<br />Passwords do not match"
        },
        mobile:          "X",
        hear:      "X",
        country:        "X",
        postcode:       "X",
        address1:       "X",
        city:           "X",
        /*county:           "X",*/
        /*terms:          "",*/
        hear_other:     "X",
        hear_extra:     "X",
        industry_other: "X"
    }

});


//--------------------------
});

