function chk_vagaa(url)
{
	var vagaa_installed = false;

	if (vagaa_detect)
	{
		if (vagaa_detect.text == "1")
		{
			window.location.href= url;
			vagaa_installed = true;
		}
	}
	
	if (vagaa_installed == false) 
	{
		var ainfo = '系统检测到您未安装兼容BT,emule下载的Vagaa哇嘎软件，点击确定安装最新版本哇嘎\n或者您使用的是非IE浏览器';
		alert(ainfo);
		window.location.href= "http://help.vagaa.com/download.html";
		return;
	}
}
function foo()//调整图片的大小(控制整个页面的)
{
	var ims = document.images;
	var max_width=780;
	for (var i=0; i<ims.length; i++)
	{
		if (ims[i].width>max_width)
		{
			var w = ims[i].width;
            var h = ims[i].height;
			ims[i].width = max_width;
			ims[i].height = h*max_width/w;
		}
	}
	/*
	if (document.all["news_photo"].width > 169)
	{
		var bl;
		bl = (document.all["news_photo"].width-169)/document.all["news_photo"].width;
		document.all["news_photo"].height = Math.round(document.all["news_photo"].height*(1-bl));
		document.all["news_photo"].width = 169;
	}*/
}
window.onload = foo;
/*
function modify_img_size()//调整图片的大小(单个)
{
	if (document.all["news_photo"].width > 169)
	{
		var bl;
		bl = (document.all["news_photo"].width-169)/document.all["news_photo"].width;
		document.all["news_photo"].height = Math.round(document.all["news_photo"].height*(1-bl));
		document.all["news_photo"].width = 169;
	}
	/*if (document.all["news_photo"].height > 150)
	{
		var blh;
		blh = (document.all["news_photo"].height-150)/document.all["news_photo"].height;
		document.all["news_photo"].height = Math.round(document.all["news_photo"].height*(1-blh));
		document.all["news_photo"].height = 150;
	}
}
window.onload = modify_img_size;
*/

function sltall()//全选
{
	var l;
	l=document.all.vdown.length;
	if(l==null) 
	{  
		l=1;
	}  
	if (l==1)
	{
		document.all.vdown.checked=true;
	}
	else
	{
		for(i=0;i<document.all.vdown.length;i++)
		{
			document.all.vdown(i).checked=true;
		}
	}
}
function sltre()//反选
{
	var l;
	l=document.all.vdown.length;
	if(l==null) 
	{  
		l=1;
	}  
	if (l==1)
	{
		if (document.all.vdown.checked==true)
			{
			document.all.vdown.checked=false;
			}
		else
			{
			document.all.vdown.checked=true;
			}
	}
	else
	{
		for(i=0;i<document.all.vdown.length;i++)
		{
			if (document.all.vdown(i).checked==true)
				{
				document.all.vdown(i).checked=false;
				}
			else
				{
				document.all.vdown(i).checked=true;
				}
		}
	}
}
/*
function suitPic()//图片等比例
{
	var width = 0;
	var height = 0;
	var changed = 0;
	var setwidth = 800;
    var setheight = 2000;
	var post_img = document.getElementsByName("post_img");
	try
	{
		for (i = 0; i < post_img.length; i++)
		{
			width = post_img[i].width;
			height = post_img[i].height;
			changed = 0;
			if (post_img[i].width >setwidth)
			{
				n = post_img[i].width / setwidth
				post_img[i].width = setwidth;
				post_img[i].height = height / n
				changed = 1;

			}
			if (post_img[i].height >setheight)
			{
				n = post_img[i].height / setheight
				post_img[i].width = post_img[i].width / n
				post_img[i].height = setheight;
				changed = 1;
			}
			if (changed==1)
			{
				//post_img[i].insertAdjacentHTML("AfterBegin", "test");
				post_img[i].insertAdjacentHTML("AfterEnd", "<table border=0 width=100% cellspacing=0 cellpadding=0><tr><td style='padding-top: 4'>原图:<a href='" + post_img[i].src + "' target=_blank>" + post_img[i].src + "</a>|" + width + " × " + height + "</td></tr></table>")
			}
		}
		window.setTimeout("suitPic()", 100)
	}
	catch(e)
	{
		window.setTimeout("suitPic()", 100)
	}
}
suitPic();
*/


function download(str, i, first) //多文件下载
{
	var a = document.getElementsByName(str);
	var n = a.length;

	for (var i=i; i<n; i++)
	{
		if(a[i].checked)
		{
			window.location=a[i].value;
			if (first)
				timeout=6000;
			else
				timeout=500;
			i++;
			window.setTimeout("download('"+str+"', "+i+", 0)", timeout);
			break;
		}
	}

}

function copy(str)//复制链接
{
	var a = document.getElementsByName(str);
	var n = a.length;
	var ed2kcopy = document.getElementById("ed2kcopy_"+str);
	ed2kcopy.innerHTML = "";
	for (var i=0; i<n; i++)
	{
		if(a[i].checked)
		{
			ed2kcopy.innerHTML +=a[i].value;
			ed2kcopy.innerHTML +="<br />";
		}
	}
		var rng = document.body.createTextRange();
		rng.moveToElementText(ed2kcopy);
		rng.scrollIntoView();
		rng.select();
		rng.execCommand("Copy");
		rng.collapse(false);
}

function em_size(str) //计算多文件的大小
{
	var a = document.getElementsByName(str);
	var n = a.length;
	try {
		var input_checkall = document.getElementById("checkall_"+str);
		var size = 0;
		input_checkall.checked = true ;
		for (var i=0; i<n; i++)	{
			if (a[i].checked) {
				var piecesArray = a[i].value.split( "|" );
				size += piecesArray[3]*1;
			} else {
				input_checkall.checked = false;
			}
		}
		test = document.getElementById("size_"+str);
		test.innerHTML = gen_size(size, 3, 1);
	} catch (e) {

	}
}

function gen_size(val, li, sepa ) {
	sep = Math.pow(10, sepa);	//小数点后的位数
	li = Math.pow(10, li);	//开始截断的长度
	retval  = val;
	unit	= 'Bytes';
	if (val >= li*1000000000) {
		val = Math.round( val / (1099511627776/sep) ) / sep;
		unit  = 'TB';
	} else if (val >= li*1000000) {
		val = Math.round( val / (1073741824/sep) ) / sep;
		unit  = 'GB';
	} else if (val >= li*1000) {
		val = Math.round( val / (1048576/sep) ) / sep;
		unit  = 'MB';
	} else if (val >= li) {
		val = Math.round( val / (1024/sep) ) / sep;
		unit  = 'KB';
	}
	return val+unit;
}

function doSearch(o) {
    if (o.q.value.length < 2) {
		alert("请至少输入2个关键词");
		return false;
	}
	o.method = "get";
	if (o.radio2.checked) {
	    o.action = "http://www.google.com/custom";
	    o.target = "_blank";
	    o.q.value = o.q.value.replace("artist:","");
		return true;
	}
	o.action = "http://search.vagaa.com/search";
	location.href = "http://search.vagaa.com/search?q=" + o.q.value;
	return false;
}

function storePageToKey365() {
	if (document.selection) {
		var sel = document.selection.createRange().text;
	}
	if (!sel) {
		var sel = '';
	}
	var url   = location.href;
	var title = document.title;
	void(window.open('http://www.vagaa.com/storeIt.aspx?t='+escape(title)+'&u='+escape(url)+'&c='+escape(sel),'_blank','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes'));
}


