function getXMLHTTPRequest() {
	var xRequest=null;
	if (window.XMLHttpRequest) {
		xRequest=new XMLHttpRequest();
	} else if (typeof ActiveXObject != "undefined") {
		xRequest=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return xRequest;
}

function sendRequest(callback,url,params,HttpMethod){
	if (!HttpMethod){
		HttpMethod="POST";
	}
	var req=getXMLHTTPRequest();
	if (req){
		req.onreadystatechange= function() {
			var ready=req.readyState;
			var data=null;
			if (ready==4){
				data=gb2utf8(req.responseBody);				
				callback(data);
			} else {
				data="loading...["+ready+"]";
			}
		};
		req.open(HttpMethod,url,true);
		req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		req.send(params);
	}
}

function gb2utf8(data){
    var glbEncode = [];
    gb2utf8_data = data;
    execScript("gb2utf8_data = MidB(gb2utf8_data, 1)", "VBScript");
    var t=escape(gb2utf8_data).replace(/%u/g,"").replace(/(.{2})(.{2})/g,"%$2%$1").replace(/%([A-Z].)%(.{2})/g,"@$1$2");
    t=t.split("@");
    var i=0,j=t.length,k;
    while(++i<j) {
        k=t[i].substring(0,4);
        if(!glbEncode[k]) {
            gb2utf8_char = eval("0x"+k);
            execScript("gb2utf8_char = Chr(gb2utf8_char)", "VBScript");
            glbEncode[k]=escape(gb2utf8_char).substring(1,6);
        }
        t[i]=glbEncode[k]+t[i].substring(4);
    }
    gb2utf8_data = gb2utf8_char = null;
    return unescape(t.join("%"));
}

function $(idname){
	if (document.getElementById){ return document.getElementById(idname); } 
	else if (document.all) { return document.all[idname];} 
	else if (document.layers) {	return document.layers[idname];	}
	else { return null; }
}
function innerText(o) {
	if (document.all) {
		return o.innerText;
	} else {
		return o.textContent;
	}
}
function toogle_memo(tohide, toshow) {
	tohide.style.display = 'none';
	toshow.style.display = 'inline';
}
function comment_submit(f, vid) {
	var msg = "";
	if (f.comment == null || f.comment.value == "") {
		msg += "请输入评论内容！\n";
	}
	if (f.comment.value.length > 300) {
		msg += "评论不能超过300个字！\n";
	}
	if (msg == "") {
		sendRequest(addcomment_callback, "/playtbcomment.asp", "comment="+escape(f.comment.value)+"&vid="+vid, "POST");
	} else {
		window.alert(msg);
		f.comment.focus();
		return false;
	}
	tooglecomment(fbpl);
	return false;
}

function addcomment_callback(data) {
	$('allreviews').innerHTML = data.substr(1) + $('allreviews').innerHTML;	
}

function tooglecomment(fbpl) {
	if (fbpl.style.display=='none') {
		fbpl.style.display='';
		document.f_comment.comment.focus();
	} else {
		fbpl.style.display='none';
		document.f_comment.comment.value = '';
	}
	void(0);
}
function tooglestar(toon, tooff) {
	toon.style.display = 'block';
	tooff.style.display = 'none';
}

function zsxz(ta, zs, maxl)
{
	if(ta.value.length > maxl)
	{
		ta.value = ta.value.substring(0,maxl);
	}
	else
	{
		zs.value = maxl - ta.value.length;
	}
}
function zsxz1(ta, zs, maxl)
{
	if(ta.value.length > maxl)
	{
		ta.value = ta.value.substring(0,maxl);
	}
	else
	{
		zs.innerHTML = maxl - ta.value.length;
	}
}

var ingallreview = 0;
function showallreviews(vid) {
	if (ingallreview == 0) {
		sendRequest(review_callback, '/playtballreviews.asp', 'vid='+vid, 'POST');
		ingallreview = 1;
	}
}

var review20 = "";
function review_callback(data) {
	var o = $('allreviews');
	review20 = o.innerHTML;
	o.innerHTML = data;
	$('xl_show_all_reviews').innerHTML = '<a href="javascript: show20reviews();" class="ll">只显示最新20条评论&raquo;</a>';
	ingallreview = 0;
}

function show20reviews() {
	var o = $('allreviews');
	o.innerHTML = review20;
	$('xl_show_all_reviews').innerHTML = '<a href="javascript: showallreviews('+vid+');" class="ll">显示全部评论&raquo;</a>';
}