﻿
var $j = jQuery.noConflict();


var DemoRequest = {
    ShowOtherReferralInput: function () {
        if ($j("#referrals .othertext input")[0].value == '#') {
            $j("#referrals .othertext input")[0].value = '';
        }

        $j("#referrals .othertext").show();
    },

    HideOtherReferralInput: function () {
        $j("#referrals .othertext").hide();
        // Dummy text to avoid validator warning.
        $j("#referrals .othertext input")[0].value = '#';
    },

    DisableAlternateDateInput: function () {
        $j(".halfAvailableWidth").addClass("disabled");
        $j(".halfAvailableWidth input").attr('disabled', 'disabled');
    },

    EnableAlternateDateInput: function () {
        $j(".halfAvailableWidth input").removeAttr('disabled');
        $j(".halfAvailableWidth").removeClass("disabled");
    },

    InitForm: function () {
        var otherOption = $j("#referrals .referralslist option:last")[0];

        if ((otherOption != undefined) && (!otherOption.selected)) {
            this.HideOtherReferralInput();
        }
        else {
            this.ShowOtherReferralInput();
        }

        var instantDemoRadio = $j(".contactPreferenceSwitcher input:radio:first").attr('checked');

        if (instantDemoRadio) {
            this.DisableAlternateDateInput();
        } else {
            this.EnableAlternateDateInput();
        }
    }
};

$j(document).ready(function() {
    DemoRequest.InitForm();
    
    $j("#referrals .referralslist").change(function(){
        if (this.options[this.selectedIndex].value == '{736DDE0F-D697-4864-AA38-0504C50B353B}') {
            DemoRequest.ShowOtherReferralInput();
        }
        else {
            DemoRequest.HideOtherReferralInput();
        }
    });

    $j(".contactPreferenceSwitcher input:radio").click(function () {
        if (this.value == 'I want an Instant Demo.' || this.value == '早くデモを見たい') {
            DemoRequest.DisableAlternateDateInput();
        }
        if (this.value == 'I want to request an alternate demo date and time.' || this.value == '希望の日時にデモを見たい') {
            DemoRequest.EnableAlternateDateInput();
        }       
    });    
});

