﻿/// <reference path="../../Scripts/jquery-1.4.1.js" />
/// <reference path="../../Scripts/jquery.validate.pack.js" />
/// <reference path="../../Scripts/MVCFutures/MicrosoftMvcJQueryValidation.js" />
/// <reference path="../../Scripts/MicrosoftAjax.js" />
/// <reference path="../../Scripts/MicrosoftMvcAjax.js" />

jQuery(document).ready(function () {

    $("#contactusForm").data("validator").settings.submitHandler = function (form) {

        $(":submit").attr("disabled", "disabled");
        form.submit();
    };

    document.getElementById("Catalog").checked = false;
    document.getElementById("AdressInfo").style.display = "none";
    document.getElementById("JavaCheck").style.display = "none";

    

    var x = $("#Catalog").is(':checked');

    if (x == true) {
        $("#Address").addClass('required');
        $("#City").addClass('required');
        $("#Zip").addClass('required');
    }

    if ($("#Country").val() == "United States") {
        $("#State").addClass('required');
        ChangeCountry();
    }

    if ($("#Country").val() != "United States") {
        $("#State").attr('disabled', 'disabled');
    }
   

    $("#Fill").val("2222");



});


function populateDropdown(select, data) {

    var x = 0;
    select.html('');
    $.each(data, function(id, option) {
        select.append($('<option></option>').val(option.Text).html(option.Value));
        x++;
    });

    if (x <= 1) {
        select.removeClass('required');
        select.attr('disabled', 'disabled');
        $("#State_validationMessage").text("");
        $("#State_validationMessage").css({ "background-color": "White" });
        document.getElementById("StateRequired").style.display = "none"; 
    }
    else {
        select.addClass('required');
        select.attr('disabled', '');
        document.getElementById("StateRequired").style.display = "";
        
    }
}

function ChangeCountry() {

    var area = $("#Country").val();
    if (area != "") {

        $.post("GetCountryStates", { country: area }, function(data) {
            populateDropdown($("#State"), data);
        });

       
    }
    else {
        $("#State").attr('disabled', 'disabled');
        $("#State").removeClass('required');
        $("#State_validationMessage").text("");
        $.post("GetCountryStates", { country: "" }, function(data) {
            populateDropdown($("#State"), data);
        });
    }

}

function CatalogChange() { 
    
   var checked = $("#Catalog").is(':checked');
   if (!checked) {

       document.getElementById("AdressInfo").style.display = "none";
       
   }
   else {
   
       document.getElementById("AdressInfo").style.display = "";
   }


}


function init_validation(divName) {

    var checked = $("#Catalog").is(':checked');
    if (!checked) {
        $('div#' + divName).find('input').removeClass('required');
        document.getElementById(divName).style.display = "none";
        if ($("#State").val() == "CA") {
            $("#Zip").val("");
        }
    }
    else {
    
        $('div#' + divName).find('input').addClass('required');
        document.getElementById(divName).style.display = "";

        if ($("#State").val() == "CA") {
            $("#Zip").removeClass('required');

        }
        
       
    }
}



function CheckState() {

    if ($("#State").val() == "CA") {

        $("#ZipCode").addClass('required');
        document.getElementById("ZipDiv").style.display = "";
        document.getElementById("CatalogZip").style.display = "none";

    }
    else {
        $("#ZipCode").removeClass('required');
        document.getElementById("ZipDiv").style.display = "none";
        document.getElementById("CatalogZip").style.display = "";
    }
}
