$(document).ready(function(){
		
			$('#send_domain').click(function(e){
				
				//stop the form from being submitted
				e.preventDefault();
				
				/* declare the variables, var error is the variable that we use on the end
				to determine if there was an error or not */
				var error = false;
				var domainname = $('#domainname').val();
				var type = $('#type').val();

	
				
				//refresh
				$('#domainname_tooshort').fadeOut(0);
				$('#domainname_toolong').fadeOut(0);
				$('#domainname_hyphen').fadeOut(0);
				$('#domainname_errorchars').fadeOut(0);
				$('#domainname_free').fadeOut(0);
				$('#domainname_notfree').fadeOut(0);
				$('#domainname_register').fadeOut(0);
				
				

				//now when the validation is done we check if the error variable is false (no errors)
				if(error == false){
					//disable the submit button to avoid spamming
					//and change the button text to Sending...
					$('#send_domain').attr({'disabled' : 'true', 'value' : 'Even geduld...' });
					
					/* using the jquery's post(ajax) function and a lifesaver
					function serialize() which gets all the data from the form
					we submit it to send_email.php */
					$.post("../../scripts/send_domainname.php", $("#order_form").serialize(),function(result){
						//and after the ajax request ends we check the text returned
						if(result == 'free'){
							//if the mail is sent remove the submit paragraph
							 $('#send_domain').remove();
							 $('#order_form').remove();
							 
							//and show the mail success div with fadeIn
							$('#domainname_free').fadeIn(500);
							document.getElementById('feedback').innerHTML = "\"<b>www." + domainname + "." + type + "</b>\" is nog beschikbaar !";
							document.getElementById('my-item-name-1').value = "<strong>1 jaar domeinnaam</strong>: (" + domainname + "." + type + ")";
							document.getElementById('my-item-name-2').value = "<strong>2 jaar domeinnaam</strong>: (" + domainname + "." + type + ")";
							document.getElementById('my-item-name-3').value = "<strong>3 jaar domeinnaam</strong>: (" + domainname + "." + type + ")";
							$('#domainname_register').fadeIn(500);
							

						
						}
						else if(result == 'tooshort'){
							$('#domainname_tooshort').fadeIn(500);
							//reenable the submit button by removing attribute disabled and change the text back to Send The Message
							$('#send_domain').removeAttr('disabled').attr('value', 'Verzenden');
						}
						else if(result == 'toolong'){
							$('#domainname_toolong').fadeIn(500);
							//reenable the submit button by removing attribute disabled and change the text back to Send The Message
							$('#send_domain').removeAttr('disabled').attr('value', 'Verzenden');
						}
						else if(result == 'hyphen'){
							$('#domainname_hyphen').fadeIn(500);
							//reenable the submit button by removing attribute disabled and change the text back to Send The Message
							$('#send_domain').removeAttr('disabled').attr('value', 'Verzenden');
						}
						
						else if(result == 'errorchars'){
							$('#domainname_errorchars').fadeIn(500);
							//reenable the submit button by removing attribute disabled and change the text back to Send The Message
							$('#send_domain').removeAttr('disabled').attr('value', 'Verzenden');
						}
							
						else if(result == 'notfree'){
							$('#domainname_notfree').fadeIn(500);
							//reenable the submit button by removing attribute disabled and change the text back to Send The Message
							$('#send_domain').removeAttr('disabled').attr('value', 'Verzenden');
						}
						
						else{
							//show the mail failed div
							$('#mail_fail').fadeIn(500);
							//reenable the submit button by removing attribute disabled and change the text back to Send The Message
							$('#send_domain').removeAttr('disabled').attr('value', 'Verzenden');
						}
					});
				}
			});    
			

			
		});
		
		
		
		
		
		
		
		
		
