// JavaScript Document
//************************************************************************************************************
function LoadTable($sTable, $iID, $sLoading){

	if($sLoading == true) $('TableHere').innerHTML = "Loading...please, wait....";

	new Ajax.Updater( 'TableHere', 'db_ajax.php', { method: 'get', 
		asynchronous: ($sLoading ? 'true' : 'false'),
		parameters: 'ID=' + $iID +  '&sFunction=' + $sTable, evalScripts: 'true' });

}

//************************************************************************************************************
function PopUp($sURL, $iWidth, $iHeight, $iScroll, $iResizable, $sID) {

	var $oDay = new Date();

	if($sID == '') $sID = $oDay.getTime();

	eval("page" + $sID + " = window.open('" + $sURL + "' , '" + $sID +
		"', 'toolbar=0,scrollbars=" + $iScroll + ",location=0,statusbar=0,menubar=0,resizable=" +
		$iResizable + ",width=" + $iWidth + ",height=" + $iHeight + ", left=10, top=10');");

}

//Maximize window*********************************************************************************************
function Maximize(){

	window.moveTo(0, 0);
	window.resizeTo(screen.width, screen.height);

}


//************************************************************************************************************
function SaveLocationInfo($sID){

	var $sPars = 'txtAddress=' + $F('txtAddress' + $sID) + "&txtcity=" + $F('txtCity' + $sID) +
				'&txtZipcode=' + $F('txtZipcode' + $sID) + '&txtFacility=' + $F('txtFacility' + $sID) +
				'&cboLocationID1=' + $F('cboLocationID1' + $sID) +
				'&cboLocationID2=' + $F('cboLocationID2' + $sID) +
				'&cboAccessible=' + $F('cboAccessible' + $sID) +
				'&txtMapsco=' + $F('txtMapsco' + $sID) + '&txtDirections=' + $F('txtDirections' + $sID) +
				'&txtBus=' + $F('txtBus' + $sID) + '&ID=' + $sID + '&hdnGroupID=' + $F('hdnGroupID') +
				'&cboPhotoGroup1=' + $F('cboPhotoGroup1' + $sID) +
				'&cboPhotoGroup2=' + $F('cboPhotoGroup2' + $sID) +
				'&cboPhotoAerial=' + $F('cboPhotoAerial' + $sID) + '&sFunction=' +
				($sID == 'New' ? 'LocationInsert' : 'LocationUpdate');

	DB_Action($sPars, 'LocationsTable', $F('hdnGroupID'));

}

//************************************************************************************************************
function DeleteLocationInfo($iID, $sAddress){

	var $sConfirm = confirm('Are you sure you want to delete location ' + $sAddress);

	if(!$sConfirm) return;

	DB_Action('&ID=' + $iID + '&sFunction=LocationDelete', 'LocationsTable', $F('hdnGroupID'));

}

//************************************************************************************************************
function SaveGroupInfo($sID){

	var $sFunction	= 'GroupInsert';
	var $sPrimary	= '';

	if($sID != 'New'){

		$sFunction	= 'GroupUpdate';
		$sPrimary	= ($F('cboMeetingLocationsID' + $sID) != '') ?
						'&cboMeetingLocationsID=' + $F('cboMeetingLocationsID' + $sID) : '';

	}

	var $sPars = 'txtName=' + $F('txtName' + $sID) + '&txtDistrict=' + $F('txtDistrict' + $sID) +
				'&txtPhone=' + $F('txtPhone' + $sID) + '&cboOutlying=' +
				$F('cboOutlying' + $sID) + '&cboChildcare=' + $F('cboChildcare' + $sID) + '&ID=' + $sID +
				'&cboNonSmoking=' + $F('cboNonSmoking' + $sID) + '&sFunction=' + $sFunction + $sPrimary;

	DB_Action($sPars, 'GroupsTable', '');

}

//************************************************************************************************************
function DeleteGroupInfo($id, $sName){

	var $sConfirm = confirm('Are you sure you want to delete group ' + $sName);

	if(!$sConfirm) return;

	DB_Action('&ID=' + $id + '&sFunction=GroupDelete', 'GroupsTable', '');

}

//************************************************************************************************************
function SaveMeetingInfo($id){

	var $sPars = 'cboDay=' + $F('cboDay' + $id) + '&cboTime=' + $F('cboTime' + $id) + '&cboType=' +
				$F('cboType' + $id) + '&cboFormatID=' + $F('cboFormatID' + $id) + '&cboNonSmoking=' +
				$F('cboNonSmoking' + $id) + '&txtNotes=' + $F('txtNotes' + $id) + '&ID=' + $id +
				'&cboChildcare=' + $F('cboChildcare' + $id) + '&hdnGroupID=' + $F('hdnGroupID') +
				'&cboMeetingLocationsID=' + $F('cboMeetingLocationsID' + $id) + '&sFunction=' +
				($id == 'New' ? 'MeetingInsert' : 'MeetingUpdate');

	DB_Action($sPars, 'MeetingsTable', $F('hdnGroupID'));

}

//************************************************************************************************************
function DB_Action($sPars, $sLoadTable, $sID){

	new Ajax.Updater('Dirty', 'db_ajax.php', { method: 'get', asynchronous: 'false',
		parameters: $sPars, evalScripts: 'true' });

	LoadTable($sLoadTable, $sID, false);


}

//************************************************************************************************************
function DeleteMeetingInfo($id, $sDay, $sTime){

	var $sConfirm = confirm('Are you sure you want to delete meeting ' + $sDay + '/' + $sTime);

	if(!$sConfirm) return;

	DB_Action('&ID=' + $id + '&sFunction=MeetingDelete', 'MeetingsTable', $F('hdnGroupID'));

}

//************************************************************************************************************
function CloseAndLoad($sURL){

	opener.location.href=$sURL;
	window.close();

}

//************************************************************************************************************
function Leaving(){

	alert('WARNING!!!\nYou are now leaving the\nDallas Intergroup Website.\nDIA is ' +
		'not affiliated with, nor is DIA\nresponsible for the content of this site!\nHave ' +
		'a great 24!');

}