$(document).ready(function() {
	
     				$('input:checkbox').click(function() {
            var buttonsChecked = $('input:checkbox:checked');
            if (buttonsChecked.length) {
                $('#submitButton').removeAttr('disabled');
                }
            else {
                $('#submitButton').attr('disabled', 'disabled');
                }
            });
            
            
        
						var min_chars = 3;
								
					  //result texts
						var characters_error = 'Minimum amount of chars is 3';
						var checking_html = 'Checking...';
						var uTitle   = '';
						var fName    = '';
						var lName    = '';
						var uUrl     = '';
						var uSSN     = '';
						var uTitle   = '';
						var pWord    = '';
						var uMail    = '';
						var uStreet  = '';
						var uCity    = '';
						var uState   = '';
						var uZip     = '';
						var uCountry = '';
						var uPhone   = '';
						var uDobm		 = '';
						var uDobd    = '';
						var uDoby    = '';

						
						
				    $("#advisorForm").submit(function() {
				      if (fName && lName && uMail && uUrl && pWord && uStreet && uCity && uState && uZip && uCountry && uPhone) {
				        return true; // button active
				      }
				      return false; // not active
				    });

   
 
         
            $("#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 Required",
                /* 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("emailPle_check.php", { username: username },
												function(result){
													var response = 0;
													//if the result is 1
													if(result == 1){
														//var response= 1;
														callback(1);
														uMail=1;
														//alert("available!");
			
													}else{
														callback(3);
														uMail=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();
                    uMail=1;
                    
                    }else{ 
                    callback(0);
                    uMail=0;
                  	}
	
								}, // leave this for validate text
                // True if the validation should be performed on every key/up event (false by default)
                validateInRealTime: false
            });
            
            // Setting up the suggestion box
            $("#txtTitle").inputTip({
                // Text displayed when the input passes the validation
                goodText: "ok...",
                // 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: "Enter a Title for your Site",
                /* 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); 
                    	uTitle=1;
                    	
                    }else{ 
                    	callback(1);
                    	uTitle=0;
                    }
                },
                // True if the validation should be performed on every key/up event (false by default)
                validateInRealTime: false
            });
            
            
            $("#txtUrl").inputTip({
                // Text displayed when the input passes the validation
                goodText: "That website is available!",
                // Text displayed when the input doesn't pass the validation
                badText: "URL must be Valid - www.yourdomain.com",
                // Text displayed as a tip when the input field is focused
                takenText: "Oops, this website is already in use",
                tipText: "example: www.mypaths.com",
                /* 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 checkUrl(){
											
			
											//get the username
											var username = $('#txtUrl').val();
									
											//use ajax to run the check
											$.post("url_check.php", { username: username },
												function(result){
													var response = 0;
													//if the result is 1
													if(result == 1){
														//var response= 1;
														callback(1);
														uUrl=1;
														//alert("available!");
			
													}else{
														callback(3);
														uUrl=0;
														//var response= '0';
														//alert("not available!");
			
													}
													
												
											});
											//return response;
									} // END checkUrl
									
									

						
						          if (inputValue.length > 4){
                    	
                    	checkUrl();
                    	callback(1);
           
                    	uUrl=1;
                    }else{ 
                    callback(0);
                    uUrl=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
            $("#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
            });
            
            
             $("#txtSSN").inputTip({
                // Text displayed when the input passes the validation
                goodText: "Ok...",
                // 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: "Enter Your SSN #",
                /* 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);
                     uSSN=1;
                     
                     
                    }else{
                    callback(1);
                    uSSN=0;
                  }
                },
                // True if the validation should be performed on every key/up event (false by default)
                validateInRealTime: false
            });
            
             $("#txtStreet").inputTip({
                // Text displayed when the input passes the validation
                goodText: "Street Looks Ok!",
                // 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: "Enter Your Street 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.
                    
                    if (inputValue.length > 1){
                     callback(1);
                     uStreet=1;
                     
                     
                    }else{
                    callback(0);
                    uStreet=0;
                  }
                },
                // True if the validation should be performed on every key/up event (false by default)
                validateInRealTime: false
            });
            
             $("#txtCity").inputTip({
                // Text displayed when the input passes the validation
                goodText: "City Looks Ok!",
                // 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: "Enter Your City",
                /* 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);
                    uCity=1;
                     
                     
                    }else{
                    callback(0);
                    uCity=0;
                  }
                },
                // True if the validation should be performed on every key/up event (false by default)
                validateInRealTime: false
            }); 
            
             $("#txtState").inputTip({
                // Text displayed when the input passes the validation
                goodText: "State 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: "Enter Your State",
                /* 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);
                     uState=1;
                     
                     
                    }else{
                    callback(0);
                    uState=0;
                  }
                },
                // True if the validation should be performed on every key/up event (false by default)
                validateInRealTime: false
            });      

              $("#txtCountry").inputTip({
                // Text displayed when the input passes the validation
                goodText: "Country 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: "Enter Your Country",
                /* 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);
                     uCountry=1;
                     
                     
                    }else{
                    callback(0);
                    uCountry=0;
                  }
                },
                // True if the validation should be performed on every key/up event (false by default)
                validateInRealTime: false
            });  
            

             $("#txtZip").inputTip({
                // Text displayed when the input passes the validation
                goodText: "Zip Code 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: "Enter Your Zip Code",
                /* 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);
                     uZip=1;
                     
                     
                    }else{
                    callback(0);
                    uZip=0;
                  }
                },
                // True if the validation should be performed on every key/up event (false by default)
                validateInRealTime: false
            });
            
            
             $("#txtPhoneMain").inputTip({
                // Text displayed when the input passes the validation
                goodText: "Phone Looks Good!",
                // Text displayed when the input doesn't pass the validation
                badText: "Enter at least 1 phone Number",
                // Text displayed as a tip when the input field is focused
                tipText: "Enter Your Main Phone",
                /* 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);
                     uPhone=1;
                     
                     
                    }else{
                    callback(0);
                    uPhone=0;
                  }
                },
                // True if the validation should be performed on every key/up event (false by default)
                validateInRealTime: false
            });            
            
            
            $("#txtDob_m").inputTip({
                // Text displayed when the input passes the validation
                goodText: "Ok...",
                // Text displayed when the input doesn't pass the validation
                badText: "Please select your birth month",
                // Text displayed as a tip when the input field is focused
                tipText: "Enter the month you were born",
                /* 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);
                    	uDobm=1;
                    }else{ 
                    callback(1);
                    uDobm=0;
                  }
                },
                // True if the validation should be performed on every key/up event (false by default)
                validateInRealTime: false
            });
            
            $("#txtDob_d").inputTip({
                // Text displayed when the input passes the validation
                goodText: "Ok...",
                // Text displayed when the input doesn't pass the validation
                badText: "Please enter the day you were born",
                // Text displayed as a tip when the input field is focused
                tipText: "Enter the day of the month you were born",
                /* 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);
                    	uDobd=1;
                    }else{ 
                    callback(1);
                    uDobd=0;
                  }
                },
                // True if the validation should be performed on every key/up event (false by default)
                validateInRealTime: false
            });
            
            $("#txtDob_y").inputTip({
                // Text displayed when the input passes the validation
                goodText: "Ok...",
                // Text displayed when the input doesn't pass the validation
                badText: "Please select the year of your birth",
                // Text displayed as a tip when the input field is focused
                tipText: "Enter the year of your birth",
                /* 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);
                    	uDoby=1;
                    }else{ 
                    callback(1);
                    uDoby=0;
                  }
                },
                // True if the validation should be performed on every key/up event (false by default)
                validateInRealTime: false
            });
                      
            
        }); // end doc ready
