$(function(){
    var words=[];
//    words['email'] = ['请填写您常用的邮箱地址, 作为您账号所有权的凭证', '恭喜您, 您输入的邮箱地址可以使用', '邮箱地址不能为空, 请填写您常用的邮箱地址!', '请您填写正确的邮箱地址', '您输入的邮箱地址已被使用, 请选择其他的邮箱进行注册'];
    words['nickname'] = ['用户名长度为2-7个字(可以由中英文,数字,下划线以及特殊字符组成)', '用户名符合规范, 您可以随时在修改资料中进行修改', '对不起, 用户名长度必须在2-7个字之内', '该名称已被注册，请更换'];
    words['cname'] = ['公司名称不能超过50个汉字', '公司名称符合规范', '对不起,公司名称长度必须在2-50个字之内', '该名称已被注册，请更换'];
    words['password'] = ['密码必须为6位以上任意字符, 建议使用数字,字母或特殊字符组合', '密码符合规范', '密码长度6-14位，区分大小写，建议数字、字母、下划线混合！'];
    words['password_confirm'] = ['请重复输入密码, 确保您的密码设置无误', '确认密码正确', '两次输入的密码不一致, 请重新输入'];
//    words['ident'] = ['请输入图片中的字符', '验证码输入正确', '验证码输入错误, 请重新输入'];
//    words['agr'] = [' ', '感谢您的阅读','请详细查看用户协议和版权说明，如有疑问，欢迎反馈给我们'];
	var error = 0;
    var verify_url = "verify.asp?";
	
//    $("img[@name=ident],a[@name=ident]").click(function(){
//        $("img[@name=ident]").attr("src", "ident.asp?flag=register&t="+Math.random());
//        return false;
//    });
	
//    $(":text[@name=email]").blur(function(){
//        var n = this.name;
//        var value = this.value.replace(/((^\s+)|(\s+$))/g, '');
//        if (value==''){
//            notice(n, 2);
//        } else if (!/^[\w-+\.]+@([\w-]+\.)+[\w-]{2,}$/i.test(value)){ 
//            notice(n, 3);
//        } else {
//            $.ajax({
//                url:verify_url+"email="+value,
//                dataType:"json",
//                success:function(data){
//                    notice(n, data.email ? 1 : 4);
//                }
//            });
//        }
//    });

    $(":text[@name=nickname]").blur(function(){
    	var value = this.value.replace(/((^\s+)|(\s+$))/g, '');
        var l = len(value), n = this.name;
        if (l<2 || l>7){
        	notice(n, 2);
        } else {
        	$.ajax({
                url:verify_url+"name="+value,
                dataType:"json",
                success:function(data){
                    notice(n, data.name ? 1 : 3);
                }
            });
        }
    });
	
    $(":text[@name=cname]").blur(function(){
    	var value = this.value.replace(/((^\s+)|(\s+$))/g, '');
        var l = len(value), n = this.name;
        if (l<2 || l>50){
        	notice(n, 2);
        }else {
			notice(n, 1);}
    });
	
//	$(":checkbox[@name=agr]").click(function(){
//        notice(this.name, this.checked ? 1 : 2);
//    });
//	
	$(":password[@name=password]").blur(function(){
        notice(this.name, len(this.value)<6 || len(this.value)>14 ? 2 : 1);
    });
    $(":password[@name=password_confirm]").blur(function(){
        var p = $(":password[@name=password]").val();
        if (len(p)>=6){
            notice(this.name, this.value!=p ? 2 : 1);
        }
    });
    $(":text[@name=ident]").blur(function(){
        var n = this.name;
        if (len(this.value)!=4){
            notice(n, 2);
        } else {
            $.ajax({
                url:verify_url+"ident="+this.value+"&flag=register",
                dataType:"json",
                success:function(data){
                    notice(n, data.ident ? 1 : 2);
                }
            });
        }
    });
    function len(word){
        return word.replace(/ |　/ig, '').length;
    }
    function notice(pos, n){
        var target = $("p[@name=notice_"+pos+"]");
        target.html(words[pos][n]);
        if (n>1){
            target.attr({className:'check_error'});
        } else if(n==1) {
            target.attr({className:'check_right'});
        }
    }
    /*$("#form").submit(function(){
    	checkall();
		if (($("p.check_error").length>0) || ($("p.check_right").length==0)){
            return false;
        }else if(this.email.value == this.nickname.value ==  this.password.value ){
			return false;
		} else {
			return true;
            $("input[@name="+h.k+"]").val(h.v);
        }
    });*/
    $("#form").submit(function(){
		checkall();
		if ($("p.check_error").length > 0 || $("p.check_right").length == 0){
			return false;
        }        
    	$("input[@name="+h.k+"]").val(h.v);
    	return true;
    });
    if ($.browser.msie && $.browser.version == 6){
        $("#nav-index li[@id!='ni-"+$("body").attr("id")+"']").hover(function(){
        	$(this).attr("className", 'selected').find("a").css("color", '#fff');;
        }, function(){
        	$(this).attr("className", 'unselected').find("a").css("color", '#000');;
        });
    }

    $("a#bookmark").click(function(){
        var title = $(this).attr("title") || document.title, url = $(this).attr("url");
        if ($.browser.mozilla){ 
            window.sidebar.addPanel(title, url, ""); 
        } else if($.browser.msie){
            window.external.AddFavorite(url, title);
        }
        return false;
    });
	
	$('a#mainpage').click(function() {
		var title = document.title, url = $(this).attr("url");
		if ($.browser.msie) {
			document.body.style.behavior='url(#default#homepage)';
			document.body.setHomePage(url);
		} else {
			window.sidebar.addPanel(title, url, ""); 
		}
	});
	
	function checkall() {
		$(":password[@name=password_confirm], :password[@name=password]").trigger("blur");
	}

})

