if(!idplace)
	var idplace = null;
var Hours = {
	HoursEdit : function(hid) {
		new Ajax.Request(slink+'ajax/business', {
			method : "post",
			parameters : {
				action : "edit hours",
				hid : hid,
				idplace : idplace
			},
			onSuccess : function(transport)
			{
				if(ajaxResponse(transport))
				{
					$("createContainer").innerHTML = transport.responseText;
					$("mainContainer").hide();
					$("createContainer").show();
				}
				else $("createContainer").hide();
			}
		});
	},
	HoursDelete : function(hid) {
		if(!confirm("Are you sure you would like to delete this span of hours?"))
			return;
		notice("Deleting these hours...");
		new Ajax.Request(slink+'ajax/business', {
			method : "post",
			parameters : {
				action : "delete hours",
				hid : hid,
				idplace : idplace
			},
			onSuccess : function(transport)
			{
				if(ajaxResponse(transport))
				{
					document.location = document.location;
				}
			}
		});
	},
	HoursRemove : function(hid) {
		if(!confirm("You are sure you would like to remove hours for this day?"))
			return;
		notice("Deleting hours for this day...");
		new Ajax.Request(slink+'ajax/business', {
			method : "post",
			parameters : {
				action : "delete day hours",
				hid : hid
			},
			onSuccess : function(transport)
			{
				if(ajaxResponse(transport))
				{
					$("bdh" + hid).remove();
					noticeDestroy();
				}
			}
		});
	},
	NewHours : function() {
		new Ajax.Request(slink+'ajax/business', {
			method : "post",
			parameters : {
				action : "new hours"
			},
			onSuccess : function(transport)
			{
				if(ajaxResponse(transport))
				{
					$("createContainer").innerHTML = transport.responseText;
					$("mainContainer").hide();
					$("createContainer").show();
				}
				else $("createContainer").hide();
			}
		});
	},
	Predefined : function() {
			win(600,''+
				'<form id="addToListForm">'+
				'<div class="formText" style="text_small">'+
					'<b>Select one of the following specialty dates</b><br>'+
					'<div><a href="javascript:void(0);" onclick="Hours.SetDay(this);">Martin Luther King Jr Day</a></div>' +
					'<div><a href="javascript:void(0);" onclick="Hours.SetDay(this);">Memorial Day</a></div>' +
					'<div><a href="javascript:void(0);" onclick="Hours.SetDay(this);">Labor Day</a></div>' +
					'<div><a href="javascript:void(0);" onclick="Hours.SetDay(this);">Thanksgiving</a></div>' +
					'<div class="cl"><br>' +
					'<div class="hideArea">'+
						'<input type="submit" class="green" value="Done" onclick="noticeDestroy();">'+
					'</div>'+
				'</div>'+
				'</form>'+
			'');
	},
	SetDay : function(obj) {
		$("txtSpecial").value = $(obj).innerHTML;
		noticeDestroy();
		$("txtTitle").value = $(obj).innerHTML;
		$("txtTitle").disabled = true;
		$("txtStartD").disabled = true;
		$("txtStartM").disabled = true;
		$("txtEndM").disabled = true;
		$("txtEndD").disabled = true;
	},
	ShowHours : function() {
		if($("txtTitle").value == "") {
			alert("You must enter a title for the date range (e.g. General Hours or Fall Hours)");
			return;
		}
		var special = $("txtSpecial").value;
		var sm,sd,em,ed;
		if(special == null || special == "") {
			sm = parseInt($("txtStartM").value);
			sd = parseInt($("txtStartD").value);
			em = parseInt($("txtEndM").value);
			ed = parseInt($("txtEndD").value);
			if(isNaN(sd) || isNaN(ed)) {
				alert("Please enter a number for the date ranges.");
				return;
			}
			if(sd < 1 || ed < 1 || sd > 31 || ed > 31) {
				alert("Please enter a number between 1 and 31 for the dates.");
				return;
			}
		}
		else {
			sm = 0;
			sd = 0;
			em = 0;
			ed = 0;
		}
		new Ajax.Request(slink+'ajax/business', {
			method : "post",
			parameters : {
				action : "save hours span",
				title : $("txtTitle").value,
				start : sm + "-" + sd,
				end : em + "-" + ed,
				special : $("txtSpecial").value,
				idplace : idplace
			},
			onSuccess : function(transport)
			{
				if(ajaxResponse(transport))
				{
					$("hoursSpan").hide();
					$("hoursSpanDisplay").innerHTML = $("txtTitle").value + ($("txtTitle").disabled ? "" : (" between " + sm + "/" + sd + " and " + em + "/" + ed));
					$("hoursSpanDisplay").show();
					$("hoursNextStep").show();
					$("nextstepbutton").value = "Done";
					$("cancelSpan").hide();
					$("nextstepbutton")['onclick'] = new Function("document.location = document.location;");
					if($("txtSpecial").value != "")
						$("AddHoursLink")['onclick'] = new Function("Hours.AddHours('"+$("txtSpecial").value+"');");
				}
			}
		});
	},
	AddHours : function(day) {
		var selday = '<select id="selDay"><option value="Sunday">Sunday</option><option value="Monday">Monday</option>' +
				'<option value="Tuesday">Tuesday</option><option value="Wednesday">Wednesday</option><option value="Thursday">Thursday</option>' +
				'<option value="Friday">Friday</option><option value="Saturday">Saturday</option></select>';
		if(day != null)
			selday = '<select id="selDay"><option value="' + day + '">' + day + '</option></select>';
		win(600,''+
			'<form id="addToListForm">'+
			'<div class="formText" style="text_small">'+
				'<b>Choose a day and hour range. You may add the same day twice for multiple hour spans.</b><br><br>'+
				'<table width="100%"><tr><td rowspan="2">'+selday+'</td>' +
				'<td><b>Open</b> <input type="text" size="2" id="txtHourStart">:<input type="text" size="2" id="txtMinStart"><select id="selAPStart"><option value="AM">AM</option><option value="PM">PM</option></select></td>' +
				'<td rowspan="2"><b>or</b> <select id="selSpecial"><option value=""></option><option value="24 Hours">24 Hours</option><option value="By Appointment">By Appointment</option><option value="Closed">Closed</option></select></td></tr>' + 
				'<tr><td><b>Close</b> <input type="text" size="2" id="txtHourEnd">:<input type="text" size="2" id="txtMinEnd"><select id="selAPEnd"><option value="AM">AM</option><option value="PM">PM</option></select></td></tr></table>' +
				'<div class="cl"><br>' +
				'<div class="hideArea">'+
					'<input type="button" class="green" value="Add Hours For This Day" onclick="Hours.AddDayHour()">'+
				'</div>'+
			'</div>'+
			'</form>'+
		'');
	},
	AddDayHour : function() {	
		var special = $("selSpecial").value;
		var start = "";
		var end = "";
		var day = $("selDay").value;
		if(special == "") {
			start = $("txtHourStart").value + ":" + $("txtMinStart").value + " " + $("selAPStart").value;
			end = $("txtHourEnd").value + ":" + $("txtMinEnd").value + " " + $("selAPEnd").value;
		}
		notice("Saving hours...");
		new Ajax.Request(slink+'ajax/business', {
			method : "post",
			parameters : {
				action : "save hours",
				day : day,
				start : start,
				end : end,
				special : $("selSpecial").value,
				idplace : idplace
			},
			onSuccess : function(transport)
			{
				if(ajaxResponse(transport))
				{
					$("hoursContainer").innerHTML += transport.responseText;
					noticeDestroy();
				}
			}
		});
	},
	HoursCancel : function() {
		$("createContainer").hide();
		$("mainContainer").show();
	}
}