if(!aramark){
	var aramark = {}
}
aramark.form = {
	response:[],
	init: function(){
		aramark.form.resizePopup();
		$(window).resize(function(){
			aramark.form.resizePopup();
		});
		$("#enquiriesForm").submit(function(e){												
			e.preventDefault();	
			aramark.form.submit();										
			//aramark.form.showPopup();
		});
		$("#closeBtn").click(function(){
			aramark.form.removePopup();
		});
	},
	resizePopup: function(){
		$("#overlay").css("width", $(document).width());
		$("#overlay").css("height", $(document).height());
		$("#overlay").css("opacity",0.5);
		$("#popupOuter").css("left",($(window).width() /2)-($("#popupOuter").width()/2));											
		$("#popupOuter").css("top",($(window).height() /2)-($("#popupOuter").height()/2));									
	},
	removePopup: function(){
		//$("#overlay").css("display","");
		//$("#popupOuter").css("display","");
		$("#overlay").fadeOut("slow");
		$("#popupOuter").fadeOut("slow");
	},
	showPopup: function(error){
		//$("#overlay").css("display","block");
		//$("#popupOuter").css("display","block");
		if(!error){
			$("#enquiriesForm > *").attr("disabled","disabled");
		}
		$("#overlay").fadeIn("slow");
		$("#popupOuter").fadeIn("slow");		
		$("#overlay").click(function(){
			aramark.form.removePopup();
		});												
	},
	submit: function(){
		var data = $('#enquiriesForm').serialize();
		$.post("../../submitform.php", data, function(result) {
			aramark.form.response = result;
			if(result["error"]){
				var status = "error";//first part of class name
			}else{
				var status = "pass";//first part of class name
			}
			// set classes rather than add them
			$("#popupOuter").attr("class",status+"Outer");
			$("#popupInner").attr("class",status+"Inner");
			// populate with messages
			$("#popupInner > h2").html(result["title"]);
			$("#popupContent").html("<p>"+result["message"]+"</p>");
			// show
			aramark.form.showPopup(result["error"]);			
		},"json");
	}	
}
