﻿<!--
/*判断依据需求自定*/
function check() {
	var username = document.getElementById('username').value;
	var password = document.getElementById('UserPSW').value;
	
	if (username == "" || username == "邮箱/会员帐号") {
		custom_alert("username", "登录名不能为空");
		return false;
	}
	var filter=/^\s*([A-Za-z0-9_-]+(\.\w+)*@(\w+\.)+\w{2,3})\s*$/;
	if (!filter.test(username)) { 
		custom_alert("username", "登录名必须是邮箱地址");
		return false;}
	if (password == "") {
		custom_alert("password", "密码不能为空");
		return false;
	}
	return true;
}
(function () {
	function $(id) {
		var obj = null;
		if(typeof(id)=='object') obj = id;
		else obj = document.getElementById(id);
		if(!obj) return null;
		return obj;
	}
	function onReady(fn) {
		if (typeof fn != "function") return;
		if (window.addEventListener) {
			window.addEventListener("load", fn, false);
		}else {
			window.attachEvent("onload", fn);
		}
	}
	function set_ns(ns, func) {
		var root = window;
		var ns_p = ns.split(".");
		var current;
		for(var i=0; i<ns_p.length; i++) {
			current = ns_p[i];
			if (!root[current]) {
				root[current] = {};
			}
			if (i == ns_p.length - 1) {
				root[current] = func;
				return;
			}
			root = root[current];
		}
	}
	function addListener(node, type, fn) {
		if(node.addEventListener) node.addEventListener(type,fn,false);
		else node.attachEvent('on' + type,fn);
		return node;
	}
	function hasClass(node, className) {
		var elementClassName = node.className;
		return (elementClassName.length > 0 && (elementClassName == className || new RegExp("(^|\\s)" + className + "(\\s|$)").test(elementClassName)));
	}
	function addClass(node, className) {
		if(!hasClass(node, className)) node.className += (node.className ? ' ' : '') + className;
	}
	function delClass(node, className) {
		node.className = node.className.replace(new RegExp("(^|\\s+)" + className + "(\\s+|$)"), ' ').replace(/(^\s*)|(\s*$)/g, '');
	}
	function show_tip(node) {
		node.style.display = "";
		opacity(node, 0, 100);
	}
	
	var browser = navigator.userAgent.toLowerCase();
	var isIE = /msie/.test(browser);
	var aid = 0;
	var thread = null;
	function stop() {
		thread = null;
	}
	function opacity_a(id, o, start, end, speed, func) {
		if (typeof(window["opacity__"+ id]) != "undefined") clearTimeout(window["opacity__"+ id]);
		var op = Math.abs(start - end);
		if (op == 0) {
			if (func) func();
			if (end == 0) o.style.display = 'none';
			window["opacity__"+ id] = null;
			stop();
			return;
		}
		var opd = speed;
		if (op < speed) opd = op;
		if (start > end) opd *= -1;
		var opm = start + opd;
		if (isIE) o.style.filter = "alpha(opacity="+ opm +")";
		else o.style.opacity = opm / 100;
		window["opacity__"+ id] = window.setTimeout(function(){opacity_a(id, o, opm, end, speed, func)}, 50);
	}
	function opacity(o, start, end, speed, func) {
		if (typeof(o) != "object") o = $(o);
		if (!o) return;
		if (typeof(start) != "number" || typeof(end) != "number") return;
		if (start > 100) start = 100;
		if (start < 0) start = 0;
		if (end > 100) end = 100;
		if (end < 0) end = 0;
		if (start == 0) {
			if (isIE) o.style.filter = "alpha(opacity="+ 0 +")";
			else o.style.opacity = 0;
		}
		speed = typeof(speed) == "number" ? speed : 20;
		var _aid = aid + 1;
		opacity_a(_aid, o, start, end, speed, func);
	}
	
	function init() {
		try {
			var username_node = $("UserName");
			var password_node = $("UserPSW");
			var vcode_node = $("vcode");
			if (username_node) {
				addListener(username_node, "focus", function(e){
					addClass(username_node, "ipt-active");
				//	delClass(username_node, "ipt-c");
					if (username_node.value == "邮箱/会员帐号") username_node.value = "";
					try {
						delClass(username_node, "ipt-error");
						$("username_tip").style.display = "none";
					}catch (e) {}
				});
				addListener(username_node, "blur", function(e){
					delClass(username_node, "ipt-active");
					if (username_node.value == "") {
						username_node.value = "邮箱/会员帐号";
						addClass(username_node, "ipt-c");
					}
				});
			}
			if (password_node) {
				addListener(password_node, "focus", function(e){
					addClass(password_node, "ipt-active");
					try {
						delClass(password_node, "ipt-error");
						$("password_tip").style.display = "none";
					}catch (e) {}
				});
				addListener(password_node, "blur", function(e){
					delClass(password_node, "ipt-active");
				});
			}
			if (vcode_node) {
				addListener(vcode_node, "focus", function(e){
					addClass(vcode_node, "ipt-active");
					try {
						delClass(vcode_node, "ipt-error");
						$("vcode_tip").style.display = "none";
					}catch (e) {}
				});
				addListener(vcode_node, "blur", function(e){
					delClass(vcode_node, "ipt-active");
				});
			}
		}catch (e) {
			throw("node lossed, init fail.");
		}
	}
	onReady(function(){
		init();
	});
	/*
	type - username/password/vcode
	content - alert content.
	*/
	function custom_alert(type, content) {
		$(type + "_tip_text").innerHTML = content;
		show_tip( $(type + "_tip") );
		addClass($(type), "ipt-error");
	}
	set_ns("custom_alert", custom_alert);
})();
//-->
