	   var isEmail = false;
	   
          function is_email(str){
                $('#emailResult').fadeOut();
                var patton = /^(?:\w+[.-])*\w+@(?:\w+[.-])?\w+\.\w+(?:[.-]\w+){0,2}$/;
                if(!patton.exec(str)) {
                    return false;
                }
               
                return true;
            }	

            function is_pwd(str){
				$('#checkPwd').fadeOut();
		
                if( str.length<6) {
                    setTimeout("finishAjax('pwdResult', '"+escape('<span class="form-error">Please enter at least 6 characters.</span>')+"')", 200);
                    return false;
                }
				
                if($('#password').val() != $('#password2').val()){
                    setTimeout("finishAjax('pwdResult', '"+escape('<span class="form-error">Please enter the same value again.</span>')+"')", 200);
                    $('#password').val('');
                    $('#password2').val('');
                    $("#password").focus();
                    return false;
                }

                return true;
            }
	
            function chk_form(){
                if(is_email($('#email').val()) == false){
                    $("#email").focus();
                    return false;
                }
                if(is_pwd($('#password').val()) == false){
                    $("#password").focus();
                    return false;
                }
                if(checkEmail()==false){
                    alert("false");
                    return false;
                }
                
                return true;
            }
            function finishAjax(id, response){
                $('#'+id).html(unescape(response));
                $('#'+id).fadeIn();
            }

            function checkEmail(){
                if(!$('#email').val()) {
                    $('#checkEmail').html('<img src="/images/loading_arrows.gif" />');
                    setTimeout("finishAjax('checkEmail', '"+escape('<span class="form-error">This field is required.</span>')+"')", 200);
                    isEmail = false;
                    return false;
                    
                }else if(!is_email($('#email').val())) {
                    $('#checkEmail').html('<img src="/images/loading_arrows.gif" />');
                    setTimeout("finishAjax('checkEmail', '"+escape('<span class="form-error">Please enter a valid email address.</span>')+"')", 200);
                    isEmail = false;
                    return false;
                    
                }else {
                    $('#emailResult').hide();
                    $('#checkEmail').html('<img src="/images/loading_arrows.gif" />');
                    $.post("../ajaxcheck.php", {
                        email: $('#email').val(),
                        action: 'email'
                    }, function(response){
                        $('#checkEmail').fadeOut();
                        if (response == 'no') {
                            setTimeout("finishAjax('checkEmail', '"+escape('<span class="form-error">Email has been used.</span>')+"')", 200);
                            isEmail = false;
                            return false;
                          
                        } else if(response == 'yes') {
                           
                            setTimeout("finishAjax('checkEmail', '"+escape('<span class="form-yes">Ok.</span>')+"')", 200);
                            return true;
                       }else{
                            setTimeout("finishAjax('checkEmail', '"+escape(response)+"')", 200);
                            isEmail = false;
                            return false;
                           
                        }
                    });
                }
                
            }

            function checPwd(){
                if(!is_pwd($('#password').val())) {
                    $('#checkPwd').html('<img src="/images/loading_arrows.gif" />');
                    isPwd = false;
					return false;
                } else {
					$('#pwdResult').fadeOut();
					setTimeout("finishAjax('checkPwd', '"+escape('<span class="form-yes">Ok.</span>')+"')", 200);
                    isPwd = true;
                    return true;
                }
            }
