var D=document,G="getElementById",G_Name="getElementsByName",G_TagName="getElementsByTagName";
window.onerror=function(){return true;}
window.onload=function(){if(navigator.userAgent.indexOf("MSIE 6.0")>0){document.execCommand('BackgroundImageCache',false,true);}}
function checkKey(o){//检测关键词
	var strs="搜索软件和游戏";
	if(o.value!=""){
		if(o.value==strs){
			o.value="";
		}
	}else{
		o.value=strs;
	}
}
function checkText(){//提交表单
	if(D[G]('searchText').value=='搜索软件和游戏' || D[G]('searchText').value==''){D[G]('searchText').value="搜索软件和游戏";openTips('s','请输入搜索关键词！');}
	else{document.headSearchForm.submit();}
}
//返回顶部
function goto_top(){document.getElementsByTagName('html')[0].scrollTop=0;}
//写入cookie
function Set_Cookie(Cookie_name,Cookie_String){
	var Then = new Date();
	Then.setTime(Then.getTime() + 24*60*60*365*1000);
	document.cookie = Cookie_name+"="+Cookie_String+";expires="+ Then.toGMTString()+";path=/";
}
function Get_Cookie(Cookie_name){
	var cookieString = new String(document.cookie);
	var cookieHeader = Cookie_name+"=";
	var beginPosition = cookieString.indexOf(cookieHeader);
	if(beginPosition != -1){return cookieString.substr(beginPosition + cookieHeader.length,1);}else{return null;}　　
}
//弹出tips
var u_tips=null;
var s_tips=null;
var c2_tips=null;
function show_u_tipsDiv(){//用户第一次登陆弹出tips
	D[G]("userCtrlTips").style.display = "block";
	//D[G]("userCtrlTips").innerHTML='<span style="float:left;background:url(images/login_tips.png) no-repeat;_background:none;_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src=\'images/login_tips.png\');height:46px;width:238px;"></span>';
	D[G]("userCtrlTips").onclick = function(){closeTips('userCtrlTips',u_tips);};
	u_tips = window.setTimeout("closeTips('userCtrlTips',u_tips)", 5000);
}
function show_search_tipsDiv(){//搜索错误弹出tips
	D[G]("searchTips").style.display = "block";
	//D[G]("searchTips").innerHTML='<span style="float:left;background:url(images/search_tips.png) no-repeat;_background:none;_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src=\'images/search_tips.png\');height:29px;width:158px;line-height:20px;padding-top:17px;font-size:12px;text-align:center;color:#E04A00;">'+arguments[0]+'</span>';
	D[G]("searchTips").innerHTML=arguments[0];
	D[G]("searchTips").onclick = function(){
		closeTips('searchTips',s_tips);
		if(D[G]('searchText').createTextRange){
			var range = D[G]('searchText').createTextRange();
			range.collapse(false);
			range.moveStart('character',D[G]('searchText').value.length);
			range.select();
		}else if(D[G]('searchText').setSelectionRange){
			D[G]('searchText').setSelectionRange(D[G]('searchText').value.length, D[G]('searchText').value.length);
			D[G]('searchText').focus();
		}
	};
	s_tips = window.setTimeout("closeTips('searchTips',s_tips);D[G]('searchText').focus();D[G]('searchText').select();", 3000);
}
function show_class2_tipsDiv(){//搜索错误弹出tips
	D[G]("class2Tips").style.display = "block";
	D[G]("class2Tips").onclick = function(){closeTips('class2Tips',c2_tips);Set_Cookie("show_class2_tips","3");};
	c2_tips = window.setTimeout("closeTips('class2Tips',c2_tips)", 20000);
}
function openTips(){
	switch(arguments[0]){
		case 'u':
			var cookval=Get_Cookie("show_u_Tips");
			if(cookval == null){
				Set_Cookie("show_u_Tips","y");
				show_u_tipsDiv();
			};
			break;
		case 's':
			show_search_tipsDiv(arguments[1]);
			break;
		default:
			var cookval=Get_Cookie("show_class2_tips");
			if(cookval == null){
				Set_Cookie("show_class2_tips","1");
				show_class2_tipsDiv();
			}else{
				var cookint=parseInt(cookval);
				if(cookint<3){
					cookint++;
					Set_Cookie("show_class2_tips",cookint);
					show_class2_tipsDiv();
				}
			}
			break;
	}
}
function closeTips(){
	D[G](arguments[0]).style.display = "none";
	window.clearTimeout(arguments[1]);
}

//用户操作下拉
var u_classA=null;
var u_sedClassTimer=null;
function add_u_Function(){
	var getObjDiv=document.getElementById("uesrCtrl");
	getObjDiv.onmouseover=function(){clearTimeout(u_sedClassTimer);}
	getObjDiv.onmouseout=function(){u_sedClassTimer = setTimeout('u_hidSedClass();', 500);}
	var getObj=getObjDiv.getElementsByTagName("a");
	var getObjlen=getObj.length;
}
function u_showSedClass(o){
	if(D[G]("userCtrlTips")){D[G]("userCtrlTips").style.display = "none";}
	u_classA=o;
	clearTimeout(u_sedClassTimer);
	o.onmouseout=function(){u_sedClassTimer = setTimeout('u_hidSedClass();', 500);}
	document.getElementById("uesrCtrl").style.display="block";
}
function u_hidSedClass(){
	document.getElementById("uesrCtrl").style.display="none";
}
//二级子分类
var classA=null;
var sedClassTimer=null;
function addFunction(){
	var getObjDiv=document.getElementById("class_frm_div");
	getObjDiv.onmouseover=function(){clearTimeout(sedClassTimer);}
	getObjDiv.onmouseout=function(){sedClassTimer = setTimeout('hidSedClass();', 500);}
	var getObj=getObjDiv.getElementsByTagName("a");
	var getObjlen=getObj.length;
	for(i=0;i<getObjlen;i++){
		getObj[i].onclick=function(){
			this.blur();
			var getObj=this.parentNode.parentNode.getElementsByTagName("a");
			var getObjlen=getObj.length;
			for(i=0;i<getObjlen;i++){getObj[i].className="";}
			this.className="active";
			//ajax接口(this.href)
			hidSedClass();
		}
	}
}
function showSedClass(o){
	closeTips('class2Tips',c2_tips);
	classA=o;
	o.className="sg_classtowactive";
	clearTimeout(sedClassTimer);
	o.onmouseout=function(){sedClassTimer = setTimeout('hidSedClass();', 500);}
	document.getElementById("class_frm_div").style.display="block";
}
function hidSedClass(){
	classA.className="sg_classtow";
	document.getElementById("class_frm_div").style.display="none";
}

//page
function page_width(){
	try{
		var getPage=document.getElementById('page_w').getElementsByTagName('a');
		var getPagelen=getPage.length;
		var p_w=0;
		for(i=0;i<getPagelen;i++){
			p_w += getPage[i].clientWidth+2;
		}
	document.getElementById('page_w').style.width=p_w+20+"px";
	}catch(e){}
}

//index tab切换
function cutOverTab_index(o){
	o.blur();
	var getAllTab = o.parentNode.getElementsByTagName("a");
	var allTabLen = getAllTab.length;
	for(i=0;i<allTabLen;i++){
		if(getAllTab[i].className!="more" && getAllTab[i].className!="hart" && getAllTab[i].className!="star"){
			getAllTab[i].className="";
		}
	}
	o.className="active";
}
//list tab切换
function cutOverTab_list(o){
	o.blur();
	var getAllTab = o.parentNode.getElementsByTagName("a");
	var allTabLen = getAllTab.length;
	for(i=0;i<allTabLen;i++){
		if(getAllTab[i].className!="more"){
			switch(getAllTab[i].className){
				case 'hart':
					getAllTab[i].className="hart";break;
				case 'star':
					getAllTab[i].className="star";break;
				case 'hartactive':
					getAllTab[i].className="hart";break;
				case 'staractive':
					getAllTab[i].className="star";break;
				case 'win7':
					getAllTab[i].className="win7";break;
				case 'win7active':
					getAllTab[i].className="win7";break;
				case 'cmt':
					getAllTab[i].className="cmt";break;
				case 'cmtactive':
					getAllTab[i].className="cmt";break;
				default:
					getAllTab[i].className="";break;
			}
		}
	}
	switch(o.className){
		case 'hart':
			o.className="hartactive";break;
		case 'star':
			o.className="staractive";break;
		case 'win7':
			o.className="win7active";break;
		case 'cmt':
			o.className="cmtactive";break;
		default:
			o.className="active";break;
	}
}
//游戏软件Tab切换
function disList(){
	for(i=0;i<arguments[1];i++){
		D[G](arguments[2]+i).style.display='none';
	}
	D[G](arguments[2]+arguments[0]).style.display='block';
}
/*下拉*/
var getSltTipUl=null;
var selectTipTimer=null;
var numms=0;
function slt_frm_load(){
	if(!document.getElementById("slt_frm")){return;}
	var sltFrm=document.getElementById("slt_frm");
	var getFrmLi =sltFrm.getElementsByTagName("li");
	var getFrmA =sltFrm.getElementsByTagName("a");
	var getFrmLiAlen= getFrmLi.length;
	for(i=0;i<getFrmLiAlen;i++){
		getFrmLi[i].onmouseover=function(){clearTimeout(selectTipTimer);}
		getFrmLi[i].onmouseout=disSelectTipUl;
		getFrmA[i].onclick=function(){
			this.blur();
			document.getElementById("slt_clk"+numms).innerHTML=this.innerHTML;
			removeSelectTips();			
		}
	}
}
function clk_select(n,o){
	o.blur();
	numms=n;
	clearTimeout(selectTipTimer);
	var getSltUl= document.getElementById('slt_frm').getElementsByTagName('ul');
	for(i=0;i<getSltUl.length;i++){
		getSltUl[i].style.display="none";
	}
	getSltTipUl= getSltUl[n-1];
	getSltTipUl.style.display="block";
}
function disSelectTipUl(){selectTipTimer = setTimeout('removeSelectTips()', 500);}
function removeSelectTips(){
	if(getSltTipUl !=null){
		getSltTipUl.style.display="none";
	}
}

//幻灯
var _$ = function(id){return "string" == typeof id ? document.getElementById(id) : id; }; 
var Class ={create: function(){return function(){this.initialize.apply(this, arguments);}}} 
Object.extend = function(destination, source){
	for (var property in source){ 
		destination[property] = source[property]; 
	} 
	return destination; 
} 
var YD_slideView = Class.create(); 
YD_slideView.prototype = { 
	//容器对象,滑动对象,切换参数,切换数量 
	initialize: function(slide_pic, slider, parameter, count, options) { 
		if(parameter <= 0 || count <= 0) return; 
		var oslide_pic = _$(slide_pic), oSlider = _$(slider), oThis = this; 
		this.Index = 0;//当前索引 
		this._timer = null;//定时器 
		this._slider = oSlider;//滑动对象 
		this._parameter = parameter;//切换参数 
		this._count = count || 0;//切换数量 
		this._target = 0;//目标参数 
		this.SetOptions(options); 
		this.Up = !!this.options.Up; 
		this.Step = Math.abs(this.options.Step); 
		this.Time = Math.abs(this.options.Time); 
		this.Auto = !!this.options.Auto; 
		this.Pause = Math.abs(this.options.Pause); 
		this.onStart = this.options.onStart; 
		this.onFinish = this.options.onFinish; 
		
		oslide_pic.style.overflow = "hidden"; 
		oslide_pic.style.position = "relative"; 
		oSlider.style.position = "absolute"; 
		oSlider.style.top = oSlider.style.left = 0; 
	}, 
	//设置默认属性 
	SetOptions: function(options){ 
		this.options = {//默认值 
			Up:true,//是否向上(否则向左) 
			Step:5,//滑动变化率 
			Time:10,//滑动延时 
			Auto:true,//是否自动转换 
			Pause:3000,//停顿时间(Auto为true时有效) 
			onStart:function(){},//开始转换时执行 
			onFinish:function(){}//完成转换时执行 
		}; 
		Object.extend(this.options, options || {}); 
	}, 
	//开始切换设置 
	Start: function(){ 
		if(this.Index < 0){this.Index = this._count - 1;}else if(this.Index >= this._count){this.Index = 0;} 
		this._target = -1 * this._parameter * this.Index; 
		this.onStart(); 
		this.Move(); 
	}, 
	//移动 
	Move: function() { 
		clearTimeout(this._timer); 
		var oThis = this, style = this.Up ? "top" : "left", iNow = parseInt(this._slider.style[style]) || 0, iStep = this.GetStep(this._target, iNow); 
		if (iStep != 0) { 
			this._slider.style[style] = (iNow + iStep) + "px"; 
			this._timer = setTimeout(function(){ oThis.Move(); }, this.Time); 
		}else{ 
			this._slider.style[style] = this._target + "px"; 
			this.onFinish(); 
			if (this.Auto){ this._timer = setTimeout(function(){ oThis.Index++; oThis.Start(); }, this.Pause);} 
		} 
	}, 
	//获取步长 
	GetStep: function(iTarget, iNow){ 
		var iStep = (iTarget - iNow) / this.Step; 
		if (iStep == 0) return 0; 
		if (Math.abs(iStep) < 1) return (iStep > 0 ? 1 : -1); 
		return iStep; 
	}, 
	//停止 
	Stop: function(iTarget, iNow){ 
		clearTimeout(this._timer); 
		this._slider.style[this.Up ? "top" : "left"] = this._target + "px"; 
	} 
}; 
function starSlide(){ 
	function Each(list,fun){ 
		for(var i=0,len=list.length;i<len;i++){fun(list[i], i);} 
	}; 
	var objs = _$("slide_mu").getElementsByTagName("a");
	for(var z=0;z<_$("slider").getElementsByTagName("img").length;z++){
		_$("slider").getElementsByTagName("img")[z].src+='?rnd='+Math.random();
		var imgx=[];
		imgx[z]=new Image();
		imgx[z].src=_$("slider").getElementsByTagName("img")[z].src;
	}
	var YD_mini_new = new YD_slideView("slide_pic","slider",175,5,{ 
		onStart : function(){ Each(objs, function(o, i){o.className = YD_mini_new.Index == i ? "active" : ""; })}//按钮样式 
	}); 
	YD_mini_new.Start(); 
	
	Each(objs, function(o, i){ 
		o.onmouseover = function(){ 
			o.className = "active"; 
			YD_mini_new.Auto = false; 
			YD_mini_new.Index = i; 
			YD_mini_new.Start(); 
		} 
		o.onmouseout = function(){ 
			o.className = ""; 
			YD_mini_new.Auto = true; 
			YD_mini_new.Start(); 
		} 
	})     
} 

//详情页（评分，顶，踩）
var setpTimer=null;
var hand_star_sucTimer=null;
var zoomIn=function(strs,aimObj,minFont,maxFont){
	aimObj.style.top="-70px";
	aimObj.style.color="#cc3300";
	if(strs=="减分"){
		aimObj.style.top="-25px";
		aimObj.style.color="#444b50";
	}else if(strs=="赞"){
		aimObj.style.top="-40px";
		aimObj.style.color="#cc3300";
	}
	aimObj.style.display="block";
	aimObj.innerHTML=strs;
	var fontSize=minFont,opacity = 1;
	var setpTimer=setInterval(function(){
		fontSize+=2;
		opacity-=0.09;
		aimObj.style.fontSize=fontSize+"px";
		aimObj.style.opacity=opacity;
		aimObj.style.filter = "Alpha(opacity="+opacity*100+")";
		if(fontSize>maxFont){clearInterval(setpTimer);aimObj.style.display="none";}
	},20);
};
//写cookie
function writecookie_x(name, value, toff){
	var Dobj = new Date();
	Dobj.setTime(Dobj.getTime() + toff);
	document.cookie=name + "=" + value +";expires=" +  Dobj.toGMTString()+";path=/";
}
//读cookie
function readcookie_x(name){
	var mycookie = document.cookie;
	var start1 = mycookie.indexOf(name + "=");
	if (start1== -1){
		return null;
	}else{
		start=mycookie.indexOf("=",start1) + 1;
		var end = mycookie.indexOf(";",start);
		if (end==-1){
			end=mycookie.length;
		}
		return unescape(mycookie.substring(start,end));
	}
}
function handStar(strs,ids,o,softId){
	o.blur();
	clearInterval(setpTimer);
	var getHandSatrCookie=readcookie_x("handStarVar");
	if(getHandSatrCookie==null){
		writecookie_x("handStarVar","l"+softId+"l",5*60*1000);
		handStarOk(strs,ids,o,softId);
	}else{
		if(getHandSatrCookie.indexOf("l"+softId+"l",0)==-1){
			if(getHandSatrCookie.length>4000){
				writecookie_x("handStarVar","l"+softId+"l",5*60*1000);
			}else{
				writecookie_x("handStarVar",getHandSatrCookie+"l"+softId+"l",5*60*1000);
			}			
			handStarOk(strs,ids,o,softId);
		}else{clearInterval(hand_star_sucTimer);hand_star_suc('您已经评过分！');return false;}
	}
	return false;
}
function handStarOk(strs,ids,o,softId){
	zoomIn(strs,D[G](ids),12,46);
	var clk_text=D[G](o.className).innerHTML;
	var clkNum=parseInt(clk_text.split(" (")[0])+1;
	D[G](o.className).innerHTML=clkNum+" (0%)";									 
	var getClkA=o.parentNode.getElementsByTagName("a");
	if(o==getClkA[0]){
		var handNum=1;
	}else{
		var handNum=2;
	}
	var h_up_1=getClkA[0].getElementsByTagName("font")[0].innerHTML.split(" (")[0];
	var h_down_1=getClkA[1].getElementsByTagName("font")[0].innerHTML.split(" (")[0];
	setup_Star(h_up_1,h_down_1);
	post_starNum(handNum);
	getClkA[0].onclick=function(){this.blur();clearInterval(hand_star_sucTimer);hand_star_suc('您已经评过分！');return false;};
	getClkA[1].onclick=function(){this.blur();clearInterval(hand_star_sucTimer);hand_star_suc('您已经评过分！');return false;};
}
function hand_star_suc(){
 	D[G]("hand_star_tips").style.display="block";
	D[G]("hand_star_tips").innerHTML=arguments[0];hand_star_sucTimer=setTimeout("D[G]('hand_star_tips').style.display='none'",1000);
}
function setup_Star(h_up,h_down){//评分
	var h_Total=parseInt(h_up)+parseInt(h_down);
	if(h_Total>0){
		var h_up_percent=parseInt((h_up/h_Total)*100);
		var h_down_percent=100-h_up_percent;
		if(h_up_percent==100){
			var perc=h_up_percent;
			h_up_percent=99;
		}
		if(h_up_percent.toString().length>1){
			var integer_n=h_up_percent.toString().substr(0,1);
			var decimal_n=h_up_percent.toString().substr(1);
		}else{
			var integer_n=0;
			var decimal_n=h_up_percent.toString().substr(0,1);
		}
	}else{
		var h_up_percent=0;
		var h_down_percent=0
		var integer_n=0;
		var decimal_n=0;
	}
	D[G]("hand_up").innerHTML=h_up+" ("+ h_up_percent +"%)";
	if(perc==100){D[G]("hand_up").innerHTML=h_up+" (100%)";}
	D[G]("hand_down").innerHTML=h_down+" ("+ h_down_percent +"%)";
	D[G]("star_blue").style.width=h_up_percent+"%";
	D[G]("star_blue").parentNode.title=integer_n+"."+decimal_n+"分";
	D[G]("integer_unm").innerHTML=integer_n;
	D[G]("decimal_unm").innerHTML="."+decimal_n;
}
//详细页tab切换
function cutOverTab_det(o,idStr){
	o.blur();
	var getAllTab = o.parentNode.getElementsByTagName("a");
	var allTabLen = getAllTab.length+1;
	for(i=1;i<allTabLen;i++){
		getAllTab[i-1].className="";
	}
	o.className="active";
	if(o==getAllTab[0]){
		 D[G](idStr).style.display="none";
	}else{
		D[G](idStr).style.display="block";
	}
}
//跑到锚点
function getScrollIntoView(o,idstr1,idstr2,idstr3,idstr4){
	o.blur();
	if(navigator.userAgent.toLowerCase().indexOf("msie")!= -1){
		D[G](idstr1).scrollTop=D[G](idstr2).offsetTop+D[G](idstr3).offsetTop+60;
	}else{
		D[G](idstr1).scrollTop=D[G](idstr2).offsetTop+D[G](idstr3).offsetTop+320+D[G](idstr4).clientHeight;
	}
}
function goScroll(){
	//document.getElementById(arguments[0]).scrollIntoView();
	window.location.hash=arguments[0];
	document.getElementById('mainBody').scrollTop=document.getElementById('mainBody').scrollTop-25;	
}

///////////////////////////////////////
function evalscript(s) {
	if(s.indexOf('<script') == -1) return s;
	var p = /<script[^\>]*?>([^\x00]*?)<\/script>/ig;
	var arr = [];
	while(arr = p.exec(s)) {
		var p1 = /<script[^\>]*?src=\"([^\>]*?)\"[^\>]*?(reload=\"1\")?(?:charset=\"([\w\-]+?)\")?><\/script>/i;
		var arr1 = [];
		arr1 = p1.exec(arr[0]);
		if(arr1) {
			appendscript(arr1[1], '', arr1[2], arr1[3]);
		} else {
			p1 = /<script(.*?)>([^\x00]+?)<\/script>/i;
			arr1 = p1.exec(arr[0]);
			appendscript('', arr1[2], arr1[1].indexOf('reload=') != -1);
		}
	}
	return s;
}

function appendscript(src, text, reload, charset) {
	var id = hash(src + text);
	//var evalscripts = [];
	//if(!reload && in_array(id, evalscripts)) return;
	//if(reload && document.getElementById(id)) {
		//document.getElementById(id).parentNode.removeChild(document.getElementById(id));
	//}
	//evalscripts.push(id);
	var scriptNode = document.createElement("script");
	scriptNode.type = "text/javascript";
	scriptNode.id = id;
	try {
		if(src) {
			scriptNode.src = src;
		} else if(text){
			scriptNode.text = text;
		}
		document.getElementById('append_parent').appendChild(scriptNode);
	} catch(e) {}
}

function hash(string, length){
	var length = length ? length : 32;
	var start = 0;
	var i = 0;
	var result = '';
	filllen = length - string.length % length;
	for(i = 0; i < filllen; i++){
		string += "0";
	}
	while(start < string.length) {
		result = stringxor(result, string.substr(start, length));
		start += length;
	}
	return result;
}

function stringxor(s1, s2){
	var s = '';
	var hash = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
	var max = Math.max(s1.length, s2.length);
	for(var i=0; i<max; i++) {
		var k = s1.charCodeAt(i) ^ s2.charCodeAt(i);
		s += hash.charAt(k % 52);
	}
	return s;
}
function cltInstalled(){
	var exed=false;
	if(navigator.userAgent.indexOf("MSIE") !=-1){	
		try{
			var cfv = new ActiveXObject("CloudFun.VersionFun2");
			exed=true;
		}
		catch(e){
			try{
				var cfv = new ActiveXObject("CloudFun.VersionFun");
				exed=true;
				/*try{
					cfv.GetVersionComments();
					if(cfv.GetVersionComments()!=1){
						exed=false;
					}else{
						exed=true;
					}			
				}
				catch(e){
					exed=false;
				}*/
			}
			catch(e){
				exed=false;
			}
		}
	}else{
		exed=true;
	}
	return exed;
}
