﻿var XMLHTTP_READYSTATE_UNLOAD = 0; //未初始化
var XMLHTTP_READYSTATE_READING = 1; //
var XMLHTTP_READYSTATE_READED = 2; //
var XMLHTTP_READYSTATE_EXCHANING = 3; //
var XMLHTTP_READYSTATE_FINISHED = 4; //

var ajaxarr = new Array();//note 每个URL只允许生成一个AJAX对象，防止重复点击。
var ajaxstackarr = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0);//note ajax 对象时间占位堆栈。预置位10个，应该足够用了。
var attackevasive = 1;//note 防止刷新是否打开
var ajsetarr = new Array();
var xctrlid;

//构造AJAX类
function ajax_cls(recvtype) {

	for(var _stackindex = 0; _stackindex < ajaxstackarr.length && ajaxstackarr[_stackindex] != 0; _stackindex++);//note 查询空闲的时间位
	ajaxstackarr[_stackindex] = 1;//note 表示该任务占位

	var aj = new Object();

	aj._recvtype = recvtype ? recvtype : 'XML';

	aj._resulthandle = null;
	aj._sendstring = '';
	aj.targeturl = '';
	aj._stackindex = 0;
	aj._stackindex = _stackindex;

	//note 默认为 XML 方式
	aj.setrecvtype = function(recvtype) {
		aj._recvtype = recvtype;
	}

	aj._create = function() {
		var request = false;
		if(window.XMLHttpRequest) {
			request = new XMLHttpRequest();
			if(request.overrideMimeType) {
				request.overrideMimeType('text/xml');
			}
		} else if(window.ActiveXObject) {
			var versions = ['Microsoft.XMLHTTP', 'MSXML.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.7.0', 'Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.5.0', 'Msxml2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP'];
			for(var i=0; i<versions.length; i++) {
				try {
					request = new ActiveXObject(versions[i]);
					if(request) {
						return request;
					}
				} catch(e) {
					continue;
				}
			}
		}
		return request;
	}

	aj._xmlhttp_request = aj._create();


	//note private
	aj._processhandle = function() {
		var XMLHTTP_READYSTATE_FINISHED = 4;
		if(aj._xmlhttp_request.readyState == XMLHTTP_READYSTATE_FINISHED && aj._xmlhttp_request.status == 200) {
			if(ajaxarr.length > 0 ) {
				for(k in ajaxarr) {
					if(ajaxarr[k] == aj.targeturl) {
						ajaxarr[k] = null;
					}
				}
			}
			if(aj._recvtype == 'HTML') {
				aj._resulthandle(aj._xmlhttp_request.responseText, aj);
			} else if(aj._recvtype == 'XML') {
				if(aj._xmlhttp_request.responseXML.lastChild != null) {
					aj._resulthandle(aj._xmlhttp_request.responseXML.lastChild.firstChild.nodeValue, aj);
				}
			}
			ajaxstackarr[aj._stackindex] = 0;//note 清空标志位，使其它对象有时间段可以被申请
		}
	}

	//note public
	aj.get = function(targeturl, resulthandle) {
		if(in_array(targeturl, ajaxarr)) {
			return false;
		} else {
			ajaxarr.push(targeturl);
		}
		aj.targeturl = targeturl;
		aj._xmlhttp_request.onreadystatechange = aj._processhandle;
		aj._resulthandle = resulthandle;
		var delay = attackevasive & 1 ? (aj._stackindex + 1) * 1001 : 100;
		if(window.XMLHttpRequest) {
			setTimeout(function(){
			aj._xmlhttp_request.open('GET', aj.targeturl);
			aj._xmlhttp_request.send(null);}, delay);
		} else {
			setTimeout(function(){
			aj._xmlhttp_request.open("GET", aj.targeturl, true);
			aj._xmlhttp_request.send();}, delay);
		}

	}
	//note public
	aj.post = function(targeturl, sendstring, _resulthandle) {
		/*
		if(in_array(targeturl, ajaxarr)) {
			return false;
		} else {
			ajaxarr.push(targeturl);
		}
		*/
		aj.targeturl = targeturl + '&inajax=1';
		aj._sendstring = sendstring;
		aj._xmlhttp_request.onreadystatechange = aj._processhandle;
		aj._resulthandle = _resulthandle;
		aj._xmlhttp_request.open('POST', aj.targeturl);
		aj._xmlhttp_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		aj._xmlhttp_request.send(aj._sendstring);
	}
	return aj;
}

//执行JS脚本
var evalscripts = new Array();
function _evalscript(s) {
	//debugger;
	if(s.indexOf('<script') == -1) return s;
	var p = /<script[^\>]*?src=\"([^\>]*?)\"[^\>]*?(reload=\"1\")?(?:charset=\"([\w\-]+?)\")?><\/script>/ig;
	var arr = new Array();
	while(arr = p.exec(s)) _appendscript(arr[1], '', arr[2], arr[3]);
	p = /<script (?!src)[^\>]*?( reload=\"1\")?>([^\x00]+?)<\/script>/ig;
	while(arr = p.exec(s)) _appendscript('', arr[2], arr[1]);
	return s;
}
// 绑定JS脚本
function _appendscript(src, text, reload, charset) {
	//debugger;
	var id = hash(src + text);
	if(!reload && in_array(id, evalscripts)) return;
	if(reload && $(id)) {
		$(id).parentNode.removeChild($(id));
	}

	evalscripts.push(id);
	var scriptNode = document.createElement("script");
	scriptNode.type = "text/javascript";
	scriptNode.id = id;
	scriptNode.charset = charset;
	try {
		if(src) {
			scriptNode.src = src;
		} else if(text){
			scriptNode.text = text;
		}
		$('supevbox').appendChild(scriptNode);
	} catch(e) {}
}
//对JS进行过滤
function _stripscript(s) {
	//debugger;
	s = unescape(s);
	return s.replace(/<script.*?>.*?<\/script>/ig, '');
}

/*	调用远程接口，并返回UI套入到当前div的容器中。
 *@ url: 需求请求的 url
 *@ id : 显示的 id
 *@ _waiting: 等待的 id，默认为显示的 id，如果 _waiting 为空字符串，则不显示 loading...， 如果为 null，则在 showid 区域显示
 *@ linkid: 是哪个链接触发的该 ajax 请求，该对象的属性(如 ajaxdisplay)保存了一些 ajax 请求过程需要的数据。
 *@ recall:　回调函数
*/
//预览视频
function previewTeacher(vodid,vodname,vodlink)
{
  openwin("open","");
  var vodplan = $("pmframe");
  vodplan.style.background = "#fff";
  vodplan.style.marginLeft = 130;
  vodplan.style.width = "553px";
  vodplan.style.marginTop = 80;
  vodplan.style.height = "414px";
  var vodbottom = $("pmbottom");
  vodbottom.innerHTML = "<b>"+vodname+"老师的体验视频</b>&nbsp;&nbsp;<a href='"+vodlink+"'>(进入详细课程)</a>";
  var s3 = new SWFObject("images/player.swf","player","513","414","7");
  s3.addParam("allowfullscreen","true");
  s3.addVariable("flashvars","&frontcolor=ffffff&lightcolor=cc9900&skin=images/overlay.swf&controlbar=over");
  s3.addVariable("file","/preview/" + vodid + ".flv");
  //s3.addVariable("image","images/video-logo.gif");
  s3.write("pmframe");
}

function previewExercise(vodid,vodpath,vodlink)
{
  openwin("open","");
  var vodplan = $("pmframe");
  vodplan.style.background = "#fff";
  vodplan.style.marginLeft = 130;
  vodplan.style.width = "553px";
  vodplan.style.marginTop = 80;
  vodplan.style.height = "414px";
  var vodbottom = $("pmbottom");
  vodbottom.innerHTML = "<b>视频讲解</b>&nbsp;&nbsp;";
  var s3 = new SWFObject("images/player.swf","player","513","414","7");
  s3.addParam("allowfullscreen","true");
  s3.addVariable("flashvars","&frontcolor=ffffff&lightcolor=cc9900&skin=images/overlay.swf&controlbar=over");
  s3.addVariable("file",vodlink + vodpath + "/vod/" + vodid + ".flv");
  //s3.addVariable("image","images/video-logo.gif");
  s3.write("pmframe");
}

function showclass(id)
{
  var url="/subscibe.aspx?sid=" + id + '&rnd=' + Math.round(Math.random()*10000);
  openwin("open","");
  aj_load(url,"pmframe");
}

function showquestion(id)
{
  var url="/subscibe.aspx?stype=1&sid=" + id + '&rnd=' + Math.round(Math.random()*10000);
  openwin("open","");
  aj_load(url,"pmframe");
}

function playclass(id)
{
  var url="/subscibe.aspx?sid=" + id + '&rnd=' + Math.round(Math.random()*10000);
  aj_load(url,"videopanel");
  openwin("close");
}

function playquestion(sid,id)
{
  if(questionlist.length>0)
  {
    var qid = questionlist[id-1].Qid;
    if(qid)
    {
      curquestion = id;
      var url="/getquestion.aspx?id=" + id + "-" + questionlist.length + "&pay=1&sid=" + sid + "&qid=" + qid + '&rnd=' + Math.round(Math.random()*10000);
      aj_load(url,"questionlist");
      openwin("close");
    }
  }
}

//调用题目
function resetquestion(sid,id)
{
  if(questionlist.length>0)
  {
    var qid = questionlist[id-1].Qid;
    if(qid)
    {
      curquestion = id;
      updatequestion();
      var url="/getquestion.aspx?id=" + id + "-" + questionlist.length + "&sid=" + sid + "&qid=" + qid + '&rnd=' + Math.round(Math.random()*10000);
      aj_load(url,"questionlist");
    }
  }
}

//跳过题目
function skipquestion()
{
   if(!$("noquestion" + curquestion))
   {
     //判断是否已做过选择
     var _option = questionlist[curquestion-1].option;
     if(typeof(_option) == "undefined")
     {
        var noquestion = $("notquestion");
        var objA = $c("A");
        objA.id = "noquestion" + curquestion;
        objA.innerHTML = "第" + curquestion + "题";
        objA.href = "#";
        //_attachEvent(objA,"click",function(){setTimeout("resetquestion(cursubject," + curquestion + ")",0)}); 
        AttachEvent(objA,"click",function(e){resetquestion(cursubject,this.Id)}, questionlist[curquestion-1]);
        noquestion.appendChild(objA);
        nextquestion();
     }
   }
}

function checkquestion()
{
   if(!$("noquestion" + curquestion))
   {
     //判断是否已做过选择
     var _option = questionlist[curquestion-1].option;
     if(typeof(_option) == "undefined")
     {
        var noquestion = $("notquestion");
        var objA = $c("A");
        objA.id = "noquestion" + curquestion;
        objA.innerHTML = "第" + curquestion + "题";
        objA.href = "#";
        //_attachEvent(objA,"click",function(){setTimeout("resetquestion(cursubject," + curquestion + ")",0)}); 
        AttachEvent(objA,"click",function(e){resetquestion(cursubject,this.Id)}, questionlist[curquestion-1]);
        noquestion.appendChild(objA);
        //nextquestion();
     }
   }
}

//交卷
function submitquestion()
{
  checkquestion();
  var issubmit = true;
  if($("notquestion").innerHTML != "")
  {
     issubmit = confirm("还存在没有做完的习题，你确定交卷吗？");
  }
  
  if(issubmit)
  {
    $("qustion_test").innerHTML = "练习结果如下：";
    _answerlist = $("question_result");
    _answerlist.innerHTML = "";
    for(var i=1;i<=questionlist.length;i++)
    {
      var _right = false;
      var _op = questionlist[i-1].option;
      var _an = questionlist[i-1].answer;
      if(typeof(_op) != "undefined" && typeof(_an) != "undefined")
      {
         if(_op == _an)
         {
            _right = true;
         }
      }
      
        var objA = $c("A");
        objA.id = "q_answer" + i;
        objA.innerHTML = "第" + i + "题";
        objA.href = "#";
        if(_right){objA.className = "seleop";}else{objA.className = "unseleop";}
        AttachEvent(objA,"click",function(e){resetquestion(cursubject,this.Id)},questionlist[i-1]);
        _answerlist.appendChild(objA);
    }
  }
  
  
}

///附加事件
function AttachEvent(target, eventName, handler, argsObject)
{
    var eventHandler = handler;
    if(argsObject)
    {
        eventHander = function(e)
        {
            handler.call(argsObject, e);
        }
    }
    if(window.attachEvent)//IE
        target.attachEvent("on" + eventName, eventHander );
    else//FF
        target.addEventListener(eventName, eventHander, false);
}

//上一题
function prequestion()
{
  checkquestion();
  var id = curquestion -1;
  if(id<1)id=1;
  resetquestion(cursubject,id);

}
//下一题
function nextquestion()
{
  checkquestion();
  var id = curquestion + 1;
  if(id>questionlist.length)id=questionlist.length;
  resetquestion(cursubject,id);
}

//更新当前题目答案
function updatequestion(answer)
{
  var _answer = questionlist[curquestion-1].answer;
  if(typeof(_answer) == "undefined")
  {
    questionlist[curquestion-1].answer = answer;
  }
  $("curqid").innerHTML = curquestion;
}

function playdefaultclass(id)
{
  var url="/subscibe.aspx?sid=" + id + '&rnd=' + Math.round(Math.random()*10000);
  aj_load(url,"videopanel");
}

///2009 10 by stangray
//检查视频
function checkvideo(id)
{
  var url="/subscibe.aspx?stype=1&ajaxtarget=checkvod&pid=" + id + '&rnd=' + Math.round(Math.random()*10000);
  aj_send(url);
}

function alertlogin()
{
	openwin("open","");
	var oshow = $("pmframe");
	oshow.innerHTML = '<p class="info">你还没有登录，请先<a href="/login.aspx">登录</a></p>';
}

//检查用户权限
function checkuser(pid)
{
	var url='/subscibe.aspx?stype=1&pid='+ pid +'&rnd=' + Math.round(Math.random()*10000);
	openwin("open","");
 	aj_load(url,"pmframe");
}

//购买视频
function buyvideo(pid)
{
	openwin("close");
	var url="/subscibe.aspx?stype=1&ajaxtarget=buyvod&pid=" + pid + '&rnd=' + Math.round(Math.random()*10000);
  	aj_send(url);
}

function StopVideoServer()
{
  try
  {
  if(typeof(window.mediaplayer)=='undefine'|| window.mediaplayer==null) 
  {
     return;
  }
  if(mediaplayer)
  {
      mediaplayer.sendEvent('STOP');
  }
  }
  catch(e){}
}

var videourl = "rtmp://61.158.219.78/";
//播放课程视频
function playvideo(key,vod,code)
{
  StopVideoServer();
  if(s1)
  {
    s1.addVariable("file",key);
    s1.addVariable("key",code);
    s1.addVariable("image","/images/video-play.gif");
    s1.addVariable("streamer",videourl + vod);
    s1.write("video_container");	
  }
}

var PLANTIME,LOSTTIME;
function calTime(endtime,curtime)
{
  PLANTIME = new Date(endtime).getTime();
  var servertime = new Date(curtime).getTime();
  LOSTTIME = servertime - new Date().getTime();
  setTimeout("show_datatime()",1000);
}

function show_datatime()
{
  setTimeout("show_datatime()",1000); 
  today=new Date();
  today = new Date(today.getTime() + LOSTTIME);
  timeold=PLANTIME-today.getTime(); 
  sectimeold=timeold/1000; 
  secondsold=Math.floor(sectimeold); 
  msPerDay=24*60*60*1000;
  e_daysold=timeold/msPerDay; 
  daysold=Math.floor(e_daysold); 
  e_hrsold=(e_daysold-daysold)*24; 
  hrsold=Math.floor(e_hrsold); 
  e_minsold=(e_hrsold-hrsold)*60; 
  minsold=Math.floor((e_hrsold-hrsold)*60); 
  if (daysold<0)
  { 
    document.getElementById("titletimer").innerHTML=""; 
  }  
  else 
  { 
    if(daysold > 0)
    {
        document.getElementById("titletimer").innerHTML = "还有"+ daysold + "天"; 
    }
    else
    {
        if (hrsold<10) {hrsold="0"+hrsold} 
        if (minsold<10) {minsold="0"+minsold} 
        if (hrsold<1 && minsold<10) { 
          document.getElementById("titletimer").innerHTML = "<font color=red>少于10分钟</font>"; 
        }  
        else { 
          document.getElementById("titletimer").innerHTML = "还有"+ hrsold+"小时"+minsold+"分";
        } 
    }
  }
}



//播放习题视频
function playquestionvideo(key,img,code)
{
  if(s2)
  {
    s2.addVariable("file",key);
    s2.addVariable("key",code);
    img = img.replace(/"-"/g,"/");
    openwin("open","");
    s2.write("pmframe");
  }
}

//更新课频个数
function resetcount(count)
{
  //$("vcount").innerHTML = count;
}

function aj_load(url, oshowid, force, loading) {
	//debugger;
	force = empty(force) ? false : force;
	if(force == false && in_array(url, ajsetarr)) {
		return false;
	} else {
		ajsetarr.push(url);
	}

	var x = new ajax_cls("HTML");
	var oshow = $(oshowid);
	var autogoto = 0;

	loading = empty(loading) ? '加载中...' : loading;
	oshow.innerHTML = '<p class="info"><img src="'+jsenv['THEME_PATH']+'res/loading.gif"> ' + loading + '</p>';

	x.oshow = oshow;

	if(url.substr(strlen(url) - 1) == '#') {
		url = url.substr(0, strlen(url) - 1);
		autogoto = 1;
	}

	var url = url + '&inajax=1&ajaxtarget=' + oshowid 

	x.get(url, function(s, x) {
		if(_ajaxshow(s)) {
			return;
		}
		_evalscript(s);
		s = _stripscript(s);
		_sinnerHTML(x.oshow, s);
		_ajaxupdateevents(x.oshow);
		_attacheffect(x.oshow);
		if(autogoto) {
			scroll(0, x.oshow.offsetTop);
		}
	});
}
//仅调用远程接口，不返回任何UI
function aj_send(url) {
	var x = new ajax_cls("HTML");
	var url = url + '&inajax=1';
	x.get(url, function(s, x){
		//if(_ajaxshow(s)) {
		//	return;
		//}
		_evalscript(s);
		s = _stripscript(s);
	});
}

var checkedtab = 'purple';
var uncheckedtab = 'sep';
/**
* 设置Tab.  调用远程UI，并在当前窗口中切换
*/
function aj_settab(cur, tabs_label, e) {
	if(isset(e)) {
		doane(e);
	}

	ocur = $(cur);
	ocur_btn = $(cur+'_btn');

	eval('var tabs='+tabs_label);

	var l = tabs.length;

	for(i = 0;  i < l; i++) {
		$(tabs[i]+'_btn').className = uncheckedtab;
		$(tabs[i]).style.display = 'none';
	}

	ocur.style.display = '';
	ocur_btn.className = checkedtab;
	ocur_btn.blur();

	aj_load(ocur_btn.href, cur);

}

function aj_form(e, ctrlid, divclass, lefttime) {
	divclass = empty(divclass) ? 'ajax_form' : divclass;
	lefttime = empty(lefttime) ? 999999 : lefttime;
	xctrlid = ctrlid;
	aj_menu(e, ctrlid, divclass, lefttime);
}

function aj_menu(e, ctrlid, divclass, lefttime) {
	divclass = empty(divclass) ? 'ajax_msg' : divclass;
	lefttime = empty(lefttime) ? 2 : lefttime;

	var div = $(ctrlid + '_menu');

	if(empty(div)) {
		div = $c('div');
		div.id = ctrlid + '_menu';
		div.style.display = 'none';
		$('supevbox').appendChild(div);
	}

	div.className = divclass;
	var x = new ajax_cls();
	x.ctrlid = ctrlid;
	var href = isset($(x.ctrlid).href) ? $(x.ctrlid).href : $(x.ctrlid).attributes['href'].value;
	
	x.div = div;
	x.get(href + '&inajax=1&ajaxtarget='+x.ctrlid+'_menu',function(s, x) {
		_evalscript(s);
		s = _stripscript(s);
		if(x.div) {
			x.div.innerHTML = s;
		}
		showMenu(x.ctrlid, true, 0, lefttime);
		
	});
	doane(e);
}

// 将返回信息插入到容器
function _sinnerHTML(oshow, s) {
	if(oshow.tagName != 'TBODY') {
		oshow.innerHTML = s;
	} else {
		while(oshow.firstChild) {
			oshow.firstChild.parentNode.removeChild(oshow.firstChild);
		}
		var div1 = $c('DIV');
		div1.id = oshow.id+'_div';
		div1.innerHTML = '<table><tbody id="'+oshow.id+'_tbody">'+s+'</tbody></table>';
		$('supevbox').appendChild(div1);
		var trs = div1.getElementsByTagName('TR');
		var l = trs.length;
		for(var i=0; i<l; i++) {
			oshow.appendChild(trs[0]);
		}
		var inputs = div1.getElementsByTagName('INPUT');
		var l = inputs.length;
		for(var i=0; i<l; i++) {
			oshow.appendChild(inputs[0]);
		}
		div1.parentNode.removeChild(div1);
	}
}

//附加选择题功能
function _attacheffect(obj)
{
  var objs = obj.getElementsByTagName("P");
  var optionid = 0;
  for(k in objs)
  {
    var o = objs[k];
    if(typeof o == 'object' && o.getAttribute) {
      if(o.getAttribute('ir'))
      {
        if(!o.id) {o.id = "_option_" + optionid}
        AttachEvent(o,"click",selectedoption,o);
        //判断已回答
        //debugger;
        var _option = questionlist[curquestion-1].option;
        if(_option != null && typeof(_option) != "undefined")
        {
          if(_option == o.id)
          {
            o.className = "seleop";
          }
        }
        optionid++;
      }
    }
  }  
}

//回答习题
function selectedoption(e)
{
  //移除习题
  var node = $("noquestion" + curquestion);
  if(node)
  {
    var noquestion = $("notquestion");
    noquestion.removeChild(node);
  }
  
  //清除选择样式
  var objs = $("q_options").getElementsByTagName("P");
  for(k in objs)
  {
    var o = objs[k];
    if(typeof o == 'object' && o.getAttribute) {
      if(o.getAttribute('ir'))
      {
        o.className="";
      }
    }
  }
  //debugger;
  this.className="seleop";
  var _option = questionlist[curquestion-1].option;
  if(_option != null && typeof(_option) != "undefined")
  {
    _option = this.id;
  }
  else
  {
    questionlist[curquestion-1].option = this.id;
  }
}


//附加事件
function _ajaxupdateevents(obj, tagName) {
	tagName = tagName ? tagName : 'A';
	var objs = obj.getElementsByTagName(tagName);
	for(k in objs) {
		var o = objs[k];
		_ajaxupdateevent(o);
	}
}
//更新事件
function _ajaxupdateevent(o) {
	if(typeof o == 'object' && o.getAttribute) {
		if(o.getAttribute('ajaxtarget')) {
			if(!o.id) {
				o.id = ('id' + Math.random() * 10).replace(/\./i, '');	//note 该标签唯一标识
			}
			var ajaxevent = o.getAttribute('ajaxevent') ? o.getAttribute('ajaxevent') : 'click';//note 默认为 click 事件
			var ajaxurl = o.getAttribute('ajaxurl') ? o.getAttribute('ajaxurl') : o.href;//note 默认为 click 事件
			_attachEvent(o, ajaxevent, newfunction('aj_load', ajaxurl, o.getAttribute('ajaxtarget'), o.getAttribute('ajaxwaitid'), o.getAttribute('ajaxloading'), o.getAttribute('ajaxdisplay')));
			if(o.getAttribute('ajaxfunc')) {
				o.getAttribute('ajaxfunc').match(/(\w+)\((.+?)\)/);
				_attachEvent(o, ajaxevent, newfunction(RegExp.$1, RegExp.$2));
			}
		}
	}
}
//弹出js信息
function _ajaxshow(s) {
	if(s.indexOf('ajaxshow()') != -1) {
		//ajaxshow();
		return true;
	}
	return false;
}


//展示列表，含翻页等功能
function getform(formName) {
	returnString = "";
	formElements = $(formName).elements;

	var first = true;

	for (var i=0; i< formElements.length; i++) {

		var e = formElements[i];
		if(e.name == null || e.name==""){
			continue;
		}
		if(e.type == "radio"){
			if(e.checked){//判断单选按钮是否被选中
				if(first == true){
					first = false;
					returnString += escape(e.name) + "=" + escape(e.value);
				}else{
					returnString += "&" + escape(e.name) + "=" + escape(e.value);
				}
			}
		}else{
			if(first == true){
				first = false;
				returnString += escape(e.name) + "=" + escape(e.value);
			}else{
				returnString += "&" + escape(e.name) + "=" + escape(e.value);
			}
		}
	}
	return returnString;
}
//提交一个post请求，并把返回结果在当前容器中
function aj_submit(formid, outid, insert, except, loading) {
	var x = new ajax_cls();
	var param = getform(formid) + '&inajax=1';
	insert = empty(insert) ? 0 : insert;
	except = empty(except) ? '' : except;
	loading = empty(loading) ? false : true;
	loadingstr = '';
	x.outid = outid;
	if(loading == true) {
		loadingstr = "<p class='info'><img src='"+jsenv['THEME_PATH']+"res/loading.gif'>loading...</p>";
	}

	var tmpinnerHTML = $(x.outid).innerHTML;
	if(isset(except)) {
		if(tmpinnerHTML.indexOf(except) != -1) {
			tmpinnerHTML = '';
		}
	}
	if(loading == true) {
		if(insert != 0) {
			$(x.outid).innerHTML = loadingstr + tmpinnerHTML;
		} else {
			$(x.outid).innerHTML = loadingstr;
		}
	}
	x.post($(formid).action, param, function(s, x) {

			setMenuPosition($(x.outid).ctrlid, 0);
			setTimeout("hideMenu()", 3000);
			_evalscript(s);
			s = _stripscript(s);
			if(insert != 0) {
				$(x.outid).innerHTML = s + tmpinnerHTML;
			} else {
				$(x.outid).innerHTML = s;
			}
			_ajaxupdateevents($(x.outid));
		
	});

	return false;
}

window.onunload = StopVideoServer;
