// 注册帐号校验标识
var registerNameFlag = false;
var passedFlag = false;
var realNameFlag = false;
var identityFlag = false;
var validCodeFlag = false;
var mobilephoneFlag = true;
var spnameFlag = true;
var _message_userName = '';
var _message_password = '';
var _message_realName = '';
var _message_identity = '';
var _message_validCode = '';
var _message_mobilephone = '';
var _message_spname = '';
var _check_finish_userName = false;
var _check_finish_password = false;
var _check_finish_realName = false;
var _check_finish_identity = false;
var _check_finish_validCode = false;
var _check_finish_mobilephone = false;
var _check_finish_spname = false;

$(document).ready(function(){
	if (typeof window['DWRUtil'] == 'undefined') 
        window.DWRUtil = dwr.util; 
    if (typeof window['DWREngine'] == 'undefined') 
        window.DWREngine = dwr.engine; 
    checkSpUserNameInit();
	// 初始化地区
	initialize(document.getElementById('provinceId'), document.getElementById('areaId'), 
			'${provinceId?if_exists}', '${areaId?if_exists}');			
	$('#changeValid').click(function(){
		$('#validCode').val('');
		$('#validCodeInfo').html('');
		document.getElementById('validCode').focus();
		$('#geneValidCode').attr('src', "../valid_code.jsp?id="+ Math.random());
	});	
	$('#registerName').focus();	
	//$('input[@name=rUser.tuijian]').get(0).checked = true;	
	$('#registerSub').click(function(){
		_check_finish_spname = false;
		if (!registerNameFlag) {
			_check_finish_userName = false;
			var name = $('#registerName').val();
			checkRegisterName(name);
		}
		if (!passedFlag) {
			_check_finish_password = false;
			checkRepassword();
		}
		if (!realNameFlag) {
			_check_finish_realName = false;
			var realname = $('#uname').val();
			checkRealName(realname);
		}
		if (!identityFlag) {
			_check_finish_identity = false;
			var cardno = $('#paper').val();
			checkIdentityCard(cardno);
		}
		if (!validCodeFlag) {
			_check_finish_validCode = false;
			var validcode = $('#validCode').val();
			validCodeInfo(validcode);
		}
		if (!mobilephoneFlag) {
			var mobilephone = $('#telephone').val();
			checkMobilePhone(mobilephone);
		}
		checkSpUserName($("#spUserName").val());
		circle = 0;
		checkFinish();
 	});
});

var circle = 0;
function checkFinish(){
	circle = circle + 1;
	if(!_check_finish_identity || !_check_finish_password || !_check_finish_realName ||
			!_check_finish_spname || !_check_finish_userName || !_check_finish_validCode){
		//5秒过后直接提交数据
		if(circle >= 9){
			registerFormPost();
		}else{
			setTimeout(checkFinish , 500);
		}
		return;
	}else{
		if (!registerNameFlag) {
			alert(_message_userName);
			return;
		}
		if (!passedFlag) {
			alert(_message_password);
			return;
		}
		if (!realNameFlag) {
			alert(_message_realName);
			return;
		}
		if (!identityFlag) {
			alert(_message_identity);
			return;
		}
		if (!validCodeFlag) {
			alert(_message_validCode);
			return;
		}
		if (!mobilephoneFlag) {
			alert(_message_mobilephone);
			return;
		}
		registerFormPost();
	}
}

function checkSpUserNameInit(){
	var name = $('#spUserName').val();
	if(name == ''){
		 spnameFlag = true;
		 return;
	}
	$('input[@name=rUser.tuijian]').get(0).checked = true
	RegisterInfoService.spUserCheck(name, {
				callback : function(str){
					if (str == 'S') {
						spnameFlag = true;
						$(":input[name='spUserName']").attr('readonly','readonly');
						$('#spUserNameInfo').attr('style', 'color:#009900;font-size:12px;');
						$('#spUserNameInfo').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 true;
					} else {
						spnameFlag = false;
						if (confirm("您填写的推荐人帐号不存在，是否继续进行注册？")) {
							$('#spUserName').val('');
			 				$('#spUserName').removeAttr('readonly');
			 				$('#spUserNameInfo').html('');
			 				return false;
						} else {
							window.location.href = "../index.html";
						}					
					}
				},
				timeout : 50000,
				errorHandler : function(message) {
					spnameFlag = false;
					alert("网络异常，请刷新页面后重新操作");
					return false;
				}
			});
}

function registerFormPost(){
		if(!spnameFlag){
			alert(_message_spname);
			return;
		}
		document.getElementById('registerSub').style.display = 'none';
		document.getElementById('requestLoad').style.display = 'block';
		$('#register_form').ajaxSubmit({
			url : 'register.do',
			type : 'post',
			dataType : 'json',
			cache : false,
			success : function(data) {
				if (data.error == 'S') {
					window.location.href = "register_success.html?s=" + data.username;
				} else {
					alert(data.message);
					document.getElementById('requestLoad').style.display = 'none';
					document.getElementById('registerSub').style.display = 'block';
					return;
				}  
			}
		});	
}
function daxiaoxie(str){
	$('#registerName').val(str.toLowerCase());
	$('#userNameInfo').attr('style','color:red;font-size:12px;');
	$('#userNameInfo').html('波克城市帐号不区分大小写');
}

function toDBC(Str) {
	var DBCStr = "";
	for (var i = 0; i < Str.length; i++) {
		var c = Str.charCodeAt(i);
		if (c == 12288) {
			DBCStr += String.fromCharCode(32);
			continue;
		}
		if (c > 65280 && c < 65375) {
			DBCStr += String.fromCharCode(c - 65248);
			continue;
		}
		DBCStr += String.fromCharCode(c);
	}
	return DBCStr;
}

// Check User Name
function checkRegisterName(name) {
	if (name == null || name.length == 0) {
		registerNameFlag = false;
		$('#userNameInfo').attr('style', 'color:#FF0000;font-size:12px;');
		$('#userNameInfo').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;" />'
						+ '请输入您要注册的帐号');
		_message_userName = '请输入您要注册的帐号';
		_check_finish_userName = true;
		return;
	}
	name = toDBC(name);
	$('#registerName').val(name)
	RegisterInfoService.registerNameCheck(name, {
		callback : function(str) {
			if (str == 'S') {
				registerNameFlag = true;
				$('#userNameInfo').attr('style', 'color:#009900;font-size:12px;');
				$('#userNameInfo').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;" />');
			} else {
				registerNameFlag = false;
				$('#userNameInfo').attr('style', 'color:#FF0000;font-size:12px;');
				$('#userNameInfo').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);
				_message_userName = str;
				_check_finish_userName = true;
				return;
			}
			_check_finish_userName = true;
		},
		timeout : 50000,
		errorHandler : function(message) {
			registerNameFlag = false;
			alert("网络异常，请刷新页面后重新操作");
			return;
		}
	});
}

function checkPassword() {
	var passwd = $('#iPassword').val();
	var repasswd = $('#rePassword').val();
	if (passwd == '') {
		$('#passwordInfo').attr('style', 'color:#FF0000;font-size:12px;');
		$('#passwordInfo').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;" />'
						+ '请输入您的密码');
		passedFlag = false;
		_message_password = '请输入您的密码';
		_check_finish_password = true;
		return;
	}
	if (passwd.length < 6 || passwd.length > 16) {
		$('#passwordInfo').attr('style', 'color:#FF0000;font-size:12px;');
		$('#passwordInfo').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;" />'
						+ '密码长度必须为6-16位');
		passedFlag = false;
		_message_password = '密码长度必须为6-16位';
		_check_finish_password = true;
		return;
	}
	if (repasswd != '') {
		if (password != repasswd) {
			$('#passwordInfo').attr('style', 'color:#FF0000;font-size:12px;');
			$('#passwordInfo').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;" />');
			$('#rpasswordInfo').attr('style', 'color:#FF0000;font-size:12px;');
			$('#rpasswordInfo').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;" />'
							+ '两次密码输入不一致，请您重新输入');
			passedFlag = false;
			_message_password = '两次密码输入不一致，请您重新输入';
			_check_finish_password = true;
			return;
		} else {
			$('#passwordInfo').attr('style', 'color:#009900;font-size:12px;');
			$('#passwordInfo').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;" />');
			passedFlag = true;
			_check_finish_password = true;
			return;
		}
	}
	$('#passwordInfo').attr('style', 'color:#009900;font-size:12px;');
	$('#passwordInfo').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;" />');
	_check_finish_password = true;
	return;
}

function checkRepassword() {
	var passwd = $('#iPassword').val();
	var repasswd = $('#rePassword').val();
	if (repasswd == '') {
		$('#rpasswordInfo').attr('style', 'color:#FF0000;font-size:12px;');
		$('#rpasswordInfo').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;" />'
						+ '请输入确认密码');
		passedFlag = false;
		_message_password = '请输入确认密码';
		_check_finish_password = true;
		return;
	}
	if (repasswd.length < 6 || repasswd.length > 16) {
		$('#rpasswordInfo').attr('style', 'color:#FF0000;font-size:12px;');
		$('#rpasswordInfo').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;" />'
						+ '确认密码长度必须为6-16位');
		passedFlag = false;
		_message_password = '确认密码长度必须为6-16位';
		_check_finish_password = true;
		return;
	}
	if (passwd != repasswd) {
		if (passwd == '') {
			$('#passwordInfo').attr('style', 'color:#FF0000;font-size:12px;');
			$('#passwordInfo').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;" />'
						+ '请输入您的密码');
			_message_password = '请输入您的密码';
			_check_finish_password = true;
		} else {
			$('#rpasswordInfo').attr('style', 'color:#FF0000;font-size:12px;');
			$('#rpasswordInfo').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;" />'
						+ '两次密码输入不一致，请您重新输入');
			_message_password = '两次密码输入不一致，请您重新输入';
			_check_finish_password = true;
		}
		passedFlag = false;
		return;
	}
	$('#rpasswordInfo').attr('style', 'color:red;font-size:12px;');
	$('#rpasswordInfo').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;" />');
	passedFlag = true;
	_check_finish_password = true;
	return
}

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;" />'
						+ '请输入您的真实姓名');
		_message_realName = '请输入您的真实姓名';
		_check_finish_realName = true;
		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;" />');
				_check_finish_realName = true;
				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);
				_message_realName = str;
				_check_finish_realName = true;
				return;
			}
		},
		timeout : 50000,
		errorHandler : function(message){
			realNameFlag = false;
			alert("网络异常，请刷新页面后重新操作");
			return;
		}
	});
}

function checkIdentityCard(cardno) {
	if (cardno == null || cardno.length == 0) {
		identityFlag = false;
		$('#paperInfo').attr('style', 'color:#FF0000;font-size:12px;');
		$('#paperInfo').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;" />'
						+ '请输入您的身份证号码');
		_message_identity = '请输入您的身份证号码';
		_check_finish_identity = true;
		return;
	}
	RegisterInfoService.checkIdentityCard(cardno, {
		callback : function(str) {
			if (str == 'S') {
				identityFlag = true;
				$('#paperInfo').attr('style', 'color:#009900;font-size:12px;');
				$('#paperInfo').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;" />');
				_check_finish_identity = true;
				return;
			} else {
				identityFlag = false;
				$('#paperInfo').attr('style', 'color:#FF0000;font-size:12px;');
				$('#paperInfo').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);
				_message_identity = str;
				_check_finish_identity = true;
				return;
			}
		},
		timeout : 50000,
		errorHandler : function(message) {
			identityFlag = false;
			alert("网络异常，请刷新页面后重新操作");
			return;
		}
	});
}

function checkMobilePhone(mobilephone) {
	if (mobilephone != '' && mobilephone.length > 0) {
		RegisterInfoService.checkMobilePhone(mobilephone, {
			callback : function(str) {
				if (str == 'S') {
					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;" />');
					_check_finish_mobilephone = true;
					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;" />'
								+ str);
					_message_mobilephone = str;
					_check_finish_mobilephone = true;
					return;
				}
			},
			timeout : 50000,
			errorHandler : function(message) {
				mobilephoneFlag = false;
				alert("网络异常，请刷新页面后重新操作");
				return;
			}
		});
	} else {
		$('#telephoneInfo').attr('style', 'color:#009900;font-size:12px;');
		$('#telephoneInfo').html('');
		mobilephoneFlag = true;
		_check_finish_mobilephone = true;
		return;
	}
}

function validCodeInfo(validCode) {
	RegisterInfoService.checkValidateCode(validCode, {
		callback : function(str) {
			if (str == 'S') {
				validCodeFlag = true;
				$('#validCodeInfo').attr('style', 'color:#009900;font-size:12px;');
				$('#validCodeInfo').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;" />');
				_check_finish_validCode = true;
				return;
			} else {
				validCodeFlag = false;
				$('#validCodeInfo').attr('style', 'color:#FF0000;font-size:12px;font-weight:normal;');
				$('#validCodeInfo').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);
				_message_validCode = str;
				_check_finish_validCode = true;
				return;
			}
		},
		timeout : 50000,
		errorHandler : function(message) {
			validCodeFlag = false;
			alert("网络异常，请刷新页面后重新操作");
			return;
		}
	});
}

function checkSpUserName(name) {
	if (name != '' && name.length > 0) {
		var tuijianTag = $('input[@name=rUser.tuijian][@checked]').val();
		if(tuijianTag == undefined){
			spnameFlag = false;
			alert("请选择推荐人类型");
			_check_finish_spname = true;
			return false;
		}
		if (tuijianTag == 0) {
			RegisterInfoService.spUserCheck(name, {
				callback : function(str){
					if (str == 'S') {
						spnameFlag = true;
						$('#spUserNameInfo').attr('style', 'color:#009900;font-size:12px;');
						$('#spUserNameInfo').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;" />');
						_check_finish_spname = true;
						return true;
					} else {
						spnameFlag = false;
						$('#spUserNameInfo').attr('style', 'color:#FF0000;font-size:12px;');
						$('#spUserNameInfo').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);
						_message_spname = str;
						_check_finish_spname = true;
						return false;
					}
				},
				timeout : 50000,
				errorHandler : function(message) {
					spnameFlag = false;
					alert("网络异常，请刷新页面后重新操作");
					return false;
				}
			});
		} else {
			RegisterInfoService.checkSpMobilePhone(name, {
				callback : function(str) {
					if (str == 'S') {
						spnameFlag = true;
						$('#spUserNameInfo').attr('style', 'color:#009900;font-size:12px;');
						$('#spUserNameInfo').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;" />');
						_check_finish_spname = true;
						return true;
					} else {
						spnameFlag = false;
						$('#spUserNameInfo').attr('style', 'color:#FF0000;font-size:12px;');
						$('#spUserNameInfo').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);
						_message_spname = str;
						_check_finish_spname = true;
						return false;
					}
				},
				timeout : 50000,
				errorHandler : function(message) {
					spnameFlag = false;
					alert("网络异常，请刷新页面后重新操作");
					return false;
				}
			});
		}		
	} else {
		$('#spUserNameInfo').attr('style', 'color:#009900;font-size:12px;');
		$('#spUserNameInfo').html('');
		spnameFlag = true;
		_check_finish_spname = true;
		return true;
	}
}

function validePassword(pwdstring, module) {
	var shu = /^[0-9]/;
	var char = /^[a-zA-Z]/;
	var regm = /^[0-9]{+}/;
	var cs = getCharNum(pwdstring);
	len = pwdstring.length;
	password = $('#iPassword').val();
	if (len == 0) {
		$('#passwordInfo').html("");
		document.getElementById("passlevel").src = "http://png.gc73.com.cn/website_img/dangerous_state.png";
	} else if (0 < len && len < 6) {
		/** 密码长度小于6时 * */
		$('#passwordInfo').attr('style', 'color:red;font-size:12px;');
		$('#passwordInfo').html("密码至少为六位！");
		document.getElementById("passlevel").src = "http://png.gc73.com.cn/website_img/dangerous_state.png";
	} else if (len >= 6 && len <= 8) {
		if (isNaN(password)) {
			if (ifNumberExist(password)) {
				$('#passwordInfo').attr('style', 'color:#009900;font-size:12px;');
				$('#passwordInfo').html("友情提醒：密码最好为数字与字母的组合！");
				document.getElementById("passlevel").src = "http://png.gc73.com.cn/website_img/common_state.png";
			} else {
				$('#passwordInfo').attr('style', 'color:#009900;font-size:12px;');
				$('#passwordInfo').html("友情提醒：再加两个数字或者字符更安全！");
				document.getElementById("passlevel").src = "http://png.gc73.com.cn/website_img/dangerous_state.png";
			}
		} else {
			$('#passwordInfo').attr('style', 'color:#009900;font-size:12px;');
			$('#passwordInfo').html("友情提醒：密码最好为数字与字母的组合！");
			document.getElementById("passlevel").src = "http://png.gc73.com.cn/website_img/dangerous_state.png";
		}
	} else if (len >= 9 && len <= 13) {
		if (isNaN(password)) {
			if (ifNumberExist(password)) {
				/** 不存在数字 * */
				$('#passwordInfo').attr('style', 'color:#009900;font-size:12px;');
				$('#passwordInfo').html("友情提醒：密码最好为数字与字母的组合！");
				document.getElementById("passlevel").src = "http://png.gc73.com.cn/website_img/safety_state.png";
			} else {
				$('#passwordInfo').attr('style', 'color:#009900;font-size:12px;');
				$('#passwordInfo').html("友情提醒：再加两个数字或者字符更安全！");
				document.getElementById("passlevel").src = "http://png.gc73.com.cn/website_img/common_state.png";
			}
		} else {
			$('#passwordInfo').attr('style', 'color:#009900;font-size:12px;');
			$('#passwordInfo').html("友情提醒：密码最好为数字与字母的组合！");
			document.getElementById("passlevel").src = "http://png.gc73.com.cn/website_img/common_state.png";
		}
	} else {
		if (isNaN(password)) {
			if (!ifNumberExist(password)) {
				$('#passwordInfo').attr('style', 'color:#009900;font-size:12px;');
				$('#passwordInfo').html("友情提醒：密码最好为数字与字母的组合！");
				document.getElementById("passlevel").src = "http://png.gc73.com.cn/website_img/common_state.png";
			} else {
				$('#passwordInfo').html('<img src="http://png.gc73.com.cn/images/Fwdw_icons_06.png" width="18" height="18"/>');
				document.getElementById("passlevel").src = "http://png.gc73.com.cn/website_img/safety_state.png";
			}
		} else {
			$('#passwordInfo').attr('style', 'color:#009900;font-size:12px;');
			$('#passwordInfo').html("友情提醒：密码最好为数字与字母的组合！");
			document.getElementById("passlevel").src = "http://png.gc73.com.cn/website_img/safety_state.png";
		}
	}
}

function getCharNum(str){
	var sum = 0;
	for(var i=0; i<str.length; i++){
		if(((str.charCodeAt(i)<=47) || (str.charCodeAt(i)>=57))){
			sum = sum + 1;
		}
	}
	return sum;
}

function ifNumberExist(str) {
   var reg = new RegExp('\w*[0-9]+\w*');
   if(reg.test(str)){
	   return true;
   }
   return false;
}
