﻿$(document).ready(function () {
	$('a.lightBox').lightBox();
    $('#ContactDesign').find('select.locationSelectBox').MakeVmSelectbox({ className: 'locationSelectBox' });
    $('#ContactDesign').find('select#Direction').MakeVmSelectbox({ width: '158', className: 'directionSelectBox' });
    var showOption = function () {
        if (($('#ContactDesign').find('input[name="Type"]:checked').val() == 'nhapho') || ($('#ContactDesign').find('input[name="Type"]:checked').val() == 'bietthu')) {
            $('#ContactDesign').find('.option').slideDown();
            showingOption = true;
        }
        else {
            $('#ContactDesign').find('.option').slideUp();
        }
    }
    var showingOption = false;
    $('#ContactDesign').find('input[name="Type"]').change(function () {
        $('#ContactDesign').find('.Status').slideDown();
        if (($('#ContactDesign').find('input[name="Status"]:checked').val() == 'xaymoi') || ($('#ContactDesign').find('input[name="Status"]:checked').val() == 'caitao')) {
            showOption();
        }
    });
    $('#ContactDesign').find('input[name="Status"]').change(function () {
        $('.info').slideDown();
        showOption();
        if ($('#ContactDesign').find('input[name="Status"]:checked').val() == 'xaymoi') {
            $('#ContactDesign').find('.other').slideDown();
            $('#ContactDesign').find('.mong').slideDown();
        }
        else {
            $('#ContactDesign').find('input[name="WeakGround"]').removeAttr("checked");
            //$('#ContactDesign').find('input[name="SmallAlley"]').removeAttr("checked");
            //$('#ContactDesign').find('.other').slideUp();
            $('#ContactDesign').find('.mong').slideUp();
        }
    });

    //BEGIN Contact Form --------------------------------
    $('#submitlienhe').click(function () {
        $('#ContactDesign').ajaxForm({
            dataType: 'json',
            beforeSubmit: showRequest,
            success: showResponse
        });
    });

    function showRequest(formData, jqForm, options) {
        $("#notice-submitting").show();
        //var queryString = $.param(formData);
        //alert('About to submit: \n\n' + queryString);
        return true;
    }

    function showResponse(data) {
        $("#notice-submitting").hide();
        if (data["resultOK"] != undefined) {
            alert("Đã gởi nội dung liên hệ thành công!\r\nCảm ơn bạn đã liên hệ Wonder-design.");
        }
        else if ((data == undefined) || (data == null) || (data == '') || (data.length == 0)) {
            alert("Chưa gởi được liên hệ.\r\nCó thể do máy chủ bận, vui lòng liên hệ vào lúc khác.");
        }
        else {
            alert("Bạn nhập thiếu thông tin.\r\nVui lòng điền đủ thông tin yêu cầu!");
        }

        if (data["Fullname"] != undefined) {
            $('label[for="Fullname"]').addClass('error').attr('title', data["Fullname"]);
        }
        else {
            $('label[for="Fullname"]').removeClass('error').attr('title', '');
        }

        if (data["Email"] != undefined) {
            $('label[for="Email"]').addClass('error').attr('title', data["Email"]);
            $('label[for="Phone"]').addClass('error').attr('title', data["Phone"]);
        }
        else {
            $('label[for="Email"]').removeClass('error').attr('title', '');
            $('label[for="Phone"]').removeClass('error').attr('title', '');
        }

        if (data["Gender"] != undefined) {
            $('label[for="nam"]').addClass('error').attr('title', data["Gender"]);
            $('label[for="nu"]').addClass('error').attr('title', data["Gender"]);
        }
        else {
            $('label[for="nam"]').removeClass('error').attr('title', '');
            $('label[for="nu"]').removeClass('error').attr('title', '');
        }
    }
    //END Contact Form --------------------------------

    $('#sliderImg').innerfade({
        speed: 1000,
        timeout: 3000
    });

    //----- BEGIN Multi upload cho việc gởi email liên hệ -----
    var fileMax = 5;
    var lastFile = "";

    $('input.multiupload').before('<div id="files_list" style="border:1px solid #333;padding:3px;margin-bottom:10px;font-size:x-small;width:441px;"><span style="margin-left:5px;font-size:12px;"><class="t">Danh sách file (tối đa ' + fileMax + '):</class></span></div>');

    $("input.multiupload").change(function () {
        doIt($(this), fileMax);
    });

    function doIt(obj, fm) {
        var v = obj.val();
        if ((v != '') && (v != null) && (v != lastFile)) {
            lastFile = v;
            if ($('input.multiupload').size() > fm) {
                alert('Chỉ đính kèm tối đa ' + fm + ' file trong mỗi lần liên hệ!');
                obj.val('');
                return false;
            }
            obj.hide();
            var newUploadElement = $('<input />', { className: 'multiupload', type: 'file', name: 'Attachments' });
            obj.after(newUploadElement);
            newUploadElement.change(function () {
                doIt($(this), fm)
            });

            $("div#files_list").append('<span style="margin-left:10px;font-size:12px;"><br />- ' + v + ' [<a href="#" style="color:red;">Xóa</a>]</span>').find("a").click(function () {
                $(this).parent().remove();
                obj.remove();
                return false;
            });
        }
    };

    //----- END Multi upload cho việc gởi email liên hệ -----

    $('.boxshadow,.print_area').animate({ boxShadow: '-1 1 3px #999' });
    $('.boxshadow,.print_area').hover(
        function () { $(this).animate({ boxShadow: '-1 1 6px #333' }, 100); },
        function () { $(this).animate({ boxShadow: '-1 1 3px #999' }, 100); }
    );
    $('#v-menu li').animate({ boxShadow: '-1 1 3px #111' });
    $('#v-menu li').hover(
        function () { $(this).animate({ boxShadow: '-1 1 6px #000' }, 100); },
        function () { $(this).animate({ boxShadow: '-1 1 3px #111' }, 100); }
    );
});
