//**********************************************************************************************
// Module: enet
//
// The enet module is the base object of a hierarchy of JavaScript objects that contain
// functions utilized as event callbacks for HTML elements within the HTML documents generated
// by the extranet application.  These objects also contain utility functions, as well as
// variables that should be considered constansts.
//
// This hierarchy of code modules (JavaScript Objects) has been constructed so that only the
// enet variable has been placed in the global namespace.  This avoids namespace clashes
// within the enet code itself and with code from other JavaScript packages we use or might
// incorporate.
//
// In order to hook into this module hierarchy to for event processing, a 'jsl' attribute
// should be defined for an element with a value of the module or method that will initialize
// events for an HTML element or block of elements.  See enet.initialize() for more information
// on how this linking occurs.
//
// ----------
// CHANGE LOG
// ----------
// Date        By   Version  Description
// ----------  ---  -------  -------------------------------------------------------------------
// 01/29/2010  TAB  4.5.0    ISSUE 947: Modifications due to upgrade of jquery.
// 07/07/2008  TAB  1.00     Added the ENET_PATH definition.
// 06/09/2008  TAB  1.00     Added the event function.
// 06/05/2008  TAB  1.00     Initial coding.
//
//**********************************************************************************************

/**
 * Define the base module (Object) in the enet hierarcy.  This will be the only var in the
 * global namespace.
 */
var enet = { };

//**********************************************************************************************
// MODULE:  enet
// --------------------------------------------------------------------------------------------
// This module is responsible for setting up the environment of a ISP extranet web page.  
//**********************************************************************************************
(function( ) {

	/**
	 * VARIABLE: enet_path
	 * ======================================================================================================
	 * Contains the definition of the main enet path.
	 */
	enet_path = "/enet/index.php";

	/**
	 * FUNCTION: alertMessage( element, message )
	 * ======================================================================================================
	 * This function provides a means of linking an alert from HTML documents.
	 */
	function alertMessage( element, message ) {
		alert(message);
	}

	/**
	 * FUNCTION contentBox( params )
	 * ======================================================================================================
	 * An interface function to the colorbox package to prevent the need to hunt down colorbox code if the
	 * package is changed.  This method also acts as a container for the functions of the contentBox closure.
	 *
	 * @param object params
	 */
	function contentBox( params ) {

		$.fn.colorbox(params);

	}

	//******************************************************************************************
	// FUNCTION:  event( e )
	// ----------------------------------------------------------------------------------------
	// This function is to provide compatibility with IE and other browsers.  In IE, you must
	// get the event object from the window.  In other browsers, the event object is passed
	// to the callback function for the event.  Every callback that makes use of the event
	// object, should define do so as:
	//
	//     func_name( event ) {
	//         event = enet.event(event);
	//         ...
	//     }
	//
	//******************************************************************************************
	function event( e ) { return (e || window.event); }

	function getAbsoluteLeft( element ) {
		var eLeft = element.offsetLeft;			// Get left position from the parent object
		while(element.offsetParent !== null) {	// Parse the parent hierarchy up to the document element
			var eParent = element.offsetParent;	// Get parent object reference
			eLeft += eParent.offsetLeft;		// Add parent left position
        	element = eParent;
		}
		return eLeft;
	}

	function getAbsoluteTop( element ) {
		var eTop = element.offsetTop;			// Get top position from the parent object
		while(element.offsetParent !== null) {	// Parse the parent hierarchy up to the document element
			var eParent = element.offsetParent;	// Get parent object reference
			eTop += eParent.offsetTop;			// Add parent top position
        	element = eParent;
		}
		return eTop;
	}

	//******************************************************************************************
	// FUNCTION:  initialize( element )
	// ----------------------------------------------------------------------------------------
	// Initialize an element along with all descendant elements.  This is done by checking
	// each element for a 'jsl' attribute, whose value is the name of a module containing an
	// initialization function.  It is possible  to leave off the beginning 'extranet.' In
	// the value of the jsl attribute.  It is added automatically.  Also, the value of the
	// jsl attribute should not contain an ending '.initialize', as this is added within
	// this function.
	//
	// If the value of element is not specified, then document.body is used.
	//******************************************************************************************
	function initialize( element ) {

		// ISSUE 947:  Modified the following statement due to upgrade of jquery.js to version 1.4.1
		//
		//$(document, $((undefined === element ? document.body : element))).find("*[jsl]").each(
		//
		$("*[jsl]", ('function' === typeof element ? document.body : element)).each(
			/**
			 * If the element has a "jsl" attribute, then call an initialization method
			 * specified in the attribute value.
			 *
			 * Examples of acceptable jsl attribute values are:
			 *
			 * Value						Description
			 * ---------------------------  ------------------------------------------------
			 * module.action                Call enet.module.action.initialize(element)
			 * module(1, 'string')	        Call enet.module.initialize(element, 1, 'string')
			 * module.action::method		Call enet.module.action.method(element)
			 * module::method(1)			Call enet.module.method(element, 1)
			 */
			function ( i ) {
				var jsl = this.getAttribute("jsl");

				/**
			 	* Prepend the 'enet.' module onto the jsl string if it is not included.  This
			 	* allows us to use the eval() call later to invoke the routine.
			 	*/
				if (jsl.slice(0, 4) != "enet") {

					// If the first two characters are '::', then only prepend 'enet', as we are attempting
					// to call a routine from this closure.  Otherwise, prepend 'enet.'.
					//
					jsl = "enet" + (jsl.slice(0, 2) == "::" ? "" : ".") + jsl;
					//jsl = "enet." + jsl;
				}

				/**
			 	* Split out any parameters that may have been passed, and then split out a
			 	* method call from the module path.
			 	*/
				var params = jsl.split("(", 2);			
				var method = params[0].split("::");

				/**
			 	* Build the method call.  If a method was not explicitly specified, then
			 	* the initialize method is called.
			 	*/
				method = method[0] + (( method.length > 1 ) ? '.' + method[1] : '.initialize');

				/**
			 	* Build the parameter list.  If the params list was specified, then prepend the
			 	* element param to the list.  Otherwise, element is the only parameter.
			 	*/
				params = (( params.length > 1 ) ? "(this, " + params[1] : "(this)");

				/**
				 * Invoke the method with the parameters.
				 */
				eval( method + params );
			}
		);
	}

	function uri( url, QVARS ) {
		var QSTRING = [ ];
		if (	undefined === url
				|| null === url) {

			url = "/enet/index.php";

		}
		for (k in QVARS) {
			QSTRING.push(encodeURIComponent(k) + "=" + encodeURIComponent(QVARS[k]));
		}
		QSTRING = QSTRING.join("&");
		return url + (QSTRING ? "?" + QSTRING : "");
	}


	//**************************************************************************************
	// LINKAGE
	// ------------------------------------------------------------------------------------
	// This linkage section is different than any other, since enet has to be defined
	// outside of the closure formed by the unnamed function.
	//**************************************************************************************
	enet.ENET_PATH = enet_path;
	enet.alertMessage = alertMessage;
	enet.contentBox = contentBox;
	enet.event = event;
	enet.getAbsoluteLeft = getAbsoluteLeft;
	enet.getAbsoluteTop = getAbsoluteTop;
	enet.initialize = initialize;
	enet.uri = uri;

})();

/**
 * Now, we set up our initialization to occur on the load of the html document, using jquery.
 */
$(document).ready(enet.initialize);
/**
 * [jsl/contact/]_contact.js
 * ==========================================================================================================
 *
 *
 * <code>
 * ----------
 * CHANGE LOG
 * ----------
 * Date      By     Ver     Description
 * --------- ------ ------- -----------
 * 01/18/10  TAB    1.0.0   ISSUE 943: initial development
 * </code>
 *
 * @package jsl_contact
 * @subpackage contact
 * @author Todd Brandys
 * @since 1.0.0
 * @version 1.0.0
 */

(function ( ) {

	// PUBLIC METHODS AND MEMBERS
	// ======================================================================================================
	enet.contact = {
		'message'	: function ( ) { }
	}

})();
/**
 * [jsl/contact/]message.js
 * ==========================================================================================================
 *
 *
 * <code>
 * ----------
 * CHANGE LOG
 * ----------
 * Date      By     Ver     Description
 * --------- ------ ------- -----------
 * 01/18/10  TAB    1.0.0   ISSUE 943: initial development
 * </code>
 *
 * @package jsl_contact
 * @subpackage message
 * @author Todd Brandys
 * @since 1.0.0
 * @version 1.0.0
 */

(function ( ) {

	var VALUES = {
		"firstname"	:	"FIRST NAME",
		"lastname"	:	"LAST NAME",
		"email"		:	"EMAIL ADDRESS",
		"address1"	:	"ADDRESS",
		"address2"	:	"APT., SUITE#, ETC.",
		"city"		:	"CITY",
		"zip"		:	"ZIP",
		"note"		:	"COMMENTS"
	};

	function initialize( element ) {

		$("input[name='firstname']", element).focus(onFocus).blur(onBlur);
		$("input[name='lastname']", element).focus(onFocus).blur(onBlur);
		$("input[name='email']", element).focus(onFocus).blur(onBlur);
		$("input[name='address1']", element).focus(onFocus).blur(onBlur);
		$("input[name='address2']", element).focus(onFocus).blur(onBlur);
		$("input[name='city']", element).focus(onFocus).blur(onBlur);
		$("input[name='zip']", element).focus(onFocus).blur(onBlur);
		$("textarea[name='note']", element).focus(onFocus).blur(onBlur);
		$(element).submit(onSubmit);

	}

	function onBlur( e ) {

		if (false === /\S/m.test($(this).val())) {

			$(this).val(VALUES[$(this).attr("name")]);

		}

	}

	function onFocus( e ) {

		if (VALUES[$(this).attr("name")] === $(this).val()) {

			$(this).val("");

		}

	}

	function onSubmit( e ) {

		var message = "";
		if ("FIRST NAME" === $("input[name='firstname']").val()) {

			message += "    * You must supply a first name.\n";

		}
		if ("LAST NAME" === $("input[name='lastname']").val()) {

			message += "    * You must supply a last name.\n";

		}
		if ("EMAIL ADDRESS" === $("input[name='email']").val()) {

			message += "    * You must supply a valid email address.\n";

		}
		if (message) {

			alert("The following errors have occurred:\n\n" + message);
			return false;

		}
		return true;

	}

	// PUBLIC METHODS AND MEMBERS
	// ======================================================================================================
	var linkage = enet.contact.message;
	linkage.initialize = initialize;

})();
/**
 * [theme/jsl/home/]_home.js
 * ==========================================================================================================
 *
 *
 */

(function( linkage ) {

	// LINKAGE
	// ======================================================================================================
	linkage.home = {
	};

})(enet);

/**
 * [theme/jsl/home/]_home.js
 * ==========================================================================================================
 *
 *
 */

(function( linkage ) {

	var INTERVAL_PERIOD	= 3000;
	var FADEOUT_PERIOD = 750;
	var IMAGES;
	var currentImage;

	function fadeImage( ) {

		var nextImage = (currentImage + 1) % IMAGES.length;
		IMAGES.eq(currentImage).css({ "z-index":10000 });
		IMAGES.eq(nextImage).css({ "z-index":9999, "display":"block" });
		IMAGES.eq(currentImage).fadeOut(FADEOUT_PERIOD);
		currentImage = nextImage;

	}

	function initialize( element ) {

		IMAGES = $("#homeImage div");
		currentImage = 0;
		window.setInterval(fadeImage, INTERVAL_PERIOD);

	}

	// LINKAGE
	// ======================================================================================================
	linkage.imageRotation = {
		"initialize"	:	initialize
	};

})(enet.home);


(function ( linkage ) {

	// LINKAGE
	// ======================================================================================================
	linkage.navigation = {
	};

})(enet);
/**
 * [jsl/navigation/]menu.js
 * ==========================================================================================================
 *
 * <code>
 * ----------
 * CHANGE LOG
 * ----------
 * Date      By     Ver     Description
 * --------- ------ ------- -----------
 * 06/30/10  TAB    1.0.0   ISSUE XXX: Initial development
 * </code>
 *
 * @package jsl_navigation
 * @subpackage menu
 * @author Todd Brandys
 * @since 1.0.0
 * @version 1.0.0
 */

(function ( linkage ) {

	var menuName = undefined;
	var timeoutId = undefined;

	function initialize( element ) {

		var position = $(element).offset();
		$("ul:eq(0)", element).detach().appendTo("body");
		$("ul[name='" + $(element).attr("name") + "']")
			.css({
				"position"	:	"absolute",
				"left"		:	position.left,
				"top"		:	position.top + $(element).outerHeight()
			});
		$("ul[name='" + $(element).attr("name") + "'] > li > a")
			.mouseout(onMouseOut)
			.mouseover(onMouseOver);
		$(element)
			.mouseover(onMouseOver)
			.mouseout(onMouseOut);

	}

	function onMouseOver( e ) {

		var menu = (
			"A" === this.tagName
				?	$(this).parents("ul[name]").attr("name")
				:	$("ul[name='" + $(this).attr("name") + "']").attr("name"));
		if (	menu === menuName
				&& undefined !== timeoutId) {

			clearTimeout(timeoutId);
			timeoutId = undefined;

		} else {

			menuName = menu;
			$("ul[name='" + $(this).attr("name") + "']").show();

		}

	}

	function onMouseOut( e ) {

		var menu = (
			"A" === this.tagName
				?	$(this).parents("ul[name]")
				:	$("ul[name='" + $(this).attr("name") + "']"));
		timeoutId = setTimeout(
			function ( ) {

				menu.hide();
				timeoutId = undefined;
				menuName = undefined;

			},
			100
		);

	}

	// LINKAGE
	// ======================================================================================================
	linkage.menu = {
		"initialize"	: initialize
	};

})( enet.navigation );

/**
 * [jsl/partner/]_partner.js
 * ==========================================================================================================
 *
 *
 * <code>
 * ----------
 * CHANGE LOG
 * ----------
 * Date      By     Ver     Description
 * --------- ------ ------- -----------
 * 01/18/10  TAB    1.0.0   ISSUE 943: initial development
 * </code>
 *
 * @package jsl_partner
 * @subpackage partner
 * @author Todd Brandys
 * @since 1.0.0
 * @version 1.0.0
 */

(function ( ) {

	// PUBLIC METHODS AND MEMBERS
	// ======================================================================================================
	enet.partner = {
		'apply'		: function ( ) { }
	}

})();
/**
 * [jsl/contact/]apply.js
 * ==========================================================================================================
 *
 *
 * <code>
 * ----------
 * CHANGE LOG
 * ----------
 * Date      By     Ver     Description
 * --------- ------ ------- -----------
 * 01/18/10  TAB    1.0.0   ISSUE 943: initial development
 * </code>
 *
 * @package jsl_contact
 * @subpackage apply
 * @author Todd Brandys
 * @since 1.0.0
 * @version 1.0.0
 */

(function ( ) {

	var VALUES = {
		"firstname"	:	"FIRST NAME",
		"lastname"	:	"LAST NAME",
		"company"	:	"COMPANY NAME",
		"address"	:	"ADDRESS",
		"city"		:	"CITY",
		"zip"		:	"ZIP",
		"phone"		:	"PHONE",
		"email"		:	"EMAIL ADDRESS",
		"note"		:	"COMMENTS"
	};

	function initialize( element ) {

		$("input[name='firstname']", element).focus(onFocus).blur(onBlur);
		$("input[name='lastname']", element).focus(onFocus).blur(onBlur);
		$("input[name='company']", element).focus(onFocus).blur(onBlur);
		$("input[name='address']", element).focus(onFocus).blur(onBlur);
		$("input[name='city']", element).focus(onFocus).blur(onBlur);
		$("input[name='zip']", element).focus(onFocus).blur(onBlur);
		$("input[name='phone']", element).focus(onFocus).blur(onBlur);
		$("input[name='email']", element).focus(onFocus).blur(onBlur);
		$("textarea[name='note']", element).focus(onFocus).blur(onBlur);
		$(element).submit(onSubmit);

	}

	function onBlur( e ) {

		if (false === /\S/m.test($(this).val())) {

			$(this).val(VALUES[$(this).attr("name")]);

		}

	}

	function onFocus( e ) {

		if (VALUES[$(this).attr("name")] === $(this).val()) {

			$(this).val("");

		}

	}

	function onSubmit( e ) {

		var message = "";
		if ("FIRST NAME" === $("input[name='firstname']").val()) {

			message += "    * You must supply a first name.\n";

		}
		if ("LAST NAME" === $("input[name='lastname']").val()) {

			message += "    * You must supply a last name.\n";

		}
		if ("COMPANY NAME" === $("input[name='company']").val()) {

			message += "    * You must supply a company name.\n";

		}
		if ("ADDRESS" === $("input[name='address']").val()) {

			message += "    * You must supply a street address.\n";

		}
		if ("CITY" === $("input[name='city']").val()) {

			message += "    * You must supply a city for your address.\n";

		}
		if ("STATE" === $("select[name='state']").val()) {

			message += "    * You must supply a state for your address.\n";

		}
		if (!/^(\d{5})|([A-Z]\d[A-Z] ?\d[A-Z]\d)$/.test($("input[name='zip']").val())) {

			message += "    * You must supply a zip code for your address.\n";

		}
		if (!/^\d{3}-\d{3}-\d{4}$/.test($("input[name='phone']").val())) {

			message += "    * You must supply a valid phone number (XXX-XXX-XXXX).\n";

		}
		if (message) {

			alert("The following errors have occurred:\n\n" + message);
			return false;

		}
		return true;

	}

	// PUBLIC METHODS AND MEMBERS
	// ======================================================================================================
	var linkage = enet.partner.apply;
	linkage.initialize = initialize;

})();

