﻿//当前评分的显示对象
var VoteObj = null;

//支持一个资源
function _GoSupport(infoRID, infoType, obj) {
    var xxx = V3.ID.WebSite.WService.DataSubmit.EvaluateSupport(infoRID, infoType, OnVote);
    VoteObj = obj;
}

//反对一个资源
function _GoAgainst(infoRID, infoType, obj) {
    V3.ID.WebSite.WService.DataSubmit.EvaluateAgainst(infoRID, infoType, OnVote);
    VoteObj = obj;
}

//通过星星控件打分
function _starEvaluateGo(infoRID, value, eType, infoType,objID) {
    V3.ID.WebSite.WService.DataSubmit.Evaluate(infoRID, value, eType, infoType, OnStarVote);
    VoteObj = $get(objID);
}

//评分结果显示
function OnVote(result) {
    if (result > -10000) {
        if (VoteObj != null) {
            VoteObj.innerHTML = result;
        }
    }
    else {
        if (result == -10000.01) {
            alert("您已参与了该项的评分，请不要重复针对一个项目进行评分！");
        }
    }

    VoteObj = null;
}

//星星评分结果显示
function OnStarVote(result) {
    if (result > -10000) {
        if (VoteObj != null) {
            V3.ID.WebSite.WService.DataSubmit.Get5StarEvaluate(result, "感谢您的评分！",OnGet5StarEvaluate);
            
        }
    }
    else {
        if (result == -10000.01) {
            alert("您已参与了该项的评分，请不要重复针对一个项目进行评分！");
            VoteObj = null;
        }
    }

    

}

//星星评分结果HTML序列化展示
function OnGet5StarEvaluate(result) {
    if (VoteObj != null) {
        VoteObj.innerHTML = result;
        VoteObj = null;
    }
}

// 星星打分组件
// Ajax Rating
// Thank you for Author:Jianglb.com
// Hunter edited 2008.8

var xmlhttp
/*@cc_on@*/
/*@if (@_jscript_version >= 5)
try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP")
} catch (e) {
    try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
    } catch (E) {
        xmlhttp = false
    }
}
@else
	 xmlhttp=false
	@end
@*/
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
        xmlhttp = new XMLHttpRequest();
    } catch (e) {
        xmlhttp = false
    }
}
function myXMLHttpRequest() {
    var xmlhttplocal;
    try {
        xmlhttplocal = new ActiveXObject("Msxml2.XMLHTTP")
    } catch (e) {
        try {
            xmlhttplocal = new ActiveXObject("Microsoft.XMLHTTP")
        } catch (E) {
            xmlhttplocal = false;
        }
    }

    if (!xmlhttplocal && typeof XMLHttpRequest != 'undefined') {
        try {
            var xmlhttplocal = new XMLHttpRequest();
        } catch (e) {
            var xmlhttplocal = false;
            alert('couldn\'t create xmlhttp object');
        }
    }
    return (xmlhttplocal);
}

function sndReq(vote, id_num, ip_num, units, story) {

    if (story != 1) {
        var theUL = document.getElementById('unit_ul_story' + id_num); // the UL

    }
    else {
        var theUL = document.getElementById('unit_ul' + id_num); // the UL
    }
    // switch UL with a loading div
    theUL.innerHTML = '<div class="loading"></div>';

    xmlhttp.open('get', '/rpc.php?j=' + vote + '&q=' + id_num + '&t=' + ip_num + '&c=' + units + '&s=' + story + '&rnd=' + Math.random());
    xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);
}

function handleResponse() {
    if (xmlhttp.readyState == 4) {
        if (xmlhttp.status == 200) {

            var response = xmlhttp.responseText;
            var update = new Array();

            if (response.indexOf('|') != -1) {
                update = response.split('|');
                changeText(update[0], update[1]);
            }
        }
    }
}

function changeText(div2show, text) {
    // Detect Browser
    var IE = (document.all) ? 1 : 0;
    var DOM = 0;
    if (parseInt(navigator.appVersion) >= 5) { DOM = 1 };

    // Grab the content from the requested "div" and show it in the "container"
    if (DOM) {
        var viewer = document.getElementById(div2show);
        viewer.innerHTML = text;
    } else if (IE) {
        document.all[div2show].innerHTML = text;
    }
}