﻿var curFavShareSel = 0;                                         //  目前分享还是收藏, 默认0是收藏并分享，1表示只分享给好友
var boxWin;
var webRoot = ".";
$(document).ready(function() {
    if ($("#globalSpaceWebRoot")) {
        webRoot = $("#globalSpaceWebRoot").val();
    }
});
function favorshare(sel) {
    if (sel == 0) {
        curFavShareSel = 0;
        $('#favsh0').addClass("curSel");
        $('#favsh1').removeClass("curSel");
        document.getElementById("stdiv").style.display = "block";
    }
    else {
        curFavShareSel = 1;
        $('#favsh1').addClass("curSel");
        $('#favsh0').removeClass("curSel");
        document.getElementById("stdiv").style.display = "none";
    }
}

function getContentHtml(nickname, title, content, favurl, favtype) {
    var html = "";
    if (favtype == 2 || favtype == 5) {                         //  日志与话题收藏
        //        html += "         <div class='favPane_content1'>来自：<span id='fnick'>" + nickname + "</span></div>";
        //        html += "         <div class='favPane_content2'><a href='" + favurl + "' title='浏览日志' target='_blank'>" + title + "</a></div>";
        //        html += "         <div class='favPane_content3' id='fcontent'>" + content + "</div>";
        html += "<div class=\"shareDiary\">";
        html += "<h4 class=\"diaryIcon\">";
        html += "<a href=\"" + favurl + "\" title=\"浏览日志\" target=\"_blank\">" + title + "</a>";
        html += "</h4>";
        html += "<div class=\"shareBody\">";
        html += content;
        html += "</div>";
        html += "</div>";
        html += "";
        html += "";
        html += "";
        html += "";

    }
    else if (favtype == 3) {                                    //  相片收藏
//        html += "         <div><a href='" + content + "' alt='' ><img src='" + favurl + "' onload='autoSize(this,50,50)' alt='' title='" + title + "' /> </a></div>";
//        html += "         <div style='float:left;'>";
//        html += "             <div><a href='" + content + "'>" + title + "</a></div>";
//        html += "             <div>来自:" + nickname + "</div>";
//        html += "         </div>";
        html += "<div class=\"shareDiary\">";
        html += "<h4 class=\"photoIcon\">";
        html += "<a href=\"" + content + "\" title=\"查看相片\" target=\"_blank\">" + title + "</a>";
        html += "</h4>";
        html += "<div class=\"shareBody\">";
        html += "<a href='" + content + "' alt='' ><img src='" + favurl + "' onload='autoSize(this,50,50)' alt='' title='" + title + "' /> </a>";
        html += "</div>";
        html += "</div>";
    }
    else if (favtype == 4) {                                    //  音乐收藏
        //        html += "         <div class='fhf'>来自：<span id='fnick'>" + nickname + "</span></div>";
        //        html += "         <div>";
        //        html += "             <img src='/skin/images/musicPlayer/musicIcon.gif' alt='' />";
        //        html += "             <a href='" + favurl + "' title='听听吧'>" + title + "</a>";
        //        html += "         </div>";
        html += "<div class=\"shareDiary\">";
        html += "<h4 class=\"musicIcon\">";
        html += "<a href=\"" + favurl + "\" title=\"听听吧\" target=\"_blank\">" + title + "</a>";
        html += "</h4>";
        html += "</div>";
    }
    else if (favtype == 7) {
        //html += "          <div>小游戏:" + title + "</div>";
        html += "<div class=\"shareDiary\">";
        html += "<h4 class=\"gameIcon\">";
        html += "小游戏:" + title;
        html += "</h4>";
        html += "</div>";
    }
    return html;
}

function showFavBox(uin, nickname, title, content, favurl, favtype, objid, desc) {
    //    var html = "<div class='favPane_container'>";
    //    html += "<ul class='favPane_tabnav'>";
    //    html += "</ul><div style='clear:both'></div>";
    //    html += "<div class='favPane_item'>";
    //    html += "<div class='favPane_l' style='float:left'>收藏理由</div>";
    //    html += "<div class='favPane_r' style='float:left'>";
    //    html += "<textarea id='favReason' class='area250_50' rows='5' cols='40' >";
    //    if (desc) html += desc;
    //    html += "</textarea>";
    //    html += "</div>";
    //    html += "</div><div style='clear:both'></div>";
    //    html += "<div class='favPane_item'>";
    //    html += "<div class='favPane_l' style='float:left'>";
    //    html += "分享给：";
    //    html += "</div>";
    //    html += "<div class='favPane_r' style='float:left'>";
    //    html += initSearchBox();
    //    html += "</div>";
    //    html += "</div><div style='clear:both'></div>";
    //    html += getContentHtml(nickname, title, content, favurl, favtype);
    //    html += "<div class='favPane_content4'>";
    //    html += "<input type='button' class='btnNormal' id='btnNormalBtn' onclick=\"addToFavorite(" + uin + ",'" + nickname + "','" + title + "','" + content + "','" + favurl + "'," + favtype + "," + objid + ");\" value='确定' title='添加到收藏' />&nbsp;&nbsp;&nbsp;&nbsp;";
    //    html += "<input type='button' class='btnCancel' id='btnCancel' onclick='cancelAction();' value='取消' title='取消' />";
    //    html += "<label id='favtishi'></label>";
    //    html += "</div>";
    //    html += "</div>";
    var html = "";
    html += "<div class=\"sharePop\" style=\"width: 400px;\">";
    html += "<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">";
    html += "<tr>";
    html += "<td align=\"right\" valign=\"top\" width=\"80px;\">";
    html += "收藏理由:";
    html += "</td>";
    html += "<td>";
    html += "<textarea id=\"favReason\" class=\"inputNormal\" rows=\"5\" cols=\"40\" style=\"width: 300px; height: 80px;\">";
    if (desc) {
        html += desc;
    }
    html += "</textarea>";
    html += "</td>";
    html += "</tr>";
    html += "<tr>";
    html += "<td align=\"right\" valign=\"top\">";
    html += "分享给:";
    html += "</td>";
    html += "<td>";
    html += "<div>";
    html += initSearchBox();
    html += "</div>";
    html += "</td>";
    html += "</tr>";
    html += "<tr>";
    html += "<td align=\"right\" valign=\"top\">";
    html += "来自:";
    html += "</td>";
    html += "<td>";
    html += "<a href=\"/" + uin + "\">" + nickname + "</a>";
    html += "</td>";
    html += "</tr>";
    html += "</table>";
    html += getContentHtml(nickname, title, content, favurl, favtype); ;
    html += "";
    html += "";
    html += "";
    html += "";
    html += "";
    html += "";
    html += "<p align=\"center\">";
    html += "<input type='button' class='btnNormal' id='btnNormalBtn' onclick=\"addToFavorite(" + uin + ",'" + nickname + "','" + title + "','" + content + "','" + favurl + "'," + favtype + "," + objid + ");\" value='确定' title='添加到收藏' />&nbsp;&nbsp;&nbsp;&nbsp;";
    html += "<input type='button' class='btnCancel' id='btnCancel' onclick='cancelAction();' value='取消' title='取消' />";
    html += "<label id='favtishi'></label>";
    html += "</p>";
    var param = { "type": "div", "divContent": html, "title": "加入我的收藏", "w": 430 };
    spaceWindow(param);
    initInputBox(10);
}

function addToFavorite(uin, nickname, title, content, favurls, favtype, objid) {
    var url = "/" + webRoot + "/h/AddFavorite.ashx";
    var ids = getIdsValue();
    var idsStr = "";                                            //  表示当前选择的好友：-1表示没有选择好友(不分享给好友), 0表示分享给所有好友, 或是好友id的cvs
    if (ids.length > 0) {
        idsStr = "" + ids[0];
        for (var i = 1; i < ids.length; ++i) {
            idsStr += "," + ids[i];
        }
    }    
    var desc = document.getElementById("favReason").value;
    var param;
    if (favtype == 3) {
        param = {
            'uin': uin,
            'title': title,
            'content': favurls,
            'reason': desc,
            'idsStr': idsStr,
            'favtype': favtype,
            'url': content,
            'objid': objid
        };
    }
    else if (favtype == 7) {                                    //  小游戏收藏

        param = {
            'uin': uin,
            'title': title,
            'content': content,
            'reason': desc,
            'idsStr': idsStr,
            'favtype': favtype,
            'url': favurls,
            'objid': objid
        };
    }
    else {
        param = {
            'uin': uin,
            'title': title,
            'content': content,
            'reason': desc,
            'idsStr': idsStr,
            'favtype': favtype,
            'url': getFavUrl(favtype,favurls),
            'objid': objid
        };
    }    
    $.post(
        url,
        param,
        function(data) {
            var params = {
                leftx: 0,                                       //  偏移el的坐标
                topy: -20,                                      //  偏移el的坐标
                width: 200,                                     //  宽
                height: 50,                                     //  高
                type: "text",                                   //  消息，还有一种是div:里面可以传自己写的DIV进去
                closetime: 1500                                 //  自动消失时间，设为0，或不传,永远显示，只能手动关闭  ［SpacecloseTip('id1') 手动关闭的函数］
            };
            if (data == "0") {
                $("#favtishi").html("收藏失败");
            }
            else {
                $("#favtishi").html("收藏成功");
                window.setTimeout("cancelAction()", 1000);
            }
        }
    );
}

//  获取URL
function getFavUrl(favtype,favurls) {
    if (favtype == 2 || favtype == 5) {                         //  日志与话题收藏
        //return window.location.href.substr(window.location.href.indexOf('/', 7));
        return favurls;
    }
    else if (favtype == 3) {                                    //  相片收藏
        return "";
    }
    else if (favtype == 4) {                                    //  音乐收藏
        return "";
    }
}

function checkthis(chk) {
    var chkToFriend = document.getElementById("chkToFriend");
    var chkToSome = document.getElementById("chkToSome");
    if (chk == 0 && chkToSome.checked && chkToFriend.checked) {
        chkToSome.checked = false;
    }
    if (chk == 1 && chkToFriend.checked && chkToSome.checked) {
        chkToFriend.checked = false;
    }
}


function cancelAction() {
    closeSpaceWindow();
}