
function checkinput(callFun){
		var uname = $.trim($("#regusername").val());
		var pwd1 = $.trim($("#password1").val());
		var pwd2 = $.trim($("#password2").val());
		var email=$.trim($("#email").val());
		var identifycode = $.trim($("#identifycode").val());
		if (uname == "") {
			$("#regusername").focus();
			$("#show_error_msg").html("username couldn't be null");
			return false;
		}
		if (pwd1 == "") {
			$("#password1").focus();
			$("#show_error_msg").html("password couldn't be null");
			return false;
		}
		if (pwd2 == "") {
			$("#password2").focus();
			$("#show_error_msg#").html("repeat password couldn't be null");
			return false;
		}
		if (email == "") {
			$("#email").focus();
			$("#show_error_msg").html("email couldn't be null");
			return false;
		}
		if (identifycode == "") {
			$("#identifycode").focus();
			$("#show_error_msg#").html("identifycode couldn't be null");
			return false;
		}
		if(pwd1!=pwd2){
			$("#show_error_msg").html("password and repeat password are not the same");
			return false;
		}
		$.post("register.do?method=validate&isAjaxPost=isAjaxPost&name="+uname+"&t="+Math.random(),function(data,TextStatus){
			var json=eval("("+data+")");
			if(json.root[0].status=="success"){
				callFun();
				return true;
			}
			else{
				//alert("failure:"+json.root[0].msg);
				$("#show_error_msg").html(json.root[0].msg);
				return false;
				//ArnetMiner_Simple_Dialog("Login failure",json.root[0].msg)
			}
			
		});

//		else if (identifycode == "" || identifycode.length < 4) {
//			$("#identifycode").focus();
//			return false;
//		}
	}

function openRegistDialog(callbackFunc){
$("body").append("<div id='RegistDialog' title='Login Arnetminer:'></div>");
$("#RegistDialog").load("RegistDialog.html",function(){
$('#RegistDialog').dialog({
					autoOpen: false,
					modal:true,
					width: 450,
					draggable:false,
					buttons: {
						"Ok": function() {
							//alert("ok click");
							checkinput(function(){

								//alert($.trim($("#username").val())+$.trim($("#pwd").val())+$.trim($("#identifycode").val()))
								//$.post("http://166.111.134.216:8180/login.do",
									//{isAjaxPost:'isAjaxPost'},
									//function(data,textStatus){alert(data)},"JSON");
								//alert("run me");
								$.post("register.do?method=register",
									{isAjaxPost:'isAjaxPost',username:$.trim($("#regusername").val()),
									oldPassword:$.trim($("#password1").val()),email:$.trim($("#email").val()),
									identifycode:$.trim($("#identifycode").val())},
									//identifycode:$.trim($("#identifycode").val())},
									function(data, textStatus){
										//alert(data);
										var json=eval("("+data+")");
										if(json.root[0].status=="success"){
											
											$("body").append("<div id='loginuserid'>"+json.root[0].userid+"</div>");
											callbackFunc(json.root[0].userid);
											//alert("success!"+json.root[0].msg)
											$('#RegistDialog').dialog("close");
											//window.location.reload(); 
											return json.root[0].userid;
										}
										else{
											//alert("failure:"+json.root[0].msg);
											$("#show_error_msg").empty();
											$("#show_error_msg").append("failure:"+json.root[0].msg);
											//ArnetMiner_Simple_Dialog("Login failure",json.root[0].msg)
										}
										},"JSON");
								//alert("success!");
							//$(this).dialog("close"); 
							
							});
						}, 
						"Cancel": function() { 
						    //ArnetMiner_Simple_Dialog("It is a test","If it shows,It works")
							
							$(this).dialog("close");
							$('#RegistDialog').remove();
							return -1;
						} 
					}
				});
            $('#RegistDialog').dialog("open");
});
}