﻿// JavaScript Document
/*
Content: Common components;
Remark: index;
Version: v0.1;
Author: guanxin.com JF.Z;
Date: 2010-07-2
*/
var Question;  // Golbal Variable
var handle;
var page = 1;
$(function() {//重置单选框
    $(".RSch :radio").hide();
    $(".RSch :radio").each(function(i) {
        if ($(".RSch :radio").eq(i).attr("checked") == true) {
            $(".RSch").eq(i).addClass("RSClick")
        }
        $(".RSch").eq(i).click(function() {
            $(".RSch :radio").attr("checked", false);
            $(".RSch").removeClass("RSClick");
            $(".RSch :radio").eq(i).attr("checked", true);
            $(".RSch").eq(i).addClass("RSClick");
        })
    })
})

$(function() {//首页搜索
    $(".MIRCCSInput").click(function() {
        if ($(".RSch :radio").eq(0).attr("checked") == true) {
            window.open("http://info.guanxin.com/RetrieveArticle?title=" + escape($(".MIRCCSText").val()) + "&sort=1");   
        } else {
        window.open("http://shop.guanxin.com/Product?HeadSearch=" + escape($(".MIRCCSText").val()) + "&HeadSearchSelect=0&=");
        }
    })
})
$(function() {
    $(".MIRCCSLabel").click(function() {
        $(".MIRCCSText").focus()
    })
})
$(document).ready(function() {
	  
    GetDetails();
    $(".questionList-bg .questionList").append("<div class=\"question qSiteAll\"><a>查看更多</a></div>");
    GetAllQuestion();
});

/* 问题详细事件绑定== Start ==  问题列表事件绑定 */
function GetDetails() {
    setQuestionStie();
    $(".loading").hide();
    $(".questionList div.question a").click(
		function() {
		    $(".questionDetail").remove();
		    var a = this.id;
		    sendQuestion(a)
		}
	)
}

function GetAllQuestion() {
    page = page + 1;
    $(".questionList-bg .questionList").append("<div class=\"question qSiteAll\"><a>查看更多</a></div>");
    $(".qSiteAll").click(function() {
        $(".questionList").append("<div class=\"loading\"><img alt=\"\" src=\"http://static.guanxin.com/index/img/ajax-loader.gif\"></div>");
        var url = "/Ajax/GetQuestionAll.ashx";
        var pars = "{\"CurrentPage\":\"" + page + "\"}";
        pub_getws(url, getMoreAnswer, pars);
    });
}
/* End */

function sendQuestion(b) {
		
    var url = "/Ajax/GetQuestionDetails.ashx";
    var pars = "{\"ID\":\"" + b + "\"}";
    pub_getws(url, getAnswer, pars);
}

var Question;
function getAnswer(data) {
    if (data.JosnModel[0].Success == "1") {
        Question = data.QuestionDetails;
        $(".questionList-bg").hide();
        $(".questionDetail-bg").fadeIn("2000");
        $(".questionDetail-bg").append("<div class=\"questionDetail\"><div class=\"loading\" style=\"display:block\"><img alt=\"\" src=\"http://static.guanxin.com/index/img/ajax-loader.gif\"></div><div class=\"moreAnswer parentTitle\">" + data.JosnModel[0].Description + "</div></div>");
        handle = setInterval("addContent()", 200);
    }
    else {
        return false;
    }
}

function addContent() {
    $.each(Question, function(i, d) {
        $(".questionDetail").show().append("<div class=\"moreAnswer answer" + ++i + "\"><a target=\"_blank\" title=\"" + d.Title + "\" href=" + d.Link + ">" + d.Title + "</a></div>");
    });
    clearInterval(handle);
    setAnswerStie();
    $(".questionDetail").append("<div class=\"moreAnswer parentBack\"><a>返回</a></div>");
    $(".loading").remove();
    $(".parentBack").click(function() {
        $(".questionDetail-bg").hide();
        $(".questionList-bg").fadeIn(1000);
        $(".loading").hide();
    });
}

function getMoreAnswer(data) {
    if (data.JosnModel[0].Success == "1") {
        $(".questionList").children().remove();
         $(".questionList").append("<div class=\"loading\"><img alt=\"\" src=\"http://static.guanxin.com/index/img/ajax-loader.gif\"></div>")
        $.each(data.Question, function(i, d) {
            var j = ++i;
            $(".questionList-bg .questionList").append("<div class=\"question qSite" + j + "\"><a id=\"" + d.ID + "\" title=\"" + d.Title + "\" >" + d.Title + "</a></div><div class=\"question Answer aSite" + j + "\"><a id=\"" + d.ID + "\" title=\"" + d.Title + "\" href=\"javascript:void(0)\" style=\" text-decoration:none; cursor:pointer;\">" + d.Description + "</a></div>");
        });
        setQuestionStie();
        GetDetails();
        GetAllQuestion();
        $(".loading").hide();
    }
    else {
        return false;
    }
}
function setQuestionStie() {
    var listQa = new Array($(".qSite1 a"), $(".qSite2 a"), $(".qSite3 a"), $(".qSite4 a"), $(".qSite5 a"));
    var listQ = new Array($(".qSite1"), $(".qSite2"), $(".qSite3"), $(".qSite4"), $(".qSite5"));

    var listAa = new Array($(".aSite1 a"), $(".aSite2 a"), $(".aSite3 a"), $(".aSite4 a"), $(".aSite5 a"), $(".aSite6 a"));
    var listA = new Array($(".aSite1"), $(".aSite2"), $(".aSite3"), $(".aSite4"), $(".aSite5"), $(".aSite6"));

    //第一层
    listQ[0].css({ "top": (Math.ceil((129 - Math.ceil(listQa[0].text().length / 5) * 25) / 2) + 26) + "px" });
    listQ[1].css({ "top": (Math.ceil((113 - Math.ceil(listQa[1].text().length / 5) * 22) / 2) + 215) + "px" });
    listQ[2].css({ "top": (Math.ceil((95 - Math.ceil(listQa[2].text().length / 5) * 20) / 2) + 62) + "px" });
    listQ[3].css({ "top": (Math.ceil((129 - Math.ceil(listQa[3].text().length / 5) * 25) / 2) + 162) + "px" });
    listQ[4].css({ "top": (Math.ceil((85 - Math.ceil(listQa[4].text().length / 5) * 20) / 2) + 21) + "px" });
    //listQ[5].css({"top":(Math.ceil((71-Math.ceil(listQa[5].text().length/5)*20)/2)+61)+"px"});
    //第二层
    listA[0].css({ "top": (Math.ceil((71 - Math.ceil(listAa[0].text().length / 4) * 18) / 2) + 103) + "px" });
    listA[1].css({ "top": (Math.ceil((74 - Math.ceil(listAa[1].text().length / 4) * 18) / 2) + 227) + "px" });
    listA[2].css({ "top": (Math.ceil((61 - Math.ceil(listAa[2].text().length / 3) * 18) / 2) + 114) + "px" });
    listA[3].css({ "top": (Math.ceil((95 - Math.ceil(listAa[3].text().length / 6) * 18) / 2) + 164) + "px" });
    listA[4].css({ "top": (Math.ceil((74 - Math.ceil(listAa[4].text().length / 4) * 18) / 2) + 56) + "px" });
    //listA[5].css({"top":(Math.ceil((74-Math.ceil(listAa[5].text().length/4)*18)/2)+75)+"px"});

}
function setAnswerStie() {
    var listAsa = new Array($(".parentTitle"), $(".answer1 a"), $(".answer2 a"), $(".answer3 a"), $(".answer4 a"), $(".answer5 a"), $(".answer6 a"), $(".answer7 a"), $(".answer8 a"));
    var listAs = new Array($(".parentTitle"), $(".answer1"), $(".answer2"), $(".answer3"), $(".answer4"), $(".answer5"), $(".answer6"), $(".answer7"), $(".answer8"));
    //第三层
    listAs[0].css({ "top": (Math.ceil((129 - Math.ceil(listAsa[0].text().length / 5) * 28) / 2) + 68) + "px" });
    listAs[1].css({ "top": (Math.ceil((113 - Math.ceil(listAsa[1].text().length / 6) * 20) / 2) + 185) + "px" });
    listAs[2].css({ "top": (Math.ceil((113 - Math.ceil(listAsa[2].text().length / 6) * 20) / 2) + 62) + "px" });
    listAs[3].css({ "top": (Math.ceil((95 - Math.ceil(listAsa[3].text().length / 5) * 20) / 2) + 222) + "px" });
    listAs[4].css({ "top": (Math.ceil((95 - Math.ceil(listAsa[4].text().length / 5) * 20) / 2) + 49) + "px" });
    listAs[5].css({ "top": (Math.ceil((95 - Math.ceil(listAsa[5].text().length / 5) * 20) / 2) + 180) + "px" });
    listAs[6].css({ "top": (Math.ceil((80 - Math.ceil(listAsa[6].text().length / 4) * 20) / 2) + 36) + "px" });
    listAs[7].css({ "top": (Math.ceil((80 - Math.ceil(listAsa[7].text().length / 4) * 20) / 2) + 140) + "px" });
    listAs[8].css({ "top": (Math.ceil((80 - Math.ceil(listAsa[8].text().length / 4) * 20) / 2) + 54) + "px" });
}