﻿var requests = new Array();

if(typeof(XMLHttpRequest) == 'undefined')
var XMLHttpRequest = function()
{
	var request = null;
	try
	{
		request = new ActiveXObject('Msxml2.XMLHTTP');
	}
	catch(e)
	{
		try
		{
			request = new ActiveXObject('Microsoft.XMLHTTP');
		}
		catch(ee)
		{}
	}
	return request;
}

function ajax_stop()
{
	for(var i=0; i<requests.length; i++)
	{
		if(requests[i] != null)
			requests[i].abort();
	}
}

function ajax_create_request(context)
{
	for(var i=0; i<requests.length; i++)
	{
		if(requests[i].readyState == 4)
		{
			requests[i].abort();
			requests[i].context = context;
			return requests[i];
		}
	}

	var pos = requests.length;
	
	requests[pos] = Object();
	requests[pos].obj = new XMLHttpRequest();
	requests[pos].context = context;
	
	return requests[pos];
}

function ajax_request(url, data, callback, context)
{
	var request = ajax_create_request(context);
	var async = typeof(callback) == 'function';

	if(async) request.obj.onreadystatechange = function()
	{
		if(request.obj.readyState == 4)
			callback(new ajax_response(request));
	}
	
	request.obj.open('POST', url, async);
	request.obj.send(data);
	
	if(!async)
		return new ajax_response(request);
}

function ajax_response(request)
{
	this.request = request.obj;
	this.error = null;
	this.value = null;
	this.context = request.context;
	
	if(request.obj.status == 200)
	{
		try
		{
			this.value = object_from_json(request);
			
			if(this.value && this.value.error)
			{
				this.error = this.value.error;
				this.value = null;
			}
		}
		catch(e)
		{
			this.error = new ajax_error(e.name, e.description, e.number);
		}
	}
	else
	{
		this.error = new ajax_error('HTTP request failed with status: ' + request.obj.status, request.obj.status);
	}
	
	return this;
}

function enc(s)
{
	return s.toString().replace(/\%/g, "%26").replace(/=/g, "%3D");
}

function object_from_json(request)
{
	if(request.obj.responseXML != null && request.obj.responseXML.xml != null && request.obj.responseXML.xml != '')
		return request.obj.responseXML;
	
	var r = null;	
	eval('r=' + request.obj.responseText + ';');
	return r;
}

function ajax_error(name, description, number)
{
	this.name = name;
	this.description = description;
	this.number = number;

	return this;
}

ajax_error.prototype.toString = function()
{
	return this.name + " " + this.description;
}

function json_from_object(o)
{
	if(o == null)
		return 'null';

	switch(typeof(o))
	{
		case 'object':
			if(o.constructor == Array)		// checks if it is an array [,,,]
			{
				var s = '';
				for(var i=0; i<o.length; ++i)
				{
					s += json_from_object(o[i]);

					if(i < o.length -1)
						s += ',';
				}

				return '[' + s + ']';
			}
			break;
		case 'string':
			return '"' + o.replace(/(["\\])/g, '\\$1') + '"';
		default:
			return String(o);
	}
}var ajaxVersion = '5.7.22.2';


function isIE(){ //ie? 
   if (window.navigator.userAgent.toLowerCase().indexOf("msie")>=1) 
    return true; 
   else 
    return false; 
} 

if(!isIE()){ //firefox innerText define
   HTMLElement.prototype.__defineGetter__(     "innerText", 
    function(){
     var anyString = "";
     var childS = this.childNodes;
     for(var i=0; i<childS.length; i++) {
      if(childS[i].nodeType==1)
       anyString += childS[i].tagName=="BR" ? '\n' : childS[i].innerText;
      else if(childS[i].nodeType==3)
       anyString += childS[i].nodeValue;
     }
     return anyString;
    } 
   ); 
   HTMLElement.prototype.__defineSetter__(     "innerText", 
    function(sText){ 
     this.textContent=sText; 
    } 
   ); 
}


function WF( arg )
{
var parm = []
var _default_version = "8,0,24,0";
var _default_quality = "high";
var _default_align = "middle";
var _default_menu = "false";

for(i = 0; i < arguments.length; i ++)
{
parm[i] = arguments[i].split(' ').join('').split('=')
for (var j = parm[i].length-1; j > 1; j --){
parm[i][j-1]+="="+parm[i].pop();
}
switch (parm[i][0])
{
case '_version' : var _version = parm[i][1] ; break ; 
case '_swf' : var _swf = parm[i][1] ; break ; 
case '_base' : var _base = parm[i][1] ; break ; 
case '_quality' : var _quality = parm[i][1] ; break ; 
case '_loop' : var _loop = parm[i][1] ; break ; 
case '_bgcolor' : var _bgcolor = parm[i][1] ; break ; 
case '_wmode' : var _wmode = parm[i][1] ; break ; 
case '_play' : var _play = parm[i][1] ; break ; 
case '_menu' : var _menu = parm[i][1] ; break ; 
case '_scale' : var _scale = parm[i][1] ; break ; 
case '_salign' : var _salign = parm[i][1] ; break ; 
case '_height' : var _height = parm[i][1] ; break ; 
case '_width' : var _width = parm[i][1] ; break ; 
case '_hspace' : var _hspace = parm[i][1] ; break ; 
case '_vspace' : var _vspace = parm[i][1] ; break ; 
case '_align' : var _align = parm[i][1] ; break ; 
case '_class' : var _class = parm[i][1] ; break ; 
case '_id' : var _id = parm[i][1] ; break ; 
case '_name' : var _name = parm[i][1] ; break ; 
case '_style' : var _style = parm[i][1] ; break ; 
case '_declare' : var _declare = parm[i][1] ; break ; 
case '_flashvars' : var _flashvars = parm[i][1] ; break ; 
default :;
}
}
var thtml = ""
thtml += "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=" + ((_version)?_version:_default_version) + "'"
if(_width) thtml += " width='" + _width + "'"
if(_height) thtml += " height='" + _height + "'"
if(_hspace) thtml += " hspace='" + _hspace + "'"
if(_vspace) thtml += " vspace='" + _vspace + "'"
if(_align) thtml += " align='" + _align + "'"
else thtml += " align='" + _default_align + "'"
if(_class) thtml += " class='" + _class + "'"
if(_id) thtml += " id='" + _id + "'"
if(_name) thtml += " name='" + _name + "'"
if(_style) thtml += " style='" + _style + "'"
if(_declare) thtml += " " + _declare
thtml += ">"
if(_swf) thtml += "<param name='movie' value='" + _swf + "'>"
if(_quality) thtml += "<param name='quality' value='" + _quality + "'>" 
else thtml += "<param name='quality' value ='" + _default_quality + "'>"
if(_loop) thtml += "<param name='loop' value='" + _loop + "'>"
if(_bgcolor) thtml += "<param name='bgcolor' value='" + _bgcolor + "'>"
if(_play) thtml += "<param name='play' value='" + _play + "'>"
if(_menu) thtml += "<param name='menu' value='" + _menu + "'>"
else thtml += "<param name='menu' value='" + _default_menu + "'>"
if(_scale) thtml += "<param name='scale' value='" + _scale + "'>"
if(_salign) thtml += "<param name='salign' value='" + _salign + "'>"
if(_wmode) thtml += "<param name='wmode' value='" + _wmode + "'>"
if(_base) thtml += "<param name='base' value='" + _base + "'>"
if(_flashvars) thtml += "<param name='flashvars' value='" + _flashvars + "'>"
thtml += "<embed pluginspage='http://www.macromedia.com/go/getflashplayer'"
if(_width) thtml += " width='" + _width + "'"
if(_height) thtml += " height='" + _height + "'"
if(_hspace) thtml += " hspace='" + _hspace + "'"
if(_vspace) thtml += " vspace='" + _vspace + "'"
if(_align) thtml += " align='" + _align + "'"
else thtml += " align='" + _default_align + "'"
if(_class) thtml += " class='" + _class + "'"
if(_id) thtml += " id='" + _id + "'"
if(_name) thtml += " name='" + _name + "'"
if(_style) thtml += " style='" + _style + "'"
thtml += " type='application/x-shockwave-flash'"
if(_declare) thtml += " " + _declare 
if(_swf) thtml += " src='" + _swf + "'"
if(_quality) thtml += " quality='" + _quality + "'"
else thtml += " quality='" + _default_quality + "'"
if(_loop) thtml += " loop='" + _loop + "'"
if(_bgcolor) thtml += " bgcolor='" + _bgcolor + "'"
if(_play) thtml += " play='" + _play + "'"
if(_menu) thtml += " menu='" + _menu + "'"
else thtml += " menu='" + _default_menu + "'"
if(_scale) thtml += " scale='" + _scale + "'"
if(_salign) thtml += " salign='" + _salign + "'"
if(_wmode) thtml += " wmode='" + _wmode + "'"
if(_base) thtml += " base='" + _base + "'"
if(_flashvars) thtml += " flashvars='" + _flashvars + "'"
thtml += "></embed>"
thtml += "</object>"
document.write(thtml)
}


function G(id){return document.getElementById(id);}
var RPath='/';

function PlayLoading()
{G('DLoadingDIV').style.top=document.documentElement.scrollTop+'px';}
function PlaySubmit()
{
	window.setTimeout('PCover()',1);
}
function PCover()
{
	if(G('DLoadingDIV')!=null)
	{
	var dload=G('DLoadingDIV');
	if(!isIE()){dload.innerHTML='<img src="http://www.315che.com/images/submiting.gif" style="padding-top:250px;">';}
	dload.style.display='';
	dload.style.height=document.documentElement.clientHeight+'px';
	dload.style.width=document.documentElement.clientWidth+'px';
	setInterval("PlayLoading()", 10);
	}
}

var doc=window.document;
function getWordNum()
{
	G('Comment_wordnum').innerText=G('Comment_Content').value.length+1;
	if(G('Comment_Content').value.length+1>199){alert('内容过长');return false;}
}

String.prototype.trim = function()
{
var reExtraSpace = /^\s*(.*?)\s+$/;
return this.replace(reExtraSpace,"$1");
}

function CheckValidator()
{
	var returnval=true;
	if(G('Comment_Content').value.trim()=='')
	{
		G('Comment_Content_Val').style.display='';
		returnval=false;
	}
	else
	{
		G('Comment_Content_Val').style.display='none';
	}

	if(G('Comment_Name').value.trim()=='')
	{
		G('Comment_Name_Val').style.display='';
		returnval=false;
	}
	else
	{
		G('Comment_Name_Val').style.display='none';
	}

	return returnval;
}


function GetSelReply(num,name)
{
   var repstr="回复 第 "+num+" 楼"+name+":";
   G('Comment_Content').value=repstr;
   G('Comment_Content').focus();
}

function show_intro(pre,pree, n, select_n) {
	for (i = 1; i <= n; i++) {
			var intro = G(pre + i);
			var cha = G(pree + i);
			intro.style.display = "none";
			cha.className="menu_off";
			if (i == select_n) {
			intro.style.display = "block";
			cha.className="menu_on";
		}
	}
}

var loading=',';

function LoadTip(oid)
{
	//return;
	var type='';
	var key='';
	var addparam='';
	var nid='';
	if(oid.getAttribute('type')!=undefined)
	{
		type=oid.getAttribute('type');
	}
	if(oid.getAttribute('key')!=undefined)
	{
		key=oid.getAttribute('key');
	}
	if(oid.getAttribute('addparam')!=undefined)
	{
		addparam=oid.getAttribute('addparam');
	}
		if(oid.getAttribute('nid')!=undefined)
	{
		nid=oid.getAttribute('nid');
	}

	if(loading.indexOf(','+oid.getAttribute('tippoint')+',')<0)
	{
		loading+=oid.getAttribute('tippoint')+',';
		NAjax.GetTipStr(type,key,nid,addparam,oid.getAttribute('tippoint'),TipBack);
	}
}

function TipBack(response)
{
	if(response.value==null || response.value[0]=='' || response.value[0]==undefined)return;
	var tid=response.value[1];
	var jstr='';
	jstr+='<div style="width:300px;position: absolute;left:-27px;top:-130px;" id="'+tid+'a">';
	jstr+='	<div style="float:left; height:12px; background:url(/images/left_top.gif) bottom left no-repeat; width:273px;" class="alpha50" ></div>';
	jstr+='	<div style="height:12px;float:left; background:url(/images/right_top.gif) bottom no-repeat; width:27px;" class="alpha50"></div>';
	jstr+='	<div style="clear:both; background:#ECEEF1; width:100%;" class="alpha50" id="'+tid+'n">';
	jstr+='	<span style="padding:10px; height:100%; display:block; border-left:1px #7B8AB5 solid; border-right:1px #7B8AB5 solid; position:relative;font-size:12px;">';
	jstr+='<input type="button" value="X" '
	+' style=" font-family: Comic Sans MS; font-size:10px;border:1px solid #666666;position: absolute;right:5px;top:-10px;" onclick="G(\''
	+tid+'\').parentNode.style.display=\'none\';">';
	jstr+= response.value[0];
	jstr+='</span></div>';
	jstr+='	<div style="float:left; height:34px; background:url(/images/left_bo.gif) left top no-repeat; width:273px;" class="alpha50" ></div>';
	jstr+='	<div style="height:34px;float:left; background:url(/images/right_bo.gif) top no-repeat; width:27px;" class="alpha50">';
	//jstr+='<input type="button" value="2" '
	//+' style=" font-family: Comic Sans MS; font-size:10px;border:1px solid #666666;position: absolute;right:5px;bottom:25px;" onclick="G(\''
	//+tid+'\').innerHTML=\'\';">'
	//	+'<input type="button" value="1" '
	//+' style=" font-family: Comic Sans MS; font-size:10px;border:1px solid #666666;position: absolute;right:45px;bottom:25px;" onclick="G(\''
	//+tid+'\').innerHTML=\'\';">'
	//	+'</div>';
	jstr+='</div>';
	
	G(tid).innerHTML=jstr;
	G(tid).parentNode.style.display='';

	if(isIE())
	{
		G(tid+'a').style.top=-44-G(tid+'n').clientHeight;
	}
	else
	{
		G(tid+'a').style.top=-40-G(tid+'n').clientHeight;
	}
	window.setTimeout('tipclose("'+tid+'")',5000);
}



function LoadAllTip()
{
	var tips=document.getElementsByTagName('span');
	var nowtip=new Array();
	for(var i=0;i<tips.length;i++)
	{	
		if(tips[i].getAttribute('tippoint')!=undefined)
		{
			nowtip[nowtip.length]=tips[i];
		}
	}
	if(nowtip.length>0)
	{
//		if(nowtip.length>1)
//		{
//			LoadTip(nowtip[0]);
//			LoadTip(nowtip[nowtip.length-1]);
//		}
//		else
//		{
			LoadTip(nowtip[0]);
//		}
	}
}

function showtip(tid)
{
	if(G(tid).innerHTML=='')
	{
		LoadTip(G(tid).parentNode);
	}
	G(tid).parentNode.style.display='';
}

function tipclose(tid)
{
	G(tid).parentNode.style.display='none';
}

function DL(type,fid)
{
	var skinpath='';
	if(G('comment')!=null)
	{
		if(G('comment').getAttribute('vskin')!=null)skinpath=G('comment').getAttribute('vskin');
		NAjax.GetComment(type,fid,skinpath,DLB);
	}
	if(G('vote')!=null)
	{
		NAjax.GetVote(G('vote').getAttribute('vname'),G('vote').getAttribute('vskin'),VLB);
	}
}

function DLO(fid)
{
	var skinpath='';
	if(G('comment')!=null)
	{
		if(G('comment').getAttribute('vskin')!=null)skinpath=G('comment').getAttribute('vskin');
		NAjax.GetComment('9999',fid,skinpath,DLB);
	}
	if(G('vote')!=null)
	{
		NAjax.GetVote(G('vote').getAttribute('vname'),G('vote').getAttribute('vskin'),VLB);
	}
}

function DLB(response)
{	
	var ds=response.value;
	if(ds!=null &&  G('comment')!=null)
	{
		G('comment').innerHTML=ds;
	}
}
function VLB(response)
{
	var ds=response.value;
	if(ds!=null &&  G('vote')!=null)
	{
		G('vote').innerHTML=ds;
	}
}
