
/*
	* @function  : show_cat
	* @use_for   : 此函数代码在软件中调用用来显示分类。参数为json文本。修改时请不要更改参数数量或函数名称
*/
function show_cat( json_dat ){
	var data2   = eval('(' + json_dat + ')');
	var htm     = "";
	var lst     = data2.lst;
	for(var key in lst){
		if(lst[key] != null){
			htm_n = '        <dd data-bg="' + lst[key].bgcolor + '" data-catid="' + lst[key].catid + '" data-act="' + lst[key].act + '" data-blk="' + lst[key].blk + '">';
			htm_n = htm_n + '<a href="" class="blk-lnk">';
			htm_n = htm_n + '	<div class="blk-ico"><img src="' + lst[key].ico + '" /></div>';
			htm_n = htm_n + '	<div class="blk-txt">' + lst[key].catname + '</div>';
			htm_n = htm_n + '</a>';
			htm_n = htm_n + '</dd>';
			htm = htm + htm_n;
		}
	}
	$(".magnet").append(htm);

	$(".magnet dd").each(function(each_id){
		var catid = $(this).attr("data-catid");
		var bgcolor = sel_cat_color(each_id);
		var act = $(this).attr('data-act');
		var blk = $(this).attr('data-blk');
		
		if(blk=="2"){
			$(this).addClass("magnet_b2");
		}
		if(catid == "undefined" || typeof(bgcolor) == "undefined"){
			catid=0;
		}
		if (typeof(bgcolor) == "undefined") { 
			bgcolor="216388";
		}  
		$(this).css('background',"#" + bgcolor);
		$(this).css('border-color',"#" + bgcolor);
		$(this).css('data-border-color',"#" + bgcolor);
		$(this).find("a").attr('href','kbtool://act=category&id='+catid);

	});
	$(".magnet dd").bind({
		mousedown : function(){
			$(this).css('border-color','transparent');
		},
		mouseup   : function(){
			$(this).css('border-color' , $(this).css('data-border-color') );
		}
	});
};

function sel_cat_color( id ){
	var colarr = ['222222','1f1f1f','1f1f1f','1f1f1f','1f1f1f','1f1f1f','1f1f1f','1f1f1f','1f1f1f','1f1f1f','1f1f1f','1f1f1f','1f1f1f','1f1f1f','1f1f1f','1f1f1f'];
	return colarr[id];
}

/*
	* @function  : show_softlst
	* @use_for   : 此函数代码在软件中调用用来显示所在分类中的软件列表。参数为json文本。
*/
function show_softlst( json_dat ){
	var data1   = eval('(' + json_dat + ')');
	var htm     = "";
	var lst     = data1.lst;
	var catid   = data1.catid;
	var catname = data1.catname;
	var actnode = data1.act_node;
	
	$(".fsl-hd").find("span").text( data1.catname );
	for(var key in lst){
		if(lst[key] != null){
			var htm_n = "";
			htm_n = htm_n + '<li data-ico="' + lst[key].icopath + '"  data-id="' + lst[key].id + '" >';
			htm_n = htm_n + '  <a href="#" class="fslli-ico"></a>';
			htm_n = htm_n + '  <a href="kbtool://act=runsoft&id=' + lst[key].id + '" class="fslbd-run"><img src="' + lst[key].icopath + '"  />' + lst[key].softname + '</a>';
			htm_n = htm_n + '  <div class="fslbd-desc">' + lst[key].description;
			htm_n = htm_n + '    <div class="fslbd-desc-act"><a href="#" data-act="1">打开目录</a> | <a href="#" data-act="2">启动程序</a> | <a href="#" data-act="3">查看使用方法</a></div>';
			htm_n = htm_n + '  </div>';
			htm_n = htm_n + '</li>';
			
			htm = htm + htm_n;
		}
	}
	$(".fsl-bd ul").html(htm);
	$(".fsl").show();
	setTimeout(function(){
		$(".fsl-bd ul li img").each(function(){  
			if(this.fileSize<=0){  
				this.src="res/ico/img.png";  
			}
		});	
	} , 50);
	if(actnode == "3"){
		$(".fsl-bd ul").append("<li><h5><a href='http://www.kbtool.cn/ziyuan.html' target='_blank'>更多资源下载</a></h5></li>");
		$(".fsl-bd ul").append("  <p>&nbsp; </p><iframe src='http://www.kbtool.cn/kbt_kjym.html' allowtransparency='true' width=395 frameborder='0' style='border:none;'></iframe>");
	}
}
$(".fslbd-desc-act a").live("click",function(){
	var act = $(this).attr("data-act");
	if(act=="1"){
		var sid = $(this).parents("LI").attr("data-id");
		window.location = "kbtool://act=opendir&id=" + sid;
	}
	if(act=="2"){
		var url = $(this).parents("LI").find(".fslbd-run").attr("href");
		if(url != "" && url != "null" ){
			
			window.location = url;
		}
	}
	if(act=="3"){
		var sid = $(this).parents("LI").attr("data-id");
		window.location = "kbtool://act=tutorial&id=" + sid;
	}
});

/*
	* @function  : show_pz
	* @use_for   : 此函数代码在软件中调用用来显示配置信息。参数为json文本。
*/
function show_pz( json_dat ){
	var data1 = eval('(' + json_dat + ')');
	var htm = "<table border=0 id='blk-pz-tab'>";
	htm = htm + "<tr><td class='blk-pz-th'>操作系统：</td><td>" + data1.system.caption + " (" + data1.system.osarchitecture + ")</td></tr>";
	htm = htm + "<tr><td class='blk-pz-th'>CPU信息：</td><td>" + data1.cpu.name + "</td></tr>\r\n";
	htm = htm + "<tr><td class='blk-pz-th'></td><td>" + data1.cpu.step + "</td></tr>\r\n";
	htm = htm + "<tr><td class='blk-pz-th'>主板信息：</td><td>" + data1.baseboard.manufacturer + " " + data1.baseboard.product + "</td></tr>\r\n";
	htm = htm + "<tr><td class='blk-pz-th'>内存信息：</td><td>" + data_mem(data1.memory) + " (" +data_mem_freq(data1.memory) + ")</td></tr>\r\n";
	htm = htm + "<tr><td class='blk-pz-th'>显卡信息：</td><td>" + data_gcd(data1.videocard) + "</td></tr>\r\n";
	htm = htm + "<tr><td class='blk-pz-th'>硬盘信息：</td><td>" + data_dsk(data1.disk) + "</td></tr>\r\n";
	htm = htm + "<tr><td class='blk-pz-th'>网卡信息：</td><td>" + data_ncd(data1.netadapter) + "</td></tr>";
	htm = htm + "<tr><td class='blk-pz-th'>声卡信息：</td><td>" + data_scd(data1.sounddevice) + "</td></tr>";
	htm = htm + "<tr><td class='blk-pz-th'>显示设备：</td><td>" + data_mnt(data1.monitor) + "</td></tr>";
	htm = htm + "</table>";
	htm = htm + "<div id='fsl-bd-pz'></div>"
	$(".blk-pz-txt").html(htm);
	
	
};

/*
	* @function  : show_ts
	* @use_for   : 此函数代码在软件中调用用来显示提示。参数为显示的文本。
*/
function show_ts( tishi ){
	$(".slayer").fadeIn(1000);
	$(".slayer").text(tishi);
	setTimeout(function(){$(".slayer").fadeOut(1000);},2000);
	
}

/*
	* @function  : show_upd
	* @use_for   : 此函数代码在软件中调用用来显示版本提示文本。参数为显示的文本。
*/
function show_upd( tishi ){
	$(".blk-update").html('软件版本：<A href="kbtool://act=update">' + tishi + '</a>');
	
}

/*
	* @function  : show_temp
	* @use_for   : 此函数代码在软件中调用用来显示版本提示文本。参数为显示的文本。
*/
function show_temp( tishi ){
	$(".blk-update").after( tishi );
	
}

/*
	* @function  : show_ad
	* @use_for   : 此函数代码在软件中调用用来显示广告。请不要删除本函数。可在软件设置里关闭广告。
*/
function show_ad( json_dat ){
	
	var data1   = eval('(' + json_dat + ')');
	var lst		= data1.adlist;
	$(".blk-ad").remove();
	for(var key in lst){
		inhtm   = "<a href='kbtool://act=openurl&href=" + encodeURIComponent(lst[key].url) + "/' class='blk-lnk'><img alt='" + lst[key].alt + "' src='" + lst[key].img + "' class='blk-ad_pic' /></a>";
		inhtm	= inhtm + "<div data-id='" + lst[key].id + "' id='blk-ad_close'>赞助 <em>×</em></div>";
		if(lst[key] != null){
			$(".magnet").append("<dd data-border-color='#ffffff' data-bg='ffffff' data-act='21' class='blk-ad'>" + inhtm + "</dd>");
			
		}
	}
	$("#blk-ad_close").click(function(){
		window.location = "kbtool://act=closead&id=" + $(this).attr('data-id');
		return false;
	});
}

$("#blk-pz-jp").click(function(){
	window.location = "kbtool://act=snapscr/";
	return false;
});
$("#blk-pz-fz").click(function(){
	var str = document.getElementById("blk-pz-txt").innerText + "\r\n--------------本信息复制自卡吧工具箱（kbtool.cn）--------------";
	if(window.clipboardData.setData('Text',str)){
		alert("已复制指定数据");
	}else{
		alert("复制配置信息失败");
	}
	return false;
});

$(".fsl-back").live('click',function(){
	$(".fsl").fadeOut(800);
});

$(".fslli-ico").live('click',function(){

	var scr = $(this).attr("data-scr");
	if(scr=="1"){
		$(this).parents("li").find(".fslbd-desc").fadeOut(500);
		$(this).attr("data-scr" , "0");
		$(this).removeClass("fslli-ico-on");
	}else{
		$(this).parents("li").find(".fslbd-desc").fadeIn(500);
		$(this).attr("data-scr" , "1");
		$(this).addClass("fslli-ico-on");
	}
});



function data_mem( obj ){
	var val = 0;
	for( var key in obj){
		val = val + parseInt(obj[key].capacity / 1024);
	}
	if(val <1048576){
		var str = fomatFloat(parseFloat(val / 1024),1) + " MB";
	}else{
		var str = fomatFloat(parseFloat(val / 1024 / 1024),1) + " GB";
	}
	return str;
}
function data_mem_freq( obj ){
	var freq_s = "";
	var val = 0;
	for( var key in obj){
		val = parseInt(obj[key].capacity / 1024);
		if(val <1048576){
			var str = fomatFloat(parseFloat(val / 1024),1) + " MB";
		}else{
			var str = fomatFloat(parseFloat(val / 1024 / 1024),1) + " GB";
		}
		
		
		freq_s = freq_s + str +" / ";
	}	
	return freq_s;
}
function data_gcd( obj ){
	var val = "";
	for( var key in obj){
		val = val + obj[key].name + "<br>";
	}
	return val;
	
}
function data_ncd( obj ){
	var val = "";
	var netid = "";
	for( var key in obj){
		obj[key].netconnectionid!="" ? netid = " (" + obj[key].netconnectionid + ")" : netid = obj[key].netconnectionid ;
		val = val + obj[key].name + netid + "<br>";
	}
	return val;
}
function data_mnt( obj ){
	var val = "";
	var mf = "";
	for( var key in obj){
		if(typeof(obj[key].vendorid) != "undefined"){
			mf = obj[key].manufacturer;
			if(mf == ""){
				mf = obj[key].vendorid;
			}
			val = val + obj[key].dspname + " " + mf + " " + obj[key].model_f + " [" + obj[key].vendorid + obj[key].model_s + "] " + obj[key].m_size + "英寸<br>";
		}
	}
	return val;
}
function data_dsk( obj ){
	var val = "";
	for( var key in obj){
		val = val + obj[key].model + " (" + data_dsk_size(obj[key].size) + ")<br>";
	}
	return val;
}
function data_dsk_size( val ){
	val1 = val / 1000 / 1000
	val2 = parseInt(val1);
	if(val1<1){
		return fomatFloat( val1 * 1000,3) + " KB";
	}
	if(val2 >1 & val2 <=1000){
		return fomatFloat( Math.round( val2 ),1 ) + " MB";
	}
	if(val2 >1000 & val2 <=1000*1000){
		return fomatFloat( Math.round( val2 / 1000 ),1 ) + " GB";
	}
	if(val2 >1000*1000 & val2 <=1000*1000*1000){
		return fomatFloat( Math.round( val2 / 1000 / 1000 ),1 ) + " TB";
	}
	if(val2 >1000*1000*1000 & val2 <=1000*1000*1000*1000){
		return fomatFloat( Math.round( val2 / 1000 / 1000 / 1000 ),1 ) + " PB";
	}
	return val1;
}
function data_scd( obj ){
	var val = "";
	for( var key in obj){
		val = val + obj[key].name + "<br>";
	}
	return val;
}

function fomatFloat(src,pos){     
	return src.toFixed(pos);     
}

