// JavaScript Document

//龙之团队漫画：动态增加上传文件的file框
function addCartoonField(){
	jQuery("#test").before("<tr><td>作品大圖：</td><td><input type='file' name='upload'/><input type='button' value='取消' onclick='javascript:delCartoonField(this)'/>------------------->作品小圖：<input type='file' name='uploadSmall'/></td></tr>");	
}
//龙之团队漫画：动态删除上传文件的file框
function delCartoonField( ths ){
	jQuery(ths).parent().parent().replaceWith("");	
}

//删除漫画作品
function delCartoon( _id , ths ){
	var t = _id ;
	jQuery.ajax({
		type: "post",
		cache: false,
		data: {cartoon_id:t},
		url: "deleteCartoonTeamAction.action",
		dataType:'html',   //接受数据格式   
		success: function(msg){
			jQuery(ths).parent().hide();
		}
	});
}

//换图：版权作品的图像附件
function delCopyRightPic(ths){
	jQuery(ths).hide();
	jQuery("#nochange").hide();
	jQuery("#change").show();
	jQuery("#change1").show();
	
}
//取消换图
function noDelCopyRightPic(ths){
	jQuery(ths).hide();
	jQuery("#change").hide();
	jQuery("#change").attr("value","");
	jQuery("#nochange").show();
	jQuery("#nochange1").show();
}
//换图 与 取消换图
function addAndReset(ths,p1,p2,p3,p4){
	jQuery(ths).toggle();
	jQuery('#'+p1).toggle();
	jQuery('#'+p2).toggle();
	jQuery('#'+p3).toggle();
	jQuery('#'+p4).attr("value","");
}
//换电子档：版权作品的电子档附件
function delCopyRightEfile(ths){
	jQuery(ths).hide();
	jQuery("#filenochange").hide();
	jQuery("#filechange").show();
	jQuery("#filechange1").show();
	
}
//取消换电子档
function noDelCopyRightEfile(ths){
	jQuery(ths).hide();
	jQuery("#filechange").hide();
	jQuery("#filechange").attr("value","");
	jQuery("#filenochange").show();
	jQuery("#filenochange1").show();
}

//群体删除 版权作品
function delMuchCopyRight(_id){
	//myform.action="trade_delete.asp";
	var myform = document.getElementById(_id);
	myform.submit(); 

}

//群体删除，版权作者
function delMuchCopyRightMan(_id){
	var myform = document.getElementById(_id);
	myform.submit(); 
}

//群体删除 龙之团队
function delMuchCartoon( _id ){
	var myform = document.getElementById(_id);
	myform.submit();
}


//全选：所有
function selectAllTest( _todoname ){
	var $name = ":checkbox[name="+_todoname+"]";
	jQuery($name).attr("checked","checked");
}
//反选: suoyou 
function selectOppTest(  _todoname){
	var $name = "[name="+_todoname+"]";
	jQuery($name).each(function(i){
		if(jQuery(this).attr("checked"))
            {
                jQuery(this).removeAttr("checked");
            }
            else
            {
                jQuery(this).attr("checked",'true');    
            }									 
	});
}

//全选或取消: suoyou 
function selectTest( _clickid , _todoname){
	var $bb = jQuery(_clickid);
	var $name = "[name="+_todoname+"]";
	
	jQuery( $name ).each(function(i){
		//alert(i);
		if( $bb.attr("checked") )
            {
				jQuery(this).attr("checked",'true');   
            }
            else
            {
               jQuery(this).removeAttr("checked");  
            }									 
	});
}

//群删新闻消息,
function delMuchNews( _id ){
	var myform = document.getElementById(_id);
	myform.submit();
}


//群删，提交很多ID
function delMuch( _id ){
	var myform = document.getElementById(_id);
	myform.submit();
}

//删除一个团队
function delTeam( _id ){
	alert("del start !");
	var t = _id ;
//	jQuery.ajax({
	//	type: "post",
		//cache: false,
		//data: {cartoon_id:t},
		//url: "deleteTeamToListTeamAction.action?artist_id="+_id,
		//dataType:'html',   //接受数据格式   
		//success: function(msg){
	//		alert("del ok !");
		//}
	//});
}


//版权交易：类别分页（ajax）
function readJiaoKeShu( startIndex , type_id , _div){
	if( startIndex!="null"){
		var t1 = startIndex;
	}else{
		var t1 = jQuery("#pageNums").val()-1;
	}
	var t2 = type_id ;
	var t3 = _div ;
	jQuery.ajax({
		type: "post",
		cache: false,
		data: {startIndex:t1,copyright_type_id:t2,copyright_div:t3},
		url: "getCRListByOneTypeCopyRightAction.action",
		dataType:'html',   //接受数据格式   
		success: function(msg){
			jQuery(_div).html(msg);
		}
	});
}

//版权交易：提交条件，搜索结果
function readCRByConditions( startIndex ,  _div ){
	var $inp = '#'+_div+'startIndex';			//表单的“当前分页”的filed的id号
	//alert($inp);
	if( startIndex!="null"){
		jQuery($inp).attr("value",startIndex);//"#startIndex"
		//alert( jQuery($inp).attr("value") );
	}else{
		var $pageNum = '#'+_div+'pageNums';
		jQuery($inp).attr("value", jQuery($pageNum).val()-1 );
	}
	
	var $form = '#'+_div+'Form';
	var $div = '#'+_div ;
    var options ={  
        //target:'#project_needs',  
        url:'searchCRUICopyRightAction.action',  //提交地址  
        type:'POST',          //方式  
        dataType: 'html',   //服务器返回的数据形式
		beforeSubmit : function(){
			jQuery("#wait").show();
		},
        success: function(msg) {    //回传函数实体，参数为XMLhttpRequest.responseText  
           jQuery($div).html(msg);
		   jQuery("#wait").hide();
        },
		error :function(){
			jQuery("#wait").hide();
		}
    }; 
    jQuery($form).ajaxSubmit(options); //options  
}
//版权交易：返回默认搜索页面
function readReturn( type_id , _div ){
	var t2 = type_id ;
	var t3 = _div ;
	jQuery.ajax({
		type: "post",
		cache: false,
		data: {startIndex:0,copyright_type_id:t2,copyright_div:t3},
		url: "searchCRUICopyRightAction.action", //getCRListByOneTypeCopyRightAction
		dataType:'html',   //接受数据格式   
		success: function(msg){
			var $div = '#'+_div ;
			jQuery($div).html(msg);
		}
	});
    //ajax提交  
    jQuery("#wait").ajaxStart(function(){   
		jQuery(this).show(); //jQuery("#wait")
    });              
     //ajax结束状态  
    jQuery("#wait").ajaxStop(function(){  
    	jQuery("#wait").hide(); 
    });  
}
//版权交易：排序
function changeOrder( _order , _div ){
	var $order = '#'+_div + 'order' ;
	jQuery($order).attr("value",_order);
	readCRByConditions( 0 ,  _div );
}

//版权交易：搜索作品（ajax）
function searchCopyRight(  _div ){
	 var $form = _div+'Form';
     var options ={  
         //target:'#project_needs',  
         url:'searchCopyRightUICopyRightAction.action',  //提交地址  
         type:'POST',          //方式  
         dataType: 'html',   //服务器返回的数据形式  
         success: function(msg) {    //回传函数实体，参数为XMLhttpRequest.responseText  
            jQuery(_div).html(msg);
         }  
     };  
     jQuery($form).ajaxSubmit(options); //options  
}


//龙之团队: 提交表单。document.form1.action="phonenoticehistory.readTelephone.do"  
function toPageOfTeam( form ,action ){
	jQuery("#startIndex").attr("value",jQuery("#pageNums").val()-1 );
	var myform = document.getElementById(form);
	document.getElementById(form).action=action;
	myform.submit();
}

function searchTeam( form,action  ){
	var myform = document.getElementById(form);
	document.getElementById(form).action=action;
	myform.submit();
}
//内容分页：下一页
function contentNext( _num){
	var tem = jQuery("div.qqqqq:visible").attr("id");	//目前页id
	var $show = '#'+ (parseInt(tem)+ parseInt(1));	//算出后一页id
	if( parseInt(tem)+ parseInt(1) < _num ){
		jQuery("span[id='nowpage']").html(parseInt(tem)+ parseInt(1) + 1);	//设置当前页
		jQuery("div.qqqqq:visible").hide();	//隐藏目前页
		jQuery($show).show();			//显示后一页
	}
}

//内容分页：上一页
function contentPrev( _num){
	var tem = jQuery("div.qqqqq:visible").attr("id");	//目前页id
	var $show = '#'+ (parseInt(tem) - parseInt(1));	//算出后一页id
	if( parseInt(tem) - parseInt(1) < _num && parseInt(tem) - parseInt(1) >= 0){
		jQuery("span[id='nowpage']").html(parseInt(tem) - parseInt(1) + 1);
		jQuery("div.qqqqq:visible").hide();	//隐藏目前页
		jQuery($show).show();			//显示后一页
	}
}

//内容分页：第ji页
function contentFirst( _num ){
	var tem = jQuery("div.qqqqq:visible").attr("id");	//目前页id
	jQuery("div.qqqqq:visible").hide();	//隐藏目前页
	jQuery("span[id='nowpage']").html( parseInt(_num) + parseInt(1) );	//设置当前页
	var $show = '#'+ _num ;
	jQuery($show).show();			//显示后一页

}

//内容分页：获得手动输入的值
function getNum(){
	return jQuery('#getnum').val()	-1 ;
}

//点击作品，增加点击率
function addClick( _id ){
	var t = _id ;
	jQuery.ajax({
		type: "post",
		cache: false,
		data: {artist_id:t},
		url: "addClickRateTeamAction.action",
		dataType:'html',   //接受数据格式   
		success: function(msg){
			var w = msg.split(";");
			if( jQuery("#click_rate") ){
				jQuery("#click_rate").attr("title","点击率为"+w[0]);
				jQuery("#hitshow").attr("style","width:"+w[1]+"px");
			}
		}
	});
}

//点击作品，增加点击率
function addClick1( _id ){
	var t = _id ;
	jQuery.ajax({
		type: "post",
		cache: false,
		data: {artist_id:t},
		url: "addClickRateTeamAction.action",
		dataType:'html',   //接受数据格式   
		success: function(msg){		}
	});
}

function addCalendar( _thi ){
	jQuery( _thi ).datepicker({
		yearRange: '1900:2099', //取值范围.
		showOn: 'both', //输入框和图片按钮都可以使用日历控件。
		//buttonImage: 'img/calendar.gif', //日历控件的按钮
		buttonImageOnly: true,
		showButtonPanel: true
	});
	jQuery( _thi ).show();
}

//版權交易的update smalltype prepare
function updSmallTypePre( ths , _id ){
	jQuery(ths).parent().parent().children(":even").hide();
	jQuery(ths).parent().parent().children(":odd").show();
}
//版權交易的update smalltype
function updSmallType( ths , _id ){
	var $va_id = "#"+_id ; 
	var val = jQuery($va_id).val();
	jQuery.ajax({
		type : 'post' ,
		cache: false,
		data:{name:val,copyright_small_type_id:_id},
		url: 'updSmallTypeCopyRightAction.action',
		dataType:'html',
		success:function(html){
			var $fanhui_id = "#"+_id+'f' ; 
			jQuery($fanhui_id).empty();
			jQuery($fanhui_id).append(html);
			//jQuery($fanhui_id).replaceWith("<td>"+html+"</td>");
			jQuery(ths).parent().parent().children(":even").show();
			jQuery(ths).parent().parent().children(":odd").hide();
		}
	});
}
//版权交易的delete smalltype
function delSmallType( ths , _id ){
	if(confirm('確實要刪除嗎?')){
		jQuery.ajax({
			url:'deleteSmallTypeCopyRightAction.action',
			type:'post',
			data:{copyright_small_type_id:_id},
			cache:false ,
			dataType:'html',
			success:function(){
				jQuery(ths).parent().parent().hide();
			}
		});
	}else{
		return false;	
	}
}

//提交好友连接申请
function applyLink( _formID){
	var options={
		url:'addLinkApplysFriendAction.action',	
		type:'POST', 
		dataType:'html',
		success:function(html){
			alert(html);
			if( html.indexOf('成功') > 0 ){
				jQuery("#linksForm").hide();
			}
			//jQuery("#linksForm").hide();
			//jQuery("#back").show();
			//jQuery("#infoForm").empty().prepend( html );
		}
	};
	jQuery('#'+_formID ).ajaxSubmit(options); //options
}

function showApply(){
	jQuery("#linksForm").show();
}
//link.jsp广告处理

//截取前面部分文字，后面加上“……”
function suolve( str , sub_length){
	var temp1 = str.replace(/[^\x00-\xff]/g,"**");
	var temp2 = temp1.substring(0,sub_length);
	//找出有多少个*
	var x_length = temp2.split("\*").length - 1 ;
	var hanzi_num = x_length /2 ;
	sub_length = sub_length - hanzi_num ;//实际需要sub的长度是总长度-汉字长度
	var res = str.substring(0,sub_length);
	if(sub_length < str.length ){
		var end  =res+"……" ;
	}else{ 
		var end  = res ;
	}
	return end ;
}
/*----------------------------------------------------*/
