$(document).ready(function(){
	$('.error').hide(); 
	$('#commentscomments').hide();
	$('#websitecomment').hide();
	$('#keywordcomment').hide();
	$('#formtext').hide();

		function showAskQOpt(){
				  $('#commentscomments').show();
				  $('#emailcomment').show();
				  $('#websitecomment').hide();
				  $('#keywordcomment').hide();
				  $('#formtext').hide();
				  return false;
		}
		function showSpeakOpt(){
					$('#emailcomment').hide();
					$('#commentscomments').hide();
					$('#websitecomment').hide();
					$('#keywordcomment').hide();
					$('#formtext').hide();
				  return false;	
		}
		function showRequestOpt(){
					$('#websitecomment').show();
					$('#emailcomment').show();
					$('#commentscomments').hide();
					$('#keywordcomment').hide();
					$('#formtext').hide();
				  return false;	
		}
		function showInqPOpt(){
					$('#websitecomment').show();
					$('#keywordcomment').show();
					$('#emailcomment').hide();
					$('#commentscomments').hide();
					$('#formtext').hide();
				  return false;	
		}
		function reqWhitePaper(){
					$('#formtext').show();
					$('#emailcomment').hide();
					$('#commentscomments').hide();
					$('#websitecomment').hide();
					$('#keywordcomment').hide();
		}		
		function initiOpt(){
					$('#emailcomment').show();
					$('#commentscomments').hide();
					$('#websitecomment').hide();
					$('#keywordcomment').hide();
					$('#formtext').hide();
					return false;	
		}

	// hides/shows fields onload - init
	var initopt = $('#request_option option:selected').val();
	if(initopt=='Ask Us a Question'){
	  showAskQOpt();
	}else if(initopt=='Speak to a SEO Expert'){
		showSpeakOpt();
	}else if(initopt=='Request SEO Analysis'){
		showRequestOpt();
	}else if(initopt=='Inquire about Pricing'){
		showInqPOpt();
	}else if(initopt=='Download a Whitepaper'){
		reqWhitePaper();
	}else{
		initiOpt();
	}		
/*$(function() {*/
	var option = $('#request_option option:selected').val();
	$('#request_option').change(function(){ // when pulldown is triggered, hide, show fields
		option = $('#request_option option:selected').val();
		if(option=='Ask Us a Question'){
		  showAskQOpt();
		}else if(option=='Speak to a SEO Expert'){
			showSpeakOpt();
		}else if(option=='Request SEO Analysis'){
			showRequestOpt();
		}else if(option=='Inquire about Pricing'){
			showInqPOpt();
		}else if(option=='Download a Whitepaper'){
			reqWhitePaper();
		}else{
			initiOpt();
		}
	});

   $("#submit_short_form").click(function(){ //submit button is triggered
														 
			var name = $("input#name").val();
			if (name == "") {
			  $("span#name_error").show();
			  $("input#name").focus();
			  //alert('name is empty');	
			  return false;
			}
			
			var email = $("input#email").val();
			if($('#email').is(':visible')){
				if (email == "") {
				  $("span#email_error").show();
				  $("input#email").focus();
				  //alert('email is empty');	
				  return false;			
				}
			}else{email='';}			
			
			var phone = $("input#phone").val();
			if (phone == "") {
			  $("span#phone_error").show();
			  $("input#phone").focus();
			  //alert('phone is empty');
			  return false;				
			}
			var comments = $("textarea#comments").val();
			if($('#commentscomments').is(':visible')){
				if (comments == "") {
				  $("span#comments_error").show();
				  $("textarea#comments").focus();
				  //alert('comments is empty');
				  return false;
				}
			}else{comments='';}
									
			var website = $("input#website").val();
			if($('#websitecomment').is(':visible')){
				if (website == "") {
				  $("span#website_error").show();
				  $("input#website").focus();
				  //alert('website is empty');	
				  return false;				
				}
			}else{website='';}
			
			var keyword = $("textarea#keyword").val();
			if($('#keywordcomment').is(':visible')){
				if (keyword == "") {
				  $("span#keyword_error").show();
				  $("textarea#keyword").focus();
				  //alert('keyword is empty');	
				  return false;
				}
			}else{keyword='';}
			
	  var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone + '&option=' + option + '&comments=' + comments + '&keyword=' + keyword + '&website=' + website ;
	  //alert (dataString); return false;
	  
	  $.ajax({
		 type: "POST",
		 url: "/bin/process.php",
		 data: dataString,
		 success: function() {
			$('#sh_contect_form').html("<div id='message'></div>");
			$('#message').html("<h2 style='margin-top:0;'>Your Info Submitted!</h2>")
				.append("<p style='line-height:18px;'>Thank you for your interest in YellowSEO. We will be in touch soon.</p>")
				.hide()
				.fadeIn(1500, function() {
			   //$('#message').append("<img id='checkmark' src='images/check.png' />");
			});
		 }
	  });
	  return false;
    });
/*  });*/
});
