// JavaScript Document
function InitAjax()
{
var ajax=false; 
    try { 
    ajax = new ActiveXObject("Msxml2.XMLHTTP"); 
  } catch (e) { 
    try { 
    ajax = new ActiveXObject("Microsoft.XMLHTTP"); 
    } catch (E) { 
     ajax = false; 
    } 
  }
  if (!ajax && typeof XMLHttpRequest!='undefined') { 
    ajax = new XMLHttpRequest(); 
  } 
  return ajax;
} 


function $(o){return document.getElementById(o)}

function Apply_Ajax(method,pars,url){
var ajax=new InitAjax();
if(pars!=""){
	pars+="&r="+Math.random();
}else{
	pars="r="+Math.random();
}
if(method.toLowerCase()=="get"){
ajax.open("GET",url+"?"+pars,true);
ajax.send();
}else{
ajax.open("POST",url+"?"+pars,true);
ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
ajax.send(pars);
}
return ajax;
}


function SelectAll(o){
var Tag=document.getElementsByName(o);
for(i=0;i<Tag.length;i++){
	if(Tag[i].checked){
		Tag[i].checked=false;
	}else{
	    Tag[i].checked=true;
	}
}
}

function getAid(){
var Tag=document.getElementsByName("aid");
for(i=0;i<Tag.length;i++){
	if(Tag[i].checked){
		return Tag[i].value;
	}
 }
}

function SelectOne(o){
var b=false;
var Tag=document.getElementsByName(o);
for(i=0;i<Tag.length;i++){
	if(Tag[i].checked){
	  b=true;
	}
}
return b;
}

/*GET TEST*/
function NextTest(id){
if(!SelectOne('aid')){alert("Please answer the questions");return false;}
var Etest=$('tstatus').value;
if(Etest==1){
var aid=getAid();
location.href="/test/result/?pid="+id+"&aid="+aid;
}else{
getInfo(id);
}
}

/*GET INFO*/
function getInfo(id){
var aid=getAid();
var sort;
if(!$('sort')){sort=0;}else{sort=$('sort').value;}
var ajax=Apply_Ajax("get","pid="+id+"&aid="+aid+"&sort="+sort,"/test/body/index.asp");
ajax.onreadystatechange=function(){
if(ajax.readyState==4 && ajax.status==200){
var Info=ajax.responseText;
$('sboyd').innerHTML=Info
}
}
}

function S_H(id){
var menu=$('m_'+id);
if(menu){
if(menu.style.display==""){
	menu.style.display="none";
}else{
	menu.style.display="";
}
}
}

function Chk_Login(){
var user=$('user');
var pwd=$('pwd');
var pwd2=$('pwd2');
var tname=$('tname');
var country=$('country');
var Tzone=$('Tzone');
if(!(/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/.test(user.value))){
	alert("Please fill in the correct EMAIL");
	user.focus();
	return false;
}
if(pwd.value==""){alert("Please fill in the password");pwd.focus();return false;}
if(pwd.value.length<6){alert("Password should not be less than the median 6");pwd.focus();return false;}
if(pwd2.value!=pwd.value){alert("War is not the same password, please re-enter");pwd2.focus();return false;}
if(tname.value==""){alert("Please fill the names");tname.focus();return false;}
if(country.value==""){alert("Please select country");country.focus();return false;}
if(Tzone.value==""){alert("Please select time zone");Tzone.focus();return false;}
}

function Clogin(){
var user=$('username');
var pwd=$('password');
if(user.value==""){alert("Please enter EMAIL");user.focus();return false;}
if(pwd.value==""){alert("Please enter passwords");pwd.focus();return false;}
}

function Lout(){
if(confirm("You sure you want to quit？")){location.href='/action/out/'}
}

function getcid(){
var info="";
var Tag=document.getElementsByName("cid");
for(i=0;i<Tag.length;i++){
	if(Tag[i].checked){
		if(info==""){
		info=Tag[i].value;
		}else{
		info=info+","+Tag[i].value;
		}
	}
 }
 return info;
}

//订单
function order(){
var cid=getcid();
if(!SelectOne('cid')){alert("Please select the courses you want to buy");return false;};
//alert(cid);
location.href="/order/?cid="+cid;
}

//退订
function Eorder(id){
var ajax=Apply_Ajax("get","id="+id,"/order/del.asp");
ajax.onreadystatechange=function(){
if(ajax.readyState==4 && ajax.status==200){
var Info=ajax.responseText;
//alert(Info);
location.href='/order/';
}
}
}

//获得北京时间
function getCTime(id){
var owerDate=$('owertime'+id).value;
var owerTimeId=$('hh'+id);
var owerTime=owerTimeId.options[owerTimeId.selectedIndex].value;
if(owerDate!=""&&ChkDate(owerDate)&&owerTime!=""){
//获得时间
var ajax=Apply_Ajax("get","owerDate="+owerDate+"&owerTime="+owerTime,"/member/getTime.asp");
ajax.onreadystatechange=function(){
if(ajax.readyState==4 && ajax.status==200){
var Info=ajax.responseText;
//alert(Info);
$("sTime"+id).innerHTML=Info;
}
}
}else{
$("sTime"+id).innerHTML="&nbsp;";
}
}

//提交审核
function sForm(id){
var owerDate=$('owertime'+id).value;
var owerTimeId=$('hh'+id);
var owerTime=owerTimeId.options[owerTimeId.selectedIndex].value;	
if(owerDate!=""&&ChkDate(owerDate)&&owerTime!=""){
	if(confirm('Are you sure you do set up?')){
	return true
	}else{
	return false
	}
}else{
	alert("Please fill in the correct time format");
	return false;
}
}