
$j(document).ready(function() {
    // hides the div as soon as the DOM is ready
    // (a little sooner than page load)
    $j('#ring1').hide();
    var r1viz = 0;
    $j('#ring2').hide();
    var r2viz = 0;
    $j('#ring3').hide();
    var r3viz = 0;
    $j('#gems').hide();
    var gemsviz = 0;
    $j('#Diamonds').show();
    $j('#Sapphires').hide();
    $j('#FancyDiamonds').hide();
    $j('#DesignerGems').hide();
    $j('#otherprod').hide();
    var othviz = 0;

    $j('.xen').append('<img src="gfx/arrowr.png" alt="expand/collapse">');

    $j('#disp-eng').click(function() {
        $j('#ring1').toggle(400);
        if (!r1viz) { $j('#disp-eng img').attr('src', 'gfx/arrowd.png'); }
        else { $j('#disp-eng img').attr('src', 'gfx/arrowr.png'); }
        r1viz = !r1viz;
        return false;
    });

    $j('#disp-wed1').click(function() {
        $j('#ring2').toggle(400);
        if (!r2viz) { $j('#disp-wed1 img').attr('src', 'gfx/arrowd.png'); }
        else { $j('#disp-wed1 img').attr('src', 'gfx/arrowr.png'); }
        r2viz = !r2viz;
        return false;
    });

    $j('#disp-wed2').click(function() {
        $j('#ring3').toggle(400);
        if (!r3viz) { $j('#disp-wed2 img').attr('src', 'gfx/arrowd.png'); }
        else { $j('#disp-wed2 img').attr('src', 'gfx/arrowr.png'); }
        r3viz = !r3viz;
        return false;
    });

    $j('#disp-gems').click(function() {
        $j('#gems').toggle();
        if (!gemsviz) { $j('#disp-gems img').attr('src', 'gfx/arrowd.png'); }
        else { $j('#disp-gems img').attr('src', 'gfx/arrowr.png'); }
        gemsviz = !gemsviz;
        return false;
    });

    $j('#disp-other').click(function() {
        $j('#otherprod').toggle(400);
        if (!othviz) { $j('#disp-other img').attr('src', 'gfx/arrowd.png'); }
        else { $j('#disp-other img').attr('src', 'gfx/arrowr.png'); }
        othviz = !othviz;
        return false;
    });

    $j('input[@name="eng_stone"]').click(function() {
        var inpval = $j('input[@name="eng_stone"]:checked').val();
        $j('#gems > div').hide();
        if (inpval == "diamond") $j("#Diamonds").show();
        if (inpval == "sapphire") $j("#Sapphires").show();
        if (inpval == "fancy_diamond") $j("#FancyDiamonds").show();
        if (inpval == "designer_gem") $j("#DesignerGems").show();
    });

    $j('input[@name="ClearDiamonds"]').click(function() {
        $j('div#Diamonds').clearForm();
        $j('#Diamonds .fdbk').html('<span class="note">(none selected) -></span>');
    });

    $j('input[@name="ClearFancyDiamonds"]').click(function() {
        $j('div#FancyDiamonds').clearForm();
        $j('#FancyDiamonds .fdbk').html('<span class="note">(none selected) -></span>');
    });

    $j('input[@name="ClearDesignerCuts"]').click(function() {
        $j('div#DesignerGems').clearForm();
        $j('#DesignerGems .fdbk').html('<span class="note">(none selected) -></span>');
    });

    $j('input[@name="ClearSapphires"]').click(function() {
        $j('div#Sapphires').clearForm();
        $j('#Sapphires .fdbk').html('<span class="note">(none selected) -></span>');
    });

    $j('.radtab').hover(function() {
        $j(this).css({ 'background-color': '#343D54' });
    },
  		function() {
  		    $j(this).css({ 'background-color': '#4D4A44' });
  		});

    /**
    * Clears the form data.  Takes the following actions on the form's input fields:
    *  - input text fields will have their 'value' property set to the empty string
    *  - select elements will have their 'selectedIndex' property set to -1
    *  - checkbox and radio inputs will have their 'checked' property set to false
    *  - inputs of type submit, button, reset, and hidden will *not* be effected
    *  - button elements will *not* be effected
    */
    $j.fn.clearForm = function() {
        return this.each(function() {
            $j('input,select,textarea', this).clearFields();
        });
    };

    /**
    * Clears the selected form elements. Modified to include hidden fields.
    */
    $j.fn.clearFields = $j.fn.clearInputs = function() {
        return this.each(function() {
            var t = this.type, tag = this.tagName.toLowerCase();
            if (t == 'text' || t == 'password' || tag == 'textarea' || t == 'hidden')
                this.value = '';
            else if (t == 'checkbox' || t == 'radio')
                this.checked = false;
            else if (tag == 'select')
                this.selectedIndex = -1;
        });
    };

});

function checkdata(form) {
    if (form.realname.value === "") {
        alert("Please provide your name in the first field so that we can better serve you.  Thank you.");
        form.realname.focus();
        return false;
    }

    if (form.email.value === "") {
        alert("Please enter an email address before submitting this form.  Thank you.");
        form.email.focus();
        return false;
    }
    if (form.email.value != form.email_check.value) {
        alert("Email addresses do not match.  Please ensure that your email address is correct.");
        return false;
    }

    return true;
}

