function getSelectedIndex(what) {
        oSel=document.getElementById(what);
        oOtherHidden=document.getElementById('sourceOtherSelected');
        oOtherBox=document.getElementById('source_specified_id');
        if(oSel.selectedIndex == (oSel.options.length - 1) ) {
                oOtherHidden.value=1;
                oOtherBox.style.display='block';
                oOtherBox.name='source_dropdown';
                oSel.name='source_inactive';
        } else {
                oOtherHidden.value=0;
                oOtherBox.style.display='none';
                oOtherBox.name='source_specified';
                oSel.name='source_dropdown';
        }
}

// Prepare to show a date picker linked to three select controls
function readLinked() {
    jQuery('#linkedDates').val(jQuery('#selectMonth').val() + '/' +
        jQuery('#selectDay').val() + '/' + jQuery('#selectYear').val());
    return {};
}

// Update three select controls to match a date picker selection
function updateLinked(date) {
    jQuery('#selectDay').val(date.substring(3, 5));
    jQuery('#selectMonth').val(date.substring(0, 2));
    jQuery('#selectYear').val(date.substring(6, 10));
}

// Prevent selection of invalid dates through the select controls
function checkLinkedDays() {
    var daysInMonth = 32 - new Date(jQuery('#selectYear').val(),
        jQuery('#selectMonth').val() - 1, 32).getDate();
    jQuery('#selectDay option').attr('disabled', '');
    jQuery('#selectDay option:gt(' + (daysInMonth - 1) +')').attr('disabled', 'disabled');
    if (jQuery('#selectDay').val() > daysInMonth) {
        jQuery('#selectDay').val(daysInMonth);
    }
}

// Prepare to show a date picker linked to three select controls
function readLinked2() {
    jQuery('#linkedDates2').val(jQuery('#selectMonth2').val() + '/' +
        jQuery('#selectDay2').val() + '/' + jQuery('#selectYear2').val());
    return {};
}

// Update three select controls to match a date picker selection
function updateLinked2(date) {
    jQuery('#selectDay2').val(date.substring(3, 5));
    jQuery('#selectMonth2').val(date.substring(0, 2));
    jQuery('#selectYear2').val(date.substring(6, 10));
}

// Prevent selection of invalid dates through the select controls
function checkLinkedDays2() {
    var daysInMonth = 32 - new Date(jQuery('#selectYear2').val(),
        jQuery('#selectMonth2').val() - 1, 32).getDate();
    jQuery('#selectDay2 option').attr('disabled', '');
    jQuery('#selectDay2 option:gt(' + (daysInMonth - 1) +')').attr('disabled', 'disabled');
    if (jQuery('#selectDay2').val() > daysInMonth) {
        jQuery('#selectDay2').val(daysInMonth);
    }
}


jQuery.metadata.setType("attr", "validate");

jQuery.noConflict();
jQuery(document).ready(function($){
//--------------------------

$("#linkedDates").datepicker({
    minDate: new Date(2010, 3 - 1, 1),
    maxDate: new Date(2013, 12 - 1, 31),
    //dateFormat: "dd/mm/yy",
    dateFormat: "mm/dd/yy",
    beforeShow: readLinked,
    onSelect: updateLinked,
    showOn: "both",
    buttonImage: "/resources/images/interface/datepicker/calendar.gif",
    buttonImageOnly: true
});
$("#selectMonth, #selectYear").change(checkLinkedDays);
$("#linkedDates2").datepicker({
    minDate: new Date(2010, 3 - 1, 1),
    maxDate: new Date(2013, 12 - 1, 31),
    //dateFormat: "dd/mm/yy",
    dateFormat: "mm/dd/yy",
    beforeShow: readLinked2,
    onSelect: updateLinked2,
    showOn: "both",
    buttonImage: "/resources/images/interface/datepicker/calendar.gif",
    buttonImageOnly: true
});
$("#selectMonth2, #selectYear2").change(checkLinkedDays2);

/*
$.validator.setDefaults({
    submitHandler: function() {
        //alert("Thank you!");
        $("#enquiriesForm input#isOK").val('1');
        $("#enquiriesForm").submit();
    }
});
*/

$("input").click(function() {
    $(this).select();
});

$("#event_type").change(function() {
    var value=$(this).val();
    if(value==$("#event_type option:last-child").val()) {
        $("#otherDiv").show();
        $("#otherDiv div").html('<input style="width:155px" type="text" name="other_event_type" id="other_event_type" value="'+$("#otherCell").attr("title")+'" class="txt required" onClick="this.select()" />');
    } else {
        $("#otherDiv").hide();
        $("#otherDiv div").html('');
    }
});

//show asterisks
var arr = [ "emailme", "callme", "postme" ];
jQuery.each(arr, function() {
    var chkbox = this;
    $("#"+chkbox+"_checkbox_id").click(function() {
        if(this.checked) {
            $("."+chkbox+"_required").after('<span class="'+chkbox+'_star" style="color:red">*</span>');
        } else {
            $("."+chkbox+"_star").replaceWith('');
        }
    })
});

$("#enquiriesForm").validate({
    rules: {
        event_type:     "required",
        timing:         "required",
        numbers:        "required",
        title:          "required",
        firstname:      "required",
        lastname:       "required",
        companyname:    "required",
        occasion:       "required",
        howtocontactyou: "required",
        email: {
            required: true,
            email: true
        },
        phone: {
            required: true
        },
        hearabout: {
            required: true
        },
        /*
        hearabout_specify: {
            required: true
        },
        */
        legal:         "required"
    },
    messages: {
        title:          "",
        firstname:      "X",
        lastname:       "X",
        email:          "X",
        event_type:     "X",
        timing:         "X",
        numbers:        "X",
        phone:          "X",
        hearabout:      "X",
        hearabout_specify:      "X",
        other:          "",
        companyname:    "X",
        legal:          "X",
        occasion:       "X",
        howtocontactyou: "X"
    }
    
});


//--------------------------
});
