/*
	[UCenter Home] (C) 2007-2008 Comsenz Inc.
	$Id: script_common.js,v 1.2 2011/04/12 04:21:51 CVSuser Exp $
*/

var userAgent = navigator.userAgent.toLowerCase();
var is_opera = userAgent.indexOf('opera') != -1 && opera.version();
var is_moz = (navigator.product == 'Gecko') && userAgent.substr(userAgent.indexOf('firefox') + 8, 3);
var is_ie = (userAgent.indexOf('msie') != -1 && !is_opera) && userAgent.substr(userAgent.indexOf('msie') + 5, 3);
var is_safari = (userAgent.indexOf('webkit') != -1 || userAgent.indexOf('safari') != -1);
var note_step = 0;
var note_oldtitle = document.title;
var note_timer;
var recommend_score=0;
var recommend2_score=0;
var platform=0;
var recommend_search=0;
var maxnum = 0;
var stopflag = 0;
var timeoutId;
var appdate = new Array();


//iframe包含
if (top.location != location) {
	top.location.href = location.href;
}

function $(id) {
	return document.getElementById(id);
}

function addSort(obj) {
	if (obj.value == 'addoption') {
 	var newOptDiv = document.createElement('div')
 	newOptDiv.id = obj.id+'_menu';
 	newOptDiv.innerHTML = '<h1>添加</h1><a href="javascript:;" onclick="addOption(\'newsort\', \''+obj.id+'\')" class="float_del">删除</a><div class="popupmenu_inner" style="text-align: center;">名称：<input type="text" name="newsort" size="10" id="newsort" class="t_input" /><input type="button" name="addSubmit" value="创建" onclick="addOption(\'newsort\', \''+obj.id+'\')" class="button" /></div>';
 	newOptDiv.className = 'popupmenu_centerbox';
 	newOptDiv.style.cssText = 'position: absolute; left: 50%; top: 200px; width: 400px; margin-left: -200px;';
 	document.body.appendChild(newOptDiv);
 	$('newsort').focus();
 	}
}
	
function addOption(sid, aid) {
	var obj = $(aid);
	var newOption = $(sid).value;
	$(sid).value = "";
	if (newOption!=null && newOption!='') {
		var newOptionTag=document.createElement('option');
		newOptionTag.text=newOption;
		newOptionTag.value="new:" + newOption;
		try {
			obj.add(newOptionTag, obj.options[0]); // doesn't work in IE
		} catch(ex) {
			obj.add(newOptionTag, obj.selecedIndex); // IE only
		}
		obj.value="new:" + newOption;
	} else {
		obj.value=obj.options[0].value;
	}
	// Remove newOptDiv
	var newOptDiv = document.getElementById(aid+'_menu');
	var parent = newOptDiv.parentNode;
	var removedChild = parent.removeChild(newOptDiv);
}

function checkAll(form, name) {
	for(var i = 0; i < form.elements.length; i++) {
		var e = form.elements[i];
		if(e.name.match(name)) {
			e.checked = form.elements['chkall'].checked;
		}
	}
}

function cnCode(str) {
	return is_ie && document.charset == 'utf-8' ? encodeURIComponent(str) : str;
}

function isUndefined(variable) {
	return typeof variable == 'undefined' ? true : false;
}

function in_array(needle, haystack) {
	if(typeof needle == 'string' || typeof needle == 'number') {
		for(var i in haystack) {
			if(haystack[i] == needle) {
					return true;
			}
		}
	}
	return false;
}

function strlen(str) {
	return (is_ie && str.indexOf('\n') != -1) ? str.replace(/\r?\n/g, '_').length : str.length;
}

function getExt(path) {
	return path.lastIndexOf('.') == -1 ? '' : path.substr(path.lastIndexOf('.') + 1, path.length).toLowerCase();
}

function doane(event) {
	e = event ? event : window.event;
	if(is_ie) {
		e.returnValue = false;
		e.cancelBubble = true;
	} else if(e) {
		e.stopPropagation();
		e.preventDefault();
	}
}

//验证码
function seccode() {
	var img = 'do.php?ac=seccode&rand='+Math.random();
	document.writeln('<img id="img_seccode" src="'+img+'" align="absmiddle">');
}
function updateseccode() {
	var img = 'do.php?ac=seccode&rand='+Math.random();
	if($('img_seccode')) {
		$('img_seccode').src = img;
	}
}

//缩小图片并添加链接
function resizeImg(id,size) {
	var theImages = $(id).getElementsByTagName('img');
	for (i=0; i<theImages.length; i++) {
		theImages[i].onload = function() {
			if (this.width > size) {
				this.style.width = size + 'px';
				if (this.parentNode.tagName.toLowerCase() != 'a') {
					var zoomDiv = document.createElement('div');
					this.parentNode.insertBefore(zoomDiv,this);
					zoomDiv.appendChild(this);
					zoomDiv.style.position = 'relative';
					zoomDiv.style.cursor = 'pointer';
					
					this.title = '点击图片，在新窗口显示原始尺寸';
					
					var zoom = document.createElement('img');
					zoom.src = 'image/zoom.gif';
					zoom.style.position = 'absolute';
					zoom.style.marginLeft = size -28 + 'px';
					zoom.style.marginTop = '5px';
					this.parentNode.insertBefore(zoom,this);
					
					zoomDiv.onmouseover = function() {
						zoom.src = 'image/zoom_h.gif';
					}
					zoomDiv.onmouseout = function() {
						zoom.src = 'image/zoom.gif';
					}
					zoomDiv.onclick = function() {
						window.open(this.childNodes[1].src);
					}
				}
			}
		}
	}
}

//Ctrl+Enter 发布
function ctrlEnter(event, btnId, onlyEnter) {
	if(isUndefined(onlyEnter)) onlyEnter = 0;
	if((event.ctrlKey || onlyEnter) && event.keyCode == 13) {
		$(btnId).click();
	}
}
//缩放Textarea
function zoomTextarea(id, zoom) {
	zoomSize = zoom ? 10 : -10;
	obj = $(id);
	if(obj.rows + zoomSize > 0 && obj.cols + zoomSize * 3 > 0) {
		obj.rows += zoomSize;
		obj.cols += zoomSize * 3;
	}
}

//复制URL地址
function setCopy(_sTxt){
	if(is_ie) {
		clipboardData.setData('Text',_sTxt);
		alert ("网址“"+_sTxt+"”\n已经复制到您的剪贴板中\n您可以使用Ctrl+V快捷键粘贴到需要的地方");
	} else {
		prompt("请复制网站地址:",_sTxt); 
	}
}

//验证是否有选择记录
function ischeck(id, prefix) {
	form = document.getElementById(id);
	for(var i = 0; i < form.elements.length; i++) {
		var e = form.elements[i];
		if(e.name.match(prefix) && e.checked) {
			if(confirm("您确定要执行本操作吗？")) {
				return true;
			} else {
				return false;
			}
		}
	}
	alert('请选择要操作的对象');
	return false;
}
function showPreview(val, id) {
	var showObj = $(id);
	if(typeof showObj == 'object') {
		showObj.innerHTML = val.replace(/\n/ig, "<br />");
	}
}

function getEvent() {
	if (document.all) return window.event;
	func = getEvent.caller;
	while (func != null) {
		var arg0 = func.arguments[0];
		if (arg0) {
			if((arg0.constructor==Event || arg0.constructor ==MouseEvent) || (typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation)) {
				return arg0;
			}
		}
		func=func.caller;
	}
	return null;
}
 
function copyRow(tbody) {
	var add = false;
	var newnode;
	if($(tbody).rows.length == 1 && $(tbody).rows[0].style.display == 'none') {
		$(tbody).rows[0].style.display = '';
		newnode = $(tbody).rows[0];
	} else {
		newnode = $(tbody).rows[0].cloneNode(true);
		add = true;
	}
	tags = newnode.getElementsByTagName('input');
	for(i in tags) {
		if(tags[i].name == 'pics[]') {
			tags[i].value = 'http://';
		}
	}
	if(add) {
		$(tbody).appendChild(newnode);
	}
}
	
function delRow(obj, tbody) {
	if($(tbody).rows.length == 1) {
		var trobj = obj.parentNode.parentNode;
		tags = trobj.getElementsByTagName('input');
		for(i in tags) {
			if(tags[i].name == 'pics[]') {
				tags[i].value = 'http://';
			}
		}
		trobj.style.display='none';
	} else {
		$(tbody).removeChild(obj.parentNode.parentNode);
	}
}

function insertWebImg(obj) {
	if(checkImage(obj.value)) {
		insertImage(obj.value);
		obj.value = 'http://';
	} else {
		alert('图片地址不正确');
	}
}

function checkFocus(target) {
	var obj = $(target);
	if(!obj.hasfocus) {
		obj.focus();
	}
}
function insertImage(text) {
	text = "\n[img]" + text + "[/img]\n";
	insertContent('message', text)
}

function insertContent(target, text) {
	var obj = $(target);
	selection = document.selection;
	checkFocus(target);
	if(!isUndefined(obj.selectionStart)) {
		var opn = obj.selectionStart + 0;
		obj.value = obj.value.substr(0, obj.selectionStart) + text + obj.value.substr(obj.selectionEnd);
	} else if(selection && selection.createRange) {
		var sel = selection.createRange();
		sel.text = text;
		sel.moveStart('character', -strlen(text));
	} else {
		obj.value += text;
	}
}

function checkImage(url) {
	var re = /^http\:\/\/.{5,200}\.(jpg|gif|png)$/i
	return url.match(re);
}

function quick_validate(obj) {
    if($('seccode')) {
		var code = $('seccode').value;
		var x = new Ajax();
		x.get('cp.php?ac=common&op=seccode&code=' + code, function(s){
			s = trim(s);
			if(s != 'succeed') {
				alert(s);
				$('seccode').focus();
           		return false;
			} else {
				obj.form.submit();
				return true;
			}
		});
    } else {
    	obj.form.submit();
    	return true;
    }
}

function trim(str) { 
	var re = /\s*(\S[^\0]*\S)\s*/; 
	re.exec(str); 
	return RegExp.$1; 
}
// 停止音乐flash
function stopMusic(preID, playerID) {
	var musicFlash = preID.toString() + '_' + playerID.toString();
	if($(musicFlash)) {
		$(musicFlash).SetVariable('closePlayer', 1);
	}
}
// 显示影视、音乐flash
function showFlash(host, flashvar, obj, shareid) {
	var flashAddr = {
		'youku.com' : 'http://player.youku.com/player.php/sid/FLASHVAR=/v.swf',
		'ku6.com' : 'http://player.ku6.com/refer/FLASHVAR/v.swf',
		'youtube.com' : 'http://www.youtube.com/v/FLASHVAR',
		'5show.com' : 'http://www.5show.com/swf/5show_player.swf?flv_id=FLASHVAR',
		'sina.com.cn' : 'http://vhead.blog.sina.com.cn/player/outer_player.swf?vid=FLASHVAR',
		'sohu.com' : 'http://v.blog.sohu.com/fo/v4/FLASHVAR',
		'mofile.com' : 'http://tv.mofile.com/cn/xplayer.swf?v=FLASHVAR',
		'music' : 'FLASHVAR',
		'flash' : 'FLASHVAR'
	};
	var flash = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="480" height="400">'
	    + '<param name="movie" value="FLASHADDR" />'
	    + '<param name="quality" value="high" />'
	    + '<param name="bgcolor" value="#FFFFFF" />'
	    + '<embed width="480" height="400" menu="false" quality="high" src="FLASHADDR" type="application/x-shockwave-flash" />'
	    + '</object>';
	var videoFlash = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="480" height="450">'
        + '<param value="transparent" name="wmode"/>'
		+ '<param value="FLASHADDR" name="movie" />'
		+ '<embed src="FLASHADDR" wmode="transparent" allowfullscreen="true" type="application/x-shockwave-flash" width="480" height="450"></embed>'
		+ '</object>';
	var musicFlash = '<object id="audioplayer_SHAREID" height="24" width="290" data="image/player.swf" type="application/x-shockwave-flash">'
		+ '<param value="image/player.swf" name="movie"/>'
		+ '<param value="autostart=yes&bg=0xCDDFF3&leftbg=0x357DCE&lefticon=0xF2F2F2&rightbg=0xF06A51&rightbghover=0xAF2910&righticon=0xF2F2F2&righticonhover=0xFFFFFF&text=0x357DCE&slider=0x357DCE&track=0xFFFFFF&border=0xFFFFFF&loader=0xAF2910&soundFile=FLASHADDR" name="FlashVars"/>'
		+ '<param value="high" name="quality"/>'
		+ '<param value="false" name="menu"/>'
		+ '<param value="#FFFFFF" name="bgcolor"/>'
	    + '</object>';
	var musicMedia = '<object height="64" width="290" data="FLASHADDR" type="audio/x-ms-wma">'
	    + '<param value="FLASHADDR" name="src"/>'
	    + '<param value="1" name="autostart"/>'
	    + '<param value="true" name="controller"/>'
	    + '</object>';
	var flashHtml = videoFlash;
	var videoMp3 = true;
	if('' == flashvar) {
		alert('音乐地址错误，不能为空');
		return false;
	}
	if('music' == host) {
		var mp3Reg = new RegExp('.mp3$', 'ig');
		var flashReg = new RegExp('.swf$', 'ig');
		flashHtml = musicMedia;
		videoMp3 = false
		if(mp3Reg.test(flashvar)) {
			videoMp3 = true;
			flashHtml = musicFlash;
		} else if(flashReg.test(flashvar)) {
			videoMp3 = true;
			flashHtml = flash;
		}
	}
	flashvar = encodeURI(flashvar);
	if(flashAddr[host]) {
		var flash = flashAddr[host].replace('FLASHVAR', flashvar);
		flashHtml = flashHtml.replace(/FLASHADDR/g, flash);
		flashHtml = flashHtml.replace(/SHAREID/g, shareid);
	}
	
	if(!obj) {
		$('flash_div_' + shareid).innerHTML = flashHtml;
		return true;
	}
	if($('flash_div_' + shareid)) {
		$('flash_div_' + shareid).style.display = '';
		$('flash_hide_' + shareid).style.display = '';
		obj.style.display = 'none';
		return true;
	}
	if(flashAddr[host]) {
		var flashObj = document.createElement('div');
		flashObj.id = 'flash_div_' + shareid;
		obj.parentNode.insertBefore(flashObj, obj);
		flashObj.innerHTML = flashHtml;
		obj.style.display = 'none';
		var hideObj = document.createElement('div');
		hideObj.id = 'flash_hide_' + shareid;
		var nodetxt = document.createTextNode("收起");
		hideObj.appendChild(nodetxt);
		obj.parentNode.insertBefore(hideObj, obj);
		hideObj.style.cursor = 'pointer';
		hideObj.onclick = function() {
			if(true == videoMp3) {
				stopMusic('audioplayer', shareid);
				flashObj.parentNode.removeChild(flashObj);
				hideObj.parentNode.removeChild(hideObj);
			} else {
				flashObj.style.display = 'none';
				hideObj.style.display = 'none';
			}
			obj.style.display = '';
		}
	}
}

//显示全部应用
function userapp_open() {
	var x = new Ajax();
	x.get('cp.php?ac=common&op=getuserapp', function(s){
		$('my_userapp').innerHTML = s;
		$('a_app_more').className = 'on';
		$('a_app_more').innerHTML = '收起';
		$('a_app_more').onclick = function() {
			userapp_close();
		}
	});
}

//关闭全部应用
function userapp_close() {
	var x = new Ajax();
	x.get('cp.php?ac=common&op=getuserapp&subop=off', function(s){
		$('my_userapp').innerHTML = s;
		$('a_app_more').className = 'off';
		$('a_app_more').innerHTML = '展开';
		$('a_app_more').onclick = function() {
			userapp_open();
		}
	});
}

//滚动
function startMarquee(h, speed, delay, sid) {
	var t = null;
	var p = false;
	var o = $(sid);
	o.innerHTML += o.innerHTML;
	o.onmouseover = function() {p = true}
	o.onmouseout = function() {p = false}
	o.scrollTop = 0;
	function start() {
	    t = setInterval(scrolling, speed);
	    if(!p) {
			o.scrollTop += 2;
		}
	}
	function scrolling() {
	    if(p) return;
		if(o.scrollTop % h != 0) {
	        o.scrollTop += 2;
	        if(o.scrollTop >= o.scrollHeight/2) o.scrollTop = 0;
	    } else {
	        clearInterval(t);
	        setTimeout(start, delay);
	    }
	}
	setTimeout(start, delay);
}

function readfeed(obj, id) {
	if(Cookie.get("read_feed_ids")) {
		var fcookie = Cookie.get("read_feed_ids");
		fcookie = fcookie + ',' + id;
	} else {
		var fcookie = id;
	}
	Cookie.set("read_feed_ids", fcookie, 120);
	obj.className = 'feedread';
}

function close_action() {
	try {
	var elemButtonWant = document.getElementById("anthor_want");
	elemButtonWant.className = "anthor_h";
	}
	catch(e) {}
	try {
	var elemButtonUsing = document.getElementById("anthor_using");
	elemButtonUsing.className = "anthor_h";
	}
	catch(e) {}
	try {
	var elemButtonUsed = document.getElementById("anthor_used");
	elemButtonUsed.className = "anthor_h";
	}
	catch(e) {}
	try{
	var elemButtonCollect = document.getElementById("anthor_collect");
	elemButtonCollect.className = "anthor_h";
	}
	catch(e) {}
}

function createXMLHTTP() {
		var request = false;
		if(window.XMLHttpRequest) {
			request = new XMLHttpRequest();
			if(request.overrideMimeType) {
				request.overrideMimeType('text/xml');
			}
		} else if(window.ActiveXObject) {
			var versions = ['Microsoft.XMLHTTP', 'MSXML.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.7.0', 'Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.5.0', 'Msxml2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP'];
			for(var i=0; i<versions.length; i++) {
				try {
					request = new ActiveXObject(versions[i]);
					if(request) {
						return request;
					}
				} catch(e) {}
			}
		}
		return request;
}
/*
function Send_Request(url) {
	var http_req = createXMLHTTP();
	http.open("GET", url + '&random=' +  Math.random()*99999, true);
	http_req.onreadystatechange = processRequest;
	http_req.send(null);
}
*/

function processRequest_list() {	
	if(http.readyState == 4) {
		if(http.status == 200) {
			showloading('none');
			var ResponseStr = http.responseText;
			document.getElementById("avatar_list").innerHTML = ResponseStr;
		}
	}
}

function processRequestStar() {	
	if(http.readyState == 4) {
		if(http.status == 200) {
			showloading('none');
			recommend_score=0;
			var ResponseStr = http.responseText;
			if( ResponseStr == "login") {
				if(confirm("你没有登陆，现在登陆吗？")){
						window.location.href="do.php?ac=4bb1ddc1e885fc0dd609a11c9f1632ef";
					}
			}
			else {
				document.getElementById("dialog").innerHTML = ResponseStr;
			}
		}
	}
}

function processRequest() {	
	if(http.readyState == 4) {
		if(http.status == 200) {
			showloading('none');
			var ResponseStr = http.responseText;
			switch (ResponseStr)
			{
				case "login":
					if(confirm("你没有登陆，现在登陆吗？")){
						window.location.href="do.php?ac=4bb1ddc1e885fc0dd609a11c9f1632ef";
					}
					break;
				case "want":
					//var status = document.getElementById("status");			
					//document.getElementById("action_text").innerHTML = "我想用这个App";
					//status.className = "status";
					//var action = document.getElementById("action");
					//action.className = "action_h";
					//document.getElementById("score").innerHTML = "";
					document.getElementById("want").innerHTML = "";
					break;
				case "used":
					var status = document.getElementById("status");
					document.getElementById("action_text").innerHTML = "我用过这个App";
					status.className = "status";
					var action = document.getElementById("action");
					action.className = "action_h";
					if(recommend_score!=0) {
						document.getElementById("score").innerHTML = "你的评分："+recommend_score*2;					
					}
					else {
						document.getElementById("score").innerHTML = "";
					}
					break;
				case "collect":
					//var status = document.getElementById("status");
					//document.getElementById("action_text").innerHTML = "我收藏了这个App";
					//status.className = "status";
					//var action = document.getElementById("action");
					//action.className = "action_h";
					//document.getElementById("score").innerHTML = "";
					document.getElementById("collect").innerHTML = "";
					break;
				default:
					//document.writeln(ResponseStr);
			}
			alert("感谢您对funso的支持！您已获得了相应的积分。");		
		}
		else {
			return "error";
		}
	}
}

	var http = createXMLHTTP();
	var httpprice = new Array();



function appStatusOwnIt(appid,star) {
	showloading();
	if(star>=1 && star<=5 && recommend2_score!=0)
		recommend_score=star;
	var url ='do.php?ac=ajax&op=appStatusOwnIt&appid=' + appid +"&score="+recommend_score;
	http.open("GET", url + '&random=' +  Math.random()*99999, true);
	http.onreadystatechange = processRequest_list;
	http.send(null);
	close_action();
	var status = document.getElementById("status");
	document.getElementById("action_text").innerHTML = "我在用这个App";
	status.className = "status";
	var action = document.getElementById("action");
	action.className = "action_h";
	if(recommend_score!=0) {
		document.getElementById("score").innerHTML = "你的评分："+recommend_score*2;					
	}
	else {
		document.getElementById("score").innerHTML = "";
	}					
}

function processRequest_recommend() {	
	if(http.readyState == 4) {
		if(http.status == 200) {
			showloading('none');
			var ResponseStr = http.responseText;
			document.getElementById("recommend").innerHTML = ResponseStr;
		}
	}
}

function recommend(appid) {
	showloading();
	var url ='do.php?ac=ajax&op=recommend&appid=' + appid;
	http.open("GET", url + '&random=' +  Math.random()*99999, true);
	http.onreadystatechange = processRequest_recommend;
	http.send(null);
}

function processRequest_cracklist() {	
	if(http.readyState == 4) {
		if(http.status == 200) {
			showloading('none');
			var ResponseStr = http.responseText;
			document.getElementById("cracklist").innerHTML = ResponseStr;
		}
	}
}

function closeCrackList() {
	document.getElementById("cracklist").innerHTML = "";
}

function processRequest_newfreeapp() {	
	if(http.readyState == 4) {
		if(http.status == 200) {
			showloading('none');
			var ResponseStr = http.responseText;
			document.getElementById("price").innerHTML = ResponseStr;
		}
	}
}

function cracklist(appid) {
	showloading();
	var url ='do.php?ac=ajax&op=cracklist&appid=' + appid;
	http.open("GET", url + '&random=' +  Math.random()*99999, true);
	http.onreadystatechange = processRequest_cracklist;
	http.send(null);
}

function delCrack(urlid,appid) {
	if(confirm("确定要删除这条地址吗？")) {
		showloading();
		var url ='do.php?ac=ajax&op=delCrack&urlid='+urlid+'&appid='+appid;
		http.open("GET", url + '&random=' +  Math.random()*99999, true);
		http.onreadystatechange = processRequest_cracklist;
		http.send(null);
	}
}

function adminEditCrackerUrl(urlid,appid){
	
	var crackerVersion = document.getElementById("crackerversion_"+urlid ).value;
	var crackerUrl = document.getElementById("crackerurl_"+urlid).value;
	if(crackerVersion==''){
		alert("版本信息不能为空！请认真填写。");
		exit(0);
	}else if(crackerUrl==''){
		alert("破解地址信息不能为空！请认真填写。");
		exit(0);
	}
	var myurl = "iApp.php?do=editCrackerUrl";
	var myRand = parseInt(Math.random()*999999999999999);
	var modurl = myurl+"&rand="+myRand;
	crackerUrl=crackerUrl.replace(/\&/g,"%26");
	http.open("POST",modurl,true);
	
	http.onreadystatechange = processRequest_cracklist;
	http.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	http.send("appid="+appid+"&urlid="+urlid+"&version="+crackerVersion+"&url="+crackerUrl);
}

function newfreeapp(price,newprice,appid){
	showloading();
	var url ='do.php?ac=ajax&op=newfreeapp&appid=' + appid + "&price=" + price + "&newprice=" + newprice;
	http.open("GET", url + '&random=' +  Math.random()*99999, true);
	http.onreadystatechange = processRequest_newfreeapp;
	http.send(null);
}

function appStatusWantIt(appid) {
	showloading();
	var url ='do.php?ac=ajax&op=appStatusWantIt&appid=' + appid;
	http.open("GET", url + '&random=' +  Math.random()*99999, true);
	http.onreadystatechange = processRequest;
	http.send(null);
	close_action();
}

function appStatusUsed(appid) {
	showloading();
	var url ='do.php?ac=ajax&op=appStatusUsed&appid=' + appid +"&score="+recommend_score;
	http.open("GET", url + '&random=' +  Math.random()*99999, true);
	http.onreadystatechange = processRequest;
	http.send(null);	
	close_action();
}

function want(appid) {
	showloading();
	var url ='do.php?ac=ajax&op=checklongin&next=want&appid=' + appid;
	http.open("GET", url + '&random=' +  Math.random()*99999, true);
	http.onreadystatechange = processRequestStar;
	http.send(null);
}

function using(appid) {
	showloading();
	var url ='do.php?ac=ajax&op=checklongin&next=using&appid=' + appid;
	http.open("GET", url + '&random=' +  Math.random()*99999, true);
	http.onreadystatechange = processRequestStar;
	http.send(null);
}

function ownstarrate(star,appid) {
	showloading();
	recommend2_score=star;
	var url ='do.php?ac=ajax&op=checklongin&next=using&appid=' + appid +'&star='+star;
	http.open("GET", url + '&random=' +  Math.random()*99999, true);
	http.onreadystatechange = processRequestStar;
	http.send(null);
}

function used(appid) {
	showloading();
	var url ='do.php?ac=ajax&op=checklongin&next=used&appid=' + appid;
	http.open("GET", url + '&random=' +  Math.random()*99999, true);
	http.onreadystatechange = processRequestStar;
	http.send(null);
}

//收藏
function collect(appid){
	showloading();
	var url ='do.php?ac=ajax&op=checklongin&next=collect&appid=' + appid;
	http.open("GET", url + '&random=' +  Math.random()*99999, true);
	http.onreadystatechange = processRequestStar;
	http.send(null);
}
 
function appStatusCollectIt(appid){
	showloading();
	var url ='do.php?ac=ajax&op=appStatusCollectIt&appid=' + appid;
	http.open("GET", url + '&random=' +  Math.random()*99999, true);
	http.onreadystatechange = processRequest;
	http.send(null);
	close_action();
}

function getaction(action) {
	if(action == 1) {
			document.getElementById("action_text").innerHTML = "我在用这个App";
			
	}
	if(action == 2) {
			document.getElementById("action_text").innerHTML = "我想用这个App";
			
	}
	if(action == 3) {
			document.getElementById("action_text").innerHTML = "我用过这个App";
		
	}
	if(action == 4) {
		document.getElementById("action_text").innerHTML = "我收藏了这个App";
	
	}
}

function delaction(appid,action) {
	if(confirm("确定要删除记录吗？")){
		showloading();
		var url ='do.php?ac=ajax&op=delaction&appid=' + appid+'&action='+action;
		http.open("GET", url + '&random=' +  Math.random()*99999, true);
		http.onreadystatechange = processRequest_list;
		http.send(null);
		close_action();	
		var status = document.getElementById("status");
		status.className = "status_s";
		var action = document.getElementById("action");
		action.className = "action";

	}
}

function processRequest_space_list() {	
	if(http.readyState == 4) {
		if(http.status == 200) {
			showloading('none');
			var ResponseStr = http.responseText;
			window.location.reload();
		}
	}
}

function space_delaction(appid,myapp) {
	if(confirm("确定要删除记录吗？")){
		showloading();
		var url ='do.php?ac=ajax&op=delaction&appid='+appid+'&action='+myapp;
		http.open("GET", url + '&random=' +  Math.random()*99999, true);
		http.onreadystatechange = processRequest_space_list;
		http.send(null);
		close_action();	
	}
}

function starico(star,id) {
	id=id.substring(0,id.length-1);
	for(var i=1;i<=star;i++) {
		if( id == "star" ||  id == "fstar") {
			try {
				var status = document.getElementById(id+i);
				status.setAttribute("src","image/sth.gif");
			}
			catch(e) {}
		}
	}
}

function staricoout(id) {
	id=id.substring(0,id.length-1);
	for(var i=1;i<=5;i++) {
		if( id == "star" ||  id == "fstar") {
			try {
				var status = document.getElementById(id+i);
				status.setAttribute("src","image/nst.gif");
			}
			catch(e) {}
		}
	}
}

function starrate(star) {
	recommend2_score=0;
	recommend_score=star;
	for(var i=1;i<=5;i++) {
			try {
				var status = document.getElementById("star"+i);
				status.setAttribute("src","image/nst.gif");
			}
			catch(e) {
				var status = document.getElementById("stared"+i);
				status.setAttribute("id","star"+i);
				status.setAttribute("src","image/nst.gif");				
			}	
	}

	for(var i=1;i<=star;i++) {
			var status = document.getElementById("star"+i);
			status.setAttribute("id","stared"+i);
			status.setAttribute("src","image/sth.gif");
	}
}



//首页中不同分类应用数据ajax请求
function searchrecommend() {
	//document.getElementById("showloadingpic").style.display = "";
	//	document.getElementById("appdetails").style.display = "none";
		
		var url ='do.php?ac=ajax&op=searchrecommend&platform=' + platform +'&search=' + recommend_search;
		http.open("GET", url + '&random=' +  Math.random()*99999, false);
		http.onreadystatechange = processRequest_search;
		http.send(null);
}
//首页中不同分类应用数据回调函数
function processRequest_search() {	
	if(http.readyState == 4) {
		if(http.status == 200) {
			
			var ResponseStr = http.responseText;
		//	document.getElementById("showloadingpic").style.display = "none";
		//	document.getElementById("appdetails").style.display = "";
			document.getElementById("appdetails").innerHTML = ResponseStr;
		}
	}
}

//首页中不同应用平台选择函数
function pop_iPhoneAppSelectShow() {
	platform=0;
	document.getElementById("iPad_AppSelect").className = "";
	document.getElementById("mac_AppSelect").className = "";
	document.getElementById("iPhone_AppSelect").className = "here";
		searchrecommend();

	
}

function pop_iPadAppSelectShow() {
	platform=1;
	document.getElementById("iPad_AppSelect").className = "here";
	document.getElementById("mac_AppSelect").className = "";
	document.getElementById("iPhone_AppSelect").className = "";
		searchrecommend();

}

function pop_macAppSelectShow() {
	platform=2;
	document.getElementById("iPad_AppSelect").className = "";
	document.getElementById("mac_AppSelect").className = "here";
	document.getElementById("iPhone_AppSelect").className = "";
		searchrecommend();

}
//首页中不同应用类型选择函数
function NewAppSelectShow() {
	recommend_search=0;
	document.getElementById("Rise_AppSelect").className = "";
	document.getElementById("New_AppSelect").className = "here";
	document.getElementById("Rebate_AppSelect").className = "";
		searchrecommend();

}

function RiseAppSelectShow() {
	recommend_search=1;
	document.getElementById("Rise_AppSelect").className = "here";
	document.getElementById("New_AppSelect").className = "";
	document.getElementById("Rebate_AppSelect").className = "";
		searchrecommend();

}

function RebateAppSelectShow() {
	recommend_search=2;
	document.getElementById("Rise_AppSelect").className = "";
	document.getElementById("New_AppSelect").className = "";
	document.getElementById("Rebate_AppSelect").className = "here";
		searchrecommend();

}

//调用登录信息登录cms

function loginCMS(){
	
	var dopost = "login";
	
	var userid = document.getElementById("username").value;
	
	var pwd = document.getElementById("password").value;
	var myurl = "http://www.funso.com/uploads/member/uc_login_cms.php?";
	var myRand = parseInt(Math.random()*999999999999999);
	var modurl = myurl+"rand="+myRand;
	
	http.open("POST",modurl,true);
	
	http.onreadystatechange = recOption;
	
	http.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	
	http.send("dopost="+dopost+"&userid='"+userid+"'&pwd='"+pwd+"'");
}

function test(){
	alert("OK");
}

function recOption(){
	if(http.readyState == 4){
		if(http.status == 200){
			var mytext = http.responseText;
			
		}
	}
}

function showcommentedit (showid) {
		var from=getElementsByClassName("quickpost");
		for(var i=0;from[i];i++)
		{
			from[i].style.display= 'none';
		}
		from=getElementsByClassName("comments_box");
		for(i=0;from[i];i++)
		{
			from[i].style.display= 'block';
		}
		from=getElementsByClassName("reply");
		for(i=0;from[i];i++)
		{
			from[i].style.display= 'none';
		}
		from=getElementsByClassName("rebut");
		for(i=0;from[i];i++)
		{
			from[i].style.display= 'block';
		}
		$('quickcommentbut_'+showid).style.display = 'none';
		$('quickcommentform_'+showid).style.display = 'block';
		document.getElementById("comment_message_"+showid).focus();
}

function hidecommentedit (showid) {
		$('quickcommentbut_'+showid).style.display = 'block';
		$('quickcommentform_'+showid).style.display = 'none';
		document.getElementById("comment_message_"+showid).value="";
}


function showreply (cid,id,formhash) {
		var from=getElementsByClassName("quickpost");
		for(var i=0;from[i];i++)
		{
			from[i].style.display= 'none';
		}
		from=getElementsByClassName("comments_box");
		for(i=0;from[i];i++)
		{
			from[i].style.display= 'block';
		}
		from=getElementsByClassName("reply");
		for(i=0;from[i];i++)
		{
			from[i].style.display= 'none';
		}
		from=getElementsByClassName("rebut");
		for(i=0;from[i];i++)
		{
			from[i].style.display= 'block';
		}
	      	document.getElementById("c_"+cid+"_reply").style.display= 'none';
 var htmltext ="<div class=\"feeds_comment_v2 currentItem\" style=\"display:block\" ><div class=\"f_ang f_ang_t bor_bg2\"></div><div class=\"mod_commnets_poster bg2 currentItem\"><div class=\"comments_poster_bd comments_poster_default\"><form id=\"reply_commentform_{$cid}\" name=\"reply_commentform_{$cid}\" method=\"post\" action=\"cp.php?ac=comment\"><table><tr><td><label for=\"message\">回复：</label><a href=\"###\" id=\"replyface_{$cid}\" onclick=\"showFace(this.id, 'message_pop_{$cid}');\"><img src=\"image/facelist.gif\" align=\"absmiddle\" /></a><br /><textarea id=\"message_pop_{$cid}\" name=\"message\" onkeydown=\"ctrlEnter(event, 'commentsubmit_btn');\" rows=\"3\" style=\"width:320px;\"></textarea></td></tr><tr><td><input type=\"hidden\" name=\"refer\" value=\""+document.URL+"\" /><input type=\"hidden\" name=\"id\" value=\"$id\"><input type=\"hidden\" name=\"idtype\" value=\"feedid\"><input type=\"hidden\" name=\"cid\" value=\"{$cid}\" /><input type=\"hidden\" name=\"commentsubmit\" value=\"true\" /><input type=\"button\" name=\"commentsubmit_btn\" id=\"commentsubmit_btn\" value=\"回复\" class=\"submit\" onclick=\"ajaxpost('reply_commentform_{$cid}', '$id', 'comment_add_feed');closereply();\" /><a href=\"\" class=\"editcancel\" onclick=\"closereply();return false;\">取消</a></td></tr></table><input type=\"hidden\" name=\"formhash\" value=\""+formhash+"\" /></form></div></div></div></div>";
			htmltext=htmltext.replace(/\{\$cid\}/g,cid);
			htmltext=htmltext.replace(/\$id/g,id);
			var status = document.getElementById("comment_"+cid+"_li");
			if( status.lastChild.id == "reply_"+cid ){
				status.removeChild(status.lastChild);
			}
				var div = document.createElement("div");
				div.setAttribute("id","reply_"+cid);
				div.style.display= 'block';
				//div.setAttribute("class","showreply");
				div.className="reply";
				div.innerHTML = htmltext;
				status.appendChild(div);
			document.getElementById("message_pop_"+cid).focus();
}

function closereply () {
		var from=getElementsByClassName("quickpost");
		for(var i=0;from[i];i++)
		{
			from[i].style.display= 'none';
		}
		from=getElementsByClassName("comments_box");
		for(i=0;from[i];i++)
		{
			from[i].style.display= 'block';
		}
		from=getElementsByClassName("reply");
		for(i=0;from[i];i++)
		{
			from[i].style.display= 'none';
		}
		from=getElementsByClassName("rebut");
		for(i=0;from[i];i++)
		{
			from[i].style.display= 'block';
		}
}

function getElementsByClassName(className, parentElement){
var elems = ($(parentElement)||document.body).getElementsByTagName("*");
var result=[];
for (i=0; j=elems[i]; i++){
  if ((" "+j.className+" ").indexOf(" "+className+" ")!=-1){
   result.push(j);
  }
}
return result;
}

function loadScript(url) {
	var script = document.createElement("script");
	script.type="text/javascript";
	script.src=url;
	document.body.appendChild(script);
}

function getdate(text)
{
	//汇率转换
	var p=0;
	while(priceCN[p]){
		if(text.results[0]["price"]==priceCN[p]){
			text.results[0]["price"] = priceUS[p];
			break;
		}
		else
			p++;
	}
	var appid = document.getElementById("appid").firstChild.nodeValue;
	var oprice = document.getElementById("new_price").firstChild.nodeValue;
	if(text.results[0].price != oprice) {
		if(confirm(oprice+"->"+text.results[0].price+"价格变化！是否立即更新?")) {
			newfreeapp(oprice,text.results[0].price,appid);
		}
	}
	else {
		alert("价格没有变化");	
	}
	//alert("<p>"+text.results[0].price+"</p>"); 
}

function showcomment( id )
{
	jq('#comment_ul_'+id+'_h').slideToggle('nomal');
	jq('#morecomments_'+id).hide();
}

function crawlStart(maxnum_t)
{
	timeoutId = setTimeout(function(){
		document.getElementById('appnum').textContent  = (parseInt(document.getElementById('appnum').textContent) + maxnum); 
		crawlStart(maxnum);
	},120000);
		while(document.getElementById('script').firstChild)
			document.getElementById('script').removeChild(document.getElementById('script').firstChild);	
		httpprice=null;
		httpprice= new Array();
		appdate = null;
		appdate = new Array()
		var progressBar = document.getElementById('p');
		progressBar.value=0;
		document.getElementById('start').disabled=true;
		document.getElementById('stop').disabled=false;
		while(document.getElementById('re_note').firstChild)
			document.getElementById('re_note').removeChild(document.getElementById('re_note').firstChild);
		progressBar.getElementsByTagName('span')[0].textContent=0;	
		showloading();
		maxnum=maxnum_t;
		var url ='do_crawl.php?checkNum='+maxnum_t;
		http.open("GET", url + '&random=' +  Math.random()*99999, true);
		http.onreadystatechange = processRequest_crawl;
		http.send(null);
}


function processRequest_crawl() {	
	if(http.readyState == 4) {
		if(http.status == 200) {
			showloading('none');
			var ResponseStr = http.responseText;
			var flag_temp  = eval(ResponseStr);		
			intiProgress_n(flag_temp[0]['flag']);
			var date = null;
			date = flag_temp[1];
			for(var i=0;date[i];i++) 
			{
				appdate[date[i]['linkid']]=date[i]['price'];
				update(date[i]['linkid'],date[i]['price']);
			}

		}
	}
}

function updateProgress()
{
	var progressBar = document.getElementById('p');
	progressBar.value = progressBar.value+1;
	//alert(progressBar.value);
	progressBar.getElementsByTagName('span')[0].textContent = progressBar.value;
	if(progressBar.value>=maxnum)
	{
		clearTimeout(timeoutId);
		document.getElementById('appnum').textContent  = (parseInt(document.getElementById('appnum').textContent) + maxnum); 
			if(stopflag==0) {		
				crawlStart(maxnum);
			}
			else {
				stopflag=0;
				document.getElementById('start').disabled=false;
				document.getElementById('stop').disabled=true;
				document.getElementById('re_note').textContent = '程序已终止';
			}
	}
}

function getProgress()
{
	var progressBar = document.getElementById('p');
	return progressBar.value;
}


function intiProgress_n(flag_temp)
{
	//alert(flag_temp);
	var progressBar = document.getElementById('p_n');
	progressBar.value = flag_temp;
	//alert(progressBar.value);
	progressBar.getElementsByTagName('span')[0].textContent =flag_temp;
}

function updateProgress_n()
{
	
	var progressBar = document.getElementById('p_n');
	progressBar.value = progressBar.value+1;
	//alert(progressBar.value);
	progressBar.getElementsByTagName('span')[0].textContent = progressBar.value;
}

function update(linkid,price)
{
	appid = linkid;
	oprice = price;
	var url='http://itunes.apple.com/lookup?id='+linkid+'&callback=getCrawlDate';
	var script = document.createElement("script");
	script.type="text/javascript";
	script.src=url;
	//document.body.appendChild(script);
	//if(document.getElementById('script').firstChild)
	//	document.getElementById('script').removeChild(document.getElementById('script').firstChild);
	document.getElementById('script').appendChild(script);
}

function crawlLoadScript(url) {
	var script = document.createElement("script");
	script.type="text/javascript";
	script.src=url;
	document.body.appendChild(script);
}

function getCrawlDate(text)
{
	if(text.results[0]) {
		//if(text.results[0].price != oprice) {
			//if(confirm(text.results[0].trackId+":"+oprice+"->"+text.results[0].price+"价格变化！是否立即更新?")) {
			//text.results[0].price=priceLib[text.results[0].price];
			/*
			for(var i=0;priceCN[i];i++)
			{
				if(priceCN[i]==text.results[0].price)
					text.results[0].price=priceUS[i];
			}
			*/
		
			if(text.results[0].price != appdate[text.results[0].trackId]) {
				//if(confirm("AppID"+text.results[0].trackId+":"+appdate[text.results[0].trackId]+"->"+text.results[0].price+"价格变化！是否立即更新?")) {
					document.getElementById('price').textContent = "AppID["+text.results[0].trackId+"]: $"+appdate[text.results[0].trackId]+" -> $"+text.results[0].price;
					priceRecord(text.results[0].price,text.results[0].trackId);
				//}
			}

							
			//}
		//}
	}
	//updateProgress_n();
	updateProgress();
}

function priceRecord(price,appid){
	//showloading();
	var i = getProgress();
	httpprice[i] = createXMLHTTP();
	var url ='do_price.php?appid=' + appid + "&newprice=" + price;
	httpprice[i].open("GET", url + '&random=' +  Math.random()*99999, true);
	httpprice[i].onreadystatechange = processRequest_priceRecord;
	httpprice[i].send(null);
}

function processRequest_priceRecord()
{
	if(http.readyState == 4) {
		if(http.status == 200) {
			//showloading('none');
			//updateProgress_n();
		}
		else
		{
			alert('error');
		}
	}

}
function crawlStop()
{
	stopflag=1;
	document.getElementById('re_note').textContent = '本次抓取完成后程序会自动终止';
}

function input_onfocus(event){
	if(event.value=='搜索朋友'||event.value=='搜索应用'){
		event.value = '';
	}
}

function input_onblur(event){
	if(event.value==''){
		if(event.name=='username'){
			event.velue='搜索朋友';
		}else if(event.name=='search'){
			event.value='搜索应用';
		}
	}
}

function newapp(){
	var flag=document.getElementById("flag").value;
	var id=document.getElementById("appid").value
	if(!id)
	{
		alert("请输入查询关键字");
		return;
	}
	if(flag=="id" && isNaN(id))
	{
		alert("id必须为数字");
		return;
	}
	document.getElementById('loadingIco').style.display="inline";
	
	addNewapp(id,flag);
}

function addNewapp(linkid,flag)
{
	//alert(linkid);
	linkid =  linkid.replace(/(^\s*)|(\s*$)/g, ""); 
	while(document.getElementById('script').firstChild)
		document.getElementById('script').removeChild(document.getElementById('script').firstChild);	
	if(flag=="id")
		var url='http://itunes.apple.com/lookup?id='+linkid+'&country=cn&callback=getNewapplDate';
	if(flag=="name")
		var url='http://itunes.apple.com/search?term='+linkid+'&country=cn&entity=software&callback=getNewapplDate';
	var script = document.createElement("script");
	script.type="text/javascript";
	script.src=encodeURI(url);
	//document.body.appendChild(script);
	//if(document.getElementById('script').firstChild)
	//	document.getElementById('script').removeChild(document.getElementById('script').firstChild);
	document.getElementById('script').appendChild(script);
	script.onerror=function () {alert("iTunes访问异常，数据抓取失败！");document.getElementById('loadingIco').style.display="none";};
}


function getNewapplDate(text)
{
			//类别字典
		var kindLab={"lifestyle":"生活",
			"finance":"财务",
			"business":"商业",
			"entertainment":"娱乐",
			"photo":"摄影与录像",
			"medical":"医疗",
			"productivity":"效率",
			"utilities":"工具",
			"sports":"体育",
			"music":"音乐",
			"newsstand":"报刊杂志",
			"books":"图书",
			"book":"图书",
			"games":"游戏",
			"news":"新闻",
			"weather":"天气",
			"health":"健康健美",
			"education":"教育",
			"navigation":"导航",
			"travel":"旅行",
			"reference":"参考",
			"social":"社交"}
		//语言字典
		var languageLab=
			{"gv":"马恩岛语",
			"gu":"古吉拉特语",
			"gd":"苏格兰盖尔语",
			"ga":"爱尔兰语",
			"gn":"瓜拉尼语",
			"gl":"加利西亚语",
			"lg":"干达语",
			"lb":"卢森堡语",
			"la":"拉丁语",
			"ln":"林加拉语",
			"lo":"老挝语",
			"tt":"塔塔尔语",
			"tr":"土耳其语",
			"ts":"宗加语",
			"li":"林堡语",
			"lv":"拉脱维亚语",
			"to":"汤加语",
			"lt":"立陶宛语",
			"lu":"卢巴-加丹加语",
			"tk":"土库曼语",
			"th":"泰语",
			"ti":"提格里尼亚语",
			"tg":"塔吉克语",
			"te":"泰卢固语",
			"ta":"泰米尔语",
			"yi":"依地语",
			"yo":"约鲁巴语",
			"de":"德语",
			"da":"丹麦语",
			"dz":"不丹语",
			"st":"南索托语",
			"dv":"迪维希语",
			"qu":"凯楚亚语",
			"el":"现代希腊语",
			"eo":"世界语",
			"en":"英语",
			"zh":"中文",
			"ee":"埃维语",
			"za":"壮语",
			"mh":"马绍尔语",
			"uk":"乌克兰语",
			"eu":"巴斯克语",
			"et":"爱沙尼亚语",
			"es":"西班牙语",
			"ru":"俄语",
			"rw":"基尼阿万达语",
			"rm":"利托-罗曼语",
			"rn":"基隆迪语",
			"ro":"罗马尼亚语",
			"bn":"孟加拉语",
			"be":"白俄罗斯语",
			"bg":"保加利亚语",
			"ba":"巴什基尔语",
			"wa":"沃伦语",
			"wo":"沃洛夫语",
			"bm":"班巴拉语",
			"jv":"爪哇语",
			"bo":"藏语",
			"bh":"比哈尔语",
			"bi":"比斯拉玛语",
			"br":"布列塔尼语",
			"bs":"波斯尼亚语",
			"ja":"日语",
			"om":"奥洛莫语",
			"oj":"奥吉布瓦语",
			"ty":"塔希提语",
			"oc":"奥克语",
			"tw":"特威语",
			"os":"奥塞梯语",
			"or":"奥利亚语",
			"xh":"科萨语",
			"ch":"查莫罗语",
			"co":"科西嘉语",
			"ca":"加泰隆语",
			"ce":"车臣语",
			"cy":"威尔士语",
			"cs":"捷克语",
			"cr":"克里语",
			"cv":"楚瓦什语",
			"cu":"教会斯拉夫语",
			"ve":"文达语",
			"ps":"普什图语",
			"pt":"葡萄牙语",
			"tl":"塔加洛语",
			"pa":"旁遮普语",
			"vi":"越南语",
			"pi":"巴利语",
			"is":"冰岛语",
			"pl":"波兰语",
			"hz":"赫雷罗语",
			"hy":"亚美尼亚语",
			"hr":"克罗地亚语",
			"iu":"伊努伊特语",
			"ht":"海地克里奥尔语",
			"hu":"匈牙利语",
			"hi":"印地语",
			"ho":"希里莫图语",
			"ha":"豪萨语",
			"he":"希伯来语",
			"mg":"马达加斯加语",
			"uz":"乌兹别克语",
			"ml":"马拉亚拉姆语",
			"mo":"摩尔达维亚语",
			"mn":"蒙古语",
			"mi":"毛利语",
			"ik":"依努庇克语",
			"mk":"马其顿语",
			"ur":"乌尔都语",
			"mt":"马耳他语",
			"ms":"马来语",
			"mr":"马拉提语",
			"ug":"维吾尔语",
			"my":"缅甸语",
			"sq":"阿尔巴尼亚语",
			"aa":"阿法尔语",
			"ab":"阿布哈兹语",
			"ae":"阿维斯陀语",
			"ss":"斯瓦特语",
			"af":"阿非利堪斯語",
			"tn":"塞茨瓦纳语",
			"sw":"斯瓦希里语",
			"ak":"阿坎语",
			"am":"阿姆哈拉语",
			"it":"意大利语",
			"an":"阿拉贡语",
			"ii":"四川彝语",
			"ia":"国际语A",
			"as":"阿萨姆语",
			"ar":"阿拉伯语",
			"su":"巽他语",
			"io":"伊多语",
			"av":"阿瓦尔语",
			"ay":"艾马拉语",
			"az":"阿塞拜疆语",
			"ie":"国际语E",
			"id":"印尼语",
			"ig":"伊博语",
			"sk":"斯洛伐克语",
			"sr":"塞尔维亚语",
			"nl":"荷兰语",
			"nn":"新挪威语",
			"no":"挪威语",
			"na":"瑙鲁语",
			"nb":"书面挪威语",
			"nd":"北恩德贝勒语",
			"ne":"尼泊尔语",
			"ng":"恩敦加语",
			"ny":"尼扬贾语",
			"vo":"沃拉普克语",
			"zu":"祖鲁语",
			"so":"索马里语",
			"nr":"南恩德贝勒语",
			"nv":"纳瓦霍语",
			"sn":"绍纳语",
			"fr":"法语",
			"sm":"萨摩亚语",
			"fy":"弗里西亚语",
			"sv":"瑞典语",
			"fa":"波斯语",
			"ff":"富拉语",
			"fi":"芬兰语",
			"fj":"斐济语",
			"sa":"梵语",
			"fo":"法罗语",
			"ka":"格鲁吉亚语",
			"kg":"刚果语",
			"kk":"哈萨克语",
			"kj":"宽亚玛语",
			"ki":"基库尤语",
			"ko":"朝鲜语、韓語",
			"kn":"卡纳达语",
			"km":"高棉语",
			"kl":"格陵兰语",
			"ks":"克什米尔语",
			"kr":"卡努里语",
			"si":"僧加罗语",
			"sh":"塞尔维亚-克罗地亚语",
			"kw":"康沃尔语",
			"kv":"科米语",
			"ku":"库尔德语",
			"sl":"斯洛文尼亚语",
			"sc":"撒丁语",
			"ky":"吉尔吉斯语",
			"sg":"桑戈语",
			"se":"北萨米语",
			"sd":"信德语"};
			
	document.getElementById('loadingIco').style.display="none";
	//alert(text.resultCount);
	var i=0;
	var applist=document.getElementById('applist');
	if(text.resultCount!=0) {
		document.getElementById('apptext').textContent="";
	}
	else {
		document.getElementById('apptext').textContent="暂无数据...";
	}
	while(applist.firstChild)
		applist.removeChild(applist.firstChild);	
	while(text.results[i]) {
		//汇率转换
		var p=0;
		while(priceCN[p]){
			if(text.results[i]["price"]==priceCN[p]){
				text.results[i]["price"] = priceUS[p];
				break;
			}
			else
				p++;
		}
		
		
		//josn数据格式转换
		//对book类别的sellerName转化
		if(text.results[i]["primaryGenreName"].toLowerCase() == "book" && text.results[i].sellerName)
			{
				text.results[i].artistName = text.results[i].sellerName;
			}
		
		//类别转换
		text.results[i]["primaryGenreName"]=text.results[i]["primaryGenreName"].toLowerCase();
		for ( var kind in kindLab)
			if (text.results[i]["primaryGenreName"].search(kind)!=-1)
				text.results[i]["primaryGenreName"]=kindLab[kind];
		//发布时间转换
		text.results[i]["releaseDate"]=text.results[i]["releaseDate"].substring(0,10);
		text.results[i]["releaseDate"]=text.results[i]["releaseDate"].replace("-","年");
		text.results[i]["releaseDate"]=text.results[i]["releaseDate"].replace("-","月");
		text.results[i]["releaseDate"]=text.results[i]["releaseDate"]+"日";
		//文件大小转换
		text.results[i]["fileSizeBytes"]=(text.results[i]["fileSizeBytes"]/(1024*1024)).toFixed(1);
		text.results[i]["fileSizeBytes"]=text.results[i]["fileSizeBytes"]+" MB";
		//语言转换
		for ( var language in text.results[i]["languageCodesISO2A"])
		{
			text.results[i]["languageCodesISO2A"][language]=text.results[i]["languageCodesISO2A"][language].toLowerCase();
			text.results[i]["languageCodesISO2A"][language]=languageLab[text.results[i]["languageCodesISO2A"][language]];
		}
		text.results[i]["languageCodesISO2A"]=text.results[i]["languageCodesISO2A"].join(", ");
		
		//兼容平台转换
		
		if(text.results[i]["supportedDevices"])
		{
			text.results[i]["supportedDevices"]=text.results[i]["supportedDevices"].toString();
				text.results[i]["supportedDevices"]=text.results[i]["supportedDevices"].toLowerCase();
				if(text.results[i]["supportedDevices"].search("all")!=-1)
				{
					text.results[i]["apprequirement"]="与 iPhone、iPod touch、iPad 兼容。 需要 iOS 4.1 或更高版本";
					text.results[i]["supportedDevices"]=3;
				}
				else
				{
					if(text.results[i]["supportedDevices"].search("iphone")!=-1 && text.results[i]["supportedDevices"].search("ipad")!=-1)
					{
						text.results[i]["apprequirement"]="与 iPhone、iPod touch、iPad 兼容。 需要 iOS 4.1 或更高版本";
						text.results[i]["supportedDevices"]=3;
					}
					else
					{
						if(text.results[i]["supportedDevices"].search("iphone")!=-1)
						{
							text.results[i]["apprequirement"]="与 iPhone 兼容。 需要 iOS 3.1 或更高版本";
							text.results[i]["supportedDevices"]=0;
						}
						else
						{
							text.results[i]["apprequirement"]="与 iPad 兼容。 需要 iOS 4.0 或更高版本";
							text.results[i]["supportedDevices"]=1;
						}
					}
				}

			}
		else
		{
			text.results[i]["apprequirement"]="Mac OS X 10.6 或更高版本";
			text.results[i]["supportedDevices"]=2;
		}
			
		//截图转换
		if(text.results[i]["screenshotUrls"][0] && text.results[i]["ipadScreenshotUrls"][0] )
			text.results[i]["screenshort"]=text.results[i]["screenshotUrls"].join(",")+", "+text.results[i]["ipadScreenshotUrls"].join(",");
		else
		{
			if(text.results[i]["screenshotUrls"][0])
				text.results[i]["screenshort"]=text.results[i]["screenshotUrls"].join(",");
			if(text.results[i]["ipadScreenshotUrls"][0])
			text.results[i]["screenshort"]=text.results[i]["ipadScreenshotUrls"].join(",");
		}
		//年龄限制转换
		text.results[i]["trackContentRating"]=text.results[i]["trackContentRating"].replace("+","");
		//alert(text.results[i]["trackContentRating"]);
		
		//图标
		var tr = document.createElement("tr");
		var td = document.createElement("td");
		td.setAttribute("width","75px");
		td.setAttribute("height","75px");
		var a = document.createElement("a");
		a.setAttribute("href",text.results[i].trackViewUrl);
		a.setAttribute("title",text.results[i].trackName);
		a.setAttribute("target","_blank");
		a.setAttribute("class","tTip");
		var div = document.createElement("div");
		div.setAttribute("class","app_img");
		var img = document.createElement("img");
		img.setAttribute("src",text.results[i].artworkUrl60);
		img.setAttribute("alt",text.results[i].trackName);
		img.setAttribute("title",text.results[i].trackName);
		var span = document.createElement("span");
		span.setAttribute("class","mask");
		div.appendChild(img);
		div.appendChild(span);
		td.appendChild(a);
		a.appendChild(div);
		tr.appendChild(td);
		applist.appendChild(tr);	
		
		//简介
		td = document.createElement("td");
		td.style.width="84%";
		td.style.paddingLeft="8px";
		td.style.paddingRight="8px";
		var h2 = document.createElement("h2");
		a = document.createElement("a");
		a.setAttribute("href",text.results[i].trackViewUrl);
		a.setAttribute("title",text.results[i].trackName);
		a.setAttribute("target","_blank");
		a.textContent=text.results[i].trackName;
		span = document.createElement("span");
		span.textContent="    ID："+ text.results[i].trackId +" / 价格：$"+ text.results[i].price;
		var p = document.createElement("p");
		p.textContent = "版权：" + text.results[i].artistName + " / 发布时间：" + text.results[i].releaseDate
		tr.appendChild(td);
		td.appendChild(h2);
		h2.appendChild(a);
		h2.appendChild(span);
		td.appendChild(p);
		
		//添加按钮
		td = document.createElement("td");
		var input = document.createElement("input");
		input.setAttribute("type","button");
		input.setAttribute("value","添加");
		input.setAttribute("id",i);
		input.style.verticalAlign = "middle";
		input.style.width = "60px";
		input.style.height = "24px";
		tr.appendChild(td);
		td.appendChild(input);


		input.onclick=function () {
			showloading();
			var myurl = "do_addapp.php?";
			var myRand = parseInt(Math.random()*999999999999999);
			var modurl = myurl+"rand="+myRand;
			
			text.results[this.id]["description"]=encodeURIComponent(text.results[this.id]["description"]);
			text.results[this.id]["trackName"]=encodeURIComponent(text.results[this.id]["trackName"]);
			

			http.open("POST",modurl,true);
			
			http.onreadystatechange = processRequest_recAddapp;
			
			http.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			
			http.send("id="+this.id+"&platform="+text.results[this.id]["supportedDevices"]+"&appname="+text.results[this.id]["trackName"]+"&kind="+text.results[this.id]["primaryGenreName"]+"&price="+text.results[this.id]["price"]+"&releasedate="+text.results[this.id]["releaseDate"]+"&vesion="+text.results[this.id]["version"]+"&size="+text.results[this.id]["fileSizeBytes"]+"&language="+text.results[this.id]["languageCodesISO2A"]+"&copyright="+text.results[this.id]["artistName"]+"&linkid="+text.results[this.id]["trackId"]+"&screenshort="+text.results[this.id]["screenshort"]+"&imgsrc="+text.results[this.id]["artworkUrl60"]+"&contentrating="+text.results[this.id]["trackContentRating"]+"&apprequirement="+text.results[this.id]["apprequirement"]+"&content="+text.results[this.id]["description"]);
			//var textTemp="";
			//for( var temp in text.results[this.id])
			//alert(text.results[this.id]["primaryGenreName"]);
			//alert(text.results[this.id]["supportedDevices"]);
			//if(temp!="description")
			//textTemp+=temp+":"+text.results[this.id][temp]+" || ";
			//alert(textTemp);
		//平台
		};
		i++;
	}
}

function processRequest_recAddapp()
{
	if(http.readyState == 4) {
		if(http.status == 200) {
			showloading('none');
			//var mytext = http.responseText;		
			
			eval('var mytext = '+http.responseText);	
			if(mytext['error']==0)
			{
				document.getElementById(mytext['id']).disabled=true;
				
				if(mytext['flag']==0)
				{
					if(confirm("成功添加应用："+mytext['appname']+", 是否立刻跳转查看？"))
					 window.location.href="http://www.funso.com/home/iosapp-"+mytext['linkid']+".html"; 
				}
				else
				{
					if(confirm("成功更新应用："+mytext['appname']+", 是否立刻跳转查看？"))
					 window.location.href="http://www.funso.com/home/iosapp-"+mytext['linkid']+".html"; 
	
				}
			}
			else
			{
				
				alert("出现错误，添加失败！");
			}
		}
	}

}

function showreply_thread(){
	//document.getElementById("topics_index").disabled=true;
	document.getElementById("topics_index").style.display="block";
}


var priceCN=new Array();
var iii=0;
priceCN[iii]=	6	;iii++;
priceCN[iii]=	12	;iii++;
priceCN[iii]=	18	;iii++;
priceCN[iii]=	25	;iii++;
priceCN[iii]=	30	;iii++;
priceCN[iii]=	40	;iii++;
priceCN[iii]=	45	;iii++;
priceCN[iii]=	50	;iii++;
priceCN[iii]=	60	;iii++;
priceCN[iii]=	68	;iii++;
priceCN[iii]=	73	;iii++;
priceCN[iii]=	78	;iii++;
priceCN[iii]=	88	;iii++;
priceCN[iii]=	93	;iii++;
priceCN[iii]=	98	;iii++;
priceCN[iii]=	108	;iii++;
priceCN[iii]=	113	;iii++;
priceCN[iii]=	118	;iii++;
priceCN[iii]=	123	;iii++;
priceCN[iii]=	128	;iii++;
priceCN[iii]=	138	;iii++;
priceCN[iii]=	148	;iii++;
priceCN[iii]=	153	;iii++;
priceCN[iii]=	158	;iii++;
priceCN[iii]=	163	;iii++;
priceCN[iii]=	168	;iii++;
priceCN[iii]=	178	;iii++;
priceCN[iii]=	188	;iii++;
priceCN[iii]=	193	;iii++;
priceCN[iii]=	198	;iii++;
priceCN[iii]=	208	;iii++;
priceCN[iii]=	218	;iii++;
priceCN[iii]=	223	;iii++;
priceCN[iii]=	228	;iii++;
priceCN[iii]=	233	;iii++;
priceCN[iii]=	238	;iii++;
priceCN[iii]=	243	;iii++;
priceCN[iii]=	248	;iii++;
priceCN[iii]=	253	;iii++;
priceCN[iii]=	258	;iii++;
priceCN[iii]=	263	;iii++;
priceCN[iii]=	268	;iii++;
priceCN[iii]=	273	;iii++;
priceCN[iii]=	278	;iii++;
priceCN[iii]=	283	;iii++;
priceCN[iii]=	288	;iii++;
priceCN[iii]=	298	;iii++;
priceCN[iii]=	308	;iii++;
priceCN[iii]=	318	;iii++;
priceCN[iii]=	328	;iii++;
priceCN[iii]=	348	;iii++;
priceCN[iii]=	388	;iii++;
priceCN[iii]=	418	;iii++;
priceCN[iii]=	448	;iii++;
priceCN[iii]=	488	;iii++;
priceCN[iii]=	518	;iii++;
priceCN[iii]=	548	;iii++;
priceCN[iii]=	588	;iii++;
priceCN[iii]=	618	;iii++;
priceCN[iii]=	648	;iii++;
priceCN[iii]=	698	;iii++;
priceCN[iii]=	798	;iii++;
priceCN[iii]=	848	;iii++;
priceCN[iii]=	898	;iii++;
priceCN[iii]=	998	;iii++;
priceCN[iii]=	1048	;iii++;
priceCN[iii]=	1098	;iii++;
priceCN[iii]=	1198	;iii++;
priceCN[iii]=	1248	;iii++;
priceCN[iii]=	1298	;iii++;
priceCN[iii]=	1398	;iii++;
priceCN[iii]=	1448	;iii++;
priceCN[iii]=	1498	;iii++;
priceCN[iii]=	1598	;iii++;
priceCN[iii]=	1648	;iii++;
priceCN[iii]=	1998	;iii++;
priceCN[iii]=	2298	;iii++;
priceCN[iii]=	2598	;iii++;
priceCN[iii]=	2998	;iii++;
priceCN[iii]=	3298	;iii++;
priceCN[iii]=	3998	;iii++;
priceCN[iii]=	4498	;iii++;
priceCN[iii]=	4998	;iii++;
priceCN[iii]=	5898	;iii++;
priceCN[iii]=	6498	;

var priceUS=new Array();
iii=0;
priceUS[iii]=	0.99	;iii++;
priceUS[iii]=	1.99	;iii++;
priceUS[iii]=	2.99	;iii++;
priceUS[iii]=	3.99	;iii++;
priceUS[iii]=	4.99	;iii++;
priceUS[iii]=	5.99	;iii++;
priceUS[iii]=	6.99	;iii++;
priceUS[iii]=	7.99	;iii++;
priceUS[iii]=	8.99	;iii++;
priceUS[iii]=	9.99	;iii++;
priceUS[iii]=	10.99	;iii++;
priceUS[iii]=	11.99	;iii++;
priceUS[iii]=	12.99	;iii++;
priceUS[iii]=	13.99	;iii++;
priceUS[iii]=	14.99	;iii++;
priceUS[iii]=	15.99	;iii++;
priceUS[iii]=	16.99	;iii++;
priceUS[iii]=	17.99	;iii++;
priceUS[iii]=	18.99	;iii++;
priceUS[iii]=	19.99	;iii++;
priceUS[iii]=	20.99	;iii++;
priceUS[iii]=	21.99	;iii++;
priceUS[iii]=	22.99	;iii++;
priceUS[iii]=	23.99	;iii++;
priceUS[iii]=	24.99	;iii++;
priceUS[iii]=	25.99	;iii++;
priceUS[iii]=	26.99	;iii++;
priceUS[iii]=	27.99	;iii++;
priceUS[iii]=	28.99	;iii++;
priceUS[iii]=	29.99	;iii++;
priceUS[iii]=	30.99	;iii++;
priceUS[iii]=	31.99	;iii++;
priceUS[iii]=	32.99	;iii++;
priceUS[iii]=	33.99	;iii++;
priceUS[iii]=	34.99	;iii++;
priceUS[iii]=	35.99	;iii++;
priceUS[iii]=	36.99	;iii++;
priceUS[iii]=	37.99	;iii++;
priceUS[iii]=	38.99	;iii++;
priceUS[iii]=	39.99	;iii++;
priceUS[iii]=	40.99	;iii++;
priceUS[iii]=	41.99	;iii++;
priceUS[iii]=	42.99	;iii++;
priceUS[iii]=	43.99	;iii++;
priceUS[iii]=	44.99	;iii++;
priceUS[iii]=	45.99	;iii++;
priceUS[iii]=	46.99	;iii++;
priceUS[iii]=	47.99	;iii++;
priceUS[iii]=	48.99	;iii++;
priceUS[iii]=	49.99	;iii++;
priceUS[iii]=	54.99	;iii++;
priceUS[iii]=	59.99	;iii++;
priceUS[iii]=	64.99	;iii++;
priceUS[iii]=	69.99	;iii++;
priceUS[iii]=	74.99	;iii++;
priceUS[iii]=	79.99	;iii++;
priceUS[iii]=	84.99	;iii++;
priceUS[iii]=	89.99	;iii++;
priceUS[iii]=	94.99	;iii++;
priceUS[iii]=	99.99	;iii++;
priceUS[iii]=	109.99	;iii++;
priceUS[iii]=	119.99	;iii++;
priceUS[iii]=	129.99	;iii++;
priceUS[iii]=	139.99	;iii++;
priceUS[iii]=	149.99	;iii++;
priceUS[iii]=	159.99	;iii++;
priceUS[iii]=	169.99	;iii++;
priceUS[iii]=	179.99	;iii++;
priceUS[iii]=	189.99	;iii++;
priceUS[iii]=	199.99	;iii++;
priceUS[iii]=	209.99	;iii++;
priceUS[iii]=	219.99	;iii++;
priceUS[iii]=	229.99	;iii++;
priceUS[iii]=	239.99	;iii++;
priceUS[iii]=	249.99	;iii++;
priceUS[iii]=	299.99	;iii++;
priceUS[iii]=	349.99	;iii++;
priceUS[iii]=	399.99	;iii++;
priceUS[iii]=	449.99	;iii++;
priceUS[iii]=	499.99	;iii++;
priceUS[iii]=	599.99	;iii++;
priceUS[iii]=	699.99	;iii++;
priceUS[iii]=	799.99	;iii++;
priceUS[iii]=	899.99	;iii++;
priceUS[iii]=	999.99	;



//计算GND模块
function GNDCalculate(msg) {
	if(http.readyState == 4) {
		if(http.status == 200) {

			var ResponseStr = http.responseText;
			
			var GND = 0;
			var N;
			var flag = document.getElementById("select").options[document.getElementById("select").options.selectedIndex].value;
			if(flag==1)
				var N = 1000000000000;
			else
				var N = 1000000000000;

			var key1,key2,key;
			var array = Array();
			array = ResponseStr.split("/");
			key1 = array[0];
			key2 = array[1];
			key = array[2];
			//log("Received: "+"key1:"+key1+"; key2:"+key2+"; key:"+key);
			log("Received: "+ResponseStr);
			var logKey1Value = Math.log(parseInt(key1));
			var logKey2Value = Math.log(parseInt(key2));
			var logKey = Math.log(parseInt(key));
			var logN = Math.log(N);
			var max = logKey1Value>logKey2Value ? logKey1Value:logKey2Value;
			var max = max>logKey ? max:logKey;
			var min = logKey1Value<logKey2Value ? logKey1Value:logKey2Value;
			//var min = min<logKey ? min:logKey;
			GND = (max-logKey)/(logN-min);
			
			//GND = logKey/logKey1Value;
			//GND = (logKey-min)/min;
			showloading('none');
			//log("logN="+logN+"; logKey1Value="+logKey1Value + "; logKey2Value="+logKey2Value + "; logKey="+logKey);
			log("GND("+document.getElementById("key1").value+","+document.getElementById("key2").value+")= "+GND);
			log("========================================");
			log("");
		}
	}

}





function sendKeyWord(){
	  showloading();
  var key1,key2;
  var txt = Array();
  var flag = document.getElementById("select").options[document.getElementById("select").options.selectedIndex].value;
  key1 = encodeURIComponent(document.getElementById("key1").value);
  key2 = encodeURIComponent(document.getElementById("key2").value);
  if((!key1) || (!key2)){ alert("Key1 and Key2 both can not be empty"); return; }
  

	

	var url ='GND_ajax.php?urlFlag=' + flag +'&key1=' + key1+'&key2=' + key2;
	http.open("GET", url + '&random=' +  Math.random()*99999, true);
	http.onreadystatechange = GNDCalculate;
	http.send(null);
}

var labels=Array();

function getLabels(){
	clearlog();
	showloading();
  var key1;
  var flag = document.getElementById("select").options[document.getElementById("select").options.selectedIndex].value;
  key1 = encodeURIComponent(document.getElementById("key1").value);

  if(!key1){ alert("App_ID can not be empty"); return; }

	var url ='GND2_label.php?urlFlag=' + flag +'&app_id=' + key1;
	http.open("GET", url + '&random=' +  Math.random()*99999, true);
	http.onreadystatechange = sendKeyWord2;
	http.send(null);
}

var GND_label_num=0;
var GND_app_id=0;
var GND_app_count=0;

function sendKeyWord2(){
	if(http.readyState == 4) {
		if(http.status == 200) {
			showloading('none');
			var ResponseStr = http.responseText;
			//log(ResponseStr);
			var temp=Array();
			temp=eval(ResponseStr);
			labels = Array();
			labels = temp[0];
			GND_app_count = temp[1];
			document.getElementById('p').setAttribute("max",labels.length);
			//log(count);
			GND_app_id=document.getElementById("key1").value;
			GND_label_num = 0;			
			GNDCalculate2();			
		}
	}
}

function GNDCalculate2()
{
	if(GND_label_num>=labels.length)
	{
		alert("计算结束");
	}
	if(GND_label_num<labels.length)
	{
		document.getElementById('appnum').textContent  = parseInt(GND_label_num+1); 
		
		var progressBar = document.getElementById('p');
		progressBar.value = GND_label_num+1;
	
		progressBar.getElementsByTagName('span')[0].textContent = parseInt(progressBar.value/labels.length*100);
				
		//log(labels[GND_label_num]['hashcode']);
		GND_label_num++;		
		var flag = document.getElementById("select").options[document.getElementById("select").options.selectedIndex].value;
		httpprice[GND_label_num] = createXMLHTTP();
		if(flag==1)
		{
			if(labels[GND_label_num]['google_count']<0)
			{
				setTimeout("GNDCalculate2()", 8000);
				return;
			}
			var url ='GND2_ajax.php?app_count=' + GND_app_count + "&hashcode=" + labels[GND_label_num]['hashcode'] + "&label_count=" + labels[GND_label_num]['google_count'] +"&app_id="+GND_app_id +"&urlFlag="+flag;
		}
		else
		{
			var url ='GND2_ajax.php?app_count=' + GND_app_count + "&hashcode=" + labels[GND_label_num]['hashcode'] + "&label_count=" + labels[GND_label_num]['baidu_count'] +"&app_id="+GND_app_id +"&urlFlag="+flag;
		}
		httpprice[GND_label_num].open("GET", url + '&random=' +  Math.random()*99999, true);
		log("request:"+ url);
		//httpprice[hashcode].onreadystatechange = processRequest_GNDCalculate;
		httpprice[GND_label_num].send(null);
		if(flag==1)
			setTimeout("GNDCalculate2()", 5000);
		else
			setTimeout("GNDCalculate2()", 1500);
	}

}

function getAppLabel()
{
	clearlog();
	showloading();
  	var key1;
  	var flag = document.getElementById("select").options[document.getElementById("select").options.selectedIndex].value;
 	 key1 = encodeURIComponent(document.getElementById("key1").value);

  	if(!key1){ alert("App_ID can not be empty"); return; }

	var url ='GND2_getlabel.php?urlFlag=' + flag +'&app_id=' + key1;
	http.open("GET", url + '&random=' +  Math.random()*99999, true);
	http.onreadystatechange = getAppLabel_callback;
	http.send(null);	
}

function getAppLabel_callback()
{
	if(http.readyState == 4) {
		if(http.status == 200) {
			showloading('none');
			var flag = document.getElementById("select").options[document.getElementById("select").options.selectedIndex].value;
			var ResponseStr = http.responseText;
			//log(ResponseStr);
			var temp=Array();
			temp=eval(ResponseStr);
			labels = Array();
			labels = temp[0];
			var appname = temp[1];
			log("AppName:"+appname);
			if(flag==1)
			{
				for( var num in labels)
				{
					var NoNum = parseInt(num)+1;
					log("No."+NoNum+"   [Label:"+labels[num]['label']+"   GoogleND:"+labels[num]['google_count']);
				}
			}
			else
			{
				
				for( var num in labels)
				{
					var NoNum = parseInt(num)+1;
					log("No."+NoNum+"   Label:"+labels[num]['label']+"   BaiduND:"+labels[num]['baidu_count']);
				}
			}
		}
	}	
}

