



// pre-submit callback 
function showRequest(formData, jqForm, options) { 
    // formData is an array; here we use $.param to convert it to a string to display it 
    // but the form plugin does this for you automatically when it submits the data 
    var queryString = $.param(formData); 
 
    // jqForm is a jQuery object encapsulating the form element.  To access the 
    // DOM element for the form do this: 
    // var formElement = jqForm[0]; 
 
    // alert('About to submit: \n\n' + queryString); 
 
    // here we could return false to prevent the form from being submitted; 
    // returning anything other than false will allow the form submit to continue 
    return true; 
} 
         
// post-submit callback 
function showResponse(responseText, statusText)  { 
    // for normal html responses, the first argument to the success callback 
    // is the XMLHttpRequest object's responseText property 
 
    // if the ajaxForm method was passed an Options Object with the dataType 
    // property set to 'xml' then the first argument to the success callback 
    // is the XMLHttpRequest object's responseXML property 
 
    // if the ajaxForm method was passed an Options Object with the dataType 
    // property set to 'json' then the first argument to the success callback 
    // is the json data object returned by the server 
 
    // alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + 
    //    '\n\nThe output div should have already been updated with the responseText.'); 
        
    $('#output').fadeIn('slow');                
}     

function initUserFormValidation (myUserForm) {

        myUserForm.validate({
    		rules: {
    			nickname: {
    				required: true,
    				minlength: 2,
    				maxlength: 20,
    				remote: "jquery-call/check-nickname.html"
    			},
    			password: {
    				required: true,
    				minlength: 6,
    				maxlength: 12
    			},
    			confirmPassword: {
    				required: true,
    				minlength: 6,
    				equalTo: "#password"
    			},
    			email: {
    				required: true,
    				email: true,
    				remote: "jquery-call/check-email.html"
    			},
    			area_code: {
        			number: true
                },
    			mobile: {
        			number: true
                },
    			dob_day: {
        		    required: true
        		},
                gender: {
                    required: true
                },
                region : {
                    required: true
                },
    			tc: {
        			required: true
    			}
    		},
    		
    		messages: {
    			nickname: {
    				required: " ",
    				minlength: jQuery.format(" enter {0} char or more"),
    				maxlength: jQuery.format (" {0} chars max"),
    				remote: jQuery.format(" '{0}' is already taken")
    			},
    			password: {
    				required: " ",
    				rangelength: jQuery.format(" Enter at least {0} characters")
    			},
    			confirmPassword: {
    				required: " ",        				
    				equalTo: " Enter the same password as above"
    			},
    			email: {
    				required: " ",
    				email: "Email invalid",
    				remote: jQuery.format(" '{0}' is already in use")
    			},
    			mobile: {
        			number: " must be number"
                },
    			dob_year: {
        			required: " "
                },
    			dob_month: {
        			required: " "
                },
    			dob_day: {
        			required: " "
                },
    			gender: {
        			required: " "
                },
    			region: {
        			required: " "
                },
                
    			tc: {
        			required: " "
    			}
    		},        		
    		
    		// set this class to error-labels to indicate valid fields
    		success: function(label) {
    			// set &nbsp; as text for IE    			
			    label.html("&nbsp;").addClass("checked");
    		}        		
            
        });
        
        // binding "click" instead of "change" to get around issues with IE 
        myUserForm.bind ("click", function(e){
        myUserForm.valid() ? 
             $("#submit").attr("disabled", false) : 
             $("#submit").attr("disabled", true);
        });
        
        $("#dob").mask("99/99/9999");
                     
}    

function scrollLock(e) {
    var a=e.data.pos;
    window.scrollTo(a[0],a[1]);
    return false;
}

function onOpen(h) {
    var a = [
        self.pageXOffset ||
        document.documentElement.scrollLeft ||
        document.body.scrollLeft
        ,
        self.pageYOffset ||
        document.documentElement.scrollTop ||
        document.body.scrollTop
        ];
    $(window).bind('scroll',{pos: a},scrollLock);
    h.w.show(); // display the jqModal window
}

function onClose(h) {
    $(window).unbind('scroll',scrollLock); // unbinds lock
    h.w.jqmClose(); // hides the jqModal window
}

$.fn.replace = function(o) { return this.after(o).remove(); }; 