$(document).ready(function() {
        
						var min_chars = 3;
								
					  //result texts
						var characters_error = 'Minimum amount of chars is 3';
						var checking_html = 'Checking...';
						var pWord = '';
						var eMail = '';
						
						
				    $("#signupForm").submit(function() {
				      if (pWord && eMail) {
				        //$("span").text("Validated...").show();
				        return true;
				      }
				     // $("span").text("Not valid!").show().fadeOut(1000);
				      return false;
				    });

   
            
            
         
            $("#txtEmail").inputTip({
                // Text displayed when the input passes the validation
                goodText: "available",
                // Text displayed when the input doesn't pass the validation
                badText: "not valid",
                // Text displayed as a tip when the input field is focused
                takenText: "already in use",
                tipText: "Valid Email",
                /* 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 = $('#txtEmail').val();
									
											//use ajax to run the check
											$.post("email_check.php", { username: username },
												function(result){
													var response = 0;
													//if the result is 1
													if(result == 1){
														//var response= 1;
														callback(1);
														eMail=1;
														//alert("available!");
			
													}else{
														callback(3);
														eMail=0
														//var response= '0';
														//alert("not available!");
			
													}
													
												
											});
											//return response;
									} // END checkUser
						
                    var emailRegexp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
                    if (emailRegexp.test(inputValue)) {
                    callback(1);
                    checkUser();
                    eMail=1;
                    
                    }else{ 
                    callback(0);
                    eMail=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
            });

            
            
        }); // end doc ready

