﻿MayVanPhong_Class = function() { };
////////////////////////////////////
MayVanPhong_Class.prototype = {

    //List Functions you have to aready
    //1) InsertTemplate
    //2) SearchTemplate
    //3) ManageTemplate
    //4) ViewByMaSo
    //5) ReloadLeftMenuFilter
    //6) UpdatePicByMaSo

    ReloadLeftMenuFilter: function(subItemId) {
        $("input:radio[@name='SearchType']").filter("[value=0]").attr("checked", true);
        $("#SubItem").val(subItemId);
        $("#Province").val("0");
        $("#District").val("0");
        $("#Cost").val("0");
        $("#MainKeyword").val("");
    },

    //////////////////////////////////////////////////////////////////////////
    InsertTemplate: function() {
        $("html, body").animate({ scrollTop: 0 }, 0);

        if (Boxy.get("#WaitZone") == null) new Boxy("#WaitZone", { title: "Đang tải dữ liệu...", modal: false, closeable: false, fixed: false }); else Boxy.get("#WaitZone").show();
        $("#checkzone-content").load("./Template/MayVanPhong/InsertTemplate.htm", function() {
            Boxy.get("#WaitZone").hide();
            //
            MayVanPhong.GenerateNewCapcha();
            SubItem.ListAllByMainItemId($("#SubItemId"), GlobalVariable.MainItem);
            //Bind change-event for "#LoaiHinh"
            jQuery("#LoaiHinh").ready(function() {
                jQuery("#LoaiHinh").change(function() {
                    if ($(this).val() == 'canthue') { $('.option').css('display', 'none') } else { $('.option').css('display', 'inline') };
                })
            });
        });
    },

    PrintTemplate: function() {
        var myWin = window.open("", "Caigichothue", "menubar=yes,scrollbars=yes,width=800,height=550,left=100,top=100");
        myWin.document.write("<html><head><style type='text/css'>td {font-size: 12px;}</style></head><body style='font-size: 12px; font-family: Arial; margin:5;padding:5;'>" + "<div style='margin:0 auto;text-align:center'><img src='../Images/logo.jpg'/></div><br>" + $("#PrintZone").html() + "</body></html>");
        myWin.document.close();
        myWin = null;
    },
    //////////////////////////////////////////////////////////////////////////
    SearchTemplate: function(pageSize, pageIndex) {
        $("html, body").animate({ scrollTop: 0 }, 0);
        Ajax.SetQueryString("1", GlobalVariable.MainItem, GlobalVariable.SubItem, pageIndex, GlobalVariable.Tmp, "0", "0");

        var classPath = "Main.BL.MayVanPhongBL";
        var methodName = "MayVanPhongSearchTemplate";
        var userId = GlobalVariable.Tmp;

        $.ajax({
            url: "Handler.ashx",
            dataType: "json",
            data: "ClassPath=" + classPath + "&MethodName=" + methodName + "&UserId=" + userId + "&SearchType=" + GlobalVariable.SearchType + "&MainKeyword=" + $("#MainKeyword").val() + "&SubItem=" + $("#SubItem").val() + "&Province=" + $("#Province").val() + "&District=" + $("#District").val() + "&Cost=" + $("#Cost").val() + "&SortColumn=" + GlobalVariable.SortColumn + "&SortDirection=" + GlobalVariable.SortDirection + "&PageSize=" + pageSize + "&PageIndex=" + pageIndex,
            type: "POST",
            timeout: GlobalVariable.AjaxTimeOut,
            beforeSend: function() {
                if (Boxy.get("#WaitZone") == null) new Boxy("#WaitZone", { title: "Đang tải dữ liệu...", modal: false, closeable: false, fixed: false }); else Boxy.get("#WaitZone").show();
            },
            success: function(result) {
                if (result.Objects != null) {
                    $("#checkzone-content").setTemplateURL("./Template/MayVanPhong/SearchTemplate.htm");
                    //Add Params to JTemplate
                    $("#checkzone-content").setParam("numberPage", result.NumberPage);
                    $("#checkzone-content").setParam("rowCount", result.RowCount);
                    $("#checkzone-content").setParam("pageIndex", pageIndex);
                    //
                    $("#checkzone-content").processTemplate(result);
                }
                else {
                    if (pageIndex - 1 > 0)
                        MayVanPhong.SearchTemplate(GlobalVariable.PageSize, pageIndex - 1);
                    else
                        $("#checkzone-content").html(GlobalVariable.MsgNoRecord);
                }
            },
            error: function(xhr, message, ex) {
                alert(GlobalVariable.MsgErrorLoadData);
            },
            complete: function() {
                Boxy.get("#WaitZone").hide();
                //Start Tooltip
                Other.ImagePreview();
            }
        });
    },

    ManageTemplate: function(pageSize, pageIndex) {
        $("html, body").animate({ scrollTop: 0 }, 0);
        Ajax.SetQueryString("2", GlobalVariable.MainItem, GlobalVariable.SubItem, pageIndex, GlobalVariable.Tmp, "0", "0");

        var classPath = "Main.BL.MayVanPhongBL";
        var methodName = "MayVanPhongManageTemplate";
        var postValue = "&SortColumn=" + GlobalVariable.SortColumn + "&SortDirection=" + GlobalVariable.SortDirection + "&PageSize=" + pageSize + "&PageIndex=" + pageIndex;

        switch (GlobalVariable.Tmp) {
            case "0": postValue = postValue + "&ThoiHan=1&Lock=1"; break;
            case "1": postValue = postValue + "&ThoiHan=1&Lock=0"; break;
            case "2": postValue = postValue + "&ThoiHan=0&Lock=1"; break;
        }

        $.ajax({
            url: "Handler.ashx",
            dataType: "json",
            data: "ClassPath=" + classPath + "&MethodName=" + methodName + postValue,
            type: "POST",
            timeout: GlobalVariable.AjaxTimeOut,
            beforeSend: function() {
                if (Boxy.get("#WaitZone") == null) new Boxy("#WaitZone", { title: "Đang tải dữ liệu...", modal: false, closeable: false, fixed: false }); else Boxy.get("#WaitZone").show();
            },
            success: function(result) {
                if (result.Objects != null) {
                    $("#checkzone-content").setTemplateURL("./Template/MayVanPhong/ManageTemplate.htm");
                    //Add Params to JTemplate
                    $("#checkzone-content").setParam("numberPage", result.NumberPage);
                    $("#checkzone-content").setParam("rowCount", result.RowCount);
                    $("#checkzone-content").setParam("pageIndex", pageIndex);
                    //
                    $("#checkzone-content").processTemplate(result);
                }
                else {
                    if (pageIndex - 1 > 0)
                        MayVanPhong.ManageTemplate(GlobalVariable.PageSize, pageIndex - 1);
                    else
                        $("#checkzone-content").html(GlobalVariable.MsgNoRecord);
                }
            },
            error: function(xhr, message, ex) {
                alert(GlobalVariable.MsgErrorLoadData);
            },
            complete: function() {
                Boxy.get("#WaitZone").hide();
                //Start Tooltip
                Other.ImagePreview();
                //Start Upload Image
                Gui.UploadPictureAll();
            }
        });
    },

    SearchTemplateExcept: function(maSo, mainItemId, subItemId, pageSize, pageIndex) {
        //$("html, body").animate({ scrollTop: 0 }, 0);

        var classPath = "Main.BL.MayVanPhongBL";
        var methodName = "MayVanPhongSearchTemplateExcept";

        $.ajax({
            url: "Handler.ashx",
            dataType: "json",
            data: "ClassPath=" + classPath + "&MethodName=" + methodName + "&MaSo=" + maSo + "&MainItemId=" + mainItemId + "&SubItemId=" + subItemId + "&SortColumn=" + GlobalVariable.SortColumn + "&SortDirection=" + GlobalVariable.SortDirection + "&PageSize=" + pageSize + "&PageIndex=" + pageIndex,
            type: "POST",
            timeout: GlobalVariable.AjaxTimeOut,
            beforeSend: function() {
                if (Boxy.get("#WaitZone") == null) new Boxy("#WaitZone", { title: "Đang tải dữ liệu...", modal: false, closeable: false, fixed: false }); else Boxy.get("#WaitZone").show();
            },
            success: function(result) {
                if (result.Objects != null) {
                    $("#checkzone-content-2").setTemplateURL("./Template/MayVanPhong/SearchTemplateExcept.htm");
                    //Add Params to JTemplate
                    $("#checkzone-content-2").setParam("maSo", maSo);
                    $("#checkzone-content-2").setParam("mainItemId", mainItemId);
                    $("#checkzone-content-2").setParam("subItemId", subItemId);

                    $("#checkzone-content-2").setParam("numberPage", result.NumberPage);
                    $("#checkzone-content-2").setParam("rowCount", result.RowCount);
                    $("#checkzone-content-2").setParam("pageIndex", pageIndex);
                    //
                    $("#checkzone-content-2").processTemplate(result);
                }
            },
            error: function(xhr, message, ex) {
                alert(GlobalVariable.MsgErrorLoadData);
            },
            complete: function() {
                Boxy.get("#WaitZone").hide();
            }
        });
    },

    TopTemplate: function() {
        var classPath = "Main.BL.MayVanPhongBL";
        var methodName = "MayVanPhongTopTemplate";

        $.ajax({
            url: "Handler.ashx",
            dataType: "json",
            data: "ClassPath=" + classPath + "&MethodName=" + methodName + "&SortColumn=Visit&SortDirection=DESC&PageSize=10",
            type: "POST",
            timeout: GlobalVariable.AjaxTimeOut,
            beforeSend: function() {
                if (Boxy.get("#WaitZone") == null) new Boxy("#WaitZone", { title: "Đang tải dữ liệu...", modal: false, closeable: false, fixed: false }); else Boxy.get("#WaitZone").show();
            },
            success: function(result) {
                if (result.Objects != null) {
                    $("#LeftMenuTop").setTemplateURL("./Template/MayVanPhong/TopTemplate.htm");
                    $("#LeftMenuTop").processTemplate(result);
                }
            },
            error: function(xhr, message, ex) {
                alert(GlobalVariable.MsgErrorLoadData);
            },
            complete: function() {
                Boxy.get("#WaitZone").hide();
            }
        });
    },

    TodayTemplate: function() {
        var classPath = "Main.BL.MayVanPhongBL";
        var methodName = "MayVanPhongTodayTemplate";

        $.ajax({
            url: "Handler.ashx",
            dataType: "json",
            data: "ClassPath=" + classPath + "&MethodName=" + methodName + "&SortColumn=Visit&SortDirection=DESC&PageSize=10",
            type: "POST",
            timeout: GlobalVariable.AjaxTimeOut,
            beforeSend: function() {
                if (Boxy.get("#WaitZone") == null) new Boxy("#WaitZone", { title: "Đang tải dữ liệu...", modal: false, closeable: false, fixed: false }); else Boxy.get("#WaitZone").show();
            },
            success: function(result) {
                if (result.Objects != null) {
                    $("#LeftMenuToday").setTemplateURL("./Template/MayVanPhong/TodayTemplate.htm");
                    $("#LeftMenuToday").processTemplate(result);
                }
            },
            error: function(xhr, message, ex) {
                alert(GlobalVariable.MsgErrorLoadData);
            },
            complete: function() {
                Boxy.get("#WaitZone").hide();
            }
        });
    },

    ViewByMaSo: function(maSo, tieuDe) {
        $("html, body").animate({ scrollTop: 0 }, 0);
        Ajax.SetQueryString("0", GlobalVariable.MainItem, GlobalVariable.SubItem, "0", "0", maSo, Other.DecodeUnicode(tieuDe));

        var classPath = "Main.BL.MayVanPhongBL";
        var methodName = "MayVanPhongSelectByMaSo";
        $.ajax({
            url: "Handler.ashx",
            dataType: "json",
            data: "ClassPath=" + classPath + "&MethodName=" + methodName + "&MaSo=" + maSo,
            type: "POST",
            timeout: GlobalVariable.AjaxTimeOut,
            beforeSend: function() {
                if (Boxy.get("#WaitZone") == null) new Boxy("#WaitZone", { title: "Đang tải dữ liệu...", modal: false, closeable: false, fixed: false }); else Boxy.get("#WaitZone").show();
            },
            success: function(result) {
                $("#checkzone-content").setTemplateURL('./Template/MayVanPhong/ViewByMaSo.htm');
                $("#checkzone-content").processTemplate(result);
                document.title = result.Objects[0].TieuDe;
                document.getElementsByName('description')[0].setAttribute('content', result.Objects[0].TieuDe);
                document.getElementsByName('keywords')[0].setAttribute('content', result.Objects[0].TieuDe);
            },
            error: function(xhr, message, ex) {
                alert(GlobalVariable.MsgErrorLoadData);
            },
            complete: function() {
                Boxy.get("#WaitZone").hide();
                //Start Tooltip
                //Other.ImagePreview();
                $("#gallery a").lightBox();
            }
        });
    },

    SelectByMaSo: function(maSo, tieuDe) {
        $("html, body").animate({ scrollTop: 0 }, 0);

        var classPath = "Main.BL.MayVanPhongBL";
        var methodName = "MayVanPhongSelectByMaSo";
        $.ajax({
            url: "Handler.ashx",
            dataType: "json",
            data: "ClassPath=" + classPath + "&MethodName=" + methodName + "&MaSo=" + maSo,
            type: "POST",
            timeout: GlobalVariable.AjaxTimeOut,
            beforeSend: function() {
                if (Boxy.get("#WaitZone") == null) new Boxy("#WaitZone", { title: "Đang tải dữ liệu...", modal: false, closeable: false, fixed: false }); else Boxy.get("#WaitZone").show();
            },
            success: function(result) {
                $("#checkzone-content").setTemplateURL('./Template/MayVanPhong/SelectByMaSo.htm');
                $("#checkzone-content").processTemplate(result);
            },
            error: function(xhr, message, ex) {
                alert(GlobalVariable.MsgErrorLoadData);
            },
            complete: function() {
                Boxy.get("#WaitZone").hide();
                //Bind change-event for "#LoaiHinh" and execute change-event       
                jQuery("#LoaiHinh").ready(function() {
                    jQuery("#LoaiHinh").change(function() {
                        if ($(this).val() == 'canthue') { $('.option').css('display', 'none') } else { $('.option').css('display', 'inline') };
                    }).change();
                });
            }
        });
    },

    //////////////////////////////////////////////////////////////////////////

    Insert: function() {
        var classPath = "Main.BL.MayVanPhongBL";
        var methodName = "MayVanPhongInsert";

        if ($("#IC").val().toLowerCase() != GlobalVariable.CapCha.toLowerCase()) {
            alert("Mã xác nhận không đúng!");
            MayVanPhong.GenerateNewCapcha();
            return false;
        }

        var postValue = MayVanPhong.CheckValidAndPost();
        switch (postValue) {
            case "0": alert("Tiêu đề tin không được để trống (số ký tự < 400)."); $("#TieuDe").focus(); $("#TieuDe").select(); return false; break;
            case "1": alert("Giá không được để trống."); $("#Price").focus(); $("#Price").select(); return false; break;
            case "2": alert("Giá phải nhập ký tự số (số ký tự <50)."); $("#Price").focus(); $("#Price").select(); return false; break;
            case "3": alert("Mô tả không được để trống (số ký tự < 4000)."); $("#MoTa").focus(); $("#MoTa").select(); return false; break;
            case "4": alert("Họ Tên không được để trống (số ký tự < 200)."); $("#LienHeHoTen").focus(); $("#LienHeHoTen").select(); return false; break;
            case "5": alert("Số điện thoại không được để trống và chỉ chấp nhận ký tự số (số ký tự < 50)."); $("#LienHeDienThoai").focus(); $("#LienHeDienThoai").select(); return false; break;
            case "6": alert("Địa chỉ liên hệ không được để trống (số ký tự < 500)."); $("#LienHeDiaChi").focus(); $("#LienHeDiaChi").select(); return false; break;
            case "7": alert("Email liên hệ < 200 ký tự."); $("#LienHeEmail").focus(); $("#LienHeEmail").select(); return false; break;
            case "8": alert("Email liên hệ không đúng chuẩn."); $("#LienHeEmail").focus(); $("#LienHeEmail").select(); return false; break;
            case "9": alert("Nick yahoo < 100 ký tự."); $("#LienHeYahoo").focus(); $("#LienHeYahoo").select(); return false; break;
            case "10": alert("Nick skype < 100 ký tự."); $("#LienHeSkype").focus(); $("#LienHeSkype").select(); return false; break;
        }

        $.ajax({
            url: "Handler.ashx",
            dataType: "json",
            data: "ClassPath=" + classPath + "&MethodName=" + methodName + postValue,
            type: "POST",
            timeout: GlobalVariable.AjaxTimeOut,
            beforeSend: function() {
                if (Boxy.get("#WaitZone") == null) new Boxy("#WaitZone", { title: "Đang tải dữ liệu...", modal: false, closeable: false, fixed: false }); else Boxy.get("#WaitZone").show();
                $("#InsertButton").attr('disabled', 'disabled');
            },
            success: function(result) {
                if (result.Success == "True") {
                    alert("Tin của bạn thêm mới thành công [Mã số của tin bạn vừa đăng là: VP" + result.MaSo + "]");
                    //Reload list user item (MayVanPhong.ManageTemplate)
                    MayVanPhong.ManageTemplate(GlobalVariable.PageSize, '1');
                    //Reload Right Menu (SubItem of MainItem)
                    MainItem.RightMenuCountByUserId();
                    SubItem.RightMenuByMainItemId($("#RightMenuSubItem"), GlobalVariable.MainItem);
                    //Reload LeftMenuToday
                    MayVanPhong.TodayTemplate();
                }
                else {
                    switch (result.MaSo) {
                        case "1": alert("Tài khoản của bạn đã bị khóa!"); break;
                        case "2": alert("Thời gian đăng tin của bạn đã hết!"); break;
                        case "3": alert("Bạn đã sử dụng hết số tin đăng cho phép!"); break;
                        default: alert(GlobalVariable.MsgErrorInsertData); break;
                    }
                    $("#InsertButton").attr('disabled', '');
                }
            },
            error: function(xhr, message, ex) {
                alert(GlobalVariable.MsgErrorLoadData);
                $("#InsertButton").attr('disabled', '');
            },
            complete: function() {
                Boxy.get("#WaitZone").hide();
            }
        });
    },

    Update: function() {
        var classPath = "Main.BL.MayVanPhongBL";
        var methodName = "MayVanPhongUpdate";

        var postValue = MayVanPhong.CheckValidAndPost();
        switch (postValue) {
            case "0": alert("Tiêu đề tin không được để trống (số ký tự < 400)."); $("#TieuDe").focus(); $("#TieuDe").select(); return false; break;
            case "1": alert("Giá không được để trống."); $("#Price").focus(); $("#Price").select(); return false; break;
            case "2": alert("Giá phải nhập ký tự số (số ký tự <50)."); $("#Price").focus(); $("#Price").select(); return false; break;
            case "3": alert("Mô tả không được để trống (số ký tự < 4000)."); $("#MoTa").focus(); $("#MoTa").select(); return false; break;
            case "4": alert("Họ Tên không được để trống (số ký tự < 200)."); $("#LienHeHoTen").focus(); $("#LienHeHoTen").select(); return false; break;
            case "5": alert("Số điện thoại không được để trống và chỉ chấp nhận ký tự số (số ký tự < 50)."); $("#LienHeDienThoai").focus(); $("#LienHeDienThoai").select(); return false; break;
            case "6": alert("Địa chỉ liên hệ không được để trống (số ký tự < 500)."); $("#LienHeDiaChi").focus(); $("#LienHeDiaChi").select(); return false; break;
            case "7": alert("Email liên hệ < 200 ký tự."); $("#LienHeEmail").focus(); $("#LienHeEmail").select(); return false; break;
            case "8": alert("Email liên hệ không đúng chuẩn."); $("#LienHeEmail").focus(); $("#LienHeEmail").select(); return false; break;
            case "9": alert("Nick yahoo < 100 ký tự."); $("#LienHeYahoo").focus(); $("#LienHeYahoo").select(); return false; break;
            case "10": alert("Nick skype < 100 ký tự."); $("#LienHeSkype").focus(); $("#LienHeSkype").select(); return false; break;
        }

        $.ajax({
            url: "Handler.ashx",
            dataType: "json",
            data: "ClassPath=" + classPath + "&MethodName=" + methodName + postValue,
            type: "POST",
            timeout: GlobalVariable.AjaxTimeOut,
            beforeSend: function() {
                if (Boxy.get("#WaitZone") == null) new Boxy("#WaitZone", { title: "Đang tải dữ liệu...", modal: false, closeable: false, fixed: false }); else Boxy.get("#WaitZone").show();
                $("#UpdateButton").attr('disabled', 'disabled');
            },
            success: function(result) {
                if (result.Success == "True") {
                    alert(GlobalVariable.MsgSuccessUpdateData);
                    //Reload list user item (MayVanPhong.ManageTemplate)
                    MayVanPhong.ManageTemplate(GlobalVariable.PageSize, result.PageIndex);
                    //Reload Right Menu (SubItem of MainItem)
                    MainItem.RightMenuCountByUserId();
                    SubItem.RightMenuByMainItemId($("#RightMenuSubItem"), GlobalVariable.MainItem);
                }
                else {
                    alert(GlobalVariable.MsgErrorUpdateData);
                    $("#UpdateButton").attr('disabled', '');
                }
            },
            error: function(xhr, message, ex) {
                alert(GlobalVariable.MsgErrorLoadData);
                $("#UpdateButton").attr('disabled', '');
            },
            complete: function() {
                Boxy.get("#WaitZone").hide();
            }
        });
    },

    UpdateCreateDateByMaSo: function(maSo) {
        var classPath = "Main.BL.MayVanPhongBL";
        var methodName = "MayVanPhongUpdateCreateDateByMaSo";
        $.ajax({
            url: "Handler.ashx",
            dataType: "json",
            data: "ClassPath=" + classPath + "&MethodName=" + methodName + "&MaSo=" + maSo,
            type: "POST",
            timeout: GlobalVariable.AjaxTimeOut,
            beforeSend: function() {
            },
            success: function(result) {
                alert(GlobalVariable.MsgSuccessUpdateData);
                //Reload list user item (MayVanPhong.ManageTemplate)
                MayVanPhong.ManageTemplate(GlobalVariable.PageSize, result.PageIndex);
                //Reload Right Menu (SubItem of MainItem)
                MainItem.RightMenuCountByUserId();
                SubItem.RightMenuByMainItemId($("#RightMenuSubItem"), GlobalVariable.MainItem);
            },
            error: function(xhr, message, ex) {
                alert(GlobalVariable.MsgErrorLoadData);
            },
            complete: function() {
            }
        });
    },

    UpdatePicByMaSo: function(maSo, pic) {
        var classPath = "Main.BL.MayVanPhongBL";
        var methodName = "MayVanPhongUpdatePicByMaSo";
        $.ajax({
            url: "Handler.ashx",
            dataType: "json",
            data: "ClassPath=" + classPath + "&MethodName=" + methodName + "&MaSo=" + maSo + "&Pic=" + pic,
            type: "POST",
            timeout: GlobalVariable.AjaxTimeOut,
            beforeSend: function() {
            },
            success: function(result) {
                if (result.Success == "False") {
                    alert(GlobalVariable.MsgErrorUpdateData);
                }
            },
            error: function(xhr, message, ex) {
                alert(GlobalVariable.MsgErrorLoadData);
            },
            complete: function() {
            }
        });

    },

    DeleteByMaSo: function(maSo) {

        var classPath = "Main.BL.MayVanPhongBL";
        var methodName = "MayVanPhongDeleteByMaSo";

        if (confirm("Bạn có đồng ý xóa tin này?")) {
            $.ajax({
                url: "Handler.ashx",
                dataType: "json",
                data: "ClassPath=" + classPath + "&MethodName=" + methodName + "&MaSo=" + maSo,
                type: "POST",
                timeout: GlobalVariable.AjaxTimeOut,
                beforeSend: function() {
                    if (Boxy.get("#WaitZone") == null) new Boxy("#WaitZone", { title: "Đang tải dữ liệu...", modal: false, closeable: false, fixed: false }); else Boxy.get("#WaitZone").show();
                },
                success: function(result) {
                    if (result.Success == "True") {
                        alert(GlobalVariable.MsgSuccessDeleteData);
                        //Reload list user item (MayVanPhong.ManageTemplate)
                        MayVanPhong.ManageTemplate(GlobalVariable.PageSize, result.PageIndex);
                        //Reload Right Menu (SubItem of MainItem)
                        MainItem.RightMenuCountByUserId();
                        SubItem.RightMenuByMainItemId($("#RightMenuSubItem"), GlobalVariable.MainItem);
                    }
                    else {
                        alert(GlobalVariable.MsgErrorDeleteData);
                    }
                },
                error: function(xhr, message, ex) {
                    alert(GlobalVariable.MsgErrorLoadData);
                },
                complete: function() {
                    Boxy.get("#WaitZone").hide();
                }
            });
        }
    },

    //////////////////////////////////////////////////////////////////////////
    CheckValidAndPost: function() {
    
        duongLink = encodeURIComponent(jQuery.trim($("#DuongLink").val()));
        ghiChu = encodeURIComponent(jQuery.trim($("#GhiChu").val()));
        lienHeYahoo = jQuery.trim($("#LienHeYahoo").val());
        lienHeSkype = jQuery.trim($("#LienHeSkype").val());
        lienHeChinhChu = $("#LienHeChinhChu:checked").val();
        lienHeDiaChi = encodeURIComponent(jQuery.trim($("#LienHeDiaChi").val()));
        lienHeMap = jQuery.trim($("#LienHeMap").val());
        lienHeDienThoai = jQuery.trim($("#LienHeDienThoai").val());
        lienHeEmail = jQuery.trim($("#LienHeEmail").val());
        lienHeHoTen = encodeURIComponent(jQuery.trim($("#LienHeHoTen").val()));
        loaiHinh = $("#LoaiHinh").val();
        mainItemId = GlobalVariable.MainItem;
        moTa = encodeURIComponent(jQuery.trim($("#MoTa").val()));
        quanHuyen = $("#QuanHuyen").val();
        subItemId = $("#SubItemId").val();
        price = jQuery.trim($("#Price").val());
        thoiGian = $("#ThoiGian").val();
        thoiHan = $("#ThoiHan").val();
        tieuDe = encodeURIComponent(jQuery.trim($("#TieuDe").val()));
        tinhThanh = $("#TinhThanh").val();

        if (tieuDe == "" || tieuDe.length > 400)
            return "0";
        if (loaiHinh == "chothue") {
            if (price == "")
                return "1";
        }
        if (loaiHinh == "canthue") {
            if (price == "")
                price = "0";
        }
        if (price.length > 50 || isNaN(price.replace(/,/g, "")))
            return "2";
        if (moTa == "" || moTa.length > 4000)
            return "3";
        if (lienHeHoTen == "" || lienHeHoTen.length > 200)
            return "4";
        if ((lienHeDienThoai == "") || (lienHeDienThoai.length > 50) || (isNaN(lienHeDienThoai.replace(/,/g, ''))))
            return "5";
        if (lienHeDiaChi == "" || lienHeDiaChi.length > 500)
            return "6";
        if (lienHeEmail.length > 200)
            return "7";
        if ((Other.CheckValidEmail(lienHeEmail) == false) && (lienHeEmail != ""))
            return "8";
        if (lienHeYahoo.length > 100)
            return "9";
        if (lienHeSkype.length > 100)
            return "10";

        return ("&DuongLink=" + duongLink + "&GhiChu=" + ghiChu + "&Price=" + price + "&LienHeYahoo=" + lienHeYahoo + "&LienHeSkype=" + lienHeSkype + "&LienHeChinhChu=" + lienHeChinhChu + "&LienHeDiaChi=" + lienHeDiaChi + "&LienHeMap=" + lienHeMap + "&LienHeDienThoai=" + lienHeDienThoai + "&LienHeEmail=" + lienHeEmail + "&LienHeHoTen=" + lienHeHoTen + "&LoaiHinh=" + loaiHinh + "&MainItemId=" + mainItemId + "&MoTa=" + moTa + "&QuanHuyen=" + quanHuyen + "&SubItemId=" + subItemId + "&ThoiGian=" + thoiGian + "&ThoiHan=" + thoiHan + "&TieuDe=" + tieuDe + "&TinhThanh=" + tinhThanh);    
    },

    //////////////////////////////////////////////////////////////////////////
    GenerateNewCapcha: function() {
        GlobalVariable.CapCha = CyloCaptcha.genRan(4); //get a new 4 random number
        $("#DC").html(CyloCaptcha.display(GlobalVariable.CapCha));
    }

};

var MayVanPhong = new MayVanPhong_Class();

