//两个常量
var skin_list = new Array(); 
var name_list = new Array(); 
var use_list = new Array();
var skin_count = window.external.GetSkinListCount();
var version = navigator.appVersion;
var cate_list = new Array();
var ended = 0;
cate_list[8] = "卡通动漫";
cate_list[9] = "影视主题";
cate_list[10] = "游戏地带";
cate_list[11] = "明星名人";
cate_list[12] = "个人专用";
cate_list[13] = "另类其他";
cate_list[14] = "时尚酷炫";
cate_list[15] = "体育专区";
cate_list[20] = "大头贴";
cate_list[21] = "皮肤系列";
cate_list[22] = "淘宝专区";
cate_list[23] = "动画皮肤";
cate_list[24] = "静物风景";
cate_list[25] = "世界杯专区";
cate_list[26] = "iconfans";
cate_list[27] = "flash皮肤";
var arVersion = navigator.appVersion.split("MSIE");
var version = parseFloat(arVersion[1]);
if(version == "6")
	var isie6 = true;
else
	var isie6 = false;
/*
if(version.indexOf("MSIE 7.0; Windows NT 6.1") >= 0 || version.indexOf("MSIE 7.0; Windows NT 6.0") >= 0)
	var iswin7 = true;
else
	var iswin7 = false;
*/
function getSkinList(cur,limit,content,skin_id,skin_name,used,first,error){
	//var skin_id = window.external.GetSkinListPart(cur,limit);
	var arr = skin_id.split("\?");
	var namearr = skin_name.split("\?");
	var usedarr = used.split("\?");
//	alert(skin_id);
//	alert(skin_name);
/*
        jQuery.ajax({
           type: "GET",
           url: "skinmgr_getlist5.3.php",
           data: "skin_id="+skin_id,
        //   data: "skin_id=1",
           success: function(res){
*/
//		var arr = eval(res);
		var i = 0;
		var html = "";
		//var noexist = new Array;
	//	if(first == 0 && arr[0]){
	//		jQuery("#curSkinId").val(arr[0] + "_" +namearr[0].replace(/[^0-9a-zA-Z_]/g,""));
	//	}
	//	if(content == "skinlist2"){
	//		alert(res);
	//	}
		while(arr[i]){
			var id = arr[i] + "_" +namearr[i].replace(/[^0-9a-zA-Z_]/g,"");
			if(jQuery("#skinTR"+id).html()){
				i++;
				continue;
            }
            if(usedarr[i] == 1)
				jQuery("#curSkinId").val(id);
            var using = usedarr[i] == 1?'class="used" ':'';
			//var using = (first==0)&&(i==0)?'class="used" ':'';
			var dis = usedarr[i] == 1?'disabled':'';
//			alert(UrlDecode(arr[i].name));
//			alert(UrlDecode(arr[i].author));
			//默认皮肤
			var name = namearr[i];
			//alert("start="+name);	
	//		alert(id);
		//	alert("run="+id+"=name="+name);
			//alert(id+"="+name);
			/*
			if(arr[i] == 0){
				html += '<tr id="skinTR'+id+'">';
				//html += '<tr id="skinTR'+id+'" onmouseout="alert(\'11\');this.className=\'trout\';" onmouseover="alert(\'11\');this.className=\'trhover\';">';
                        	html += '<td class="checkbox1" width="4%"></td>';
                        	html += '<td width="30%" class="tit" align=center>';
				if(isie6)
                        		html += '<a href="javascript:window.external.ApplySkin(\'0\',\''+name+'\');"><div class="skin_pic"><span id="pic'+id+'" style="width:230px;display:inline-block;height:100%;"></span></div></a>';
				else
                        		html += '<a href="javascript:window.external.ApplySkin(\'0\',\''+name+'\');"><div class="skin_pic"><img width="230" id="pic'+id+'" src="'+arr[i].piccomp+'" /></div></a>';
                        	html += '<h4>输入法默认皮肤</h4>';
                        	html += '<td class="author" width="11%"><a href="http://pinyin.sogou.com/skins/home.php?pp=11085f1f0b5e71155a015f101f070e0b" target="_blank">搜狗拼音输入法</a></td>';
                        	html += '</td>';
			//添加分类
				html += '<td class="cate" width="9%"><input type="hidden" name="skin_name" value="'+name+'">系统皮肤</td>';
                        	html += '<td class="star" width="11%"><div class="m_star"><div class="star_rating" style="width:100%;"></div></div><p>5.00分</p></td>';
				if(using)
                        		html += '<td class="mr_link" width="7%"><a '+using+' href="#">使用</a></td>';
				else
                        		html += '<td class="mr_link" width="7%"><a '+using+' href="javascript:window.external.ApplySkin(\'0\',\''+name+'\');">使用</a></td>';
                        	html += '<td class="mr_link" width="7%"><span class="disable">删除</span></td>';
				html += '<td class="mr_link" width="7%"><span class="disable">另存为</span></td>';
                        	html += '<td class="mr_link" width="7%"><span class="disable">分享</span></td>';
                        	html += '<td class="mr_link" width="7%"><span class="disable">设置</span></td>';
		//	html += '<div class="deltip" id="deltip'+arr[i].id+'">确定删除这个皮肤？ <div class="delok"><a href="javascript:delok(\''+arr[i].id+'\');">确定</a></div><div class="delcancel"><a href="javascript:delcancel(\''+arr[i].id+'\');">取消</a></div></div>';
                        	html += "</tr>\n";
			//	html += '<tr id="skinTRD'+id+'">';
			//	html += '<td colspan="4" align="center"><div id="delcon'+id+'" class="deltip" id="deltip'+id+'"><span style="float:left">确定要删除吗？</span> <span class="delok"><a href="javascript:delok(\''+arr[i].id+'\',\''+name+'\');">确定</a></span><span class="delcancel"><a href="javascript:delcancel(\''+arr[i].id+'\',\''+name+'\');">取消</a></span></div></td>';
			//	html += '</tr>';
				i++;
				continue;
			}*/
			//md5
			/*
			if(arr[i].skin_id)
				link = true;
			else
				link = false;*/
//		if(content == "skinlist"){
//			alert(arr[i].id);
//		}
			//不存在的时候
		//	if(!arr[i].piccomp && arr[i] != 0){
//		if(content == "skinlist"){
//			alert("noexist"+arr[i].id);
//		}
				html += '<tr id="skinTR'+id+'">';
				html += "</tr>\n";
				//alert(html);
				//html += '<tr id="skinTRD'+id+'">';
				//html += "</tr>\n";
				//请求客户端函数，获取md5找不到的皮肤的数据
				//window.external.GetSkinItemInfo(arr[i].id); 
				//alert(arr[i].id);
				//noexist.push(arr[i].id);
				i++;
				continue;
		//	}
		//	var name = cutStr(UrlDecode(arr[i].name),12);
		//	var author = cutStr(UrlDecode(arr[i].author),10);
			//alert(UrlDecode(arr[i].cate_name));
		//	alert(decodeURI(arr[i].cate_name));
		/*
			//html += '<tr id="skinTR'+id+'" onmouseover="trhover(\''+id+'\');" onmouseout="trout(\''+id+'\');">';
			html += '<tr id="skinTR'+id+'">';
                        html += '<td class="checkbox1" width="4%"><input ' +dis+ ' id="input_'+id+'" type="checkbox" value="'+id+'" name="skinck"></td>';
                        html += '<td class="tit" width="30%" align=center>';

			if(isie6)
                        	html += '<a href="javascript:window.external.ApplySkin(\''+arr[i].id+'\',\''+name+'\');"><div class="skin_pic"><span id="pic'+id+'" style="width:230px;display:inline-block;height:100%;"></span></div></a>';
			else
                        	html += '<a href="javascript:window.external.ApplySkin(\''+arr[i].id+'\',\''+name+'\');"><div class="skin_pic"><img width="230" id="pic'+id+'" src="'+arr[i].piccomp+'" /></div></a>';
                        html += '<h4 id="skinName'+id+'"></h4>';
                        html += '</td>';
			if(link){
                        	html += '<td class="author" width="11%"><a id="skinAuthor'+id+'" href="http://pinyin.sogou.com/skins/home/'+arr[i].u+'_1.html" target="_blank"></a></td>';
			}
			else{
                        	html += '<td id="skinAuthor'+id+'" class="author" width="11%"></td>';
			}
			html += '<td class="cate" width="9%"><input type="hidden" name="skin_name" value="'+name+'">'+cate_list[arr[i].cate_id]+'</td>';
                        html += '<td class="star" width="11%"><div class="m_star"><div class="star_rating" style="width:'+arr[i].sper+'%;"></div></div><p>'+arr[i].score+'分</p></td>';
			if(using){
                        	html += '<td class="mr_link" width="7%"><a '+using+' href="#">使用</a></td>';
                        	html += '<td class="mr_link" width="7%"><span class="disable">删除</span></td>';
			}
			else{
                        	html += '<td class="mr_link" width="7%"><a '+using+' href="javascript:window.external.ApplySkin(\''+arr[i]+'\',\''+name+'\');">使用</a></td>';
				html += '<td class="mr_link" width="7%"><a href="javascript:delSkin(\''+id+'\')">删除</a></td>';
			}
			html += '<td class="mr_link" width="7%"><a href="javascript:window.external.SaveSkinAs(\''+arr[i]+'\',\''+name+'\')">另存为</a></td>';
                        html += '<td class="mr_link" width="7%"><a href="javascript:window.external.ShareSkin(\''+arr[i]+'\',\''+name+'\');">分享</a></td>';
                        html += '<td class="mr_link" width="7%"><a href="javascript:window.external.SetSkin(\''+arr[i]+'\',\''+name+'\');">设置</a></td>';
                        html += "</tr>\n";
		//	html += '<tr id="skinTRD'+id+'">';
		//	html += '<td colspan="4" align="center"><div id="delcon'+id+'" class="deltip" id="deltip'+id+'"><span style="float:left">确定要删除吗？</span> <span class="delok"><a href="javascript:delok(\''+arr[i].id+'\',\''+name+'\');">确定</a></span><span class="delcancel" style="float:left;"><a href="javascript:delcancel(\''+arr[i].id+'\',\''+name+'\');">取消</a></span></div></td>';
		//	html += '</tr>';
			i++;
			//alert(i+"=="+name);
			*/
		}
//		if(content == "skinlist"){
//			alert(html);
//		}
		//jQuery("#"+content).html(html);
		if(content == "skinlist"){
			jQuery("#skinlist").prepend(html);
		}
		else{
			jQuery("#skinlist").append(html);
		}
		//if(content == "skinlist" && i == 5){
			//getSkinList(5,0,"skinlist2");
		//}
	//	if(content == "skinlist" && i < 5){
	//		jQuery("#skinCount").html("本地共"+i+"款皮肤");
	//	}
	//	else if(content == "skinlist2"){
	//		jQuery("#skinCount").html("本地共"+(i+5)+"款皮肤");
	//	}
		//noexist最终请求生成
		//alert(noexist.length);
		//for(var i = 0;i < noexist.length;i++){
		//	alert("noexist="+noexist[i]);
		//	window.external.GetSkinItemInfo(noexist[i]); 
		//}

		//alert(arr.length);
	
		for(var i = 0;i < arr.length;i++){
		//	alert("noexist="+noexist[i]);
			//alert("push="+arr[i].id+"----"+namearr[i]);
			//alert("run="+namearr[i]);
			window.external.GetSkinItemInfo(arr[i],namearr[i]); 
		}
		if(content == "skinlist" || content == "skinlist3"){
			if(!error){
				skin_count = window.external.GetSkinListCount();
				jQuery("#skinCount").html("本地共"+skin_count+"款皮肤");
			}
			window.external.WebIsReady();
		}

                //if(_ie > 0 && _ie < 7 && content == "skinlist3")
                //	pngfix();
		//test
		//window.external.GetSkinItemInfo(arr[0].id); 
      //     }
    //    });
}
function UrlDecode(str){ 
    var ret=""; 
    for(var i=0;i<str.length;i++)
    { 
        var chr = str.charAt(i); 
        if(chr == "+")
        { 
            ret+=" "; 
        }
        else if(chr=="%")
        { 
            var asc = str.substring(i+1,i+3); 
            if(parseInt("0x"+asc)>0x7f)
            { 
                ret+=asc2str(parseInt("0x"+asc+str.substring(i+4,i+6))); 
                i+=5; 
            }
            else
            { 
                ret+=asc2str(parseInt("0x"+asc)); 
                i+=2; 
            } 
        }
        else
        { 
            ret+= chr; 
        } 
    } 
    return ret; 
} 
/*
//获取md5查询不到的皮肤的数据,客户端返回函数
function showMd5Skin(md5,name,picurl,author){
	html += '<td class="checkbox1" width="9%"><input type="checkbox" value="'+md5+'" name="skinck"></td>';
	html += '<td class="tit">';
        html += '<h4>'+name+'</h4>';
        html += '<div class="skin_pic"><img width="182" src="'+picurl+'" /></div>';
        html += '</td>';
        html += '<td class="author" width="19%">'+author+'</td>';
        html += '<td class="star" width="18%"><div class="m_star"><div class="star_rating" style="width:0%;"></div></div><p>0分</p></td>';
	html += '<td class="mr_link" width="7%"><a href="javascript:window.external.ApplySkin(\''+md5+'\');">使用</a></td>';
        html += '<td class="mr_link" width="7%"><a href="javascript:window.external.DelSkin(\''+md5+'\');">删除</a></td>';
        html += '<td class="mr_link" width="7%"><a href="javascript:window.external.ShareSkin(\''+md5+'\');">分享</a></td>';
        html += '<td class="mr_link" width="7%"><a href="javascript:window.external.SetSkin(\''+md5+'\');">设置</a></td>';
	jQuery("#skinTR"+md5).html(html);
}*/
//客户端删除皮肤成功之后调用函数
function mgrDelSkin(id,name){
	id = id + "_" +name.replace(/[^0-9a-zA-Z_]/g,"");
	jQuery("#skinTR"+id).css("display","none");
	//jQuery("#skinTRD"+id).css("display","none");
	jQuery("#skinTR"+id+" td:eq(0) input").attr("checked",false);
	skin_count = window.external.GetSkinListCount();
	jQuery("#skinCount").html("本地共"+skin_count+"款皮肤");
	//alert(skin_count);
}
function delSkin(id,name){
	var name = jQuery("#skinTR"+id+" td:eq(2) input").val();
	name = UrlDecode(name.replace(/#/g,"%"));
	//id = id + "_" +encodeURIComponent(name).replace(/\%/g,"-");
	name = name.replace(/@&(.*)&/,"$1<皮肤系列>");;
	name = cutStr2(name,12);
	jQuery("#delname").html("“"+name+"”");
	jQuery("#delok").attr("href","javascript:delok('"+id+"')");
	jQuery("#delbg").css("display","block");
	jQuery("#deltip").css("display","block");
    var width = window.external.GetWebWidth();
    var height = window.external.GetWebHeight();
    jQuery("#deltip").css("top",(height-180)/2+"px");
    jQuery("#deltip").css("left",(width-250)/2+"px");
		
	//alert("1");
	//alert(skin_id);
	//var e = window.event;
	//alert(e.clientX +"=="+e.clientY);
	//alert(e.offsetX +"=="+e.offsetY);
	//alert(e.pageX +"=="+e.pageY);
	//alert(e.screenX +"=="+e.screenX);
	//jQuery("#deltip").css("top",(e.clientY-85)+"px");
	//jQuery("#deltip").css("left",(e.clientX-75)+"px");
	//jQuery("#deltip").css("display","block");
	//jQuery("#delcon"+skin_id).show(500);
//	if(confirm("确定删除这个皮肤？"))
//		window.external.DelSkin(skin_id);
}
function delok(id){
	var idtmp = id.split("_");
        var skin_id = idtmp[0];
	var name = jQuery("#skinTR"+id+" td:eq(2) input").val();
	window.external.DelSkin(skin_id,name);
	//jQuery("#delcon"+skin_id).hide(500);
	//alert(jQuery("#skinTR"+id).html());
	jQuery("#skinTR"+id).css("background","none");
	jQuery("#skinTR"+id).css("display","none");
	//jQuery("#skinTRD"+skin_id).css("background","none");
	jQuery("#delbg").css("display","none");
	jQuery("#deltip").css("display","none");
}
function delcancel(skin_id){
	//jQuery("#delcon"+skin_id).hide(500);
	jQuery("#delbg").css("display","none");
	jQuery("#deltip").css("display","none");
}

//客户端使用皮肤之后调用函数
function mgrUseSkin(id,name){
	id = id + "_" +name.replace(/[^0-9a-zA-Z_]/g,"");
	var curid = jQuery("#curSkinId").val();
        var curidtmp = curid.split("_");
	var curname = jQuery("#skinTR"+curid+" td:eq(2) input").val();
	//alert(jQuery("#skinTR"+curid).html());
	//alert(jQuery("#skinTR"+id+" td:eq(4)").html());
	//alert(jQuery("#skinTR"+curid+" td:eq(5) a").html());
	jQuery("#skinTR"+curid+" td:eq(3) a").removeClass("used");
	//添加旧皮肤链接
	jQuery("#skinTR"+curid+" td:eq(3) a").attr("href","javascript:window.external.ApplySkin('"+curidtmp[0]+"','"+curname+"');");
	//alert(curid+"="+curname);
	if(curidtmp[0] != 0)
		jQuery("#skinTR"+curid+" td:eq(4)").html('<a href="javascript:delSkin(\''+curid+'\');">删除</a>');
	jQuery("#skinTR"+id+" td:eq(3) a").addClass("used");
	//新皮肤链接修改
	jQuery("#skinTR"+id+" td:eq(3) a").attr("href","#");
	jQuery("#skinTR"+id+" td:eq(4)").html('<span class="disable">删除</span>');
	//alert(j1uery("#skinTR"+id+" td:eq(0)").html());
	//alert(jQuery("#skinTR"+curid+" td:eq(0)").html());
	jQuery("#skinTR"+id+" td:eq(0) input").attr("disabled","true");
	jQuery("#skinTR"+id+" td:eq(0) input").attr("checked","");
	jQuery("#skinTR"+curid+" td:eq(0) input").attr("disabled","");
	//jQuery("#delcon"+id).hide(500)none;
	//alert(jQuery("#skinlist").html());
	
	jQuery("#curSkinId").val(id);
	
}

//客户端页面大小变化之后调用我这边的函数告诉我这边长宽
function mgrResize(width,height){
	width += 18;
	//height += 116;
	height += 93;
	//height = iswin7 ? height-12:height;
	jQuery(".skmng_wrapper").css("width",(width+20)+"px");
	jQuery(".mainskmng").css("height",(height-197)+"px");
	//jQuery("#nav_link_online").css("width",(width-40)+"px");
	jQuery("#nav_link_offline").css("width",(width-18)+"px");
	jQuery("#content_offline").css("width",(width-18)+"px");
	//jQuery("#mainskmng").css("width",(width-18)+"px");
	//jQuery("#tb_nav").css("width",(width-18)+"px");
	//jQuery("#content_online").css("width",(width-18)+"px");
        //jQuery("#skinmgr_iframe").css("width",(width-20)+"px");
        //jQuery("#skinmgr_iframe").css("height",(height-125)+"px");
	//jQuery(".topbar").css("width",(width-16)+"px");
	/*
	if(window.external.GetDlgMaxState()){
		jQuery("#bigsize").removeClass("big");
		jQuery("#bigsize").addClass("big2");
	}
	else{
		jQuery("#bigsize").removeClass("big2");
		jQuery("#bigsize").addClass("big");
	}*/
	//height:647px;
	//width:890px;
}
//客户端传递皮肤ID的函数
function AddSkinItem(skin_id,skin_name,used){
	skin_count = window.external.GetSkinListCount();
	//alert(skin_id+"-----"+skin_name);
	//alert(UrlDecode(skin_name));
	//skin_name = UrlDecode(skin_name);
	//alert(decodeURI(skin_name));
	skin_list.push(skin_id);
	name_list.push(skin_name);
	use_list.push(used);
	var n = skin_list.length;
	if(n == 5){
		//jQuery("#skinmgr_iframe").attr("src","http://pinyin.sogou.com/skins/");
		var arr = skin_list.join("\?");
		var narr = name_list.join("\?");
		var uarr = use_list.join("\?");
		getSkinList(0,5,"skinlist",arr,narr,uarr,0,0);
	}
	else if(n % 5 == 0 && n > 5){
		var x = (Math.floor(n / 5)-1)*5;
		var arr = new Array;
		var narr = new Array;
		var uarr = new Array;
		for(var i=0;i<5;i++,x++){
			arr.push(skin_list[x]);
			narr.push(name_list[x]);
			uarr.push(use_list[x]);
		}
		arr = arr.join("\?");
		narr = narr.join("\?");
		uarr = uarr.join("\?");

		getSkinList(5,0,"skinlist2",arr,narr,uarr,1,0);
	}
	else if(n == skin_count){
		//jQuery("#skinmgr_iframe").attr("src","http://pinyin.sogou.com/skins/");
		var skin_arr = skin_list;
		var name_arr = name_list;
		var use_arr = use_list;
		var x = Math.floor(n / 5)*5;
		if(x == skin_count){
			//if(_ie > 0 && _ie < 7)
			//	pngfix();
			return;
		}
		var arr = "";
		var narr = "";
		var uarr = "";
		for(var i=x;i<skin_arr.length;i++){
			arr += skin_arr[i]+"\?";
			narr += name_arr[i]+"\?";
			uarr += use_arr[i]+"\?";
		}
		
		if(skin_list.length <= 5)
			getSkinList(5,0,"skinlist3",arr,narr,uarr,0,0);
		else
			getSkinList(5,0,"skinlist3",arr,narr,uarr,1,0);
	}
}
function LoadSkinListEnd(){
	//alert(n);
	//alert(skin_count);
	if(skin_list.length != skin_count){
		skin_count = skin_list.length;
		jQuery("#skinCount").html("本地共"+skin_count+"款皮肤");
                //jQuery("#skinmgr_iframe").attr("src","http://pinyin.sogou.com/skins/");
                var skin_arr = skin_list;
				var name_arr = name_list;
				var use_arr = use_list;
                var x = Math.floor(skin_arr.length / 5)*5;
                if(x == skin_count){
                        return;
                }
                skin_arr.splice(0,x);
                name_arr.splice(0,x);
				use_arr.splice(0,x);
                var arr = skin_arr.join("?");
                var narr = name_arr.join("?");
				var uarr = use_arr.join("?");
		if(skin_count <= 5)
			getSkinList(5,0,"skinlist3",arr,narr,uarr,0,1);
		else
			getSkinList(5,0,"skinlist3",arr,narr,uarr,1,1);
		delete skin_list;
        delete name_list;
		delete use_list;
	}
}
//客户端传递那些网络读取失败了的皮肤信息
function getSkinItemInfo(skin_id,author,name,picurl,picwidth,picheight){
	//alert("end="+skin_id+"=name"+name);
	//alert("pic="+picwidth+"-"+picheight);
		//		var image = new Image();
		//		image.src = picurl.replace("\\","\\\\");
		//		picheight = image.height;
		//		alert("testout"+picheight);
	var namel = name;
	var id = skin_id + "_" +name.replace(/[^0-9a-zA-Z_]/g,"");
	//修改name
	name = UrlDecode(name.replace(/#/g,"%"));
	name = name.replace(/@&(.*)&/,"$1<皮肤系列>");;
	name = cutStr(name,12);
	author = cutStr(UrlDecode(author.replace(/#/g,"%")),10);
//	alert(jQuery("#skinTR"+id).html());
	if(jQuery("#skinTR"+id).html() == ""){
		if(jQuery("#curSkinId").val() == id){
			var using = 'class="used" ';
			var dis = 'disabled';
		}
		else{
			var using = '';
			var dis = '';
		}
		if(skin_id == 0)
			html = '<td class="checkbox1" width="4%"></td>';
		else
			html = '<td class="checkbox1" width="4%"><input id="input_'+id+'" type="checkbox" '+dis+' value="'+id+'" name="skinck"></td>';
		html += '<td width="30%" class="tit" align=center>';
		//alert(picurl);
		//alert(skin_id);
		//html += '<div class="skin_pic"><img src="'+picurl+'" /></div>';
		if(isie6){
			if(picheight == 0){
				var image = new Image();
				image.src = picurl.replace("\\","\\\\");
				picheight = image.height;
			}
			if(picheight == 0)
				html += '<a href="javascript:window.external.ApplySkin(\''+skin_id+'\',\''+namel+'\');"><div class="skin_pic"><img width="230" id="pic'+id+'" src="'+picurl.replace("\\","\\\\")+'" /></div></a>';
			else
				html += '<a href="javascript:window.external.ApplySkin(\''+skin_id+'\',\''+namel+'\');"><div class="skin_pic"><span id="pic'+id+'" style="width:230px;display:inline-block;height:'+picheight+'px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+picurl.replace("\\","\\\\")+'\',sizingMethod=\'scale\');"></span></div></a>';
		}
		else
			html += '<a href="javascript:window.external.ApplySkin(\''+skin_id+'\',\''+namel+'\');"><div class="skin_pic"><img width="230" id="pic'+id+'" src="'+picurl.replace("\\","\\\\")+'" /></div></a>';
		html += '<h4>'+name+'</h4>';
		html += '</td>';
		html += '<td class="author" width="11%">'+author+'<input type="hidden" name="skin_name" value="'+namel+'"></td>';
		//html += '<td class="cate" width="9%">暂无<input type="hidden" name="skin_name" value="'+namel+'"></td>';
		//html += '<td class="star" width="11%"><div class="m_star"><div class="star_rating" style="width:0%;"></div></div><p>0.00分</p></td>';
		if(using)
			html += '<td class="mr_link" width="7%"><a '+using+' href="#">使用</a></td>';
		else
			html += '<td class="mr_link" width="7%"><a '+using+' href="javascript:window.external.ApplySkin(\''+skin_id+'\',\''+namel+'\');">使用</a></td>';
		if(jQuery("#curSkinId").val() == id || skin_id == 0)
			html += '<td class="mr_link" width="7%"><span class="disable">删除</span></td>';
		else
			html += '<td class="mr_link" width="7%"><a href="javascript:delSkin(\''+id+'\')">删除</a></td>';
		if(skin_id == 0){
			html += '<td class="mr_link" width="7%"><span class="disable">另存为</span></td>';
			html += '<td class="mr_link" width="7%"><span class="disable">分享</span></td>';
			html += '<td class="mr_link" width="7%"><span class="disable">设置</span></td>';
		}
		else{
			html += '<td class="mr_link" width="7%"><a href="javascript:window.external.SaveSkinAs(\''+skin_id+'\',\''+namel+'\')">另存为</a></td>';
			html += '<td class="mr_link" width="7%"><span class="disable">分享</span></td>';
			html += '<td class="mr_link" width="7%"><a href="javascript:window.external.SetSkin(\''+skin_id+'\',\''+namel+'\');">设置</a></td>';
		}
		jQuery("#skinTR"+id).html(html);

		//html2 = '<td colspan="4" align="center"><div id="delcon'+id+'" class="deltip" id="deltip'+id+'"><span style="float:left">确定要删除吗？</span> <span class="delok"><a href="javascript:delok(\''+skin_id+'\',\''+namel+'\');">确定</a></span><span class="delcancel"><a href="javascript:delcancel(\''+skin_id+'\',\''+namel+'\');">取消</a></span></div></td>';
		//jQuery("#skinTRD"+id).html(html2);
	}
	else{
		if(!isie6)
			jQuery("#skinTR"+id+" td:eq(1) div").html('<img width="230" id="pic'+id+'" src="'+picurl.replace("\\","\\\\")+'" />');
		jQuery("#skinName"+id).html(name);
		jQuery("#skinAuthor"+id).html(author);
		if(isie6){
			//alert("test"+picheight);
			if(picheight == 0){
				var image = new Image();
				image.src = picurl.replace("\\","\\\\");
				picheight = image.height;
			}
			if(picheight == 0)
				jQuery("#skinTR"+id+" td:eq(1) div").html('<img width="230" id="pic'+id+'" src="'+picurl.replace("\\","\\\\")+'" />');
			else{
				jQuery("#pic"+id).css("height",picheight+'px');
				jQuery("#pic"+id).css("filter",'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+picurl.replace("\\","\\\\")+'\',sizingMethod=\'scale\'');
			}
		}
		//jQuery("#pic"+skin_id).attr("src",picurl.replace("\\","\\\\"));
	}
	
	jQuery("#skinTR"+id).mouseover(function(){
			//alert("1");
            if(jQuery("#skinTR"+id+" td:eq(0) input").attr("checked") == true){
                jQuery("#skinTR"+id).css("backgroundColor","#e8f6ff");
                //this.style.backgroundColor ='#e8f6ff';
              /*  jQuery("#skinTR"+id+" td:eq(4) div:eq(0)").addClass("m_stara");
                jQuery("#skinTR"+id+" td:eq(4) div:eq(0)").removeClass("m_star");
                jQuery("#skinTR"+id+" td:eq(4) div:eq(0)").removeClass("m_starh");
                jQuery("#skinTR"+id+" td:eq(4) div div").addClass("star_ratinga");
                jQuery("#skinTR"+id+" td:eq(4) div div").removeClass("star_rating");
                jQuery("#skinTR"+id+" td:eq(4) div div").removeClass("star_ratingh");*/
            }
            else{
				//alert(jQuery("#skinTR"+id));
				//alert(jQuery("#skinTR"+id).html());
                jQuery("#skinTR"+id).css("backgroundColor","#f8fcff");
                //this.style.backgroundColor ='#f8fcff';
             /*   jQuery("#skinTR"+id+" td:eq(4) div:eq(0)").addClass("m_starh");
                jQuery("#skinTR"+id+" td:eq(4) div:eq(0)").removeClass("m_star");
                jQuery("#skinTR"+id+" td:eq(4) div:eq(0)").removeClass("m_stara");
                jQuery("#skinTR"+id+" td:eq(4) div div").addClass("star_ratingh");
                jQuery("#skinTR"+id+" td:eq(4) div div").removeClass("star_rating");
                jQuery("#skinTR"+id+" td:eq(4) div div").removeClass("star_ratinga");*/
            }
	});

	jQuery("#skinTR"+id).mouseout(function(){
            if(jQuery("#skinTR"+id+" td:eq(0) input").attr("checked") == true){
                jQuery("#skinTR"+id).css("backgroundColor","#e8f6ff");
                //this.style.backgroundColor ='#e8f6ff';
           /*     jQuery("#skinTR"+id+" td:eq(4) div:eq(0)").addClass("m_stara");
                jQuery("#skinTR"+id+" td:eq(4) div:eq(0)").removeClass("m_star");
                jQuery("#skinTR"+id+" td:eq(4) div:eq(0)").removeClass("m_starh");
                jQuery("#skinTR"+id+" td:eq(4) div div").addClass("star_ratinga");
                jQuery("#skinTR"+id+" td:eq(4) div div").removeClass("star_rating");
                jQuery("#skinTR"+id+" td:eq(4) div div").removeClass("star_ratingh");*/
            }
            else{
                jQuery("#skinTR"+id).css("backgroundColor","");
                //this.style.backgroundColor ='';
           /*     jQuery("#skinTR"+id+" td:eq(4) div:eq(0)").addClass("m_star");
                jQuery("#skinTR"+id+" td:eq(4) div:eq(0)").removeClass("m_stara");
                jQuery("#skinTR"+id+" td:eq(4) div:eq(0)").removeClass("m_starh");
                jQuery("#skinTR"+id+" td:eq(4) div div").addClass("star_rating");
                jQuery("#skinTR"+id+" td:eq(4) div div").removeClass("star_ratinga");
                jQuery("#skinTR"+id+" td:eq(4) div div").removeClass("star_ratingh");*/
            }
	});
	var selid = "input_" + id;
	jQuery("#"+selid).click(function(){
            var id = selid.replace("input_","skinTR");
            if(jQuery("#"+selid).attr("checked")){
                jQuery("#"+id).css("backgroundColor","#e8f6ff");
        /*        jQuery("#"+id+" td:eq(4) div:eq(0)").addClass("m_stara");
                jQuery("#"+id+" td:eq(4) div:eq(0)").removeClass("m_star");
                jQuery("#"+id+" td:eq(4) div:eq(0)").removeClass("m_starh");
                jQuery("#"+id+" td:eq(4) div div").addClass("star_ratinga");
                jQuery("#"+id+" td:eq(4) div div").removeClass("star_rating");
                jQuery("#"+id+" td:eq(4) div div").removeClass("star_ratingh");*/
            }
            else{
                jQuery("#"+id).css("backgroundColor","#f8fcff");
          /*      jQuery("#"+id+" td:eq(4) div:eq(0)").addClass("m_starh");
                jQuery("#"+id+" td:eq(4) div:eq(0)").removeClass("m_star");
                jQuery("#"+id+" td:eq(4) div:eq(0)").removeClass("m_stara");
                jQuery("#"+id+" td:eq(4) div div").addClass("star_ratingh");
                jQuery("#"+id+" td:eq(4) div div").removeClass("star_rating");
                jQuery("#"+id+" td:eq(4) div div").removeClass("star_ratinga");*/
            }
	});

	//jQuery("#skinTR"+id).bind("mouseover",trhover(id));
	//jQuery("#skinTR"+id).bind("mouseout",trout(id));
	ended++;
	if(ended == skin_count){
		window.external.WebIsReady();
        delete name_list;
        delete skin_list;
        delete use_list;
		//correctPNG();
		//alert(jQuery("#skinlist").html());
	}
}
	/*
//是否可以前进

function EnableForward(n){
	if(n){
		//jQuery("#link_back").addClass("link_back");
		jQuery("#link_back").href("javascript:parent.skinmgr_iframe.history.go(-1);");
	}
	else{
		//jQuery("#link_back").removeClass("link_back");
		jQuery("#link_back").href("javascript:return false;");
	}
}
//是否可以后退
function EnableBack(n){
	if(n){
		//jQuery("#link_go").addClass("link_go");
		jQuery("#link_go").href("javascript:parent.skinmgr_iframe.history.go(1);");
	}
	else{
		//jQuery("#link_go").removeClass("link_go");
		jQuery("#link_go").href("javascript:return false;");
	}
}
function goto(n){
	if(n){
		if(jQuery("#offlinelink").attr("className").indexOf("cur") >= 0)
			return;
		jQuery("#offlinelink").removeClass("nav2");
		jQuery("#offlinelink").addClass("nav4");
		jQuery("#offlinelink").addClass("cur");
		jQuery("#onlinelink").removeClass("nav1");
		jQuery("#onlinelink").removeClass("cur");
		jQuery("#onlinelink").addClass("nav3");
		jQuery("#nav_link_online").css("display","none");
		jQuery("#nav_link_offline").css("display","block");
		jQuery("#content_online").css("display","none");
		jQuery("#content_offline").css("display","block");
	}
	else{
		if(jQuery("#onlinelink").attr("className").indexOf("cur") >= 0)
			return;
		jQuery("#onlinelink").removeClass("nav3");
		jQuery("#onlinelink").addClass("cur");
		jQuery("#onlinelink").addClass("nav1");
		jQuery("#offlinelink").removeClass("nav4");
		jQuery("#offlinelink").removeClass("cur");
		jQuery("#offlinelink").addClass("nav2");
		jQuery("#nav_link_offline").css("display","none");
		jQuery("#nav_link_online").css("display","block");
		jQuery("#content_offline").css("display","none");
		jQuery("#content_online").css("display","block");
	}
}
*/
function select(n){
        var n = n ==1?true:false;
        var opts = document.getElementsByName("skinck");
        for(var i=0;i<opts.length;i++){
		var id = opts[i].id.replace("input_","skinTR");
		if(opts[i].disabled){
                	opts[i].checked = false;
			document.getElementById(id).style.backgroundColor ='';
               /* 	jQuery("#"+id+" td:eq(4) div:eq(0)").addClass("m_star");
                	jQuery("#"+id+" td:eq(4) div:eq(0)").removeClass("m_stara");
			jQuery("#"+id+" td:eq(4) div:eq(0)").removeClass("m_starh");
			jQuery("#"+id+" td:eq(4) div div").addClass("star_rating");
			jQuery("#"+id+" td:eq(4) div div").removeClass("star_ratinga");
			jQuery("#"+id+" td:eq(4) div div").removeClass("star_ratingh");*/
		}
		else{
                	opts[i].checked = n;
			if(n){
				document.getElementById(id).style.backgroundColor ='#e8f6ff';
                /*		jQuery("#"+id+" td:eq(4) div:eq(0)").addClass("m_stara");
                		jQuery("#"+id+" td:eq(4) div:eq(0)").removeClass("m_star");
				jQuery("#"+id+" td:eq(4) div:eq(0)").removeClass("m_starh");
				jQuery("#"+id+" td:eq(4) div div").addClass("star_ratinga");
				jQuery("#"+id+" td:eq(4) div div").removeClass("star_rating");
				jQuery("#"+id+" td:eq(4) div div").removeClass("star_ratingh");*/
			}
			else{
				document.getElementById(id).style.backgroundColor ='';
                /*		jQuery("#"+id+" td:eq(4) div:eq(0)").addClass("m_star");
                		jQuery("#"+id+" td:eq(4) div:eq(0)").removeClass("m_stara");
				jQuery("#"+id+" td:eq(4) div:eq(0)").removeClass("m_starh");
				jQuery("#"+id+" td:eq(4) div div").addClass("star_rating");
				jQuery("#"+id+" td:eq(4) div div").removeClass("star_ratinga");
				jQuery("#"+id+" td:eq(4) div div").removeClass("star_ratingh");*/
			}
		}
        }
}
function delAll(n){
	var obj = document.getElementsByName("skinck");
	var delArr = new Array;
	for(var i =0;i < obj.length;i++){
		if(obj[i].checked)
			delArr.push(obj[i].value);
	}
	if(n == 1){
		var id = delArr.pop();
		while(id){
			var idtmp = id.split("_");
			var skin_id = idtmp[0];
			var name = jQuery("#skinTR"+id+" td:eq(2) input").val();
			//jQuery("#delcon"+id).hide(500);
			window.external.DelSkin(skin_id,name);
			id = delArr.pop();
		}
		jQuery("#delbg").css("display","none");
		jQuery("#deltip").css("display","none");
	}
	else{
		
		if(delArr.length == 0){
			alert("当前尚未勾选任何皮肤");
			return;
		}
		else{
		
			jQuery("#delname").html("这"+delArr.length+"款皮肤");
			jQuery("#delok").attr("href","javascript:delAll(1)");
			jQuery("#delbg").css("display","block");
			jQuery("#deltip").css("display","block");
			var width = window.external.GetWebWidth();
			var height = window.external.GetWebHeight();
			jQuery("#deltip").css("top",(height-180)/2+"px");
			jQuery("#deltip").css("left",(width-250)/2+"px");
			/*
			if(!confirm("确定删除这些皮肤？"))
				return;
			var id = delArr.pop();
			while(id){
				var idtmp = id.split("_");
				var skin_id = id[0];
				var name = decodeURIComponent(id[1]);
				//jQuery("#delcon"+id).hide(500);
				window.external.DelSkin(skin_id,name);
				id = delArr.pop();
			}*/
		}
	}
}
/*
function goHome(){

//alert(document.getElementById("skinmgr_iframe").src);
//return;
document.getElementById("skinmgr_iframe").src = "http://pinyin.sogou.com/skins/";
}*/
/*
function changemode(css,n){
	if(n){
		alert(n);
		jQuery(this).removeClass(css+"_active");
		jQuery(this).addClass(css);
	}
	else{
		jQuery(this).removeClass(css);
		jQuery(this).addClass(css+"_active");
	}
}*/
//设置皮肤名长度限制
function cutStr(str,num){
	var len = str.length;
	if(len <= num)
		return str;
	else if(len > num && len <= num*2){
		str = str.substring(0,num) + "<br/>" + str.substring(num);
	}
	else if(len > num*2){
		str = str.substring(0,num) + "<br/>" + str.substring(num,num*2)+"...";
	}
	return str;
}
function cutStr2(str,num){
	var len = str.length;
	if(len <= num)
		return str;
	else if(len > num){
		str = str.substring(0,num) + "...";
	}
	return str;
}
//刷新页面
function onfresh(){
		window.external.startRefresh();
		location.href = location.href;
}
/*
//test
function test2(){
	var ah = jQuery("html").html();
        jQuery.ajax({
           type: "POST",
           url: "/skins/test.php",
           data: "t="+ah
	});
	//alert(jQuery("html").html());
}*/
/*
function skinSelect(selid){
            var id = selid.replace("input_","skinTR");
            if(jQuery("#"+selid).attr("checked")){
                jQuery("#"+id).css("backgroundColor","#e8f6ff");
                jQuery("#"+id+" td:eq(4) div:eq(0)").addClass("m_stara");
                jQuery("#"+id+" td:eq(4) div:eq(0)").removeClass("m_star");
                jQuery("#"+id+" td:eq(4) div:eq(0)").removeClass("m_starh");
                jQuery("#"+id+" td:eq(4) div div").addClass("star_ratinga");
                jQuery("#"+id+" td:eq(4) div div").removeClass("star_rating");
                jQuery("#"+id+" td:eq(4) div div").removeClass("star_ratingh");
            }
            else{
                jQuery("#"+id).css("backgroundColor","#f8fcff");
                jQuery("#"+id+" td:eq(4) div:eq(0)").addClass("m_starh");
                jQuery("#"+id+" td:eq(4) div:eq(0)").removeClass("m_star");
                jQuery("#"+id+" td:eq(4) div:eq(0)").removeClass("m_stara");
                jQuery("#"+id+" td:eq(4) div div").addClass("star_ratingh");
                jQuery("#"+id+" td:eq(4) div div").removeClass("star_rating");
                jQuery("#"+id+" td:eq(4) div div").removeClass("star_ratinga");
            }
}
function trhover(id){
		alert("hover"+id);
            if(jQuery("#skinTR"+id+" td:eq(0) input").attr("checked") == true){
		jQuery("#skinTR"+id).css("backgroundColor","#e8f6ff");
                //this.style.backgroundColor ='#e8f6ff';
                jQuery("#skinTR"+id+" td:eq(4) div:eq(0)").addClass("m_stara");
                jQuery("#skinTR"+id+" td:eq(4) div:eq(0)").removeClass("m_star");
                jQuery("#skinTR"+id+" td:eq(4) div:eq(0)").removeClass("m_starh");
                jQuery("#skinTR"+id+" td:eq(4) div div").addClass("star_ratinga");
                jQuery("#skinTR"+id+" td:eq(4) div div").removeClass("star_rating");
                jQuery("#skinTR"+id+" td:eq(4) div div").removeClass("star_ratingh");
            }
            else{
		jQuery("#skinTR"+id).css("backgroundColor","#f8fcff");
                //this.style.backgroundColor ='#f8fcff';
                jQuery("#skinTR"+id+" td:eq(4) div:eq(0)").addClass("m_starh");
                jQuery("#skinTR"+id+" td:eq(4) div:eq(0)").removeClass("m_star");
                jQuery("#skinTR"+id+" td:eq(4) div:eq(0)").removeClass("m_stara");
                jQuery("#skinTR"+id+" td:eq(4) div div").addClass("star_ratingh");
                jQuery("#skinTR"+id+" td:eq(4) div div").removeClass("star_rating");
                jQuery("#skinTR"+id+" td:eq(4) div div").removeClass("star_ratinga");
            }
}
function trout(id){
//		alert(id);
            if(jQuery("#skinTR"+id+" td:eq(0) input").attr("checked") == true){
		jQuery("#skinTR"+id).css("backgroundColor","#e8f6ff");
                //this.style.backgroundColor ='#e8f6ff';
                jQuery("#skinTR"+id+" td:eq(4) div:eq(0)").addClass("m_stara");
                jQuery("#skinTR"+id+" td:eq(4) div:eq(0)").removeClass("m_star");
                jQuery("#skinTR"+id+" td:eq(4) div:eq(0)").removeClass("m_starh");
                jQuery("#skinTR"+id+" td:eq(4) div div").addClass("star_ratinga");
                jQuery("#skinTR"+id+" td:eq(4) div div").removeClass("star_rating");
                jQuery("#skinTR"+id+" td:eq(4) div div").removeClass("star_ratingh");
            }
            else{
		jQuery("#skinTR"+id).css("backgroundColor","");
                //this.style.backgroundColor ='';
                jQuery("#skinTR"+id+" td:eq(4) div:eq(0)").addClass("m_star");
                jQuery("#skinTR"+id+" td:eq(4) div:eq(0)").removeClass("m_stara");
                jQuery("#skinTR"+id+" td:eq(4) div:eq(0)").removeClass("m_starh");
                jQuery("#skinTR"+id+" td:eq(4) div div").addClass("star_rating");
                jQuery("#skinTR"+id+" td:eq(4) div div").removeClass("star_ratinga");
                jQuery("#skinTR"+id+" td:eq(4) div div").removeClass("star_ratingh");
            }
}*/
String.prototype.replaceAll  = function(s1,s2){    
return this.replace(new RegExp(s1,"gm"),s2);    
}  
