/**
 * @author TONY
**/

var name,sn,src_str,tag_num,remarks_str,intro_str,play_str,operate_str,show_ms,xml_gameinfo,tmp_zc_model,modeltype,tmp_model_arry,tmp_model_arry_num,game_no,trial_game_no,sending_push,submiting_c,loging;
function showLogin(){
	var login_str = '<form name="lf" onsubmit="return false;"><div id="login"><div id="mobile"><div id="mobile_01"><img src="http://www.motogames.com.cn/images/login_mobile.gif" alt="moto 手机 游戏 摩托罗拉 mobile game"/></div><input name="un" type="text" class="input_01" title="手机号" maxlength="11"/></div><div id="mobile"><div id="mobile_01"><img src="http://www.motogames.com.cn/images/login_password.gif" alt="moto 手机 游戏 摩托罗拉 mobile game"/></div><input name="pwd" type="password" class="input_04" title="密码" /></div><div id="login_btn"><input type=image src="http://www.motogames.com.cn/images/login_log.gif" border=0 class="img_01" onclick="javascript:asynSubmit(\'login\')"/><a href=javascript:; onClick="window.open(\'http://join.motorola.com.cn/DesktopModules/MotoDnnModules/signup1/index.aspx?campaign=MOTOGAME&amp;action=register\',\'_blank\',\'width=670,height=400,status=yes,toolbar=no,menubar=no,location=no,resizable=no\');"><img src="http://www.motogames.com.cn/images/login_reg.gif" class="img_01" border="0" /></a></div><div id="login_text">MOTO体验中心用户首次登陆点击<a href="javascript:;" onClick="window.open(\'http://join.motorola.com.cn/DesktopModules/MotoDnnModules/signup1/index.aspx?campaign=MOTOGAME&amp;action=login\',\'_blank\',\'width=670,height=400,status=yes,toolbar=no,menubar=no,location=no,resizable=no\');" class="font_01">这里</a><a href="javascript:;" class="font_01" onclick="javascript:forgetNum();">忘记密码</a></div></div></form>';
	var all_info = getCookie("_ALL_INFO");
	var uid = getCookie('USERID');
	name = String(getCookie('NUMBER'));
	if(all_info!='' && name!='' && uid!=''){
		makeRequest();
		if (!http_request){
			alert('Giving up :( Cannot create an XMLHTTP instance)');
		}else{
			/*tmp_rand = parseInt(10*Math.random());
			uid += tmp_rand;
			http_request.open("GET","http://www.motogames.com.cn/newmg/interface/check_out.php?userid="+uid,false);
			http_request.send(null);*/
			var uid_value = 'userid='+uid;
			var uid_url = 'http://www.motogames.com.cn/newmg/interface/check_out.php';
			http_request.open('POST', uid_url, false);
			http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			http_request.send(uid_value);
			var rtnResult = http_request.responseText;
			http_request = null;
			if(rtnResult==0){
				login_str = '<div id="login_text1">您好<a class="font_13">'+name+'</a> 欢迎光临MOTO游戏站!&nbsp;&nbsp;&nbsp;&nbsp;<img src="http://www.motogames.com.cn/games_images/motorolasin18.gif" width="4" height="5" align="absmiddle" /> <a href="http://www.motogames.com.cn/newmg/user_operate/update_info.php" class="font_13" target="_blank">修改个人资料</a>&nbsp;&nbsp;&nbsp;&nbsp;如果您不是<a class="font_13">'+name+'</a> 请点击这里<a href="javascript:;" onclick="javascript:asynSubmit(\'logout\')" class="font_13">重新登录</a></div>';
			}else{
				var expire_date=new Date();
				expire_date.setTime(expire_date.getTime());
				var expire_string=expire_date.toGMTString();
				if(sn==0){
					document.cookie='_ALL_INFO="";expires=0;path=/;';
					document.cookie='USERID="";expires=0;path=/;';
					document.cookie='NUMBER="";expires=0;path=/;';
				}else{
					document.cookie='_ALL_INFO=null;expires=0;path=/;domain="www.motogames.com.cn";secure';
					document.cookie='USERID=null;expires=0;path=/;domain="www.motogames.com.cn";secure';
					document.cookie='NUMBER=null;expires=0;path=/;domain="www.motogames.com.cn";secure';
				}
				location.reload();
			}
		}
	}
	document.getElementById('login1').innerHTML += login_str;
	showIframe();
}

function showTag(tnum){
	if(document.getElementById('q_body')!=null){
		tag_num = tnum;
		makeRequest();
		var tag_url = 'http://www.motogames.com.cn/newmg/xml/tag.xml';
		http_request.onreadystatechange = ajaxTag;
		http_request.open('GET', tag_url, true);
		http_request.send(null);
	}
}

function ajaxTag(){
	if (http_request.readyState == 4){
		if (http_request.status == 200){
			var xml_doc = http_request.responseXML;
			http_request = null;
			if(!xml_doc){
				createMessageDiv('There was a problem with the XML,Please change IE5.0!',1,10000,400,90,'red',0,90);
				return false;
			}
			var tag_values = xml_doc.getElementsByTagName('Message')[0].childNodes;
			if(tag_num<=0) tag_num = tag_values.length;
			var tag_name;
			var tag_str = '';
			for(var i=0;i<tag_num;i++){
				tag_name = tag_values[i].childNodes[0].data;
				tag_str += '<a href="http://www.motogames.com.cn/newmg/user_operate/newmysearch.php?tid='+tag_values[i].getAttribute('id')+'&tname='+tag_values[i].childNodes[0].data+'" class="f_'+tag_values[i].getAttribute('fz')+'" target="_blank">'+tag_name+'</a>';
			}
			if(tag_str!='') document.getElementById('q_body').innerHTML = tag_str;
		}else{
			createMessageDiv('There was a problem with the Tag request,Please reload!',1,10000,400,90,'red',0,90);
		}
	}
}

function showModel(){
	if(document.mysearch.umodel.options.length<=1){
		makeRequest();
		var model_url = 'http://www.motogames.com.cn/newmg/xml/phone_model.xml';
		http_request.onreadystatechange = ajaxModel;
		http_request.open('GET', model_url, true);
		http_request.send(null);
	}
}

function ajaxModel(){
	if (http_request.readyState == 4){
		if (http_request.status == 200){
			closeMessageDiv();
			var xml_doc = http_request.responseXML;
			http_request = null;
			if(!xml_doc){
				createMessageDiv('There was a problem with the XML,Please change IE5.0!',1,10000,400,90,'red',0,90);
				return false;
			}
			var model_values = xml_doc.getElementsByTagName('Message')[0].childNodes;
			model_num = model_values.length;
			for(var i=0;i<model_num;i++){
				document.mysearch.umodel.options.add(new Option(model_values[i].getAttribute('name').replace('A1200','明'),model_values[i].getAttribute('name')));
			}
		}else{
			createMessageDiv('There was a problem with the Model request,Please reload!',1,10000,400,90,'red',0,90);
		}
	}else{
		createMessageDiv('数据读取中!',0,0,185,75,0,0,90);
	}
}

/*function showIframe(){
	var all_info = getCookie("_ALL_INFO");
	var src_str = 'http://www.weberliu.com/store_embed.php?style=game';
	var eq_div = document.getElementById('equipment');
	if(eq_div!=null){
		if(all_info!=''){
			makeRequest();
			if (!http_request){
				alert('Giving up :( Cannot create an XMLHTTP instance)');
			}else{
				var tmp_rand = parseInt(10*Math.random());
				http_request.open("GET","http://www.motogames.com.cn/newmg/interface/iframe_out.php?"+tmp_rand,false);
				http_request.send(null);
				var rtnResult = http_request.responseText;
				http_request = null;
				if(rtnResult!=0) src_str += '&'+rtnResult;
			}
		}
		eq_div.innerHTML = '<iframe id="iframe" src="'+src_str+'" frameborder="0" width="645"  height="1024"  allowtransparency="yes" scrolling="auto" />';
	}
}*/

function showIframe(){
	var all_info = getCookie("_ALL_INFO");
	var eq_div = document.getElementById('equipment');
	src_str = 'http://www.motostore.com.cn/store_embed.php?style=game';
	if(eq_div!=null){
		if(all_info!=''){
			makeRequest();
			//var tmp_rand = parseInt(10*Math.random());
			//var iframe_url = 'http://www.motogames.com.cn/newmg/interface/iframe_out.php?'+tmp_rand;
			var iframe_url = 'http://www.motogames.com.cn/newmg/interface/iframe_out.php';
			eq_div.innerHTML = '';
			http_request.onreadystatechange = ajaxIframe;
			http_request.open('POST', iframe_url, true);
			http_request.send(null);
		}else{
			eq_div.innerHTML = '<iframe id="iframe" src="'+src_str+'" frameborder="0" width="582"  height="806"  allowtransparency="yes" scrolling="auto" />';
		}
	}
}

function ajaxIframe(){
	if (http_request.readyState == 4){
		if (http_request.status == 200){
			var eq_div = document.getElementById('equipment');
			var rtnResult = http_request.responseText;
			http_request = null;
			if(rtnResult!=0) src_str += '&'+rtnResult;
			eq_div.innerHTML = '<iframe id="iframe" src="'+src_str+'" frameborder="0" width="582"  height="806"  allowtransparency="yes" scrolling="auto" />';
		}else{
			createMessageDiv('There was a problem with the iframe request,Please reload!',1,10000,400,90,'red',0,90);
		}
	}else{
		var load_str = '<img src="http://www.motogames.com.cn/images/loading.gif" align="absmiddle" width="188" height="32" border="0" />';
		document.getElementById('equipment').innerHTML = load_str;
	}
}

function forgetNum(){
	var fs = '<form name="fs" onsubmit="return false;"><div id="mobile_01">手机:</div><input name="fsun" type="text" class="input_03" title="手机号" /><input type=image src="http://www.motogames.com.cn/images/submit.gif" border=0 onclick="javascript:findNum()" class="img_01"/></form>';
	createMessageDiv(fs,0,0,185,100,0,0,90);
}

function findNum(){
	var fsun = document.fs.fsun.value;
	if(fsun==''){
		alert('手机号不能为空!');
	}else{
		if(/^1\d{10}$/g.test(fsun)){
			closeMessageDiv();
			makeRequest();
			var find_value = 'pn='+fsun;
			var find_url = 'http://www.motogames.com.cn/newmg/user_operate/find_pwd.php';
			http_request.open('POST', find_url, true);
			http_request.onreadystatechange = findResult;
			http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			http_request.send(find_value);
			/*closeMessageDiv();
			var fs = '<img src="http://www.motogames.com.cn/images/loading.gif" align="absmiddle" width="188" height="32" border="0" />';
			if (!http_request){
				alert('Giving up :( Cannot create an XMLHTTP instance)');
			}else{
				createMessageDiv(fs,0,0,200,90,0,0);
				var tmp_rand = parseInt(10*Math.random());
				http_request.open("GET","http://www.motogames.com.cn/newmg/user_operate/find_pwd.php?"+tmp_rand+"&pn="+fsun,false);
				http_request.send(null);
				var rtnResult = http_request.responseText;
				http_request = null;
				alert(rtnResult)
				closeMessageDiv();
				if(rtnResult==1)
					createMessageDiv('您的密码已经发送成功!',1,2000,365,90,0,0);
				else
					createMessageDiv('对不起，超出今日发送次数!',1,2000,365,90,'red',0);
			}*/
		}else{
			alert('手机号不正确!');
		}
	}
}

function findResult(){
	if (http_request.readyState == 4){
		if (http_request.status == 200){
			closeMessageDiv();
			var rtnResult = http_request.responseText;
			http_request = null;
			if(rtnResult==1)
				createMessageDiv('您的密码已经发送成功!',1,2000,365,90,0,0,90);
			else if(rtnResult==2)
				createMessageDiv('对不起，密码下发失败!',1,2000,365,90,'red',0,90);
			else if(rtnResult==3)
				createMessageDiv('对不起，您还未<a href="javascript:;" onClick="window.open(\'http://join.motorola.com.cn/DesktopModules/MotoDnnModules/signup1/index.aspx?campaign=MOTOGAME&amp;action=register\',\'_blank\',\'width=670,height=400,status=yes,toolbar=no,menubar=no,location=no,resizable=no\');" class="font_01">注册!</a>',1,5000,365,90,'red',0,90);
			else
				createMessageDiv('对不起，超出今日发送次数!',1,2000,365,90,'red',0,90);
		}else{
			alert('There was a problem with the find request.');
		}
	}else{
		var fs = '<img src="http://www.motogames.com.cn/images/loading.gif" align="absmiddle" width="188" height="32" border="0" />';
		createMessageDiv(fs,0,0,200,90,0,0,90);
	}
}

function loginSubmit(){
	if(loging){
		alert('正在为您登录!');
		return false;
	}
	if(sending_push){
		alert('正在为您下发PUSH!');
		return false;
	}
	if(submiting_c){
		alert('正在为您提交信息!');
		return false;
	}
	if(name==''){
		var unum = document.lf.un.value;
		var upwd = document.lf.pwd.value;
		if(unum=='' || upwd==''){
			createMessageDiv('对不起,用户名或密码不能为空!',1,2000,365,90,'red',0,90);
			return false;
		}else{
			if(/^1\d{10}$/g.test(unum)){
				document.getElementById('login1').innerHTML = '';
				loging = true;
				makeRequest();
				var login_value = 'unum='+unum+'&upwd='+upwd+'&login=index';
				var login_url = 'http://www.motogames.com.cn/newmg/user_operate/login.php';
				http_request.open('POST', login_url, true);
				http_request.onreadystatechange = loginResult;
				http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				http_request.send(login_value);
			}else{
				createMessageDiv('对不起,手机号不正确!',1,2000,365,90,'red',0,90);
			}
		}
	}
}

function loginResult(){
	var load_str;
	if (http_request.readyState == 4){
		loging = false;
		if (http_request.status == 200){
			document.getElementById('login1').innerHTML = '';
			load_str = String(getCookie('NUMBER'));
			if(load_str=='') createMessageDiv('对不起,登录失败!',1,2000,365,90,'red',0,90);
			http_request = null;
			showLogin();
		}else{
			createMessageDiv('There was a problem with the login request,Please reload!',1,10000,400,90,'red',0,90);
		}
	}else{
		load_str = '<img src="http://www.motogames.com.cn/images/msgloading.gif" align="absmiddle" width="188" height="32" border="0" />';
		document.getElementById('login1').innerHTML = load_str;
	}
}

function logOutSubmit(){
	if(loging){
		alert('正在为您登录!');
		return false;
	}
	if(sending_push){
		alert('正在为您下发PUSH!');
		return false;
	}
	if(submiting_c){
		alert('正在为您提交信息!');
		return false;
	}
	if(name!=''){
		document.getElementById('login1').innerHTML = '';
		loging = true;
		makeRequest();
		//var tmp_rand = parseInt(10*Math.random());
		//var logout_url = 'http://www.motogames.com.cn/newmg/user_operate/logout.php?'+tmp_rand;
		var logout_url = 'http://www.motogames.com.cn/newmg/user_operate/logout.php';
		http_request.open('POST', logout_url, true);
		http_request.onreadystatechange = logOutResult;
		http_request.send(null);
	}
}

function logOutResult(){
	var load_str;
	if (http_request.readyState == 4){
		loging = false;
		if (http_request.status == 200){
			document.getElementById('login1').innerHTML = '';
			//load_str = String(getCookie('NUMBER'));
			//if(load_str!='') alert('对不起,退出失败');
			http_request = null;
			showLogin();
			location.reload();
		}else{
			createMessageDiv('There was a problem with the logout request,Please reload!',1,10000,400,90,'red',0,90);
		}
	}else{
		load_str = '<img src="http://www.motogames.com.cn/images/msgloading.gif" align="absmiddle" width="188" height="32" border="0" />';
		document.getElementById('login1').innerHTML = load_str;
	}
}

function showGameInfo(){
	var fn = getFileName();
	if(fn!=''){
		makeRequest();
		var info_url = 'http://www.motogames.com.cn/newmg/xml/gamesinfo/'+fn+'.xml';
		http_request.onreadystatechange = ajaxGameInfo;
		http_request.open('GET', info_url, true);
		http_request.send(null);
	}else{
		window.close();
	}
}

function ajaxGameInfo(){
	if (http_request.readyState == 4){
		if (http_request.status == 200){
			xml_gameinfo = http_request.responseXML;
			http_request = null;
			if(!xml_gameinfo){
				createMessageDiv('There was a problem with the XML,Please change IE5.0!',1,10000,400,90,'red',0,90);
				return false;
			}

			document.title = xml_gameinfo.getElementsByTagName('name')[0].childNodes[0].data+'-'+document.title;
			var cg_value = xml_gameinfo.getElementsByTagName('cgname')[0].childNodes;
			with(cg_value[0]){
				if(data=='动作冒险')
					cg = 1;
				else if(data=='角色扮演')
					cg = 2;
				else if(data=='体育竞技')
					cg = 3;
				else if(data=='棋牌休闲')
					cg = 4;
				else if(data=='网络游戏')
					cg = 5;
			}
			var score = xml_gameinfo.getElementsByTagName('score')[0].childNodes[0].data;
			if(score!='' && score<30){
				ystar = 1;
				gstar = 4;
			}else if(score>=30 && score<60){
				ystar = 2;
				gstar = 3;
			}else if(score>=60 && score<80){
				ystar = 3;
				gstar = 2;
			}else if(score>=80 && score<90){
				ystar = 4;
				gstar = 1;
			}else{
				ystar = 5;
				gstar = 0;
			}
			var star_str = '';
			for(i=0;i<ystar;i++) star_str += '<img src="http://www.motogames.com.cn/newmg/img/star_yellow.gif"/>';
			for(i=0;i<gstar;i++) star_str += '<img src="http://www.motogames.com.cn/newmg/img/star_gray.gif"/>';
			
			intro_str = xml_gameinfo.getElementsByTagName('gameintro')[0].childNodes[0].data;
			remarks_str = analysisXml('remarks',xml_gameinfo);
			var all_message_str = analysisXml('gameplay',xml_gameinfo);
			operate_str = '';
			play_str = '';
			if(all_message_str){
				var zz=/\|/;
				if(zz.exec(all_message_str)){
					operate_str = RegExp.leftContext;
					play_str = RegExp.rightContext;
				}else{
					operate_str = all_message_str;
				}
			}
			var cut_str = '';
			for(i=1;i<5;i++) cut_str += '<div class="game_cut"><img src="'+xml_gameinfo.getElementsByTagName('imgsrc')[0].childNodes[0].data+i+'.'+xml_gameinfo.getElementsByTagName('imgtype')[0].childNodes[0].data+'" width="128" height="128" /></div>';
			modeltype = xml_gameinfo.getElementsByTagName('isphonesort')[0].childNodes[0];
			var zc_model = '支持大类机型(点击机型查看所包含的机型)：';
			var zc_model_num = xml_gameinfo.getElementsByTagName('modelnum')[0].childNodes[0].data;
			var tag_mod_num = '';
			tmp_zc_model = '';
			for(i=0;i<zc_model_num;i++){
				tag_mod_num = 'model'+i;
				if(modeltype && modeltype.data==0){
					tmp_zc_model += xml_gameinfo.getElementsByTagName(tag_mod_num)[0].childNodes[0].data+'|';
					zc_model += xml_gameinfo.getElementsByTagName(tag_mod_num)[0].childNodes[0].data+' | ';
				}else if(modeltype && modeltype.data==1){
					tmp_zc_model += xml_gameinfo.getElementsByTagName(tag_mod_num)[0].childNodes[0].data+'|';
					zc_model += '<a href="javascript:;" onclick="showAllModel(\''+xml_gameinfo.getElementsByTagName(tag_mod_num)[0].childNodes[0].data+'\')">'+xml_gameinfo.getElementsByTagName(tag_mod_num)[0].childNodes[0].data+'</a> | ';
				}
			}
			if(modeltype && modeltype.data==0) zc_model = zc_model.replace('大类机型(点击机型查看所包含的机型)','机型');
			if(xml_gameinfo.getElementsByTagName('gameNo')[0].childNodes[0]){
				game_no = xml_gameinfo.getElementsByTagName('gameNo')[0].childNodes[0].data;
				document.getElementById('gamedown').style.display = "block";
				document.getElementById('gamedown').innerHTML = '<img src="http://www.motogames.com.cn/images/mobile2.gif" />';
			}
			if(xml_gameinfo.getElementsByTagName('trialgameNo')[0].childNodes[0]){
				trial_game_no = xml_gameinfo.getElementsByTagName('trialgameNo')[0].childNodes[0].data;
				document.getElementById('trialgamedown').style.display = "block";
				document.getElementById('trialgamedown').innerHTML = '<img src="http://www.motogames.com.cn/images/mobile1.gif" />';
			}
			if(xml_gameinfo.getElementsByTagName('rardown')[0].childNodes[0].data==1){
				rar_url = xml_gameinfo.getElementsByTagName('rarurl')[0].childNodes[0].data;
				document.getElementById('rardown').style.display = "block";
				document.getElementById('rardown').innerHTML = '<img src="http://www.motogames.com.cn/images/PC.gif" />';
			}
			
			document.getElementById('imgdiv').innerHTML = '<img src="'+xml_gameinfo.getElementsByTagName('imgsrc')[0].childNodes[0].data+'0.'+xml_gameinfo.getElementsByTagName('imgtype')[0].childNodes[0].data+'" border="1" width="120" height="120"/><br/>[<a href="http://www.motogames.com.cn/newmg/user_operate/newmysearch.php?typeid='+cg+'" target="_blank">'+cg_value[0].data+'</a>]';
			document.getElementById('namediv').innerHTML = '游戏名称：'+xml_gameinfo.getElementsByTagName('name')[0].childNodes[0].data+'<br/>推荐指数：'+star_str+'<br/>收费价格：'+xml_gameinfo.getElementsByTagName('gameprice')[0].childNodes[0].data+'元';
			document.getElementById('messagetext').innerHTML = intro_str;
			document.getElementById('imgcut').innerHTML = cut_str;
			document.getElementById('showmodel').innerHTML = zc_model;
			document.getElementById('mzspname').innerHTML = xml_gameinfo.getElementsByTagName('spname')[0].childNodes[0].data;
			document.getElementById('mzgamename').innerHTML = xml_gameinfo.getElementsByTagName('name')[0].childNodes[0].data;
			document.getElementById('mzgameprice').innerHTML = xml_gameinfo.getElementsByTagName('gameprice')[0].childNodes[0].data;
			document.getElementById('mzpricetype').innerHTML = '元';
			document.getElementById('mzspphone').innerHTML = xml_gameinfo.getElementsByTagName('spphone')[0].childNodes[0].data;
			showComment();
		}else{
			createMessageDiv('There was a problem with the GameInfo request,Please reload!',1,10000,400,90,'red',0,90);
		}
	}
}

function showAllModel(modelsort){
	if(modelsort){
		show_ms = modelsort;
		makeRequest();
		var ms_url = 'http://www.motogames.com.cn/newmg/xml/phone_model.xml';
		http_request.onreadystatechange = ajaxSallmodel;
		http_request.open('GET', ms_url, true);
		http_request.send(null);
	}
}

function ajaxSallmodel(){
	if (http_request.readyState == 4){
		if (http_request.status == 200){
			document.getElementById('allmodel').innerHTML = '';
			var xml_doc = http_request.responseXML;
			http_request = null;
			if(!xml_doc){
				createMessageDiv('There was a problem with the XML,Please change IE5.0!',1,10000,400,90,'red',0,90);
				return false;
			}
			var ms_value = xml_doc.getElementsByTagName('Message')[0].childNodes;
			var ms_num = ms_value.length;
			var ps_id = '';
			for(i=0;i<ms_num;i++){
				if(ms_value[i].getAttribute('name')==show_ms) ps_id = ms_value[i].getAttribute('psid');
			}
			if(ps_id){
				var am_str = '';
				for(i=0;i<ms_num;i++){
					if(ms_value[i].getAttribute('psid')==ps_id) am_str += ms_value[i].getAttribute('name')+' | ';
				}
				am_str = am_str.replace('A1200','明');
				document.getElementById('allmodel').style.display = "block";
				document.getElementById('allmodel').innerHTML = show_ms+'包含机型:&nbsp;'+am_str;
			}
		}else{
			createMessageDiv('There was a problem with the model request,Please reload!',1,10000,400,90,'red',0,90);
		}
	}else{
		var load_str = '<img src="http://www.motogames.com.cn/images/msgloading.gif" align="absmiddle" width="188" height="32" border="0" />';
		document.getElementById('allmodel').innerHTML = load_str;
	}
}

function sendPushModel(ptyep){
	if(ptyep && document.sgp.sgpmode.options.length<=1){
		if(ptyep==1 && tmp_zc_model){
			tmp_model_arry = tmp_zc_model.split('|');
			tmp_model_arry_num = tmp_model_arry.length;
			if(modeltype && modeltype.data==0){
				for(i=0;i<tmp_model_arry_num;i++){
					if(tmp_model_arry[i]) document.sgp.sgpmode.options.add(new Option(tmp_model_arry[i].replace('A1200','明'),tmp_model_arry[i]));
				}
			}else if(modeltype && modeltype.data==1){
				setPushModel();
			}
		}else if(ptyep==2){
			var tmodeltype = xml_gameinfo.getElementsByTagName('istphonesort')[0].childNodes[0];
			if(tmodeltype){
				tmp_model_arry_num = xml_gameinfo.getElementsByTagName('tmodelnum')[0].childNodes[0].data;
				var tag_mod_num = '';
				var tmname = '';
				for(i=0;i<tmp_model_arry_num;i++){
					tag_mod_num = 'tmodel'+i;
					if(tmodeltype.data==0){
						tmname = xml_gameinfo.getElementsByTagName(tag_mod_num)[0].childNodes[0].data;
						document.sgp.sgpmode.options.add(new Option(tmname.replace('A1200','明'),tmname));
					}else if(tmodeltype.data==1){
						tmname += xml_gameinfo.getElementsByTagName(tag_mod_num)[0].childNodes[0].data+'|';
					}
				}
				if(tmname.indexOf('|')>0){
					tmp_model_arry = tmname.split('|');
					setPushModel();
				}
			}
		}
	}
}

function setPushModel(){
	if(tmp_model_arry && tmp_model_arry_num){
		makeRequest();
		var spm_url = 'http://www.motogames.com.cn/newmg/xml/phone_model.xml';
		http_request.onreadystatechange = setPmodel;
		http_request.open('GET', spm_url, true);
		http_request.send(null);
	}
}

function setPmodel(){
	if (http_request.readyState == 4){
		if (http_request.status == 200){
			var xml_doc = http_request.responseXML;
			http_request = null;
			if(!xml_doc){
				createMessageDiv('There was a problem with the XML,Please change IE5.0!',1,10000,400,90,'red',0,90);
				return false;
			}
			var ms_value = xml_doc.getElementsByTagName('Message')[0].childNodes;
			var ms_num = ms_value.length;
			var ps_id = '';
			for(i=0;i<tmp_model_arry_num;i++){
				for(j=0;j<ms_num;j++){
					if(ms_value[j].getAttribute('name')==tmp_model_arry[i]){
						ps_id = ms_value[j].getAttribute('psid');
						for(k=0;k<ms_num;k++){
							if(ms_value[k].getAttribute('psid')==ps_id) document.sgp.sgpmode.options.add(new Option(ms_value[k].getAttribute('name').replace('A1200','明'),ms_value[k].getAttribute('name')));
						}
					}
				}
			}
		}else{
			createMessageDiv('There was a problem with the model request,Please reload!',1,10000,400,90,'red',0,90);
		}
	}
}

function sendGamePush(t_g){
	if(loging){
		alert('正在为您登录!');
		return false;
	}
	if(sending_push){
		alert('正在为您下发PUSH!');
		return false;
	}
	if(submiting_c){
		alert('正在为您提交信息!');
		return false;
	}
	var sppn = document.sgp.pn.value;
	var sppm = document.sgp.sgpmode.value;
	var spvc = document.sgp.valicode.value;
	if(sppn!='' && sppm!=0 && spvc!='' && spvc==getCookie('img_md5_code').substr(0,4)){
		if(/^1\d{10}$/g.test(sppn)){
			if(t_g==1 && !getCookie('NUMBER')){
				createMessageDiv('对不起，您还没有登录!',1,2000,365,90,'red',0,90);
				return false;
			}
			//'&name='+xml_gameinfo.getElementsByTagName('name')[0].childNodes[0].data+
			var push_value = 'sppn='+sppn+'&sppm='+sppm+'&spvc='+spvc+'&sp='+xml_gameinfo.getElementsByTagName('spename')[0].childNodes[0].data+'&gameid='+xml_gameinfo.getElementsByTagName('gid')[0].childNodes[0].data;
			if(t_g==0 && game_no){
				push_value += '&id='+game_no+'&trial='+t_g;
			}else if(t_g==1 && trial_game_no){
				push_value += '&id='+trial_game_no+'&trial='+t_g;
			}else{
				createMessageDiv('游戏编号不正确!',1,2000,365,90,'red',0,90);
				push_value = '';
				return false;
			}
			if(push_value!=''){
				sending_push = true;
				makeRequest();
				var push_url = 'http://www.motogames.com.cn/newmg/user_operate/send_push.php';
				http_request.open('POST', push_url, true);
				http_request.onreadystatechange = pushResult;
				http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				http_request.send(push_value);
			}
		}else{
			createMessageDiv('手机号不正确!',1,2000,365,90,'red',0,90);
		}
	}else{
		createMessageDiv('手机号、手机型号、验证码不能为空,或验证码不正确!',1,2000,365,90,'red',0,90);
	}
}

function pushResult(){
	if (http_request.readyState == 4){
		sending_push = false;
		if (http_request.status == 200){
			closeMessageDiv();
			var rtnResult = http_request.responseText;
			http_request = null;
			if(rtnResult=='ok'){
				createMessageDiv('游戏PUSH下发成功!',1,2000,365,90,0,0,90);
				setTimeout("location.reload();",2000);
			}else if(rtnResult==1){
				createMessageDiv('对不起，您没有登录!',1,2000,365,90,'red',0,90);
			}else if(rtnResult==2){
				createMessageDiv('对不起，验证码输入不正确!',1,2000,365,90,'red',0,90);
			}else if(rtnResult==3){
				createMessageDiv('对不起，手机号不正确!',1,2000,365,90,'red',0,90);
			}else if(rtnResult==4){
				createMessageDiv('对不起，有空值!',1,2000,365,90,'red',0,90);
			}else if(rtnResult==5){
				createMessageDiv('对不起，PUSH下载失败!',1,2000,365,90,'red',0,90);
			}else{
				createMessageDiv('对不起，超出今日发送次数!',1,2000,365,90,'red',0,90);
			}
		}else{
			createMessageDiv('There was a problem with the sendPush request,Please reload!',1,10000,400,90,'red',0,90);
		}
	}else{
		var fs = '<img src="http://www.motogames.com.cn/images/loading.gif" align="absmiddle" width="188" height="32" border="0" />';
		createMessageDiv(fs,0,0,200,90,0,0,90);
	}
}

function submitComment(){
	if(loging){
		alert('正在为您登录!');
		return false;
	}
	if(sending_push){
		alert('正在为您下发PUSH!');
		return false;
	}
	if(submiting_c){
		alert('正在为您提交信息!');
		return false;
	}
	var sc = document.comment.content.value;
	if(sc=='' || sc.getByteLength()>150){
		createMessageDiv('对不起，您没有评论内容或内容超过150个字!',1,2000,365,90,'red',0,90);
	}else{
		var comment_value = 'commentid='+getFileName();
		if(getCookie('NUMBER')) comment_value += '&phonenum='+getCookie('NUMBER');
		comment_value += '&content='+sc;
		if(document.comment.show.checked) comment_value += '&showphone='+document.comment.show.value;
		submiting_c = true;
		makeRequest();
		var submit_url = 'http://www.motogames.com.cn/newmg/user_operate/submit.php';
		http_request.open('POST', submit_url, true);
		http_request.onreadystatechange = submitResult;
		http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		http_request.send(comment_value);
	}
}

function submitResult(){
	if (http_request.readyState == 4){
		submiting_c = false;
		if (http_request.status == 200){
			closeMessageDiv();
			var rtnResult = http_request.responseText;
			http_request = null;
			if(rtnResult=='ok'){
				createMessageDiv('评论提交成功!',1,2000,365,90,0,0,90);
				document.comment.content.value = '';
				showComment();
			}else if(rtnResult==1){
				createMessageDiv('对不起，有空值!',1,2000,365,90,'red',0,90);
			}else if(rtnResult==2){
				createMessageDiv('对不起，评论内容中有屏蔽字符!',1,2000,365,90,'red',0,90);
			}else if(rtnResult==3){
				createMessageDiv('对不起，该IP地址被禁止发表评论!',1,2000,365,90,'red',0,90);
			}else if(rtnResult==4){
				createMessageDiv('对不起，文件生成失败!',1,2000,365,90,'red',0,90);
			}else{
				createMessageDiv('对不起，评论提交失败!',1,2000,365,90,'red',0,90);
			}
		}else{
			createMessageDiv('There was a problem with the sendPush request,Please reload!',1,10000,400,90,'red',0,90);
		}
	}else{
		var fs = '<img src="http://www.motogames.com.cn/images/loading.gif" align="absmiddle" width="188" height="32" border="0" />';
		createMessageDiv(fs,0,0,200,90,0,0,90);
	}
}

function showComment(){
	makeRequest();
	if (!http_request){
		alert('Giving up :( Cannot create an XMLHTTP instance)');
	}else{
		var tmp_rand = parseInt(100*Math.random());
		var fnid = getFileName();
		http_request.open("GET","http://www.motogames.com.cn/newmg/xml/gamessubmit/"+fnid+".xml?"+tmp_rand,false);
		http_request.send(null);
		var xml_doc = http_request.responseXML;
		http_request = null;
		if(!xml_doc){
			createMessageDiv('There was a problem with the XML,Please change IE5.0!',1,10000,400,90,'red',0,90);
			return false;
		}
		var comment_obj = xml_doc.getElementsByTagName('Message')[0];
		if(comment_obj){
			//document.getElementById('showsubcontent').innerHTML = '<div class="comment1_over">&nbsp;&nbsp;游戏任你评：('+xml_doc.getElementsByTagName('Total')[0].childNodes[0].data+')&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.motogames.com.cn/newmg/user_operate/show_more.php?commentid='+ fnid+'" target="_blank">更多评论</a></div>';
			document.getElementById('showsubcontent').innerHTML = '<div class="comment1_over">&nbsp;&nbsp;游戏任你评：('+xml_doc.getElementsByTagName('Total')[0].childNodes[0].data+')</div>';
			var comment_value = comment_obj.childNodes;
			var comment_num = comment_value.length;
			var content,cu,ct,temp;
			for(var i=1;i<comment_num;i++){
				content = comment_value[i].childNodes[0].data;
				temp = content;
				content = content.replace(/\r/g,'<br />').replace(/\n/g,'<br />');
				if(content.length>17) temp = temp.substr(0,17)+'...';
				cu = comment_value[i].getAttribute('cu');
				ct = comment_value[i].getAttribute('ct');
				document.getElementById('showsubcontent').innerHTML += '<div class="comment1" onmouseover="this.className=\'comment1_over\'" onmouseout="this.className=\'comment1_out\'">'+i+'、<a href="javascript:;" onclick="ajaxShowComment(\''+cu+'\',\''+ct+'\',\''+content+'\')" class="font_12" title="点击这里察看完整留言!">'+temp+'</a></div>';
			}
		}else{
			document.getElementById('showsubcontent').innerHTML = '暂无评论';
		}
	}
}

function ajaxShowComment(contuser,conttime,content){
	var asc = '<div class="asc_title">'+conttime+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+contuser+'</div><div class="asc_content">'+content+'</div>';
	createMessageDiv(asc,0,0,400,'auto',0,0,90);
}