$(document).ready(function() {
        
						var min_chars = 3;
								
					  //result texts
						var characters_error = 'Minimum amount of chars is 3';
						var checking_html = 'Checking...';
						var fName = '';
						var lName = '';
						var uName = '';
						var uNamel= '';
						var pWord = '';
						var eMail = '';
						
						
				    $("#signupForm").submit(function() {
				      if (fName && lName && uName && uNamel && pWord && eMail) {
				        //$("span").text("Validated...").show();
				        return true;
				      }
				     // $("span").text("Not valid!").show().fadeOut(1000);
				      return false;
				    });

        
       
            // Setting up the suggestion box
            $("#txtFirstName").inputTip({
                // Text displayed when the input passes the validation
                goodText: "First name looks good!",
                // Text displayed when the input doesn't pass the validation
                badText: "Ouch, it looks empty!",
                // Text displayed as a tip when the input field is focused
                tipText: "Ok, enter your first name",
                /* Function called to validate the input. It should fire "callback" with the following parameters
                *  First parameter:
                *  - 0: validation failed
                *  - 1: validation succeeded
                *  - 2: show the tip text
                * Second parameter: optional text to display instead of the standard text */
                validateText: function(inputValue, callback) {
                    // Checking if the input field contains text.
                    if (inputValue.length > 0){
                    	callback(1); 
                    	fName=1;
                    	
                    }else{ 
                    	callback(0);
                    	fName=0;
                    }
                },
                // True if the validation should be performed on every key/up event (false by default)
                validateInRealTime: false
            });
            
            $("#txtLastName").inputTip({
                // Text displayed when the input passes the validation
                goodText: "Last name looks good!",
                // Text displayed when the input doesn't pass the validation
                badText: "Hmm, this looks empty!",
                // Text displayed as a tip when the input field is focused
                tipText: "Now, enter your last name",
                /* Function called to validate the input. It should fire "callback" with the following parameters
                *  First parameter:
                *  - 0: validation failed
                *  - 1: validation succeeded
                *  - 2: show the tip text
                * Second parameter: optional text to display instead of the standard text */
                validateText: function(inputValue, callback) {
                    // Checking if the input field contains text.
                    
                    if (inputValue.length > 1){
                     callback(1);
                     lName=1;
                     
                     
                    }else{
                    callback(0);
                    lName=0;
                  }
                },
                // True if the validation should be performed on every key/up event (false by default)
                validateInRealTime: false
            });
            
            
         
            $("#txtUserName").inputTip({
                // Text displayed when the input passes the validation
                goodText: "That username is available!",
                // Text displayed when the input doesn't pass the validation
                badText: "Usernames must be 3 or more characters!",
                // Text displayed as a tip when the input field is focused
                takenText: "Oops, this username is already in use",
                tipText: "Enter a username. it must be unique",
                /* Function called to validate the input. It should fire "callback" with the following parameters
                *  First parameter:
                *  - 0: validation failed
                *  - 1: validation succeeded
                *  - 2: show the tip text
                * Second parameter: optional text to display instead of the standard text */
                validateText: function(inputValue, callback) {
                    // Checking if the input field contains text.
 
	
                    
									function checkUser(){
											
			
											//get the username
											var username = $('#txtUserName').val();
									
											//use ajax to run the check
											$.post("remote_check.php", { username: username },
												function(result){
													var response = 0;
													//if the result is 1
													if(result == 1){
														//var response= 1;
														callback(1);
														uName=1;
														//alert("available!");
			
													}else{
														callback(3);
														uName=0
														//var response= '0';
														//alert("not available!");
			
													}
													
												
											});
											//return response;
									} // END checkUser
						
						
						   if (inputValue.length > 3) {
						   			checkUser();
						   			uNamel=1;
                    }else{ 
                    callback(0);
                    uNamel=0
                  }
	
								}, // leave this for validate text
                // True if the validation should be performed on every key/up event (false by default)
                validateInRealTime: false
            });
            

            $("#txtPassword").inputTip({
                // Text displayed when the input passes the validation
                goodText: "Your Password looks great!",
                // Text displayed when the input doesn't pass the validation
                badText: "Must be 4 or more characters!",
                // Text displayed as a tip when the input field is focused
                tipText: "Enter a password",
                /* Function called to validate the input. It should fire "callback" with the following parameters
                *  First parameter:
                *  - 0: validation failed
                *  - 1: validation succeeded
                *  - 2: show the tip text
                * Second parameter: optional text to display instead of the standard text */
                validateText: function(inputValue, callback) {
                    // Checking if the input field contains text.
                    
                    if (inputValue.length > 4){
                    	callback(1);
                    }else{ 
                    callback(0);
                  }
                },
                // True if the validation should be performed on every key/up event (false by default)
                validateInRealTime: false
            });
            
            $("#txtCPassword").inputTip({
                // Text displayed when the input passes the validation
                goodText: "The passwords match!",
                // Text displayed when the input doesn't pass the validation
                badText: "Sorry, Passwords must match.",
                // Text displayed as a tip when the input field is focused
                tipText: "Enter the same password again",
                /* Function called to validate the input. It should fire "callback" with the following parameters
                *  First parameter:
                *  - 0: validation failed
                *  - 1: validation succeeded
                *  - 2: show the tip text
                * Second parameter: optional text to display instead of the standard text */
                validateText: function(inputValue, callback) {
                    // Checking if the input field contains text.
                    
                    if ($("#txtCPassword").val() == $("#txtPassword").val()) { 
                    	callback(1);
                    	pWord=1;
                    }else{ 
                    callback(0);
                    pWord=0;
                  }
                },
                // True if the validation should be performed on every key/up event (false by default)
                validateInRealTime: false
            });


            // Setting up the suggestion box
            $("#txtEmail").inputTip({
                // Text displayed when the input passes the validation
                goodText: "This email looks to be valid!",
                // Text displayed when the input doesn't pass the validation
                badText: "Hmm, it doesn't look like an email!",
                // Text displayed as a tip when the input field is focused
                tipText: "Type an email address",
                /* Function called to validate the input. It should fire "callback" with the following parameters
                *  First parameter:
                *  - 0: validation failed
                *  - 1: validation succeeded
                *  - 2: show the tip text
                * Second parameter: optional text to display instead of the standard text */
                validateText: function(inputValue, callback) {
                // Checking if the input field contains text.
                    var emailRegexp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
                    if (emailRegexp.test(inputValue)) {
                    callback(1);
                    eMail=1;
                    
                    }else{ 
                    callback(0);
                    eMail=0;
                  }
                },
                // True if the validation should be performed on every key/up event (false by default)
                validateInRealTime: false
            }); // end email tooltip
            
            
        }); // end doc ready

