//--------------------------------------------------
// product page script

$(document).ready(function () {

    //--------------------------------------------------
    // Write


    if ($('#write').length > 0) {

        //--------------------------------------------------
        // Star ratings

        $('#write #rate').addClass('enabled');
        $('#write .rate input, #write .rate label span').addClass('offScreen');

        // Set hover state
        $('#write .rate label').hover(function () {
            $(this).toggleClass('hover');
        });

        // Set active state

        var ratings = [];
        $("#write .rate").each(function (i) {
            ratings[i] = $(this);
            $('label', ratings[i]).click(function () {
                $(ratings[i]).children().removeClass('active');
                $(this).addClass('active');
            });
        });

        if ($(this).is(":checked")) {
            $(this).next().addClass('active');
        }

    };

    var tabbed2 = "write";

    $('#reviewButton').click(function () {
        $("#" + tabbed2 + ' .tabControl').removeClass('selected')
        $('#tab_1').addClass('selected')
        $("#" + tabbed2 + ' .tab').hide();
        $("#" + tabbed2 + ' .tab:nth(1)').show();
    });

    $('#enquiryButton').click(function () {
        $("#" + tabbed2 + ' .tabControl').removeClass('selected')
        $('#tab_0').addClass('selected')
        $("#" + tabbed2 + ' .tab').hide();
        $("#" + tabbed2 + ' .tab:nth(0)').show();
    });

    // binds form submission and fields to the validation engine
    $("#formID").validationEngine({ promptPosition: "topLeft", scroll: false });
    $("#lForm").validationEngine({ promptPosition: "topLeft", scroll: false });
    $("#rForm").validationEngine({ promptPosition: "topLeft", scroll: false });
    $("#rlForm").validationEngine({ promptPosition: "topLeft", scroll: false });

});


function toggleDiv(id, flagit) {
    if (flagit == "1") {
        if (document.layers) document.layers['' + id + ''].style.display = "block"
        else if (document.all) document.all['' + id + ''].style.display = "block"
        else if (document.getElementById) document.getElementById('' + id + '').style.display = "block"
    }
    else
        if (flagit == "0") {
            if (document.layers) document.layers['' + id + ''].style.display = "none"
            else if (document.all) document.all['' + id + ''].style.display = "none"
            else if (document.getElementById) document.getElementById('' + id + '').style.display = "none"
        }
}
function checkcoun(countryID) {
    if (countryID == "" || countryID == null)
    { countryID = "0" }

    if (countryID == "126") {
        toggleDiv('commentForm', 1)
    }
    else {
        toggleDiv('commentForm', 0)
    }

}
function checkField(fieldID) {
    if (fieldID == "" || fieldID == null)
    { fieldID = "0" }

    if (fieldID == "31") {
        toggleDiv('fieldOtherDiv', 1)
    }
    else {
        toggleDiv('fieldOtherDiv', 0)
    }

}
function checkPos(posID) {
    if (posID == "" || posID == null)
    { posID = "0" }

    if (posID == "21") {
        toggleDiv('posOtherDiv', 1)
    }
    else {
        toggleDiv('posOtherDiv', 0)
    }

}
function checkDisc(discID) {
    if (discID == "" || discID == null)
    { discID = "0" }

    if (discID == "33") {
        toggleDiv('discOtherDiv', 1)
    }
    else {
        toggleDiv('discOtherDiv', 0)
    }

}
function initForm() {
    checkcoun(document.getElementById('countryID').value); checkPos(document.getElementById('positionID').value); checkDisc(document.getElementById('discID').value); checkField(document.getElementById('fieldID').value);
}
