
	var aCategories = [];
	var aDictionaries = [];
	var nShow = -1;
	var sShow = '';
	var response;
	var so = new SWFObject("AudioPlayer.swf", "sotester", "100", "50", "8", "#EEEEEE");
	so.setAttribute("style", ";");
	var uploadElement;
 
 	var m_sDictName = "";
    var	m_nDictID = -1;
    var m_nImgID = -1;
    var m_nWordID = -1;
    var m_sWordName = "";
    var m_nOwnerID = -1;
    var m_sOwnerName = "";
    var m_sWordEditMode = "detail";
    var	m_nTypeId = -1;
	var	m_sAlt = "";
	var m_sCurrUsername = "";
	var m_nTypeId = -1;
	
	var m_aDefaultTypeNames = Array('Noun','Verb','Adjective','Adverb','Pronoun','Phrase','Misc');
	var m_nDefaultTypes = 7;
	
	var m_pResponse;
	
	var m_sViewMode = "top";
	
	var m_sMode = "play";
	
	var m_bLoggedIn = false;
	var m_sUsername;
	

	// TODO: Save the selected word id

	// Adds in the Flash audio player
	function addAudioPlayer(sound_id)
    {
    	// TODO: Make flash go and get flash player if flash player not installed
    	//so.useExpressInstall('swfobject/expressinstall.swf');
		so.addVariable("flashVarText", sound_id);
		so.addParam("scale", "noscale");
		so.write("audioPlayer");
    }
    
	function addSBX(dict_id, hWnd)
    {	
        var sbx = new SWFObject("didusay.swf", "didusay", "887", "557", "8", "#ADDFFF");
        // TODO: Make flash go and get flash player if flash player not installed
    	//so.useExpressInstall('swfobject/expressinstall.swf');
    	
        sbx.setAttribute("style", ";");
		sbx.addVariable("dict_id", dict_id);
		sbx.addParam("flashvars","dict_id="+dict_id);
		sbx.addParam("scale", "noscale");
		sbx.write(hWnd);
    }
    
    function setMode(sMode)
	{
		m_sMode = sMode;
		if(sMode == "play")
		{	
			showPlayCurrent();
			document.getElementById('edit').className = ""; 	
		}
		else
		{
			showEditCurrent();
			document.getElementById('play').className = ""; 	
		}
	};
   			
   	// Get the normal display, will be hover if the mode is the current mode
   	function getNormalClass(sMode)
   	{
   		if(sMode != m_sMode)
   		{
   			return "";
   		}
   		else
   		{
   			return "hover";
   		}
   	}
    
    function showPlayCurrent()
    {
    	showPlay(m_nDictID,m_sDictName,m_nImgID);
    }
    
    
    function showPlay(dict_id, dict_name, img_id)
    {
    	document.getElementById('header-main').innerHTML = "Loading . . ."; 	
    	var html = "<div id=\"app_window\"></div>";
    	html += '<div class="rbroundbox" id="footer"><p>Copyright - elevatedstudios.com - email sbx@elevatedstudios.com for questions</p><div class="rbbot"><div></div></div></div>';
    	document.getElementById('frame').innerHTML = html; 	
    	
    	html = '<img class="headerImage" src="image.php5?type=image&id='+img_id+'\" /> ';
    	
    	html += dict_name;
    	document.getElementById('header-main').innerHTML = html; 	
    	
    	    	
    	m_sDictName = dict_name;
    	m_nDictID = dict_id;
    	m_nImgID = img_id;
    	
    	addSBX(dict_id,"app_window");
    	
    	if(!m_bLoggedIn)
    	 return;
    	 
    	html = '<ul>';
		html += '<li id="navplay" class="selected">Play</li>';
	  	html += '<li id="navedit" onclick="showEditCurrent();" onmouseover="this.className=\'hover\';" onmouseout="this.className=\'\';">Edit</li>';
	    html += '<li style="font-size: 12px"><< Click here to add more sounds!</li>';
		html += '</ul>';
		
		document.getElementById('nav_left').innerHTML = html; 	
    	
  		
    }
    
    function showEditCurrent()
    {
    	showEdit(m_nDictID,m_sDictName,m_nImgID);   	
     }
    
    function showEdit(dict_id, dict_name, img_id)
    {  
    
    	if(!m_bLoggedIn)
    	 return; 		
    	
    	m_sDictName = dict_name;
    	m_nDictID = dict_id;
    	m_nImgID = img_id;
     	var html;
     	
     	html = '<img class="headerImage" src="image.php5?type=image&id='+img_id+'\" /> ';
    	html += dict_name;
    	document.getElementById('header-main').innerHTML = html; 	
     	
     	html = '<div id="edit_main">Loading . . .</div>';
     	html += '<div style="float:left;margin:0;padding:0;">';
     	html += '<div id="nav_edit">';
     	html += '<ul>';
     	html += '<li name="word_new" onmouseover="this.className=\'hover\'" onmouseout="this.className=\'\'" onmousedown="selectWordEditMode(\'new\')">New</li>';
     	html += '<li name="word_edit" onmouseover="this.className=\'hover\'" onmouseout="this.className=\'\'" onmousedown="selectWordEditMode(\'edit\')">Edit</li>';
       	html += '<li name="word_delete" onmouseover="this.className=\'hover\'" onmouseout="this.className=\'\'" onmousedown="selectWordEditMode(\'delete\')">Delete</li>';
     	html += '</ul>';
    	html += '</div>';
     	html += '<div id="edit_sidebar">';
    	html += '<span id="audioPlayer"></span>';
    	html += '<p id="owner_name">Owner:</p>';
    	html += '<p id="sound_name">Sound Name:</p>';
    	html += '<span id="usage">Usage:</span>';
    	html += '<span id="upload_span"></span>';
    	html += '<iframe frameborder="0" name="upload_frame" id="upload_frame" src="imageupload.php5?action=init" width="260" height="250" ';
    	html += 'style="display:none" ';
    	html += '></iframe>';
    	html += '</div>';	
    	html += '</div>';
    	html += '<div class="rbroundbox" id="footer"><p>Copyright - elevatedstudios.com - email sbx@elevatedstudios.com for questions</p><div class="rbbot"><div></div></div></div>';	
    	 
       	document.getElementById('frame').innerHTML = html; 
    	if(m_nDictID != -1)
    	{
    		finddict_request();//m_nDictID, m_sDictName);
    	}
    	addAudioPlayer(1);
    	
    	html = '<ul>';
		html += '<li id="play" onclick="showPlayCurrent();" onmouseover="this.className=\'hover\';" onmouseout="this.className=\'\';">Play</li>';
		html += '<li id="edit" class="selected">Edit</li>';
		html += '</ul>';
		
		document.getElementById('nav_left').innerHTML = html; 	
    
    }
    
    function selectWordEditMode(sAction)
    {
    	m_sWordEditMode = sAction;

 				
    	switch(sAction)
    	{
	    	case "new":
	    	{
	    		document.getElementById('audioPlayer').innerHTML = "";
		    	document.getElementById('sound_name').innerHTML = ""; 
				document.getElementById('owner_name').innerHTML = "";	
				document.getElementById('usage').innerHTML = "";	
				document.getElementById('upload_span').innerHTML = getUploader(true);
				//document.getElementById('upload_frame').src="imageupload.php5?action=new&dict_id="+m_nDictID;
				break;
			}
			case "edit":
			{
				if((m_nWordID != -1) && (m_sCurrUsername == m_sOwnerName))
				{
					document.getElementById('audioPlayer').innerHTML = "";
					document.getElementById('sound_name').innerHTML = "Word: " + m_sWordName; 
					document.getElementById('owner_name').innerHTML = "Owner: " + m_sOwnerName; 	
					document.getElementById('usage').innerHTML = "";	
					document.getElementById('upload_span').innerHTML = getUploader(false);
					//document.getElementById('upload_frame').src="imageupload.php5?action=edit&sound_id="+m_nWordID;
				}
				break;
			}
			case "delete":
			{
				if((m_nWordID != -1) && (m_sCurrUsername == m_sOwnerName))
				{
					document.getElementById('sound_name').innerHTML = "Are you sure you want to delete \""+ m_sWordName+"\"?"; 
					document.getElementById('owner_name').innerHTML = "This may impact other users who are using this word."; 	
					document.getElementById('usage').innerHTML = ""; 	
					document.getElementById('upload_span').innerHTML = getDelete();
					//document.getElementById('sound_name').innerHTML = "Currently you cannot delete sounds. This feature will be added soon. You can modify and change existing sounds."; 
				}
					break;
			}
			case "empty":
			{
				addAudioPlayer(m_nWordID);
				document.getElementById('sound_name').innerHTML = "Word: "; 
				document.getElementById('owner_name').innerHTML = "Owner: "; 	
				document.getElementById('usage').innerHTML = "Usage: "; 	
				document.getElementById('upload_span').innerHTML = "";
				document.getElementById('upload_frame').src='imageupload.php5?action=init';
				break;
			}
			case "restore":
			{
				addAudioPlayer(m_nWordID);
				document.getElementById('owner_name').innerHTML = "Word \""+m_sWordName+"\" has been deleted"; 
				document.getElementById('sound_name').innerHTML = "If the deletion was accidental, then press restore to restore the sound."; 	
				document.getElementById('usage').innerHTML = ""; 	
				document.getElementById('upload_span').innerHTML = getUploader(false);
				break;
			}
			default:
			{
				addAudioPlayer(m_nWordID);
				document.getElementById('sound_name').innerHTML = "Word: " + m_sWordName; 
				document.getElementById('owner_name').innerHTML = "Owner: " + m_sOwnerName; 	
				document.getElementById('usage').innerHTML = "Usage: " + m_aDefaultTypeNames[m_nTypeId]; 	
				document.getElementById('upload_span').innerHTML = "";
				document.getElementById('upload_frame').src='imageupload.php5?action=init';
			}
		}
    }
    
    function getUploader(bNew)
    {
	   	var html = '<form action="imageupload.php5" id="edit_form" name="edit_form" target="upload_frame" method="post" enctype="multipart/form-data" onsubmit="document.getElementById(\'edit_main\').innerHTML=\'Updating  . . .\';setTimeout( \'finddict_request()\', 2000);this.edit_submit.disabled=true;" >';
	   	html += '<input type="hidden" name="MAX_FILE_SIZE" value="2000000" />';
	   	
 		var nTypeId = 6;
 		var sAlt = "";
 		if(!bNew)
 		{
 			html += '<input type="hidden" name="sound_id" value="'+m_nWordID+'" />';	
 			nTypeId = m_nTypeId;
 			sAlt = m_sAlt;
 			// TODO: If edit, then populate alt and type	
		}
		
		html += '<input type="hidden" name="dict_id" value="'+m_nDictID+'">';
				
		// TODO: Need to pass up the type and alt text via AJAX	
		html += 'Type: '+createTypeSelector(nTypeId)+'';
		html += '<p>alt: <input name="alt" type="text" value="'+sAlt+'" /></p>';
		
		html += '<p>Upload File: <input name="sound_file" id="sound_file" type="file" /></p>';
		if(!bNew)
		{
			html += '<input name="Update" type="submit" id="edit_submit"  value="  Update  " />';
			html += '<input type="hidden" name="action" id="action" value="modify" />';
		}
		else
		{
			html += '<input name="Update" type="submit" id="edit_submit"  value="  Add  " />';
			html += '<input type="hidden" name="action" id="action"  value="add" />';
		}
		
		html += '</form>';
		
		return html;	
    }
    
    function getDelete()
    {
	   	var html = '<form action="imageupload.php5" name="edit_form" id="upload_form1" target="upload_frame" method="post" enctype="multipart/form-data" onsubmit="onDelete();" >';
 		html += '<input name="Update" type="submit" id="edit_submit" value="  Delete  " />';
 		html += '<input type="hidden" name="sound_id" value="'+m_nWordID+'" />';	
 		html += '<input type="hidden" name="action" id="action" value="delete" />';
 		html += '<input type="hidden" name="dict_id" value="'+m_nDictID+'">';
 		html += '<input name="alt" type="hidden" value="'+m_sAlt+'" />';
 		html += '<input name="type" type="hidden" value="'+m_nTypeId+'" />';
		html += '</form>';
				
		return html;	
    }
    
    function onDelete()
    {
    	//alert("onDelete");
	    if(document.getElementById('action').value == "restore")
	    {
	   	 //TODO: Call - selectWordEditMode("detail");
	   	 document.edit_form.edit_submit.disabled = true;
	   	 setTimeout('finddict_request(true)', 2000);
	   	 return;
	    }
    	document.getElementById('edit_main').innerHTML='Updating  . . .';
		document.getElementById('owner_name').innerHTML = "Word \""+m_sWordName+"\" has been deleted"; 
		document.getElementById('sound_name').innerHTML = "If the deletion was accidental, then press restore to restore the sound."; 	
		document.getElementById('usage').innerHTML = ""; 	  
		document.edit_form.edit_submit.disabled = true;	
		setTimeout('finddict_request(true)', 2000);
    }

    function createTypeSelector(nTypeId)
	{
		var str = '';
		str += '<select name="type">';
		var i =0;
		for(i = 0; i < m_nDefaultTypes; i++)
		{
			str +=	'<option value="'+i+'" ';
			if(nTypeId == i)
				str += 'selected="selected" ';
			str += '>';
			str += m_aDefaultTypeNames[i];
			str += '</option>';
		}
		str += '</select>';

		return str;
	}
    
    
    function showHome()
    {
    	var html = '<div class="leftside">';
    	html += '<div id="loginPanel"><ul><li class="header">Login</li></ul><span id="loginContent">This is where login will go</span></div>';
    	html += '<div id="helpPanel"><ul><li class="header">Welcome to didUsay</li></ul><span id="helpContent"></span></div>';
		html += '<div id="previewPanel"><a href="tour.html"><img src="preview.jpg"/></a></div></div>'
		html += '<div class="panelgroup"><div id="sidebar"></div></div>';
		html += '<div class="panelgroup"><div id="main"></div></div>';
		html += '<div class="rbroundbox" id="footer"><p>Copyright - elevatedstudios.com - email sbx@elevatedstudios.com for questions</p><div class="rbbot"><div></div></div></div>';
      	document.getElementById('frame').innerHTML = html; 
      	document.getElementById('header-main').innerHTML = ""; 	
      	//showCategories(true);
      	addSortedSentencePlayer();
      	showDictionaries(true);
      	showHelp();
        showLogin();
 
      	document.getElementById('nav_left').innerHTML = ""; 	
      	m_sMode = "play";
    }
    
    function updateCategories()
    {
      var param = 'action=category';
	  http( 'POST' , 'ajax_request.php', onGetCategories , param );
	}
	
	function showCategories(bUpdate)
	{
		if(bUpdate)
		{
			updateCategories();
			return;
		}
			
		var i;
		var html = '<li class="header">Categories</li>';
		var sID;

		for(i = 0; i < categories._length; i++)
		{
			sID = "cat_"+categories[i].name;
			html += '<li id="'+sID+'" '; 
			html += 'onmouseover="this.className=\'hover\'" ';
			html += 'onmouseout="this.className=\'\';" >';
			html += categories[i]['name']+"</li>";
		}
		document.getElementById('sidebar').innerHTML = html;
	
	}
	
	function onGetCategories(obj)
	{
		categories = obj;
		//showCategories(false);
	}
	
	function updateDictionaries()
    {
      var param = 'action=dictionary';
	  http( 'POST' , 'ajax_request.php', onGetDictionaries , param );
	}
	
	function showDictionaries(bUpdate)
	{
		if(bUpdate)
		{
			document.getElementById('main').innerHTML = "loading...";
			updateDictionaries();
			return;
		}
		

		var i;
		var html = "<li class='header'>Top Dictionaries</li>";
		var sID;
		var nID;
		var sImg;
		for(i = 0; i < dictionaries._length; i++)
		{
			sID = "dict_"+dictionaries[i].name;
			nID = dictionaries[i].id;
			sImg = '<img class="centeredImage" src="image.php5?type=image&size=small&id='+dictionaries[i].imgid+'\"/>';

			html += '<li class="seperated" id="'+sID+'" '; 
			html += 'onmouseover="this.className=\'selected\'" ';
			html += 'onmouseout="this.className=\'seperated\'" ';
			html += 'onmousedown="showPlay('+nID+',\''+dictionaries[i].name+'\','+dictionaries[i].imgid+');" >';
			html += sImg;
			html += dictionaries[i]['name'] + " - " + dictionaries[i]['nCount'] + " words";
			html += "<br><span style='font-size: 10px'>Last word added by " + dictionaries[i]['sUser'] + "</span>";
			html += '</li>';
		}
		document.getElementById('main').innerHTML = html;
	
	}
	
	function onGetDictionaries(obj)
	{
		dictionaries = obj;
		showDictionaries(false);
	}
    
	function updateDetailsPanel(nWordID, sWordName, nOwnerID, sOwnerName, sCurrUsername, nTypeId, sAlt )
	{
		//alert(nWordID + " " + sWordName + " " + nOwnerID + " " +  sOwnerName + " " +  sCurrUsername);
	   	m_nWordID = nWordID;
	   	m_sWordName = sWordName;
    	m_nOwnerID = nOwnerID;
		m_sOwnerName = sOwnerName;
		m_nTypeId = nTypeId;
		m_sAlt = sAlt;
		m_sCurrUsername = sCurrUsername;
		selectWordEditMode("detail");
	}
	
    function finddict_request()
	{
		var param = 'action=words&dict='+m_nDictID+'&viewmode='+m_sViewMode;
		document.getElementById('edit_main').innerHTML = " Loading " + m_sDictName + " . . . ";
		http( 'POST' , 'ajax_request.php', finddict_response , param );
	    sShow = m_sDictName; 
    }
   	
   
   	function finddict_response(obj)
   	{
   		m_pResponse = obj;
   		parseDictResponse();
   		
   		document.edit_form.edit_submit.disabled = false;	
   		if(document.getElementById('action').value == "restore")
   		{
   			selectWordEditMode("details");
   		}
   		else if(document.getElementById('action').value == "delete")
   		{
   			document.getElementById('action').value = "restore";
   		//	document.getElementById('upload').value = "restore";
   			document.edit_form.edit_submit.value = "Restore";
   		}
   		//selectWordEditMode("restore");
   		
   	
   	}
	
	function selectView(sMode)
	{
		m_sViewMode = sMode;
		finddict_request();
	}
	
	function selectTypeFilter( nTypeId )
	{
		//alert(nTypeId);
		m_nTypeId = nTypeId;
		parseDictResponse();
	}
	
	function parseDictResponse( )
	{
	    if(m_pResponse._length == 0)
	    {
		    document.getElementById('edit_main').innerHTML = "There are no sounds in this dictionary - Please select New to add the first word.";
	    }
	    else
	    {
	        document.getElementById('edit_main').innerHTML = "Loading . . .";
	    }
	    
		// DIV the entire section containting the words
		var sHtml = '<div>';
			
		// Show the views
		sHtml += '<ul class="menu_views">';
		sHtml += '<li class="menu_normal" style="font-size:14px;color:#FAA">View:</li>';
		if(m_sViewMode == "top")
			sHtml += '<li class="menu_sel">Top 100</li>';
		else
			sHtml += '<li class="menu_normal" onmouseover="this.className=\'menu_hover\'" onmouseout="this.className=\'menu_normal\'" onmousedown="selectView(\'top\')">Top 100</li>';
		
		if(m_sViewMode == "all")
			sHtml += '<li class="menu_sel">All</li>';
		else
			sHtml += '<li class="menu_normal" onmouseover="this.className=\'menu_hover\'" onmouseout="this.className=\'menu_normal\'" onmousedown="selectView(\'all\')">All</li>';
		
		if(m_sViewMode == "my")
			sHtml += '<li class="menu_sel">My Sounds</li>';
		else
			sHtml += '<li class="menu_normal" onmouseover="this.className=\'menu_hover\'" onmouseout="this.className=\'menu_normal\'" onmousedown="selectView(\'my\')">My Sounds</li>';
		

		sHtml += '</ul>';
		

		// Show the categories
		// TODO: May change this to a dropdown list
		sHtml += '<ul class="menu_categories">';
		sHtml += '<li class="menu_normal" style="font-size:14px;color:#FAA">Filter:</li>';
		for(var i=0; i < m_pResponse.type._length; i++)
		{
			if(m_pResponse.type[i].id == m_nTypeId)
			 	sHtml += '<li class="menu_sel">'+m_pResponse.type[i].name+'</li>';
			else
				sHtml += '<li class="menu_normal" onmouseover="this.className=\'menu_hover\'" onmouseout="this.className=\'menu_normal\'" onmousedown="selectTypeFilter('+m_pResponse.type[i].id+')">'+m_pResponse.type[i].name+'</li>';
		}
		
		if(-1 == m_nTypeId)
			 	sHtml += '<li class="menu_sel">Off</li>';
			else
				sHtml += '<li class="menu_normal" onmouseover="this.className=\'menu_hover\'" onmouseout="this.className=\'menu_normal\'" onmousedown="selectTypeFilter(-1)">Off</li>';
		
		sHtml += '</ul>';

		var nCol = 0;
		var nRow = 0;
		
		for(var i=0; i < m_pResponse._length; i++) 
		{
			if((m_nTypeId == -1) || (m_nTypeId == m_pResponse[i].type_id))
			{
				var sound_short = m_pResponse[i].name.substring(0,15);
				var sound_long = m_pResponse[i].name;
				
				// This div defines the start of a row
				if(nCol == 0)
				{
					sHtml += '<div style="clear:both;" >';
				}
				
			    sHtml += '<div class="word_normal" id="'+m_pResponse[i].id+'" ';
				
				sHtml += 'onmouseover="this.className=\'word_hover\'" onmouseout="this.className=\'word_normal\'"" '
				sHtml += 'onmouseover="this.className=\'word_hover\'" onmouseout="this.className=\'word_normal\'"" ';
				sHtml += "onmousedown=\"updateDetailsPanel("+m_pResponse[i].id+", '"+sound_long+"', 0, '"+m_pResponse[i].user_name+"','"+m_pResponse.curruser+"','"+m_pResponse[i].type_id+"','"+m_pResponse[i].alt+"')\">";
			
				sHtml += sound_short + '</div>';
				
				// This div defines the end of a row
				if(nCol  == 4)
				{
			        sHtml += '</div>';
					nCol = 0;
					nRow++;
				}
				else
				{
					nCol++;
				}
			}   
		}
		if(nCol != 0)
		   sHtml += '</div>'; 

		sHtml += '</div>';
		
		document.getElementById('edit_main').innerHTML = sHtml;

   }
   
   function showHelp()
   {
   		var sHtml = '';
   		sHtml += "<ul class='bulletlist'>";
   		sHtml += "<li>Take Sounds and arrange them any way you like using the easy to use drag and drop interface</li>";
   		sHtml += "<li>Save your creations and share them with your friends</li>";
   		sHtml += "<li>Add new sounds to the sound boards as a community. Your sounds will be heard by everyone. Also the sounds can be in any format</li>";
   		sHtml += "<li>Currently you cannot create new boards and you cannot delete sounds you add.  I am working to correct this</li>";
   		sHtml += "<li>Note: that the categories selection does not work.</li>";
   		sHtml += "<li>Note: Loading the sound for the first time may take a few seconds.  Once played, setences and words will play much faster.</li>";
   		sHtml += "<li>Report any bugs to sbx@elevatedstudios.com</li>";
   		sHtml += "<li>Coming soon - Create your own soundboards. </li>";
   		sHtml += "</ul>";
   
   		document.getElementById("helpContent").innerHTML = sHtml;
   }
   
   function showLogin()
   {

 	    var sHtml = '';
 	    
 	    if(m_bLoggedIn)
 	    {
 	    	sHtml += "Welcome " + m_sUsername;
 	    	document.getElementById("logout").innerHTML = '<li onclick="onLogout();" onmouseover="this.className=\'hover\';" onmouseout="this.className=\'\';">Logout</a></li>';
 	    }
		else
		{
	   		sHtml += "<ul style='padding-left: 5px;' class='nobulletlist'>";
	   		sHtml += '<form action="login.php5" id="login_form" name="login_form" method="post" enctype="multipart/form-data" onsubmit="this.login_submit.disabled=true;login_request(this.username.value, this.pass.value);return false;" >';
			sHtml += '<li>Username:</li>';
			sHtml += '<li><input type="text" name="username" maxlength="100">';
			sHtml += '<li>Password:</li>';
			sHtml += '<li><input type="password" name="pass" maxlength="100"></li>';
			sHtml += '<li><input type="submit" name="submit" id="login_submit" value="   Login   "></li>';
			sHtml += '</form>';
			sHtml += '<li style="text-align: right;"><a href="registration.php">Click here to Register</a></li>';			
			sHtml += "</ul>";
			
			document.getElementById("logout").innerHTML = '';
		}
				
		document.getElementById("loginContent").innerHTML = sHtml;

   }
   
    function login_request(sUsername, sPassword)
	{
		var param = 'username='+sUsername+'&password='+sPassword;
		http('POST', 'login.php5', login_response , param);
    }
   	
   	function login_response(obj)
   	{
   		if(obj["status"] == "200")
   		{
   			m_bLoggedIn = true;
   			m_sUsername = obj["sUsername"];
   		}
   		else
   		{
   			alert("Log in failed, EC = " + obj["status"]);
   		}
   		
   		showLogin();
   	}
   	
   	function logout_request()
	{
	 	 document.getElementById("logout").innerHTML = '<li>Logging Out . . .</li>';
		 http('POST', 'logout.php5', logout_response);
    }
   	
   	function logout_response(obj)
   	{
   		if(obj["status"] == "200")
   		{
   			m_bLoggedIn = false;
   			m_sUsername = "";
   			showHome();
   		}
   	}
   	   	
   	function onLogout()
   	{
   		logout_request();
   	}
   	
   	function addSortedSentencePlayer()
	{
		var sentencePlayer = new SWFObject("SentencePlayer.swf", "sentence", "300", "500", "8", "#EFDBCD");
		sentencePlayer.addVariable("sort", "random");
		sentencePlayer.addVariable("limit", "10");
		sentencePlayer.addParam("scale", "noscale");
		sentencePlayer.write("sidebar");
	}	
   		
   

