﻿function displayClassMore()
{
    document.getElementById("moreLink").style.display = "none";
    document.getElementById("moreClass").style.display = "block";
}
function UrlRewriter(state)
{
    var url = top.location.href;
    var sindex = url.indexOf("/s-");
    if(sindex > 0)
    { 
        if(state != "1" && state != "2")
        {
            top.location.href= url.substring(0,sindex+1);
        }
    }
}
function UrlRewriter()
{
    var url = top.location.href;
    var sindex = url.indexOf("/ask/?c=");
    if(!url.endWith("/") && sindex<0)
    {
       top.location.href= url+"/";
    }
}
String.prototype.endWith=function(str){   
    if(str==null||str==""||this.length==0||str.length>this.length)   
      return false;   
    if(this.substring(this.length-str.length)==str)   
      return true;   
    else  
      return false;   
    return true;   
} 
    
function keyDown() 
{ 
    var e=event.srcElement;        
    if(event.keyCode==13) 
    {  
        search();
    }
} 
function search() {
    var keyStr = document.getElementById("TxtSearch").value;
    if(keyStr == "")
    {
        alert("提示：请先输入您想获得的问题。\n\n技巧：关键字尽可能短，多个关键字以空格隔开。\n\n示例：NOKIAN73  怎么样");
        $(".keyinput").val("").focus();
        return false;
     }
     document.location.href = "/Question/Search.aspx?key=" + escape(keyStr);
}
function ask(stat) {
    var s = "";
    if (stat != "")
        s = "&stat=" + stat;
        
    var keyStr = document.getElementById("TxtSearch").value;
        //document.location.href = "/ask/AskDetal.aspx?title=" + keyStr+s;
    document.location.href = "/ask/";
}
function setHome(obj){   
    obj.style.behavior='url(#default#homepage)';   
    obj.setHomePage('http://www.zhigou.com');   
    return false;   
} 
function setCollect(){   
    window.external.AddFavorite('http://www.zhigou.com/','智购打听 -- 解决您的购物问题');return false
}
function GetTopLoginInfo() {
    $.getJSON("http://pia.zhigou.com/user/aaa.ashx?callback=?", { mode: "1", stamp: Math.round(Math.random() * 100000000) }, function(json) { SetTopLoginInfo(json); });
}
function SetTopLoginInfo(json) {
    var html = '';
    if (json.isloggedin == "1") {
        html += '<ul><li class="login">欢迎你，' + json.username + ' [<a href="javascript:logoutUserFromTopBar();">退出</a>]</li>'
        html += '<li><a href="http://www.zhigou.com">智购首页</a>|</li>'
        html += '<li><a href="http://my.zhigou.com">我的智购</a>|</li>'
        html += '<li><a title="收藏本站以备不时之需，竭诚为您服务" onclick="setCollect()" href="#">加入收藏</a>|</li>'
        html += '<li><a onclick="setHome(this)" href="#">设为首页</a>|</li>'
        html += '<li><a href="http://www.zhigou.com/service/index.html">客服中心</a></li>'
        html += '</ul>'
        html += '<span></span>'; 
    }
    else {
        html += '<ul><li><a href="http://my.zhigou.com/signup.html?returnurl=' + escape(window.location.href) + '">免费注册</a>|</li>'
        html += '<li><a href="http://my.zhigou.com/signin.html?returnurl=' + escape(window.location.href) + '">登陆</a>|</li>'
        html += '<li><a href="http://www.zhigou.com">智购首页</a>|</li>'
        html += '<li><a title="收藏本站以备不时之需，竭诚为您服务" onclick="setCollect()" href="#">加入收藏</a>|</li>'
        html += '<li><a onclick="setHome(this)" href="#">设为首页</a>|</li>'
        html += '<li><a href="http://www.zhigou.com/service/index.html">客服中心</a></li>'
        html += '</ul>'
        html += '<span></span>';
    }
    $("#login_h_div").html(html);
}
function logoutUserFromTopBar() {
    $.getJSON("http://pia.zhigou.com/user/aaa.ashx?callback=?", { mode: "4", stamp: Math.round(Math.random() * 100000000) }, function(json) { logoutUserFromTopBarHandler(json) });
}
function logoutUserFromTopBarHandler(json) {
    if (json.isloggedin == "0") {
        var html = '';
        html += '<ul><li><a href="http://my.zhigou.com/signup.html?returnurl=' + escape(window.location.href) + '">免费注册</a>|</li>'
        html += '<li><a href="http://my.zhigou.com/signin.html?returnurl=' + escape(window.location.href) + '">登陆</a>|</li>'
        html += '<li><a href="http://www.zhigou.com">智购首页</a>|</li>'
        html += '<li><a title="收藏本站以备不时之需，竭诚为您服务" onclick="setCollect()" href="#">加入收藏</a>|</li>'
        html += '<li><a onclick="setHome(this)" href="#">设为首页</a>|</li>'
        html += '<li><a href="http://www.zhigou.com/service/index.html">客服中心</a></li>'
        html += '</ul>'
        html += '<span></span>';
        $("#login_h_div").html(html);
    }    
    document.location.reload(); 
}
function NavUrl()
{
    var url = top.location.href;
    document.getElementById("index").className = "";
    document.getElementById("p").className = "";
    document.getElementById("m").className = "";
    document.getElementById("z").className = "";
    if(url.indexOf("/p/")>-1)
    {
        document.getElementById("p").className = "on";
    }
    else if(url.indexOf("/m/")>-1)
    {
        document.getElementById("m").className = "on";
    }
    else if(url.indexOf("/z/")>-1)
    {
        document.getElementById("z").className = "on";
    }
    else
    {
        var tempIndex =url.indexOf(".com/");
        var temp = url.substr(tempIndex+5) 
        temp = temp.replace("index.html", "");
        if(temp.length<3)
        {
            document.getElementById("index").className = "on";
        }
        else
        {
            document.getElementById("p").className = "on";
        }
    }
}
function DeleteQuestion(qid)
{
    if(confirm('你真的要删除吗？')){
        $.getJSON("/Ajax/Question.ashx", {mode:"2",qID:qid,stamp:Math.round(Math.random()*100000000)},function(json){DeleteQuestionHandler(json);});
    }
}
function DeleteQuestionHandler(json)
{
    if (json.state == "0") {
        alert('删除问题失败！');
    }  
    else
    {
        alert('删除问题成功！');
        top.location.href=json.url;
    }
}
function DeleteAnswer(qid,aid)
{
    if(confirm('你真的要删除吗？')){
        $.getJSON("/Ajax/Question.ashx", {mode:"5",qID:qid,aID:aid,stamp:Math.round(Math.random()*100000000)},function(json){DeleteAnswerHandler(json);});
    }
}
function DeleteAnswerHandler(json)
{
     if (json.state == "0") {
        alert('删除回答失败！');
    }  
    else
    {
        alert('删除回答成功！');
        top.location.href=json.url;
    }
}
function DeleteComment(qid,cid)
{
    if(confirm('你真的要删除吗？')){
        $.getJSON("/Ajax/Question.ashx", {mode:"6",qID:qid,cID:cid,stamp:Math.round(Math.random()*100000000)},function(json){DeleteCommentHandler(json);});
    }
}
function DeleteCommentHandler(json)
{
     if (json.state == "0") {
        alert('删除评论失败！');
    }  
    else
    {
        alert('删除评论成功！');
        top.location.href=json.url;
    }
}