var realNameFlag = false;//初始化时真实姓名有效性状态
var mobilephoneFlag = false;//初始化时联系电话有效性状态 
var validCodeFlag = false;//初始化时验证码有效性状态
var awardDescFlag = false;//初始化时道具描述有效性状态
var gameNameFlag = false;//初始化时游戏名称列表状态
$(document).ready(function(){
	if (typeof window['DWRUtil'] == 'undefined') 
        window.DWRUtil = dwr.util; 
    if (typeof window['DWREngine'] == 'undefined') 
        window.DWREngine = dwr.engine; 
});  
function checkRealName(name) {
	if (name == null || name.length == 0) {
		realNameFlag = false;
		$('#uNameInfo').attr('style', 'color:#FF0000;font-size:12px;');
		$('#uNameInfo').html('<img src="http://png.gc73.com.cn/website_img/error_icon.gif" width="15" height="14" style="vertical-align:bottom;display:inline;position:relative;padding-right:5px;top:-3px;" />'
						+ '请输入您的真实姓名');
		return;
	}
	RegisterInfoService.checkRealName(name, {
		callback : function(str) {
			if (str == 'S') {
				realNameFlag = true;
				$('#uNameInfo').attr('style', 'color:#009900;font-size:12px;');
				$('#uNameInfo').html('<img src="http://png.gc73.com.cn/website_img/right_icon.gif" width="15" height="14" style="vertical-align:bottom;display:inline;position:relative;padding-right:5px;top:-3px;" />');
				return;
			} else {
				realNameFlag = false;
				$('#uNameInfo').attr('style', 'color:#FF0000;font-size:12px;');
				$('#uNameInfo').html('<img src="http://png.gc73.com.cn/website_img/error_icon.gif" width="15" height="14" style="vertical-align:bottom;display:inline;position:relative;padding-right:5px;top:-3px;" />'
								+ str);
				return;
			}
		},
		timeout : 50000,
		errorHandler : function(message){
			realNameFlag = false;
			alert("网络异常，请刷新页面后重新操作");
			return;
		}
	});
}

function checkMobilePhone(mobilephone) {
	if(mobilephone== null || mobilephone == ""){
		mobilephoneFlag = false;
		$('#telephoneInfo').attr('style', 'color:#FF0000;font-size:12px;');
		$('#telephoneInfo').html('<img src="http://png.gc73.com.cn/website_img/error_icon.gif" width="15" height="14" style="vertical-align:bottom;display:inline;position:relative;padding-right:5px;top:-3px;" />'
								+ "联系电话为空");
		return ;
	}
	var reg = /^(\(\d{3,4}\)|\d{3,4}-)?\d{7,8}$|(013?\d{9}$)|(13?\d{9}$)|(15?\d{9}$)|(18?\d{9}$)/;
	if(reg.test(mobilephone)){
		mobilephoneFlag = true;
		$('#telephoneInfo').attr('style', 'color:#009900;font-size:12px;');
		$('#telephoneInfo').html('<img src="http://png.gc73.com.cn/website_img/right_icon.gif" width="15" height="14" style="vertical-align:bottom;display:inline;position:relative;padding-right:5px;top:-3px;" />');
		return;
	}else{
		mobilephoneFlag = false;
		$('#telephoneInfo').attr('style', 'color:#FF0000;font-size:12px;');
		$('#telephoneInfo').html('<img src="http://png.gc73.com.cn/website_img/error_icon.gif" width="15" height="14" style="vertical-align:bottom;display:inline;position:relative;padding-right:5px;top:-3px;" />'
								+ "联系电话输入有误");
		return;
	} 
}

function changeValidateCodeGame(){
	$('#validCodeGame').val('');
	$('#validCodeInfoGame').html('');
	document.getElementById('validCodeGame').focus();
	$('#geneValidCodeGame').attr('src', "valid_code.jsp?id="+ Math.random());
}
function validCodeInfoGame(validCode) {
	RegisterInfoService.checkValidateCode(validCode, {
		callback : function(str) {
			if (str == 'S') {
				validCodeFlag = true;
				$('#validCodeInfoGame').attr('style', 'color:#009900;font-size:12px;');
				$('#validCodeInfoGame').html('<img src="http://png.gc73.com.cn/website_img/right_icon.gif" width="15" height="14" style="vertical-align:bottom;display:inline;position:relative;padding-right:5px;top:-3px;" />');
				return;
			} else {
				validCodeFlag = false;
				$('#validCodeInfoGame').attr('style', 'color:#FF0000;font-size:12px;font-weight:normal;');
				$('#validCodeInfoGame').html('<img src="http://png.gc73.com.cn/website_img/error_icon.gif" width="15" height="14" style="vertical-align:bottom;display:inline;position:relative;padding-right:5px;top:-3px;" />'
								+ str);
				return;
			}
		},
		timeout : 50000,
		errorHandler : function(message) {
			validCodeFlag = false;
			alert("网络异常，请刷新页面后重新操作");
			return;
		}
	});
}

function checkAwardsDescStep(awardsDescStr){
	if( awardsDescStr.length > 5000 ){
		alert("攻略描述不能超过5000字");	
		awardDescFlag = false;
		$('#leaveNumber').html('0');
		document.getElementById("leaveNumber").focus();
		return ;
	}
	awardDescFlag = true;	
	$('#leaveNumber').html(5000-awardsDescStr.length);
	return; 
}
function checkGameName(){
	if($('#gameNameSec').val().replace(/[ ]/g,'') == ""){
		gameNameFlag = false;
		$('#gameNameInfo').attr('style', 'color:#FF0000;font-size:12px;font-weight:normal;');
		$('#gameNameInfo').html('<img src="http://png.gc73.com.cn/website_img/error_icon.gif" width="15" height="14" style="vertical-align:bottom;display:inline;position:relative;padding-right:5px;top:-3px;" />请选择游戏名称');
		return;
	}else{
		gameNameFlag = true;
		$('#gameNameInfo').attr('style', 'color:#009900;font-size:12px;');
		$('#gameNameInfo').html('<img src="http://png.gc73.com.cn/website_img/right_icon.gif" width="15" height="14" style="vertical-align:bottom;display:inline;position:relative;padding-right:5px;top:-3px;" />');
		return;
	}
}
function gameCaptureSubmit(){
	$('#gameCaptureTd').html('<span style="color:red;font-size:16px;font-weight:bold;">提交中。。。</span>');
	validCodeInfoGame($('#validCodeGame').val());
	checkGameName();
	checkAwardsDescStep($('#cooperationAwardDesc').val());
	checkRealName($('#uname').val());
	checkMobilePhone($('#contactMobile').val());
	setTimeout("gameCaptureOk()",300);
}
function gameCaptureOk(){
	if(!validCodeFlag){
		alert("验证码不正确");
		gameCaptureReset();
		return ;
	}
	if(!gameNameFlag){
		alert("请选择游戏名称");
		gameCaptureReset();
		return;
	}
	if(!awardDescFlag){
		alert("游戏攻略输入不正确");
		gameCaptureReset();
		return;
	}
	if(!realNameFlag){
		alert("真实姓名输入不正确");
		gameCaptureReset();
		return;
	}
	if(!mobilephoneFlag){
		alert("联系电话输入不正确");
		gameCaptureReset();
		return;
	}
	$('#gameCaptureForm').ajaxSubmit({
		url : 'gameCapSuggSubmit.do',
		type : 'post',
		dataType : 'json',
		cache : false,
		success : function(data) {
			if (data.error == 'S') {
				alert("提交成功，点击返回主页");
				window.location.href = "index.html";
			}else if(data.error == 'A'){
				alert(data.message);
				ifLogin();
				gameCaptureReset();
			} else {
				alert(data.message);
				gameCaptureReset();
				return;
			}  
		}
	});
}
function gameCaptureReset(){
	$('#gameCaptureTd').html('<a href="javascript:gameCaptureSubmit();"><img src="http://png.gc73.com.cn/website_img/submit_advice.png" width="140" height="29" border="0" /></a>');
}
