//alert(1);


//生成ajax对象
function ajax(){
	xmlHttp=false;
	if(window.ActiveXObject){//IE
		 try{
		  	xmlHttp=new ActiveXObject("Msxml2.xmlHttp");
		 }catch(e){
			try{
				xmlHttp=new ActiveXobject("Microsoft.xmlHttp");
			}catch(e){}
		 }
	}else{//Mozilla
		 xmlHttp=new XMLHttpRequest();
		 if(xmlHttp.overrideMimeType){//MIME
		 	xmlHttp.overrideMimeType("text/xml");
		 }
	}
	
}

//搜索提法层隐藏
function dclear(){
	document.getElementById("listkeys").style.display="none";
}

//搜索提示
function keys(v,key){
	if( key>=32 || ( key>=48 && key<=57) ||(key>=65 && key < 90) ){
		if(v=="" || v.length > 10){
			document.getElementById("listkeys").style.display="none";
		}else{
			var obj=document.getElementById("listkeys");
			obj.style.display='block';
			obj.innerHTML='';
			ajax();
			xmlHttp.open("GET","/Public/keyword/txt/"+encodeURI(v),true);
			xmlHttp.onreadystatechange = function(){
				if(xmlHttp.readyState == 4){
					var msg=xmlHttp.responseText;//johncode
					var ayy=eval('('+msg+')');
					for(i=0;i<ayy.length-1;i++){
						newdiv = document.createElement("div");
						with(newdiv){
							id='listkeys'+i;
							innerHTML=ayy[i].title;
							align="left";
							onmouseover=function(){this.style.background='#99ccff';};
							onmouseout=function(){this.style.background='#E4F7FF';};
							onclick=function(){
								document.getElementById('sea_c').value=this.innerHTML;
								obj.style.display='none';
							};
							style.cursor='pointer';
							style.height='20px';
						}
						obj.appendChild(newdiv);
					}
				}
			};
			xmlHttp.send(null);
		}
	}
}

//查询提交
function dosearch(url){
	if(url!=''){
		var v=document.getElementById("searchpid").value;
//		if(v==""){
//			alert("请选择信息类别");
//			document.getElementById("sea_c").focus();
//			return false;
//		}
		
		var keyword=document.getElementById("sea_c").value;
		if(keyword==""){
			alert("请输入关键字");
			document.getElementById("sea_c").focus();
			return false;
		}
		
		if(v=='2')
			window.location.href=url+"-newssearch-sid-2-keyword-"+encodeURI(keyword)+".html";
		else
			window.location.href=url+"-dosearch-sid-1-keyword-"+encodeURI(keyword)+".html";
	}
}


//在线报名检测
function bmcheck(f){
  var user=document.getElementById("name");
  if(user.value==""){
	  alert("请填写姓名/称呼！");
	  user.focus();
	  return false;
  }
  
  var tel=document.getElementById("tel");
  if(tel.value=="" ){
	  alert("请填写联系方式：电话/qq/Email ");
	  tel.focus();
	  return false;
  }
  
}


//在线报名 ajax
function bmsubmit(url){
  var user=document.getElementById("name");
  if(user.value==""){
	  alert("请填写姓名/称呼！");
	  user.focus();
	  return false;
  }
  
  var tel=document.getElementById("tel");
  if(tel.value=="" ){
	  alert("请填写联系方式：电话/qq/Email ");
	  tel.focus();
	  return false;
  }
  
  
  var title=document.getElementById("title").value;
  var qq=document.getElementById("qq").value;
  var email=document.getElementById("email").value;
  var contents=document.getElementById("contents").value;
  var addr=document.getElementById("addr").value;
  var pxid=document.getElementById("pxid").value;
  
  ajax();
  var str="title="+title+"&name="+user.value+"&tel="+tel.value+"&qq="+qq+"&email="+email+"&contents="+contents+"&pxid="+pxid+"&addr="+addr;
	
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 4){
			var msg=xmlHttp.responseText;
			
			if(msg==1){
				closediv('light');
				alert("报名成功");
			}
		}
	};
	xmlHttp.send(str);
}



//课程列表条件选项
function lists(obj,str){
    var objs=document.getElementsByName(str+"[]");
	for(var i=0;i<objs.length;i++){
		objs[i].checked = false;
	}
	obj.checked = true;
	var v=obj.value;
	var url=window.location.pathname;
	
	//条件加入或替换 1价格
	if(str=='price'){
		var ok=url.search(/price/);
		if(ok>=0){
			url=url.replace(/price-\d+/,'price-'+v);
		}else{
			url=url.replace(/.html/,'');
			url+='-price-'+v+'.html';
		}
		url=url.replace(/-prices1-\d+/,'');
		url=url.replace(/-prices2-\d+/,'');
	}
	
	//条件加入或替换 2上课时段
	else if(str=='kc'){
		var ok=url.search(/kc/);
		if(ok>=0){
			url=url.replace(/kc-\d+/,'kc-'+v);
		}else{
			url=url.replace(/.html/,'');
			url+='-kc-'+v+'.html';
		}
	}

	window.location.href=url;
}

//课程列表条件选项 输入价格
function listprice(){
	var v1=document.getElementById("prices1").value;
	if(v1==""){
		alert("请输入查询价格1");
		document.getElementById("prices1").focus();
		return false;
	}
	var v2=document.getElementById("prices2").value;
	if(v2==""){
		alert("请输入查询价格2");
		document.getElementById("prices2").focus();
		return false;
	}
	if(v1 > v2){
		alert("输入价格区间有误:后面的价格不能小于前面的价格");
		document.getElementById("prices2").focus();
		return false;
	}
	
	var obj1=document.getElementsByName("price[]");
	for(var i=0;i<obj1.length;i++){
		obj1[i].checked = false;
	}
	
	var url=window.location.pathname;
	//条件加入或替换 1价格
	
	var ok=url.search(/price/);
	if(ok>=0){
		url=url.replace(/-price-\d+/,'');
	}
	
	var ok=url.search(/prices1/);
	if(ok>=0){
		url=url.replace(/prices1-\d+/,'prices1-'+v1);
	}else{
		url=url.replace(/.html/,'');
		url+='-prices1-'+v1+'.html';
	}
	
	var ok=url.search(/prices2/);
	if(ok>=0){
		url=url.replace(/prices2-\d+/,'prices2-'+v2);
	}else{
		url=url.replace(/.html/,'');
		url+='-prices2-'+v2+'.html';
	}
	
	window.location.href=url;
}

//课程列表城市选项
function listcity(str){
	document.getElementById('citys').value=str;
	var v=encodeURI(str);
	var url=window.location.pathname;
	var ok=url.search(/citys/);
	if(ok>=0){
		url=url.replace(/.html/,'');
		url=url.replace(/citys-[^-]+/,'citys-'+v);
		url+='.html';
	}else{
		url=url.replace(/.html/,'');
		url+='-citys-'+v+'.html';
	}
	window.location.href=url;
}
//课程列表城市选项
function listcityall(){
	document.getElementById('citys').value='';
	var url=window.location.pathname;
	var ok=url.search(/citys/);
	if(ok>=0){
		url=url.replace(/-citys-[^-]+/,'');
	}
	window.location.href=url;
}

//课程列表城市选项 直接输入
function listcitygo(){
	var v=encodeURI(document.getElementById('citys').value);
	var url=window.location.pathname;
	var ok=url.search(/citys/);
	if(ok>=0){
		url=url.replace(/citys-[^-]+/,'citys-'+v);
	}else{
		url=url.replace(/.html/,'');
		url+='-citys-'+v+'.html';
	}
	window.location.href=url;
}

//课程列表 排序
function listsort(v1,v2){
	var url=window.location.pathname;
	var ok=url.search(/sort/);
	if(ok>=0){
		url=url.replace(/sort-\d+/,'sort-'+v1);
	}else{
		url=url.replace(/.html/,'');
		url+='-sort-'+v1+'.html';
	}
	
	v2=(v2==0)?1:0;
	var ok2=url.search(/asc/);
	if(ok2>=0){
		url=url.replace(/asc-\d+/,'asc-'+v2);
	}else{
		url=url.replace(/.html/,'');
		url+='-asc-'+v2+'.html';
	}
	window.location.href=url;
}


//在线报名弹出层
function op(url,id){
	
	var light=parent.document.getElementById('light');
	light.style.display='block';
	var diffY=0;
	if (document.documentElement && document.documentElement.scrollTop)
		diffY = document.documentElement.scrollTop;
	else if (document.body)
		diffY = document.body.scrollTop
	light.style.top=diffY+100+"px";
	
	var layer=parent.document.createElement("div");
	layer.id="layer";
	layer.style.width=layer.style.height="100%";
	layer.style.position=  "absolute";
	layer.style.top=layer.style.left=0;
	layer.style.backgroundColor="#000";
	layer.style.zIndex="9998";
	layer.style.opacity="0.6";
	layer.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75"; 
	layer.style.height=parent.document.body.offsetHeight +300+"px";
	parent.document.body.appendChild(layer);
	
	
	document.getElementById("va").innerHTML="";
	var layer=document.getElementById("light");
	layer.style.display="block";
	layer.style.position= "absolute";
	layer.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=95,finishOpacity=100";
	
	layer.style.left="350px";
	layer.style.zIndex="9999";
	
	ajax();
	xmlHttp.open("GET",url+"-id-"+id+"-html-1.html",true);
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 4){
			
			var msg=xmlHttp.responseText;
			document.getElementById("va").innerHTML=msg;
		}
	};
	xmlHttp.send(null);
}

//隐藏层
function closediv(id){
	var d=document.getElementById(id);
	d.style.display="none";
	var layer=parent.document.getElementById('layer');
	document.body.removeChild(layer); 
}

var cookie = new Cookies();

//显示添加短信内容
function sms(id,str){

	
	smsid1=cookie.get("smsid1");
	smsid2=cookie.get("smsid2");
	smsid3=cookie.get("smsid3");
	
	if(id==smsid1 || id==smsid2 || id==smsid3){
		if(document.getElementById("hsy51").style.display=="block"){
			alert('已经存在！');
		}
	}else{
		if(!cookie.get("sms1")){
			cookie.set("smsid1",id);
			cookie.set("sms1",str);
		}else if(!cookie.get("sms2")){
			cookie.set("smsid2",id);
			cookie.set("sms2", str);  
		}else if(!cookie.get("sms3")){
			cookie.set("smsid3",id);
			cookie.set("sms3", str);  
		}else{
			alert('一次最多只能发送3条');
		}
	}
	
	document.getElementById("sms1").innerHTML=cookie.get("sms1");
	document.getElementById("sms2").innerHTML=cookie.get("sms2");
	document.getElementById("sms3").innerHTML=cookie.get("sms3");	
	
	document.getElementById("hsy51").style.display="block";
}



//删除选定短信内容
function cleardiv(id){
	if(confirm('确定删除？')){
		cookie.remove("sms"+id);
		cookie.remove("smsid"+id);
		if(id==1){
			if(cookie.get("smsid2")){
				cookie.set("sms1",cookie.get("sms2"));
				cookie.remove("sms2");
				cookie.set("smsid1",cookie.get("smsid2"));
				cookie.remove("smsid2");
			}
			if(cookie.get("smsid3")){
				cookie.set("sms2",cookie.get("sms3"));
				cookie.remove("sms3");
				cookie.set("smsid2",cookie.get("smsid3"));
				cookie.remove("smsid3");
			}
		}else if(id==2){
			if(cookie.get("smsid3")){
				cookie.set("sms2",cookie.get("sms3"));
				cookie.remove("sms3");
				cookie.set("smsid2",cookie.get("smsid3"));
				cookie.remove("smsid3");
			}
		}
		document.getElementById("sms1").innerHTML=cookie.get("sms1");
		document.getElementById("sms2").innerHTML=cookie.get("sms2");
		document.getElementById("sms3").innerHTML=cookie.get("sms3");
	}
	
}

String.prototype.Trim = function() {   
    return this.replace(/^\s+/g, "").replace(/\s+$/g, "");   
}   


//cookies对象  
function Cookies() {   
    this.get = function(key) {   
        var cookie = document.cookie;   
        var cookieArray = cookie.split(';');   
        var val = "";   
        for (var i = 0; i < cookieArray.length; i++) {   
            if (cookieArray[i].Trim().substr(0, key.length) == key) {   
                val = cookieArray[i].Trim().substr(key.length + 1);   
                break;   
            }   
        }   
        return unescape(val);   
    };   
    this.getChild = function(key, childKey) {   
        var child = this.get(key);   
        var childs = child.split('&');   
        var val = "";   
  
        for (var i = 0; i < childs.length; i++) {   
            if (childs[i].Trim().substr(0, childKey.length) == childKey) {   
                val = childs[i].Trim().substr(childKey.length + 1);   
                break;   
            }   
        }   
        return val;   
    };   
    this.set = function(key, value) {   
        var cookie = "";   
        if (!!key && !!value)   
            cookie += key + "=" + escape(value) + ";";   
        if (!!arguments[2])   
            cookie += "expires=" + arguments[2].toGMTString() + ";";   
        if (!!arguments[3])   
            cookie += "domain=" + arguments[3] + ";";   
        if (!!arguments[4])   
            cookie += "path=" + arguments[4] + ";";   
        document.cookie = cookie;   
    };   
    this.remove = function(key) {   
        var date = new Date();   
        date.setFullYear(date.getFullYear() - 1);   
        var cookie = " " + key + "=;expires=" + date + ";"  
        document.cookie = cookie;   
    }   
}  

//短信发送
function send(url){
	var tel=document.getElementById("tel").value;
	var name=document.getElementById("name").value;
	var md5=document.getElementById("verify").value;
	
	if(tel.length!=11){
		alert("手机号不正确或没有登录。手机号正确会员才能发送！");
		return false;
	}
	
//	if(name==""){
//		alert("请输入姓名！");
//		return false;
//	}
		
	if( md5==""){
		alert("请输入验证码！");
		document.getElementById("verify").focus();
		return false;
	}
	
	var id1=cookie.get("smsid1");
	var id2=cookie.get("smsid2");
	var id3=cookie.get("smsid3");
	if(id1=="" && id2=="" && id3==""){
		alert("没有选择发送内容！");
		document.getElementById("tel").focus();
		return false;
	}
	document.getElementById("sending").innerHTML="发送中，请稍等……";
	
	var ids="";
	if(id1){
		ids=id1
	}
	if(id2){
		ids+=","+id2
	}
	if(id3){
		ids+=","+id3
	}
	ajax();
	xmlHttp.open("GET",url+"-sendsms-ids-"+ids+"-tel-"+tel+"-md5-"+md5+"-name-"+encodeURI(name)+'.html',true);
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 4){
			var msg=xmlHttp.responseText;//johncode
			if(msg==0){
					cookie.remove("smsid1");
					cookie.remove("smsid2");
					cookie.remove("smsid3");
					cookie.remove("sms1");
					cookie.remove("sms2");
					cookie.remove("sms3");
					document.getElementById("sending").innerHTML="";
					document.getElementById("verify").value="";
					document.getElementById("verifyid").src=url+"/verify";
					far_close()
					alert("发送完成！");
					
			}else{
				document.getElementById("sending").innerHTML="";
				alert(msg);				
			}
		}
	};
	xmlHttp.send(null);
}

//字体大小
function doZoom(size) {
        var zoom = document.all ? document.all['Zoom'] : document.getElementById('Zoom');
        zoom.style.fontSize = size + 'px';
}


//会员注册检测
function checkreg(f) {
	if(f.username.value==""){
		alert('请输入用户名');
		f.username.focus();
		return false;
	}
	
	if(f.pwd1.value.length<6){
		alert('请输入密码，至少6位');
		f.pwd1.focus();
		return false;
	}	
		
	if(f.pwd1.value!=f.pwd2.value){
		alert('两次输入密码不同？');
		f.pwd2.focus();
		return false;
	}
	
	if(f.email.value==""){
		alert('请输入电子邮箱，可以找回忘记密码');
		f.email.focus();
		return false;
	}
	
	if(f.code.value==""){
		alert('请输入验证码');
		f.code.focus();
		return false;
	}
}

//会员登录检测
function checklogin(f) {
	if(f.username.value==""){
		alert('请输入用户名');
		f.username.focus();
		return false;
	}
	
	if(f.pwd1.value==""){
		alert('请输入密码');
		f.pwd1.focus();
		return false;
	}	
		
	if(f.code.value==""){
		alert('请输入验证码');
		f.code.focus();
		return false;
	}
		
}

//检测会员名/email是否存在
function checkhad(url,id){
	var v=document.getElementById(id).value;
	if(id=="email"){
		var strD=/^.+@.+\..+/; 	
		if(!strD.test(v)){
			document.getElementById("pro"+id).innerHTML="格式错误!";
			return false
		}	
	}
	if(v!=""){
		ajax();
		xmlHttp.open("GET",url+"-checkhad-id-"+id+"-v-"+encodeURI(v)+".html",true);
		xmlHttp.onreadystatechange = function(){
			if(xmlHttp.readyState == 4){
				var msg=xmlHttp.responseText;
				document.getElementById("pro"+id).innerHTML=msg;
			}
		};
		xmlHttp.send(null);
	}
}


function logout(url){
	if(confirm('确定退出？'))parent.location.href=url;
}

//全部检测
function checks(){
	var num = arguments.length;
	for(var i=0;i<num; i+=2){
		var obj=document.getElementById(arguments[i]);
		if(obj.value==''){
			alert(arguments[i+1]);
			obj.focus();
			return false;
		}
	}
}


//生成课程子分类选择菜单
function pids(id,n){
	document.getElementById("pid"+n).innerHTML="";
	if(id>0){
		ajax();
		xmlHttp.open("GET","-Public-pxitems-id-"+id+".html",true);
		xmlHttp.onreadystatechange = function(){
			if(xmlHttp.readyState == 4){
				var msg=xmlHttp.responseText;
				if(msg!=0){
					
					var n2=eval(n)+1;
					var str="<select name=\"pid[]\" onchange=\"pids(this.value,"+n2+")\" >";
					str+="<option value='' >请选择</option>";					
					var arr=eval('('+msg+')');
					for(i=0;i<arr.length;i++){
						str+="<option value=\""+arr[i].id+"\">"+arr[i].title+"</option>";
					}
					str+="</select></span><span id='pid"+n2+"'>";
					document.getElementById("pid"+n).innerHTML=str;					
				}
				
			}
		};
		xmlHttp.send(null);
	}
}


//课程提交检测
function checkpx(f) {
	if(f.title.value==""){
		alert('请输入课程名称');
		f.title.focus();
		return false;
	}
	
	if(f.cityid.value==""){
		alert('请选择城市');
		f.cityid.focus();
		return false;
	}	
	
	var pid=document.getElementsByName("pid[]");
	
	if(pid[pid.length-1].value==""){
		alert('请选择课程分类');
		return false;
	}
		
}



//ajax二级联动
function a2b(id1,id2,url,act){
	 var v1=document.getElementById(id1);
	 var v2=document.getElementById(id2);
	 ajax();
	 xmlHttp.open("GET",url+"-pid-"+v1.value+"-act-"+act+".html",true);
	 xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 4){
			for(i=v2.length-1;i>=0;i--){
				v2.remove(v2.i);
			}
			var msg=xmlHttp.responseText;//johncode
			//alert(msg);
			var j=eval('('+msg+')');
			for (i=0;i<j.length;i++)
			{ 
				v2.options.add(new Option(j[i].py.substr(0,1)+"."+j[i].title,j[i].id)); 
			}
		}
	 }
	 xmlHttp.send(null); 
}


	
function choosechar(obj){
	document.getElementById("container2").style.display="block";
	//obj.value="";
}

function chooseok(v){
	document.getElementById("searchpid").value=v;
	if(v==1)
		document.getElementById("char").value="课程";
	else
		document.getElementById("char").value="资讯";
	
	document.getElementById("container2").style.display="none";
}


//0901 复制网址
function CopyURL(){
	var txt='http://'+window.location.hostname+window.location.pathname;
	
	if(window.clipboardData) {    
             window.clipboardData.clearData();    
             window.clipboardData.setData("Text", txt); 
			  alert(txt+" 网址复制成功！");
     } else if(navigator.userAgent.indexOf("Opera") != -1) {    
          window.location = txt;
		   alert(txt+" 网址复制成功！");
     } else if (window.netscape) {    
          try {    
               netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");    
          } catch (e) {    
               alert("被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'");    
          }    
          var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);    
          if (!clip)    
               return;    
          var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);    
          if (!trans)    
               return;    
          trans.addDataFlavor('text/unicode');    
          var str = new Object();    
          var len = new Object();    
          var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);    
          var copytext = txt;    
          str.data = copytext;    
          trans.setTransferData("text/unicode",str,copytext.length*2);    
          var clipid = Components.interfaces.nsIClipboard;    
          if (!clip)    
               return false;    
          clip.setData(trans,null,clipid.kGlobalClipboard);    
         alert(txt+" 网址复制成功！");
     }    
}

//0902 弹出报名显/隐格式
  
function v(id){
	for(var i=0;i<4;i++){
		document.getElementById("kctop"+i).style.display="none";
	}
	document.getElementById("kctop"+id).style.display="block";
}

