var qid="";
var qstyle="";
var selcount=0;
var uAddr="";

var speed=20//速度数值越大速度越慢
var value = -1;
var MyMar ;
var lens;

function GoodLoad()
{
    var  xmlData="<action>LinkLoadData</action>";

    xmlData=formatXmlData("",xmlData);
    result=sendXmlData(xmlData,"Main/service/service.jsp");
    if(!checkResult(result))
    {
        var errResult = getErrorMessage(result);
        if(errResult!=null)
        {
            alert(errResult);
        }
        return false;
    }
    else
    {
        var oDiv = document.createElement("DIV");
        oDiv.innerHTML = getErrorMessage(result);
        oDiv = oDiv.childNodes[0];
        var count = oDiv.getAttribute("count");
        var len = count/2;
        len = len + count % 2 / 2;

        var table = "<table cellSpacing='0' cellPadding='0' width='100%' border='0'><tr vAlign='top' align='center'>";
        for(i=0;i<count;i++){
            if(i == len){
                table += "</tr><tr>";
            }
            table += "<td align='center' valign='middle'>&nbsp;<img src='GoodLink/uploadImages/"+ oDiv.childNodes[i].getAttribute("imgurl");
            table += "' width='88'  height='31'";
            if(oDiv.childNodes[i].getAttribute("comurl") != ""){
                table += "onclick=\"window.open('"+ oDiv.childNodes[i].getAttribute("comurl") + "')\" style='cursor:hand'";
            }
            table += " alt='"+ replaceClientValue(oDiv.childNodes[i].getAttribute("comname")) +"'></td>";
        }
//        if(count%2 != 0){
//            table += "<td align='center' valign='middle'>&nbsp;<img src='"+ oDiv.childNodes[0].imgurl;
//            table += "' width='90' style='cursor:hand' height='33' onclick=window.open('"+ oDiv.childNodes[0].comurl;
//            table += "') alt='"+ replaceClientValue(oDiv.childNodes[0].comname) +"'></td>";
//        }
        table += "</tr></table>";
        document.getElementById('spana').innerHTML = table;
        if(count>=9)
        {
            document.getElementById('spanb').innerHTML = table;
        }
    }
}

function Marquee(){

    if(document.getElementById('demo')){


    if(window.ActiveXObject)
    {
        if(document.getElementById('demo').scrollLeft<=value){
            document.getElementById('demo').scrollLeft -= document.getElementById('demo1').offsetWidth;
            value = -1;
        }else{
            value = document.getElementById('demo').scrollLeft;
            document.getElementById('demo').scrollLeft++;
        }
    }
    else
    {
        if(document.getElementById('demo').scrollLeft<=value){
            document.getElementById('demo').scrollLeft -= document.getElementById('demo1').offsetWidth;
            value = -1;
        }else{
            value = document.getElementById('demo').scrollLeft;
            document.getElementById('demo').scrollLeft++;
        }
        /*
        if(isNaN(document.getElementById('demo').pageXOffset))
        {
            document.getElementById('demo').pageXOffset = 0;
            alert(document.getElementById('demo').scrollLeft );
            alert(document.getElementById('demo1').offsetWidth);
        }

        if(document.getElementById('demo').pageXOffset<=value){
            document.getElementById('demo').pageXOffset -= document.getElementById('demo1').offsetWidth;
            document.getElementById('demo').style.left='0px';
            value = -1;
        }else{
            value = document.getElementById('demo').pageXOffset;
            document.getElementById('demo').pageXOffset--;
            document.getElementById('demo').style.left=''+ document.getElementById('demo').pageXOffset +'px';
            //alert(document.getElementById('demo').style.left);
        }
        */
    }}
}
function MoseOver(){
    clearInterval(MyMar);
}
function MoseOut(){
    MyMar=setInterval(Marquee,speed);
}

function window_onload()
{
    var  xmlData="<action>FormLoadData</action><TYPE>1</TYPE><PAGENO>1</PAGENO>";

    MyMar = setInterval(Marquee,speed);
    xmlData=formatXmlData("",xmlData);
    result=sendXmlData(xmlData,"QuesAndAnswer/service/service.jsp");
    if(!checkResult(result))
    {
        var errResult = getErrorMessage(result);
        if(errResult!=null)
        {
            alert(errResult);
        }
        return false;
    }
    else
    {
        var oDiv = document.createElement("DIV");
        oDiv.innerHTML = getErrorMessage(result);
        if(oDiv.childNodes[0].getAttribute("repeat") == "0"){
            oDiv = oDiv.childNodes[0];
            var count = oDiv.getAttribute("pagerowcount");
            for(i=0;i<count;i++){
                document.getElementById('link_QA'+i).href = "QuesAndAnswer/QaDetail.jsp?oid=" + oDiv.childNodes[i].getAttribute("oid");
                if(window.ActiveXObject){
                    document.getElementById('span_QA'+i).innerText = cutString(oDiv.childNodes[i].getAttribute("question"),40);
                    document.getElementById('span_QAT'+i).innerText = oDiv.childNodes[i].getAttribute("time");
                }else if(window.XMLHttpRequest){
                    document.getElementById('span_QA'+i).textContent = cutString(oDiv.childNodes[i].getAttribute("question"),40);
                    document.getElementById('span_QAT'+i).textContent = oDiv.childNodes[i].getAttribute("time");
                }

                if(i == 4){
                    break;
                }
            }
        }
    }
    LoadData();
    UserApp();
    LoadQuestion();
    GoodLoad();
}

function UserApp()
{
    var  xmlData="<action>UserApp</action>";
    xmlData=formatXmlData("",xmlData);
    result=sendXmlData(xmlData,"Main/service/service.jsp");
    if(!checkResult(result))
    {
        var errResult = getErrorMessage(result);
        if(errResult!=null)
        {
            alert(errResult);
        }
        return false;
    }
    else
    {
        var oDiv = document.createElement("DIV");
        oDiv.innerHTML = getErrorMessage(result);
        qdiv=oDiv.childNodes[0];
        if(qdiv.getAttribute("repeat") == "0"){
            document.getElementById('link_APPNEW').href = "App/app.jsp?oid=" + qdiv.getAttribute("oid");
            document.getElementById('img_APPOPIC').src = "Testmzone/PIC/" + qdiv.getAttribute("opic");
            document.getElementById('img_APPCODEPIC').src = "Testmzone/CODE/" + qdiv.getAttribute("codepic");
            if(window.ActiveXObject){
                document.getElementById('span_APPTITLE').innerText = replaceClientValue(qdiv.getAttribute("title"));
                document.getElementById('span_APPOCHAR').innerText = replaceClientValue(qdiv.getAttribute("ochar"));
            }else if(window.XMLHttpRequest){
                document.getElementById('span_APPTITLE').textContent = replaceClientValue(qdiv.getAttribute("title"));
                document.getElementById('span_APPOCHAR').textContent = replaceClientValue(qdiv.getAttribute("ochar"));
            }
        }
    }
}

function LoadQuestion(){
    var  xmlData="<action>LoadQuestion</action>";
    xmlData=formatXmlData("",xmlData);
    result=sendXmlData(xmlData,"Main/service/service.jsp");
    if(!checkResult(result))
    {
        var errResult = getErrorMessage(result);
        if(errResult!=null)
        {
            document.getElementById('btn_SUBMIT').style.display = "none";
            document.getElementById('btn_OPEN').style.display = "none";
        }
        return false;
    }
    else
    {
        var oDiv = document.createElement("DIV");
        oDiv.innerHTML = getErrorMessage(result);
        qdiv=oDiv.childNodes[0];
        selcount=qdiv.getAttribute("count");
        if(window.ActiveXObject){
            document.getElementById('qname').innerText=qdiv.getAttribute("qname");
        }else if(window.XMLHttpRequest){
            document.getElementById('qname').textContent=qdiv.getAttribute("qname");
        }
        qid=qdiv.getAttribute("qid");
        qstyle=qdiv.getAttribute("qstyle");
        var seloption="<table>";
        for(var i=0;i<selcount;i++){
            adiv=qdiv.childNodes[i];
            seloption+="<tr><td>";
            if(qstyle=='0'){
                seloption+="<textarea id='txt_answer' name='textarea' cols='10' maxlength=''  rows='20' ></textarea>";
            }else if(qstyle=='1'){
                seloption+="<input type='radio' name='radio' value='"+adiv.getAttribute("aid")+"' onClick='selectQues(this)'/>"+adiv.getAttribute("aname");
            }else{
                seloption+="<input type='checkbox' name='checkbox' value='"+adiv.getAttribute("aid")+"' onClick='selectQues(this)'/>"+adiv.getAttribute("aname");
            }
            seloption+="</td></tr>";
        }
        seloption+="</table>";
        document.getElementById('qselect').innerHTML=seloption;

    }
}
var selData="";
function selectQues(temp){
    var aid=temp.value;
    if(qstyle=='1'){
        if(temp.checked==true){
            selData=aid;
        }
    }else{
        if(temp.checked==true){
            selData+="," + aid;
        }else{
            selData=selData.replace("," + aid,"");
        }
    }
}
function savequestion(){
    if(qstyle=='0'){
        if(textarea.text==""){
            return;
        }
    }else{
        if(selData==""){
            alert('请选择答案后再提交');
            return;
        }
    }
    var cb="";
    var  xmlData="<action>SaveAnswer</action>";
    xmlData+="<qid>"+qid+"</qid>";
    xmlData+="<uAddr>"+uAddr+"</uAddr>";
    xmlData+="<qstyle>"+qstyle+"</qstyle>";
    if(qstyle=='0'){
        xmlData+="<text>"+replaceValue(textarea.text)+"</text>";
    }else if(qstyle=='1'){
        xmlData+="<radio>"+selData+"</radio>";

    }else{
        xmlData+="<checkbox>"+selData+"</checkbox>";
    }
    xmlData=formatXmlData("",xmlData);
    result=sendXmlData(xmlData,"Main/service/service.jsp");
    if(!checkResult(result))
    {
        var errResult = getErrorMessage(result);
        if(errResult!=null)
        {
            alert(errResult);
        }
        return false;
    }
    else
    {
        var oDiv = document.createElement("DIV");
        oDiv.innerHTML = getErrorMessage(result);
        if(oDiv.childNodes[0].getAttribute("result")=="ok"){
            location.href = 'Main/succeed.jsp';
        }
    }
}
function LoadData()
{

//    var  xmlData="<action>LoadData</action>";
    var xmlData="<action>LoadListData</action><PAGENO>1</PAGENO><FILTER></FILTER><tableName>MOINNEWS</tableName>";
    xmlData=formatXmlData("",xmlData);
    result=sendXmlData(xmlData,"news/service/service.jsp");

    if(!checkResult(result))
    {
        var errResult = getErrorMessage(result);
        if(errResult!=null)
        {
            alert(errResult);
        }
        return false;
    }
    else
    {

        var oDiv = document.createElement("DIV");
        oDiv.innerHTML = getErrorMessage(result);
        oDiv = oDiv.childNodes[0];

        for(i=0;i<oDiv.childNodes.length;i++){
            if(oDiv.childNodes[i].getAttribute("oid")!="")
            {
                if(oDiv.childNodes[i].getAttribute("type") == "0"){
                    document.getElementById('link_VIEW'+i).href = "news/newsdetaile.jsp?oid=" + oDiv.childNodes[i].getAttribute("oid");
                }else{
                    document.getElementById('link_VIEW'+i).href = "news/" + oDiv.childNodes[i].getAttribute("oid");
                }
                if(window.ActiveXObject){
                    document.getElementById('span_News'+i).innerText = cutString(oDiv.childNodes[i].getAttribute("name"),40);
                    document.getElementById('span_TIME'+i).innerText = oDiv.childNodes[i].getAttribute("time");
                }else if(window.XMLHttpRequest){
                    document.getElementById('span_News'+i).textContent = cutString(oDiv.childNodes[i].getAttribute("name"),40);
                    document.getElementById('span_TIME'+i).textContent = oDiv.childNodes[i].getAttribute("time");
                }
            }
            if(i == 5){
                break;
            }
        }

    }
}
//function ViewNews(index)
//{
//    window.navigate('news/newsdetaile.jsp?oid=' + document.getElementById('span_NewsOID'+index).oid);
//}

function GotoNews()
{
    location.href = 'news/index.html';
}

//function QaChange(TYPE)
//{
//    var url = "QuesAndAnswer/QaDetail.jsp?oid=" + document.getElementById('span_OID' + TYPE).innerText;
////    f_openFullWindow(url,600,600);
//    window.navigate(url);
//}

function cutString(str, outputLen){
    var strLen,tLen, charCode;
    if(str==undefined){ return ""; }
    strLen=str.length;
    tLen=0;
    for(var i=0;i<strLen;i++){
        charCode=str.charCodeAt(i);
        if(charCode<0||charCode>255){ tLen+=2 }else{ tLen++ }
        if(tLen>=outputLen){ return str.substr(0,i)+"..."; }
    }
    return str;
}


function CreateCode()//创建手机条码
{
    location.href = 'CreateCodeManager/CreateCodeCARD.jsp?size=1&imgtype=2&level=0';
}



function DownLoad()//软件下载
{
    location.href = 'download/service/download.jsp?filename=soft/moin_personal_V1.exe&type=2';
//    window.location.replace('../download/index.htm');
}
function DownloadSMS()
{
    location.href = 'download/index.jsp';
}
function aQuestion()
{
   location.href = 'QuesAndAnswer/QuesAndAnswer.jsp?flag=1';
}

function ReadApp()//识读手机条码
{
    location.href = 'App/AppPage.jsp?page=1';
}

function showresult(){
    var  xmlData="<action>showresult</action>";
    xmlData=formatXmlData("",xmlData);
    result=sendXmlData(xmlData,"service/service.jsp");
    if(!checkResult(result))
    {
        var errResult = getErrorMessage(result);
        if(errResult!=null)
        {
            alert(errResult);
        }
        return false;
    }
    else
    {
        var oDiv = document.createElement("DIV");
        oDiv.innerHTML = getErrorMessage(result);
        qdiv=oDiv.childNodes[0];
        if(window.ActiveXObject){
            document.getElementById('person').innerText=qdiv.getAttribute("count");
            document.getElementById('qname').innerText=qdiv.getAttribute("qname");
        }else if(window.XMLHttpRequest){
            document.getElementById('person').textContent=qdiv.getAttribute("count");
            document.getElementById('qname').textContent=qdiv.getAttribute("qname");
        }
        var inhtml="<table width='490' border='0' cellspacing='2' cellpadding='0'>";
        var j=0;
        for(var i=0;i<qdiv.getAttribute("total");i++){
            sdiv=qdiv.childNodes[i];
            inhtml+="<tr><td width='130' height='25' align='left' bgcolor='#F0F0F0'>";
            inhtml+="<span id='sname_"+i+"'>"+sdiv.getAttribute("sname")+"</span>";
            inhtml+="</td><td width='60' height='25' align='center' bgcolor='#F0F0F0'>";
            inhtml+="<span id='ticket_"+i+"'>"+sdiv.getAttribute("count")+"票</span>";
            inhtml+="</td><td height='25' align='left' bgcolor='#F0F0F0'>";
            inhtml+="<img id='imgshow0' src='../images/colorbar_"+j+".gif' width='"+parseInt((parseInt(sdiv.getAttribute("count"))/parseInt(qdiv.getAttribute("num")))*100)*2+"' height='15' /></td><td width='100' height='25' align='left' bgcolor='#F0F0F0'>";
            j++;
            if(j>=5){
                j=0;
            }
            if(qdiv.getAttribute("num") == "0" && sdiv.getAttribute("count") == "0"){
                inhtml+="<span id='persent_"+i+"'>0%</span></td></tr>";
            }else{
                inhtml+="<span id='persent_"+i+"'>"+parseInt(parseInt(sdiv.getAttribute("count"))/parseInt(qdiv.getAttribute("num"))*100)+"%</span></td></tr>";
            }
        }
        inhtml+="</table>";
        document.getElementById('showdata').innerHTML=inhtml;
    }
}
