/**
 * @author Christopher Klaver
 */

var xmlHttp
var DivID

function viewBillTracking(BillID, reLoad)
{
	loggedIn=checkLoggedIn();
	if (loggedIn == 0) {
		alert('You must log in above to use this resource.');
	}
	else {
		var url = "includes/BillTrackForm.cfm";
		url = url + "?billID=" + BillID;
		if(reLoad != undefined){url = url + "&reload=" + reLoad;}
		url = url + "&sid=" + Math.random();
		DivID = "LightBox"
		ajaxObject(url,DivID);
		positionForm();
		changeVisible(DivID, "block");
	}
}

function processBillTracking(billID, reLoad){
	var newGroups = ""
	var newGroupBox = document.getElementById('NewGroup') 
	if (newGroupBox != undefined) {
		newGroups = newGroups + newGroupBox.value;
		newGroups = newGroups.replace(/ /g, "%20");
	}
	var existGroups = "";
	var existGroupsList = document.getElementById('BillGroups');
	if (existGroupsList != undefined) {
		var i;
		var count = 0;
		for (i = 0; i < existGroupsList.options.length; i++) {
			if (existGroupsList.options[i].selected) {
				if (count > 0) {
					existGroups = existGroups + ","
				}
				existGroups = existGroups + existGroupsList.options[i].value;
				count++;
			}
		}
	}
	var url = "includes/billtrackprocessor.cfm?";
	url = url + "billid=" + billID;
	if (newGroups != ""){url = url + "&newgroups=" + newGroups;}
	if (existGroups != ""){url = url + "&exgroups=" + existGroups;}
	DivID = "LightBox"
	ajaxObject(url,DivID);
	changeVisible(DivID, "none");
	if (reLoad == 1)
	{
		setTimeout("location.replace('mygongwer.cfm')",2000);
	}
}

function viewBillTrackingGroup(GroupID, reLoad)
{
	loggedIn=checkLoggedIn();
	if (loggedIn == 0) {
		alert('You must log in above to use this resource.');
	}
	else {
		var url = "includes/BillTrackGroupForm.cfm";
		url = url + "?groupid=" + GroupID;
		if(reLoad != undefined){url = url + "&reload=1";}
		url = url + "&sid=" + Math.random();
		DivID = "LightBox"
		ajaxObject(url,DivID);
		positionForm();
		changeVisible(DivID, "block");
	}
}

function processBillTrackingGroup(groupID, reLoad){
	var groupName = "";
	var groupNameBox = document.getElementById('txtgroup');
	if (groupNameBox == undefined){
		groupName = "Unnamed";
	}
	else{
		groupName = groupNameBox.value;
		groupName = groupName.replace(/ /g,"%20");
	}
	var newBills = "";
	var newBillBox = document.getElementById('newbills');
	if (newBillBox != undefined) {
		newBills = newBills + newBillBox.value;
		newBills = newBills.replace(/ /g, "%20");
	}
	var deleteBills = "";
	var deleteBillsList = document.frmGroupEdit.ckDelete;
		var i;
		var count = 0;
		for (i = 0; i < deleteBillsList.length; i++) {
			if (deleteBillsList[i].checked==true) {
				if (count > 0) {
					deleteBills = deleteBills + ","
				}
				deleteBills = deleteBills + deleteBillsList[i].value;
				count++;
			}
		}
	var url = "includes/BillTrackGroupEdit.cfm?";
	url = url + "groupid=" + groupID;
	url = url + "&groupname=" + groupName;
	if (newBills != ""){url = url + "&newbills=" + newBills;}
	if (deleteBills != ""){url = url + "&delbills=" + deleteBills;}
	DivID = "LightBox"
	ajaxObject(url,DivID);
	changeVisible(DivID, "none");
	if (reLoad == 1)
	{
		setTimeout("location.replace('mygongwer.cfm')",2000);
	}
}

function deleteGroup(groupID){
	var answer = confirm("Are you sure you want to delete this group?");
	if (answer){
		var url = "includes/BillTrackDeleter.cfm?groupid=" + groupID;
		window.location.assign(url);
	}
}

function deleteBill(billID){
	var answer = confirm("Are you sure you want to stop tracking this bill?");
	if (answer){
		var url = "includes/BillTrackDeleter.cfm?billid=" + billID;
		window.location.assign(url);
	}
}

function deleteSearch(searchID){
	var answer = confirm("Are you sure you want to delte this saved search?");
	if (answer){
		var url = "includes/BillTrackDeleter.cfm?searchid=" + searchID;
		window.location.assign(url);
	}
}

