//////////////////////////////////////////////////////////////////////////////////////////
// LISTINGs
//////////////////////////////////////////////////////////////////////////////////////////

function getInactiveListings( landlordId, sortBy, direction, listingName, houseType, areaType )
{
	new Ajax.Updater('inactiveListings', '/Controllers/ListingController.cfc?method=getInactiveListingsByLandlordId',
		{
			evalScripts: true,
			method: 'post',
			parameters: 
			{ 	
				landlord_id: landlordId, 
				sortBy: sortBy, 
				direction: direction, 
				listingName: listingName,
				houseType: houseType,
				areaType: areaType
			}
		}
	);
};

function getActiveListings( landlordId, sortBy, direction, listingName, houseType, areaType )
{
	new Ajax.Updater('activeListings', '/Controllers/ListingController.cfc?method=getActiveListingsByLandlordId',
		{
			evalScripts: true,
			method: 'post',
			parameters: 
			{ 	
				landlord_id: landlordId, 
				sortBy: sortBy, 
				direction: direction, 
				listingName: listingName,
				houseType: houseType,
				areaType: areaType
			}
		}
	);
};

function getListingsUnverified( sortBy, direction, email, monthCreated )
{
	new Ajax.Updater('landlordList', '/Controllers/listingController.cfc?method=getListingsUnverified',
		{
			evalScripts: true,
			method: 'post',
			parameters: 
			{ 	
				sortBy: sortBy, 
				direction: direction,
				email: email,
				monthCreated: monthCreated
			}
		}
	);
};


/* Delete the Listings */
function deleteListingById( listingId, listingName )
{
	var deleteIt = confirm("Are you sure you want to delete the listing with the title: " + listingName + 
		"? You will not be able to recover this record in the future.");
	
	if(deleteIt)
	{			
		new Ajax.Request('/Controllers/ListingController.cfc?method=deleteListingById',
		{
			parameters: {
				listingId: listingId
			},
			onComplete:function() {
				getListingsUnverified( '', '', '', 0 );
			}
		});
	}
};

/* De-activate the Listings */
function deactivateActiveListingById( listingId, landlordId, sortBy, direction, listingName, houseType, areaType )
{
	var deleteIt = confirm("Are you sure you want to de-activate the listing with the title: " + listingName + "? This will make the listing unavailable to users.");
	
	if(deleteIt)
	{			
		new Ajax.Request('/Controllers/ListingController.cfc?method=deactivateActiveListingById',
		{
			parameters: {
				listingId: listingId
			},
			onComplete:function() {
				getActiveListings( landlordId, sortBy, direction, listingName, houseType, areaType );
				getInactiveListings( landlordId, sortBy, direction, listingName, houseType, areaType );
			}
		});
	}
};



/* Activate the Listings */
function activateActiveListingById( listingId, landlordId, sortBy, direction, listingName, houseType, areaType )
{
	// NGM - Sept 29, added this conditional as part of the requested update to request if the Landlords wants to re-activate and inactive listing after editing
	if( listingName.length > 0 )
		var deleteIt = confirm("Are you sure you want to activate the listing with the title: " + listingName + "? This will make the listing visible to users.");
	else
		var deleteIt = confirm("Would you like to activate the listing you just edited? This will make the listing visible to users.");
	
	if(deleteIt)
	{			
		new Ajax.Request('/Controllers/ListingController.cfc?method=activateActiveListingById',
		{
			parameters: {
				listingId: listingId
			},
			onComplete:function() {
				getActiveListings( landlordId, sortBy, direction, listingName, houseType, areaType );
				getInactiveListings( landlordId, sortBy, direction, listingName, houseType, areaType );
			}
		});
	}
};




/* Delete the Listings */
function deleteActiveListingById( listingId, landlordId, sortBy, direction, listingName, houseType, areaType )
{
	var deleteIt = confirm("Are you sure you want to delete the listing with the title: " + listingName + 
		"? You will not be able to recover this record in the future.");
	
	if(deleteIt)
	{			
		new Ajax.Request('/Controllers/ListingController.cfc?method=deleteListingById',
		{
			parameters: {
				listingId: listingId
			},
			onComplete:function() {
				getActiveListings( landlordId, sortBy, direction, listingName, houseType, areaType );
			}
		});
	}
};


/* Delete the Listings */
function deleteInactiveListingById( listingId, landlordId, sortBy, direction, listingName, houseType, areaType  )
{
	var deleteIt = confirm("Are you sure you want to delete the listing with the title: " + listingName + 
		"? You will not be able to recover this record in the future.");
	
	if(deleteIt)
	{			
		new Ajax.Request('/Controllers/ListingController.cfc?method=deleteListingById',
		{
			parameters: {
				listingId: listingId
			},
			onComplete:function() {
				getInactiveListings( landlordId, sortBy, direction, listingName, houseType, areaType );
			}
		});
	}
};




//////////////////////////////////////////////////////////////////////////////////////////
// LANDLORDs
//////////////////////////////////////////////////////////////////////////////////////////

/* Get Landlords */
function getLandlords( sortBy, direction, email, monthCreated )
{
	new Ajax.Updater('landlordList', '/Controllers/LandlordController.cfc?method=getLandlords',
		{
			evalScripts: true,
			method: 'post',
			parameters: 
			{ 	
				sortBy: sortBy, 
				direction: direction,
				email: email,
				monthCreated: monthCreated
			}
		}
	);
};


/* Delete Landlord */
function deleteLandlordById( landlordId, landlordName )
{
	var deleteIt = confirm("Are you sure you want to delete this landlord with the title: " + landlordName + 
		", and all of their associated listings? NOTE: You will not be able to recover this information in the future.");
	
	if(deleteIt)
	{			
		new Ajax.Request('/Controllers/LandlordController.cfc?method=deleteLandlordById',
		{
			parameters: {
				landlordId: landlordId
			},
			onComplete:function() {
				getLandlords( '', '', '', 0 );
			}
		});		
	}
};



//////////////////////////////////////////////////////////////////////////////////////////
// RESOURCEs
//////////////////////////////////////////////////////////////////////////////////////////

/* Get Resources */
function getResources( sortBy, direction, name, sectorTypeId, dateCreated )
{
	new Ajax.Updater('resourceList', '/Controllers/ResourceController.cfc?method=getResources',
		{
			evalScripts: true,
			method: 'post',
			parameters: 
			{
				sortBy: sortBy, 
				direction: direction,
				name: name,
				sectorTypeId: sectorTypeId,
				dateCreated: dateCreated
			}
		}
	);
};



/* Delete Resource by Id */
function deleteResourceById( resourceId, resourceType, resourceName )
{
	var deleteIt = confirm("Are you sure you want to delete this " + resourceType + " titled \"" + resourceName + 
		"\"? NOTE: You will not be able to recover this information in the future.");
	
	if(deleteIt)
	{			
		new Ajax.Request('/Controllers/ResourceController.cfc?method=deleteResourceById',
		{
			parameters: {
				resourceId: resourceId,
				resourceType: resourceType
			},
			onComplete:function() {
				getResources( '', '', '', -1, '' );
			}
		});		
	}
};



//////////////////////////////////////////////////////////////////////////////////////////
// BUILDINGs
//////////////////////////////////////////////////////////////////////////////////////////

/* Get Buildings */
function getBuildings( sortBy, direction, name, houseType, areaType )
{
	new Ajax.Updater('buildingsList', '/Controllers/BuildingController.cfc?method=getBuildings',
		{
			evalScripts: true,
			method: 'post',
			parameters: 
			{ 	
				sortBy: sortBy, 
				direction: direction,
				name: name,
				houseType: houseType,
				areaType: areaType
			}
		}
	);
};


/* Delete Buildings by Id */
function deleteBuildingById( buildingId, buildingName )
{
	var deleteIt = confirm("Are you sure you want to delete the building with the title: " + buildingName + 
		"? You will not be able to recover this record in the future.");
	
	if(deleteIt)
	{			
		new Ajax.Request('/Controllers/BuildingController.cfc?method=deleteBuildingById',
		{
			parameters: {
				buildingId: buildingId
			},
			onComplete:function() {
				getBuildings( '', '', '', -1, -1 );
			}
		});		
	}
};


function getBuildingsWithAttributes( propertyManager, areaType )
{
	new Ajax.Updater('buildingsList', '/Controllers/BuildingController.cfc?method=getBuildingsWithAttributes',
		{
			evalScripts: true,
			method: 'post',
			parameters: 
			{ 	
				propertyManager: propertyManager, 
				areaType: areaType
			}
		}
	);
};



function getLanguagesDisplay( sortBy, direction )
{
	new Ajax.Updater('languageList', '/Controllers/LanguageController.cfc?method=getLanguagesDisplay',
		{
			evalScripts: true,
			method: 'post',
			parameters: 
			{
				sortBy: sortBy, 
				direction: direction
			}
		}
	);
};


function deleteLanguageById( languageId )
{
	var deleteIt = confirm("This will delete the language, ALL keys, AND translations for each key. Are you sure you want to delete this language?");

	if(deleteIt)
	{
		new Ajax.Request('/Controllers/LanguageController.cfc?method=deleteLanguageById',
		{
			parameters: {
				languageId: languageId
			},
			onComplete:function() {
				getLanguagesDisplay( '', '');
			}
		});
	}
};


function getDictionaryDisplayByLanguageId( languageId, sortBy, direction )
{
	new Ajax.Updater('dictionaryList', '/Controllers/LanguageController.cfc?method=getDictionaryDisplayByLanguageId',
		{
			evalScripts: true,
			method: 'post',
			parameters: 
			{
				languageId: languageId
			}
		}
	);
};


function deleteDictionaryKeyById( keyId )
{
	var deleteIt = confirm("This will delete this key and will not be recoverable. Are you sure you want to DELETE this key?");

	if(deleteIt)
	{			
		new Ajax.Request('/Controllers/LanguageController.cfc?method=deleteDictionaryKeyById',
		{
			parameters: {
				keyId: keyId
			},
			onComplete:function() {
				getDictionaryDisplayByLanguageId( 0, '', '' );
			}
		});
	}
};


function setSessionLanguageId( languageId )
{
	new Ajax.Request('/Controllers/LanguageController.cfc?method=setSessionLanguageId',
	{
		parameters: {
			languageId: languageId
		},
		onComplete:function() {
			window.location.reload(true);
		}
	});
};


function setFontPreferenceById( sizePref )
{
	new Ajax.Request('/Controllers/LanguageController.cfc?method=setFontPreferenceById',
	{
		parameters: {
			sizePref: sizePref
		},
		onComplete:function() {
			window.location.reload(true);
		}
	});
};


function addRemovePrintId( listingId )
{
	new Ajax.Request('/Controllers/ListingController.cfc?method=addRemovePrintId',
	{
		parameters: {
			listingId: listingId
		}
	});
};