// 核心js
//独孤剑  QQ：348885333
function getbyid(id){
		if (document.getElementById) {
			return document.getElementById(id);
		} else if (document.all) {
			return document.all[id];
		} else if (document.layers) {
			return document.layers[id];
		} else {
			return null;
		}
	}


function getByName(s){
		return document.getElementsByName(s);
	}
	
	
function trims(str){
		return str.replace(/\s+/g,"");   
	}

function sl(st){
	sl1=st.length;
	strLen=0;
	for(i=0;i<sl1;i++){
		if(st.charCodeAt(i)>255) strLen+=2;
	 else strLen++;
	}
	return strLen;
}

var xmlHttp;
function createXHR(){
	if (window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();
	}else if (window.ActiveXObject) {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}

	if (!xmlHttp) {
		alert('您使用的瀏覽器不支援 XMLHTTP 物件');
		return false;
	}
}

function chkLength(which,obj) {  
var maxChars = 300;  
if (which.value.length > maxChars)  
which.value = which.value.substring(0,maxChars);  
var curr = maxChars - which.value.length;  
getbyid(obj).innerHTML = curr.toString();  
}  


function flash(file,w,h) {
		document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+w+'" height="'+h+'"> ');
		document.write('<param name="movie" value="' + file + '">');
		document.write('<param name="quality" value="high"> ');
		document.write('<param name="wmode" value="transparent"> ');
		document.write('<param name="menu" value="false"> '); 
		document.write('<embed src="' + file + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+w+'" height="'+h+'" wmode="transparent" ></embed> ');
		document.write('</object> ');
	}
	
function out_username(){
	var strl=sl($("#username").val());
	var str=$("#username").val();
	var chk=true;
	if ((strl<4 || strl>12)){chk=false;}
	if (chk){
		$('#d_username').html('<img src=/img/li_ok.gif style="vertical-align: text-bottom;margin-right:2px;">姓名已经输入。');
	}else{
		$('#d_username').html('<img src=/img/li_err.gif style="vertical-align: text-bottom;margin-right:2px;"><font color="red">不能少于 4 个字符或 2 个汉字</font>');
		chk=false;
	}
	return chk;
}

function out_userpass(){
	var obj=$("#d_password");
	var str=$("#password").val();
	var strl=str.length;
	
	var chk=true;

	if (strl<6 || strl>12){chk=false;}
	if (chk){
		obj.html('<img src=/img/li_ok.gif style="vertical-align: text-bottom;margin-right:2px;">密码已经输入。');
	}else{
		obj.html('<img src=/img/li_err.gif style="vertical-align: text-bottom;margin-right:2px;"><font color="red">密码长度6～12位，字母区分大小写</font>');
		chk=false;
	}
	return chk;
}

function out_userpass2(){
	var obj=$("#d_password2");
	var strl=sl($("#password2").val());
	var str=$("#password2").val();
	var chk=true;
	//alert(str);
	if ((strl<6 || strl>12)||str!=$("#password").val()){chk=false;}
	if (chk){

		obj.html('<img src=/img/li_ok.gif style="vertical-align: text-bottom;margin-right:2px;">重复密码正确');
	}else{
		obj.html('<img src=/img/li_err.gif style="vertical-align: text-bottom;margin-right:2px;"><font color="red">重复密码有误,密码长度6～12位</font>');
		chk=false;
	}
	return chk;
}

function out_truename(){
	var obj=$("#d_truename");
	var strl=sl($("#truename").val());
	var str=$("#truename").val();
	var chk=true;
	//alert(str);
	if (strl<4 || strl>12){chk=false;}
	if (chk){
		obj.html('<img src=/img/li_ok.gif style="vertical-align: text-bottom;margin-right:2px;">真实姓名已经输入。');
	}else{
		obj.html('<img src=/img/li_err.gif style="vertical-align: text-bottom;margin-right:2px;"><font color="red">请输入您的真实姓名</font>');
		chk=false;
	}
	return chk;
}

function out_zjnum(){
	var obj=$("#d_zjnum");
	var strl=sl($("#zjnum").val());
	var str=$("#zjnum").val();
	var chk=true;
	if (strl<8 || strl>24){chk=false;}
	if (chk){
		obj.html('<img src=/img/li_ok.gif style="vertical-align: text-bottom;margin-right:2px;">证件号已经输入。');
	}else{
		obj.html('<img src=/img/li_err.gif style="vertical-align: text-bottom;margin-right:2px;"><font color="red">请输入您的证件号码</font>');
		chk=false;
	}
	return chk;
}

function out_dwmc(){
	var obj=$("#d_dwmc");
	var strl=sl($("#dwmc").val());
	var str=$("#dwmc").val();
	var chk=true;
	if (strl<8&&$('#hostext').html()==''){chk=false;}
	if (chk){
		obj.html('<img src=/img/li_ok.gif style="vertical-align: text-bottom;margin-right:2px;">单位名称已经输入,为得到更好的服务,如系统无贵单位信息,切记要选择对应的省份信息。');
	}else{
		obj.html('<img src=/img/li_err.gif style="vertical-align: text-bottom;margin-right:2px;"><font color="red">请输入您的单位名称</font>');
		chk=false;
	}
	return chk;
}

function out_address(){
	var obj=$("#d_address");
	var strl=sl($("#address").val());
	var str=$("#address").val();
	var chk=true;
	if (strl<12){chk=false;}
	if (chk){
		obj.html('<img src=/img/li_ok.gif style="vertical-align: text-bottom;margin-right:2px;">单位地址已经输入。');
	}else{
		obj.html('<img src=/img/li_err.gif style="vertical-align: text-bottom;margin-right:2px;"><font color="red">请输入您的单位地址</font>');
		chk=false;
	}
	return chk;
}

function out_zipcode(){
	var obj=$("#d_zipcode");
	var strl=sl($("#zipcode").val());
	var str=$("#zipcode").val();
	var chk=true;
	if (strl<6){chk=false;}
	if (chk){
		obj.html('<img src=/img/li_ok.gif style="vertical-align: text-bottom;margin-right:2px;">邮编已经输入。');
	}else{
		obj.html('<img src=/img/li_err.gif style="vertical-align: text-bottom;margin-right:2px;"><font color="red">请输入您的邮政编码</font>');
		chk=false;
	}
	return chk;
}

function out_tel(){
	var obj=$("#d_tel");
	var strl=sl($("#tel").val());
	var str=$("#tel").val();
	var chk=true;
	if (strl<6){chk=false;}
	if (chk){
		obj.html('<img src=/img/li_ok.gif style="vertical-align: text-bottom;margin-right:2px;">联系电话已经输入。');
	}else{
		obj.html('<img src=/img/li_err.gif style="vertical-align: text-bottom;margin-right:2px;"><font color="red">请输入您的联系电话</font>');
		chk=false;
	}
	return chk;
}

function out_email(){
	var obj=$("#d_email");
	var str=$("#email").val();
	var chk=true;
	if (str==''|| !str.match(/^[\w\.\-]+@([\w\-]+\.)+[a-z]{2,4}$/ig)){chk=false}
	if (chk){
		obj.html('<img src=/img/li_ok.gif style="vertical-align: text-bottom;margin-right:2px;">电子邮箱地址已经输入。');
	}else{
		obj.html('<img src=/img/li_err.gif style="vertical-align: text-bottom;margin-right:2px;"><font color="red">请输入您的电子邮箱地址</font>');
		chk=false;
	}
	return chk;
}

function out_mobile(){
	var obj=$("#d_mobile");
	var strl=sl($("#mobile").val());
	var str=trims($("#mobile").val());
	var chk=true;
	//alert(str);
	if (!str.match(/^1\d{10}$/) ){chk=false;}
	if (chk){
		obj.html('<img src=/img/li_ok.gif style="vertical-align: text-bottom;margin-right:2px;">手机号已经输入。');
	}else{
		obj.html('<img src=/img/li_err.gif style="vertical-align: text-bottom;margin-right:2px;"><font color="red">手机号格式不正确</font>');
		chk=false;
	}
	return chk;
}
		
function num2chr(n){
	if(n==''){
		return "Z";	
	}
	n=parseInt(n);
	r="Z";
	
	switch(n){
		case 0:
			r="A";
			break;
		case 1:
			r="B";
			break;
		case 2:
			r="C";
			break;
		case 3:
			r="D";
			break;
		case 4:
			r="E";
			break;
		
	}
	return r;
}

function chklog(){
	var chk=true;
	var username=$.trim($('#logusername').val());
	var userpass=$.trim($('#loguserpass').val());
	if(username==''){
		alert('用户名没有添写!');
		$("#logusername").focus();
		chk=false;
	}else if(userpass==''){
		alert('密码没有添写!');
		$("#loguserpass").focus();
		chk=false;	
	}
	
	if(chk){
		$.get("inc/chklog.php",{t:Math.random(),username:username,password:userpass},function(data){
					k=data.split("|");
					if(parseInt(k[0])==200){
						alert(k[1]);	
						window.location.href='/member';
					}else{
						alert(k[1]);		
					}
					
			});	
	}
	
}

function CopyContent(copy)   
{   
    if (window.clipboardData)   
    {   
      window.clipboardData.setData("Text", copy);   
    }   
    else if (window.netscape)   
    {   
      netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');   
      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=copy;   
         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("已复制到剪贴板");   
      return false;      
}  

function showmap(){
		if($('#mapwin')[0].style.display=='none'){
			$('#mapwin').show();
			$('#maptip')[0].innerHTML='标注完毕';
		}else{
			$('#mapwin').hide();
			$('#maptip')[0].innerHTML='点击标注地图';
		}
	}
	
//画地图
function drawMap(poiandzom,message,info)
{
	postr=poiandzom.split("|");
	long=postr[0];
    lat = postr[1];
	scale=postr[2];
    var maps = new LTMaps("mapDiv");
    
    var point = new LTPoint(long, lat);
    maps.centerAndZoom(point,scale);
    
    
    var ScaleControl = new LTScaleControl();
    maps.addControl( ScaleControl );
    
   
    var smapcontrol = new LTSmallMapControl();
    maps.addControl( smapcontrol );
    
    {
    var icon = new LTIcon();
    icon.setImageUrl("http://www.51emedia.com/img/map_dot.gif");
    var marker = new LTMarker(new LTPoint(long, lat), icon);

    maps.addOverLay(marker);
    var infoWin = new LTInfoWindow( point,[5,35] );
		infoWin.setTitle( message ); 
		infoWin.setLabel(info.replace(/\\n/ig,'<br />')); 
		maps.addOverLay( infoWin ); 
    }
}




//发送加盟信息
function send_msg(){
	var chk=true;
	
	var username=$.trim($('#username').val());
	var tel=$.trim($('#tel').val());
	var email=$.trim($('#email').val());
	var address=$.trim($('#address').val());
	var zipcode=$.trim($('#zipcode').val());
	var code=$.trim($('#code').val());
	var content=$.trim($('#content').val());
	
	if(username==''){
		alert('姓名没有添写!');
		$("#username").focus();
		chk=false;
	}else if(!tel.match(/\d{6,13}/ig)){
		alert('电话没有添写或格式不正确!');
		$("#tel").focus();
		chk=false;	
	}else if(!email.match(/^[\w\.\-]+@([\w\-]+\.)+[a-z]{2,4}$/ig)){
		alert('Email没有添写或格式不正确!');
		$("#email").focus();
		chk=false;	
	}else if(address==''){
		alert('地址没有添写!');
		$("#address").focus();
		chk=false;	
	}else if(!zipcode.match(/\d{6}/ig)){
		alert('邮编没有添写!');
		$("#zipcode").focus();
		chk=false;	
	}else if(content==''){
		alert('加盟的简单说明没有添写!');
		$("#content").focus();
		chk=false;	
	}else if(code==''){
		alert('验证码没有添写!');
		$("#code").focus();
		chk=false;	
	}
	
	if(chk){
		$.post("inc/jmsave.php",{t:Math.random(),username:username,tel:tel,email:email,address:address,zipcode:zipcode,content:content,code:code},function(data){
					k=data.split("|");
					if(parseInt(k[0])==200){
						alert(k[1]);	
						window.location.href='?';
					}else{
						alert(k[1]);	
						$('#sub').removeAttr('disabled');
					}
					
			});	
	}else{
		$('#sub').removeAttr('disabled');	
	}
	
}


function dgjtdshow(id){
	$(".noshow").hide();
	$("#dgj"+id).slideDown('slow');
}	

//视频播放
function showflv(pic,flv,w,h){
	$("head").append("<script language='javascript' src='/js/jwplayer/swfobject.js'></script>");
	 var so = new SWFObject('/js/jwplayer/player.swf','ply',w,h,'9','#000000');
  so.addParam('allowfullscreen','true');
  so.addParam('allowscriptaccess','always');
  so.addParam('wmode','opaque');
  so.addVariable('image',pic);
  so.addVariable('file',flv);
  so.addVariable('controlbar','bottom');
 // so.addVariable('duration','34');
  so.addVariable('fullscreen','true');
  so.addVariable('stretching','fill');
  so.addVariable('autostart','false');
  so.write('mediaspace');
}


//导航显示
var timeout    = 100;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open()
{  
	jsddm_canceltimer();
   jsddm_close();
   $(this).addClass('d4');
   ddmenuitem = $(this).find('div').show();
}

function jsddm_close()
{
	if(ddmenuitem) ddmenuitem.hide();
}

function jsddm_timer()
{  
	$(this).removeClass('d4');
	closetimer = window.setTimeout(jsddm_close, timeout);
}

function jsddm_canceltimer()
{  
	if(closetimer){  
   		window.clearTimeout(closetimer);
        closetimer = null;
	}
}

//通用横向滚动
function dgj_ty_news(elementID,num,boxw,ml){
	var box = '#' + elementID;
	if($(box).children().length<num){
		return;	
	}
	$($(box).children()[0]).animate({ opacity: 0 }, 1000, "linear", function() {
        $($(box).children()[0]).animate({ marginLeft: -boxw }, 1000, "linear", function() {
          $($(box).children()[0]).css({ marginLeft: ml });
            $(box).append($($(box).children()[0]));
            $($(box).children()[(num-1)]).animate({ opacity: 1 }, 1000);
        });
    });
}

//报名信息滚动
function bm_news(){	
	if($("#scro_bm").children().length<3){
		return;	
	}
	$($("#scro_bm").children()[0]).animate({ opacity: 0 }, 1000, "linear", function() {
		var fcw=$("#scro_bm span:first-child").width();		
        $($("#scro_bm").children()[0]).animate({ marginLeft: -fcw }, 1000, "linear", function() {
			$($("#scro_bm").children()[0]).css("margin", 0);																				  
            $("#scro_bm").append($($("#scro_bm").children()[0]));
			$($("#scro_bm").children(2)).css({opacity: 1,marginLeft:5});
        });
    });
}


function hp_news(){	
	if($("#div_hp").children().length<5){
		return;	
	}
	$($("#div_hp").children()[0]).animate({ opacity: 0 }, 1000, "linear", function() {
        $($("#div_hp").children()[0]).animate({ marginTop: -24 }, 1000, "linear", function() {
          $($("#div_hp").children()[0]).css({ marginTop: 0 });
            $("#div_hp").append($($("#div_hp").children()[0]));
            $($("#div_hp").children()[(5-1)]).animate({ opacity: 1 }, 1000);
        });
    });
}

//省市联动
function GetStateText(id,s){
	if(id>0){
		$('#xiantext').html('');	
		$.get('/inc/getcity.php',{t:Math.random(),id:id,ctype:s},function(data){
			var str=data.split("|");
			if(parseInt(str[0])==200){
				if(str[1].search(/option/i)>0){
					$("#"+s+"text").html(str[1]);	
				}	
			}else{
				alert(str[1]);	
			}
		});	
	}
}



//注册时省市联动
function GetregStateText(id,s){
	if(id>0){
		$('#xiantext').html('');	
		$('#hostext').html('');		
		$.get('/inc/getuserhos.php',{t:Math.random(),id:id,ctype:s},function(data){
			var str=data.split("|");
			if(parseInt(str[0])==200){
				if(str[1].search(/option/i)>0){
					$("#"+s+"text").html(str[1]);	
				}	
			}else{
				alert(str[1]);	
			}
		});	
	}
}


//通用的切换
function ty_showdiv(o,num1,num2,c1,c2){ 
			 o.className=c1; 
			 var j;
			 var id;
			 var e;
			 for(var i=num1;i<num2;i++){
				 	id="dgj_nav_"+i;
					j=getbyid(id);
					e=getbyid("dgj_sub_"+i);
					if(id!=o.id){
							j.className=c2;
							e.style.display="none";
						}else{
								e.style.display="block";
							}
				 }
		 }
		 
function checkuser(){
			var chk=true;
			if (!out_username()){chk=false}
			if(chk){
					$.get('/inc/chkreg.php',{t:Math.random(),username:$("#username").val()},function(data){
						k=data.split("|");
						$("#d_username").html(k[1]);	
				});
			}
		}
		

//省市联动
function showsubcity(id,s,k){
	if(id>0){
		if($('#rankspan_'+id).html()=='折叠'){
			$('#rankspan_'+id).html('展开');
			$('#rankdiv_'+id).html('');
		}else{
			$.get('/inc/getrankcity.php',{t:Math.random(),id:id,ctype:s,rank:k},function(data){
				var str=data.split("|");
				if(parseInt(str[0])==200){
					$('#rankspan_'+id).html('折叠');
					$('#rankdiv_'+id).html(str[1]);
				}else{
					alert(str[1]);	
				}
			});	
		}
	}
}

//报名信息的滚动
function exam_scroll(){
	var childnum=$('#examsc').children().length;
	var childheight=$($('#examsc').children()[0]).height();
	if(childnum>8){
		for(var i=8;i<childnum;i++){
			 $($("#examsc").children()[i]).css("opacity", "0");
		}
		//$('#examsc').append($('#examsc').children()[0]);	//复制一份
		$($("#examsc").children()[0]).animate({ opacity: 0 }, 1000, "linear", function() {
			$($("#examsc").children()[0]).animate({ marginTop: -childheight }, 1000, "linear", function() {
			$($("#examsc").children()[0]).css("margin", 0);
			$("#examsc").append($($("#examsc").children()[0]));
			$($("#examsc").children()[7]).animate({ opacity: 1 }, 1000);
			});
		});
		
	}
}

function isInDiv(e,obj){
	if((e.clientX+$(document).scrollLeft()>obj.offset().left&& e.clientX+$(document).scrollLeft()<=obj.offset().left+obj.width())&& (e.clientY+$(document).scrollTop()>obj.offset().top &&e.clientY+$(document).scrollTop()<=obj.offset().top+obj.height())){
		return true;
	}else{
		return false;
	}
}
