Event.observe(window,"load",function(){
	if(o = $("businessList"))
	{
		Event.observe(o,"change",function(event){
			var e = Event.element(event);
			if(e.value != "")
			{
				var page = location.href.match(/[a-zA-Z_]+\.html/g);
				location.href = businesslink+page+"?id="+e.value;
			}
		});
	}
	var a = $$(".deleteableEvent");
	for(var i=0;i<a.length;i++)
	{
		Event.observe(a[i],"click",EventDelete.Do);
	}
});

var EventDelete = {
	Do : function(event)
	{	
		var e = Event.element(event);
		holder = e.up(".event");
		holder.hide();
		new Ajax.Request(slink+'ajax/business', {
			method : "post",
			parameters : {
				action : "delete event",
				idrow : e.getAttribute("idrow")
			},
			onSuccess : function(transport)
			{
				if(ajaxResponse(transport))
				{
					holder.remove();	
					var a = $$(".event");
					if(a.length == 0)
					{
						$("posts").update('<div id="none">You have no new events or notifications for this business.</div>');
					}
				}
				else				
				{
					holder.show();	
				}
			}
		});
	}
}

function Claim(obj) {
	var par = $(obj).up(".place");
	if(par.down(".init").value == "") {
		alert("Please enter your initials to certify that you claimed this business.");
		return;
	}
	var bid = par.getAttribute("uid");
	notice("Please wait, claiming your business...");
	new Ajax.Request(slink+'ajax/business', {
		method : "post",
		parameters : {
			action : "claim business",
			bid : bid
		},
		onSuccess : function(transport)
		{
      alert(transport.responseText);
			par.down(".init").up().innerHTML = "You are in control of this";
			noticeDestroy();
		}
	});
}

function SwitchEmployee(uid) {
  notice("Switching...");
	new Ajax.Request(slink+'ajax/business', {
		method : "post",
		parameters : {
			action : "switch user",
			uid : uid
		},
		onSuccess : function(transport)
		{
			document.location = document.location;
		}
	});
}

function DoBusLogin(ind) {
  notice("Just a moment, logging in...");
	new Ajax.Request(slink+'ajax/business', {
		method : "post",
		parameters : {
			action : "business login",
			txtBusUsername : $("txtBusUsername").value,
			txtBusPassword : $("txtBusPassword").value
		},
		onSuccess : function(transport)
		{
      if(transport.responseText == "failed")
        document.location = document.location;
      else if(ind)
        document.location = businesslink;
      else
        document.location = document.location;
		}
	});
}

function ChangeEmployee() {
  if($("showOtherUsers").style.display == "none")
    $("showOtherUsers").show();
  else
    $("showOtherUsers").hide();
}

function JoinEmployee(e,b,obj,hourly) {
	notice("Adding this employee to your business...");
	new Ajax.Request(slink+'ajax/business', {
		method : "post",
		parameters : {
			action : "join employee",
			e : e,
			b : b,
			hourly : hourly
		},
		onSuccess : function(transport)
		{
			if(ajaxResponse(transport)) {
				location.href = location.href;
			}
		}
	});
}

function NewEmployee() {
	new Ajax.Request(slink+'ajax/business', {
			method : "post",
			parameters : {
				action : "new employee"
			},
			onSuccess : function(transport)
			{
				if(ajaxResponse(transport))
				{
					$("createContainer").innerHTML = transport.responseText;
					$("searchadd").hide();
					$("createContainer").show();
				}
				else $("createContainer").hide();
			}
		});
}
function NewEmployeeCancel() {
	$("createContainer").hide();
	$("searchadd").show();
}
function NewEmployeeSave() {
	notice("Creating Gathergo user account for employee...");
	new Ajax.Request(slink+'ajax/business', {
			method : "post",
			parameters : {
				action : "signup employee",
				name : $("txtName").value,
				phonenumber : $("txtPhone").value,
				email : $("txtEmail").value,
				timezone : new Date().getTimezoneOffset()
			},
			onSuccess : function(transport)
			{
				if(ajaxResponse(transport))
				{
					var data = eval("(" + transport.responseText + ")");
					var eid = data['id'];
					JoinEmployee(eid,null,null,$("hourly").checked);
				}
			}
		});
}
function EmployeeSettings(obj) {
	if($(obj).id == "manall") {
		$("manemp").disabled = $("manall").checked;
		$("manset").disabled = $("manall").checked;
		$("manemp").checked = $("manall").checked;
		$("manset").checked = $("manall").checked;
	}
	else if($(obj).id == "manemp") {
		$("manset").disabled = $("manemp").checked;
		$("manset").checked = $("manemp").checked;
	}
	if($(obj).id == "manall" || $(obj).id == "manemp") {
		$("edit").disabled = $("manemp").checked;
		$("photos").disabled = $("manemp").checked;
		$("menus").disabled = $("manemp").checked;
		$("comments").disabled = $("manemp").checked;
		$("edit").checked = $("manemp").checked;
		$("photos").checked = $("manemp").checked;
		$("menus").checked = $("manemp").checked;
		$("comments").checked = $("manemp").checked;
	}
}
function UndisableEmployeeSettings() {
	$("manemp").disabled = false;
	$("manset").disabled = false;
	$("edit").disabled = false;
	$("photos").disabled = false;
	$("menus").disabled = false;
	$("comments").disabled = false;
}
function DisableEmployeeSettings() {
	if($("manall").checked)
		EmployeeSettings($("manall"));
	if($("manemp").checked)
		EmployeeSettings($("manemp"));
}
var BusinessMessage = {
  Post : function() {
    win(650,'<div>Please select the degree of severity, select concerned parties, and fill in a brief note.</div><br>'+
			             '<div style="padding:3px;padding-left:30px">Severity:</div>'+
			             '<div style="padding:3px;padding-left:30px"><select id="severity"><option value="10">Normal</option><option value="5">Important</option><option value="1">Critical</option></select></div>'+
			             '<div style="padding:3px;padding-left:30px">People:</div>'+
			             '<div style="padding:3px;padding-left:30px" id="peoplediv"><img src="images/loading.gif"></div>'+
			             '<div style="padding:3px;padding-left:30px">Note:<br><textarea id="txtmsg" cols="60" rows="4"></textarea><br>'+
			             '<div><input type="button" value="Send" class="green" onclick="BusinessMessage.Send();">&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="Cancel" class="red" onclick="noticeDestroy();"></div>');
    
    new Ajax.Request(slink+'ajax/business', {
				method : "post",
				parameters : {
					action : "get people options"
				},
				onSuccess : function(transport)
				{
					if(ajaxResponse(transport,false))
					{
							$("peoplediv").innerHTML = ' <select multiple size="5" style="width:200px" id="people">'+transport.responseText+'</select>';
					}
				}
			});
  },
  Send : function() {
    notice("Sending your note...");
    var ppl = "" + $("people").getValue();
    new Ajax.Request(slink+'ajax/business', {
				method : "post",
				parameters : {
					action : "send business note",
					severity: $("severity").getValue(),
					people: ppl,
					txtmsg: $("txtmsg").getValue()
				},
				onSuccess : function(transport)
				{
					if(ajaxResponse(transport,false))
					{
							document.location.reload();
					}
				}
			});
  }
}
var Schedule = {
	SpecificDay : function() {
		if($("generalDate").style.display == "none") {
			$("generalDate").show();
			$("specificDate").hide();
			$("sdText").innerHTML = "or specific day";
		}
		else {
			$("generalDate").hide();
			$("specificDate").show();
			$("sdText").innerHTML = "or general day";
		}
	},
	AddSchedule : function() {
		notice("Adding this employee to the schedule...");
		new Ajax.Request(slink+'ajax/business', {
			method : "post",
			parameters : {
				action : "add schedule",
				eid : $("employeeList").value,
				day : $("daysList").value,
				month : $("month").value,
				date : $("day").value,
				start : $("shr").value+":"+$("smin").value+" "+$("startAP").value,
				end : $("ehr").value+":"+$("emin").value+" "+$("endAP").value
			},
			onSuccess : function(transport)
			{
				if(ajaxResponse(transport))
				{
					noticeDestroy();
					document.location = document.location;
				}
			},
			onFailure : function(transport)
			{
				alert("There was a problem adding this user to the schedule. Please review all fields to make sure they are properly filled out.");
				noticeDestroy();
			}
		});
	},
	Print : function() {
		notice("Creating PDF...");
		var el = document.createElement("form");
		el.id = "pseudoform";
		el.action = slink+'ajax/business';
		el.method = "POST";
		el.innerHTML = '<input type="hidden" name="action" value="print schedule">';
		document.body.appendChild(el);
		$("pseudoform").submit();
	}
}
var Survey = {
	sid : null,
	NewSurvey : function() {
		Survey.sid = null;
		new Ajax.Request(slink+'ajax/business', {
			method : "post",
			parameters : {
				action : "new survey"
			},
			onSuccess : function(transport)
			{
				if(ajaxResponse(transport))
				{
					$("surveyMain").hide();
					$("newSurveyArea").show();
				}
			}
		});
	},
	NewCancel : function() {
		$("newSurveyArea").hide();
		$("surveyMain").show();
		$("txtTitle").value = "";
		$("itemArea").innerHTML = "";
	},
	AddItem : function() {
		win(600,''+
			'<form id="addToListForm">'+
			'<div class="formText" style="text_small">'+
				'<b>Your Question</b><br>'+
				'<input type="text" size="75" id="txtQuestion"><br><br>'+
				'<input type="hidden" id="txtType">' +
				'<table width="100%" cellspacing="5" cellpadding="0"><tr><td colspan="2"><b>Choose type of answer</b></td></tr>' +
				'<tr><td><i>Type</i></td><td><i>Example</i></td></tr>'+
				'<tr><td valign="top"><a href="javascript:void(0);" id="text" onclick="Survey.SelectAddItem(this);">Single line</a></td><td><input type="text" value="One line response box" size="55"></td></tr>'+
				'<tr><td colspan="2"><div style="width:100%;border-top:1px dotted #ccc"></div></td></tr>'+
				'<tr><td valign="top"><a href="javascript:void(0);" id="textarea" onclick="Survey.SelectAddItem(this);">Multi-line</a></td><td><textarea cols="50" rows="5">Paragraph response area</textarea></td></tr>'+
				'<tr><td colspan="2"><div style="width:100%;border-top:1px dotted #ccc"></div></td></tr>'+
				'<tr><td valign="top"><a href="javascript:void(0);" id="radio" onclick="Survey.SelectAddItem(this);">Select one</a></td><td>Select-one variety<br><input type="radio" name="group1" value="Pepsi">Pepsi<br><input type="radio" name="group1" value="Coke">Coke<br><input type="radio" name="group1" value="RC Cola">RC Cola</td></tr>'+
				'<tr><td colspan="2"><div style="width:100%;border-top:1px dotted #ccc"></div></td></tr>'+
				'<tr><td valign="top"><a href="javascript:void(0);" id="checkbox" onclick="Survey.SelectAddItem(this);">Multi-select</a></td><td>Multi-select variety<br><input type="checkbox" name="group1" value="Read Books">Read Books<br><input type="checkbox" name="group2" value="Watch Movies">Watch Movies<br><input type="checkbox" name="group3" value="Solve Puzzles">Solve Puzzles</td></tr>'+
				'</table>' +
				'<div class="cl"><br>' +
				'<div class="hideArea">'+
					'<input type="button" class="green" value="Add Item To Survey" onclick="Survey.FinishAddItem()">'+
				'</div>'+
			'</div>'+
			'</form>'+
		'');
	},
	SelectAddItem : function(obj) {
		if($(obj).style.backgroundColor) {
			$(obj).style.backgroundColor = null;
			$("txtType").value = "";
		}
		else {
			$("text").style.backgroundColor = $("textarea").style.backgroundColor = $("radio").style.backgroundColor = $("checkbox").style.backgroundColor = null;
			$(obj).style.backgroundColor = "#ddd";
			$("txtType").value = $(obj).id;
		}
	},
	FinishAddItem : function() {
		var q = $("txtQuestion").value;
		var a = $("txtType").value;
		if(q == "" || a == null || a == "") {
			alert("You must enter a question and select a type of answer.");
			return;
		}
		new Ajax.Request(slink+'ajax/business', {
			method : "post",
			parameters : {
				action : "add survey item",
				q : q,
				variety : a
			},
			onSuccess : function(transport)
			{
				if(ajaxResponse(transport))
				{
					$("itemArea").innerHTML += transport.responseText;
					noticeDestroy();
				}
			}
		});
	},
	AddRadio : function(obj) {
		var par = $(obj).up();
		par.innerHTML += '<input type="radio" name="undefined"><span><input type="text" size="10" onblur="Survey.SetItemName(this);"><span class="smallText">Fill in item text here, then hit tab</span></span><br>';
	},
	AddCheck : function(obj) {
		var par = $(obj).up();
		par.innerHTML += '<input type="checkbox" name="undefined"><span><input type="text" size="10" onblur="Survey.SetItemName(this);"><span class="smallText">Fill in item text here, then hit tab</span></span><br>';
	},
	SetItemName : function(obj) {
		var par = $(obj).up("span");
		var iditem = $(obj).up("div").id;
		par.innerHTML = '<b>' + $(obj).value + '</b>';
		new Ajax.Request(slink+'ajax/business', {
			method : "post",
			parameters : {
				action : "add survey item item",
				iditem : iditem,
				newvalue : $(obj).value
			},
			onSuccess : function(transport)
			{
				if(ajaxResponse(transport))
				{
					
				}
			}
		});
	},
	Save : function(obj) {
		var title = ($("txtTitle").value == "" ? "General Survey" : $("txtTitle").value);
		notice("Saving Survey...");
		new Ajax.Request(slink+'ajax/business', {
			method : "post",
			parameters : {
				action : "save survey",
				title : title,
				sid : Survey.sid
			},
			onSuccess : function(transport)
			{
				if(ajaxResponse(transport))
				{
					document.location = document.location;
				}
			}
		});
	},
	Edit : function(id) {
		$("surveyMain").hide();
		$("newSurveyArea").show();
		notice("Loading survey...");
		new Ajax.Request(slink+'ajax/business', {
			method : "post",
			parameters : {
				action : "edit survey",
				sid : id
			},
			onSuccess : function(transport)
			{
				if(ajaxResponse(transport))
				{
					Survey.sid = id;
					var data = eval("(" + transport.responseText + ")");
					$("txtTitle").value = data['title'];
					$("itemArea").innerHTML = data['items'];
					noticeDestroy();
				}
			}
		});
	},
	UpItem : function(id) {
		var prev = $(id).previous();
		if(prev) {
			new Ajax.Request(slink+'ajax/business', {
				method : "post",
				parameters : {
					action : "survey item updown",
					iditem : id,
					idnext : prev.id
				},
				onSuccess : function(transport)
				{
					if(ajaxResponse(transport))
					{
						prev.insert({before : $(id) });
					}
				}
			});
		}
		else
			alert("This item is already at the top.");
	},
	DownItem : function(id) {
		var next = $(id).next();
		if(next) {
			new Ajax.Request(slink+'ajax/business', {
				method : "post",
				parameters : {
					action : "survey item updown",
					iditem : id,
					idnext : next.id
				},
				onSuccess : function(transport)
				{
					if(ajaxResponse(transport))
					{
						next.insert({after : $(id) });
					}
				}
			});
		}
		else
			alert("This item is already at the bottom.");
	},
	DeleteItem : function(id) {
		new Ajax.Request(slink+'ajax/business', {
				method : "post",
				parameters : {
					action : "survey item delete",
					iditem : id
				},
				onSuccess : function(transport)
				{
					if(ajaxResponse(transport))
					{
						$(id).remove();
					}
				}
			});
	},
	Print : function(id) {
		var win = window.open("","printsurvey","menubar=1,scrollbars=1,width=800,height=500,resizable=1");
		new Ajax.Request(slink+'ajax/business', {
			method : "post",
			parameters : {
				action : "print",
				pid : id,
				printer : "true"
			},
			onSuccess : function(transport)
			{
				if(ajaxResponse(transport))
				{
					win.document.write('<title>Survey</title><head><link rel="stylesheet" type="text/css" href="' + slink + 'styles/core.css">');
					win.document.write('<link rel="stylesheet" type="text/css" href="' + slink + 'styles/fonts.css">');
					win.document.write('<link rel="stylesheet" type="text/css" href="' + slink + 'styles/form.css"></head>');
					
					win.document.write('<body><form>' + transport.responseText + '</form></body></html>');
					win.document.body.style.background = "#FFFFFF";
					win.document.body.style.padding = "30px";
					win.document.close();
				}
			}
		});
	},
	DisplayResults : function(id) {
		var win = window.open("","printsurvey","menubar=1,scrollbars=1,width=800,height=500,resizable=1");
		new Ajax.Request(slink+'ajax/business', {
			method : "post",
			parameters : {
				action : "display results",
				sid : id
			},
			onSuccess : function(transport)
			{
				var res = "";
				if(ajaxResponse(transport))
				{	
					win.document.write('<title>Survey</title><head><link rel="stylesheet" type="text/css" href="' + slink + 'styles/core.css">');
					win.document.write('<link rel="stylesheet" type="text/css" href="' + slink + 'styles/fonts.css">');
					win.document.write('<link rel="stylesheet" type="text/css" href="' + slink + 'styles/form.css"></head>');
					
					win.document.write('<body><form>' + transport.responseText + '</form></body></html>');
					win.document.body.style.background = "#FFFFFF";
					win.document.body.style.padding = "30px";
					win.document.close();
				}
			}
		});
	},
	TakeSurvey : function(id,txtpons) {
		scroll(0,0);
		if(txtpons > 0) {
			win(600,'<div>You have two options for receiving and using your coupon. The first option is to print the coupon on paper and give '+
			             'it to the retailer. The second option is to have the coupon sent to your cell phone as a text message (standard cell phone text '+
			             'message charges apply) and show the message to the retailer. Your number is used for only this purpose. We will discard it '+
			             'after we send you your TXTcoup&trade;. Please select a method.</div><br>'+
			             '<div class="mt"><form><input type="radio" name="coutype" id="coutxt" value="txt"> Send my coupon as a text message:'+
			             '<div style="padding:3px;padding-left:30px">Phone number: <input type="text" id="phone" size="10"></div>'+
			             '<div style="padding:3px;padding-left:30px"> Provider: <select id="carrier"><option value="">Please Select Your Provider</option><option value="ATT">AT&T</option><option value="Sprint">Sprint</option><option value="TMobile">TMobile</option><option value="Verizon">Verizon</option></select></div>'+
			             '<br><input type="radio" name="coutype" id="couprint">I will print my coupon</form></div><br>'+
			             '<div><input type="button" value="Continue Survey" class="green" onclick="Survey.TakeSurveyFinish('+id+','+txtpons+');"></div>');
		
		}
		else {
			Survey.EnterData(id,1);
		}
	},
	TakeSurveyFinish : function(id,txtpons,number,carrier) {
		if(!$("coutxt").checked && !$("couprint").checked) {
			alert("Please select an option for receiving your coupon.");
			return;
		}
		if($("coutxt").checked) {
			var number = $("phone").value;
			var carrier = $("carrier").value;
			if(number.length < 10 || carrier == "") {
				alert("Please enter your phone number and your carrier if you want to receive your coupon via text.");
				return;
			}
			noticeDestroy();
			Survey.EnterData(id,1);
			new Ajax.Request(slink+'ajax/business', {
				method : "post",
				parameters : {
					action : "set txtpon",
					sid : id,
					number : number,
					carrier : carrier
				},
				onSuccess : function(transport)
				{
					if(ajaxResponse(transport))
					{
					}
				}
			});
		}
		else {
			noticeDestroy();
			Survey.EnterData(id,1);
		}
	},
	EnterData : function(id,isuser) {
		notice("Loading survey...");
		var d = document.createElement("div");
		if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
			var pageWidth = (document.body.scrollWidth - 80)+'px';
			var pageHeight = document.body.scrollHeight+'px';
		} else if( document.body.offsetWidth ) {
			var pageWidth = (document.body.offsetWidth - 80) +'px';
			var pageHeight = document.body.offsetHeight+'px';
		} else {
			var pageWidth='90%';
			var pageHeight='100%';
		}
		d.style.width= pageWidth;
		d.style.height= pageHeight;
		d.style.padding = "10px";
		d.id = "thesurvey";
		d.style.position = "absolute";
		d.style.top = "0px";
		d.style.left = "30px";
		d.style.zIndex = "3000";
		d.style.background = "#FFFFFF";
		new Ajax.Request(slink+'ajax/business', {
			method : "post",
			parameters : {
				action : "print",
				pid : id,
				printer : "false"
			},
			onSuccess : function(transport)
			{
				if(ajaxResponse(transport))
				{
					var iFrameID = "surveyframe";
					var iframe = document.createElement("iframe");
					iframe.name = iFrameID;
					iframe.id = iFrameID;
					iframe.style.display = "none";
					iframe.style.width = "1px";
					iframe.style.height = "1px";
					document.body.appendChild(iframe);
					if(self.frames[iFrameID].name != iFrameID) { /* *** IMPORTANT: This is a BUG FIX for Internet Explorer *** */ self.frames[iFrameID].name = iFrameID; }
					if(!isuser)
						isuser = 0;
					var dinnerHTML = '<form name="thesurvey" target="surveyframe" action="'+slink+'ajax/business" method="POST"><input type="hidden" name="sid" value="'+id+'"><input type="hidden" id="isuser" name="isuser" value="'+isuser+'"><input type="hidden" name="action" value="save survey data">' + transport.responseText;
					dinnerHTML += '<br><br><span style="padding-right:150px"><input type="submit" class="green" value="Send Survey"></span><input type="button" class="red" value="Cancel" onclick="Survey.CancelData();"></form><br>';
					d.innerHTML = dinnerHTML;
					document.body.appendChild(d);
					noticeDestroy();
				}
			}
		});
	},
	SaveData : function(isuser,sid) {
		if(isuser > 0) {
			new Ajax.Request(slink+'ajax/business', {
				method : "post",
				parameters : {
					action : "print coupon",
					sid : sid,
					type : "HTML",
					count : "single"
				},
				onSuccess : function(transport)
				{
					if(ajaxResponse(transport))
					{
						if(transport.responseText.length > 0) {
							var win = window.open("","coupondisplay","menubar=1,scrollbars=1,width=800,height=500,resizable=1");
							win.document.write('<title>Gathergo Coupon</title><head><link rel="stylesheet" type="text/css" href="' + slink + 'styles/core.css">');
							win.document.write('<link rel="stylesheet" type="text/css" href="' + slink + 'styles/fonts.css">');
							win.document.write('<link rel="stylesheet" type="text/css" href="' + slink + 'styles/form.css"></head>');
					
							win.document.write('<body>' + transport.responseText + '</body></html>');
							win.document.body.style.background = "#FFFFFF";
							win.document.body.style.padding = "30px";
							win.document.close();
						}
					}
				}
			});
		}
		$("thesurvey").remove();
		noticeTimed("Thank you!");
	},
	CancelData : function() {
		$("thesurvey").remove();
	},
	Embed : function(id) {
		win(600,'<div>Embedding your survey into your website or blog couldn\'t be easier. Simply edit your website or blog template and add the following lines to the header:</div>' +
				'<div class="defaultText"><blockquote>&lt;script language="javascript" src="'+slink+'js/widgets.php"&gt; &lt;/script&gt;</blockquote></div>' +
				'<div>Then add the following link for taking the survey:</div>'+
				'<div class="defaultText"><blockquote>&lt;a href="javascript:scroll(0,0);" onclick="Widgets.TakeSurvey('+id+');"&gt;Take our survey!&lt;/a&gt;</blockquote></div>'+
				'<br><br><input type="button" onclick="noticeDestroy();" class="green" value="Done">');
	},
	Activate : function(id,obj) {
		notice("Changing survey status...");
		var status = 0;
		if($(obj).innerHTML == "Activate")
			status = 1;
		new Ajax.Request(slink+'ajax/business', {
			method : "post",
			parameters : {
				action : "activate survey",
				sid : id,
				status : status
			},
			onSuccess : function(transport)
			{
				if(ajaxResponse(transport))
				{
					$(obj).innerHTML = transport.responseText;
					noticeDestroy();
				}
			}
		});
	},
	ManageIncentives : function(id) {
		notice("Loading incentives...");
		new Ajax.Request(slink+'ajax/business', {
			method : "post",
			parameters : {
				action : "get incentives",
				sid : id
			},
			onSuccess : function(transport)
			{
				if(ajaxResponse(transport))
				{
					noticeDestroy();
					win(600,'<div>Please select a coupon which your customers will be rewarded with for filling out the survey.</div><br><div><form name="iform">' + transport.responseText + '</form></div><br><br><input type="button" class="green" value="Finish" onclick="Survey.SelectIncentive('+id+');">');
				}
			}
		});
	},
	SelectIncentive : function(id) {
	
		var iv = document.iform.incentive;
		for(var i = 0; i < iv.length; i++) {
			if(iv[i].checked) {
				iv = iv[i].value;
				break;
			}
		}
		noticeDestroy();
		noticeTimed("Successfully saved incentive for this survey.");
		new Ajax.Request(slink+'ajax/business', {
			method : "post",
			parameters : {
				action : "save incentive",
				sid : id,
				iv : iv
			},
			onSuccess : function(transport)
			{
				if(ajaxResponse(transport))
				{
					
				}
			}
		});
	},
	Delete : function(id) {
		if(confirm("Are you sure you want to delete this survey? You will lose ALL survey data.")) {
			notice("Deleting survey...");
			new Ajax.Request(slink+'ajax/business', {
				method : "post",
				parameters : {
					action : "delete survey",
					sid : id
				},
				onSuccess : function(transport)
				{
					if(ajaxResponse(transport))
					{
						document.location.reload();
					}
				}
			});
		}
	}
}
var Apply = {
	sid : null,
	NewApply : function() {
		Apply.sid = null;
		new Ajax.Request(slink+'ajax/business', {
			method : "post",
			parameters : {
				action : "new apply"
			},
			onSuccess : function(transport)
			{
				if(ajaxResponse(transport))
				{
					$("applyMain").hide();
					$("newApplyArea").show();
				}
			}
		});
	},
	NewCancel : function() {
		$("newApplyArea").hide();
		$("applyMain").show();
		$("txtTitle").value = "";
		$("itemArea").innerHTML = "";
	},
	AddItem : function() {
		win(600,''+
			'<form id="addToListForm">'+
			'<div class="formText" style="text_small">'+
				'<b>Your Question</b><br>'+
				'<input type="text" size="75" id="txtQuestion"><br><br>'+
				'<input type="hidden" id="txtType">' +
				'<table width="100%" cellspacing="5" cellpadding="0"><tr><td colspan="2"><b>Choose type of answer</b></td></tr>' +
				'<tr><td><i>Type</i></td><td><i>Example</i></td></tr>'+
				'<tr><td valign="top"><a href="javascript:void(0);" id="text" onclick="Apply.SelectAddItem(this);">Single line</a></td><td><input type="text" value="One line response box" size="55"></td></tr>'+
				'<tr><td colspan="2"><div style="width:100%;border-top:1px dotted #ccc"></div></td></tr>'+
				'<tr><td valign="top"><a href="javascript:void(0);" id="textarea" onclick="Apply.SelectAddItem(this);">Multi-line</a></td><td><textarea cols="50" rows="5">Paragraph response area</textarea></td></tr>'+
				'<tr><td colspan="2"><div style="width:100%;border-top:1px dotted #ccc"></div></td></tr>'+
				'<tr><td valign="top"><a href="javascript:void(0);" id="radio" onclick="Apply.SelectAddItem(this);">Select one</a></td><td>Select-one variety<br><input type="radio" name="group1" value="Pepsi">Pepsi<br><input type="radio" name="group1" value="Coke">Coke<br><input type="radio" name="group1" value="RC Cola">RC Cola</td></tr>'+
				'<tr><td colspan="2"><div style="width:100%;border-top:1px dotted #ccc"></div></td></tr>'+
				'<tr><td valign="top"><a href="javascript:void(0);" id="checkbox" onclick="Apply.SelectAddItem(this);">Multi-select</a></td><td>Multi-select variety<br><input type="checkbox" name="group1" value="Read Books">Read Books<br><input type="checkbox" name="group2" value="Watch Movies">Watch Movies<br><input type="checkbox" name="group3" value="Solve Puzzles">Solve Puzzles</td></tr>'+
				'</table>' +
				'<div class="cl"><br>' +
				'<div class="hideArea">'+
					'<input type="button" class="green" value="Add Item To Application" onclick="Apply.FinishAddItem()">'+
				'</div>'+
			'</div>'+
			'</form>'+
		'');
	},
	SelectAddItem : function(obj) {
		if($(obj).style.backgroundColor) {
			$(obj).style.backgroundColor = null;
			$("txtType").value = "";
		}
		else {
			$("text").style.backgroundColor = $("textarea").style.backgroundColor = $("radio").style.backgroundColor = $("checkbox").style.backgroundColor = null;
			$(obj).style.backgroundColor = "#ddd";
			$("txtType").value = $(obj).id;
		}
	},
	FinishAddItem : function() {
		var q = $("txtQuestion").value;
		var a = $("txtType").value;
		if(q == "" || a == null || a == "") {
			alert("You must enter a question and select a type of answer.");
			return;
		}
		new Ajax.Request(slink+'ajax/business', {
			method : "post",
			parameters : {
				action : "add apply item",
				q : q,
				variety : a
			},
			onSuccess : function(transport)
			{
				if(ajaxResponse(transport))
				{
					$("itemArea").innerHTML += transport.responseText;
					noticeDestroy();
				}
			}
		});
	},
	AddRadio : function(obj) {
		var par = $(obj).up();
		par.innerHTML += '<input type="radio" name="undefined"><span><input type="text" size="10" onblur="Apply.SetItemName(this);"><span class="smallText">Fill in item text here, then hit tab</span></span><br>';
	},
	AddCheck : function(obj) {
		var par = $(obj).up();
		par.innerHTML += '<input type="checkbox" name="undefined"><span><input type="text" size="10" onblur="Apply.SetItemName(this);"><span class="smallText">Fill in item text here, then hit tab</span></span><br>';
	},
	SetItemName : function(obj) {
		var par = $(obj).up("span");
		var iditem = $(obj).up("div").id;
		par.innerHTML = '<b>' + $(obj).value + '</b>';
		new Ajax.Request(slink+'ajax/business', {
			method : "post",
			parameters : {
				action : "add apply item item",
				iditem : iditem,
				newvalue : $(obj).value
			},
			onSuccess : function(transport)
			{
				if(ajaxResponse(transport))
				{
					
				}
			}
		});
	},
	Save : function(obj) {
		var title = ($("txtTitle").value == "" ? "General Survey" : $("txtTitle").value);
		notice("Saving Application...");
		new Ajax.Request(slink+'ajax/business', {
			method : "post",
			parameters : {
				action : "save apply",
				title : title,
				sid : Apply.sid
			},
			onSuccess : function(transport)
			{
				if(ajaxResponse(transport))
				{
					document.location = document.location;
				}
			}
		});
	},
	Edit : function(id) {
		$("applyMain").hide();
		$("newApplyArea").show();
		notice("Loading application...");
		new Ajax.Request(slink+'ajax/business', {
			method : "post",
			parameters : {
				action : "edit apply",
				sid : id
			},
			onSuccess : function(transport)
			{
				if(ajaxResponse(transport))
				{
					Apply.sid = id;
					var data = eval("(" + transport.responseText + ")");
					$("txtTitle").value = data['title'];
					$("itemArea").innerHTML = data['items'];
					noticeDestroy();
				}
			}
		});
	},
	UpItem : function(id) {
		var prev = $(id).previous();
		if(prev) {
			new Ajax.Request(slink+'ajax/business', {
				method : "post",
				parameters : {
					action : "apply item updown",
					iditem : id,
					idnext : prev.id
				},
				onSuccess : function(transport)
				{
					if(ajaxResponse(transport))
					{
						prev.insert({before : $(id) });
					}
				}
			});
		}
		else
			alert("This item is already at the top.");
	},
	DownItem : function(id) {
		var next = $(id).next();
		if(next) {
			new Ajax.Request(slink+'ajax/business', {
				method : "post",
				parameters : {
					action : "apply item updown",
					iditem : id,
					idnext : next.id
				},
				onSuccess : function(transport)
				{
					if(ajaxResponse(transport))
					{
						next.insert({after : $(id) });
					}
				}
			});
		}
		else
			alert("This item is already at the bottom.");
	},
	DeleteItem : function(id) {
		new Ajax.Request(slink+'ajax/business', {
				method : "post",
				parameters : {
					action : "apply item delete",
					iditem : id
				},
				onSuccess : function(transport)
				{
					if(ajaxResponse(transport))
					{
						$(id).remove();
					}
				}
			});
	},
	Print : function(id) {
		var win = window.open("","printapply","menubar=1,scrollbars=1,width=800,height=500,resizable=1");
		new Ajax.Request(slink+'ajax/business', {
			method : "post",
			parameters : {
				action : "print apply",
				pid : id,
				printer : "true"
			},
			onSuccess : function(transport)
			{
				if(ajaxResponse(transport))
				{
					win.document.write('<title>Application</title><head><link rel="stylesheet" type="text/css" href="' + slink + 'styles/core.css">');
					win.document.write('<link rel="stylesheet" type="text/css" href="' + slink + 'styles/fonts.css">');
					win.document.write('<link rel="stylesheet" type="text/css" href="' + slink + 'styles/form.css"></head>');
					
					win.document.write('<body><form>' + transport.responseText + '</form></body></html>');
					win.document.body.style.background = "#FFFFFF";
					win.document.body.style.padding = "30px";
					win.document.close();
				}
			}
		});
	},
	DisplayResults : function(id) {
		var win = window.open("","printapply","menubar=1,scrollbars=1,width=800,height=500,resizable=1");
		new Ajax.Request(slink+'ajax/business', {
			method : "post",
			parameters : {
				action : "display apply results",
				sid : id
			},
			onSuccess : function(transport)
			{
				var res = "";
				if(ajaxResponse(transport))
				{	
					win.document.write('<title>Application</title><head><link rel="stylesheet" type="text/css" href="' + slink + 'styles/core.css">');
					win.document.write('<link rel="stylesheet" type="text/css" href="' + slink + 'styles/fonts.css">');
					win.document.write('<link rel="stylesheet" type="text/css" href="' + slink + 'styles/form.css"></head>');
					
					win.document.write('<body><form>' + transport.responseText + '</form></body></html>');
					win.document.body.style.background = "#FFFFFF";
					win.document.body.style.padding = "30px";
					win.document.close();
				}
			}
		});
	},
	TakeSurvey : function(id,txtpons) {
		scroll(0,0);
		if(txtpons > 0) {
			win(600,'<div>You have two options for receiving and using your coupon. The first option is to print the coupon on paper and give '+
			             'it to the retailer. The second option is to have the coupon sent to your cell phone as a text message (standard cell phone text '+
			             'message charges apply) and show the message to the retailer. Your number is used for only this purpose. We will discard it '+
			             'after we send you your TXTcoup&trade;. Please select a method.</div><br>'+
			             '<div class="mt"><form><input type="radio" name="coutype" id="coutxt" value="txt"> Send my coupon as a text message:'+
			             '<div style="padding:3px;padding-left:30px">Phone number: <input type="text" id="phone" size="10"></div>'+
			             '<div style="padding:3px;padding-left:30px"> Provider: <select id="carrier"><option value="">Please Select Your Provider</option><option value="ATT">AT&T</option><option value="Sprint">Sprint</option><option value="TMobile">TMobile</option><option value="Verizon">Verizon</option></select></div>'+
			             '<br><input type="radio" name="coutype" id="couprint">I will print my coupon</form></div><br>'+
			             '<div><input type="button" value="Continue Survey" class="green" onclick="Survey.TakeSurveyFinish('+id+','+txtpons+');"></div>');
		
		}
		else {
			Survey.EnterData(id,1);
		}
	},
	TakeSurveyFinish : function(id,txtpons,number,carrier) {
		if(!$("coutxt").checked && !$("couprint").checked) {
			alert("Please select an option for receiving your coupon.");
			return;
		}
		if($("coutxt").checked) {
			var number = $("phone").value;
			var carrier = $("carrier").value;
			if(number.length < 10 || carrier == "") {
				alert("Please enter your phone number and your carrier if you want to receive your coupon via text.");
				return;
			}
			noticeDestroy();
			Survey.EnterData(id,1);
			new Ajax.Request(slink+'ajax/business', {
				method : "post",
				parameters : {
					action : "set txtpon",
					sid : id,
					number : number,
					carrier : carrier
				},
				onSuccess : function(transport)
				{
					if(ajaxResponse(transport))
					{
					}
				}
			});
		}
		else {
			noticeDestroy();
			Survey.EnterData(id,1);
		}
	},
	EnterData : function(id,isuser) {
		notice("Loading application...");
		var d = document.createElement("div");
		if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
			var pageWidth = (document.body.scrollWidth - 80)+'px';
			var pageHeight = document.body.scrollHeight+'px';
		} else if( document.body.offsetWidth ) {
			var pageWidth = (document.body.offsetWidth - 80) +'px';
			var pageHeight = document.body.offsetHeight+'px';
		} else {
			var pageWidth='90%';
			var pageHeight='100%';
		}
		d.style.width= pageWidth;
		d.style.height= pageHeight;
		d.style.padding = "10px";
		d.id = "theapplication";
		d.style.position = "absolute";
		d.style.top = "0px";
		d.style.left = "30px";
		d.style.zIndex = "3000";
		d.style.background = "#FFFFFF";
		new Ajax.Request(slink+'ajax/business', {
			method : "post",
			parameters : {
				action : "print apply",
				pid : id,
				printer : "false"
			},
			onSuccess : function(transport)
			{
				if(ajaxResponse(transport))
				{
					var iFrameID = "applyframe";
					var iframe = document.createElement("iframe");
					iframe.name = iFrameID;
					iframe.id = iFrameID;
					iframe.style.display = "none";
					iframe.style.width = "1px";
					iframe.style.height = "1px";
					document.body.appendChild(iframe);
					if(self.frames[iFrameID].name != iFrameID) { /* *** IMPORTANT: This is a BUG FIX for Internet Explorer *** */ self.frames[iFrameID].name = iFrameID; }
					if(!isuser)
						isuser = 0;
					var dinnerHTML = '<form name="theapplication" target="applyframe" action="'+slink+'ajax/business" method="POST"><input type="hidden" name="sid" value="'+id+'"><input type="hidden" id="isuser" name="isuser" value="'+isuser+'"><input type="hidden" name="action" value="save apply data">' + transport.responseText;
					dinnerHTML += '<br><br><span style="padding-right:150px"><input type="submit" class="green" value="Send Application"></span><input type="button" class="red" value="Cancel" onclick="Survey.CancelData();"></form><br>';
					d.innerHTML = dinnerHTML;
					document.body.appendChild(d);
					noticeDestroy();
				}
			}
		});
	},
	SaveData : function(isuser,sid) {
		$("theapplication").remove();
		noticeTimed("Thank you!");
	},
	CancelData : function() {
		$("theapplication").remove();
	},
	Embed : function(id) {
		win(600,'<div>Embedding your application into your website or blog couldn\'t be easier. Simply edit your website or blog template and add the following lines to the header:</div>' +
				'<div class="defaultText"><blockquote>&lt;script language="javascript" src="'+slink+'js/widgets.php"&gt; &lt;/script&gt;</blockquote></div>' +
				'<div>Then add the following link for filling out the application:</div>'+
				'<div class="defaultText"><blockquote>&lt;a href="javascript:scroll(0,0);" onclick="Widgets.TakeSurvey('+id+');"&gt;Take our survey!&lt;/a&gt;</blockquote></div>'+
				'<br><br><input type="button" onclick="noticeDestroy();" class="green" value="Done">');
	},
	Activate : function(id,obj) {
		notice("Changing application status...");
		var status = 0;
		if($(obj).innerHTML == "Activate")
			status = 1;
		new Ajax.Request(slink+'ajax/business', {
			method : "post",
			parameters : {
				action : "activate apply",
				sid : id,
				status : status
			},
			onSuccess : function(transport)
			{
				if(ajaxResponse(transport))
				{
					$(obj).innerHTML = transport.responseText;
					noticeDestroy();
				}
			}
		});
	},
	Delete : function(id) {
		if(confirm("Are you sure you want to delete this application template? You will lose ALL application data.")) {
			notice("Deleting application...");
			new Ajax.Request(slink+'ajax/business', {
				method : "post",
				parameters : {
					action : "delete apply",
					sid : id
				},
				onSuccess : function(transport)
				{
					if(ajaxResponse(transport))
					{
						document.location.reload();
					}
				}
			});
		}
	}
}
var Subscription = {
  Save : function() {
    noticeTimed("Subscription Settings Successfully Saved");
  },
  Update : function(obj,item) {
    new Ajax.Request(slink+'ajax/business', {
				method : "post",
				parameters : {
					action : "update subscription association",
					idobject : $(obj).options[obj.selectedIndex].value,
					idsub : item 
				},
				onSuccess : function(transport)
				{
					if(ajaxResponse(transport))
					{
						
					}
				}
			});
  }
}
var Coupon = {
	Create : function() {
		$("couponMain").hide();
		$("newCouponArea").show();
	},
	NewCancel : function() {
		$("newCouponArea").hide();
		$("couponMain").show();
		$("txtDesc").value = "";
		$("txtMon").value = "";
		$("txtDay").value = "";
		$("txtYear").value = "";
		$("desc").innerHTML = "";
		$("exp").innerHTML = "";
		$("chkTxtpons").checked = true;
	},
	UpdateDesc : function() {
		var tmp = $("txtDesc").value;
		$("desc").innerHTML = tmp.replace(/\n/g,"<br>");
	},
	UpdateExp : function() {
		$("exp").innerHTML = ($("txtMon").value == "" ? "" : "Expires: " + $("txtMon").value + "/" + $("txtDay").value + "/" + $("txtYear").value);
	},
	HelpTxtpons : function() {
		win(400,"<div>TXTcoups&trade; are the ability for your customers to choose to receive coupons as text messages on their cell phones. These messages are then shown to an employee when the customer wishes to redeem the coupon." +
					'</div><br><br><input type="button" class="green" value="Done" onclick="noticeDestroy();">');
	},
	Save : function() {
		var expire = "";
		if($("txtYear").value != "")
			expire = $("txtYear").value+"-"+$("txtMon").value+"-"+$("txtDay").value;
		var txtpons = ($("chkTxtpons").checked ? "1" : "0");
		notice("Saving coupon...");
			new Ajax.Request(slink+'ajax/business', {
				method : "post",
				parameters : {
					action : "save coupon",
					desc : $("txtDesc").value,
					exp : expire,
					txtpons : txtpons
				},
				onSuccess : function(transport)
				{
					if(ajaxResponse(transport))
					{
						document.location.reload();
					}
				}
			});
	},
	Print : function(id) {
		notice("Creating PDF...");
		var el = document.createElement("form");
		el.id = "pseudoform";
		el.action = slink+'ajax/business';
		el.method = "POST";
		el.innerHTML = '<input type="hidden" name="action" value="print coupon">'+
						   '<input type="hidden" name="cid" value="'+id+'">'+
						   '<input type="hidden" name="type" value="PDF">'+
						   '<input type="hidden" name="count" value="multiple">';
		document.body.appendChild(el);
		$("pseudoform").submit();
	},
	Delete : function(id) {
		if(confirm("Are you sure you want to delete this coupon? (Any surveys associated with the coupon will no longer have this incentive.)")) {
			notice("Deleting coupon...");
			new Ajax.Request(slink+'ajax/business', {
				method : "post",
				parameters : {
					action : "delete coupon",
					cid : id
				},
				onSuccess : function(transport)
				{
					if(ajaxResponse(transport))
					{
						document.location.reload();
					}
				}
			});
		}
	}
}
var Order = {
  Remove : function(obj,item) {
    $(obj).up("table").up().up().remove();
    new Ajax.Request(slink+'ajax/business', {
      method : "post",
      parameters : {
        action : "remove order",
        item : item
      },
      onSuccess : function(transport)
			{
        if(document.location.href.indexOf('?') > 0)
          document.location = document.location.href.substr(0,document.location.href.indexOf('?'));
        else
          document.location = document.location;
			}
    });
  },
  CheckLogin : function() {
    if(typeof uid=="undefined") {
      win(600,'<div class="defaultText">Before you complete the transaction, please take a moment to secure an account so we can associate your desired services with you.</div>' +
          '<div><b>Username</b></div>'+
          '<div><input type="text" id="txtSignupUsername"></div>'+
          '<div><b>Password</b></div>'+
          '<div><input type="password" id="txtSignupPassword"></div>'+
          '<div><b>Email</b></div>'+
          '<div><input type="text" id="txtSignupEmail"></div>'+
          '<br><br><input type="button" onclick="Order.CompleteSignup();" class="green" value="Continue">');
    }
    else
      Order.WaitPayment();
  },
  CompleteSignup : function() {
    var parms = {
				action : "signup short",
				username : $F("txtSignupUsername"),
				password : $F("txtSignupPassword"),
				email : $F("txtSignupEmail"),
				timezone : new Date().getTimezoneOffset()
			}

			notice("Creating Account");
			new Ajax.Request(slink+'ajax/core', {
					method : "post",
					parameters : parms,
					onSuccess : function(transport)
					{
						if(ajaxResponse(transport))
						{
							noticeDestroy();
							Order.WaitPayment();
						}
					}
				});
  },
  WaitPayment : function() {
    $("amount").value = $("totalPrice").innerHTML;
    win(600,'<div class="businessText" id="ver">When you have completed your payment, please click below.<br><br><br>' +
          '<br><br><input type="button" onclick="Order.Verify();" class="green" value="Verify Payment"></div>');
    $("paypal").submit();
  },
  Verify : function() {
    new Ajax.Request(slink+'ajax/business', {
				method : "post",
				parameters : {
					action : "verify business order"
				},
				onSuccess : function(transport)
				{
					if(ajaxResponse(transport))
					{
					
					}
				}
    });
    $("ver").innerHTML = '<center><img src="images/loading.gif"><br>Verifying your payment for Gathergo Business Services...</center>';
    setTimeout(function() {$("ver").innerHTML = 'Success! Thanks for purchasing Gathergo Business Services. Please close this dialog'+
            ' and begin using the services. If you need assistance, please use the contact page at the bottom of the site.<br><br><br><br><br>'+
             '<input type="button" onclick="Login.Logout(\''+businesslink+'\');" value="Get Started!">';},4000);
  }
}
var MailingList = {
	ChangeBlurb : function() {
		notice("Changing blurb...");
		new Ajax.Request(slink+'ajax/business', {
			method : "post",
			parameters : {
				action : "change blurb",
				blurb : $("blurb").value
			},
			onSuccess : function(transport)
			{
				if(ajaxResponse(transport))
				{
					document.location.reload();
				}
			}
		});
	},
	AddPerson : function() {
		notice("Adding this person to your mailing list...");
			new Ajax.Request(slink+'ajax/business', {
				method : "post",
				parameters : {
					action : "mailing list add person",
					name : $("mlname").value,
					email : $("mlemail").value,
					phonenumber : $("mlcell").value,
					provider : $("mlprovider").value,
					timezone : new Date().getTimezoneOffset()
				},
				onSuccess : function(transport)
				{
					if(ajaxResponse(transport))
					{
						document.location.reload();
					}
				}
			});
	},
	EmailAll : function() {
		if(confirm("Are you sure you want to send an email to all of your customers listed here?")) {
			MailingList.PreSend("email");
		}
	},
	TextAll : function() {
		if(confirm("Are you sure you want to send a text to all of your customers listed below? Remember, use this sparingly and offer something most will appreciate.")) {
			MailingList.PreSend("text");
		}
	},
	PreSend : function(variety) {
		win(400,'<div>Type: ' + variety + '</div><br><div>Subject<br><input type="text" id="txtSubject" size="10"></div><br>' +
					'<div>Message<br><textarea id="txtMessage" cols="40" rows="3"></textarea></div><br><br>'+
					'<input type="button" class="green" value="Send" onclick="MailingList.DoSend(\'' + variety + '\');">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" class="red" value="Cancel" onclick="noticeDestroy();">');
	},
	DoSend : function(variety) {
		notice("Sending " + variety + " to all of your subscribed customers...");
		new Ajax.Request(slink+'ajax/business', {
			method : "post",
			parameters : {
				action : "mailing list mass",
				variety : variety,
				subject : $("txtSubject").value,
				message : $("txtMessage").value
			},
			onSuccess : function(transport)
			{
				if(ajaxResponse(transport))
				{
					noticeDestroy();
					noticeTimed("Message sent successfully.");
				}
			}
		});
	},
	Print : function() {
		notice("Creating PDF...");
		var el = document.createElement("form");
		el.id = "pseudoform";
		el.action = slink+'ajax/business';
		el.method = "POST";
		el.innerHTML = '<input type="hidden" name="action" value="print mailing list">';
		document.body.appendChild(el);
		$("pseudoform").submit();
	}
}
function AttachFinanceAuto() {
  if($("item") != null) {
    var options = {
				script:slink+'ajax/business',
				action:'financeac',
				varname:'input',
				json:true,
				shownoresults:true,
				maxresults:8,
				callback: function (obj) {
					//$("txtLocation").setAttribute("selectedid",obj.id);
				}
			};
			var json=new AutoComplete('item',options);
		}
		if($("group") != null) {
    var optionsG = {
				script:slink+'ajax/business',
				action:'financeacgroup',
				varname:'input',
				json:true,
				shownoresults:true,
				maxresults:8,
				callback: function (obj) {
					//$("txtLocation").setAttribute("selectedid",obj.id);
				}
			};
			var jsonG=new AutoComplete('group',optionsG);
		}
}
var Finance = {
  MacroDelete : function(id) {
    if(confirm("Are you sure you want to delete this item?")) {
      notice("Deleting item...");
      new Ajax.Request(slink+'ajax/business', {
        method : "post",
        parameters : {
          action : "finance macro delete",
          itemid : id
        },
        onSuccess : function(transport)
        {
          if(ajaxResponse(transport))
          {
            document.location.reload();
          }
        }
      });
    }
  }
}
