$(function(){
	show("title1","content1");
	show("title2","content2");
	show("title3","content3");
	show("title4","content4");
	show("title5","content5");
	show("title6","content6");
	show("title7","content7");
	function show(title,content){
		$("#"+title).mouseover(function(){
			 $(this).addClass("current_on");
			 $("#"+content).show();
		})
		$("#"+title).mouseout(function(){
			 $(this).removeClass("current_on");
			 $("#"+content).hide();
		})
		$("#"+content).mouseover(function(){
			$("#"+title).addClass("current_on");
			 $("#"+content).show();
		})
		$("#"+content).mouseout(function(){
			$("#"+title).removeClass("current_on");
			 $("#"+content).hide();
		})
	}
		$("#tab1").bind("click",function(){
	  $(".tab li").removeClass("current");
	  $(".tab_sc li").hide();
	  $(this).addClass("current");
	  $("#tab1_1").show();
  });
  $("#tab2").bind("click",function(){
	  $(".tab li").removeClass("current");
	  $(".tab_sc li").hide();
	  $(this).addClass("current");
	  $("#tab2_2").show();						   
  });
  $("#tab3").bind("click",function(){
	  $(".tab li").removeClass("current");
	  $(".tab_sc li").hide();
	  $(this).addClass("current");
	  $("#tab3_3").show();							   
  });
  $("#tab4").bind("click",function(){
	  $(".tab li").removeClass("current");
	  $(this).addClass("current");
	  $(".tab_sc li").hide();
	  $(this).addClass("current");
	  $("#tab4_4").show();
  });
  $("#tab5").bind("click",function(){
	  $(".tab li").removeClass("current");
	  $(this).addClass("current");
	  $(".tab_sc li").hide();
	  $(this).addClass("current");
	  $("#tab5_5").show();
  });
  $("#tab6").bind("click",function(){
	  $(".tab li").removeClass("current");
	  $(this).addClass("current");
	  $(".tab_sc li").hide();
	  $(this).addClass("current");
	  $("#tab6_6").show();
  });
  if(document.getElementById("top_css")){
  setInterval("topResize()",10);
  }
	//文字滚动
	//多行应用@Mr.Think
	var $_wrap=$('#mulitline');//定义滚动区域
	var $_interval=2000;//定义滚动间隙时间
	var $_moving;//需要清除的动画
	$_wrap.hover(function(){
	clearInterval($_moving);//当鼠标在滚动区域中时,停止滚动
	},function(){
	$_moving=setInterval(function(){
	var $_field=$_wrap.find('li:first');//此变量不可放置于函数起始处,li:first取值是变化的
	var $_h=$_field.height();//取得每次滚动高度
	$_field.animate({marginTop:-$_h+'px'},500,function(){//通过取负margin值,隐藏第一行
	$_field.css('marginTop',0).appendTo($_wrap);//隐藏后,将该行的margin值置零,并插入到最后,实现无缝滚动
	})
	},2000)//滚动间隔时间取决于_interval
	}).trigger('mouseleave');//函数载入时,模拟执行mouseleave,即自动滚动	
	
	
})

function FormatNumber(intInput) {
            var strInput = Math.abs(intInput).toString();
            var strXS = "";
            if (strInput.indexOf(".", 0) != -1) {
                strXS = strInput.substring(strInput.split(".")[0].length, strInput.length);
                strInput = strInput.split(".")[0];
            }
            var iLen = strInput.length;
            if (iLen <= 3) {
                return intInput;
            } else {
                var iMod = iLen % 3;
                var iStart = iMod;
                var aryReturn = [];
                while (iStart + 3 <= iLen) {
                    aryReturn[aryReturn.length] = strInput.substring(iStart, iStart + 3);
                    iStart = iStart + 3;
                }
                aryReturn = aryReturn.join(",");
                if (iMod != 0) {
                    aryReturn = strInput.substring(0, iMod) + "," + aryReturn;
                }
                if (intInput < 0) { aryReturn = "-" + aryReturn; }

                return aryReturn + strXS;
            }
}
function topResize(){
	 if(document.compatMode == "BackCompat"){
		var dou = document.body;
	 }else{
		var dou = document.documentElement;
	 }
	 var isIE=(document.all)?true:false;
	 if(isIE){
		document.getElementById("top_css").style.position="absolute";
		document.getElementById("top_css").style.top = (parseInt(dou.clientHeight) - parseInt(70) + parseInt(dou.scrollTop)) + "px";
	 }else{
		document.getElementById("top_css").style.position="fixed";
		document.getElementById("top_css").style.top = (parseInt(dou.clientHeight) - parseInt(70)) + "px";
	 }
     document.getElementById("top_css").style.left = (parseInt(dou.clientWidth) - parseInt(375) + parseInt(dou.scrollLeft)) + "px";
}
function loadKey(){
	 var Zindex = 1000;
     var Opacity = 100;
	 if(document.compatMode == "BackCompat"){
		var dou = document.body;
	 }else{
		var dou = document.documentElement;
	 }
	 var __bw = $("body").width();
     var __bh = $("body").height() > $(window).height() ? $("body").height() : $(window).height();
     var __bgdiv = '<div id="bg_div" style="position:absolute;left:0px;top:0px;display:none;width:' + __bw + 'px;height:' + parseInt(__bh) + 'px;background:#000;filter:alpha(opacity=' + (Opacity * 0.3) + ');opacity:' + 0.3 + ';z-index:' + (Zindex) + ';"></div><div id="loading" style="display:none;position:absolute;left;0px;background:url(./skin_new/images/onLoad.gif) top no-repeat;width:100%;height:200px;z-index:3000;"></div>';
     $("body").append(__bgdiv);
	 $("#bg_div").fadeIn();
	 $("#loading").fadeIn();
	 document.getElementById("loading").style.top=(parseInt(150) + parseInt(dou.scrollTop)) + "px";

}

var start=0;
var end=0;
function savePos(textBox){
	if(typeof(textBox.selectionStart) == "number"){
		start = textBox.selectionStart;
		end = textBox.selectionEnd;
	}
	else if(document.selection){
		var range = document.selection.createRange();
		if(range.parentElement().id == textBox.id){
			var range_all = document.body.createTextRange();
			range_all.moveToElementText(textBox);
			for (start=0; range_all.compareEndPoints("StartToStart", range) < 0; start++) {
				range_all.moveStart('character', 1);
			}
			for (var i = 0; i <= start; i ++) {
				if (textBox.value.charAt(i) == '\n')
				start++;
			}
			var range_all = document.body.createTextRange();
			range_all.moveToElementText(textBox);
			for (end = 0; range_all.compareEndPoints('StartToEnd', range) < 0; end ++) {
				range_all.moveStart('character', 1);
			}
			for (var i = 0; i <= end; i ++){
				if (textBox.value.charAt(i) == '\n'){
					end ++;
				}
			}
		}
	}
}

function add(value){
	var columnValue = $("#columnValue").val();
	var selectValue = $("#selectValue").val();
	var selectId = $("#selectId").val();
	var nameIdObj = $("#nameId");
	var nameId = nameIdObj.val();
	var keyValue=$("#keyValue").val();
	var textBox = document.getElementById("textBox");
	var pre = textBox.value.substr(0, start);
	var post = textBox.value.substr(end);
	textBox.focus();   //重要
	
	if (keyValue == "kwd") {
		textBox.value = pre + "[关键词:" +selectValue+ "]"+ post;
		$("#keyValue").val("");
	} else if (value == "AND") {
		textBox.value = pre + " 和 " + post;
	} else if(value == "OR") {
		textBox.value = pre + " 或 " + post;
	} else if(value == "NOT") {
		if (columnValue && selectValue) {
			textBox.value = pre + " " +columnValue+ "<>'" +selectValue+ "' " + post;
			$("#columnValue").val("");
			$("#selectValue").val("");
		}
	} else if(value == "()") {
		var selected = textBox.value.substr(start,end-start);
		textBox.value = pre + "(" +selected+ ")" + post;
	} else {
		if (columnValue && selectValue) {
			textBox.value = pre + "[" + columnValue +":"+selectValue + "]"+ post;
			if (columnValue !='时') {
				//nameIdObj.val(nameId + "|" + selectValue + "=" + selectId);
				nameIdObj.val(nameId + "|" + columnValue + ":" + selectValue + "=" + selectId);
			}
			$("#columnValue").val("");
			$("#selectValue").val("");
			$("#selectId").val("");
		}
	}
	savePos(textBox);	
}
function showNode(othis,num){
	if($(othis).attr("src")=="./skin_new/images/icon_37.gif"){
		$(othis).attr("src","./skin_new/images/icon_36.gif");
		$(".treeNode"+num).show();
	}else{
	    $(othis).attr("src","./skin_new/images/icon_37.gif");
		$(".treeNode"+num).hide();
	}
}



function readCookie(n) {
        var co=document.cookie;
        
        var v,t,p=co.indexOf(n);
        if (p<0) {
                return "";
        }

        if (p>0) {
                n=" "+n;
                p=co.indexOf(n);
        }

        if (p<0) {
                return "";
        }

        t=co.substring(p+1+n.length,co.length);
        p=t.indexOf(";")
        if (p < 0) {
                        v=t;
        }
        else {
                v=t.substring(0,p);
        }

        return v;
}
function dingyue(id,mid,mmid,parentid){
    var ids;
	var num;
	ids = $("#tids").val();
	num = ids.indexOf(id);
	if(num == -1) {
		$.ajax({
		   type: "POST",
		   url: "/dingyue.php",
		   data: "id="+id,
		   dataType:"json",
		   success: function(msg){
			countStr = '<div class="cae_con">';
			countStr+='<img src="'+msg.file_path+'" width="128" height="66"/>'
			countStr+='<h3><span class="online"><a href="content.php?id='+id+'&mid='+mid+'&mmid='+mmid+'&parentid='+parentid+'" class="gray_s" target="_blank">在线观看</a></span>&nbsp;<span class="xiazai"><a href="case_center.php?id='+id+'&isDownload=1" class="gray_s" target="_blank">下载</a></span></h3>';
			countStr+='</div>';
			$("#dy").after(countStr);
			if(ids == ''){
				ids = id;
			} else {
				ids = ids+','+id;
			}
			$("#tids").val(ids);
		   }
		}); 
	} else {
		alert("您已经订阅了此案例");
		return flase;
	}
}

function dingyuestatic(id,mid,mmid,parentid){
    var ids;
	var num;
	ids = $("#tids").val();
	num = ids.indexOf(id);
	if(num == -1) {
		$.ajax({
		   type: "POST",
		   url: "/dingyue.php",
		   data: "id="+id,
		   dataType:"json",
		   success: function(msg){
			countStr = '<div class="cae_con">';
			countStr+='<img src="'+msg.file_path+'" width="128" height="66"/>'
			countStr+='<h3><span class="online"><a href="/show/show'+id+'_'+mid+'_'+mmid+'.html" class="gray_s" target="_blank">在线观看</a></span>&nbsp;<span class="xiazai"><a href="case_center.php?id='+id+'&isDownload=1" class="gray_s" target="_blank">下载</a></span></h3>';
			countStr+='</div>';
			$("#dy").after(countStr);
			if(ids == ''){
				ids = id;
			} else {
				ids = ids+','+id;
			}
			$("#tids").val(ids);
		   }
		}); 
	} else {
		alert("您已经订阅了此案例");
		return flase;
	}
}

function clearMailInput(obj){
	if( $(obj).val() == '' || $(obj).val() == "请输入您的Email" ){
		$(obj).val('');
	}
}
function resetMailInput(obj){
	if( $(obj).val() == '' || $(obj).val() == "请输入您的Email" ){
		$(obj).val('请输入您的Email');
	}
}
function takeSubmit(obj) {
	if($("#tids").val() == ''){
		alert('你还没有订阅，不能发送邮件');
		return false;
	}
	if(!isEmail($("#mails").val())){
		alert('邮件地址不正确，不能发送邮件');
		return false;
	}
	//alert($("#mails").val());return false;
	$.post("/email.php",
		{ act:"takeMail", nids: $("#tids").val(), email: $("#mails").val() },
		function(data){
			if(data == '1'){
				alert("订阅成功");
			}else{
				alert("订阅失败，稍后再订阅");
			}
			$("#mails").val('请输入您的Email');
			$("#tids").val('')
		}
	);
	return false;
}
/* checkEmail */
function isEmail(val) {
	var reg = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
	if(val.match(reg) && val != "" && val != "请输入您的Email") {
		return true;
	}else {
		return false;
	}
}
function jsRedirectTo(url) {
	if(url == null){url=location.host;}
	window.open(url);
}
