
/***  DOCUMENTATION LAYER

	Mushpup Functions

	File: mushpup.js
	Last Update: Jul 2006
	Author: Tom Atwell (klenwell@gmail.com), Wired Jaw Technologies
	License: BSD (See Bottom for Full License)

	FUNCTIONS:
	
		mushpup_load()
		min_sidebar_faq()
		mushpup_reset_form()
		mushpup_get_hash()
		mushpup_show_passkey_confirm(show)
		mushpup_show_now_what(show)
		mushpup_show_faq(show)
		mushpup_capture_ctrlc(e)


  NOTES:
	
		To link: <script type="text/javascript" src="path/to/mushpup.js"></script>

______________________________________________________________________________*/


// mushpup_load
/*____________________________________________________________________________*/
function mushpup_load()
{
	// Register Key Capturer	
	document.onkeyup = mushpup_capture_ctrlc;
	
} // end Fx
/*____________________________________________________________________________*/



// min_sidebar_faq
/*____________________________________________________________________________*/
function min_sidebar_faq()
{
	dom_no_display_id('sidebar_faq');
	dom_display_id('sidebar_preset');
	document.getElementById('pitch').style.margin = "0";
	
} // end Fx
/*____________________________________________________________________________*/



// mushpup_reset_form
/*____________________________________________________________________________*/
function mushpup_reset_form()
{
	// *** DATA
		
			
	// *** MANIPULATE
	
		// Clear Form Fields
		dom_form_set_value("mushpup_passkey", "");
		dom_form_set_value("site", "");
		
		// Reset Toggles
		mushpup_show_passkey_confirm(0);
		mushpup_show_now_what(0);
		mushpup_show_faq(0);
		dom_display_id("noob_block", "block");
		dom_no_display_id("solution_block_parent");
		dom_no_display_id("noob_table");
	
	// *** RETURN
	
		return;
	
} // end Fx
/*____________________________________________________________________________*/



// mushpup_get_hash()
/*____________________________________________________________________________*/
function mushpup_get_hash()
{
	// *** DATA
	
		// Debug
		var _debug = 0;

		// Document Objects
		var dom_key = document.getElementsByName("mushpup_passkey")[0];
		var dom_check_key = document.getElementsByName("passkey_confirm_input")[0];
		var dom_context = document.getElementsByName("site")[0];
		var dom_password = document.getElementsByName("password_hash")[0];
	
		// Internal
		var input_key = '';
		var input_context = '';
		var trim_key = '';
		var trim_context = '';
		var salt = '';
		var raw_hash = '';
		var the_hash = '';		 
		
		// Return
		// void
		
			
	// *** MANIPULATE
	
		// DEBUG
		if ( _debug ) alert('mushpup called');
	
		// Get Values
		input_key = dom_key.value;
		input_check_key = dom_check_key.value;
		input_context = dom_context.value;

		// Trim Input Fields
		trim_key = js_trim(input_key);
		trim_check_key = js_trim(input_check_key);
		trim_context = js_trim(input_context);
		
		// DEBUG
		if ( _debug ) alert('input key: ' + input_key);
		if ( _debug ) alert('trim_check_key: ' + trim_check_key);
		
		// Check Keys
		if ( (trim_check_key != '__^skip$__') && (trim_key != trim_check_key) )
		{
			alert("your mushpup secret words didn't match.  carefully re-enter them.");
			return;
		}
		
		// Empty Warnings
		if ( trim_key == "" ) alert('Warning: the mushpup secret word you entered is blank.');
		if ( trim_context == "" ) alert('Warning: the url you entered is blank.'); 

		// Concatenate
		salt = trim_context + trim_key;
		if ( _debug ) alert('salt: ' + salt);
		
		// Hash
		raw_hash = mushpup_sha24(salt);
		
		// Style
		the_hash = ( '<span class="hash0">' + raw_hash.substr(0,8) + "</span>" );
		the_hash += ( '<span class="hash1">' + raw_hash.substr(8,8) + "</span>" );
		the_hash += ( '<span class="hash0">' + raw_hash.substr(16,8) + "</span>" );
		the_hash += ( '<span class="hash1">' + raw_hash.substr(24,8) + "</span>" );
		
		
		// Display
		dom_no_display_id("noob_block");
		dom_display_id("solution_block_parent", "block");
		dom_set_id_html("the_hash", the_hash);
	
	
	// *** RETURN
	
		return raw_hash;

} // end Fx
/*____________________________________________________________________________*/


// mushpup_show_passkey_confirm
/*____________________________________________________________________________*/
function mushpup_show_passkey_confirm(show)
{
	// *** DATA
	
		// Block IDs
		var id1 = "confirm_activate";
		var id2 = "passkey_confirm";
		var confirm_field = "passkey_confirm_input";
		
		// Return
		// Void
		
			
	// *** MANIPULATE
	
		// Hide Activate Link
		
		// Show Input Field
		if ( show )
		{
			dom_no_display_id(id1);
			dom_display_id(id2, "block");
			dom_form_set_value(confirm_field, "");
		}
		else
		{
			dom_no_display_id(id2);
			dom_display_id(id1, "block");
			dom_form_set_value(confirm_field, "__^skip$__");			
		}
	
	
	// *** RETURN
	
		return;
	
} // end Fx
/*____________________________________________________________________________*/



// mushpup_show_now_what
/*____________________________________________________________________________*/
function mushpup_show_now_what(show)
{
	// *** DATA
		
		// Return
		// Void
		
			
	// *** MANIPULATE
	
		// Hide Activate Link
		
		// Show Input Field
		if ( show )
		{
			dom_no_display_id("not_sure");
			dom_display_id("now_what_block", "block");
		}
		else
		{
			dom_no_display_id("now_what_block");
			dom_display_id("not_sure", "block");
		}
	
	
	// *** RETURN
	
		return;
	
} // end Fx
/*____________________________________________________________________________*/


// mushpup_show_faq
/*____________________________________________________________________________*/
function mushpup_show_faq(show)
{
	// *** DATA
	
		// Block IDs
		var id1 = "sidebar_preset";
		var id2 = "sidebar_faq";
		
		// Document Objects
		var solutionObj = document.getElementById('solution_block_parent');
		var pitchObj = document.getElementById('pitch');
		
		// Return
		// Void
		
			
	// *** MANIPULATE

		// Hide Activate Link
		if ( show == null ) show = 0;
		
		// Show Input Field
		if ( show )
		{
			dom_no_display_id(id1);
			dom_display_id(id2, "block");
			pitchObj.style.margin = "0 0 0 26%";
			solutionObj.style.margin = "0 0 10px 26%";
		}
		else
		{
			dom_no_display_id(id2);
			dom_display_id(id1, "block");
			pitchObj.style.margin = "0";
			solutionObj.style.margin = "0 0 10px 0";
		}
	
	
	// *** RETURN
	
		return;
	
} // end Fx
/*____________________________________________________________________________*/



// mushpup_capture_ctrlc
/*____________________________________________________________________________*/
function mushpup_capture_ctrlc(e)
{
	// *** DATA
	
		// DEBUG
		var _debug = 0;
	
		var pressed = (window.event) ? event : e;
		var key_code = (window.event) ? event.keyCode : e.keyCode;
		
			
	// *** MANIPULATE
	
		// DEBUG
		if ( _debug) alert('event keycode is ' + key_code);
		if ( _debug && pressed.ctrlKey ) alert('ctrl key pressed');
	
		// Ctrl-C Pressed
		if ( pressed.ctrlKey && key_code == 67)
		{
			if ( _debug) alert('ctrl-c has been pressed -- will reset form');
  		
			// Reset Form
			mushpup_reset_form();
  	}
		else
		{
			if ( _debug) alert('did not press ctrl-c');
		}
	
	
	// *** RETURN
	
		return;
	
} // end Fx
/*____________________________________________________________________________*/



/***  LICENSE (http://www.opensource.org/licenses/bsd-license.php)

	Copyright (c) 2006, Tom Atwell (klenwell@gmail.com)
	Wired Jaw Technologies (http://www.wiredjawtech.com/)
	All rights reserved.

	Redistribution and use in source and binary forms, with or without modification, 
	are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice, 
			this list of conditions and the following disclaimer.
			
    * Redistributions in binary form must reproduce the above copyright notice, 
			this list of conditions and the following disclaimer in the documentation 
			and/or other materials provided with the distribution.
			
    * Neither the name of Wired Jaw Technologies nor the names of its contributors 
			may be used to endorse or promote products derived from this software without 
			specific prior written permission.

	THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
	ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
	WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
	IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
	INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
	BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
	DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
	LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
	OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
	OF THE POSSIBILITY OF SUCH DAMAGE.
______________________________________________________________________________*/


