/*
	!!***********************************************************************!!
	!!***********************************************************************!!
	!!********* MAKE SURE THAT ANY FILE UTILIZING THIS JS FILE ALSO *********!!
	!!*************** HAS common.modal.css, common.buttons.css **************!!
	!!***************************** and JQUERY! *****************************!!
	!!***********************************************************************!!
	!!***********************************************************************!!

	Javascript Modal Dialog--
		This script allows for a quick call to a MD_Generate_[pagetype]() function
		on a page to bring up a desired dialog.  All dialogs are pre-defined.

	Rach 04/07/2010-04/21/2010 and then some
*/

/******************************************************************************************************************/
/******************************************************************************************************************/
/********************** global variables - easily change values outside of functions, such as *********************/
/************************** the border's image dimensions, height of the header, etc... ***************************/
/******************************************************************************************************************/
/******************************************************************************************************************/

/* Global attributes, feel free to change if the images change */
// Width/height of the images for the border corners
var BORDER_W = 48;
var BORDER_H = 48;
// Minimum size a modal can be without looking funny
var MIN_MODAL_W = BORDER_W*2;
var MIN_MODAL_H = BORDER_H*2;
// Height of the header
var MODAL_HEADER_HEIGHT = 50;

// Used to reset modal size
var modal_original_w;
var modal_original_h;
var error_lastResize;

// For error checking
var errorMessage = new Array();
var errorCount = 0;
var errorPresent = false;
var debugLog = new Array();
var debug = false;
var debugDisplayIndividually = false;

// Links that we need, passed to CreateModal.  Based on PHP function
var link_PrivacyPolicy;
var link_ImagePath;

// Name of botcheck input field.  Didn't want to use the word 'bot' in case bots check for that. o_O
var botCheckField = "Grilled_Cheese_Sandwich";

/**************************** LINK FUNCTIONS ***********************************/
// These are to be passed, with the argument being a <? HrefGo() ?> link

/**
* Allows user to set the link to the Privacy Policy (usually will pass a HrefGo function return)
* @param 		string path URL to the privacy policy
* @author 	Rach
*/
function MD_Link_PrivacyPolicy( path ) 	{ link_PrivacyPolicy 	= path; } // Relative path to privacy policy page

/**
* Allows user to set the image asset path
* @param 		string path URL to the ^assets/images folder
* @author 	Rach
*/
function MD_Link_ImagePath( path ) 			{ link_ImagePath 			= path; }	// Relative path for images


/******************************************************************************************************************/
/******************************************************************************************************************/
/******************************************************************************************************************/
/******************* "public" functions - to be called by other pages to generate modal dialogs *******************/
/******************************************************************************************************************/
/******************************************************************************************************************/
/******************************************************************************************************************/

/**
* Closes the super container and kills it prettily with JQuery effects
*
* @author 	Rach
*/
function MD_Close_Dialog()		// FXCLOSEDIALOG
{
	// Clear out error messages
	errorMessage.length = 0;
	errorCount = 0;

	$('#div_modal_container').fadeOut( 'slow', function()
		{
			// Destroy super container
			var dialog = document.getElementById( "super_container" );
			if ( dialog != null )
			{
				dialog.style.display = "none";
				dialog.parentNode.removeChild( dialog );
			}

			// Destroy veil
			dialog = document.getElementById( "veil" );
			if ( dialog != null )
			{
				dialog.style.display = "none";
				dialog.parentNode.removeChild( dialog );
			}
		} );
} // MD_Close_Dialog

/**
* Allows the user to get the value of an element on the Modal
*
* @param 		string		elementid		ID or name of the element whose value we want
* @author 	Rach
*/
function MD_Get_Value( elementid )	// FXGETVALUE
{
	var item = document.getElementById( elementid );
	if ( item == null ) { errorMessage[errorCount++] = "<MD_Get_Value(...)> could not find item " + elementid; MD_Display_Errors(); return; }
	return item.value;
}

/**
* Generates a "Are you sure? (y/n)" -type page.  Currently unused and incomplete
*
* @param 		string		formid		Name that the modal's form will have
* @author 	Rach
*/
function MD_Generate_Confirmation( formid ) // FXCONFIRMATION
{
	modal_original_w = 550;
	modal_original_h = 250;

	MD_Create_BaseWindow( "Are you sure you want to do this?", modal_original_w, modal_original_h, formid );

	// Helper variables to make formatting easier
	var offsetY = 20;
	var spacing = 20;
	var labelOffsetX = 50;

	// Populate the dialog window
	MD_Create_Label						( "modal_body", labelOffsetX, offsetY, 	"Are you sure you want to do this? Changes may be irreversible." );
	MD_Create_CancelButton		( "modal_body", 100, 					offsetY+(2*spacing),	"No", 	"button_submit", "XL", "red" );
	MD_Create_SubmitButton		( "modal_body", 275, 					offsetY+(2*spacing),	"Yes", 	"button_submit", "XL", "green" );

	MD_Create_BotCheckInput( "modal_body" );

	// Output any errors that arose during window creation
	MD_Display_Errors();
} // MD_Generate_Confirmation

/**
* Generates a Contact Us page, with fields for Name, Email, Phone, Subject and Message.
*
* @param 		string			formid			Name that the modal's form will have
* @param 		array				dialogtext	String array of all the text that will be displayed in the form- this is for language support.
*
* @author 	Rach
*
* 04/30/2010 Changed out the one-line-textarea inputs to the new MD_Create_TextboxInput function
*/

function MD_Generate_ContactUs( formid, dialogtext ) // FXCONTACTUS
{
	modal_original_w = 550;
	modal_original_h = 550;
	//var textarray = dialogtext.split('~'); // strings are separated by ~'s

	//if ( textarray.length < 8 ) { errorMessage[errorCount++] = "<MD_Generate_FeedbackForm(...)> Not enough strings passed to function.  Need 7."; }

	MD_Create_BaseWindow( "Contact Us", modal_original_w, modal_original_h, formid );

	// Helper variables to make formatting easier
	var offsetY = 30;
	var spacing = 40;
	var labelOffsetX = 15;

	// Populate the dialog window
	// function MD_Create_PrivacyStatement( parentName, x, y, text1, text2 )
	MD_Create_PrivacyStatement( "modal_body", 0,								offsetY, "We take your privacy very seriously at StorageFront.  View our ", "privacy policy." );

	// function MD_Create_Label( parentName, x, y, label )
	MD_Create_Label						( "modal_body", labelOffsetX, 		offsetY+(1*spacing), 	  "Name (optional:)" );
	MD_Create_TextboxInput		( "modal_body", 200, 							offsetY+(1*spacing), 		200, "pra_name", false, true );

	MD_Create_Label						( "modal_body", labelOffsetX, 		offsetY+(2*spacing),    "Email (optional):" );
	MD_Create_TextboxInput		( "modal_body", 200, 							offsetY+(2*spacing), 		200, "pra_email", false, false );

	MD_Create_Label						( "modal_body", labelOffsetX, 		offsetY+(3*spacing), 		"Phone (optional):" );
	MD_Create_TextboxInput		( "modal_body", 200, 							offsetY+(3*spacing), 		200, "pra_phone", false, false );

	MD_Create_Label						( "modal_body", labelOffsetX, 		offsetY+(4*spacing), 		"Subject:" );
	MD_Create_TextboxInput		( "modal_body", 200, 							offsetY+(4*spacing), 		200, "pra_subject", true, false );

	MD_Create_Label						( "modal_body", labelOffsetX, 		offsetY+(5*spacing), 		"Message:" );
	MD_Create_TextareaInput		( "modal_body", 200, 							offsetY+(5*spacing), 		200, 125, 5, "pra_message", true, false );

	MD_Create_SubmitButton		( "modal_body", 380, 							offsetY+(9*spacing),			"Send", 	"button_submit", "S", "green" );

	// MD_Create_InvisibleInput( parentName, objectType, objectName, objectValue )
	MD_Create_InvisibleInput( "modal_body", "hidden", "feedback_action", "send_mail" );

	MD_Create_BotCheckInput( "modal_body" );

	// Output any errors that arose during window creation
	MD_Display_Errors();
	MD_Display_DebugLog();

	$('.focus_field').focus();	// Set focus to the field that has the class "focus_field"
}

/**
* Generates a dialog box to let the user know the Contact Us email has been sent.
*
* @param 		string			formid			Name that the modal's form will have
* @param 		array				dialogtext	String array of all the text that will be displayed in the form- this is for language support.
*
* This function currently does not support multiple languages, and is hard-coded as English.
*
* @author 	Rach
*/
function MD_Generate_ContactUsConfirmation( formid, dialogtext ) // FXCONTACTUSCONFIRMATION
{
	modal_original_w = 550;
	modal_original_h = 225;
	//var textarray = dialogtext.split('~'); // strings are separated by ~'s
	/*
		textarray[0] = feedback_text_8 	= Thank you for your feedback
		textarray[1] = feedback_text_9		= Close Window
	*/

	// Helper variables to make formatting easier
	var offsetY = 15;
	var spacing = 15;

	//if ( textarray.length < 2 ) { errorMessage[errorCount++] = "<MD_Generate_FeedbackConfirmation(...)> Not enough strings passed to function.  Need 2."; }
	MD_Create_BaseWindow( "Your message is being processed", modal_original_w, modal_original_h, formid );

	MD_Create_Label						( "modal_body", 90, offsetY, 	"Thank you for taking the time to contact us." );
	MD_Create_Label						( "modal_body", 120, offsetY + (1*spacing), 	"Your message has been sent." );

	MD_Create_CancelButton( "modal_body", 190, offsetY + (2*spacing)+20,		"Close", "button_close_confirm", "S", "green" );

	MD_Display_Errors();
	MD_Display_DebugLog();
} // MD_Generate_ShowFriendConfirmation

/**
* Generates an Inquiry window for users looking at minipages.
*
* @param	boolean					loggedIn	whether the user is logged in or not - not used for first version
* @param	string-array		text			Text used in the modal - this is for language support
*
* @author Rach
*
* 05/19/2010 Created function to replace MD_Generate_InquiryNotLoggedIn
*/
function Modal_Inquiry( loggedIn, text )
{
	modal_original_w = 550; 	modal_original_h = 525;
	MD_Create_BaseWindow( text["header"], modal_original_w, modal_original_h, "inquiry_form" );

	var div = "modal_body";
	var x1 = 50, x2 = 200, x3 = 380, w = 200, h = 125, y = 30, s = 40;

	// Populate the dialog window
	MD_Create_PrivacyStatement( div, 40, y, text["privacy_text1"], text["privacy_text2"] );

	MD_Create_Label( div, x1, y+s, text["first_name"] );
	//function MD_Create_TextboxInput( parentName, x, y, w, textboxid, requiredField, defaultFocus )
	MD_Create_TextboxInput( div, x2, y+s, w, "name_first", true, true );

	MD_Create_Label( div, x1, y+2*s, text["last_name"] );
	MD_Create_TextboxInput( div, x2, y+2*s, w, "name_last", true, false );

	MD_Create_Label( div, x1, y+3*s, text["email"] );
	MD_Create_TextboxInput( div, x2, y+3*s, w, "email", true, false );

	MD_Create_Label( div, x1, y+4*s, text["phone"] );
	MD_Create_TextboxInput( div, x2, y+4*s, w, "phone", true, false );

	MD_Create_Label( div, x1, y+2*s, text["questions"] );
	//function MD_Create_TextareaInput( parentName, x, y, w, h, rowCount, textareaid, requiredField, defaultFocus )
	MD_Create_TextareaInput( div, x2, y+5*s, w, h, 5, "question", true, false );

	MD_Create_SubmitButton( div, x3, y+9*s-15, text["close"], "button_submit", "S", "green" );

	MD_Create_InvisibleInput( div, "hidden", "subject", "&nbsp;" );
	MD_Create_InvisibleInput( div, "hidden", "rand", "&nbsp;" );
	MD_Create_InvisibleInput( div, "hidden", "command", "question_guest" );

	MD_Create_BotCheckInput( div );

	MD_Display_Errors();

	$('.focus_field').focus();
}

/**
* Generates an Inquiry window for users looking at minipages.
* Includes Privacy Policy link and input fields for Name, Email, Phone, and their Inquiry
*
* @param 		string			formid			Name that the modal's form will have
* @param 		array				dialogtext	String array of all the text that will be displayed in the form- this is for language support.
*
* @author 	Rach
*
* 04/30/2010 Changed out the one-line-textarea inputs to the new MD_Create_TextboxInput function
*/
function MD_Generate_InquiryNotLoggedIn( formid, dialogtext ) // FXINQUIRY
{
	modal_original_w = 550;
	modal_original_h = 525;

	var textarray = dialogtext.split('~'); // strings are separated by ~'s
	/*
		textarray[0] = send_inquiry_header_2 			= Send us an inquiry!
		textarray[1] = send_inquiry_text_4 				= We take your privacy very seriously at StorageFront. View our
		textarray[2] = send_inquiry_text_5 				= privacy policy
		textarray[3] = send_inquiry_text_6  			= First Name:
		textarray[4] = send_inquiry_text_25  			= Last Name:
		textarray[5] = send_inquiry_text_7 				= Email:
		textarray[6] = send_inquiry_text_8 				= Daytime Phone:
		textarray[7] = send_inquiry_text_9 				= Questions?
		textarray[8] = send_inquiry_text_10 			= Close
	*/
	if ( textarray.length < 9 ) { errorMessage[errorCount++] = "<MD_Generate_InquiryNotLoggedIn(...)> Not enough strings passed to function.  Need 7."; }

	MD_Create_BaseWindow( textarray[0], modal_original_w, modal_original_h, formid );

	// Helper variables to make formatting easier
	var offsetY = 30;
	var spacing = 40;
	var labelOffsetX = 50;

	// Populate the dialog window
	MD_Create_PrivacyStatement( "modal_body", 40,								offsetY, textarray[1], textarray[2] );

	MD_Create_Label						( "modal_body", labelOffsetX, 		offsetY+(1*spacing), 		textarray[3] );
	MD_Create_TextboxInput		( "modal_body", 200, 							offsetY+(1*spacing), 		200, "name_first", true, true );

	MD_Create_Label						( "modal_body", labelOffsetX, 		offsetY+(2*spacing), 		textarray[8] );
	MD_Create_TextboxInput		( "modal_body", 200, 							offsetY+(2*spacing), 		200, "name_last", true, false );

	MD_Create_Label						( "modal_body", labelOffsetX, 		offsetY+(3*spacing),  	textarray[4] );
	MD_Create_TextboxInput		( "modal_body", 200, 							offsetY+(3*spacing), 		200, "email", true, false );

	MD_Create_Label						( "modal_body", labelOffsetX, 		offsetY+(4*spacing), 		textarray[5] );
	MD_Create_TextboxInput		( "modal_body", 200, 							offsetY+(4*spacing), 		200, "phone", true, false );

	MD_Create_Label						( "modal_body", labelOffsetX, 		offsetY+(5*spacing), 		textarray[6] );
	MD_Create_TextareaInput		( "modal_body", 200, 							offsetY+(5*spacing), 		200, 125, 5, "question", true, false );

	MD_Create_SubmitButton		( "modal_body", 380, 							offsetY+(9*spacing)-15,	textarray[7], 	"button_submit", "S", "green" );

	//MD_Create_InvisibleInput( parentName, objectType, objectName, objectValue )
	//MD_Create_InvisibleInput( "modal_body", "hidden", "name_last", "" );
	MD_Create_InvisibleInput( "modal_body", "hidden", "subject", "&nbsp;" );
	MD_Create_InvisibleInput( "modal_body", "hidden", "rand", "&nbsp;" );
	MD_Create_InvisibleInput( "modal_body", "hidden", "command", "question_guest" );

	MD_Create_BotCheckInput( "modal_body" );

	// Output any errors that arose during window creation
	MD_Display_Errors();

	$('.focus_field').focus();	// Set focus to the field that has the class "focus_field"
} // MD_Generate_Inquiry

/**
* Generates a Reserve page, with fields for Name, Email, and Phone.
*
* @param 		string			formid					Name that the modal's form will have
* @param		string			whatValue				The type of the storage facility they're trying to reserve (size)
* @param		string			priceValue			The price of the storage facility they're trying to reserve
* @param		string			descValue				The ?
* @param		string			featuresValue		The features available to the facility they're trying to reserve
* @param 		array				dialogtext			String array of all the text that will be displayed in the form- this is for language support.
*
* @author 	Rach
*
* 04/30/2010 Changed out the one-line-textarea inputs to the new MD_Create_TextboxInput function
*/
function MD_Generate_ReserveNotLoggedIn( formid, whatValue, priceValue, descValue, featuresValue, dialogtext ) // FXRESERVATION FXRESERVE
{
	modal_original_w = 550;
	modal_original_h = 400;
	var textarray = dialogtext.split('~'); // strings are separated by ~'s
	/*
		textarray[0] = reserve_online_header_1 			= Ready to reserve
		textarray[1] = reserve_online_text_1 				= We take your privacy very seriously at StorageFront. View our
		textarray[2] = reserve_online_text_2 				= privacy policy
		textarray[3] = reserve_online_text_3  			= First Name:
		textarray[4] = reserve_online_text_4 				= Email:
		textarray[5] = reserve_online_text_5 				= Daytime Phone:
		textarray[6] = reserve_online_text_6 				= Cancel
		textarray[7] = reserve_online_text_7 				= Submit
	*/
	if ( textarray.length < 8 ) { errorMessage[errorCount++] = "<MD_Generate_ReserveNotLoggedIn(...)> Not enough strings passed to function.  Need 7."; }

	MD_Create_BaseWindow( textarray[0], modal_original_w, modal_original_h, formid );

	// Make sure values aren't blank - causes problems with email creation
	if ( whatValue == "" || whatValue == null || whatValue == " " )
		whatValue = "N/A";
	if ( priceValue == "" || priceValue == null || priceValue == " " )
		priceValue = "N/A";
	if ( descValue == "" || descValue == null || descValue == " " )
		descValue = "N/A";
	if ( featuresValue == "" || featuresValue == null || featuresValue == " " )
		featuresValue = "N/A";

	// Helper variables to make formatting easier
	var offsetY = 20;
	var spacing = 40;
	var labelOffsetX = 50;

	// Populate the dialog window
	MD_Create_PrivacyStatement( "modal_body", 40,								offsetY, textarray[1], textarray[2] );

	MD_Create_Label						( "modal_body", labelOffsetX, 		offsetY+(1*spacing), 		textarray[3] );
	MD_Create_TextboxInput		( "modal_body", 200, 							offsetY+(1*spacing), 		200, "name_first", true, true );

	MD_Create_Label						( "modal_body", labelOffsetX, 		offsetY+(2*spacing), 		textarray[4] );
	MD_Create_TextboxInput		( "modal_body", 200, 							offsetY+(2*spacing), 		200, "name_last", true, false );

	MD_Create_Label						( "modal_body", labelOffsetX, 		offsetY+(3*spacing),  	textarray[5] );
	MD_Create_TextboxInput		( "modal_body", 200, 							offsetY+(3*spacing), 		200, "email", true, false );

	MD_Create_Label						( "modal_body", labelOffsetX, 		offsetY+(4*spacing), 		textarray[6] );
	MD_Create_TextboxInput		( "modal_body", 200, 							offsetY+(4*spacing), 		200, "phone", true, false );

	MD_Create_CancelButton		( "modal_body", 100, 							offsetY+(5*spacing)+10,	textarray[7], 	"button_submit", "XL", "red" );
	MD_Create_SubmitButton		( "modal_body", 275, 							offsetY+(5*spacing)+10,	textarray[8], 	"button_submit", "XL", "green" );

	//MD_Create_InvisibleInput( parentName, objectType, objectName, objectValue )
	MD_Create_InvisibleInput	( "modal_body", "hidden", "command", 		"reserve_guest" );
	MD_Create_InvisibleInput	( "modal_body", "hidden", "what", 			whatValue );
	MD_Create_InvisibleInput	( "modal_body", "hidden", "miscinfo", 	"general" );
	MD_Create_InvisibleInput	( "modal_body", "hidden", "price", 			priceValue );
	MD_Create_InvisibleInput	( "modal_body", "hidden", "desc", 			descValue );
	MD_Create_InvisibleInput	( "modal_body", "hidden", "features", 	featuresValue );

	MD_Create_BotCheckInput( "modal_body" );

	// Output any errors that arose during window creation
	MD_Display_Errors();

	$('.focus_field').focus();	// Set focus to the field that has the class "focus_field"
} // MD_Generate_ReserveNotLoggedIn




/**
* QS reservation modal
*
* @param 		string			formid					Name that the modal's form will have
* @param		string			whatValue				The type of the storage facility they're trying to reserve (size)
* @param		string			priceValue			The price of the storage facility they're trying to reserve
* @param		string			descValue				The ?
* @param		string			featuresValue		The features available to the facility they're trying to reserve
* @param 		array				dialogtext			String array of all the text that will be displayed in the form- this is for language support.
*
* @author 	Ryan
*
*/
function qsReservation( formid, whatValue, priceValue, descValue, featuresValue, dialogtext ) // FXRESERVATION FXRESERVE
{
	modal_original_w = 550;
	modal_original_h = 400;
	var textarray = dialogtext.split('~'); // strings are separated by ~'s
	/*
		textarray[0] = reserve_online_header_1 			= Ready to reserve
		textarray[1] = reserve_online_text_1 				= We take your privacy very seriously at StorageFront. View our
		textarray[2] = reserve_online_text_2 				= privacy policy
		textarray[3] = reserve_online_text_3  			= First Name:
		textarray[4] = reserve_online_text_4 				= Email:
		textarray[5] = reserve_online_text_5 				= Daytime Phone:
		textarray[6] = reserve_online_text_6 				= Cancel
		textarray[7] = reserve_online_text_7 				= Submit
	*/
	if ( textarray.length < 8 ) { errorMessage[errorCount++] = "<MD_Generate_ReserveNotLoggedIn(...)> Not enough strings passed to function.  Need 7."; }

	MD_Create_BaseWindow( textarray[0], modal_original_w, modal_original_h, formid );

	// Make sure values aren't blank - causes problems with email creation
	if ( whatValue == "" || whatValue == null || whatValue == " " )
		whatValue = "N/A";
	if ( priceValue == "" || priceValue == null || priceValue == " " )
		priceValue = "N/A";
	if ( descValue == "" || descValue == null || descValue == " " )
		descValue = "N/A";
	if ( featuresValue == "" || featuresValue == null || featuresValue == " " )
		featuresValue = "N/A";

	// Helper variables to make formatting easier
	var offsetY = 20;
	var spacing = 40;
	var labelOffsetX = 50;

	// Populate the dialog window
	MD_Create_PrivacyStatement( "modal_body", 40,								offsetY, textarray[1], textarray[2] );

	MD_Create_Label						( "modal_body", labelOffsetX, 		offsetY+(1*spacing), 		textarray[3] );
	MD_Create_TextboxInput		( "modal_body", 200, 							offsetY+(1*spacing), 		200, "name_first", true, true );

	MD_Create_Label						( "modal_body", labelOffsetX, 		offsetY+(2*spacing), 		textarray[4] );
	MD_Create_TextboxInput		( "modal_body", 200, 							offsetY+(2*spacing), 		200, "name_last", true, false );

	MD_Create_Label						( "modal_body", labelOffsetX, 		offsetY+(3*spacing),  	textarray[5] );
	MD_Create_TextboxInput		( "modal_body", 200, 							offsetY+(3*spacing), 		200, "email", true, false );

	MD_Create_Label						( "modal_body", labelOffsetX, 		offsetY+(4*spacing), 		textarray[6] );
	MD_Create_TextboxInput		( "modal_body", 200, 							offsetY+(4*spacing), 		200, "phone", true, false );

	MD_Create_CancelButton		( "modal_body", 100, 							offsetY+(5*spacing)+10,	textarray[7], 	"button_submit", "XL", "red" );
	MD_Create_SubmitButton		( "modal_body", 275, 							offsetY+(5*spacing)+10,	textarray[8], 	"button_submit", "XL", "green" );

	//MD_Create_InvisibleInput( parentName, objectType, objectName, objectValue )
	MD_Create_InvisibleInput	( "modal_body", "hidden", "command", 		"reserve_guest" );
	MD_Create_InvisibleInput	( "modal_body", "hidden", "what", 			whatValue );
	MD_Create_InvisibleInput	( "modal_body", "hidden", "miscinfo", 	"general" );
	MD_Create_InvisibleInput	( "modal_body", "hidden", "price", 			priceValue );
	MD_Create_InvisibleInput	( "modal_body", "hidden", "desc", 			descValue );
	MD_Create_InvisibleInput	( "modal_body", "hidden", "features", 	featuresValue );

	MD_Create_BotCheckInput( "modal_body" );

	// Output any errors that arose during window creation
	MD_Display_Errors();

	$('.focus_field').focus();	// Set focus to the field that has the class "focus_field"
} // MD_Generate_ReserveNotLoggedIn


/**
* Generates a Feedback window
*
* @param 		string			formid					Name that the modal's form will have
* @param 		array				dialogtext			String array of all the text that will be displayed in the form- this is for language support.
*
* @author 	Rach
*
* 04/30/2010 Changed out the one-line-textarea inputs to the new MD_Create_TextboxInput function
*/
function MD_Generate_FeedbackForm( formid, dialogtext ) // FXFEEDBACK
{
	modal_original_w = 550;
	modal_original_h = 525;
	var textarray = dialogtext.split('~'); // strings are separated by ~'s
	/*
		textarray[0] = Thank you for the feedback.
		textarray[1] = We take your privacy very seriously at StorageFront.  View our
		textarray[2] = privacy policy
		textarray[3] = Full name (Optional):
		textarray[4] = Email (Optional):
		textarray[5] = Phone (Optional):
		textarray[6] = Comments:
		textarray[7] = Send
	*/
	if ( textarray.length < 8 ) { errorMessage[errorCount++] = "<MD_Generate_FeedbackForm(...)> Not enough strings passed to function.  Need 7."; }

	MD_Create_BaseWindow( textarray[0], modal_original_w, modal_original_h, formid );

	// Helper variables to make formatting easier
	var offsetY = 30;
	var spacing = 40;
	var labelOffsetX = 15;

	// Populate the dialog window
	// function MD_Create_PrivacyStatement( parentName, x, y, text1, text2 )
	MD_Create_PrivacyStatement( "modal_body", 0,								offsetY, textarray[1], textarray[2] );

	// function MD_Create_Label( parentName, x, y, label )
	MD_Create_Label						( "modal_body", labelOffsetX, 		offsetY+(1*spacing), 		textarray[3] );
	MD_Create_TextboxInput		( "modal_body", 200, 		offsetY+(1*spacing), 200, "input_name", false, true );

	MD_Create_Label						( "modal_body", labelOffsetX, 		offsetY+(2*spacing),   textarray[4] );
	MD_Create_TextboxInput		( "modal_body", 200, 							offsetY+(2*spacing), 		200, "input_email", false, false );

	MD_Create_Label						( "modal_body", labelOffsetX, 		offsetY+(3*spacing), 		textarray[5] );
	MD_Create_TextboxInput		( "modal_body", 200, 							offsetY+(3*spacing), 		200, "input_phone", false, false );

	MD_Create_Label						( "modal_body", labelOffsetX+30, 	offsetY+(4*spacing), 		textarray[6] );
	MD_Create_TextareaInput		( "modal_body", 200, 							offsetY+(4*spacing), 		200, 150, 5, "input_comments", true, false );

	//MD_Create_Image( parentName, x, y, imageName )
	MD_Create_Image						( "modal_body", 15, offsetY+(5*spacing)-15, "feedBackSheep.png" );

	MD_Create_SubmitButton		( "modal_body", 380, 							offsetY+(8*spacing)+25,			textarray[7], 	"button_submit", "S", "green" );

	// MD_Create_InvisibleInput( parentName, objectType, objectName, objectValue )
	MD_Create_InvisibleInput( "modal_body", "hidden", "feedback_action", "send_mail" );

	MD_Create_BotCheckInput( "modal_body" );

	// Output any errors that arose during window creation
	MD_Display_Errors();
	MD_Display_DebugLog();

	$('.focus_field').focus();	// Set focus to the field that has the class "focus_field"
} // MD_Generate_FeedbackFormNotLoggedIn

/**
* Generates a Feedback Confirmation window
*
* @param 		string			formid					Name that the modal's form will have
* @param 		array				dialogtext			String array of all the text that will be displayed in the form- this is for language support.
*
* @author 	Rach
*/
function MD_Generate_FeedbackConfirmation( formid, dialogtext ) // FXFEEDBACKCONFIRMATION
{
	modal_original_w = 550;
	modal_original_h = 225;
	var textarray = dialogtext.split('~'); // strings are separated by ~'s
	/*
		textarray[0] = feedback_text_8 	= Thank you for your feedback
		textarray[1] = feedback_text_9		= Close Window
	*/

	// Helper variables to make formatting easier
	var offsetY = 15;
	var spacing = 15;

	if ( textarray.length < 2 ) { errorMessage[errorCount++] = "<MD_Generate_FeedbackConfirmation(...)> Not enough strings passed to function.  Need 2."; }
	MD_Create_BaseWindow( textarray[0], modal_original_w, modal_original_h, formid );

	MD_Create_Label						( "modal_body", 90, offsetY, 	"Thank you for taking the time to fill out our feedback form." );
	MD_Create_Label						( "modal_body", 120, offsetY + (1*spacing), 	"Your evaluation is important to StorageFront." );

	MD_Create_CancelButton( "modal_body", 190, offsetY + (2*spacing)+20,		textarray[1], "button_close_confirm", "S", "green" );

	MD_Display_Errors();
	MD_Display_DebugLog();
} // MD_Generate_ShowFriendConfirmation

/**
* Generates a Show Friend window
*
* @param 		string			formid					Name that the modal's form will have
* @param 		array				dialogtext			String array of all the text that will be displayed in the form- this is for language support.
*
* @author 	Rach
*
* 04/30/2010 Changed out the one-line-textarea inputs to the new MD_Create_TextboxInput function
*/
function MD_Generate_ShowAFriendNotLoggedIn( formid, dialogtext ) // FXSHOWAFRIEND // FXSHARE
{
	modal_original_w = 550;
	modal_original_h = 350;
	var textarray = dialogtext.split('~'); // strings are separated by ~'s
	/*
		textarray[0] = show_page_header_2 	= Show a friend this page.
		textarray[1] = show_page_text_5 		= We take your privacy very seriously at StorageFront. View our
		textarray[2] = show_page_text_6 		= privacy policy
		textarray[3] = show_page_text_7  		= Your Name:
		textarray[4] = show_page_text_8 		= Friend's Email:
		textarray[5] = show_page_text_9 		= Subject:
		textarray[6] = show_page_text_10 		= Close
	*/
	if ( textarray.length < 7 ) { errorMessage[errorCount++] = "<MD_Generate_ShowAFriendNotLoggedIn(...)> Not enough strings passed to function.  Need 7."; }

	MD_Create_BaseWindow( textarray[0], modal_original_w, modal_original_h, formid );

	// Helper variables to make formatting easier
	var offsetY = 30;
	var spacing = 40;
	var labelOffsetX = 45;

	// Populate the dialog window
	MD_Create_PrivacyStatement( "modal_body", 40,								offsetY, textarray[1], textarray[2] );

	MD_Create_Label						( "modal_body", labelOffsetX, 		offsetY+(1*spacing), 		textarray[3] );
	MD_Create_TextboxInput		( "modal_body", 200, 							offsetY+(1*spacing), 		200, "sender_name",	true, true );

	MD_Create_Label						( "modal_body", labelOffsetX, 		offsetY+(2*spacing),  	textarray[4] );
  MD_Create_TextboxInput		( "modal_body", 200, 							offsetY+(2*spacing), 		200, "recipient_email",	true, false );

	MD_Create_Label						( "modal_body", labelOffsetX, 		offsetY+(3*spacing),  	textarray[5] );
	MD_Create_TextboxInput		( "modal_body", 200, 							offsetY+(3*spacing), 		200, "subject",	true, false );

	MD_Create_SubmitButton		( "modal_body", 380, 							offsetY+(4*spacing),		textarray[6], 	"button_submit", "S", "green" );

	//function MD_Create_InvisibleInput( parentName, objectType, objectName, objectValue )
	MD_Create_InvisibleInput( "modal_body", "hidden", "command", "send_page" );
	MD_Create_InvisibleInput( "modal_body", "hidden", "send_url", textarray[7] );

	MD_Create_BotCheckInput( "modal_body" );

	// Output any errors that arose during window creation
	MD_Display_Errors();

	$('.focus_field').focus();	// Set focus to the field that has the class "focus_field"
} // MD_Generate_ShowAFriendNotLoggedIn

/**
* Generates a confirmation window for Show Friend
*
* @param 		string			formid					Name that the modal's form will have
* @param 		array				dialogtext			String array of all the text that will be displayed in the form- this is for language support.
*
* @author 	Rach
*/
function MD_Generate_ShowFriendConfirmation( formid, dialogtext, recipient ) // FXSHOWAFRIENDCONFIRMATION // FXSHARECONFIRMATION
{
	modal_original_w = 550;
	modal_original_h = 200;
	var textarray = dialogtext.split('~'); // strings are separated by ~'s
	/*
		textarray[0] = show_page_header_3 	= Your message is being processed.
		textarray[1] = show_page_text_11 		=	We've sent your email to
		textarray[2] = show_page_text_12		= Close Window
	*/
	if ( textarray.length < 3 ) { errorMessage[errorCount++] = "<MD_Generate_ShowFriendConfirmation(...)> Not enough strings passed to function.  Need 7."; }
	MD_Create_BaseWindow( textarray[0], modal_original_w, modal_original_h, formid );

	var message = textarray[1] + recipient;
	// Center the text based on an offset
	var offset = (message.length)*3;

	MD_Create_Label( "modal_body", (225-offset), 15, 	message ); // 225 = (550/2)
	MD_Create_CancelButton( "modal_body", 165, 50,		textarray[2], "button_close_confirm", "S", "green" );

	MD_Display_Errors();
} // MD_Generate_ShowFriendConfirmation

/**
* Generates a confirmation window for an unpaid reservation
*
* @param 		string			formid					Name that the modal's form will have
* @param 		array				dialogtext			String array of all the text that will be displayed in the form- this is for language support.
*
* @author 	Rach
*/
	function MD_Generate_ShowReserveConfirmation( formid, dialogtext ) // FXSHOWRESERVECONFIRMATION // FXSHOWRESERVATIONCONFIRMATION
{
	modal_original_w = 550;
	modal_original_h = 200;
	var textarray = dialogtext.split('~'); // strings are separated by ~'s
	/*
		textarray[0] = reserve_online_header_3 	= Your reservation is being processed.
		textarray[1] = reserve_online_text_8 		=	You will be contacted shortly by this store to confirm your reservation.
		textarray[2] = reserve_online_text_9		= Reservation is subject to availability.
		textarray[3] = reserve_online_text_10		= Close window
	*/
	if ( textarray.length < 4 ) { errorMessage[errorCount++] = "<MD_Generate_ShowReserveConfirmation(...)> Not enough strings passed to function.  Need 7."; }

	MD_Create_BaseWindow( textarray[0], modal_original_w, modal_original_h, formid );

	MD_Create_Label( "modal_body", (255-(textarray[1].length*3)), 15, 				textarray[1] );
	MD_Create_Label( "modal_body", (255-(textarray[2].length*3)), 30, 				textarray[2] );
	MD_Create_CancelButton( "modal_body", 155, 50,	textarray[3], "button_close_confirm", "S", "green" );

	MD_Display_Errors();
} // MD_Generate_ShowFriendConfirmation

/**
* Generates a confirmation window for an Inquiry
*
* @param 		string			formid					Name that the modal's form will have
* @param 		array				dialogtext			String array of all the text that will be displayed in the form- this is for language support.
*
* @author 	Rach
*/
function MD_Generate_ShowInquiryConfirmation( formid, dialogtext ) // FXSHOWINQUIRYCONFIRMATION
{
	modal_original_w = 550;
	modal_original_h = 200;
	var textarray = dialogtext.split('~'); // strings are separated by ~'s
	/*
		textarray[0] = send_inquiry_header_3 	= Your inquiry is being processed.
		textarray[1] = send_inquiry_text_11 	=	We'll get in touch with you shortly to answer your question.
		textarray[2] = send_inquiry_text_12		= We are looking forward to talking with you!
		textarray[3] = send_inquiry_text_14		= Close window
	*/
	if ( textarray.length < 4 ) { errorMessage[errorCount++] = "<MD_Generate_ShowInquiryConfirmation(...)> Not enough strings passed to function.  Need 7."; }
	MD_Create_BaseWindow( textarray[0], modal_original_w, modal_original_h, formid );

	MD_Create_Label					( "modal_body", (255-(textarray[1].length*3)), 15, 	textarray[1] );
	MD_Create_Label					( "modal_body", (255-(textarray[2].length*3)), 30, 	textarray[2] );
	MD_Create_CancelButton	( "modal_body", 180, 50,	textarray[3], "button_close_confirm", "S", "green" );

	MD_Display_Errors();
} // MD_Generate_ShowFriendConfirmation

/**
* For debugging, shows a list of errors that happened while trying to create
* the modal.
*
* @author 	Rach
*/
function MD_Display_Errors()
{
	if ( errorCount > 0 )
	{
		var statusMessage = "";
		for ( err in errorMessage )
		{
			statusMessage += "\nERROR ["+err+"]: " + errorMessage[err] + "\n";
		}

		alert( "The following errors came up:\n" + statusMessage );
	}
} // MD_Display_Errors

/******************************************************************************************************************/
/******************************************************************************************************************/
/********************* "private" functions - for use by the library's Generate functions only *********************/
/****************************** Do not call from the pages, use the public functions ******************************/
/******************************************************************************************************************/
/******************************************************************************************************************/

/**
* Generates the base window for the modal, including the window itself, the border graphics, the red-circle-X close button, and the blue header.
* It creates a div object named "div_modal_container" to be referenced by other functions.
*
* This calls MD_Create_Header, so it does not need to be called manually
*
* @param 		string			header				Text to appear in the window's header
* @param 		number			w							Width of the modal
* @param 		number			h							Height of the modal
* @param 		string			formid				Name that the modal's form will have
*
* @author 	Rach
*/
function MD_Create_BaseWindow( header, w, h, formid ) // FXCREATEBASEWINDOW // FXCREATEWINDOW
{
  // Make sure that the modal is big enough, or it will look weird.
  if ( w < MIN_MODAL_W || h < MIN_MODAL_H )
  {
    errorMessage[errorCount++] = "<MD_Create_BaseWindow(...)> Modal dimensions are too small!\n" +
			"Min. dimensions are (w=" + MIN_MODAL_W + ", h=" + MIN_MODAL_H + "), current dimensions are (w="+w+", h="+h+")!";
  }

	// Create a supercontainer veil
	var veil												= document.createElement("div");
	veil.className 									= "veil";
	veil.id													= "veil";
	veil.name												= "veil";

	// Create the main storage container
	// This is because the div_modal_container is positioned
	// relatively, and the super_modal_container is positioned absolutely.
	var superContainer							= document.createElement("div");
	superContainer.className				= "super_modal_container";
	superContainer.id								= "super_container";
	superContainer.name							= "super_container";

  // Create new div container
  var newModalContainer 					= document.createElement("div");
  newModalContainer.id 						= "div_modal_container";
  newModalContainer.name 					= "div_modal_container";
  newModalContainer.className 		= "modal_container";
  newModalContainer.style.width 	= w + "px";
  newModalContainer.style.height 	= h + "px";
	newModalContainer.style.top		= "50px";

  // Setup the container border.
	// POst form
  var htmlCode =  "<form method='post' action='' 		onSubmit='return MD_Verify_Input()'		id='"+formid+"'><fieldset>" +
									"<div class='border_top'          id='border_top' name='border_top'				style='left:"+BORDER_W+"px;		width:"+(w-(2*BORDER_W))+"px;  height:"+BORDER_H+"px'></div>" +
                  "<div class='border_bottom'       id='border_bottom' name='border_bottom'	style='left:"+BORDER_W+"px;		width:"+(w-(2*BORDER_W))+"px;  height:"+BORDER_H+"px'></div>" +
                  "<div class='border_left'         id='border_left' name='border_left'			style='top:"+BORDER_H+"px;		width:"+BORDER_W+"px;          height:"+(h-(2*BORDER_H))+"px'></div>" +
                  "<div class='border_right'        id='border_right' name='border_right'		style='top:"+BORDER_H+"px;		width:"+BORDER_W+"px;          height:"+(h-(2*BORDER_H))+"px'></div>" +

                  "<div class='border_topleft'      style='width:"+BORDER_W+"px;  height:"+BORDER_H+"px'></div>" +
                  "<div class='border_topright'     style='width:"+BORDER_W+"px;  height:"+BORDER_H+"px'></div>" +
                  "<div class='border_bottomleft'   style='width:"+BORDER_W+"px;  height:"+BORDER_H+"px'></div>" +
                  "<div class='border_bottomright'  style='width:"+BORDER_W+"px;  height:"+BORDER_H+"px'></div>" +

                  "<div class='modal_background' id='modal_body' name='modal_body' style='left:"+BORDER_W+"px;	top:"+(BORDER_H+MODAL_HEADER_HEIGHT-16)+"px;	width:"+(w-(2*BORDER_W))+"px; height:"+(h-(2*BORDER_H)-MODAL_HEADER_HEIGHT+16)+"px;'></div>" +
									"</fieldset></form>";

  newModalContainer.innerHTML = htmlCode;

  // Create div border inside of the container
	try
	{
		document.body.appendChild( veil );
	}
	catch( error )
	{
		var err = "<MD_Create_BaseWindow(...)> Caught error on appending VEIL to DOCUMENT BODY: " + error + ".\nVEIL returns: " + veil + ", DOCUMENT BODY returns: " + document.body;
		if ( document.body == null )
		{
			err += "\nLooks like 'document.body' is 'null'.  Make sure you're not trying to create a modal in the middle of a POST-induced refresh or something. :P";
		}
		errorMessage[errorCount++] = err;
	}

	try
	{
		superContainer.appendChild( newModalContainer );
	}
	catch( error )
	{
		errorMessage[errorCount++] = "<MD_Create_BaseWindow(...)> Caught error on appending NEWMODALCONTAINER to SUPERCONTAINER: " + error + ".\nNEWMODALCONTAINER returns: " + newModalContainer + ", SUPERCONTAINER returns: " + superContainer;
	}

	try
	{
	  document.body.appendChild( superContainer );
	}
	catch( error )
	{
		errorMessage[errorCount++] = "<MD_Create_BaseWindow(...)> Caught error on appending SUPERCONTAINER to DOCUMENT BODY: " + error + ".\nSUPERCONTAINER returns: " + superContainer + ", DOCUMENT BODY returns: " + document.body;
	}

  // Append the header to the window, pass the text for the header, and the name of this parent
  MD_Create_Header( header, "div_modal_container" );

	$('#div_modal_container').fadeIn( 'slow', function() { ; } );
} // MD_Create_BaseWindow

/******************************************************************************
	function MD_Resize_BaseWindow( containerName, w, h )

	Description--
		Allows base window to be resized
*/
/**
* Allows base window to be resized. Also adjusts it's Y position on the document.
*
* @param 		string			containerName		Name of the container that will be resized
* @param 		number			w								Width to resize the window to
* @param 		number			h								Height to resize the window to
* @param 		number			resizeAmt				The difference between the current height and the new height
*
* @author 	Rach
*/
function MD_Resize_BaseWindow( containerName, w, h, resizeAmt ) // FXRESIZEBASEWINDOW // FXRESIZEWINDOW
{
	var container = document.getElementById( containerName );

	if ( !errorPresent )
	{
		container.style.top			= ( parseInt( container.style.top ) - (resizeAmt/2) ) + "px";
	}
	container.style.width 	= w + "px";
  container.style.height 	= h + "px";

	// Resize the border divs
	var borderDiv = document.getElementById( "border_top" );
		borderDiv.style.width = (w-(2*BORDER_W))+"px";

	borderDiv = document.getElementById( "border_bottom" );
		borderDiv.style.width = (w-(2*BORDER_W))+"px";

	borderDiv = document.getElementById( "border_left" );
		borderDiv.style.height = (h-(2*BORDER_H))+"px";

	borderDiv = document.getElementById( "border_right" );
		borderDiv.style.height = (h-(2*BORDER_H))+"px";

	// Resize the background of the container
	borderDiv = document.getElementById( "modal_body" );
		borderDiv.style.height = (h-(2*BORDER_H)-MODAL_HEADER_HEIGHT+16)+"px";
		borderDiv.style.width = (w-(2*BORDER_W))+"px";
} // MD_Resize_BaseWindow

/******************************************************************************
	BASE WINDOW GET FUNCTIONS FOR WIDTH & HEIGHT...:
*/
/**
* Returns the base window's width
*
* @author 	Rach
*/
function MD_Get_BaseWindowWidth() { return document.getElementById( "div_modal_container" ).style.width; }

/**
* Returns the base window's height
*
* @author 	Rach
*/
function MD_Get_BaseWindowHeight() { return document.getElementById( "div_modal_container" ).style.height; }

/**
* Generates the header and appends it to the parent container.
* This gets called by MD_Create_BaseWindow()
*
* @param 		string			header					Text that the header will have
* @param 		array				parentName			Name of the parent to append to
*
* @author 	Rach
*/
function MD_Create_Header( header, parentName ) // FXCREATEHEADER
{
  // Get the main modal body
  var parentModal = document.getElementById( parentName );
  // Make sure the parent modal exists
  if ( parentModal == null ) { errorMessage[errorCount++] = "<MD_Create_Header()> Parent modal does not exist for header '"+header+"'!  Please create '" + parentName + "'."; return; }

	// Offsets header to fit container better.  Affects Top, Left, Width, and Height.
	var offsetX = -16;
	var offsetY = -16;

  // Add header text on the background border
  var headerDiv = document.createElement("div");
  headerDiv.className = "modal_header";
  headerDiv.style.top 		= (BORDER_H + offsetX) + "px";
  headerDiv.style.left 		= (BORDER_W + offsetY) + "px";
  headerDiv.style.width 	= ((parseInt(parentModal.style.width) - (BORDER_W*2)) - (2*offsetX)) + "px";
  headerDiv.style.height 	= (MODAL_HEADER_HEIGHT) + "px";

  // Add "X" button
	// ** TEMP : Should this reload the page with the dialog gone, or should it destroy it in javascript?
  headerDiv.innerHTML = "<h1 style='margin-top:10px'>"+header+"</h1>"+
                      "<a class='button_x' href='javascript:MD_Close_Dialog()' style='right:"+(-40)+"px;	top:"+(-40)+"px;'></a>";
                      //"<a class='button_x' href='"+link_CloseButton+"' style='right:"+(-40)+"px;	top:"+(-40)+"px;'></a>";

  // Append to the parent case
  parentModal.appendChild( headerDiv );
} // MD_Create_Header

/**
* Creates an input of type textbox
*
* @param	string				parentName			Name of the parent to append to (usually, "modal_body")
* @param	number				x								X (or Left) coordinate for the position
* @param 		number			y 							Y (or Top) coordinate for the position
* @param 		number			w 							Width of the input
* @param 		string			textboxid 			ID/Name of the input
* @param 		boolean			requiredField 	Whether this field is required or not
* @param 		boolean			defaultFocus 		Whether this field gets the default focus
*
* @author 	Rach
* @since		04/30/2010
*/
function MD_Create_TextboxInput( parentName, x, y, w, textboxid, requiredField, defaultFocus ) // FXCREATETEXTBOXINPUT // FXTEXTBOX
{
	var parentModal = document.getElementById( parentName );
	// Make sure the parent modal exists
  if ( parentModal == null ) { errorMessage[errorCount++] = "<MD_Create_TextareaInput(...)> Parent modal does not exist!  Please create '" + parentName + "'."; return; }

	var h = 25;
	var inputDiv = document.createElement( "div" );
	inputDiv.className				= "modal_div";
	inputDiv.style.left 			= x + "px";
	inputDiv.style.top 				= y + "px";
	inputDiv.style.width 			= w + "px";
	inputDiv.style.height 		= h + "px";
	inputDiv.style.textAlign	= "left";
	inputDiv.style.position 	= "absolute";

	// Is required field -flag
	var classSpec;
	if ( requiredField == true )
		classSpec = "required_field";
	else
		classSpec = "not_required_field";

	// Has default focus -flag
	if ( defaultFocus == true )
		classSpec += " focus_field";
	else
		classSpec += " not_focus_field";

	var borderWH = 10;

	// Add divs for the textarea border, and create the textarea
	inputDiv.innerHTML = "<div class='field_textbox'>"+

												/*"<div class='textarea_background' style='left:"+borderWH+"px;top:"+borderWH+"px;width:"+(w-(2*borderWH))+"px;height:"+(h-(2*borderWH))+"px;'></div>"+*/
													"<input type='text' id="+textboxid+" name="+textboxid+" class='"+classSpec+"' style='padding:5px; min-width:"+(w-25)+"px; max-width:"+(w-10)+"px; width:100%' />"+

													"<div class='textarea_top' 		style='width:"+(w-(2*borderWH))+"px;'></div>"+
													"<div class='textarea_bottom' style='width:"+(w-(2*borderWH))+"px;'></div>"+
													"<div class='textarea_left'		style='height:"+(h-(2*borderWH))+"px;'></div>"+
													"<div class='textarea_right'	style='height:"+(h-(2*borderWH))+"px;'></div>"+

													"<div class='textarea_topleft'></div>"+
													"<div class='textarea_topright'></div>"+
													"<div class='textarea_bottomleft'></div>"+
													"<div class='textarea_bottomright'></div>"+

												"</div>";

	parentModal.appendChild( inputDiv );
}

/**
* Creates a textarea and appends it to the window
*
* @param 		string			parentName			Name of the parent to append to (usually, "modal_body")
* @param 		number			x								X (or Left) coordinate for the position
* @param 		number			y 							Y (or Top) coordinate for the position
* @param 		number			w 							Width of the textarea
* @param 		number			h 							Height of the textarea
* @param 		number			rowCount 				Amount of rows (height) for the textarea - make it 1 to be a textbox
* @param 		string			textareaid 			ID/Name of the textarea
* @param 		boolean			requiredField 	Whether this field is required or not
* @param 		boolean			defaultFocus 		Whether this field gets the default focus
*
* @author 	Rach
*/
function MD_Create_TextareaInput( parentName, x, y, w, h, rowCount, textareaid, requiredField, defaultFocus ) //FXCREATETEXTAREAINPUT
{
	var parentModal = document.getElementById( parentName );
	// Make sure the parent modal exists
  if ( parentModal == null ) { errorMessage[errorCount++] = "<MD_Create_TextareaInput(...)> Parent modal does not exist!  Please create '" + parentName + "'."; return; }

	var inputDiv = document.createElement( "div" );
	inputDiv.className				= "modal_div";
	inputDiv.style.left 			= x + "px";
	inputDiv.style.top 				= y + "px";
	inputDiv.style.width 			= w + "px";
	inputDiv.style.height 		= h + "px";
	inputDiv.style.textAlign	= "left";

	var borderWH = 10;

	var inputRows = h/16;
	var inputCols = w/8;

	var classSpec;
	if ( requiredField == true )
		classSpec = "required_field";
	else
		classSpec = "not_required_field";

	if ( defaultFocus == true )
		classSpec += " focus_field";
	else
		classSpec += " not_focus_field";

	// Add divs for the textarea border, and create the textarea
	inputDiv.innerHTML = "<div class='field_textbox'>"+

												/*"<div class='textarea_background' style='left:"+borderWH+"px;top:"+borderWH+"px;width:"+(w-(2*borderWH))+"px;height:"+(h-(2*borderWH))+"px;'></div>"+*/
													"<textarea id='"+textareaid+"' name='"+textareaid+"' class='"+classSpec+"' style='min-width:"+(w-30)+"px; max-width:"+(w-25)+"px; min-height:"+(h-15)+"px; rows:"+rowCount+";  width:100%; height:100%;padding:5px;'></textarea>" +

													"<div class='textarea_top' 		style='width:"+(w-(2*borderWH))+"px;'></div>"+
													"<div class='textarea_bottom' style='width:"+(w-(2*borderWH))+"px;'></div>"+
													"<div class='textarea_left'		style='height:"+(h-(2*borderWH))+"px;'></div>"+
													"<div class='textarea_right'	style='height:"+(h-(2*borderWH))+"px;'></div>"+

													"<div class='textarea_topleft'></div>"+
													"<div class='textarea_topright'></div>"+
													"<div class='textarea_bottomleft'></div>"+
													"<div class='textarea_bottomright'></div>"+

												"</div>";

	parentModal.appendChild( inputDiv );
} // MD_Create_TextareaInput

/**
* Generates some basic text
*
* @param 		string			parentName			Name of the parent to append to (usually, "modal_body")
* @param 		number			x								X (or Left) coordinate for the position
* @param 		number			y 							Y (or Top) coordinate for the position
* @param 		string			label 					Text that the label will contain
*
* @author 	Rach
*/
function MD_Create_Label( parentName, x, y, label ) // FXCREATELABEL
{
	var parentModal = document.getElementById( parentName );
	// Make sure the parent modal exists
  if ( parentModal == null ) { errorMessage[errorCount++] = "<MD_Create_Label(...)> Parent modal does not exist!  Please create '" + parentName + "'."; return; }

	var inputDiv = document.createElement( "div" );
	inputDiv.className 			= "modal_div";
	inputDiv.style.left 		= x + "px";
	inputDiv.style.top 			= y + "px";

	inputDiv.innerHTML = 	"<label>"+label+"</label>";

	parentModal.appendChild( inputDiv );
} // MD_Create_Label

/**
* Creates a submit button, which will post the form on click.
*
* @param 		string			parentName			Name of the parent to append to (usually, "modal_body")
* @param 		number			x								X (or Left) coordinate for the position
* @param 		number			y 							Y (or Top) coordinate for the position
* @param 		string			buttonText			Text that the button will read
* @param 		string			size			 			Size code for the button (ex, "S", "XL")
* @param 		string			color						Color code for the button (ex, "Green", "Blue")
*
* @author 	Rach
*/
function MD_Create_SubmitButton( parentName, x, y, buttonText, buttonid, size, color ) // FXCREATESUBMITBUTTON // FXCREATEBUTTONSUBMIT // FXSUBMIT
{
	var parentModal = document.getElementById( parentName );
	// Make sure the parent modal exists
  if ( parentModal == null ) { errorMessage[errorCount++] = "<MD_Create_SubmitButton(...)> Parent modal does not exist!  Please create '" + parentName + "'."; return; }

	var inputDiv = document.createElement( "div" );
	inputDiv.className 			= "modal_div";
	inputDiv.style.left 			= x + "px";
	inputDiv.style.top 				= y + "px";

	var buttonOptions;

	// Set button size and color
	buttonOptions = MD_Format_Button( size, color );

	inputDiv.innerHTML =	"<button class='"+buttonOptions+"' type='submit' id='"+buttonid+"' name='"+buttonid+"'><em>" +
													"<span></span>" + buttonText +
												"</em></button>";

	parentModal.appendChild( inputDiv );
} // MD_Create_SubmitButton

/**
* Generates a cancel button, which closes the window.
*
* @param 		string			parentName			Name of the parent to append to (usually, "modal_body")
* @param 		number			x								X (or Left) coordinate for the position
* @param 		number			y 							Y (or Top) coordinate for the position
* @param 		string			buttonText			Text that the button will read
* @param 		string			size			 			Size code for the button (ex, "S", "XL")
* @param 		string			color						Color code for the button (ex, "Green", "Blue")
*
* @author 	Rach
*/
function MD_Create_CancelButton( parentName, x, y, buttonText, buttonid, size, color ) // FXCREATECANCELBUTTON // FXCREATEBUTTONCANCEL
{
	var parentModal = document.getElementById( parentName );
	// Make sure the parent modal exists
  if ( parentModal == null ) { errorMessage[errorCount++] = "<MD_Create_CancelButton(...)> Parent modal does not exist!  Please create '" + parentName + "'."; return; }

	var inputDiv = document.createElement( "div" );
	inputDiv.className 			= "modal_div";

	inputDiv.style.left 			= x + "px";
	inputDiv.style.top 				= y + "px";

	var buttonOptions;

	// Set button size and color
	buttonOptions = MD_Format_Button( size, color );

	inputDiv.innerHTML =	"<button class='"+buttonOptions+"' type='button' onClick='MD_Close_Dialog()'><em>" +
													"<span></span>" + buttonText +
												"</em></button>";

	parentModal.appendChild( inputDiv );
} // MD_Create_CancelButton

/**
* Creates and places an image on the parent.
*
* @param 		string			parentName			Name of the parent to append to (usually, "modal_body")
* @param 		number			x								X (or Left) coordinate for the position
* @param 		number			y 							Y (or Top) coordinate for the position
* @param		string			imageName				Name of the image
*
* @author 	Rach
*/
function MD_Create_Image( parentName, x, y, imageName ) // FXCREATEIMAGE
{	// asdfasdf
	var parentModal = document.getElementById( parentName );
	// Make sure the parent modal exists
  if ( parentModal == null ) { errorMessage[errorCount++] = "<MD_Create_Image(...)> Parent modal does not exist!  Please create '" + parentName + "'."; }
	if ( link_ImagePath == null ) { errorMessage[errorCount++] = "<MD_Create_Image(...)> link_ImagePath has not been specified, cannot link to image."; }

	var inputDiv = document.createElement( "div" );
	inputDiv.className 			= "modal_div";
	inputDiv.style.left 		= x + "px";
	inputDiv.style.top 			= y + "px";
// ** TEMP: Test this

	var imagePath = link_ImagePath + "/images/" + imageName;

	//alert( document.location.pathname );  /rmorris/storagefront/public/
	inputDiv.innerHTML = 	"<img src='"+imagePath+"'>";

	parentModal.appendChild( inputDiv );
} // MD_Create_Image

/**
* Creates the Privacy Statement text and link
*
* @param 		string			parentName			Name of the parent to append to (usually, "modal_body")
* @param 		number			x								X (or Left) coordinate for the position
* @param 		number			y 							Y (or Top) coordinate for the position
* @param 		string			text1 					Text for the "Your privacy is very important to us. Read our" label.
* @param 		string			text2 					Text for the "privacy policy" link.
*
* @author 	Rach
*/
function MD_Create_PrivacyStatement( parentName, x, y, text1, text2 ) // FXCREATEPRIVACYSTATEMENT // FXCREATEPRIVACYPOLICY
{
	// Make sure we have a path to the privacy policy
	if ( link_PrivacyPolicy == null || link_PrivacyPolicy == "" )	{	errorMessage[errorCount++] = "<MD_Create_PrivacyStatement(...)> Link to the Privacy Policy page was not provided!"; return; }

	var parentModal = document.getElementById( parentName );
	// Make sure the parent modal exists
  if ( parentModal == null ) { errorMessage[errorCount++] = "<MD_Create_PrivacyStatement(...)> Parent modal does not exist!  Please create '" + parentName + "'."; }

	var offset = (255-((text1.length+text2.length)*2.75));

	var inputDiv = document.createElement( "div" );
	inputDiv.className 			= "modal_div";
	inputDiv.style.left 		= offset + "px";
	inputDiv.style.top 			= y + "px";

	inputDiv.innerHTML = 	"<label>  &nbsp;" + text1 + "<a href='"+link_PrivacyPolicy+"'>"+text2+"</a>.</label>";

	parentModal.appendChild( inputDiv );
} // MD_Create_PrivacyStatement

/**
* Creates an input, generally to be hidden
*
* @param 		string			parentName			Name of the parent to append to (usually, "modal_body")
* @param 		number			objectType			Type of the input object (ex, "hidden")
* @param 		number			objectName			Name/ID of the input object
* @param 		number			objectValue			Value of the input object
*
* @author 	Rach
*/
function MD_Create_InvisibleInput( parentName, objectType, objectName, objectValue ) // FXCREATEINVISIBLEINPUT // FXCREATEHIDDENINPUT
{
	var parentModal = document.getElementById( parentName );
	// Make sure the parent modal exists
  if ( parentModal == null ) { errorMessage[errorCount++] = "<MD_Create_InvisibleInput(...)> Parent modal does not exist!  Please create '" + parentName + "'."; }

	var inputDiv = document.createElement( "div" );
	inputDiv.className = "modal_div";

	inputDiv.innerHTML = "<input type="+objectType+" value="+objectValue+" name="+objectName+" id="+objectName+" style='visibility:hidden;' />";

	parentModal.appendChild( inputDiv );
} // MD_Create_InvisibleInput

/**
* Creates a simple bot-check field.  If this input gets filled in, then it is probably a bot.
*
* @param 		string			parentName			Name of the parent to append to (usually, "modal_body")
*
* @author 	Rach
*/
function MD_Create_BotCheckInput( parentName ) // FXCREATEBOTCHECK
{
	var parentModal = document.getElementById( parentName );
	// Make sure the parent modal exists
  if ( parentModal == null ) { errorMessage[errorCount++] = "<MD_Create_InvisibleInput(...)> Parent modal does not exist!  Please create '" + parentName + "'."; }

	var inputDiv = document.createElement( "div" );
	inputDiv.className = "modal_div";
	inputDiv.innerHTML = "<input type='hidden' value='' name="+botCheckField+" id="+botCheckField+" style='visibility:hidden;' />";

	parentModal.appendChild( inputDiv );
}

/**
* Creates an Error Dialog div
*
* @param 		string			parentName			Name of the parent to append to (usually, "modal_body")
* @param 		array				missingFields		Text notification for each missing field (sentence is generated by MD_Verify_Input())
*
* @author 	Rach
*/
function MD_Create_ErrorDialog( parentName, missingFields ) // FXCREATEERRORDIALOG // FXERROR
{
	MD_Set_Debug( false );
	MD_Set_DebugIndividually( false );
	MD_Append_DebugLog( "Begin MD_Create_ErrorDialog().." );

	var parentModal = document.getElementById( parentName );
	// Make sure the parent modal exists
  if ( parentModal == null ) { errorMessage[errorCount++] = "<MD_Create_ErrorDialog(...)> Parent modal does not exist!  Please create '" + parentName + "'."; }

	var resizeLength = 65;

	var previousErrorsExist = false;
	var errorDiv = document.getElementById( "error_dialog" );
	if ( errorDiv == null )
	{
		errorDiv = document.createElement( "div" );
		errorDiv.name = "error_dialog";
		errorDiv.id = errorDiv.name;
		error_lastResize = 0;
	}
	else
	{
		previousErrorsExist = true;
	}

	//var inner = "<h3><img src='../images/error.png' /><span>Unable to send</span></h3><ul>";// +
	var inner = "<h3><span>Unable to send</span></h3><ul>";// +

	for ( var i = 0; i < missingFields.length; i++ )
	{
		inner += "<li>" + missingFields[i] + "</li>";
		resizeLength += 12;
	}

	inner += "</ul>";

	errorDiv.innerHTML = inner;

	// Resize window
	MD_Resize_BaseWindow( "div_modal_container", modal_original_w, modal_original_h+resizeLength, resizeLength );
	errorPresent = true; // Keeps the window from moving as it gets resized in the future.

	// Push down existing fields
	//Object doesn't support this property or method
	var fields = $('.modal_div');//parentModal.getElementsByClassName( "modal_div" );
	for ( var index=0; index < fields.length; index++ )
	{
		//fields[index].style.top = (parseInt(fields[index].style.top) + resizeLength) + "px";
		var windowShift = parseInt(fields[index].style.top,10) + (resizeLength - error_lastResize);
		windowShift += "px";
		try
		{
			fields[index].style.top = windowShift; //parseInt(fields[index].style.top, 10);// + (resizeLength - error_lastResize)) + "px";
		}
		catch( error )
		{
			MD_Append_DebugLog( "Error trying to shift element: " + fields[index].name + ": " + error );
		}
	} //for ( var index in requiredFields )

	error_lastResize = resizeLength;

	parentModal.appendChild( errorDiv );

	MD_Display_DebugLog();
} // MD_Create_ErrorDialog

/**
* Verifies that all required textarea inputs with the flag "required_field"
* are filled in, make sure email and phone #'s are valid.  Creates an
* error message with MD_Create_ErrorDialog(...) if it's in bad order.
*
* @author 	Rach
*/
function MD_Verify_Input() // FXVERIFYINPUT // FXVALIDATE // FXVALIDATION
{
	MD_Set_Debug( false );
	MD_Set_DebugIndividually( false );
	MD_Append_DebugLog( "Begin MD_Verify_Input()" );

	var parentModal = document.getElementById( "modal_body" );
	// Make sure the parent modal exists
  if ( parentModal == null ) { errorMessage[errorCount++] = "<MD_Verify_Input(...)> Parent modal does not exist!  Please create '" + parentName + "'."; }

	// Check to see if the bot-check input has been entered.  If it has, do not submit the form.
	var botcheck = document.getElementById( botCheckField );
	if ( botcheck.value != "" )
	{
		errorMessage[errorCount++] = "<MD_Verify_Input(...)> Bot-check fail";
		MD_Close_Dialog();
		return false;
	}

	var requiredFields;

	try
	{
		requiredFields = $( ".required_field" );
		MD_Append_DebugLog( "'required_field' found." );
	}
	catch( error )
	{
		MD_Append_DebugLog( "Cannot find elements via class 'required_field':\n" + error );
		try
		{
			requiredFields = $( ".not_required_field" );
		}
		catch( error )
		{
			MD_Append_DebugLog( "Cannot find elements via class 'not_required_field':\n" + error );
		}
	}

	var missingData = false;
	var missingFields = new Array();
	missingFields.length = 0;

	for ( var index=0; index<requiredFields.length; index++ )
	{
		MD_Append_DebugLog( " For " + index );
		if ( !requiredFields[index].value )
		{

			MD_Append_DebugLog( " Missing field " );
			missingData = true;
			// Get rid of understores and capitalize name of the field.
			var prettyText = MD_Prettify_Text( requiredFields[index].id );

			errorMessage[errorCount++] = "<MD_Verify_Input()>: Required field \"" + prettyText + "\" is missing value";
			missingFields[ missingFields.length++ ] = "Please check the \"" + prettyText + "\" field. It must be filled out.\n";
			MD_Append_DebugLog( "- " + missingFields[ missingFields.length-1 ] );
		}

		// Check to make sure it's a valid email
		else if ( requiredFields[index].id.indexOf( 'email' ) != -1 && (requiredFields[index].value.indexOf( '@' ) == -1 || requiredFields[index].value.indexOf( '.' ) == -1) )
		{
			MD_Append_DebugLog( " email wrong " );
			missingData = true;

			var prettyText = MD_Prettify_Text( requiredFields[index].id );

			missingFields[ missingFields.length++ ] = "Please check \"" + prettyText + "\": Not a valid email address.\n";
			MD_Append_DebugLog( "- " + missingFields[ missingFields.length-1 ] );
		}
		else if ( requiredFields[index].id.indexOf( 'phone' ) != -1 )
		{
			// Check to make sure it's a valid phone number
			requiredFields[index].value = requiredFields[index].value.replace( /[-)( ]/g, "" );
			//requiredFields[index].value = requiredFields[index].value.replace( ")", " " );
			//requiredFields[index].value = requiredFields[index].value.replace( "-", " " );
			//requiredFields[index].value = requiredFields[index].value.replace( " ", "" );

			// Check if there are enough characters
			if ( requiredFields[index].value.length < 10 )
			{
				MD_Append_DebugLog( " Phone not long enough " );
				missingData = true;
				var prettyText = MD_Prettify_Text( requiredFields[index].id );

				missingFields[ missingFields.length++ ] = "Please check \"" + prettyText + "\": Phone number is too short.\n";
				MD_Append_DebugLog( "- " + missingFields[ missingFields.length-1 ] );
			}
			// Check if it is all numbers and no letters
			if ( isNaN( requiredFields[index].value ) )
			{
				MD_Append_DebugLog( " Phone contains alpha characters " );
				missingData = true;
				var prettyText = MD_Prettify_Text( requiredFields[index].id );

				missingFields[ missingFields.length++ ] = "Please check \"" + prettyText + "\": Not a valid phone number, please make sure it is only numbers.\n";
				MD_Append_DebugLog( "- " + missingFields[ missingFields.length-1 ] );
			}
		}
	} //for ( var index in requiredFields )

	if ( missingData == true )
		MD_Append_DebugLog( "Missing data TRUE" );
	else
		MD_Append_DebugLog( "Missing data FALSE" );

	MD_Display_DebugLog();

	if ( missingData == false )
	{
		// Post data
		return true;
	} // if ( missingData == false )
	else
	{
		// Generate error message
		MD_Create_ErrorDialog( "modal_body", missingFields );
		return false;
	} // ELSE !(if ( missingData == false ))
} // MD_Verify_Input

/**
* (DEBUG) : Appends the text given as an argument to the debugLog string array.
*
* @param 		string			text			Text to store in the debugLog.
*
* @author 	Rach
*/
function MD_Append_DebugLog( text ) // FXAPPENDDEBUG // FXDEBUGAPPEND
{
	if ( debug )
	{
		if ( debugDisplayIndividually )
		{
			debugLog[ 0 ] = text;
			MD_Display_DebugLog();
		}
		else
		{
			debugLog[ debugLog.length ] = text;
		}
	}
}

/**
* Displays entire Debug Log in one alert(), resets the Debug Log length back to 0.
*
* @author 	Rach
*/
function MD_Display_DebugLog() // FXDISPLAYDEBUGLOG // FXDEBUGDISPLAYLOG
{
	if ( debug )
	{
		var msg = "DEBUG LOG:\n";
		if( debugLog.length == 0 )
			msg += "empty";
		for ( var i = 0; i < debugLog.length; i++ )
		{
			msg += "\n\t" + debugLog[i];
		}

		alert( msg );

		debugLog.length = 0;
	}
}

/**
* Turns on/off the debug window display
*
* @param 		boolean			isOn			Whether the debug dialogs will display or not.
*
* @author 	Rach
*/
function MD_Set_Debug( isOn ) // FXSETDEBUG // FXDEBUGSET
{
	debug = isOn;
}

/**
* Sets whether the debug dialogs will be shown as soon as it's set (making it
* like a JS alert()), or if it appends to the string array to be outputted
* all at once.
*
* @param 		boolean			isOn			Whether everything appended to the debug log will be displayed individually or not.
*
* @author 	Rach
*/
function MD_Set_DebugIndividually( isOn ) // FXSETDEBUGINDIVIDUALLY // FXDEBUGSETINDIVIDUALLY
{
	debugDisplayIndividually = isOn;
}

/**
* Takes input from the button creation functions and formats them into the css classes.
*
* @param 		string			size 			Size code (ex, "XS", "extrasmall", "xl")
* @param 		string			color			Color code (ex, "green", "red")
*
* @author 	Rach
*/
function MD_Format_Button( size, color ) // FXFORMATBUTTON // FXBUTTON
{
	var buttonOptions;

	if ( size == "extrasmall" || size == "xs" || size == "XS" )
	{
		buttonOptions = "button_XS";
		size = "XS";
	}
	else if ( size == "small" || size == "s" || size == "S" )
	{
		buttonOptions = "button_S";
		size = "S";
	}
	else if ( size == "medium" || size == "m" || size == "M" )
	{
		buttonOptions = "button_M";
		size = "M";
	}
	else if ( size == "large" || size == "l" || size == "L" )
	{
		buttonOptions = "button_L";
		size = "L";
	}
	else if ( size == "extralarge" || size == "xl" || size == "XL" )
	{
		buttonOptions = "button_XL";
		size = "XL";
	}
	else
	{
		errorMessage[errorCount++] = "<MD_Format_Button(...)> Invalid or no size specified, defaulted to M.\nOptions are: XS, S, M, L, XL";
		buttonOptions = "button_M";
		size = "M";
	}

	// Set button color
	if ( color == "green" )
	{
		buttonOptions += " green_" + size;
	}
	else if ( color == "red" )
	{
		if ( size == "XS" || size == "XL" )
			buttonOptions += " red_" + size;
		else
			errorMessage[errorCount++] = "<MD_Format_Button(...)> Invalid color specified.\n Red can only be used with extra small and extra large-sized buttons.";
	}
	else if ( color == "orange" )
	{
		if ( size == "M" || size == "L" || size == "XL" )
			buttonOptions += " orange_" + size;
		else
			errorMessage[errorCount++] = "<MD_Format_Button(...)> Invalid color specified.\n Orange can only be used with medium, large, and extra large-sized buttons.";
	}
	else if ( color == "blue" )
	{
		buttonOptions += " blue_" + size;
	}
	else if ( (color == "lightGreen" || color == "lightgreen") )
	{
		if ( size == "L" || size == "M" )
			buttonOptions += " lightGreen_" + size;
		else
			errorMessage[errorCount++] = "<MD_Format_Button(...)> Invalid color specified.\n Light green can only be used with medium and large-sized buttons.";
	}
	else if ( color == "gray" )
	{
		if ( size == "M" )
			buttonOptions += " gray_" + size;
		else
			errorMessage[errorCount++] = "<MD_Format_Button(...)> Invalid color specified.\n Gray can only be used with medium-sized buttons.";
	}
	else if ( color == "teal" )
	{
		if ( size == "M" )
			buttonOptions += " teal_" + size;
		else
			errorMessage[errorCount++] = "<MD_Format_Button(...)> Invalid color specified.\n Teal can only be used with medium-sized buttons.";
	}
	else if ( color == "" || color == null )
	{
		; // Default is blue
	}
	else
	{
		errorMessage[errorCount++] = "<MD_Format_Button(...)> Invalid color specified.\nPlease make sure color provided is available for the corresponding size.";
	}

	return buttonOptions;
} // MD_Format_Button

/******************************************************************************
	function MD_PrettifyText( text )

	Description--
		Gets rid of underscores and capitalizes first letter of each word
*/

/**
* Converts text to become prettier for the error dialog.  Removes any
* underscores, or "input" suffixes/prefixes in the name.  Sets first
* letters to uppercase.
*
* @param 		string			uglyText			Text that needs to be formatted
*
* @return		string			Returns the text that has been formatted
*
* @author 	Rach
*/
function MD_Prettify_Text( uglyText ) // FXPRETTIFYTEXT // FXPRETTYTEXT
{
	var	uglyText;
	uglyText = uglyText.replace( "_", " " );
	uglyText = uglyText.replace( " input", "" );
	uglyText = uglyText.replace( "input ", "" );
	uglyText = uglyText.replace( "pra ", "" );

	var textArray = uglyText.split( ' ' );
	var prettyText = "";

	prettyText += textArray[0].substring(0,1).toUpperCase() + textArray[0].substring(1,textArray[0].length)
	for ( var i=1; i<textArray.length; i++ )
	{
		prettyText += " " + textArray[i].substring(0,1).toUpperCase() + textArray[i].substring(1,textArray[i].length);
	}

	return prettyText;
}

