var fNum = 255;	//总字数

//换算中文字长
String.prototype.cnSize = function()
{
	var arr=this.match(/[^\x00-\xff]/ig);
	return this.length+(arr==null?0:arr.length);
}
//取出部分文字
String.prototype.sub_cnStr = function(num,mode,vvStr)
{
	if(!/\d+/.test(num))
		return(this);
	var str = this.substr(0,num);
	if(!mode)
		return str;
	var strNum = str.cnSize();
	if(strNum<subTitle_cnf)
	{
		return this;
	}
	else
	{
		var n = strNum - str.length;
		num = num - parseInt(n/2);
		return this.substr(0,num)+vvStr;
	}
}
//判断非法字符
function noStr( vStr )
{
	if(/[\<\>]/i.vStr)
		return true;
	else
		return false;
}
//还原html
function HtmlToStr( vStr )
{
	vStr = vStr.replace(/&amp;/g,"&");
	vStr = vStr.replace(/&quot;/g,'"');
	vStr = vStr.replace(/&#039;/g,"'");
	vStr = vStr.replace(/&lt;/g,"<");
	vStr = vStr.replace(/&gt;/g,">");
	return vStr;
}
//还原url
function urlToStr( vStr )
{
	vStr = vStr.replace(/%3C/g,"\<");
	vStr = vStr.replace(/%3E/g,"\>");
	vStr = vStr.replace(/%27/g,"'");
	vStr = vStr.replace(/%22/g,'"');
	vStr = vStr.replace(/\\/g,'/');
	return vStr;
}
//创造下拉菜单

//选择下拉框
function change_select( vVar , oName )
{
	var sObj = getObj(oName);
	var sLen = sObj.length;
	var i = 0;
	for(i;i<sLen;i++)
	{
		if(vVar=="")
		{
			sObj.options[i].selected = true;
			break;
		}
		if(sObj.options[i].value==vVar)
		{
			sObj.options[i].selected = true;
			break;
		}
	}
	return true;
}
//交换图片
function c1( obj , vSrc )
{
	obj.src = "images/edit"+vSrc+".gif";
	return true;
}
function c2( obj , vSrc )
{
	obj.src = "images/del"+vSrc+".gif";
	return true;
}
//菜单编辑显示操作
function d1( vKey )
{
	getObj("d"+vKey).style.display = "block";
}
//隐藏操作
function d2( vKey )
{
	getObj("d"+vKey).style.display = "none";
}
//文字数量校验
//vObj 检察对像 fNum 总数 fName 回显对象名,空则不回显
function checkMKNum(vObj,fNum,fName)
{
	var nowNum = fNum - vObj.value.cnSize();
	if(nowNum<0)
	{
		nowNum = 0;
		alert("该内容已经达到最大字数限制.. \\n您的文字将在 "+fNum+" 个字节后被截取..");
		vObj.value = vObj.value.substr(0,fNum);
		return false;
	}
	if(fName!="")
		getObj(fName).innerHTML = nowNum;
	return true;
}
//获取通用对象
function getObj(id)
{
	if(document.getElementById)
	{
		return document.getElementById(id);
	}
	else if(document.all)
	{
		return document.all[id];
	}
	else if(document.layers)
	{
		return document.layers[id];
	}
}
//显示对话框
function openDiv( nDiv )
{
	var w,h,ow,oh;
	var dbg = getObj("divBg");
	w=document.body.clientWidth+20;
	h=document.body.clientHeight+20;
	dbg.style.width=w+'px';
	dbg.style.height=h+'px';
	dbg.style.display = "block";
	var onDiv = getObj(nDiv);
	var pw = parseInt(onDiv.style.width.substr(0,(onDiv.style.width.length-2)));	//ff
	onDiv.style.left = (w-pw)/2+"px";
	onDiv.style.top = 180+"px";
	onDiv.style.display = "block";
	onDiv.disabled = false;
	scroll(0,0);
	var s = arguments.length;
	if(s==2)
		getObj(arguments[1]).focus();

	//IE6 下拉框兼容
	
	return false;
}
//关闭对话框
function closeDiv(nDiv)
{
	var s = arguments.length;
	//不关闭背景
	if(s!=2)
		getObj("divBg").style.display = "none";
	var onDiv = getObj(nDiv);
	onDiv.style.display = "none";
	onDiv.disabled = true;

	//IE6 下拉框兼容
	
	return true;
}
//复制内容至剪切板

//全选框
function checkall(typeId ,obj)
{
	alert(document.all.length);
	return true;
	var num=document.all.length;
	for(var i=0;i<num;i++)
	{
		if(document.all(i).name == typeId)
		{
			if(document.all(i).checked ==false)
				var vChecked = true;
			else
				var vChecked = false;
			document.all(i).checked = vChecked;
		}
	}
	return true;
}
//全选2
//fName from名字
function selectIt(fName)
{
	var ff = getObj(fName);
	for(var i=0 ;i<ff.elements.length;i++)
	{
		if(ff.elements[i].type=="checkbox")
		{
			ff.elements[i].checked = true;
		}
	}
	return true;
}
//返回有多少个多选框被选中
function check_box_num( fName )
{
	var ff = getObj(fName);
	var j = 0;
	for(var i=0 ;i<ff.elements.length;i++)
	{
		if(ff.elements[i].type=="checkbox")
		{
			if(ff.elements[i].checked==true)
			{
				j++;
			}
		}
	}
	return j;
}

//搜索收藏
function sea()
{
	var vKey = getObj('vKey').value;
	var tj = getObj('sea_ed').value;
	location.href = "?tj="+tj+"&vKey="+vKey;
	return true;
}
//------------------------------------------------------------
//初始化
//初始化批量操作对话框
function alert_ok_window( v1 , v2 )
{
	//标题设置
	getObj('alert_ok_font').innerHTML = v1;
	//对话内容设置
	getObj('alert_ok_font2').innerHTML = v2;
	return true;
}
//初始化对话框
function ini_ok( v1 , v2 , v3 , v4 )
{
	//标题设置
	getObj('del_ok_font').innerHTML = v1;
	//对话内容设置
	getObj('del_ok_font2').innerHTML = v2;
	//命令设置
	getObj('del_ok_cmd').value = v3;
	//参数设置
	getObj('del_id').value = v4;
	return true;
}
//初始化分类操作对话框
function add_sort_window( v1 , v2 , v3 , v4 )
{
	//标题设置
	getObj('add_sort_font').innerHTML = v1;
	//值设置
	getObj('vSort').value = v2;
	//命令设置
	getObj('add_sort_cmd').value = v3;
	//参数设置
	getObj('add_sort_id').value = v4;
	return true;
}
//初始化收藏操作对话框
function add_fav_window( v1 , v2 , v3 , v4 )
{
	//标题设置
	getObj('add_fav_title').innerHTML = v1;
	//值设置
	if(v2.length==5)
	{
		//编辑收藏
		getObj('vTitle').value = v2[0];	//标题
		getObj('vUrl').value = urlToStr(v2[1]);	//链接
		getObj('vMK').value = HtmlToStr(v2[2]).replace(/<br>/g,"\n");	//备注
		change_select(v2[3],"favSort");	//分类
		
		
		getObj('add_fav_sb').value = "编辑收藏";	//按钮
	}
	else
	{
		//添加收藏
		getObj('vTitle').value = "";	//标题
		getObj('vUrl').value = "http://";	//链接
		getObj('vMK').value = "";	//备注
		change_select("","favSort");	//分类
		getObj('add_fav_sb').value = "添加收藏";	//按钮
	}
	//命令设置
	getObj('add_fav_cmd').value = v3;
	//参数设置
	getObj('add_fav_id').value = v4;
	return true;
}
//检察函数
function c_add_sort()
{
	var vSort = getObj('vSort');
	var vLen = vSort.value.cnSize();
	if(vLen<1 || vLen>12)
	{
		alert("分类请在1-12个字节以内..");
		vSort.focus();
		return false;
	}
	return true;
}
//-------------------------------------------------------------
//底部操作
//删除全部
function delall()
{
	var fn = check_box_num("mmForm");
	if(fn<=0)
	{
		alert("请选择您要删除的收藏..");
		return false;
	}
	//设置删除命令
	getObj('all_cmd').value = "delall";
	alert_ok_window("&nbsp;&nbsp;删除收藏","<br>是否要将这 "+fn+" 个收藏删除？<br><br>");
	openDiv("alert_ok","alert_ok_focus");
	return true;
}


//------------------------------------------------------------------------
//删除单个收藏
function delmm( vStr )
{
	ini_ok("确认删除收藏?","","del_fav",vStr);
	openDiv("del_ok","ok_focus");
	return false;
}
//添加分类
function add_sort( )
{
	if( total_sort==15 )
	{
		alert("收藏分类最大上限为15个，请先删除你现有的类别..");
		return false;
	}
	//初始化对话框
	add_sort_window( "添加新分类" , "" , "add_sort" , "" );
	openDiv("add_sort","vSort");
	return true;
}
//删除分类
function del_sort( vKey )
{
	var st = getObj('st'+vKey).innerHTML;
	if(st>0)
	{
		alert("删除分类前请转移该分类下的 "+st+" 收藏。");
		location.href = "index.asp?id="+vKey;
		return false;
	}
	else
	{
		ini_ok( "&nbsp;&nbsp;确认删除？" , "" , "del_sort" , vKey );
		openDiv("del_ok","ok_focus");
	}
	return false;
}
//编辑分类
function edit_sort( vKey )
{
	/*
	var ee = '&lt;';
	alert(sArray[vKey].replace(/ee/g,"<"));
	return true;
	*/
	//初始化对话框

	add_sort_window( "修改分类" , sArray["t_"+vKey] , "edit_sort" , vKey );
	openDiv("add_sort","vSort");
	return true;
}
//检察添加收藏
function c_add_fav()
{
	var tObj = getObj('vTitle');
	var vLen = tObj.value.cnSize();
	if(vLen<1 || vLen>20)
	{
		alert("标题请在1-20个字节以内..");
		tObj.focus();
		return false;
	}
	var uObj = getObj('vUrl');
	var vLen = uObj.value.cnSize();
	if(vLen<11)
	{
		alert("链接请在11个字节以上..");
		uObj.focus();
		return false;
	}
	return true;
}
//添加收藏
function add_fav()
{
	if(total_mm>=2000)
	{
		alert("收藏最大上限为1000个，请先删除你现有的收藏..");
		return false;
	}
	//添加收藏
	add_fav_window( "&nbsp;&nbsp;添加新收藏" , "" , "add_fav" , "" );
	openDiv('add_fav','vTitle');
	return true;
}
//编辑收藏
function ef( vKey )
{
	var info = mArray[vKey].split('<>');
	var vArray = new Array;
	vArray[0] = info[1];
	vArray[1] = info[2];
	vArray[2] = info[3];
	vArray[3] = info[0];
	vArray[4] = info[4];
	add_fav_window( "&nbsp;&nbsp;编辑收藏" , vArray , "edit_fav" , vKey );
	openDiv('add_fav','vTitle');
	return true;
}



