﻿if(self!=top){top.location=self.location;} 
//设为首页
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 = "";
    
    if ($('#base_download').length < 1)
    {
         return false;
    }
    
	var thunder_dxurl = $('#base_download').attr('href');
	var softid = document.getElementById('softid').value;
	var dx_html = '<li><img src="/images/ico-xl-16.gif" alt="" /> <a href="javascript://" title="迅雷高速下载" thunderHref="' + ThunderEncode(thunder_dxurl) + '" thunderPid="' + thunder_pid + '" thunderResTitle="' + restitle + '" onClick="hits('+softid+',\'down\'); return OnDownloadClick_Simple(this,2,4)" oncontextmenu="ThunderNetwork_SetHref(this)">迅雷下载</a></li>'
                +'<li><img src="/images/ico-kc-16.gif" alt="" /> <a href="javascript://" title="快车高速下载" onClick="convertFgURL(\''+thunder_dxurl+'\',1926);hits('+softid+',\'down\'); "  oncontextmenu="Flashget_SetHref_js(\''+thunder_dxurl+'\',1926);" >快车下载</a></li>'
                +'<li><img src="/images/ico-xf-16.gif" alt="" /> <a href="#" OnClick="OnDownload_template(\'qqdl://'+encode64(thunder_dxurl)+'\', 30002,\'http://down.xiazaiba.com/QQDownload.exe\');" title="超级旋风下载">旋风下载</a></li>';
	$("#xunlei_download").prepend(dx_html);

 
    /*
     * 电信
     */
	var dx_html = '<a href="javascript://" title="迅雷高速下载" thunderHref="' + ThunderEncode(thunder_dxurl) 
			      + '" thunderPid="' + thunder_pid + '" thunderResTitle="' + restitle 
			      + '" onClick="return OnDownloadClick_Simple(this,2,4)" oncontextmenu="ThunderNetwork_SetHref(this)" class="xunlei">迅雷下载</a>'
			      + '<a href="javascript://" title="快车高速下载" onClick="convertFgURL(\''+thunder_dxurl+'\',1926)" oncontextmenu="Flashget_SetHref_js(\'' 
			      + thunder_dxurl+'\',1926);"  class="kc">快车下载</a><a href="javascript://" class="xf" OnClick="OnDownload_template(\'qqdl://'+encode64(thunder_dxurl)+'\', 30002 ,\'http://down.xiazaiba.com/QQDownload.exe\');" title="超级旋风下载">旋风下载</a>';
	$("#isp_dx").append(dx_html);
	$("#isp_wt").append(dx_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';
}

// 系统统计
var countimg=document.createElement('img');
function hits(sid, type) {
    $.post("/Comment.aspx/AddHits?" + new Date(), {
        softid: sid
    }, function(data) {
        $("#down_num").html("已有 " + data + " 次下载");
    });
}
function logad(id){
       gettime=new Date().getTime();
       url=_PHP_URL+'/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 ( true ){
        copy($("#soft2bbspost").text());
        //window.clipboardData.setData('text', d);
    }else{
        window.open(_PHP_URL+"/post2bbs.php?id="+softid);
    }
}
function post2bbsII (softid) {
    if (window.clipboardData){
        copy($("#soft2bbspost").text());
        //window.clipboardData.setData('text', d);
    }else{
        window.open(_PHP_URL+"/post2bbs.php?id="+softid);
    }
}
function copy(pStr,showMsg)
{
    //IE            
  if(window.clipboardData)
  {
    window.clipboardData.clearData();
    window.clipboardData.setData("Text", pStr);
  }
  //Opera浏览器
  else if(navigator.userAgent.indexOf("Opera") != -1)
  {
      window.location = txt;
  }
  //FireFox
  else if (window.netscape)
  {
      try
      {
          netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
      }
      catch (e)
      {
          alert("您的firefox安全限制限制您进行剪贴板操作，请打开'about:config'将signed.applets.codebase_principal_support'设置为true'之后重试");
          return false;
      }
      var clip = Components.classes["@mozilla.org/widget/clipboard;1"].createInstance(Components.interfaces.nsIClipboard);
      if (!clip)
          return;
      var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
      if (!trans)
          return;
      trans.addDataFlavor('text/unicode');
      var str = new Object();
      var len = new Object();
      var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
      var copytext = pStr;
      str.data = copytext;
      trans.setTransferData("text/unicode",str,copytext.length*2);
      var clipid = Components.interfaces.nsIClipboard;
      if (!clip)
      return false;
      clip.setData(trans,null,clipid.kGlobalClipboard);
  }
  var showMsg = showMsg ? showMsg:"内容已复制到剪切板！";
  alert(showMsg);
}
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 = "点击小图查看大图片!";
        }
    }
}

// flashget union
function convertFgURL(url,id){
    try{
        FlashgetDown(FlashgetEncode_js(url,id),id);
    }catch(e){
        //alert(e.message);
        location.href = url;
    }

}
function Flashget_SetHref_js(url,uid){
    obj.href = FlashgetEncode_js(url,uid) ;
}

function FlashgetEncode_js(t_url,uid) {
    var prefix = "Flashget://";
    var FlashgetURL =  prefix + encode64(strUnicode2Ansi("[FLASHGET]" +t_url + "[FLASHGET]"))+"&"+uid;
    return FlashgetURL;
}
function FlashgetDown(str,uid){
    str = str+"&1248503250";
    AddLink(str,"www.kuaiche.com",window.location.href,uid);
}

function AddLink(durl,text,qurl,uid){
        var JetCarCatch = null;       
    if (navigator.appName == "Netscape")
    {    
        window.open (durl, "newwindow", "");
    }
    else
    {

        try{
            JetCarCatch=new ActiveXObject("FG2CatchUrl.Netscape");
        }catch(e){
            try{
                JetCarCatch = new ActiveXObject("BHO.IFlashGetNetscape");
            }catch(e){
                try{
                    JetCarCatch=new ActiveXObject("JetCar.Netscape");
    			}catch(e){}
			}
		}
	
		if(JetCarCatch!=null){
			try{
				JetCarCatch.AddUrl(durl,text,qurl);
			}catch(e){
				JetCarCatch.AddUrlEx(durl,text,qurl,"","0");	
			}
		}else{
			kuaicheMsg(uid);
		}
	}
}


function Flashget_in_array(uid) {
var u =  new Array(20230,13399,99999);
  for (var i = 0; i <u.length; i++) {
     thisEntry = u[i].toString();
     if (thisEntry == uid) {
	     return true;
     }
  }
  return false;
}


function kuaicheMsg(uid){	
alert("\u672c\u94fe\u63a5\u4e3a\u5feb\u8f66\u9ad8\u901f\u4e0b\u8f7d\u94fe\u63a5\uff0c\u9700\u5b89\u88c5\u65b0\u7248\u5feb\u8f66\uff08\u0046\u006c\u0061\u0073\u0068\u0067\u0065\u0074\uff09\u4ee5\u63d0\u9ad8\u4e0b\u8f7d\u901f\u5ea6\n\u0020\u0020\u0020\u0020\u0020\u70b9\u51fb\u786e\u5b9a\u4e0b\u8f7d\u6700\u65b0\u7248\u672c\uff0c\u5373\u53ef\u63d0\u5347\u591a\u500d\u4e0b\u8f7d\u901f\u5ea6\uff0c\u4eab\u53d7\u6781\u901f\u4e0b\u8f7d");
		
		if(uid==7863)
                	window.open("http://dl.game.kuaiche.com/flashget/index_union.html?fid="+uid,"","");
		else if(Flashget_in_array(uid))
			//location.href="http://down5.flashget.com/unmini/fgmun_"+uid+"_3.exe";	
			location.href="http://down6.flashget.com/un/flashget_"+uid+"_1.exe";
		else
			location.href="http://down6.flashget.com/unxp/flashget_"+uid+"_1.exe";
}

Cookie = {};
Cookie.Set = function(name, value, hours){
  var expire = "";
  if(hours != null){
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire;
}

Cookie.Get = function(name){
  var cookieValue = "";
  var search = name + "=";
  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;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}

function search_sort( keyword, type ){
    window.location=_PHP_URL+"search.php?keyword="+keyword+"&order=" + type;
}
$(document).ready(function() {
    $("table.down-lines").hide();

    var showDownListTimer;
    var hideState = true;

    var showDownListBox = function() {
        var a = $(".down-area a.down-list");
        var span = $(a.find("span.arrow"));
        span.addClass("arrow-up");
        $("table.down-lines").show();
    }

    var hideDownListBox = function() {
        if (hideState) {
            var a = $(".down-area a.down-list");
            var span = $(a.find("span.arrow"));
            span.removeClass("arrow-up");
            $("table.down-lines").hide();
        }
    }

    $(".down-area a.down-list").bind("mouseover", function() {
        if (showDownListTimer) {
            window.clearTimeout(showDownListTimer);
            showDownListTimer = null;
        }
        hideState = false;
        showDownListTimer = window.setTimeout(showDownListBox, 400);
    }).bind("click", function() {
        if (hideState) {
            if (showDownListTimer) {
                window.clearTimeout(showDownListTimer);
                showDownListTimer = null;
            }
            hideState = false;
            showDownListTimer = window.setTimeout(showDownListBox, 400);
        }
    }).bind("mouseout", function() {
        if (showDownListTimer) {
            window.clearTimeout(showDownListTimer);
            showDownListTimer = null;
        }
        hideState = true;
        showDownListTimer = window.setTimeout(hideDownListBox, 400);
    });
    
    $("table.down-lines").bind("mouseover", function() {
        hideState = false;
    }).bind("mouseout", function() {
        if (showDownListTimer) {
            window.clearTimeout(showDownListTimer);
            showDownListTimer = null;
        }
        hideState = true;
        showDownListTimer = window.setTimeout(hideDownListBox, 400);
    });

    //发表评论
    $("#js_com_submit1").bind("click", function() {
        var obj = {};
        obj.username = $("#your_name").val();
        obj.imgcode = $("#code").val();
        obj.comment = $("#your_desc").val();
        obj.softid = $("#softid").val();
        obj.email = $("#your_email").val();
        obj.softname = $("#softname").val();
        var errorbox = $("#form_error_box");
        errorbox.hide();
        var errorMsg = InsertRecomment(obj, function(res) {
            var result = eval("(" + res + ")");
            if (result.state == 1) {
                $("#code").val('');
                $("#your_desc").val('');
                alert("发表成功!");
                window.location.hash = "#soft_comment";
                document.getElementById("com_iframe").contentWindow.location.reload();
            }
            else {
                errorbox.show();
                errorbox.html(result.msg);
            }
            $("#js_img_code").attr("src", "/Comment.aspx/Code" + new Date());
        });
        if (errorMsg != "") {
            errorbox.show();
            errorbox.html(errorMsg);
        }
    });

    var changeImgState = true;
    $("#code").bind("focus", function() {
        var imgBox = $("#js_img_code");
        imgBox.appendTo("#" + this.id + "_imgbox");
    }).bind("blur", function() {
        if (changeImgState) {
            var imgBox = $("#js_img_code");
            imgBox.appendTo("#js_cache_box");
        }
    });

    $("#js_img_code").bind("mouseover", function() {
        changeImgState = false;
    }).bind("mouseout", function() {
        changeImgState = true;
    }).bind("click", function() {
        this.src = "/Comment.aspx/Code?" + new Date();
    });


});
var InsertRecomment = function(obj, callback) {
    obj.username = $.trim(obj.username);
    obj.imgcode = $.trim(obj.imgcode);
    obj.comment = $.trim(obj.comment);
    obj.email = $.trim(obj.email);

    if (obj.username == "") {
        return "昵称不能为空";
    }
    if (obj.username.length > 15) {
        return "昵称不能超过15个字符";
    }
    if (obj.email == "") {
        return "电子邮件不能为空";
    }
    if (!isEmail(obj.email)) {
        return "请正确输入电子邮件";
    }
    if (obj.comment == "") {
        return "请输入评论内容";
    }
    if (obj.comment.length < 3 || obj.comment.length > 200) {
        return "评论内容要在3到200个字符以内";
    }
    if (obj.imgcode == "") {
        return "请输入验证码";
    }
    $.post("/Comment.aspx/PostComment?" + new Date(), {
        username: obj.username,
        email: obj.email,
        imgcode: obj.imgcode,
        comment: obj.comment,
        softid: obj.softid,
        softname: obj.softname
    }, callback);
    return "";
}

//好评度
function add_vote(type, softid) {
    var softListID = $.cookie('softListID');
    if (softListID == null)
        softListID = '';
    if (softListID.indexOf(',' + softid + ',') >= 0) {
        window.alert('感谢您的支持，您已经投过票了！');
        return false;
    }
    if (softListID == '') {
        softListID = ',' + softid + ',';
    }
    else {
        softListID = ',' + softid + softListID;
    }
    $.cookie('softListID', softListID, { path: '/', expires: 30 * 24 });
    $.ajax({
        type: "POST",
        url: "/Comment.aspx/Vote",
        data: "softid=" + softid + "&type=" + type + "&rnd" + new Date(),
        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;

            }
        }
    });
}

function init() {
    var softid = $("#softid").val();
    $.post("/Comment.aspx/Init?" + new Date(), {
        softid: softid
    }, function(data) {
        var result = eval("(" + data + ")");
        var good = result.gooddigg;
        var bad = result.baddigg
        $("#goodvalue").html(good);
        $("#badvalue").html(bad);
        $("#down_num").html("已有 " + result.hits + " 次下载");
        var total = good + bad;
        if(total>0)
        {
        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 + '%';
        }
    });    
}

function isEmail(strEmail) {
    if (strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
}

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') {
        options = options || {};
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toGMTString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toGMTString();
        }
        var path = options.path ? '; path=' + options.path : '';
        var domain = options.domain ? '; domain=' + options.domain : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else {
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
function initcommon() {
    $("#banner_1").html("<a href=\"http://www.itlike.net\"><img alt=\"绿色软件,迅雷下载,电驴下载,精品分享绿色下载群！\" src=\"/css/1.jpg\"  border=\"0\"></a>");
    $("#banner_2").html("<iframe src=\"/scripts/google.html\" scrolling=\"no\" frameborder=\"0\" width=\"468\" height=\"60\"></iframe>");
    $("#banner_3").html("<a href=\"http://aq.115.com/\" target=\"_blank\"><img src=\"/css/3.jpg\"  border=\"0\"></a>");
    $("#gg_360").html("<a href=\"/\" target=\"_blank\"><img src=\"/css/gg_360.gif\"  border=\"0\"></a>");
    $("#hottag").html("<a href='/' style='color:#077C00; font-size:12px;' target='_blank'>首页修复</a> <a href='/' style=' font-size:12px;' target='_blank'>我要上网</a> <a href='/' style='color:#E4001C; font-size:12px;' target='_blank'>游戏下载吧</a> <a href='/' style=' font-size:12px;' target='_blank'>我要听歌</a> <a href='/' style=' font-size:12px;' target='_blank'>我要杀毒</a> <a href='/' style=' font-size:12px;' target='_blank'>播放器</a> <a href='/' style=' font-size:12px;' target='_blank'>超级兔子</a> <a href='/' style=' font-size:12px;' target='_blank'>免费Office</a> <a href='/' style=' font-size:12px;' target='_blank'>傲游</a> ");
}