//设为首页
function set_homepage(url){
	if (document.all)
	{
		document.body.style.behavior='url(#default#homepage)';
		document.body.setHomePage(url);
	}else{
		if (window.sidebar)
		{
			try {
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
			}
			catch (e)
			{
				alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将[signed.applets.codebase_principal_support]设置为'true'");
				return false;
			}
			var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
			prefs.setCharPref('browser.startup.homepage',url);

		}
	}
}

//添加书签
function add_bookmark(title,url) {
	if (window.sidebar) {
		window.sidebar.addPanel(title, url,"");
	} else if( document.all ) {
		window.external.AddFavorite( url, title);
	} else if( window.opera && window.print ) {
		return true;
	}
}

//显示分类更新
function show_box(n){
	for(var i=0;i<11;i++){
		if(document.getElementById("box"+i) != null){
			document.getElementById("boxtitle"+i).className="";
			document.getElementById("box"+i).style.display="none";
		}
	}
	document.getElementById("boxtitle"+n).className="current";
	document.getElementById("box"+n).style.display="block";
}

//显示隐藏软件介绍
function set_introduction(type){

	//取得滚动条的位置
	var position = document.documentElement.scrollTop;

	if(type){
	    document.getElementById("softintrd").style.height = 'auto';
		document.getElementById("hide").style.display = 'inline';
		document.getElementById("display").style.display = 'none';
	}else{
		document.getElementById("softintrd").style.height = '100px';
		document.getElementById("hide").style.display = 'none';
		document.getElementById("display").style.display = 'inline';
		window.scrollBy(0,position);
	}

	

}
function showxunlei(){
	 var thunder_pid = "45241";
     var restitle = "";
	 var dx_url=new Array();
	 var wt_url=new Array();
	 var thunder_dxurl = "";
	 var thunder_wturl = "";
	 var n = 0;
	 var i = -1;
	 var k = -1;
	 /*
	  *电信
	  */
     $("#isp_dx a").each(function(){
		 if($(this).attr('href').indexOf('http://xiazai.xiazaiba.com/') == -1 &&
			$(this).attr('href').indexOf('http://down.xiazaiba.com/') == -1 && 
			$(this).attr('href').indexOf('http://gamedown.xiazaiba.com/') == -1
		   ) 
		   {
			 dx_url[++i]=$(this).attr('href');
		   }
     });
	 if(dx_url.length){
       n = Math.floor(Math.random()*dx_url.length); 
	   thunder_dxurl = dx_url[n];
	   var dx_html = '<li class="xunlei"><a href="#"  title="迅雷高速下载"   thunderHref="' + ThunderEncode(thunder_dxurl) + '" thunderPid="' + thunder_pid + '" thunderResTitle="' + restitle + '" onClick="return OnDownloadClick_Simple(this,2,4)" oncontextmenu="ThunderNetwork_SetHref(this)">迅雷高速下载</a></li>';
	   $("#isp_dx").append(dx_html);
	 }
	
     $("#isp_wt a").each(function(){
		 if($(this).attr('href').indexOf('http://xiazai.xiazaiba.com/') == -1 &&
			$(this).attr('href').indexOf('http://down.xiazaiba.com/') == -1 && 
			$(this).attr('href').indexOf('http://gamedown.xiazaiba.com/') == -1 
		   ) 
		   {
			 wt_url[++k]=$(this).attr('href');
		   }
     });
	 if(wt_url.length){
       n = Math.floor(Math.random()*wt_url.length); 
	   thunder_wturl = wt_url[n];
	   wt_html = '<li class="xunlei"><a href="#"  title="迅雷高速下载"   thunderHref="' + ThunderEncode(thunder_wturl) + '" thunderPid="' + thunder_pid + '" thunderResTitle="' + restitle + '" onClick="return OnDownloadClick_Simple(this,2,4)" oncontextmenu="ThunderNetwork_SetHref(this)">迅雷高速下载</a></li>';
       $("#isp_wt").append(wt_html);
     }	  
}
//评论检查
function check_comment(){
	if(document.getElementById('comment').value == ''){
		alert('很抱歉,请您先填写评论!');
		document.getElementById('comment').focus();
		return false;
	}
	if(document.getElementById('comment').value.length < 3){
		alert('很抱歉,评论字数不能少于3个!');
		document.getElementById('comment').focus();
		return false;
	}
	if(document.getElementById('imgcode').value == ''){
		alert('很抱歉,请您先填写验证码!');
		document.getElementById('imgcode').focus();
		return false;
	}
	if(document.getElementById('comment').value.length > document.getElementById('reviewlong').value){
		alert('很抱歉,评论字数不能超过'+document.getElementById('reviewlong').value+'个!');
		document.getElementById('comment').focus();
		return false;
	}
}

//搜索检查
function check_search(){
	if(document.getElementById('keyword').value == ""){
		alert('很抱歉,请您先输入您要搜索的内容!');
		document.getElementById('keyword').focus();
		return false;
	}
	if(document.getElementById('keyword').value == "请输入关键字搜索，支持软件名、版本号"){
		alert('很抱歉,请您先输入您要搜索的内容!');
		return false;
		document.getElementById('keyword').focus();
	}
	if(document.getElementById('keyword').value.length < 2){
		alert('很抱歉,搜索的内容不能少于2个字!');
		return false;
	}
}

//投诉检查
function check_complain(){
	if(document.getElementById('complain').value == ""){
		alert('很抱歉,请您先输入您要投诉的内容!');
		document.getElementById('complain').focus();
		return false;
	}
	if(document.getElementById('complain').value.length < 5){
		alert('很抱歉,投诉的内容不能少于5个字!');
		document.getElementById('complain').focus();
		return false;
	}
}

//评论回复
/*
function comment_reply(id,orderid){

	document.getElementById("comment").value='{回复'+orderid+"楼}:\r\n";

	document.getElementById("reply").value = id;

	//IE
	if(typeof document.selection !="undefined")
	{
		object = document.getElementById("comment").createTextRange();
		object.collapse(true);
		object.moveStart('character',8);
		object.select()
	}

	//FF ?
	//..................
}
*/
function comment_quote(id,orderid){
    document.getElementById("comment_title").parentNode.style.display = 'block';
	document.getElementById("comment_title").innerHTML='回复<strong class="color_f60">'+orderid+"</strong> 楼的评论";

	document.getElementById("quote_id").value = id;

	 document.getElementById("cancel").style.display = 'inline';

	//IE
	if(typeof document.selection !="undefined")
	{
		object = document.getElementById("comment").createTextRange();
		object.collapse(true);
		object.moveStart('character',0);
		object.select()
	}

	//FF ?
	//..................
}

function cancel_comment(){
  document.getElementById("comment_title").parentNode.style.display = 'none';
  document.getElementById("comment_title").innerHTML = '';
  document.getElementById("quote_id").value = '';
  document.getElementById("cancel").style.display = 'none';
}

//好评度
function add_vote(type,softid){
	$.ajax({
		type: "POST",
		url: "../vote.php",
		data: "action=add&softid="+softid+"&type="+type,
		cache:false,
		success: function(msg){
			alert(msg);

			//改变调回的数据
			if(msg == '投票成功！'){

				//原始值
				var up = document.getElementById('goodvalue') ;
				var down = document.getElementById('badvalue');
				
				if(!up.innerHTML){
				   up.innerHTML = 0;	
				}
				if(!down.innerHTML){
				   down.innerHTML = 0;
				}

				//计算
				var good = parseInt(up.innerHTML,10);
				var bad = parseInt(down.innerHTML,10);

				if(type == 'good'){
					good +=  1;
				}else{
					bad += 1 ;
				}

				var total = good + bad;

				var goodper = Math.round((good/total)*100);
				var badper = Math.round((bad/total)*100);

				document.getElementById('upbar').style.width = goodper+'%';
				document.getElementById('downbar').style.width = badper+'%';

				up.innerHTML = good;
				down.innerHTML  = bad;

			}
		}
	});
}
// 系统统计
var countimg=document.createElement('img');
function hits(sid,type){
	if (!get_cookie(type+'_'+sid))
	{
		  gettime=new Date().getTime();
          url='http://www1.xiazaiba.com/softcount.php?action='+type+'&sid='+sid+'&gettime='+gettime;
          countimg.src=url;
	}
}
function logad(id){
       gettime=new Date().getTime();
       url='http://www1.xiazaiba.com/countjs.php?id='+id+'&gettime='+gettime;
       countimg.src=url;  
}
function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) {
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1)
end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function post2bbs(softid){
	if (document.all){
		var obj = document.getElementById('soft2bbspost');
		var d=obj.innerText; 
		window.clipboardData.setData('text', d);
		alert('软件详细信息已经复制到剪贴板!');
	}else{
		window.open("http://www.xiazaiba.com/post2bbs.php?id="+softid);
	}
}
function copy(txt)
{
    if (window.clipboardData)
    {
        window.clipboardData.setData("Text",txt);
    }
    else
    {
        txt = encodeURIComponent(txt);

        var flashcopier = 'flashcopier';
        if(!document.getElementById(flashcopier))
        {
            var divholder = document.createElement('div');
            divholder.id = flashcopier;
            document.body.appendChild(divholder);
        }
        document.getElementById(flashcopier).innerHTML = '';
        var divinfo = '<embed src="/images/clipboard.swf" flashvars="clipboard='+txt+'" type="application/x-shockwave-flash" width="0" height="0"></embed>';
        document.getElementById(flashcopier).innerHTML = divinfo;
    }

    alert("复制成功");
}
var flag=false;
function DrawImage(ImgD,iwidth,iheight){
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= iwidth/iheight){
if(image.width>iwidth){ 
ImgD.width=iwidth;
ImgD.height=(image.height*iwidth)/image.width;
}else{
ImgD.width=image.width; 
ImgD.height=image.height;
}

ImgD.alt="点击小图查看大图片!";
}
else{
if(image.height>iheight){ 
ImgD.height=iheight;
ImgD.width=(image.width*iheight)/image.height; 
}else{
ImgD.width=image.width; 
ImgD.height=image.height;
}
ImgD.alt="点击小图查看大图片!";
}
}
}
