﻿Other_Class = function() { };
////////////////////////////////////
Other_Class.prototype = {

    //////////////////////////////////////////////////////////
    //              FEATURE PICKUP                          //
    //////////////////////////////////////////////////////////
    FeatureByPosition: function (feature, position) {
        featureArray = feature.split(";", 34);
        return featureArray[position];
    },

    FeatureRender: function (feature, mainItem) {
        featureArray = feature.split(";", 34);
        if (mainItem == "NhaDat") {
            if (featureArray[0] == "on") $("#ND-MetVuong").html("/m&sup2;");

            if (featureArray[1] != "") $("#ND-DienTichTong").html(featureArray[1] + "m&sup2;");
            if (featureArray[2] != "") $("#ND-DienTichNgang").html(featureArray[2] + "m");
            if (featureArray[3] != "") $("#ND-DienTichDai").html(featureArray[3] + "m");
            if (featureArray[4] != "") $("#ND-DuongTruocNha").html(featureArray[4] + "m");
            $("#ND-ViTri").html(featureArray[5]);
            $("#ND-PhapLy").html(featureArray[6]);
            $("#ND-Huong").html(featureArray[7]);
            $("#ND-SoPhongKhach").html(featureArray[8]);
            $("#ND-SoPhongNgu").html(featureArray[9]);
            $("#ND-SoPhongTam").html(featureArray[10]);
            $("#ND-SoLau").html(featureArray[11]);

            if (featureArray[12] == "on") $("#ND-GanTruong").html("<img src='../../Images/check.jpg'/>");
            if (featureArray[13] == "on") $("#ND-GanCho").html("<img src='../../Images/check.jpg'/>");
            if (featureArray[14] == "on") $("#ND-GanSieuThi").html("<img src='../../Images/check.jpg'/>");
            if (featureArray[15] == "on") $("#ND-GanBenhVien").html("<img src='../../Images/check.jpg'/>");
            if (featureArray[16] == "on") $("#ND-GanBenXe").html("<img src='../../Images/check.jpg'/>");
            if (featureArray[17] == "on") $("#ND-GanSanBay").html("<img src='../../Images/check.jpg'/>");
            if (featureArray[18] == "on") $("#ND-GanAnNinh").html("<img src='../../Images/check.jpg'/>");
            if (featureArray[19] == "on") $("#ND-TienNhaBep").html("<img src='../../Images/check.jpg'/>");
            if (featureArray[20] == "on") $("#ND-TienGara").html("<img src='../../Images/check.jpg'/>");
            if (featureArray[21] == "on") $("#ND-TienSanVuon").html("<img src='../../Images/check.jpg'/>");
            if (featureArray[22] == "on") $("#ND-TienHoBoi").html("<img src='../../Images/check.jpg'/>");
            if (featureArray[23] == "on") $("#ND-TienKinhDoanh").html("<img src='../../Images/check.jpg'/>");
            if (featureArray[24] == "on") $("#ND-TienNhaO").html("<img src='../../Images/check.jpg'/>");
            if (featureArray[25] == "on") $("#ND-TienVanPhong").html("<img src='../../Images/check.jpg'/>");
            if (featureArray[26] == "on") $("#ND-TienSanXuat").html("<img src='../../Images/check.jpg'/>");
            if (featureArray[27] == "on") $("#ND-TienSinhVien").html("<img src='../../Images/check.jpg'/>");
            if (featureArray[28] == "on") $("#ND-TienInternet").html("<img src='../../Images/check.jpg'/>");
            if (featureArray[29] == "on") $("#ND-TienThangMay").html("<img src='../../Images/check.jpg'/>");
            if (featureArray[30] == "on") $("#ND-TienTruyenHinhCap").html("<img src='../../Images/check.jpg'/>");
            if (featureArray[31] == "on") $("#ND-TienMayLanh").html("<img src='../../Images/check.jpg'/>");
            if (featureArray[32] == "on") $("#ND-TienMayNuocNong").html("<img src='../../Images/check.jpg'/>");
            if (featureArray[33] == "on") $("#ND-TienBonTam").html("<img src='../../Images/check.jpg'/>");
        }
    },


    //////////////////////////////////////////////////////////
    //              GET CLIENT IP                           //
    //////////////////////////////////////////////////////////
    GetUserIP: function () {
        var classPath = "Main.OTHER.GetSystemInfo";
        var methodName = "GetUserIP";
        $.ajax({
            url: "Handler.ashx",
            dataType: "json",
            data: "ClassPath=" + classPath + "&MethodName=" + methodName,
            type: "POST",
            timeout: GlobalVariable.AjaxTimeOut,
            success: function (result) {
                document.title = "CaiGiChoThue.com  [" + result.UserIP + "]";
            },
            error: function (xhr, message, ex) {
                //alert(GlobalVariable.MsgErrorLoadData);
            },
            complete: function () {
            }
        });
    },

    //////////////////////////////////////////////////////////
    //              TAB                                   //
    //////////////////////////////////////////////////////////
    TabInit: function () {
        //Default Action
        $(".tab_content").hide(); //Hide all content
        $("ul.tabs li:first").addClass("active").show(); //Activate first tab
        $(".tab_content:first").show(); //Show first tab content
        //On Click Event
        $("ul.tabs li").click(function () {
            $("ul.tabs li").removeClass("active"); //Remove any "active" class
            $(this).addClass("active"); //Add "active" class to selected tab
            $(".tab_content").hide(); //Hide all tab content
            var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
            $(activeTab).fadeIn(); //Fade in the active ID content
            return false;
        });
    },

    //////////////////////////////////////////////////////////
    //              GMAP                                    //
    //////////////////////////////////////////////////////////
    GMapInit: function (point, description) {
        //point: setCenter point position
        //description: show description info at Gmaker
        if ((point != "") && (point != null)) {
            $("#GMapZone").css("display", "block");
            if (GBrowserIsCompatible()) {
                //Options of Google Search bar
                var opts = {
                    googleBarOptions: {
                        style: 'new'
                    }
                }

                //Options of Marker icon
                var blueIcon = new GIcon(G_DEFAULT_ICON);
                blueIcon.image = "http://maps.google.com/intl/en_us/mapfiles/ms/micons/green-dot.png";
                markerOptions = { icon: blueIcon };
                //LOAD MAP
                GlobalVariable.GMap = new GMap2(document.getElementById("GMapZone"), opts);
                GlobalVariable.GMap.setUIToDefault();

                p = point.split("|");
                gpoint = new GLatLng(p[1], p[0]);
                GlobalVariable.GMap.enableGoogleBar();
                GlobalVariable.GMap.setCenter(gpoint, 14);
                GlobalVariable.GMarker = new GMarker(gpoint, markerOptions);
                GlobalVariable.GMap.addOverlay(GlobalVariable.GMarker);
                GlobalVariable.GMap.openInfoWindowHtml(gpoint, description);
            }

            //Add event CLICK & MOUSE OVER on Google Map
            GEvent.addListener(GlobalVariable.GMarker, "mouseover", function () {
                if (description != "") {
                    GlobalVariable.GMarker.openInfoWindowHtml(description);
                }
            });
        }
    },

    /////////////////////////////////////////////////////////////
    //              TOOLTIP                                    //
    /////////////////////////////////////////////////////////////
    ImagePreview: function () {


        $("a.preview").hover(function (e) {
            this.t = this.title;
            this.title = "";
            var c = (this.t != "") ? "<br/>" + this.t : "";
            $("body").append("<p id='preview'><img src='" + this.href + "' alt='Image preview' />" + c + "</p>");
            $("#preview").css({ top: e.pageY - 300, left: '50%', margin: '-' + ($('#preview').height() / 2) + 'px 0 0 -' + ($('#preview').width() / 2) + 'px' }).fadeIn("fast");
        },
	    function () {
	        this.title = this.t;
	        $("#preview").remove();
	    });
        $("a.preview").mousemove(function (e) {
            $("#preview").css({ top: e.pageY - 300, left: '50%', margin: '-' + ($('#preview').height() / 2) + 'px 0 0 -' + ($('#preview').width() / 2) + 'px' });
        });
    },


    /////////////////////////////////////////////////////////////
    //              CHECK EMAIL VALID                          //
    /////////////////////////////////////////////////////////////
    CheckValidEmail: function (str) {

        var at = "@"
        var dot = "."
        var lat = str.indexOf(at)
        var lstr = str.length
        var ldot = str.indexOf(dot)
        if (str.indexOf(at) == -1) {
            return false;
        }

        if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) {
            return false;
        }

        if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) {
            return false;
        }

        if (str.indexOf(at, (lat + 1)) != -1) {
            return false;
        }

        if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) {
            return false;
        }

        if (str.indexOf(dot, (lat + 2)) == -1) {
            return false;
        }

        if (str.indexOf(" ") != -1) {
            return false;
        }

        return true
    },

    /////////////////////////////////////////////////////////////
    //              NUMBER FUNCTION                            //
    /////////////////////////////////////////////////////////////
    NumberAddCommas: function (nStr) {
        nStr = nStr.replace(/,/g, '');
        nStr += '';

        nStr = "" + (parseFloat(nStr) - 0);
        if (nStr == 'NaN') return "";

        x = nStr.split('.');
        x1 = x[0];
        x2 = x.length > 1 ? '.' + x[1] : '';
        var rgx = /(\d+)(\d{3})/;
        while (rgx.test(x1)) {
            x1 = x1.replace(rgx, '$1' + ',' + '$2');
        }
        return x1 + x2;
    },

    // Only allow input number with . (dot) ==> Float
    IsNumberKeyDot: function (evt) {
        var charCode = (evt.which) ? evt.which : event.keyCode;
        if (charCode != 46) {
            if ((charCode > 31) && (charCode < 48 || charCode > 57))
                return false;
        }
        return true;
    },

    // Only allow input number and no . (dot) ==> Integer
    IsNumberKey: function (evt) {
        var charCode = (evt.which) ? evt.which : event.keyCode;
        if ((charCode > 31) && (charCode < 48 || charCode > 57))
            return false;
        return true;
    },

    /////////////////////////////////////////////////////////////
    //              DECODE UNICODE                             //
    /////////////////////////////////////////////////////////////
    DecodeUnicode: function (str) {
        str = str.toLowerCase();
        str = str.replace(/à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ/g, "a");
        str = str.replace(/è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ/g, "e");
        str = str.replace(/ì|í|ị|ỉ|ĩ/g, "i");
        str = str.replace(/ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ/g, "o");
        str = str.replace(/ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ/g, "u");
        str = str.replace(/ỳ|ý|ỵ|ỷ|ỹ/g, "y");
        str = str.replace(/đ/g, "d");
        str = str.replace(/!|@|%|\^|\*|\(|\)|\+|\=|\<|\>|\?|\/|,|\.|\:|\;|\'| |\"|\&|\#|\[|\]|~|$|_/g, "-");
        /* tìm và thay thế các kí tự đặc biệt trong chuỗi sang kí tự - */
        str = str.replace(/-+-/g, "-"); //thay thế 2- thành 1-
        str = str.replace(/^\-+|\-+$/g, "");
        //cắt bỏ ký tự - ở đầu và cuối chuỗi
        return str;
    },

    DecodeUnicodeToAscii: function (str) {
        str = str.toLowerCase();
        str = str.replace(/à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ/g, "a");
        str = str.replace(/è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ/g, "e");
        str = str.replace(/ì|í|ị|ỉ|ĩ/g, "i");
        str = str.replace(/ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ/g, "o");
        str = str.replace(/ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ/g, "u");
        str = str.replace(/ỳ|ý|ỵ|ỷ|ỹ/g, "y");
        str = str.replace(/đ/g, "d");
        return str;
    },

    /////////////////////////////////////////////////////////////
    //              SHOW LOADING NOTIFICATION                  //
    /////////////////////////////////////////////////////////////
    getScrollTop: function () {
        if (document.documentElement.scrollTop)
            return document.documentElement.scrollTop;
        return document.body.scrollTop;
    },

    scrollHandler: function () {
        var e = document.getElementById('rc_notify');
        e.style.top = Other.getScrollTop();
    },

    showNotify: function (str) {
        var elem = document.getElementById('rc_notify');
        elem.style.display = 'block';
        elem.style.visibility = 'visible';

        elem.innerHTML = "" + str;
    },

    hideNotify: function () {
        var elem = document.getElementById('rc_notify');
        elem.style.display = 'none';
        elem.style.visibility = 'hidden';
        window.onscroll = null;
    },

    /////////////////////////////////////////////////////////////
    //              SHOW POPUP OTHER WINDOW                    //
    /////////////////////////////////////////////////////////////
    PopupCenter: function (pageURL, title, w, h) {
        var left = (screen.width / 2) - (w / 2);
        var top = 10 + (screen.height / 2) - (h / 2);
        var targetWin = window.open(pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
    }

};

var Other = new Other_Class();
