﻿function drop_mouseover(pos){
	try{window.clearTimeout(timer);}catch(e){}
}
function drop_mouseout(pos){
	var posSel=document.getElementById(pos+"Sel").style.display;
	if(posSel=="block"){
		timer = setTimeout("drop_hide('"+pos+"')", 1000);
	}
}
function drop_hide(pos){
	document.getElementById(pos+"Sel").style.display="none";
}
function search_show(pos,searchType,href){
    document.getElementById("cateID").value = searchType;
    document.getElementById(pos+"Sel").style.display="none";
    document.getElementById(pos+"Slected").innerHTML=href.innerHTML;
    document.getElementById('q').focus();
    var sE = document.getElementById("searchExtend");
    if(sE != undefined && searchType == "bar"){
    	sE.style.display="block";
    }else if(sE != undefined){
    	sE.style.display="none";
    }
	try{window.clearTimeout(timer);}catch(e){}
	return false;
}

function enterClick(id) {

    if (event.keyCode == 13) {
        event.keyCode = 9;
        event.returnValue = false;
        $("#" + id).click();
    }
}

function TabClick(region, tab, tabs) {
    for (var i = 1; i <= tabs; i++) {           
        $("#" + region + "Title" + i).attr("class", "tab");
        $("#" + region + i).hide();
    }
    $("#" + region + "Title" + tab).attr("class", "cur");
    $("#" + region + tab).show();
}

function TabClick2(region, tab, tabs) {
    for (var i = 1; i <= tabs; i++) {
        $("#" + region + "Title" + i).removeAttr("class");
        $("#" + region + i).hide();
    }
    $("#" + region + "Title" + tab).attr("class", "cur");
    $("#" + region + tab).show();
}

var searchType = 1;
var searchTextWidth = $('#q').width();
function AutoComplete() {
    $("#q").autocomplete("/key/GetSimilarKey?type=" + searchType + "&" + Math.random(), {
        minChars: 0,
        width: searchTextWidth,
        matchContains: "word",
        autoFill: false,
        delay: 5,
        dataType: "json",
        parse: function (data) {
            return $.map(data, function (row) {
                return {
                    data: row,
                    value: row.Name,
                    result: row.Name
                }
            });
        },
        formatItem: function (row, i, max) {
            var item = "<table id='auto" + i + "' style='width:95%;'><tr><td align='left'>" + row.Name + "</td> <td align='right' style='color:#e6e6e6;'>" + ' 约"' + row.Count + '"结果' + "</td> </tr>  </table>";

            return item;
        },
        formatMatch: function (row, i, max) {
            return row.Name;
        },
        formatResult: function (row) {
            return row.Name;
        }
    }).result(function (e, row) {
        location.href = '/Search/List?type=' + searchType + '&q=' + encodeURI(row.Name);
    });
};
$(document).ready(function () {
    if (typeof $("[name=type]") != "undefined")
        searchType = $("[name=type]").attr("value");
    $("input[name=type]").click(function () { searchType = $("input[name=type]:checked").attr("value"); AutoComplete(); });
    AutoComplete();

    var valueQ = $.queryString('q');
    $("#q").val(valueQ);
});

function SendDiamond(toUserID,bookID) {
    $.getJSON("/User/SendDiamond?" + Math.random(), { toUserID: toUserID, bookID: bookID }, function (json) {
        if (json.IsOk) {
            alert(json.Msg);
            $('#Diamond').html(json.StatusCode);
        }
        else {
            if (json.StatusCode == -1) {
                alert('你还没登录，请登录！');
                $('#LoginID').focus();
                return;
            }
            alert(json.Msg);
        }
    });
}

function SendFlower(toUserID, bookID) {
    $.getJSON("/User/SendFlower?" + Math.random(), { toUserID: toUserID, bookID: bookID }, function (json) {
        if (json.IsOk) {
            alert(json.Msg);
            $('#Flower').html(json.StatusCode);
        }
        else {
            if (json.StatusCode == -1) {
                alert('你还没登录，请登录！');
                $('#LoginID').focus();
                return;
            }
            alert(json.Msg);
        }
    });
}

function AwardAuthor(toUserID, bookID) {
    $.getJSON("/User/AwardAuthor?" + Math.random(), { toUserID: toUserID, bookID: bookID }, function (json) {
        if (json.IsOk) {
            alert(json.Msg);
            $('#Award').html(json.StatusCode);
        }
        else {
            if (json.StatusCode == -1) {
                alert('你还没登录，请登录！');
                $('#LoginID').focus();
                return;
            }
            else if (json.StatusCode == -2) {
                alert('你当前积分不足，请充值！打赏每次150积分');
                $('#LoginID').focus();
                return;
            }
            alert(json.Msg);
        }
    });
}

function MagicPen(toUserID, bookID) {
    $.getJSON("/User/MagicPen?" + Math.random(), {toUserID: toUserID, bookID: bookID }, function (json) {
        if (json.IsOk) {
            alert(json.Msg);
            $('#MagicPen').html(json.StatusCode);
        }
        else {
            if (json.StatusCode == -1) {
                alert('你还没登录，请登录！');
                $('#LoginID').focus();
                return;
            }
            else if (json.StatusCode == -2) {
                alert('你当前积分不足，请充值！誉为神笔每次100积分');
                $('#LoginID').focus();
                return;
            }
            alert(json.Msg);
        }
    });
}

function ThrowingEggs(toUserID, bookID) {
    $.getJSON("/User/ThrowingEggs?" + Math.random(), { toUserID: toUserID, bookID: bookID }, function (json) {
        if (json.IsOk) {
            alert(json.Msg);
            $('#Egg').html(json.StatusCode);
        }
        else {
            if (json.StatusCode == -1) {
                alert('你还没登录，请登录！');
                $('#LoginID').focus();
                return;
            }
            alert(json.Msg);
        }
    });
}

function Coffee(toUserID, bookID) {
    $.getJSON("/User/Coffee?" + Math.random(), { toUserID: toUserID, bookID: bookID }, function (json) {
        if (json.IsOk) {
            alert(json.Msg);
            $('#Coffee').html(json.StatusCode);
        }
        else {
            if (json.StatusCode == -1) {
                alert('你还没登录，请登录！');
                $('#LoginID').focus();
                return;
            }
            alert(json.Msg);
        }
    });
}

function Bookshelf(bookID) {
    $.getJSON("/User/Bookshelf?" + Math.random(), {bookID: bookID }, function (json) {
        if (json.IsOk) {
            alert(json.Msg);
        }
        else {
            if (json.StatusCode == -1) {
                alert('你还没登录，请登录！');
                $('#LoginID').focus();
                return;
            }
            alert(json.Msg);
        }
    });
}

function RecommendInfo(bookID) {
    $.getJSON("/User/RecommendInfo?" + Math.random(), {bookID: bookID }, function (json) {
        if (json.IsOk) {
            alert(json.Msg);
        }
        else {
            if (json.StatusCode == -1) {
                alert('你还没登录，请登录！');
                $('#LoginID').focus();
                return;
            }
            alert(json.Msg);
        }
    });
}

function Subscribe(bookID) {
    $.getJSON("/User/Subscribe?" + Math.random(), { bookID: bookID }, function (json) {
        if (json.IsOk) {
            alert(json.Msg);
        }
        else {
            if (json.StatusCode == -1) {
                alert('你还没登录，请登录！');
                $('#LoginID').focus();
                return;
            }
            alert(json.Msg);
        }
    });
}

function DownLoad(bookID) {
    $.getJSON("/User/CheckLogin?" + Math.random(), function (json) {
        if (json.IsLogin) {
			window.open("http://www.eastshu.com/Download/" + bookID+".zip","_blank");
        }
        else {
            alert('你还没登录，请登录！登录后才能下载。');
            $('#LoginID').focus();
            return;
        }
    });
}

function SetCurrentTab(tabID) {
    $('.menu .nav ul li').removeClass();
    $('#' + tabID).addClass('cur');
}

function fayin(url) {
    document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="20" height="20">');
    document.write('<param name="wmode" value="transparent">');
    document.write('<param name="movie" value="http://img.eastshu.com/flash/fayin.swf" />');
    document.write('<param name="quality" value="high" />');
    document.write('<param name="flashVars" value="lj=' + url + '" />');
    document.write('<embed flashvars="lj=' + url + '" src="http://img.eastshu.com/flash/fayin.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="20" height="20"></embed>');
    document.write('</object>');
}

function Setswf(width, height, url) {
    document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="' + width + '" height="' + height + '">');
    document.write('<param name="movie" value="' + url + '">');
    document.write('<param name="quality" value="high">');
    document.write('<param name="wmode" value="Opaque">');
    //透明document.write('<param name="wmode" value="transparent">');
    document.write('<param name="menu" value="false">');
    document.write('<embed src="' + url + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '"></embed>');
    document.write('</object>');
}
