function fav() {
    doFav(document.URL, document.title);
}

function copyurl() {
    //
}

function doFav(url,text) {
    window.external.AddFavorite(url, text) 
}

function setImg(img, width, height) {
    var scale_w = img.width / width;
    var scale_h = img.height / height;
    var scale = scale_w > scale_h ? scale_w : scale_h;

    var val = img.width / scale;

    if (val < img.width) {
        img.width = val;
    }
    return false;
}

function middleimage(sender) {
    $(sender).parent().wrapAll("<table width=100% height=100%><tr><td align=center></td></tr></table>");
}

function GetQueryString(sProp) {
    var re = new RegExp("[&,?]" + sProp + "=([^\\&]*)", "i");
    var a = re.exec(document.location.search);
    if (a == null)
        return "";
    return decodeURI(a[1]);
}

var homeExtShopInfoArr = new Array();
$(function() {

    $(".favurl").click(function() { fav(); });
    $(".copyurl").click(function() { copyurl(); });

    $(".middleimage").each(function() {
        $(this).wrapAll("<table width=100% height=100%><tr><td align=center></td></tr></table>");
    });

    $(".quitsession").click(function() {
        quitSession();
    });

    $(".htab .tabs a").bind("mouseenter", function() {
        $(".htab .tabs a").removeClass("chked");
        $(this).addClass("chked");
        $(".numlist ul").css("display", "none");
        $(".numlist ." + this.id).css("display", "");
    });

    $(".container .tabs a").bind("mouseenter", function() {
        $(".container .tabs a").removeClass("chked");
        $(this).addClass("chked");
        $(".container ul").css("display", "none");
        $(".container ." + this.id).css("display", "");
    });

    $(".autotab .tabs .tab").bind("mouseenter", function() {
        $(this).parent().parent().find(".tab").removeClass("chked");
        $(this).addClass("chked");
        $(this).parent().parent().find(".panelitem").css("display", "none");
        //$(".autotab .panelitem").css("display", "none");
        $(".autotab ." + this.id).css("display", "");
    });

    $(".txtkeywords").bind("change", function() {
        if ($(this).val() == "") {
            $(this).css("backgroundImage", "url(" + $(".txtkeywords").attr("img") + ")"); //  /images/inputdef.gif
            $(this).css("backgroundRepeat", "no-repeat");
            $(this).css("backgroundPosition", "left center");
        } else {
            $(this).css("backgroundImage", "none");
        }
    });
    $(".txtkeywords").trigger("change");

    $(".txtkeywords").bind("focus", function() {
        if ($(this).css("backgroundImage").indexOf($(this).attr("img")) > -1) {
            $(this).css("backgroundImage", "none");
        }
    });

    $(".txtkeywords").bind("blur", function() {
        if ($(this).val() == "") {
            $(this).css("backgroundImage", "url(" + $(this).attr("img") + ")");
        }
    });

    $(".loginstatus").html("载入中..");
    $.ajax({
        url: "/inc/aspx/LoginStatus.aspx",
        data: {},
        cache: false,
        success: function(html) {
            $(".loginstatus").html(html);
        }
    });

    $(".topsearchbtn").click(function() {
        if ($(".topsearchddl").val() == "news") {
            window.location = "/newslist.aspx?st=" + $(".topsearchddl").val() + "&keywords=" + encodeURI($(".txtkeywords").val());
        }
        else {
            window.location = "/shoplist.aspx?st=" + $(".topsearchddl").val() + "&keywords=" + encodeURI($(".txtkeywords").val());
        }
    });

    $(".buildmyplan").click(function() {
        window.top.location = "/lovecenter/PersonPlans.aspx?type=2&date="
            + $("#planyear").val() + "-" + $("#planmonth").val() + "-" + $("#planday").val();
    });

    $("a.recomm").click(function() {
        if (getcookie("askpost" + $(this).attr("tag")) == "") {
            $.ajax({
                url: "/ask/VoteItem.aspx",
                data: { postid: $(this).attr("tag") },
                cache: false,
                success: function(html) {
                }
            });
            setcookie("askpost" + $(this).attr("tag"), 1);
            $(this).find("span").html(parseInt($(this).find("span").html()) + 1);
            alert("您已投票成功。");
        }
        else {
            alert("抱歉，您已投票过。");
        }
    });

    $("a.use").click(function() {
        if (!confirm("确实要采纳该答案吗？")) return;

        $.ajax({
            url: "/ask/AcceptAsk.ashx",
            data: { postid: $(this).attr("tag") },
            cache: false,
            success: function(html) {
                if (html == "1") {
                    alert("恭喜您，已成功采纳该答案。");
                    window.location.reload();
                }
                else
                    alert("系统忙，采纳失败。");
            }
        });
    });

    $(".newsdetailintro").html("<strong>福建婚嫁网版权与免责声明 </strong><br /><ul><li>1、凡本网注明“来源：福建婚嫁网”的所有作品，版权均属福建婚嫁网所有，未经本网书面授权不得转载、摘编、复制或利用其他方式使用上述作品。已经本网授权使用作品的，被授权人应在授权范围内使用，并注明“来源：福建婚嫁网”。违反上述声明者，本网将追究其相关法律责任。</li><li>2、本网其他来源作品，均转载自其他媒体，转载目的在于传播更多信息，丰富网络文化，此类稿件不代表本网观点。</li><li>3、任何单位或个人认为本网站或本网站链接内容可能涉嫌侵犯其合法权益，应该及时向本网站反馈，权属证明及详细侵权情况证明，本网站将会尽快移除被控侵权的内容或链接。</li></ul>");
    $(".barrister").html("法律顾问：福建格律律师事务所 郑磊律师");

    /* 以下是问答内容 */
    $(".askbtmschbtn").click(function() {
        if ($(".askbtmschtxt").attr("value").length < 4) {
            alert("请输入大于4个字符的内容。");
            return;
        }
        window.location = "/ask/AskList.aspx?isfind=true&keyword=" + encodeURI($(".askbtmschtxt").attr("value"));
    });

    $(".askbtmdobtn").click(function() {
        if ($(".askbtmschtxt").attr("value").length < 4) {
            alert("请输入大于4个字符的内容。");
            return;
        }
        window.location = "/ask/PostQuestion.aspx?keyword=" + encodeURI($(".askbtmschtxt").attr("value"));
    });

    $(".searchbutton").click(function() {
        if ($(".txtkeywords").attr("value").length < 4) {
            alert("请输入大于4个字符的内容。");
            return;
        }
        window.location = "/ask/AskList.aspx?isfind=true&keyword=" + encodeURI($(".txtkeywords").attr("value"));
    });

    $(".askbutton").click(function() {
        if ($(".txtkeywords").attr("value").length < 4) {
            alert("请输入大于4个字符的内容。");
            return;
        }
        window.location = "/ask/PostQuestion.aspx?keyword=" + encodeURI($(".txtkeywords").attr("value"));
    });

    $(".asksearch").click(function() {
        var txt = $("#" + $(this).attr("txtid"));
        if (txt.attr("value").length < 4) {
            alert("请输入大于4个字符的内容。");
            return;
        }
        window.location = "/ask/AskList.aspx?keyword=" + txt.attr("value");
    });

    $(".block2_1 .logos li").mouseover(function() {
        if ($(this).attr("class") == "chked") return;
        $(".block2_1 .logos li").attr("class", "");
        $(this).attr("class", "chked");

        if ($(".block2_1 .tabcnt").height() < 250) {
            $(".block2_1 .tabcnt").animate({ height: 300 }, 500);
            $(".block2_1 .infos").slideDown(500);
        }

        for (var i = 0; i < homeExtShopInfoArr.length; i++) {
            if (homeExtShopInfoArr[i].shopid == $(this).attr("shopid")) {
                $(".block2_1 .infos").html(homeExtShopInfoArr[i].html);
                return;
            }
        }

        $(".block2_1 .infos").css("backgroundImage", "url(/images/lightbox-ico-loading.gif)");
        $(".block2_1 .infos").html("");
        var shopid = $(this).attr("shopid");
        $.ajax({
            url: "/inc/aspx/HomeExtendShopInfos.aspx",
            data: { shopid: $(this).attr("shopid") },
            cache: false,
            success: function(html) {
                homeExtShopInfoArr.push({ shopid: shopid, html: html });
                $(".block2_1 .infos").css("backgroundImage", "none");
                $(".block2_1 .infos").html(html);
            }
        });
    });

    $(".block2_1 .tabs a").bind("click", function() {
        if ($(".block2_1 .tabcnt").height() > 250) {
            $(".block2_1 .tabcnt").animate({ height: 140 }, 500, function() {
                $(".block2_1 .infos").hide();
                $(".block2_1 .logos li").attr("class", "");
            });
        }
        $(".block2_1 .infos").hide();
        $(".block2_1 .logos li").attr("class", "");
        

        $(".block2_1 .tabs a").attr("class", "");
        $(this).attr("class", "chked");
        $(".block2_1 .tabcnt .logos").hide();
        $("." + $(this).attr("id")).show();
    });
});

function changetsize(jqueryText, size) {
    $(jqueryText).css("fontSize", size);
}

function dispPlanDates() {
    var dateHtmls = "";
    var now = new Date();
    var myYears = (now.getYear() < 1900) ? (1900 + now.getYear()) : now.getYear();

    dateHtmls = "<select id='planyear'>"
    for (var i = myYears; i <= myYears + 5; i++) {
        dateHtmls += "<option>" + i + "</option>";
    }
    dateHtmls += "</select> "

    dateHtmls += "<select id='planmonth'>"
    for (var i = 1; i <= 12; i++) {
        dateHtmls += "<option>" + i + "</option>";
    }
    dateHtmls += "</select> "


    dateHtmls += "<select id='planday'>"
    for (var i = 1; i <= 31; i++) {
        dateHtmls += "<option>" + i + "</option>";
    }
    dateHtmls += "</select>"

    document.write(dateHtmls);
}

function quitSession() {
    if (confirm("确实要退出吗？")) {
        window.top.location = "/inc/aspx/logout.aspx";
    }
}

function fav() {
    window.external.addFavorite(document.location.href, document.title);
}

function setcookie(name,value){   
    var Days = 30;
    var exp  = new Date();   
    exp.setTime(exp.getTime() + Days*24*60*60*1000);   
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();   
}   
  
function getcookie(name){   
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));    
    if(arr != null){   
        return unescape(arr[2]);   
    }else{   
        return "";   
    }   
}   
 
function delcookie(name){   
    var exp = new Date();    
    exp.setTime(exp.getTime() - 1);   
    var cval=getCookie(name);   
    if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();   
}   
  
//delcookie("GD-cms");   
if (document.cookie != "") {    
    setcookie("GD-cms", "gae-django-cms");   
}
//alert(getcookie("GD-cms"));

$(".buildmyplan").click(function() {

});

