// JavaScript Document
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}
function winSizer(){
	windowWidth = window.screen.availWidth;
	windowHeight = window.screen.availHeight;
	if (document.body.clientWidth < windowWidth || document.body.clientHeight < windowHeight ){
		window.moveTo(0,0);
		window.resizeTo(windowWidth,windowHeight);
	}
}
//重载验证码
function reloadcode(){
var verify=document.getElementById('imgCode');
verify.setAttribute('src','includes/verify.php?'+Math.random());
}
//建立active对象
function CreateXMLHttpRequest(){
	if (window.ActiveXObject){
		return new ActiveXObject("Microsoft.XMLHTTP");
	}else if (window.XMLHttpRequest){
		return new XMLHttpRequest();
	}
}

//验证管理员填写大盘直播
function check(form){
	if (form.art_author.value=='' || form.art_content.value==''){
		alert('请输入直播员和内容');
		return false;
	}
	
}

//读取学员提问列表
function readQuest(){
	if (window.ActiveXObject){
		xmlobj4 =  new ActiveXObject("Microsoft.XMLHTTP");
	}else if (window.XMLHttpRequest){
		xmlobj4 =  new XMLHttpRequest();
	}	
	
	if (document.getElementById("quest_zoom")){
		document.getElementById("quest_zoom").innerHTML = "正在加载问题列表...";
	}
				
	xmlobj4.open("GET","quest_right.php",true);
	xmlobj4.setRequestHeader("If-Modified-Since","0");
	xmlobj4.onreadystatechange = function(){
		if (xmlobj4.readyState == 4 && xmlobj4.status == 200){
			if (document.getElementById("quest_zoom")){
				document.getElementById("quest_zoom").innerHTML = xmlobj4.responseText;
			}
		}
	};
	xmlobj4.send(null);
}
//读取答案列表
function readAnswer(){
	var obj;
	if (window.ActiveXObject){
		obj =  new ActiveXObject("Microsoft.XMLHTTP");
	}else if (window.XMLHttpRequest){
		obj =  new XMLHttpRequest();
	}	
	
	if (document.getElementById("answer_zoom")){
		document.getElementById("answer_zoom").innerHTML = "正在加载问题列表...";
	}
				
	obj.open("GET","answer_right.php",true);
	obj.setRequestHeader("If-Modified-Since","0");
	obj.onreadystatechange = function(){
		if (obj.readyState == 4 && obj.status == 200){
			if (document.getElementById("answer_zoom")){
				document.getElementById("answer_zoom").innerHTML = obj.responseText;
			}
		}
	};
	obj.send(null);
}
//加载学员提问表单
function writeQuest(){
	xmlobj2 = CreateXMLHttpRequest();							
	xmlobj2.open("GET","write_quest.php",true);
	xmlobj2.setRequestHeader("If-Modified-Since","0");
	xmlobj2.onreadystatechange = function(){
		if (xmlobj2.readyState == 4 && xmlobj2.status == 200){
			if (document.getElementById("get_quest")){
				document.getElementById("get_quest").innerHTML = xmlobj2.responseText;
			}
		}
	};
	xmlobj2.send(null);
}
//学员提问提交
function submitOrder(){
	xmlobj3 = CreateXMLHttpRequest();
	var executeUrl = "do_wriet_que.php";		
	var parm = "mess_content=" + document.getElementById("mess_content").value + "&mess_type=" + document.getElementById("mess_type").value + "&code=" + document.getElementById("code").value;
	xmlobj3.open("POST",executeUrl,true);
	xmlobj3.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlobj3.onreadystatechange = statHandler;
	xmlobj3.send(parm);

}
//学员提问返回是否成功
function statHandler(){
	if (xmlobj3.readyState == 4 && xmlobj3.status == 200){
		if (xmlobj3.responseText == "1"){
			form1.mess_content.value="";
			form1.code.value="";	
			readQuest();
			writeQuest();					
			alert("提问成功!");	
			if (isreload == 1) {
				window.location.reload();	
			}
		}else{
			alert(xmlobj3.responseText);
		}
	}
	
}
//检查用户名，邮箱是否可以注册
function checkUserName(){
	xmlobj5 = CreateXMLHttpRequest();
	var executeUrl = "do_reg.php?fresh="+Math.random();		
	var parm = "checkform=1&username=" + document.getElementById("username").value + "&email=" + document.getElementById("email").value +
				"&nickname="+document.getElementById("nickname").value+"&code="+document.getElementById("code").value+
				"&password="+document.getElementById("password").value+"&password1="+document.getElementById("password1").value+
				"&pass_question="+document.getElementById("pass_question").value+"&pass_answer="+document.getElementById("pass_answer").value;
	xmlobj5.open("POST",executeUrl,true);
	xmlobj5.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlobj5.onreadystatechange = function(){
		if (xmlobj5.readyState == 4 && xmlobj5.status == 200){
			if (xmlobj5.responseText == "1"){
				document.getElementById("returnMess").innerHTML = "";
				//form_submit();
				return '1';
			}else{
				return '2';
				document.getElementById("returnMess").innerHTML = xmlobj5.responseText;				
			}
		}
	};
	xmlobj5.send(parm);
}
//加载留言列表
function readMess(){
	xmlobj6 = CreateXMLHttpRequest();
	if (document.getElementById("quest_zoom")){
		document.getElementById("quest_zoom").innerHTML = "正在加载留言列表...";
	}
				
	xmlobj6.open("GET","mess_right.php",true);
	xmlobj6.setRequestHeader("If-Modified-Since","0");
	xmlobj6.onreadystatechange = function(){
		if (xmlobj6.readyState == 4 && xmlobj6.status == 200){
			if (document.getElementById("mess_right")){
				document.getElementById("mess_right").innerHTML = xmlobj6.responseText;
			}
		}
	};
	xmlobj6.send(null);
}
//加载留言表单
function writeMess(){
	xmlobj7 = CreateXMLHttpRequest();							
	xmlobj7.open("GET","write_mess.php",true);
	xmlobj7.setRequestHeader("If-Modified-Since","0");
	xmlobj7.onreadystatechange = function(){
		if (xmlobj7.readyState == 4 && xmlobj7.status == 200){
			if (document.getElementById("get_mess")){
				document.getElementById("get_mess").innerHTML = xmlobj7.responseText;
			}
		}
	};
	xmlobj7.send(null);
}


//留言提交
function submitMess(){		
	xmlobj3 = CreateXMLHttpRequest();
	var executeUrl = "do_wriet_que.php";		
	var parm = "mess_content=" + document.getElementById("mess_content").value + "&mess_type=" + document.getElementById("mess_type").value + "&code=" + document.getElementById("code").value;
	xmlobj3.open("POST",executeUrl,true);
	xmlobj3.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlobj3.onreadystatechange = statMess;
	xmlobj3.send(parm);

}
//留言是否成功
function statMess(){
	if (xmlobj3.readyState == 4 && xmlobj3.status == 200){
		if (xmlobj3.responseText == "1"){
			form1.mess_content.value="";
			form1.code.value="";	
			readMess();
			writeMess();						
			alert("留言成功!");
			if (isreload0 == 1) {
				window.location.reload();	
			}
		}else{
			alert(xmlobj3.responseText);
		}
	}
	
}

//控制文本区域能输入的最多字数
function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) 
		field.value = field.value.substring(0,maxlimit);
	else 
		countfield.innerHTML = maxlimit - field.value.length;
}

//登录页面隐藏域随机数code
function randCode(){
	var obj;	
	obj = CreateXMLHttpRequest();							
	obj.open("GET","/includes/code.php",true);
	obj.setRequestHeader("If-Modified-Since","0");
	obj.onreadystatechange = function(){
		if (obj.readyState == 4 && obj.status == 200){
			document.getElementById('code').value = obj.responseText;
			document.getElementById('vip_code').value = obj.responseText;			
		}
	};
	obj.send(null);
}




