$(document).ready(function() {

	$('#addCarpet').click(function(){
        $("#serviceList").append("<li><a href='JavaScript:void(0);' title='Remove this service'>Carpet Cleaning: <em>" + $('#CarpetedArea').val() + "</em></a></li>");
    });
	
	$('#addRug').click(function(){
        $("#serviceList").append("<li><a href='JavaScript:void(0);' title='Remove this service'>Rug Cleaning: <em>" + $("input[name='RugType']:checked").val() + ": " + $('#NumberofRugs').val() + "</em></a></li>");
    });
	
	$('#addUpholstery').click(function(){
        $("#serviceList").append("<li><a href='JavaScript:void(0);' title='Remove this service'>Upholstery Cleaning: <em>" + $("input[name='UpholsteryType']:checked").val() + ": " + $('#FurnitureType').val() + "</em></a></li>");
    });
	
	$('#addSTG').click(function(){
        $("#serviceList").append("<li><a href='JavaScript:void(0);' title='Remove this service'>Stone Tile and/or Grout <em>" + $('#STGArea').val() + "</em></a></li>");
    });

	
	$('#serviceList li a').live('click', function (){
    	$(this).closest('li').remove();
    });
	
	
	
	$('#SendRequest').click(function(){
		
		function isEmailValid(email){
		var e = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
		return e.test(email);
	}
		
		//Inputed Strings
		var ZipCode = $('#ZipCode').val(),
			YourName = $('#YourName').val(),
			YourPhoneNumber = $('#YourPhoneNumber').val(),
			YourEmail = $('#YourEmail').val(),
			Services = [];
			

		
		
		jQuery("#imessageOK, #imessageERROR").hide();
		jQuery(".required").removeClass("required");
		
		if(jQuery("#ZipCode").val()==""){
			jQuery("#ZipCode").addClass("required");
			return false;
		}
		
		if(jQuery("#YourName").val()==""){
			jQuery("#YourName").addClass("required");
			return false;
		}
		
		if(jQuery("#YourPhoneNumber").val()==""){
			jQuery("#YourPhoneNumber").addClass("required");
			return false;
		}
		
		if(jQuery("#YourEmail").val()==""){
			jQuery("#YourEmail").addClass("required");
			return false;
		}
		
		$("#serviceList li").each(function() {
			Services.push($(this).find('a').text())
		});
			
		jQuery("#SendRequest").val("Please Wait...");
				
		
		jQuery.ajax({
			type: "post",
			url: "http://cleananddry.biz/wp-content/themes/TemplateEleven/quote_send.php",
			data: "ZipCode=" + ZipCode + "&YourName=" + YourName + "&YourPhoneNumber=" + YourPhoneNumber + "&YourEmail=" + YourEmail + "&Services=" + Services,
			success: function(data){
				if(data=='OK'){
					jQuery("#imessageOK").fadeIn();
					jQuery("#SendRequest").val("Send Quote Request!");									 
				} else { 
					jQuery("#imessageERROR").fadeIn();
					jQuery("#SendRequest").val("Send Quote Request!");
				}
			}
			
		});
	});
});
