﻿// JavaScript Document

/**
 * 
 * 切换 Div Function 
 * 
 * param1：dom
 * 
 * param2: 当前样式
 * 
 * param3: 被切换的div 前缀
 * 
 * param4: 另一个div前缀
 * 
 * param5: 不在当前页的样式
 * 
 * param6: 切换的个数
 * 
 */

function switchDiv(o,classname,prefix,nextfix,oldclassname,k){

	o.className=classname
	
	 var j;
	 var id;
	 var e;
	 for(var i=1;i<=k;i++){
	   id =prefix+i;
	   j = document.getElementById(id);
	   e = document.getElementById(nextfix+i);
	   if(id != o.id){
	   	 j.className=oldclassname;
	   	 e.style.display = "none";
	   }else{
		e.style.display = "block";
	   }
	 }
	
	}


//会员登录
function check(){
//		if(document.bbsMemberUserForm.userid.valuedocument.bbsMemberUserForm.userid.value==null || document.bbsMemberUserForm.userid.value ==""){
//			alert("请注意，帐号不能为空,请输入！");
//			return false;
//		}
//		if(document.bbsMemberUserForm.kl.value==null || document.bbsMemberUserForm.kl.value==""){
//			alert("请注意，密码不能为空，请输入！");
//			return false;
//		}
		document.bbsMemberUserForm.submit();
}

function refreshValidation(){
	var img = document.getElementById('validationCodeGenerator');
	img.src = "/register/joinASK123.shtml?p=validationCodeGenerator&r=" + Math.random();
}

function fnValidationCode(val){
 	bmb.validationCode(val, backvalidationCode);
 }
 
 function backvalidationCode(rnt){
 	if(rnt != null && rnt == true){
 		document.b_plbForm.validationCode2.value = "1";
 	}else{
 		document.b_plbForm.validationCode2.value = "0";
 	}
 	
 }

function inputListener(){
	var userid = document.getElementById("userid");
	var pass = document.getElementById("pass");
	var validationCode = document.getElementById("validationCode");
	var loginSubmitButton = document.getElementById("loginSubmitButton");
	
	if(userid.value == null || userid.value == "" ||
		pass.value == null || pass.value == "" ||
		validationCode.value == null || validationCode.value == "" ){
		loginSubmitButton.disabled = true;
	}else{
		loginSubmitButton.disabled = false;
	}
}


//繁简体切换
function toConvert(lang){
    var locUrl = window.location.href;
    document.convertForm.convertUrl.value = locUrl;
    document.convertForm.action = "/index.shtml?language="+lang;
    document.convertForm.submit();
}

//回车提交,兼容IE与Firefox
function enterSubmit(e){
	var msie = (document.all) ? true : false;
    var keycode;
    if(!msie)keycode=e.which;
    else keycode=event.keyCode;
    
	if (keycode == 13) {        
		check();
    }
}

//电子报订阅
function toSubmit(){
   if(document.enewsForm.yx.value == "" || document.enewsForm.yx.value == '请输入Email'){
    	alert("请填写邮箱！");
    	document.enewsForm.yx.focus();
    	return false;
     }
     
     if(document.enewsForm.zt.checked ==true){
     	document.enewsForm.zt.value = '1';
     }else{
     	document.enewsForm.zt.value = '0';
     }
     
     if(document.enewsForm.azt.checked ==true){
     	document.enewsForm.azt.value = '1';
     }else{
     	document.enewsForm.azt.value = '0';
     }
     
     if(document.enewsForm.dzt.checked ==true){
     	document.enewsForm.dzt.value = '1';
     }else{
     	document.enewsForm.dzt.value = '0';
     }
     
   if(document.enewsForm.yx.value != ""){
  	     if(!chkemail(document.enewsForm.yx.value)){
  	    	alert("请注意，您没有正确填写邮箱！");
  	    	return false;
  	     }
  	     document.enewsForm.submit();
   }
 }
 
 function register(){
 	window.open("/register/wizard.jsp");
 }
 
 //回车提交
 function getMail(e){
 	var msie = (document.all) ? true : false;
    var keycode;
    if(!msie)keycode=e.which;
    else keycode=event.keyCode;

	  if(keycode==13)  {
	 	 toSubmit();
	  }
 }
 
 function chkemail(a){		
	return  /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/.test(a);
}

//省份城市联动
//value  省份的值
//con    需要填充的select 这里是城市
pro_city = function(value,con,defval){
	var showResponse=function(transport){
		var json = eval(transport.responseText); 
		$(con).options.length=0;
		if(json == null || json == undefined){
			var oNewNode=new Option();
			oNewNode.value="";
		    oNewNode.text="--请选择--";
			$(con).options.add(oNewNode);
		}
		else{
			var oNewNode=new Option();
			oNewNode.value="";
		    oNewNode.text="--请选择--";
		    $(con).options.add(oNewNode);
		    
			for(var i=0;i<json.length;i++){
				var oNewNode=new Option();
				oNewNode.value=json[i].key;
			    oNewNode.text=json[i].value;
			    if(defval == oNewNode.value)
			    { oNewNode.selected = true;}
				$(con).options.add(oNewNode);
			}	
		}
		
	}
	
	new Ajax.Request('/custPopSelect.shtml',
			{
				method: 'post',
				parameters:'p=pro_city&value='+value,
				onComplete: showResponse
			}
		);
}

function winopen(url, w, h) {
	OWinID = window.open(url, "", "toolbar=no,width=" + w + ",height=" + h + ",top=200 left=300 directories=no,status=no,scrollbars=no,resizable=no,menubar=no");
	OWinID.focus();
}


/**
 * 
 *图片切换广告 01
 * 
 * adsUrl 目标链接地址ID
 * 
 * adsImg 目标图片地址ID
 * 
 * adsLinks 链接集合
 * 
 * adsImages 图片地址集合
 * 
 */
 function switchPicAds(adsUrl, adsImg, adsLinks, adsImages, adsIds, adsPlaceIds, time){
 	 var curIndex=0;
	 //时间间隔 单位毫秒
	 var timeInterval=5000;
	 if(time != null && time != ''){
	 	timeInterval = time;
	 }
	 var arrimg = new Array();
	 var arrurl = new Array();
	 var arrid = new Array();
	 var arrplaceid = new Array();
	 
	var links = adsLinks.split(",");
	var images = adsImages.split(",");
	var ids = adsIds.split(",");
	var placeids = adsPlaceIds.split(",");
	if(links.length <= 1){//至少有两个广告才会轮转
		return;
	}
	for(var i = 0; i < links.length; i++ ){
	    arrurl[i] = links[i];
		arrimg[i] = images[i];
		arrid[i] = ids[i];
		arrplaceid[i] = placeids[i];
	}
	 
	 setInterval(changeImg,timeInterval);
	 function changeImg()
	 {
		 var adhurl=document.getElementById(adsUrl);
		 var adhimg=document.getElementById(adsImg);
		 if (curIndex==arrimg.length-1)
		 {
		 curIndex=0;
		 }
		 else
		 {
		 curIndex+=1;
		 }
		 
		 adhimg.src=arrimg[curIndex];
		 adhimg.alt=arrplaceid[curIndex]+"广告位,"+arrid[curIndex]+","+arrplaceid[curIndex];
		 adhurl.href=arrurl[curIndex];
	 }
 }
 
 /**
 * 
 *图片切换广告 02
 * 
 * 
 * adsLinks 链接集合
 * 
 * adsImages 图片地址集合
 * 
 * picWidth 图片宽度
 * 
 * picHeight; 图片高度
 * 
 * 
 */
 function switchPicAds02(adsLinks, adsImages,picWidth, picHeight, adsids, adsplaceids){
	
	var pic_width=picWidth; 
	var pic_height=picHeight; 
	var button_pos=4; //按扭位置 1左 2右 3上 4下
	var stop_time=4000; //图片停留时间(1000为1秒钟)
	var show_text=0; //是否显示文字标签 1显示 0不显示
	var txtcolor="000000"; //文字色
	var bgcolor="DDDDDD"; //背景色
	
	var imag=new Array();
	var link=new Array();
	var text=new Array();
	
	var links = adsLinks.split(",");
	var images = adsImages.split(",");
	var adsids = adsids.split(",");
	var adsplaceids = adsplaceids.split(",");
	
	for(var i = 1; i <= links.length; i++ ){
		var surl = window.location.href;
	    link[i] = '/ask123_ads_counting.shtml?catagory=2&adsid='+adsids[i-1]+'&placeid='+adsplaceids[i-1]+'&surl='+surl;
	    link[i] = escape(link[i]);
		text[i] = "title"+i;
		imag[i] = images[i-1];
	}
	
	
	//可编辑内容结束
	var swf_height=show_text==1?pic_height+20:pic_height;
	var pics="", links="", texts="";
	for(var i=1; i<imag.length; i++){
		pics=pics+("|"+imag[i]);
		links=links+("|"+link[i]);
		texts=texts+("|"+text[i]);
	}
	pics=pics.substring(1);
	links=links.substring(1);
	texts=texts.substring(1);
	
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cabversion=6,0,0,0" width="'+ pic_width +'" height="'+ swf_height +'">');
	document.write('<param name="movie" value="/ad/focus.swf">');
	document.write('<param name="quality" value="high"><param name="wmode" value="opaque">');
	document.write('<param name="FlashVars" value="pics='+pics+'&links='+links+'&texts='+texts+'&pic_width='+
					pic_width+'&pic_height='+pic_height+'&show_text='+show_text+'&txtcolor='+txtcolor+'&bgcolor='
					+bgcolor+'&button_pos='+button_pos+'&stop_time='+stop_time+'">');
	document.write('<embed src="/ad/focus.swf" FlashVars="pics='+pics+'&links='+links+'&texts='+texts+'&pic_width='
					+pic_width+'&pic_height='+pic_height+'&show_text='+show_text+'&txtcolor='+txtcolor+'&bgcolor='
					+bgcolor+'&button_pos='+button_pos+'&stop_time='+stop_time+'" quality="high" width="'+ pic_width +'" height="'
					+ swf_height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
 }
 

///////////////////////////////
/////评论提交
/////资讯中心、资源中心等
///////////////////////////////

 function commentSummit(){
	 	
	 	if(document.b_plbForm.cj_userxm.value==""){
	   		alert("评论人不能为空");
	   		return false;
	   	}
	   	if(document.b_plbForm.pldj.value==""){
	   		alert("等级不能为空");
	   		return false;
	   	}
	   	if(document.b_plbForm.nr.value==""){
	   		alert("内容不能为空");
	   		return false;
	   	}
	   	if(document.b_plbForm.nr.value.length>4000){
	   		alert("内容太长");
	   		return false;
	   	}
	   	if(document.b_plbForm.validationCode.value==""){
	   		alert("验证码必填！");
	   		return false;
	   	}
	   	
	   	if(document.b_plbForm.validationCode2.value == '1'){
	   		 document.b_plbForm.submit();
	   		 alert("感谢您的评论！");
	   	}else{
	   		alert("验证码输入有误！");
	   		return false;
	   	}
}

function indexover(id,pre,num )
{
	for(var i=1;i<=num;i++)
	{
		var obj1=document.getElementById(pre+i);
		var obj2=document.getElementById(pre+i+"_content");
		if(i==id)
		{
			obj1.className="m_on";
			obj2.className="content";
		}
		else
		{
			
			obj1.className="m_off";
			obj2.className="content_off";
						
		  }
	}
}

 	
