function Cookie(){
	Cookie.GetCookie = function(name){   
		var arg = name + "=";
		var alen = arg.length;
		var clen = document.cookie.length;
		var i = 0;
		var j = 0;
		while(i < clen){
			j = i + alen;
			if(document.cookie.substring(i, j) == arg)
				return Cookie.GetCookieVal(j);
			i = document.cookie.indexOf(" ", i) + 1;
			if(i == 0) break;
		}
		return null;
	}
	Cookie.GetCookieVal = function(offset) {   
		var endstr = document.cookie.indexOf (";", offset);
		if(endstr == -1) endstr = document.cookie.length;
		return unescape(document.cookie.substring(offset, endstr));
	}
	Cookie.DeleteCookie = function(name) {   
		var exp = new Date();
		var cval = Cookie.GetCookie(name);
		exp.setTime(exp.getTime() - 1);
		document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
	}
	Cookie.SetCookie = function(name, value, days) {
		var path = "/";
		var domain = null;
		var secure = false;
		var expires = new Date();
		Cookie.DeleteCookie(name);
		expires.setTime(expires.getTime() + (days * 86400000));
		document.cookie = name + "=" + value + "; expires=" + expires.toGMTString() + ((domain == null) ? "" : ("; domain=" + domain)) + ((path == null) ? "" : ("; path=" + path)) +  ((secure == true) ? "; secure" : "");
	}
}Cookie();

//设置菜单
function SetPhoneTypeSelect(mainID, expandID, con1, con2, btn_return, btn_jump1, btn_jump2, brandID, typeID, platID){
	var url = "http://www.pandaapp.com/script/download_phoneType.js";
	var charset = "utf-8";
	var cookieDays = 30;
	var typeInfo = [
		{ name:"Windows Mobile", menu:"window mobile", url:"http://download.pandaapp.com/?app=soft&controller=wm&psys=ppc" },
		{ name:"Android", menu:"android", url:"http://download.pandaapp.com/?app=soft&controller=android" },
		{ name:"Symbian", menu:"symbian", url:"http://download.pandaapp.com/?app=soft&controller=s60&psys=3" },
		{ name:"iPhone", menu:"iphone", url:"http://download.pandaapp.com/?app=soft&controller=iphone" }
	];
	
	var script = document.createElement("script"), main = document.getElementById(mainID), expand = document.getElementById(expandID), mobile_info = Cookie.GetCookie("mobile_info"), mobile_url = Cookie.GetCookie("mobile_url"), temp, btn = document.getElementById(btn_return), jump1 = document.getElementById(btn_jump1), jump2 = document.getElementById(btn_jump2), brandID = document.getElementById(brandID), typeID = document.getElementById(typeID), platID = document.getElementById(platID);

	//品牌，机型cookie
	var mobile_brand = Cookie.GetCookie("mobile_brand"), mobile_type = Cookie.GetCookie("mobile_type");	

	con1 = document.getElementById(con1);con2 = document.getElementById(con2);
	if(con1 && con2){
		if(mobile_info && mobile_url && mobile_brand && mobile_type){
			con2.style.display = "block";
			con1.style.display = "none";
			brandID.innerHTML=mobile_brand;
			typeID.innerHTML=mobile_type;
			if (platID) platID.innerHTML=mobile_info;
			for(var i = 0; i < typeInfo.length; i++)
				if(typeInfo[i].name == mobile_info) temp = typeInfo[i];
				
		}else{
			con2.style.display = "none";
			con1.style.display = "block";
		}
	}
	if(btn) btn.onclick = function(){ con2.style.display = "none"; con1.style.display = "block"; Cookie.DeleteCookie("mobile_info"); Cookie.DeleteCookie("mobile_url"); Cookie.DeleteCookie("mobile_brand"); Cookie.DeleteCookie("mobile_type"); }
	if(jump1) jump1.onclick = function(){ if(mobile_url) window.location.href = mobile_url; else alert("Please select your cell phone type"); }
	if(jump2) jump2.onclick = function(){ if(mobile_url) window.location.href = mobile_url; else alert("Please select your cell phone type"); }
	script.setAttribute('type', 'text/javascript');
	script.setAttribute("src", url);
	script.setAttribute("charset", charset);
	function mouseselect(){
		var msg = document.createElement("option");
		msg.innerHTML = "Select type";expand.innerHTML = "";
		expand.appendChild(msg);
		if(!phoneType) return;
		for(var i = 0; i < phoneType.length; i++)
			if(i == this.value){
				for(var k = 0; k < phoneType[i].type.length; k++){
					msg = document.createElement("option");
					msg.value = phoneType[i].type[k].platform;
					msg.innerHTML = phoneType[i].type[k].name;
					expand.appendChild(msg);
				}
				break;
			}
	}
	function expandSelect(){
		if(typeInfo){
			for(var i = 0; i < typeInfo.length; i++)
				if(typeInfo[i].name == this.value){
					temp = typeInfo[i];
					mobile_url = temp.url;
					Cookie.SetCookie("mobile_info", temp.name, cookieDays);
					Cookie.SetCookie("mobile_url", temp.url, cookieDays);
					Cookie.SetCookie("mobile_brand", main.options[main.selectedIndex].text, cookieDays);
					Cookie.SetCookie("mobile_type", expand.options[expand.selectedIndex].text, cookieDays);
				}
		}
	}
	function ajaxCallBack(){
		var state = this.readyState, returnValue, msg = document.createElement("option");
		try{if(!phoneType){ phoneType = null; }}catch(err){ return; }
		main.innerHTML = "";
		msg.innerHTML = "Select brand"; main.appendChild(msg);
		for(var i = 0; i < phoneType.length; i++){
			msg = document.createElement("option")
			msg.value = i;
			msg.innerHTML = phoneType[i].name;
			main.appendChild(msg);
		}
		main.onchange = mouseselect;
		expand.onchange = expandSelect;
	}
	document.getElementsByTagName("head")[0].appendChild(script);
	script.onreadystatechange = ajaxCallBack;
	script.onload = ajaxCallBack;
}

//news share
function social_share(infoTitle){	
	var current_url=encodeURIComponent(window.location.href);
	var str_share='<div class="social_share">';
	str_share+='<ul>';
	str_share+='<li>Bookmark and share to your friends: </li>';
	str_share+='<li><a title="Buzz it" href="http://www.addtoany.com/add_to/google_buzz?linkurl='+current_url+'&linkname='+infoTitle+'"  class="buzz"></a></li>';
	str_share+='<li><a title="Tweet This" href="http://twitter.com/home?status='+infoTitle+' - '+current_url+'" class="twitter"></a></li>';
	str_share+='<li><a title="Sent to Facebook" href="http://www.facebook.com/sharer.php?u='+current_url+'&t= '+infoTitle+'"  class="facebook"></a></li>';
	str_share+='<li><a title="Digg This" href="http://digg.com/submit?url='+current_url+'&title= '+infoTitle+'" class="diggthis"></a></li>';
	str_share+='<li><a title="Delicious" href="http://delicious.com/post?url='+current_url+'&title= '+infoTitle+'" class="delicious"></a></li>';
	str_share+='<li><a title="Stumble" href="http://www.stumbleupon.com/submit?url='+current_url+'&title= '+infoTitle+'" class="stumble"></a></li>';
	str_share+='<li><a title="MySpace" href="http://www.myspace.com/Modules/PostTo/Pages/?u='+current_url+'&t= '+infoTitle+'" class="myspace"></a></li>';
	str_share+='</ul>';
	str_share+='</div>';
	document.writeln(str_share);
}


//选择smile图片
function setFace(face_id)    {document.getElementById('comment_content').value += face_id;   }
   
//显示或收起smile图片
function intosm(smile_btn,smile_con){
		var smile_btn=document.getElementById(smile_btn);
		var intosm=document.getElementById(smile_con);
		var smimg = "";
		for(var i=1;i<=24;i++){
			smimg += "<img onclick=\"setFace('[f=" + i + "]')\" src=\"http://images.pandaapp.com/www/images/comment/" + i + ".gif\">";
		}
		intosm.innerHTML=smimg;
		smile_btn.onclick=function(){
			if (intosm.style.display=="none") intosm.style.display="block"
				else intosm.style.display="none";
			}
}

//星级推荐
function showstar(str1){
	var a1=str1.split(";");
	var num1= a1.length;
	if (a1[num1-1]=="") num1--;
	var str2="";
	for (var i=0; i<num1; i++){
		var a21=a1[i].split(":")[0], a22=parseInt(a1[i].split(":")[1]);
		if(isNaN(a22) || (a22>5) || (a22<1)) a22='0';	
		str2+='<div class="clearfix"><span class="span1 '+a21.split(".")[0]+'" title="'+a21+'"">'+a21+'</span><span class="starbg"><a class="star'+a22+'"></a></span></div>';
	}
	document.write(str2);
}


//网盘下载
function showdownbtn(str1){
	var a1=str1.split(";");
	var num1= a1.length;
	if (a1[num1-1]=="") num1--;
	var str2="";
	for (var i=0; i<num1; i++){
		str2+='<a href="'+a1[i]+'" target="_blank" class="btn_netdisk">Download '+(i+1)+'</a>';
	}
	document.write(str2);
}

//固件支持
function showfirmware(str1){
//	document.write(str1.split(",")[0]);
	document.write((str1.split(",")[0]).split('<br>')[0]);
}

