﻿var waiting_on_ajax = false;

function updateElement( id, value )
{
	el = document.getElementById( id );
	if( el )
	{
		el.innerHTML = value;
	}
}

function updateStore( property_count )
{
	el = document.getElementById( 'store' );
	if( el )
	{
		el.innerHTML = property_count;
	}
}


function checkBox( name, state )
{
	el = document.getElementById( 'check_' + name );
	if( el )
	{
		el.checked = state;
	}
}

function checkStatus( name )
{
	el = document.getElementById( 'check_' + name );
	if( el )
	{
		return el.checked;
	}
}

function swapCheckBox( name )
{
	el = document.getElementById( 'check_' + name );
	if( el )
	{
		el.checked != el.checked;	
	}
}


function save_property( property_code , storage ){ 
	
	if( waiting_on_ajax != false )
	{
		// Reset what they clicked
		swapCheckBox( property_code );
		alert( "Please wait before clicking again" );
	}
	else
	{
		// The cheked status is the state after the button was pressed
		if( checkStatus( property_code ) == false )
		{
			x_remove_property( property_code, storage, remove_property_callback );
		}
		else
		{
			x_save_property( property_code, storage, save_property_callback ); 
		}
		waiting_on_ajax = property_code;
	}
}

