
var isID = 0;
var isAll = 0;
var isLayers = 0;

if(document.getElementById) {
  isID = 1;
}
if(document.layers) {
  isLayers = 1;
}
if(document.all) {
  isAll = 1;
}

function findObject(objectID)
{
	if(isID) {
		return document.getElementById(objectID);
	}
	if(isAll) {
		return document.all[objectID];
	}
	if(isLayers) {
		return document.layers[objectID];
	}
	return null;
}

function reloadParent()
{
	window.opener.location.reload();
}

function OpenWindow(nWidth,nHeight,strURL)
{
	var objOpenWindow = window.open(strURL,'','scrollbars=yes,menubar=no,height='+nHeight+',width='+nWidth+',resizable=yes,toolbar=no,location=no,status=yes');
}

function popUp(strURL)
{
	var objOpenWindow = window.open(strURL,'','scrollbars=yes,menubar=no,height=500,width=490,resizable=yes,toolbar=no,location=no,status=yes');
}

function deleteClient()
{
	var objClient = findObject('cboClients');
	
	if (objClient != null)
	{
		var response = confirm( 'Are you sure you want to delete this client including all appointments and existing invoices for this client?' );
		if (response)
		{
			document.location.href = 'diary_clients.php?DeleteID=' + objClient.value;
			return true;
		}
	}
	return false;
}

function deleteUser()
{
	var objUsers = findObject('cboUsers');
	
	if (objUsers != null)
	{
		var response = confirm( 'Are you sure you want to delete this user?' );
		if (response)
		{
			document.location.href = 'diary_users.php?DeleteID=' + objUsers.value;
			return true;
		}
	}
	return false;
}


function checkPropertyInventory()
{
	var objClient = findObject('cboClient');
	var objProperty = findObject('cboProperty');
	
	if (objClient != null &&
	    objProperty != null)
	{
		document.location.href = 'diary_upload.php?PropertyID=' + objProperty.value + '&ClientID=' + objClient.value;
		return true;
	}
	return false;
}


function checkPropertyInventoryMD()
{
	var objClient = findObject('cboClient');
	var objProperty = findObject('cboProperty');
	
	if (objClient != null &&
	    objProperty != null)
	{
		document.location.href = 'manage_docs.php?PropertyID=' + objProperty.value + '&ClientID=' + objClient.value;
		return true;
	}
	return false;
}

function deleteBooking()
{
	var objClient = findObject('cboClients');
	var objProperty = findObject('cboBookings');
	
	if (objClient != null &&
	    objProperty != null)
	{
		var OK = confirm( 'Are you sure you want to delete the selected property?' );
		if (OK)
		{
			document.location.href = 'diary_bookings.php?DeleteID=' + objProperty.value + '&ClientID=' + objClient.value;
			return true;
		}
	}
	return false;
}

function SelectClientEditA(nAppID)
{
	var objClient = findObject('cboClient');
	if (objClient != null)
	{
		document.location.href = 'diary_edit.php?AppID=' + nAppID + '&ClientID=' + objClient.value;
	}
}

function SelectProperyEditA(nClientID, nAppID)
{
	var objProperty = findObject('cboProperty');
	if (objProperty != null)
	{
		document.location.href = 'diary_edit.php?AppID=' + nAppID + '&ClientID=' + nClientID + '&PropertyID=' + objProperty.value;
	}
}


function SelectUser()
{
	var objUsers = findObject('cboUsers');
	if (objUsers != null)
	{
		document.location.href = 'diary_users.php?UserID=' + objUsers.value;
	}
}


function SelectClient(strURL)
{
	objClient = document.getElementById('cboClient');
	document.location.href = 'diary_add.php?ClientID=' + objClient.value + strURL;
}
function SelectClientMD()
{
	objClient = document.getElementById('cboClient');
	document.location.href = 'manage_docs.php?ClientID=' + objClient.value;
}

function SelectClientEdit()
{
	var objClients = findObject('cboClients');
	if (objClients != null )
	{
		document.location.href = 'diary_clients.php?ClientID=' + objClients.value;
	}
}

function SelectClientBooking()
{
	var objClients = findObject('cboClients');
	if (objClients != null )
	{
		document.location.href = 'diary_bookings.php?ClientID=' + objClients.value;
	}
}

function SelectBooking(nClientID)
{
	var objBookings = findObject('cboBookings');
	if (objBookings != null)
	{
		document.location.href = 'diary_bookings.php?ClientID=' + nClientID + '&BookingID=' + objBookings.value;
	}
}


function SelectClientPrice()
{
	var objClients = findObject('cboClient');
	if (objClients != null )
	{
		document.location.href = 'diary_prices.php?ClientID=' + objClients.value;
	}
}

function SelectClientInvoice()
{
	var objClients = findObject('cboClientExisting');
	if (objClients != null )
	{
		document.location.href = 'monthly_invoice.php?ExClientID=' + objClients.value;
	}
}

function SelectProperty(nClientID)
{
	objProperty = document.getElementById('cboProperty');
	if ( objProperty )
	{
		document.location.href = 'diary_add.php?ClientID=' + nClientID + '&PropertyID=' + objProperty.value;
	}
}

function deleteAppointment(nAppointmentID, nInvoiceID, nDeleteInvoice, strURL)
{
	if (nInvoiceID > 0)
	   if (nDeleteInvoice == 1)
	      var response = confirm( 'Please note that because your invoice is not currently active for this appointment, it will also get deleted along with this appointment.\nAre you sure you want to delete this appointment and invoice? ' );
      else
	      var response = confirm( 'Please note that because your invoice for this appointment is currently active it will not get deleted.\nAre you sure you want to delete this appointment?' );
	else
	   var response = confirm( 'Are you sure you want to delete this appointment?' );
	   
	if (response)
	{
		document.location.href = strURL + '&DeleteID=' + nAppointmentID + '&InvoiceID=' + nInvoiceID + '&DeleteInvoice=' + nDeleteInvoice;
	}
}

function DeleteInvoice(nClientID, nInvoiceID)
{
	var response = confirm( 'Are you sure you want to delete the selected invoice?' );
	if (response)
	{
		document.location.href = 'monthly_invoice.php?ExClientID=' + nClientID + '&InvoiceID=' + nInvoiceID + '&Delete=True';
	}	
}

function Print()
{
	var response = confirm( 'Are you sure you want to print this page?' );
	if (response)
	{
		window.print();
	}
}


function urlRedirect(strURL)
{
	document.location.href = strURL;
}


function SelectPriceList()
{
	var objPriceList = findObject('cboPriceList');
	if (objPriceList != null)
	{
		urlRedirect ('diary_prices.php?PriceListID=' + objPriceList.value);
	}
}

function deletePriceList()
{
	var objPriceList = findObject('cboPriceList');
	if (objPriceList != null)
	{
		var OK = confirm('Are you sure you want to delete the selected price list?');
		if (OK)
		{
			urlRedirect ('diary_prices.php?Delete=' + objPriceList.value);
		}
	}
}

function deletePriceListItem(nPriceListID, nItemID)
{
	var OK = confirm('Are you sure you want to delete the selected price list item?');
	if (OK)
	{
		urlRedirect ('diary_prices.php?PriceListID=' + nPriceListID + '&ItemID=' + nItemID);
	}
}