// Mote Functions
// By: Adwait A. Walimbe

last = "";

function WorkMote( elemText, last, moteId )
{

	//alert( elemText );
	if( elemText == null )
	{
		// The user has typed nothing
		// Otherwise the user has erased his text
		// A mote has already begun for this case
		
	}
	else
	{
		// The user has typed something
		// Create a new mote, or edit an existing mote
		
		// Check if this mote already exists by checking if the value before editing was already in the database
		
		// If it's already there, just update it
		// Otherwise, create it		
		
		// elemText = the current text in the field
		// last = the last text in the field, and probably the text in the database
		
		if( moteId == "<input>" || moteId == "Error" || moteId == "" )
		{
			// Create a new mote
			genMote( elemText );
			moteId = stripHTML( document.getElementById("moteId").innerHTML );
			
			if( moteId == "Error" || moteId == "" )
			{
				//document.getElementById('moteLink').innerHTML = "Your mote was not created properly. <br/>Please clear the mote area, refresh this page, and try again.";
			}
			else
			{
				moteURL = "mote?id=" + moteId;
				document.getElementById('moteLink').innerHTML = "<a href='" + moteURL + "'>Click here</a> to view / share your mote. </a><br/> Your mote URL is: <b>http://www.socialdecks.com/iMotable/" + moteURL + "</b>";
			}
			
		}
		else
		{
			// The mote is already created
			// Now just update the data
			
			editMote( moteId, elemText );
			
		}
		
		
		document.getElementById('lastVal').value = elemText;
		document.getElementById('moteId').value = moteId;
	}
	
}
