﻿
/*全局处理JS*/

//去除两边空格
String.prototype.trim = function() { return this.replace(/(^\s*)|(\s*$)/g, ""); }
// 正则判断日期格式
function isDate(str) {
    var reg = /^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$/
    if (reg.test(str)) return true;
    return false;
}
//大小判断，转成日期变量，然后比较符判断即可
function CheckDatesBS(date1, date2) {
    try {
        var v1Ary = date1.split('-');
        var v2Ary = date2.split('-');
        var d1 = new Date(v1Ary[1] + '/' + v1Ary[2] + '/' + v1Ary[0]); //出发日期
        var d2 = new Date(v2Ary[1] + '/' + v2Ary[2] + '/' + v2Ary[0]); //返回日期
        if (d1 > d2) { return false; }
        else { return true; }
    } catch (e) { alert(e); }
}
//获取当前元素的X，Y位置
function XP_getPoint(source) {
    var pt = { x: 0, y: 0 };
    do { pt.x += source.offsetLeft; pt.y += source.offsetTop; source = source.offsetParent; }
    while (source);
    return pt;
}
// 获取三字代码
function XP_Get3Code(str) {
    var regExp = /\(([A-Z]{3})\)/;
    if (regExp.exec(str) != null) { var author = RegExp.$1; return author }
    else { if (str.length == 3) { if (isEN(str)) { return str; } else { return ""; } } return ""; }
}
//让层居中显示
function setDivToCenter(obj) {
    obj.style.position = "absolute";
    obj.style.zIndex = "99999"
    obj.style.display = "block";
    obj.style.top = (document.documentElement.scrollTop + (document.documentElement.clientHeight - obj.offsetHeight) / 2) + "px";
    obj.style.left = (document.documentElement.scrollLeft + (document.documentElement.clientWidth - obj.offsetWidth) / 2) + "px";
}
//让IFREAM自动适应高度
function reSetIframe(iframe) {
    try {
        var bHeight = iframe.contentWindow.document.body.scrollHeight;
        var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
        var height = Math.max(bHeight, dHeight);
        iframe.height = height;
    } catch (ex) { }
}
//隐藏父窗体中的对象
function hideParentObj(objID) {
    $("#" + objID + "").hide();
}
//处理无法显示图片
function SetErrorImgByClass(className) {
    $("." + className + "").error(function() {
        this.src = '/images/error/cover.jpg';
    });
}
function SetErrorImgById(id) {
    $("#" + id + "").error(function() {
        this.src = '/images/error/cover.jpg';
    });
}
//载入
$(document).ready(function() {
    $(".txt_search").bind("focus", function() {
        if (this.value == '请输入景区/景点') {
            $(this).val('');
        }
    })
    $(".txt_search").bind("blur", function() {
        if (this.value == '') {
            $(this).val('请输入景区/景点');
        }
    })
    $(".btn_search,.default_btn_search").bind("click", function() {
        if ($(".txt_search").val() == '') {
            alert('请输入景区/景点');
        }
        else {
            var searchUrl = '/search.aspx?keyword=' + encodeURIComponent($(".txt_search").val());
            window.open(searchUrl);
        }
    })
    bindLeftNav();
})
//绑定左侧的导航
function bindLeftNav() {
    $(".left_nav li").hover(function() {
        $(this).addClass("left_nav_li_hover");
    },
    function() {
        $(this).removeClass("left_nav_li_hover");
    })
}
//左侧菜单选中
function selectLeftNav(id) {    
    $("#" + id + "").addClass("left_nav_li_select");
}
//更新IP统计信息
function getUpdateIpTotal() {
    $.ajax({
        url: "/AjaxData/GetUpdateIpTotal.ashx",
        cache: false
    });
}