/*
Name: ICM_Extensions.js
Sysnopsis: This file contains some extensions to be prototyped on to the Insite_Cookie_Manager class defined in insite_cookie_manger.js
Author: Jason Starnes, Senior Interactive Developer, Rock Hill Herald
*/

Insite_Cookie_Manager.prototype.getInsiteCookieValue = getInsiteCookieValue;

// Purpose: This function will return the value of any field from the 'insite_account_info' cookie
function getInsiteCookieValue(field) {
	if( document.cookie.length > 0 ) {
			var cookieValue = document.cookie.match( '(^|;)*' + this.insiteAccountInfoCookie + '=([^;]*)(;|$)' );
		        if( cookieValue && !document.cookie.match( '(^|;)*' + this.insiteDefaultCookie + '=\.threshold([^;]*)(;|$)' ) ){
				// Get the index of the first and last character in the cookie argument we need
				var start = cookieValue[2].indexOf( field+"%3D" );
				var end   = cookieValue[2].indexOf( "%7C", start );
				// Extract that one piece of the cookie based on the start, end values.  The calculate a new 'start' for the '=' to get the 
				//   actual value of the piece we are interested ... increment by 3 based on teh '%3D' Hex code for '='
				// The little 'end == -1' part is needed if the value found is the last value in the cookie ... if it is then the
				//   'end' index (where we look for the next occurence of a pipe ("%7C") wont exist and brakes stuff.
				if( end == -1 )
					var extractedCookieValue = cookieValue[2].substr( start );
				else
					var extractedCookieValue = cookieValue[2].substring( start,end );
				start = extractedCookieValue.indexOf( "%3D" );
				start = start + 3;
				var value = extractedCookieValue.substr(start);
				return( value );
			} else
				return( "0" );
		} else
			return( "0" );
}
