$(document).ready(function() {

	$('#rot').cycle();

	$('#content').tabs();

	$(".error").hide();

	$(".button").click(function(){

		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

		var nameVal = $("input.name").val();
		if(nameVal == '') {
			$("input.name").after('<br/><span class="error">You forgot to enter your name.</span>');
			hasError = true;
		}


		var telephoneVal = $("input.telephone").val();
		if(telephoneVal == '') {
			$("input.telephone").after('<br/><span class="error">You forgot to enter your telephone number.</span>');
			hasError = true;
			}


		var emailVal = $("input.email").val();
		if(emailVal == '') {
			$("input.email").after('<br/><span class="error">You forgot to enter your email address.</span>');
			hasError = true;
			}
		else if(!emailReg.test(emailVal)) {
			$("input.email").after('<br/><span class="error">Enter your name.</span>');
			hasError = true;
			}


		var commentsVal = $("#comments").val();
		if(commentsVal == '') {
			$("#comments").after('<br/><span class="error">You forgot to enter your comments.</span>');
			hasError = true;
			}


		if(hasError == false) {
			$(this).hide();
			$("#sendmail .button").append('<img src="img/loading.gif" alt="Loading" id="loading" />');

			$.post("sendmail.php",
   				{ nameFrom: nameVal, emailFrom: emailVal, telephone: telephoneVal, comments: commentsVal },
   					function(data){
						$("#contactform").slideUp("normal", function() {				   
							$("#contactform").before('<h1>Success!</h1><p>Your email has been received and a service representative will be contacting you within the next 24 hours.</p><p>Thank you.</p>');											
						});
   					}
				 );
			}


		return false;

		});
		
		
		
		$(".button2").click(function(){

			var hasError = false;
			var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

			var nameVal = $("input.name2").val();
			if(nameVal == '') {
				$("input.name2").after('<br/><span class="error">You forgot to enter your name.</span>');
				hasError = true;
			}


			var telephoneVal = $("input.telephone2").val();
			if(telephoneVal == '') {
				$("input.telephone2").after('<br/><span class="error">You forgot to enter your telephone number.</span>');
				hasError = true;
				}


			var emailVal = $("input.email2").val();
			if(emailVal == '') {
				$("input.email").after('<br/><span class="error">You forgot to enter your email address.</span>');
				hasError = true;
				}
			else if(!emailReg.test(emailVal)) {
				$("input.email").after('<br/><span class="error">Enter your name.</span>');
				hasError = true;
				}


			var commentsVal = $("#comments2").val();
			if(commentsVal == '') {
				$("#comments2").after('<br/><span class="error">You forgot to enter your comments.</span>');
				hasError = true;
				}


			if(hasError == false) {
				$(this).hide();
				$("#sendmail .button2").append('<img src="img/loading.gif" alt="Loading" id="loading" />');

				$.post("sendmail.php",
	   				{ nameFrom: nameVal, emailFrom: emailVal, telephone: telephoneVal, comments: commentsVal },
	   					function(data){
							$("#contactform2").slideUp("normal", function() {				   
								$("#contactform2").before('<h1>Success!</h1><p>Your email has been received and a service representative will be contacting you within the next 24 hours.</p><p>Thank you.</p>');											
							});
	   					}
					 );
				}


			return false;

			});

		$('#prodLineDiv').hide();

		$('#prodLineBtn').click(function() {
			$('#prodLineDiv').slideToggle();
			});
			
		$('#prodLineBtn').toggle(function() {
				$(this).html('Click here to close.');
			}, function() {
				$(this).html('To view our product line, click here.');
			});

		$('#prodLineBtn').hover(function() {
			$(this).css('color', '#5A5A5A');
		}, function() {
			$(this).css('color', '#4590E9');
		});

});