﻿function addBookmark(title, url) {
    var url = window.location.href;
    var title = document.title;
    if (window.sidebar) {
        window.sidebar.addPanel(title, url, "");
    }
    else if (document.all) {
        window.external.AddFavorite(url, title);
    }
    else if (window.opera && window.print) {
        return true;
    }
}
function submitVote() {
    var voteid = $("#voteid").val();
    var quesid = $("#quesid").val();
    var choiceid;
    if (voteid == -1 || quesid == -1) {
        alert("抱歉,投票出错了!");
        return;
    }
    var b = false;
    $("input[name='currentVote']").each(function() { if ($(this).attr("checked")) { choiceid = $(this).val(); b = true; return; } });
    if (!b || choiceid.length == 0) {
        alert("请选择选项!");
        return;
    }
    $.ajax({

        type: "post",

        url: "/Action/PostVote.aspx",

        data: { VoteID: voteid, QuesID: quesid, ChoiceID: choiceid },

        dataType: 'text',

        error: function(msg) { alert(msg); },

        success: function(msg) { alert(msg); }

    });
}
function viewResult() {
    var voteid = $("#voteid").val();
    var quesid = $("#quesid").val();
    window.location.href = "/Action/ViewVote.aspx?VoteID=" + voteid + "&QuesID=" + quesid;
}
(function($) {
    $.fn.jMarquee = function(o) {
        o = $.extend({
            speed: 250,
            step: 1,
            direction: "up",
            visible: 1
        }, o || {});

        var i = 0;
        var div = $(this);
        var ul = $("ul", div);
        var tli = $("li", ul);
        var liSize = tli.size();
        if (o.direction == "left")
            tli.css("float", "left");
        var liWidth = tli.innerWidth();
        var liHeight = tli.height();
        var ulHeight = liHeight * liSize;
        var ulWidth = liWidth * liSize;


        if (liSize > o.visible) {
            ul.append(tli.slice(0, o.visible).clone())
            li = $("li", ul);
            liSize = li.size();


            div.css({ "position": "relative", overflow: "hidden" });
            ul.css({ "position": "relative", margin: "0", padding: "0", "list-style": "none" });
            li.css({ margin: "0", padding: "0", "position": "relative" });

            switch (o.direction) {
                case "left":
                    div.css("width", (liWidth * o.visible) + "px");
                    ul.css("width", (liWidth * liSize) + "px");
                    li.css("float", "left");
                    break;
                case "up":
                    div.css({ "height": (liHeight * o.visible) + "px" });
                    ul.css("height", (liHeight * liSize) + "px");
                    break;
            }


            var MyMar = setInterval(ylMarquee, o.speed);
            ul.hover(
            function() { clearInterval(MyMar); },
            function() { MyMar = setInterval(ylMarquee, o.speed); }
        );
        };
        function ylMarquee() {
            if (o.direction == "left") {
                if (div.scrollLeft() >= ulWidth) {
                    div.scrollLeft(0);
                }
                else {
                    var leftNum = div.scrollLeft();
                    leftNum += parseInt(o.step);
                    div.scrollLeft(leftNum)
                }
            }

            if (o.direction == "up") {
                if (div.scrollTop() >= ulHeight) {
                    div.scrollTop(0);

                }
                else {
                    var topNum = div.scrollTop();
                    topNum += parseInt(o.step);
                    div.scrollTop(topNum);
                }
            }

        };

    };

})(jQuery);

String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
function keysBlur(el) {
    if (el.value.length == 0) {
        el.style.color = "#cccccc";
        el.value = "--输入关键字--";
    }
    else if (el.value == "--输入关键字--") {
        el.style.color = "#cccccc";
    }
    else {
        el.style.color = "#4B4B4B";
    }
}
function clearTxt(el) {
    if (el.value == "--输入关键字--") {
        el.value = "";
        el.style.color = "#cccccc";
    }
}
function dosearch(pd) {
    $("#keyWord")[0].focus();
    var keys = $("#keyWord").val();
    var siteid = $("#siteid").val();
    var nodes = new Array();
    if (pd == "zw") {
        nodes = ["-1", "-1", "16", "-1"];
    }
    if (pd == "news") {
        nodes = ["-1", "-1", "16", "-1", "-1"];
    }
    var i = 0;
    var nodename;
    var nodeid;
    $(".searchtitle div").each(function() { if ($(this).attr("class").indexOf("focus") > -1) { nodename = $(this).text(); nodeid = nodes[i]; return; } i++; });
    var q = "";
    if (keys.trim().length == 0) {
        alert("请输入关键字!");
        $("#keyWord")[0].focus();
        return;
    }
    q = "?keys=" + keys;
    if (nodeid) {
        q += "&nodeid=" + nodeid;
        q += "&nodename=" + nodename;
    }
    if (siteid) {
        q += "&id=" + siteid;
    }
    window.location.href = "/search.aspx" + q;
}
function dosearchnews() {
    var keys = $("#txtkeyWord").val();
    if (keys.trim().length == 0) {
        alert("请输入关键字!");
        $("#txtkeyWord")[0].focus();
        return;
    }
    window.location.href = "/search.aspx?keys=" + keys + "&nodeid=" + nodeid;
}
function switchEffect(obj, idx, type) {
    var src = obj.src;
    if (type) {
        src = "Images/m" + idx + ".jpg";
    }
    else {
        src = "Images/m" + idx + "a.jpg";
    }
    obj.src = src;
}
jQuery.fn.loadthumb = function(options) {
    options = $.extend({
        src: ""
    }, options);
    var _self = this;
    _self.fadeOut("fast");
    var img = new Image();
    $(img).load(function() {
        _self.attr("src", options.src);
        _self.fadeIn("fast");
    }).attr("src", options.src);
    return _self;
}
function Inpart(ob) {
    var voteid = $(ob).prev().val();
    window.location.href = "Suvery.aspx?VoteID=" + voteid;
}
function topage(keys, pagecount, pid) {
    var idx = $("#custompage").val();
    var v = Number(idx);
    if (v && v > 0) {
        if (v > pagecount) {
            alert("页数超出范围!");
            $("#custompage").val(pagecount);
            //window.location.href="column.aspx?pid="+columnid+"&page="+pagecount;
        }
        else {
            if (keys.length == 0) {
                window.location.href = "column.aspx?pid=" + pid + "&page=" + v;
            }
            else {
                if (pid > 0) {
                    window.location.href = "columnshow.aspx?keys=" + keys + "&pid=" + pid + "&page=" + v;
                }
                else {
                    window.location.href = "columnshow.aspx?keys=" + keys + "&page=" + v;
                }
            }
        }
    }
    else {
        alert("请输入合法的页码!");
        $("#custompage")[0].focus();
        return;
    }
}

function topagefood(cls, clsValue, pagecount, pid) {
    var idx = $("#custompage").val();
    var v = Number(idx);
    if (v && v > 0) {
        if (v > pagecount) {
            alert("页数超出范围!");
            $("#custompage").val(pagecount);
            //window.location.href="column.aspx?pid="+columnid+"&page="+pagecount;
        }
        else {

            window.location.href = "column.aspx?ID" + cls + "=" + clsValue + "&pid=" + pid + "&page=" + v;


        }
    }
    else {
        alert("请输入合法的页码!");
        $("#custompage")[0].focus();
        return;
    }
}

function topagebyurl(keys, pagecount, pid, url) {
    var idx = $("#custompage").val();
    var v = Number(idx);
    if (v && v > 0) {
        if (v > pagecount) {
            alert("页数超出范围!");
            $("#custompage").val(pagecount);
            //window.location.href="column.aspx?pid="+columnid+"&page="+pagecount;
        }
        else {
            if (keys.length == 0) {
                window.location.href = url + "?pid=" + pid + "&page=" + v;
            }
            else {
                if (pid > 0) {
                    window.location.href = "columnshow.aspx?keys=" + keys + "&pid=" + pid + "&page=" + v;
                }
                else {
                    window.location.href = "columnshow.aspx?keys=" + keys + "&page=" + v;
                }
            }
        }
    }
    else {
        alert("请输入合法的页码!");
        $("#custompage")[0].focus();
        return;
    }
}

//用于景区图片详细页
function topagebyAlbumurl(keys, pagecount, pid, cid, url) {
    var idx = $("#custompage").val();
    var v = Number(idx);
    if (v && v > 0) {
        if (v > pagecount) {
            alert("页数超出范围!");
            $("#custompage").val(pagecount);
            //window.location.href="column.aspx?pid="+columnid+"&page="+pagecount;
        }
        else {
            if (keys.length == 0) {
                window.location.href = url + "?pid=" + pid + "&cid=" + cid + "&page=" + v;
            }
            else {
                if (pid > 0) {
                    window.location.href = "columnshow.aspx?keys=" + keys + "&pid=" + pid + "&page=" + v;
                }
                else {
                    window.location.href = "columnshow.aspx?keys=" + keys + "&page=" + v;
                }
            }
        }
    }
    else {
        alert("请输入合法的页码!");
        $("#custompage")[0].focus();
        return;
    }
}

//用于景区酒店预订栏目翻页
function topagebyHotelurl(code, pagecount, pid, url) {
    var idx = $("#custompage").val();
    var v = Number(idx);
    if (v && v > 0) {
        if (v > pagecount) {
            alert("页数超出范围!");
            $("#custompage").val(pagecount);
            //window.location.href="column.aspx?pid="+columnid+"&page="+pagecount;
        }
        else {
            if (code.length > 0) {
                window.location.href = url + "?Code=" + code + "&pid=" + pid + "&page=" + v;
            }
            else {
                if (pid > 0) {
                    window.location.href = "columnshow.aspx?Code=" + code + "&pid=" + pid + "&page=" + v;
                }
                else {
                    window.location.href = "columnshow.aspx?Code=" + code + "&page=" + v;
                }
            }
        }
    }
    else {
        alert("请输入合法的页码!");
        $("#custompage")[0].focus();
        return;
    }
}

//去除字符串空格
String.prototype.Trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

//前台推荐酒店列表
function showHoteldiv(i, rows) {
    for (var j = 0; j < rows; j++) {
        if (i == j) {
            $("#dv_" + j).css({ display: "" });
            $("#sev_" + j).addClass('selected');
        }
        else {
            $("#dv_" + j).css({ display: "none" });
            $("#sev_" + j).removeClass('selected');
        }
    }
}
function CityChange(tag,value)
{
  if(tag==1)
  {
     var dobj=document.getElementById("country");
     dobj.length=1;
     if(value=="-1")
     {
        return;
     }
     
     for(var i=0;i<CountryArrObj.length;i++)
    {
       if(CountryArrObj[i][1].substring(0,4)==value)
       {
          dobj.options[dobj.length]=new Option(CountryArrObj[i][0],CountryArrObj[i][1]); 
       }
    }     
  }
 else
 {
     var severdobj=document.getElementById("server");
     severdobj.length=1;
     if(value=="-1")
     {
        return;
     }  
     for( var i=0;i<ServerArrObj.length;i++)
    {
       if(ServerArrObj[i][1].substring(0,7)==value)
       {
          severdobj.options[severdobj.length]=new Option(ServerArrObj[i][0],ServerArrObj[i][1]); 
       }
    } 
 }
}

//景区首页 检测搜索表单输入
//tag=1:城市搜索
//tag=2:景区搜索
function checkSearchForm(tag) {
 
    var BeginDate=null;
    var EndDate=null;
    if(tag==2)
    {
       BeginDate = $("#BeginDate2");
       EndDate = $("#EndDate2");
        if (BeginDate.val().Trim() == "") {
        alert("请选择入住时间");
        document.getElementById("BeginDate2").focus();
        return false;
    }
    if (EndDate.val().Trim() == "") {
        alert("请选择离店时间");
        document.getElementById("EndDate2").focus();
        return false;
    }
       
        CheckTime_home("BeginDate2", "EndDate2");
    }
    else
    {
      BeginDate = $("#BeginDate");
      EndDate = $("#EndDate");
     if (BeginDate.val().Trim() == "") {
        alert("请选择入住时间");
        document.getElementById("BeginDate").focus();
        return false;
    }
    if (EndDate.val().Trim() == "") {
        alert("请选择离店时间");
        document.getElementById("EndDate").focus();
        return false;
    }
    CheckTime_home("BeginDate", "EndDate");
    }
    

    //searchForm.submit();
}

//判断时间
function CheckTime_home(startID, endID) {
    var DayNum = 0;
    var StartTimeString = $("#" + startID).val();
    var EndTimeString = $("#" + endID).val();
    if (StartTimeString == "" || EndTimeString == "") {
        if (StartTimeString == "") {
            $("#" + startID).focus();
        }
        else {
            $("#" + endID).focus();
        }
        return 0;
    }
    var StartDate = new Date(StartTimeString.replace(/-/g, "/"));
    var EndDate = new Date(EndTimeString.replace(/-/g, "/"));
    if (StartDate > EndDate) {
        $("#" + startID).val(EndTimeString);
        $("#" + endID).val(StartTimeString);
        StartDate = new Date(EndTimeString.replace(/-/g, "/"));
        EndDate = new Date(StartTimeString.replace(/-/g, "/"));

    }
    DayNum = (EndDate - StartDate) / 1000 / 60 / 60 / 24;
    if (DayNum == 0) {
        alert("你入住和离店日期不应相等！");
        $("#" + endID).focus();
        return 0;
    }
    return DayNum;
}

//login 用户登录
function checkLogin() {
    var name = $("#name").val();
    var pwd = $("#pwd").val();
    if (name.trim() == "") {
        alert("请输入账号"); return false;
    }
    if (pwd.trim() == "") { alert("请输入密码"); return false; }
    $.ajax({
        type: "post",
        url: "/Ajax/LoginAjax.aspx",
        data: { name: name, pwd: pwd },
        dataType: 'text',
        error: function(msg) { alert(msg.responseText); },
        success: function(msg) {
            if (msg == "1") { window.location.reload(); }
            else { alert("用户名或密码错误，请重新输入"); }
        }
    });
}


document.onkeydown = function(e) {
    e = e || window.event;
    if (e.keyCode == 13) {
        var btnLogin = document.getElementById("btnLogin");
        if (btnLogin != null && btnLogin != undefined) {
            document.getElementById("btnLogin").click();
            return false;
        }
    }
}


//login 用户登录
function LoginOut() {
    $.ajax({
        type: "post",
        url: "/Ajax/LoginOutAjax.aspx",
        data: { name: "" },
        dataType: 'text',
        error: function(msg) { alert(msg.responseText); },
        success: function(msg) {
            window.location.reload();
        }
    });
}

//提交评论
$(document).ready(function() {



    //判断Enter键事件
//    var userBox = document.getElementById("userBox");
//    if (userBox != null || userBox != undefined) {
//        userBox.onkeydown = function() {
//            if (e.keyCode == 13) {
//                var btnLogin = document.getElementById("btnLogin");
//                if (btnLogin != null && btnLogin != undefined) {
//                    document.getElementById("btnLogin").click();
//                    return false;
//                } 
//            }
//        }
//    }

//    var userBox = document.getElementById("userBox");
//    if (userBox != null || userBox != undefined) {
//        userBox.onkeydown = function() {
//            if (e.keyCode == 13) {
//                var btnLogin = document.getElementById("btnLogin");
//                if (btnLogin != null && btnLogin != undefined) {
//                    document.getElementById("btnLogin").click();
//                    return false;
//                }
//            }
//        }
//    }




    $("#CommentSubmit").click(function() {
        //参数
        var cid = "", pid = "", commenttext = "", CommentContent = "", nickname = "", contact = "", siteid1 = "", email = "", islogin = 0, checkCode1 = "";
        cid = request("cid");
        pid = request("pid");
        siteid1 = getCookie("SiteID");
        var tableName = $("#tbn").val();
        var titleName = $("#TitleName").val();
        commenttext = $("#CommentContent").val();
        if ($("#CommentName").val() == undefined) {
            //已经登录的情况
            islogin = 1;
        }
        else {
            //未登录的情况
            nickname = $("#CommentName").val();
            contact = $("#CommentTel").val();
            CommentContent = $("#CommentContent").val();
            email = $("#CommentEmail").val();
            checkCode1 = $("#CommentCheckCode").val();
            if (nickname.trim() == "") { alert("请输入您的称呼"); $("#CommentName").focus(); return false; }
            if (contact.trim() == "") { alert("请输入手机号码"); $("#CommentTel").focus(); return false; }
            if (CommentContent.trim() == "") { alert("请输入评论内容"); $("#CommentContent").focus(); return false; }
            if (checkCode1.trim() == "") { alert("请输入验证码!"); $("#CommentCheckCode").focus(); $("#imgCheckCode").click(); return false; }
        }
        $.ajax({
            type: "post",
            url: "/Ajax/PSMComment.aspx",
            data: { titlename: titleName, tablename: tableName, cid: cid, pid: pid, commenttext: commenttext, nickname: nickname, contact: contact, siteid1: siteid1, email: email, islogin: islogin, checkCode1: checkCode1 },
            dataType: 'text',
            error: function(msg) { alert(msg.responseText); },
            success: function(msg) {
                //msg = msg.responseText;
                if ($("#CommentSubmit").val() == "报名") { msg = msg.replace("发表评论", "报名"); }
                alert(msg);
                if (msg == "发表评论成功!" || msg == "报名成功!") { $("#CommentCheckCode").val(""); $("#CommentContent").val(""); $("#CommentEmail").val(""); $("#CommentName").val(""); $("#CommentTel").val(""); $("#imgCheckCode").click(); }
                if (msg == "请输入验证码!" || msg == "请输入正确的验证码!") { $("#CommentCheckCode").focus(); $("#CommentCheckCode").val(""); $("#imgCheckCode").click(); }
            }
        });
    });
}
);

//写cookies函数 
function SetCookie(name, value)//两个参数，一个是cookie的名子，一个是值
{
    //var Days = 30; //此 cookie 将被保存 30 天
    var exp = new Date();    //new Date("December 31, 9998");
    exp.setTime(exp.getTime() + 5 * 60 * 1000);
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}
function getCookie(name)//取cookies函数        
{
    var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
    if (arr != null) return unescape(arr[2]); return null;

}
function delCookie(name)//删除cookie
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = getCookie(name);
    if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}
//获取网页参数
function request(paras) {
    var url = location.href;
    var paraString = url.substring(url.indexOf("?") + 1, url.length).split("&");
    var paraObj = {}
    for (i = 0; j = paraString[i]; i++) {
        paraObj[j.substring(0, j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=") + 1, j.length);
    }
    var returnValue = paraObj[paras.toLowerCase()];
    if (typeof (returnValue) == "undefined") {
        return "";
    } else {
        return returnValue;
    }
}

function showSelradio(i) {
    if (i == 1) {
        $("#scenicLi").hide();
        $("#cityLi").show();
    }
    else if (i == 2) {
        $("#scenicLi").show();
        $("#cityLi").hide();
    }
}
Date.prototype.format = function(format) {
    var o = {
        "M+": this.getMonth() + 1, //month   
        "d+": this.getDate(),    //day   
        "h+": this.getHours(),   //hour   
        "m+": this.getMinutes(), //minute   
        "s+": this.getSeconds(), //second   
        "q+": Math.floor((this.getMonth() + 3) / 3), //quarter   
        "S": this.getMilliseconds() //millisecond   
    }
    if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
     (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o) if (new RegExp("(" + k + ")").test(format))
        format = format.replace(RegExp.$1,
       RegExp.$1.length == 1 ? o[k] :
         ("00" + o[k]).substr(("" + o[k]).length));
    return format;
}
Date.prototype.addDays = function(d) {
    this.setDate(this.getDate() + d);
};
