/* base functions */
var nU = navigator.userAgent, nA = navigator.appVersion;
var Env = {
	IE: !!(window.attachEvent && !window.opera),
	IE7: nA.indexOf('MSIE 7') != -1,
	IE6: nA.indexOf('MSIE 6') != -1,
	Opera: !!window.opera,
	Safari: nU.indexOf(' AppleWebKit/') != -1, 
	KHTML: (/Konqueror|Safari|KHTML/).test(nU),
	Gecko:  nU.indexOf('Gecko') != -1 && !nU.indexOf('KHTML') != -1
};
nU = nA = null;
function extend(d, s) {
	for (p in s) {
		if (s[p] !== null) d[p] = (typeof(s[p]) == 'object' && !(s[p].nodeType) && !(s[p] instanceof Array)) ? extend({}, s[p]) : s[p];
	}
	return d;
}

var forEach = function(obj, fn) {
	if (!obj) return;
	var isElement = (obj[0] && obj[0].nodeName && obj[0].nodeType == 1) ? true : false;
	if (obj instanceof Array || obj instanceof Function || isElement) {
		for (var i = 0; i < obj.length ; i++) {
			fn.call(obj, obj[i], i);
		}
	} else if (typeof(obj) == 'string' ) {
		for (var i = 0; i < obj.length ; i++) {
			fn.call(obj, obj.charAt(i), i);
		}
	} else if (typeof(obj) == 'object') {
		for (var i in obj) {
			if (typeof Object.prototype[i] == 'undefined' && typeof Element.prototype[i] == 'undefined') {
				fn.call(obj, obj[i], i);
			}
		}
	}
	isElement = null;
};


extend(Function.prototype, {
	bind: function(obj) {
		var fn = this;
		return function() {
			return fn.apply(obj, arguments);
		};
	},
	listen: function(obj) {
		var fn = this;
		return function(event) {
			fn.call(obj, event || window.event);
		};
	}
});

extend(String.prototype, {
	camelCase: function() {
		return this.replace(/-\D/gi, function(match){
			return match.charAt(match.length - 1).toUpperCase();
		});
	},
	trim: function() {
		return this.replace(/^(\s|\r|\n|\r\n)*|(\s|\r|\n|\r\n)*$/g, '');
	},
	tranColor: function() {
		var str = this;
		var regColor = /rgb\s*\(\s*(\d+),\s*(\d+),\s*(\d+)\s*\)/i;
		while (m = regColor.exec(str)) {
			var s = '#';
			for(i = 1; i <= 3; i++) {
				var _s = (m[i] - 0).toString(16);
				s += (m[i] < 16) ? ('0' + _s) : _s;
			}
			str = str.replace(regColor, s);
		}
		return str;
	}
});

extend(Array.prototype, {
	indexOf: function(obj) {
		for (var i = 0; i < this.length; i++) {
			if (this[i] == obj) {
				return i;
			}
		}
		return -1;
	},
	has: function(obj) {
		return this.indexOf(obj) !== -1;
	},
	each: function(fn, obj){
		for (var i = 0; i < this.length ; i++) {
			fn.call(obj, this[i], i);
		}
	}
});

if (typeof Array.prototype.push == 'undefined') {
	extend(Array.prototype,{
		push: function(obj) {
			this[this.length] = obj;
		}
	});
}


var Event = {
	target: function(e) {
		return e.target  || e.srcElement;
	},
	stop: function(e) {
		try{
			e.preventDefault();
			e.stopPropagation();
		} catch(er) {
			e.returnValue = false;
			e.cancelBubble = true;
		}
	}
};


var Element = function(el, arg, doc) {
	doc = doc ? doc : document;
	var attributes = arguments[1] || {};
	if (typeof(el) == 'string') {
		el = reg_gel(doc.createElement(el));
		if (attributes.style) {
			el.setStyle(attributes.style);
			attributes.style = null;
		}
		extend(el, attributes);
	}
	return el;
};

Element.prototype = {
	clean: function() {
		for (var i = 0; i < this.childNodes.length; i++) {
			var node = this.childNodes[i];
			if (node.nodeType == 3 && /\s/.test(node.nodeValue)) this.removeChild(node);
		}
		return this;
	},
	addEvent: function(eventName, fn) {
		fn = fn.listen(this);
		var el = this;
		Unload.listeners.push([el, eventName, fn]);
		
		if (this.addEventListener) {
			if (eventName.toLowerCase() == 'onmousewheel') {
				eventName = 'DOMMouseScroll';
			}
			this.addEventListener(eventName, fn, false);
		} else if(this.attachEvent) {
			this.attachEvent('on' + eventName, fn);
		}
		return this;
	},
	addEvents: function(arg) {
		for (var i in arg) {
			this.addEvent(i, arg[i]);
		}
		return this;
	},
	addClass: function(className) {
		if (className && !this.hasClass(className)) {
			this.className += (this.className ? ' ' : '') + className;
		}
		return this;
	},
	hasClass: function(className) {
		return this.allClass().has(className);
	},
	allClass: function() {
		return this.className.trim().split(/\s+/);
	},
	dropClass: function(className) {
		var classes = this.allClass();
		if (className && classes.has(className)) {
			classes.splice(classes.indexOf(className), 1);
		}
		this.className = classes.join(' ');
		return this;
	},
	dropEvent: function(eventName, fn) {
		if (this.removeEventListener) {
			this.removeEventListener(eventName, fn, false);
		} else if (this.detachEvent) {
			this.detachEvent('on' + eventName, fn);
		}
		return this;
	},
	within: function(x, y) {
		var o = this.getOffset(), s = this.getSize();
		return (y >= o[1] && y <=  o[1] + s[1] && x >= o[0] && x <=  o[0] + s[0]);
	},
	getOffset: function(absoluteOffset) {
		var el = this, offset = [0, 0];
		do {
			offset[0] += el.offsetLeft || 0;
			offset[1] += el.offsetTop  || 0;
			el = reg_gel(el.offsetParent);
			if (!absoluteOffset && el) {
				p = el.getStyle('position');
				if (p == 'relative' || p == 'absolute') break;
			}
		} while (el);
		el = null;
		return offset;
	},
	setStyle: function(style) {
		var value;
		for (var name in style) {
			value = style[name];
			
			if (name.toLowerCase().trim() == 'opacity') {
				this.setOpacity(value);
			} else if (value !== '' && !isNaN(value)) {
				value += 'px';
			}
			try{
				this.style[name.camelCase()] = value;
			} catch(e) {}
		}
		return this;
	},
	getStyle: function(style) {
		var cStyle = style.camelCase();
		var value = this.style[cStyle];
		if ((typeof value == 'undefined' || value == '')) {
			if (document.defaultView) {
				value = document.defaultView.getComputedStyle(this, null).getPropertyValue(style);
				if (Env.Opera && (style == 'width' || style == 'height')) {
					value = '';
				}
			} else if (this.currentStyle) {
				value = this.currentStyle[cStyle];
			}
			if (['margin', 'padding'].has(cStyle) && value == '') {
				return [this.getStyle(cStyle + '-top') || 0, this.getStyle(cStyle + '-right') || 0, this.getStyle(cStyle + '-bottom') || 0, this.getStyle(cStyle + '-left') || 0].join(' ');
			}
		}
		if (typeof value == 'undefined') value = '';
		return value.toString().tranColor();
	},
	setOpacity: function(opacity) {
		opacity = parseFloat(opacity);
		if (Env.IE) {
			this.style.filter = (opacity >= 1) ? '' : 'alpha(opacity=' + opacity * 100 + ')';
		} else {
			this.style.opacity = this.style['MozOpacity'] = opacity;
		}
		return this;
	},
	getSize: function() {
		if (this.style.display.toLowerCase() !== 'none') {
			return [this.offsetWidth, this.offsetHeight];
		}
		var oV = this.style.visibility, oP = this.style.position;
		this.setStyle({visibility: 'hidden', position: 'absolute', display: 'block'});
		var oSize= [this.offsetWidth, this.offsetHeight];
		this.setStyle({visibility: oV, position: oP, display: 'none'});
		return oSize;
	}

};

extend(document, Element.prototype);
extend(document, {
	getScroll: function() {
		return [
			document.body.scrollLeft || document.documentElement.scrollLeft || window.pageXOffset || 0,
			document.body.scrollTop || document.documentElement.scrollTop || window.pageYOffset || 0
		];
	}
});


function reg_gel(el, doc) {
	doc = doc ? doc : document;
	if (typeof(el) == 'string') {
		el = doc.getElementById(el);
	}
	if (el && ((el.nodeName && el.nodeType == 1) || el.nodeType == 9)) {
		if (Unload.elements.has(el)) {
			return el;
		}
		if (typeof el.addEvent == 'undefined') {
		
			extend(el, Element.prototype);
		}
		Unload.elements.push(el);
		return el;
	}
	return false;
}

function $s(options, att, doc) {
	this.options = extend({
		tag: '*',
		parent: document,
		nested: true
	}, options || {});
	
	this.att = att || {};
	if (typeof this.att.id !== 'undefined') {
		return reg_gel(this.att.id);
	}
	var tag = this.options.tag ? this.options.tag.toLowerCase() : '*';
	if (!this.options.parent || !this.options.parent.nodeType) {
		this.options.parent = doc ? doc : document;
	}
	var result = [];
	var els = this.options.nested ? this.options.parent.getElementsByTagName(tag) :  this.options.parent.childNodes;
	Outer:
	for (var i =0; i < els.length; i++) {
		if (!this.options.nested && (els[i].nodeName.toLowerCase() !== tag || els[i].nodeType !== 1)) {
			continue;
		}
		for (var att in this.att) {
			var att1 = att;
			att = att.toLowerCase();
			if (att === 'for') {
				att1 = 'htmlFor';
			}
			if (!(att == 'class' && els[i].className.trim().split(/\s+/).has(this.att[att])) && els[i][att1] !== this.att[att]) {
				continue Outer;
			}
		}
		result.push(reg_gel(els[i]));
	}
	return result;
}

var Load = [];
var Unload = {
	events: [],
	elements: [],
	listeners: [],
	functions: [],
	unload: function() {
		var i;
		for (i = 0; i < Unload.functions.length; i++) {
			Unload.functions[i]();
		}
		for (i = 0; i < Unload.listeners.length; i++) {
			var el = Unload.listeners[i][0];
			var eventName = Unload.listeners[i][1];
			var fn = Unload.listeners[i][2];
			if (el.dropEvent) {
				el.dropEvent(eventName, fn);
			}
			Unload.listeners[i][0] = null;
			Unload.listeners[i][2] = null;
		}
		el = null;
		fn = null;
		for (i = 0; i < Unload.elements.length; i++) {
			Unload.elements[i] = null;
		}
		Unload = null;
		for (i = 0; i < Load.length; i++) {
			Load[i] = null;
		}
		Load = null;
	}
};

window.addEvent = Element.prototype.addEvent;
window.addEvent('unload', Unload.unload);

/*
 * Ajax object
 */
var X = function(n) {
	this.options = extend({
		method: 'post',
		url: null,
		vars: {},
		timeOut: 60000,
		evalScripts: false,
		onStart: null,
		onLoad: null,
		onFail: null,
		onTimeout: null
	}, arguments[0] || {});
	this.options.method = this.options.method.toLowerCase();
	
	['Start', 'Load', 'Fail', 'Timeout'].each(function(v, i) {
		if (this.options['on' + v]) this['on' + v] = this.options['on' + v];
	}, this);
	this.reset().setVars(this.options.vars);
	return this;
};
 
X.prototype = {
	reset: function() {
		clearTimeout(this.timer);
		this.loading = false;
		this.data = '';
		this.vars = {};
		return this;
	},
	getXmlHttp: function() {
		if (window.XMLHttpRequest) {
			return new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			var a = ['Msxml2.XMLHTTP.5.0', 'Msxml2.XMLHTTP.4.0', 'Msxml2.XMLHTTP.3.0', 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP.1.0', 'Microsoft.XMLHTTP.1', 'Microsoft.XMLHTTP'];
			for (var i = 0; i < a.length; i++) {
				try {
					return new ActiveXObject(a[i]);
				} catch (e) {}
			}
		}
		return false;
	},
	setVars: function(vars) {
		var tempVars = this.vars, t;
		if (vars) {
			forEach(vars, function(v, k) {
				if (v instanceof Array) {
					t = [];
					v.each(function(vv) {
						t.push(encodeURIComponent(vv));
					})
				} else {
					t = encodeURIComponent(v);
				}
				tempVars[encodeURIComponent(k.trim())] = t;
			});
		}
		this.vars = tempVars;
		return this;
	},
	getData: function() {
		var temp = [];
		forEach(this.vars, function(v, k) {
			if (k !== '') {
				if (v instanceof Array) {
					v.each(function(vv) {
						temp.push(k + '=' + vv);
					});
				} else {
					temp.push(k + '=' + v);
				}
			} 
		});
		this.data = temp.join('&');
		return this;
	},
	initProxy: function(rDomain) {
		try{
			document.domain = window.location.hostname.split('.').reverse().slice(0,2).reverse().join('.');
		} catch(e) {}
		
		var proxyUrl = 'http://' + rDomain + '/ajaxproxy.htm';
		if (!this.proxyIFrame) {
			this.proxyIFrame = new Element('IFRAME', {src: 'about:blank', style: {display: 'none'}});
			this.proxyIFrame.addEvent('load', this.proxyIFrameLoaded.bind(this));
			document.body.insertBefore(this.proxyIFrame, document.body.childNodes[0]);
			this.proxyIFrame.src = proxyUrl;
		} else {
			//this.proxyXmlhttp = this.proxyIFrame.contentWindow.getTransport();
			//this.send();
			this.proxyIFrameLoaded();
		}
	},
	proxyIFrameLoaded: function() {
		this.xmlhttp = this.proxyIFrame.contentWindow.getTransport();
		this.send();
	},
	getUrlDomain: function(url) {
        var a = new Element('a');
        a.href = url;
        return a.hostname.toLowerCase();
	},
	send: function(url) {
		if (this.loading) return;
		if (url) this.options.url = url;
		
		
		var wDomain = document.domain.toLowerCase(), rDomain = this.getUrlDomain(url);
		if (wDomain !==  rDomain) {
			if (!this.xmlhttp) {
				this.initProxy(rDomain);
				return;
			} 
		} else {
			if (!this.xmlhttp) this.xmlhttp = this.getXmlHttp();
		}
		
		if (this.xmlhttp) {
			this.loading = true;
			this.onStart();
			var self = this;
			this.xmlhttp.onreadystatechange = function() {
				if (self.xmlhttp.readyState == 4) {
					self.response = self.xmlhttp.responseText;
					if (self.options.evalScripts) self.evalScripts(self.response);
					self.status = self.xmlhttp.status;
					self.reset().onLoad();
					self.xmlhttp.onreadystatechange = function() {};
					self.xmlhttp = null;
					self = null;
				} 
			};
		} else {	
			this.onFail();
			return this;
		}
		
		this.setVars({'rndval': new Date().getTime()}).getData();
		if (this.options.method == 'get') {
			this.xmlhttp.open('get', this.options.url + '?' + this.data, true);
		} else {
			this.xmlhttp.open('post', this.options.url, true);
			this.xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			if (this.xmlhttp.overrideMimeType) this.xmlhttp.setRequestHeader('Connection', 'close');
		}
		this.xmlhttp.send(this.data);
		this.timer = setTimeout(this.onTimeout.bind(this), this.options.timeOut); 
		return this;
	},
	abort: function() {
		if (this.loading) this.xmlhttp.abort();
	},
	evalScripts: function(text) {
		if(scripts = text.match(/<script[^>]*?>[\S\s]*?<\/script>/g)) {
			forEach(scripts, function(script) {
				try{
					eval(script.replace(/^<script[^>]*?>/, '').replace(/<\/script>$/, ''));
				} catch(e) {}
			});
		}
	},
	getJSON: function() {
		if (this.response !== '') {
			try{
				return eval('(' + this.response + ')');
			} catch(e) {};
		}
		return false;
	},
	onStart: function() {},
	onLoad: function() {},
	onFail: function() {},
	onTimeout: function() {}
};





/*
 * Auto Complete object
 */


var AutoComplete = function(el) {
	this.el = reg_gel(el);
	this.el.autocomplete = 'off';
	
	this.options = extend({
		url: null,
		form: null,
		mode: 'request'
	}, arguments[1] || {});
	
	if (this.options.form) this.options.form = reg_gel(this.options.form);

	this.panel = new Element('ul', {'className': 'autocomplete_panel', 'style': {
		'border': '1px solid #ccc',
		'background': '#f5f5f5',
		'padding': '1px',
		'margin': '0',
		'list-style': 'none',
		'position': 'absolute',
		'display': 'none'
	}});
	
	var body = document.body;
	_el  = body.childNodes[0];
	body.insertBefore(this.panel, _el);
	//this.el.addEvents({'keydown': this.keydown.bind(this), 'keyup': this.keyup.bind(this), 'blur': this.hidePanelBlur.bind(this)});
	document.addEvent('mousedown', this.hidePanel.bind(this));
	window.addEvent('blur', this.hidePanel.bind(this));
	
	this.items = [];
	this.show = false;
};

AutoComplete.prototype = {
	keydown: function(e) {
		if (e.keyCode == 13) {
			Event.stop(e);
			return false;
		}
	},
	keyup: function(e) {
		if (this.move(e.keyCode, e) === false) {
			this.update();
			Event.stop(e);
		}
	},
	move: function(keyCode, e) {
		if (this.el.value.trim() === '') return;
		if (keyCode == 27) {
			this.hidePanel();
		} else if (keyCode == 38) {
			this._move(-1);
		} else if (keyCode == 13) {
			this[(this.show === true) ? 'hidePanel' : 'showPanel']();
		} else if (keyCode == 40) {
			this._move(1);
		} else {
			return false;
		}
		return true;
	},
	_move: function(direction) {
		var c, l = this.items.length;
		
		if (!this.show) {
			this.panel.style.display = 'block';
			this.show = true;
			return this._move(direction);
		}
		
		if (typeof(this.currentItemIndex) == 'undefined') {
			this.currentItemIndex = -1;
		} 
		c = this.currentItemIndex + direction;
		if (c < -1) c = l - 1;
		
		if (this.items[this.currentItemIndex]) this.items[this.currentItemIndex].setStyle({'background': ''});
		
		if (c < 0 || c >= l ) {
			this.el.value = this.value;
			this.currentItemIndex = -1;
		} else {
			this.el.value = this.items[c].value;
			this.items[c].setStyle({'background': '#d2e3ff'});
			this.currentItemIndex = c;
		}
	},
	update: function() {
		this.value = this.el.value.trim();
		var v = this.value, prefix, mailbox;
		if (v !== '' && /^[^@]+@.+$/i.test(v)) {
			prefix = v.replace(/@.*$/, '');
			
			mailbox = v.replace(/^[^@]+@/, ''); 
			if  (prefix !== '' && /^yah/i.test(mailbox) && ('yahoo.com.cn'.indexOf(mailbox) === 0 || 'yahoo.cn'.indexOf(mailbox) === 0)) {
				
				this.valueItems = [v, [prefix + '@yahoo.com.cn', prefix + '@yahoo.cn', prefix + '@yahoo.com']];
				this.showPanel();
			} else {
				this.hidePanel();
			}
		} else {
			this.hidePanel();
		}
	},
	showPanel: function() {
		if (!this.valueItems) return;
		var p = this.el.getOffset(true), s = this.el.getSize();
		
		items = this.valueItems[1];
		
		this.panel.innerHTML = '';
		var i, l = items.length, item, li, a;
		
		if (l < 1) {
			this.hidePanel();
			return;
		}
		this.items = [];
		this.currentItemIndex = -1;
		
		for (i = 0; i < l; i++) {
			item = items[i];
			li = new Element('li', {style: {
			}});
			a = li.appendChild(new Element('span', {innerHTML: item, style: {
				'line-height': '1.8em',
				'display': 'block',
				'padding': '0 5px',
				'cursor': 'pointer'
				}}));
			a.addEvents({'mouseover': function(){if (this.getStyle('background-color') == '#d2e3ff') return; this.style.backgroundColor = '#fff'}, 'mouseout': function(){if (this.getStyle('background-color') == '#d2e3ff') return; this.style.backgroundColor = ''}});
			a.value = item;
			a.addEvent('click', this.setValue.bind(this));
			this.items.push(a);
			
			this.panel.appendChild(li);
		}
		
		this.show = true;
		this.panel.setStyle({'display': 'block', 'left': p[0], 'top': p[1] + s[1] - 1, 'width': s[0] - 4});
		this.panel.style.zIndex = 500;
	},
	hidePanelBlur: function(e) {
		setTimeout(this.hidePanel.bind(this), 500);
	},
	hidePanel: function(e, forceHide) {
		if (e && !forceHide) {
			var s = document.getScroll();
			if (this.panel.within(e.clientX + s[0], e.clientY + s[1])) {
				return;
			}
		}

		this.show = false;
		if (this.items[this.currentItemIndex]) this.items[this.currentItemIndex].setStyle({'background': ''});
		this.currentItemIndex = -1;
		this.panel.setStyle({'display': 'none'});
		
	},
	setValue: function(e) {
		var el = Event.target(e);
		if (e.nodeName == 'LI') el = el.childNode[0];
		this.el.value = el.value;
		this.hidePanel(null, true);
		this.el.focus();
		Event.stop(e);
	}
};

/* register functions*/



function strlen(str) {
	var len = 0;
	for ( var i = 0; i < str.length; i++) {
		if (str.charCodeAt(i) > 255) {
			len += 2;
		} else {
			len++;
		}
	}
	return len;
}

function chinese(str) {
	var count = 0;
	for ( var i = 0; i < str.length; i++) {
		if (str.charCodeAt(i) > 255)
			count++;
	}
	return count;
}

var LoginCheck = function() {
	this.email = reg_gel('email').addEvents({'focus': this.emailFocus.bind(this), 'blur': this.emailBlur.bind(this)});
	this.emailFocus();
	this.emailBlur();

};
LoginCheck.prototype = {
	emailFocus: function() {
		if (this.email.value == '用户邮箱/手机号/用户名') {
			this.email.value = '';
			this.email.style.color = '#333';
		}
	},
	emailBlur: function() {
		if (this.email.value == '') {
			this.email.value = '用户邮箱/手机号/用户名';
			this.email.style.color = '#888';
		}
	}
};

var defaultTip = {
	'regEmail': '请输入正确的邮箱',
	'nicknameId': '请输入6-20位字母或数字(不含纯数字)',
	'regMobile':'请输入真实的手机号',
	'pwd': '密码必须由6-20个字符组成',
	'pwd2': '输入的确认密码必需与上方密码一致',
	'nickName2': '输入的昵称不能为空',
	'name': '请输入<span style="color: red;font-weight: bold">真实中文姓名</span>，方便朋友查找',
	'icode': '请输入验证码'
};



var code ; //在全局 定义验证码
function createCode(){ 
	code = "";
	var codeLength = 4;//验证码的长度
	var checkCode = document.getElementById("checkCode");
	checkCode.value = "";

	var selectChar = new Array(1,2,3,4,5,6,7,8,9,0,'a','b','c','d','e','f','g','h','i','j','k','l','m','n','p','q','r','s','t','u','v','w','x','t','z');

	for(var i=0;i<codeLength;i++) {
		var charIndex = Math.floor(Math.random()*32);
		code +=selectChar[charIndex];
	}
	if(code.length != codeLength){
		createCode();
	}
	checkCode.value = code;
};

var RegCheck = function() {
	
	this.form = reg_gel('signup_form').addEvent('submit', this.checkForm.bind(this));
	if (reg_gel('regEmail')) reg_gel('regEmail').addEvents({'focus': this.showEmailTip.bind(this), 'blur': this.checkEmail.bind(this)});
	if (reg_gel('icode')) reg_gel('icode').addEvents({'blur': this.checkCode.bind(this), 'focus': this.showCodeTip.bind(this)});
	reg_gel('pwd').addEvents({'blur': this.checkPassword.bind(this), 'focus': this.showPassWordTip.bind(this)});
	reg_gel('pwd2').addEvents({'blur': this.checkPassword2.bind(this), 'focus': this.showpasswd_verifyTip.bind(this)});
	
	reg_gel('nickName').addEvents({'blur': this.checkNickName.bind(this), 'focus': this.showNickNameTip.bind(this)});

	var errorDiv = $s({tag: 'div'}, {'class': 'errors_div'});
	if (errorDiv && errorDiv.length > 0) showPop();
	
	for (tip in defaultTip) {
		var t = reg_gel(tip);
		if (t) t.setAttribute('autocomplete', 'off');
	}
	
	new AutoComplete('regEmail');
	
	this.useDate = false;
	
	this.defaultShowTip = (typeof defaultShowTip === 'undefined') ? false : true;
	if (this.defaultShowTip) {
		for (tip in defaultTip) {
			this.showRegMessage(tip, defaultTip[tip]);
		}
	}
	
	this.regType = 'regEmail';
	
};


RegCheck.prototype = {
	showEmailTip: function() {
		if (reg_gel('regEmail').value === '') {
			this.showRegMessage('regEmail', defaultTip['regEmail'], true);
		}
	},
	showpasswd_verifyTip: function() {
		if (reg_gel('pwd2').value === '') {
			this.showRegMessage('pwd2', defaultTip['pwd2'], true);
		}
	},
	showPassWordTip: function() {
		if (reg_gel('pwd').value === '') {
			this.showRegMessage('pwd', defaultTip['pwd'], true);
		}
	},
	showNickNameTip: function() {
		if (reg_gel('nickName').value === '') {
			this.showRegMessage('nickName', defaultTip['nickName2'], true);
		}
	},
	showCodeTip: function() {
		if (reg_gel('icode').value === '')
		{
			this.showRegMessage('icode', defaultTip['icode'], true);
		}
	},
	hideCodeTip: function() {
		this.hideRegError('icode');
	},
	checkForm: function(e) {
		var formChecked = true;
		if(reg_gel('regEmail')){
			if (reg_gel('regEmail_error_span').hasClass('box-error-error') === true && formChecked === true && reg_gel('regEmail_error_span').style.display=='block') {
				Event.stop(e);
				return false;
			}
			else if (reg_gel('regEmail').value == '')
			{
				this.showRegError('regEmail', '邮箱不能为空');
				Event.stop(e);
				return false;
			}
		}
		if (reg_gel('nickName'))
		{
			if (reg_gel('nickName').value == '')
			{
				this.showRegError('nickName', '昵称不能为空');
				Event.stop(e);
				return false;
			}
			else if (reg_gel('nickName_error_span').hasClass('box-error-error') === true && formChecked === true && reg_gel('nickName_error_span').style.display=='block') {
				Event.stop(e);
				return false;
			}
		}
		if(reg_gel('pwd')){
			if (reg_gel('pwd').value == '') {
				this.showRegError('pwd', '密码不能为空或全部为空格');
				Event.stop(e);
				return false;
			}
			else if (reg_gel('pwd_error_span').hasClass('box-error-error') === true && formChecked === true && reg_gel('pwd_error_span').style.display=='block') {
				Event.stop(e);
				return false;
			}
		}
		if (reg_gel('pwd2'))
		{
			if (reg_gel('pwd2').value == '') {
				this.showRegError('pwd2', '确认密码必需与上方密码相同');
				Event.stop(e);
				return false;
			}
			else if (reg_gel('pwd2_error_span').hasClass('box-error-error') === true && formChecked === true && reg_gel('pwd2_error_span').style.display=='block') {
				Event.stop(e);
				return false;
			}
		}
		if(reg_gel('icode')){
			if (reg_gel('icode').value == '') {
				this.showRegError('icode', '验证码不能为空');
				Event.stop(e);
				return false;
			}else if (reg_gel('icode').value!=reg_gel('checkCode').value){
				this.showRegError('icode', '验证码输入不相同');
				Event.stop(e);
				return false;				
			}else if (reg_gel('icode_error_span').hasClass('box-error-error') === true && formChecked === true && reg_gel('icode_error_span').style.display=='block') {
				Event.stop(e);
				return false;
			}
		}
		
		if(reg_gel('name_error_span') && reg_gel('name_error_span').hasClass('box-error-error') === true){
			if (formChecked === true && reg_gel('name_error_span').style.display=='block') {
				Event.stop(e);
				return false;
			}
		}
		if (reg_gel('regEmail') && (reg_gel('regEmail').id === 'regEmail') && false === this.checkEmail(null, true)) formChecked = false;
		else if (reg_gel('icode') && (reg_gel('icode').id === 'icode')  && false === this.checkCode(null, true)) formChecked = false;
		else if (false === this.checkPassword(null, true)) formChecked = false;
		else if (false === this.checkPassword2(null, true)) formChecked = false;
		else if (false === this.checkNickName(null, true)) formChecked = false;
		
		if (formChecked === false) {
			Event.stop(e);
			return false;
		}
	},
	checkEmail: function(e, submit) {
		this.hideRegError('regEmail');
		var mailValue = reg_gel('regEmail').value;
		if (!submit && mailValue === ''){
		reg_gel('dmmg').style.display = 'none';
		return;
		};
		
		if (mailValue.length > 50) {
			this.showRegError('regEmail', '电子邮箱不能多于50个字符');
			return false;
		} else 
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (!filter.test(mailValue)) {
			this.showRegError('regEmail', '请输入正确的邮箱');
			error = true;
			return false;
		} 
		
		var mailFilter = [/eyou\.com$/i,/yaoyaobuluo\.cn$/i,/love126\.com$/i], k;
		
		if (typeof filterQQ !== 'undefined') {
			mailFilter.push(/qq\.com$/i);
		}
		
		for (k = 0; k < mailFilter.length; k++) {
			if (mailFilter[k].test(mailValue)) {
				this.showRegError('regEmail', '您的邮箱可能收不到激活信');
				return false;
			}
		}
		
		this.checkEmailAjax();
		reg_gel('dmmg').style.display = 'inline';
		return true;
	},
	checkEmailAjax: function() {
		var mailValue = reg_gel('regEmail').value;
		var url = '/reg/email_a';
		var params = {};
		params.email = mailValue;
		Ext.Ajax.request({
			url:url,
			method: 'POST',
			success: this.checkEmailAjaxLoad.createDelegate(this, [], true),
			params:params
		});
		/*if (!this.x) this.x  = new X();
		this.x.onLoad = this.checkEmailAjaxLoad.bind(this);
		this.x.setVars({
			'authType': 'email',
			'value': mailValue,
			't': (new Date()).getTime()
		});
		this.x.send(FORM_AUTH_URL);*/
	},
	checkEmailAjaxLoad: function(response, act) {
		var obj = Ext.decode(response.responseText);
		var rt = obj.data;
		if (rt != 'OK') {
			if(rt ==''){
				this.hideRegError('regEmail');
			}
			else{
				this.showRegError('regEmail', rt);
				return false;
			}
		}
		else {
			this.hideRegError('regEmail');
			reg_gel('dmmg').style.display = 'inline';
			return true;
		}

	},
	checkPassword: function(e, submit) {
		this.hideRegError('pwd');
		var password = reg_gel('pwd').value;
		reg_gel('mmg').style.display = 'none';
		if (!submit && password === '') return;
		password = password.trim();
		if (password === '') {
			this.showRegError('pwd', '请输入密码，不能全部为空格');
			return false;
		}
		if (password.length < 6 || password.length > 20) {
			this.showRegError('pwd', '密码应该在6到20位之间');
			return false;
		}
		if (this.isPwdTooSimple(password) === true) {
			this.showRegError('pwd', '密码过于简单，请修改');
			return false;
		}
		reg_gel('mmg').style.display = 'inline';
		return true;
	},
	checkNickName: function(e, submit) {
		this.hideRegError('nickName');
		var NickName = reg_gel('nickName').value;
		reg_gel('mg_nickName').style.display = 'none';
		if (!submit && NickName === '') return;
		NickName = NickName.trim();
		if (NickName === '')
		{
			this.showRegError('nickName', '输入的昵称不能为空');
			return false;
		}
		reg_gel('mg_nickName').style.display = 'inline';
		return true;
	},
	checkPassword2: function(e,submit){
		this.hideRegError('pwd2');
		var password = reg_gel('pwd').value;
		var password2 = reg_gel('pwd2').value;
		reg_gel('mmg2').style.display = 'none';
		if (!submit && password2 === '') return;
		password2 = password2.trim();
		if (password2 != password)
		{
			this.showRegError('pwd2', '确认密码必需与上方密码相同');
			return false;
		}
		reg_gel('mmg2').style.display = 'inline';
		return true;
	},
	checkCode: function(e,submit) {
		this.hideRegError('icode');
		var code1 = reg_gel('icode').value;
		var trueCode = reg_gel('checkCode').value;
		reg_gel('mg_code').style.display = 'none';
		if (!submit && code1 === '') return;
		code1 = code1.trim();
		if (code1 === '') {
			this.showRegError('icode', defaultTip['icode']);
			return false;
		}
		if (code1 != trueCode)
		{
			this.showRegError('icode', '验证码输入不相同');
			return false;
		}
		reg_gel('mg_code').style.display = 'inline';
		return true;
	},
	isPwdTooSimple: function(pwd) {
		var patrn = /^(\w|\`|\~|\!|\@|\#|\$|\%|\^|\&|\*|\(|\)|\_|\+|\{|\}|\:|\"|\||\<|\>|\?|\=|\-|\]|\[|\\|\'|\;|\/|\.|\,)\1*$/;
		var num = '12345678909876543210';

		if (pwd.length < 6) {
			return true;
		} else if (patrn.test(pwd) == true) {
			return true;
		} else if (num.indexOf(pwd) != -1) {
			return true;
		} else {
			return false;
		}
	},
	showRegMessage: function(field, message, focus) {
		if (reg_gel(field + '_error_span_i')) {
			reg_gel(field + '_error_span_i').innerHTML = message;
			reg_gel(field + '_error_span').addClass(focus ? 'box-error-focus' : '').dropClass('box-error-error').style.display = 'block';
		}
	},
	//提交进入错误页面
	showRegError: function(field, message, isPop) {
		var errorWrap = reg_gel(field + '_error_span'), nameTip;
		
		if (!errorWrap) return;
		if (field == 'regEmail') {
			reg_gel('dmmg').style.display = 'none';
		}
		if (field == 'pwd') {
			reg_gel('mmg').style.display = 'none';
		}
		if (field == 'pwd2')
		{
			reg_gel('mmg2').style.display = 'none';
		}
		if (field == 'icode')
		{
			reg_gel('mg_code').style.display = 'none';
		}
		if (field == 'nickName')
		{
			reg_gel('mg_nickName').style.display = 'none';
		}
		reg_gel(field + '_error_span_i').innerHTML = message;
		errorWrap.dropClass('box-error-focus').addClass('box-error-error').style.display = 'block';
		if (isPop === true) {
			errorWrap.addClass('box-error-pop');
			var p = reg_gel(errorWrap.parentNode);
			if (p.className == 'input_wrap') {
				//errorWrap.style.left = p.offsetWidth + ((['relative', 'absoute'].has(p.getStyle('position'))) ?  -5 :  p.offsetLeft + 10) + 'px';
			}
		};
		

	},
	hideRegError: function(field, isPop) {
		var errorWrap = reg_gel(field + '_error_span');
		if (!errorWrap) return;
		errorWrap.dropClass('box-error-focus').dropClass('box-error-error');
		if (!this.defaultShowTip || isPop === true) {
			errorWrap.style.display = 'none';
			if (field === 'name' && reg_gel('name_tip')) {
				reg_gel('name_tip').style.display = 'none';
			}
		} else {
			if (defaultTip[field]) reg_gel(field + '_error_span_i').innerHTML = defaultTip[field];
		}
	}	
};
 






