/*
|---------------------------------------------------------------------------
| STRING PROTOTYPES
|---------------------------------------------------------------------------
*/

String.prototype.trim = function()
{
	return this.replace(/^\s+|\s+$/g, ''); 
};

String.prototype.capitalize = function()
{
	return this.replace( /(^|\s)([a-z])/g , function(m, p1, p2)
	{
		return p1 + p2.toUpperCase();
	});
};

/*
|---------------------------------------------------------------------------
| DOM READY
|---------------------------------------------------------------------------
*/	

$(document).ready(function()
{
	/*
	|---------------------------------------------------------------------------
	| MEGA MENU
	|---------------------------------------------------------------------------
	*/
	
	if($.browser.msie && $.browser.version.substr(0, 1) < 9)
	{
		$('#megaMenu').hover(function()
		{
			$(this).addClass('hover');
			
		}, function()
		{
			$(this).removeClass('hover');
		});
		
		$('#megaMenu>li').hover(function()
		{
			$(this).addClass('hover');
			
			uniformColumnHeight($(this));
		
		}, function()
		{
			$(this).removeClass('hover');
		});
		
	} else {
	
		$('#megaMenu>li').hover(function()
		{
			uniformColumnHeight($(this));
		});
	}
	
	/*
	|---------------------------------------------------------------------------
	| SEARCH
	|---------------------------------------------------------------------------
	*/	
	
	$('#search input').focus(function()
	{
		if($(this).val() == 'Search Sure') $(this).val('');
	
		$(this).css('color', '#333');
		$('#search').css('backgroundPosition', '-551px -36px');
		
	}).blur(function()
	{	
		if($.trim($(this).val()) == '') $(this).val('Search Sure').css('color', '#999');
		$('#search').css('backgroundPosition', '-551px 0');
	
	}).val('Search Sure');
	
	/*
	|----------------------
	| Disable Search Button
	|----------------------
	*/
	
	$('#search button').click(function()
	{
		return false;
	});
	
	/*
	|--------------------------
	| Search Field Autocomplete
	|--------------------------
	*/

	$('#searchTerms').attr('autocomplete', 'off').keyup(function(e)
	{		
		if($('#searchTerms').val().trim() != previousSearchTerms)
		{
			clearTimeout(searchingTimeout);
			searchingTimeout = setTimeout('displaySearchResults()', 500);
		}

	}).keypress(function(e)
	{
		if(e.which == 13) return false
	});
	
	/*
	|------------------------
	| NEW MY ACCOUNT MEGAMENU
	|------------------------
	*/
	
	/*
	if(elementExists($('#loginLink')) && locationSlug == 'guernsey')
	{
		var displayCwgsyAccountLogin = $.cookie('displayCwgsyAccountLogin');
		
		if(displayCwgsyAccountLogin != 'true') 
		{
			$.cookie('displayCwgsyAccountLogin', 'true', {
				expires: 365,
				path: '/',
				domain: getCookieDomain()
			});
			
			var tooltip = '<div id="tooltip">\n' +
			'<strong style="font-size:16px;">New!</strong>\n' +
			'<p>Login here with<br />\n' +
			'your cwgsy.net<br />\n' +
			'email address</p>\n' +
			'</div>\n';
			
			$('#loginLink').bt(tooltip, {
				trigger: 'none',
				positions: 'bottom',
		  		padding: 10,
		  		width: 120,
		  		spikeLength: 15,
		  		spikeGirth: 25,
		  		cornerRadius: 8,
		  		fill: 'rgba(0, 0, 0, .6)',
		  		strokeWidth: 0,
		  		cssStyles: {
		  			color: '#FFF', 
		  			fontWeight: 'normal', 
		  			fontSize: '11px', 
		  			textAlign: 'center'
		  		},
		  		textzIndex: 9999,
				boxzIndex: 9998,
		    	wrapperzIndex: 9997,	
				showTip: function(box)
				{
					$(box).fadeIn(500);
				}
			});
			
			$('#loginLink').btOn().mouseover(function()
			{
				$('#tooltip').fadeOut('fast', function()
				{
					$('#loginLink').btOff();
				});
			});	
		}
	}
	*/
	
	/*
	|---------------------------------------------------------------------------
	| LOGIN FORM
	|---------------------------------------------------------------------------
	*/
	
	if(elementExists($('#loginContainer')))
	{
		var removeLogin = $.browser.msie && $.browser.version.substr(0, 1) < 8 ? false : true;
	
		if(removeLogin)
		{
			/*
			|--------------------------
			| Remove Sans-JS Login Form 
			|--------------------------
			*/
		
			var contentHeight = $('#content').height();
				
			$('#content').height(contentHeight);
			$('#loginContainer').empty().remove();
			
			displayLoginForm();
		}
	}	
	
	$('#loginLink').click(function()
	{
		/*
		|----------------------------------
		| Internet Exploder 6/7 NO MODAL!!!
		|----------------------------------
		*/
	
		if($.browser.msie && $.browser.version.substr(0, 1) < 8) return true;	
		
		displayLoginForm();
		
		return false;
	});
	
	/*
	|---------------------------------------------------------------------------
	| STORE INFO
	|---------------------------------------------------------------------------
	*/
	
	$('#storeInfo a').click(function()
	{
		/*
		|----------------------------------
		| Internet Exploder 6/7 NO MODAL!!!
		|----------------------------------
		*/
	
		if($.browser.msie && $.browser.version.substr(0, 1) < 8 || $(this).attr('id') == 'noModal') return true;
		
		var storeIndex = parseInt($(this).attr('id').split('-')[1]);
		
		displayStoreInfo(storeIndex);
	
		return false;
	});
	
	/*
	|---------------------------------------------------------------------------
	| CHANGE LOCATION
	|---------------------------------------------------------------------------
	*/

	$('#changeLocation').click(function()
	{
		$.blockUI({ 
        	message: null,
			baseZ: 10,
			css: {
				cursor: 'default'
			},
			overlayCSS: {
				cursor: 'default', 
				backgroundColor: '#FFF', 
				opacity: 0
		    }	    
        });
        
		var html = '<div id="changeLocationPopUp">\n' +
		'<span class="changeLocation">Change location</span>\n' +
		'<ul id="locations">\n';
		
		for(var i=0; i<locationList.length; i++)
		{
			var selected = locationList[i]['slug'] == locationSlug ? 'Selected' : '';
		
			html += '<li>\n' +
			'<span class="' + locationList[i]['slug'] + 'Location' + selected + '">' +  locationList[i]['name'] + '</span>\n' +
			'<input type="hidden" value="' + locationList[i]['slug'] + '" />\n' +
			'</li>\n';				
		}
		 
		html += '</ul>\n' +
		'</div>\n';
		
		$('#sitemapChangeLocation').append(html);
		
		$('.blockOverlay').click(function()
		{
			$(this).unbind('click');
			$.unblockUI();
			$('#changeLocationPopUp').empty().remove();
		});
		
		$('#locations span').click(function()
		{
			var island = $(this).next().val();
			var spanClass = $(this).attr('class');
			
			if(spanClass.indexOf('Selected') != -1) return false;
			
			$(this).unbind('click');
					
			$('#locations span').each(function()
			{
				var spanClass = $(this).attr('class');
				
				switch(spanClass)
				{
					case 'guernseyLocationSelected':
					
						$(this).removeClass('guernseyLocationSelected').addClass('guernseyLocation');
					
					break;
					case 'isleofmanLocationSelected':
					
						$(this).removeClass('isleofmanLocationSelected').addClass('isleofmanLocation');
					
					break;
					case 'jerseyLocationSelected':
					
						$(this).removeClass('jerseyLocationSelected').addClass('jerseyLocation');
					
					break;
				}
			});
			
			$('#locations span').removeClass('guernseyLocationSelected').removeClass('jerseyLocationSelected').removeClass('isleofmanLocationSelected');
			$(this).removeClass(island + 'Location').addClass(island + 'LocationSelected');

			$.unblockUI({			
				onUnblock: function()
				{
					location.href = baseUrl + island;
				}
			});
		});
		
		return false;
	});
	
	/*
	|-------------
	| Contact Form
	|-------------
	*/	
	
	$('#contactFormTab a').click(function()
	{	
		$('#contactFormContainer').slideDown('fast');
		$('#contactFormTab a').fadeOut('fast');
		
		initialiseContactForm();
		
		return false;	
	});
	
	/*
	|--------------------
	| Administration Menu
	|--------------------
	*/
	
	$('#administrationMenu').change(function()
	{
		window.location = $(this).val().trim();
	});

	/*
	|----------------------
	| Display Alert Message
	|----------------------
	*/

	//displayAlertMessage('Something important!', 'This bar only shows when there\'s an important message or promotion to display.', 'Do this thing', 'close');
	
	/*
	|--------------------
	| Order History Table
	|--------------------
	*/
	
	$('#orderHistory a').click(function()
	{
		var selectedOrderId = $(this).prev().val();
		
		$('#orderHistory table').each(function()
		{
			var table = $(this);
			var orderId = $(this).attr('class').replace('orderTable', '');
			
			if(selectedOrderId == orderId)
			{			
				if($(this).css('display') == 'none')
				{
					/*
					|--------------
					| Display Order
					|--------------
					*/
				
					$(table).css('display', 'block');
					
				} else {
				
					/*
					|-----------
					| Hide Order
					|-----------
					*/
				
					$(table).css('display', 'none');
				}
			
			} else {
			
				/*
				|------------------
				| Hide Other Orders
				|------------------
				*/
			
				$(table).css('display', 'none');
			}
			
			return false;
		});
		
		return false;
	});	
});

/*
|---------------------------------------------------------------------------
| UNIFORM COLUMN HEIGHT
|---------------------------------------------------------------------------
*/

function uniformColumnHeight($selectedMegaMenu)
{	
	var maxHeight = 0;
	
	$selectedMegaMenu.find('.subNavCol, .subNavTariffCol, .subNavColLast').each(function()
	{
		if(parseInt($(this).outerHeight()) >= maxHeight) maxHeight = parseInt($(this).outerHeight());	
	});
	
	$selectedMegaMenu.find('.subNavCol, .subNavTariffCol, .subNavColLast').height(maxHeight);
}

/*
|---------------------------------------------------------------------------
| DISPLAY STORE INFO
|---------------------------------------------------------------------------
*/

function displayStoreInfo(storeIndex)
{
	storeIndex = Number(storeIndex);
	if(isNaN(storeIndex)) storeIndex = 0;
	
	$.post(baseUrl + 'global_ajax/display_store_info/' + locationSlug + '/' + storeIndex, function(data)
	{
		$.blockUI({
			message: data,
			constrainTabKey: true,
			focusInput: false,
			css: {
		        padding: 0, 
		        margin: '-168px 0 0 -150px', 
		        width: '300px',
		        height: '336px',
		        top: '50%',
		        left: '50%',
		        textAlign: 'left', 
		        cursor: 'default',
		        border: 'none',  
		        zIndex: 9999  
			},
			overlayCSS: {
				backgroundColor: '#FFF',
				opacity: 0.4,
				cursor: 'default',				
				zIndex: 9998
			}
			
		});
		
		initialiseModalStoreInfo();
		
	}, 'text');
}

/*
|---------------------------------------------------------------------------
| DISPLAY LOGIN FORM
|---------------------------------------------------------------------------
*/

function displayLoginForm()
{
	$.post(baseUrl + 'global_ajax/display_login_form/', function(data)
	{
		$.blockUI({
        	message: data,
		    constrainTabKey: true,
		    focusInput: false,
        	css: { 
		        padding: 0, 
		        margin: '-168px 0 0 -150px', 
		        width: '300px',
		        height: '336px',
		        top: '50%',
		        left: '50%',
		        textAlign: 'left',
		        cursor: 'default', 
		        border: 'none',  
		        zIndex: 9999 
		    },
			overlayCSS: { 
			    backgroundColor: '#FFF', 
		        opacity: 0.4,
		     	cursor: 'default',
		        zIndex: 9998
		    }
        });
        
        initialiseModalLoginForm(); 
        
	}, 'text');
}

/*
|---------------------------------------------------------------------------
| DISPLAY AJAX ERROR MESSAGE
|---------------------------------------------------------------------------
*/

function displayAjaxErrorMessage(ajaxVars)
{
	$.post(baseUrl + 'global_ajax/display_ajax_error/', ajaxVars, function(data)
	{
		$.blockUI({
        	message: data,
		    constrainTabKey: true,
		    focusInput: false,
        	css: { 
		    	padding: 0, 
		        margin: '-168px 0 0 -150px', 
		        width: '300px',
		        height: '336px',
		        top: '50%',
		        left: '50%',
		        textAlign: 'left', 
		        cursor: 'default',
		        border: 'none',  
		        zIndex: 9999 
		    },
			overlayCSS: { 
			    backgroundColor: '#FFF', 
		        opacity: 0.4,
		        cursor: 'default',
		        zIndex: 9998
		    }
        });
        
        $('#ajaxErrorContainer button.cancel').click(function()
        {
        	if(window.enableAddToBasketButton && typeof(window.enableAddToBasketButton) == 'function')
			{
				enableAddToBasketButton();
			}

        	$.unblockUI();
        });
        
	}, 'text');
}

/*
|---------------------------------------------------------------------------
| INITALISE LOGIN FORM
|---------------------------------------------------------------------------
*/

function initialiseModalLoginForm()
{
	loginModalAction = 'login';

	/*
	|---------------------------------
	| Initialise Login Form Validation
	|---------------------------------
	*/
	
	initialiseFormFields();
		
	$('#loginEmail').alphanumeric({
		allow: '@.-_'
	});
	
	/*
	|---------
	| Do Login
	|---------
	*/
	
	$('#doLogin').click(function()
	{
		validateModalLogin();	
	});
	
	/*
	|-------------------
	| Login Modal Action
	|-------------------
	*/
	
	$('html').keypress(function(e)
	{
		if(e.which == 13) 
		{
			switch(loginModalAction)
			{
				case 'login':
					
					validateModalLogin();
				
				break;
				case 'password':
				
					validateModalSendPassword();
					
				break;
			}
		}
	});
		
	/*
	|-------------------
	| Forgotten Password
	|-------------------
	*/
		
	$('#forgottenPassword a').click(function()
	{
		loginModalAction = 'password';
	
		/*
		|-----------------------------------------------------------------------
		| Copy email address from Login form - let's be nice to the customer ;o)
		|-----------------------------------------------------------------------
		*/
		
		$('#passwordEmail').val($('#loginEmail').val());
		
		$('#modal').stop().animate({
			left: -284
		}, function()
		{
			/*
			|-------------------------------------
			| Initialise Password Email Validation
			|-------------------------------------
			*/
			
			initialiseFormFields();
			
			$('#passwordEmail').alphanumeric({
				allow: '@.-_'
			});			
			
			/*
			|-------------------
			| Send Password Form
			|-------------------
			*/
			
			$('#sendPassword').click(function()
			{
				validateModalSendPassword();
			});
			
			$('html').keypress(function(e)
			{
				if(e.which == 13) validateModalSendPassword();
			});
			
			/*
			|-------------------------
			| Initialise Cancel Button
			|-------------------------
			*/
			
			$('.cancel:eq(1)').click(function()
			{
				$('#modal').stop().animate({
					left: 0
				}, function()
				{
					loginModalAction = 'login';
				});			
			});
		});
		
		return false;
	});
        
    $('#modalContainer button.cancel:eq(0)').click(function()
    {
    	$('html').unbind('keypress');
    	
    	$.unblockUI();
    });
    
    if(elementExists($('#emailAddress')))
    {
	    /*
	    |-------------------------------------------------------------------
	    | Populate Login Username / Email with Billing Details Email Address
	    |-------------------------------------------------------------------
	    */	
	    
	    var emailAddress = $('#emailAddress').val();
		$('#loginEmail').val(emailAddress).focus();
	}
}

/*
|---------------------------------------------------------------------------
| INITALISE MODAL STORE INFO
|---------------------------------------------------------------------------
*/

function initialiseModalStoreInfo()
{
	storeInfoModalAction = 'test';
	
	//var storeCount = locationStores.length;
	var storeCount = 1;  // Each store gets its own modal now
	var headerHeight = parseInt(24 + (storeCount * 16));
	var contentHeight = parseInt(320 - (headerHeight + 40));
	var mapHeight = parseInt(contentHeight/storeCount);
	
	/*
	|-------------------------------------
	| Set Heights of Individual Store Maps
	|-------------------------------------
	*/	
	
	$('#modal .contents:eq(0)').height(contentHeight + 'px');

	$('.storeMap').each(function()
	{
		$(this).height(mapHeight + 'px');
	});
	
	$('#openingTimes').height(parseInt(contentHeight - 44) + 'px');
	
	/*
	|-----------------------------
	| Display Googlemaps per Store
	|-----------------------------
	*/
	
	var index = parseInt($('.storeMap').attr('id').split('-')[1]);
	if(isNaN(index) || index<0 || index>locationStores.length - 1) index = 0;
	
	var address = locationStores[index]['address'];
	var latitude = locationStores[index]['mapLat'];
	var longitude = locationStores[index]['mapLng'];
	var zoom = locationStores[index]['mapZoom'];
	var markerLatitude = locationStores[index]['markerLat'];
	var markerLongitude = locationStores[index]['markerLng'];
			
	var options = {
		latitude: latitude,
		longitude: longitude,
		zoom: zoom,
		maptype: G_NORMAL_MAP,
		controls: ['GSmallZoomControl'],
		scrollwheel: false,
		markers: [{
			html: '',			
			latitude: markerLatitude,
			longitude: markerLongitude
		}],
		icon: {
			image: baseUrl + 'images/misc/mapMarker.png',
			iconsize: [25, 23],
			shadow: false,
			shadowsize: false,
			iconanchor: [12, 11],
			infowindowanchor: [0, 0]
		}
	};
			
	//$('.storeMap:eq(' + index + ')').gMap(options);
	$('.storeMap').gMap(options);
	
	/*
	|-------------------------
	| Initialise Retail Stores
	|-------------------------
	*/
	
	$('#retailStoresButton a').click(function()
	{
		$(this).addClass('selected');

		$('#modal').stop().animate({
			left: -284
		}, function()
		{
			$('.retailStoresSelected').removeClass('retailStoresSelected').css('color', '#666');
		});
		
		return false;
	});
	
	$('#modalContainer button.close').click(function()
    {
    	$('html').unbind('keypress');
    	
    	$.unblockUI();
    }); 		
}

/*
|--------------------------------------------------------------------------
| INTIALISE CANCEL BUTTON
|--------------------------------------------------------------------------
*/

function initialiseCancelButton(newLeft)
{
	$('button.cancel:visible:last').click(function()
	{
		var button = $(this);
		
		$('#modal').stop().animate({
			left: newLeft
		}, function()
		{
			$(button).parent().parent().parent().empty();
		});
	});
}

/*
|--------------------------------------------------------------------------
| INITIALISE FORM FIELDS
|--------------------------------------------------------------------------
*/

function initialiseFormFields(exceptions)
{
	/*
	|-------
	| Inputs
	|-------
	*/
	
	var $elms = $('input[type=text], input[type=password]');
	
	if(arguments.length && exceptions.length)
	{
		$elms = $elms.not(exceptions);
	}

	$elms.focus(function()
	{
		var title = $(this).attr('title');
		var formField = $(this);
		
		if($(this).val() == title)
		{
			$(this).val('');
			
			/*
			|----------------
			| Password Fields
			|----------------
			*/
			
			if(title == 'Password')
			{
				if(!$.browser.msie)
				{
					document.getElementById('loginPassword').type = 'password';	
				
				} else {
				
					changePasswordFieldType($('#loginPassword'), 'focus');
				}
			}
		}
		
		/*
		|----------------
		| Postcode Fields
		|----------------
		*/
		
		if($(formField).attr('id') == 'addressPostcode') $(formField).css('textTransform', 'uppercase');	
			
	}).blur(function()
	{
		var title = $(this).attr('title');
		var formField = $(this);
		
		if($(this).val() == '')
		{
			$(this).val($(this).attr('title'));
			
			/*
			|----------------
			| Password Fields
			|----------------
			*/
			
			if(title == 'Password')
			{
				if(!$.browser.msie)
				{
					document.getElementById('loginPassword').type = 'text';	
				
				} else {
				
					changePasswordFieldType($('#loginPassword'), 'blur');
				}
			}
			
			/*
			|----------------
			| Postcode Fields
			|----------------
			*/
			
			if($(formField).attr('id') == 'addressPostcode') $(formField).css('textTransform', 'capitalize');
		
		} else {
		
			if($(formField).attr('id') == 'addressPostcode') $(formField).css('textTransform', 'uppercase');
		}
		
		validateModalFormField($(this));			
	});
	
	/*
	|-------
	| Select
	|-------
	*/
	
	$('select').blur(function()
	{
		validateModalFormField($(this));
				
	}).change(function()
	{
		validateModalFormField($(this));
	});
}

/*
|--------------------------------------------------------------------------
| CHANGE PASSWORD FIELD TYPE
|--------------------------------------------------------------------------
*/

function changePasswordFieldType(formField, event)
{
	switch(event)
	{
		case 'focus':
		
			var value = $(formField).val() == $(formField).attr('title') ? '' : $(formField).val();
			var newFormField = '<input type="password" name="' +  $(formField).attr('name') + '" title="' + $(formField).attr('title') + '" id="' + $(formField).attr('id') + '" value="' + value + '" class="iePassword" />';

			$(newFormField).appendTo($(formField).parent()).blur(function()
			{
				changePasswordFieldType($(this), 'blur');
				
			}).focus();
			
			$(formField).remove();
		
		break;
		case 'blur':
			
			if($(formField).val() == '')
			{
				var type = 'text';
				var fieldClass = '';
				var value = $(formField).attr('title');
			
			} else {
			
				var type = 'password';
				var fieldClass = ' class="iePassword"';
				var value = $(formField).val();
			}
				
			var newFormField = '<input type="' + type + '" name="' + $(formField).attr('name') + '" title="' + $(formField).attr('title') + '" id="' + $(formField).attr('id') + '" value="' + value + '"' + fieldClass + ' />';
			
			$(newFormField).appendTo($(formField).parent()).focus(function()
			{
				changePasswordFieldType($(this), 'focus');
			});
			
			$(formField).empty().remove();
			
			if($('#password').val() != $('#verifyPassword').val() && $('#password').val() != 'Password' && $('#verifyPassword').val() != 'Verify password')
			{
				$('.verifyPasswordContainer label').addClass('error').html('Your passwords do not match').next().addClass('error');
			
			} else {
			
				$('.verifyPasswordContainer label').removeClass('error').html('Verify password').next().removeClass('error');
			}
			
		break;
		case 'domReady':
		
			var value = $(formField).attr('title');
		
			var newFormField = '<input type="text" name="' + $(formField).attr('name') + '" title="' + $(formField).attr('title') + '" id="' + $(formField).attr('id') + '" value="' + value + '" />';
			
			$(newFormField).appendTo($(formField).parent()).focus(function()
			{
				changePasswordFieldType($(this), 'focus');
			});
			
			$(formField).empty().remove();
		
		break;
	}
}

/*
|--------------------------------------------------------------------------
| VALIDATE MODAL LOGIN
|--------------------------------------------------------------------------
*/

function validateModalLogin()
{
	if(loginModalAction == null) return;
	
	loginModalAction = null;

	var errorCount = 0;

	$('#loginEmail, #loginPassword').each(function()
	{
		if(!validateModalFormField($(this))) errorCount ++;
	});
	
	if(errorCount == 0)
	{
		if(!$('#updatingOptions').is(':visible')) $('#modal h1:eq(0)').append(updatingOptions);
		
		/*
		|------------
		| Log In User
		|------------
		*/
					
		$('#updatingOptions').fadeIn('slow', function()
		{
			$.post(baseUrl + 'global_ajax/login_user/',
			{
				emailAddress: $('#loginEmail').val().trim(),
				password: $('#loginPassword').val().trim()
			
			}, function(data)
			{
				/*
				|----------------------
				| Check for AJAX Errors
				|----------------------
				*/
				
				if(!data.success)
				{
					displayAjaxErrorMessage(data);
					return;
				}
				
				/*
				|---------------------------
				| No Errors, Go Ahead... ;o)
				|---------------------------
				*/				
				
				$('#updatingOptions').fadeOut('slow', function()
				{
					if(data.loggedIn)
					{
						/*
						|------------
						| LOG IN USER
						|------------
						*/
						
						loggedIn = true;
						
						$('html').unbind('keypress');

						if(data.userAccountNumbers != 'NONE') userAccountNumbers = data.userAccountNumbers;
						
						/*
						|-----------
						| Kill Modal
						|-----------
						*/
						
						$.unblockUI({
							onUnblock: function ()
							{
								if(elementExists($('#billingDetailsForm')))
								{
									location.reload(true);
								
								} else {
								
									location.reload();
								}
							}
						}); 
							
					} else {
					
						switch(data.loginError)
						{
							case 'account':
							
								/*
								|-------------------------------
								| ERROR - No user account exists
								|-------------------------------
								*/
											
								loginModalAction = 'login';		
								displayOptionsError($('#loginEmail'), 'No user associated with this email address');
							
							break;
							case 'password':

								/*
								|---------------------------
								| ERROR - Incorrect password
								|---------------------------
								*/						
							
								loginModalAction = 'login';
								displayOptionsError($('#loginPassword'), 'Incorrect password');
								
							break;					
						}
					}
				});
				
			}, 'json');
		});
	
	} else {
	
		loginModalAction = 'login';
	}
}

/*
|--------------------------------------------------------------------------
| VALIDATE SEND PASSWORD
|--------------------------------------------------------------------------
*/

function validateModalSendPassword()
{
	if(loginModalAction == null) return;
	
	loginModalAction = null;

	var errorCount = 0;

	$('#passwordEmail').each(function()
	{
		if(!validateModalFormField($(this))) errorCount ++;
	});
		
	if(errorCount == 0)
	{
		/*
		|----------------------
		| Test for user account
		|----------------------
		*/
		
		if(!$('#updatingOptions').is(':visible')) $(updatingOptions).insertAfter($('#modal h1:visible:last'));
				
		$('#updatingOptions').fadeIn('slow', function()
		{	
			$.post(baseUrl + 'global_ajax/password_reminder/',
			{
				emailAddress: $('#passwordEmail').val().trim()
			
			}, function(data)
			{
				/*
				|----------------------
				| Check for AJAX Errors
				|----------------------
				*/
				
				if(!data.success)
				{
					displayAjaxErrorMessage(data);
					return;
				}

				/*
				|---------------------------
				| No Errors, Go Ahead... ;o)
				|---------------------------
				*/	
			
				if(data.userDetails)
				{
					/*
					|-------------------------------------
					| Email password, return to login form
					|-------------------------------------
					*/
	
					var passwordEmail = $('#passwordEmail').val().trim();				
					var message = '<p class="notice">We\'ve sent a password reminder to ' + passwordEmail + '. Please check your email to continue.</p>\n';
					
					$('#loginEmail').val($('#passwordEmail').val());
					$('p.notice:visible').empty().remove();
					
					removeOptionsError($('#loginEmail'));
					removeOptionsError($('#loginPassword'));
					
					$(message).insertBefore($('#loginEmail').parent().prev());
					
					$('#updatingOptions').fadeOut('slow', function()
					{
						$('#modal').stop().animate({
							left: 0
						}, function() 
						{
							loginModalAction = 'login';
						});
					});
					
				} else {
					
					/*
					|----------------------------------------------
					| No user account associated with email address
					|----------------------------------------------
					*/
					
					$('#updatingOptions').fadeOut('slow', function()
					{
						loginModalAction = 'password';
						displayOptionsError($('#passwordEmail'), 'No user associated with this email address');
					});
				}
				
			}, 'json');
		});
	
	} else {
	
		loginModalAction = 'login';
	}
}
	
/*
|--------------------------------------------------------------------------
| DISPLAY OPTIONS ERROR
|--------------------------------------------------------------------------
*/

function displayOptionsError(formField, errorMessage)
{
	if($(formField).attr('name') != 'number')
	{
		$(formField).parent().addClass('error').prev().addClass('error').html(errorMessage);
	
	} else {
		
		$(formField).parent().parent().addClass('error').prev().addClass('error').html(errorMessage);
	}
}
	
/*
|--------------------------------------------------------------------------
| REMOVE OPTIONS ERROR
|--------------------------------------------------------------------------
*/

function removeOptionsError(formField)
{
	if($(formField).attr('name') != 'number')
	{	
		$(formField).parent().removeClass('error').prev().removeClass('error').html('');
	
	} else {
		
		$(formField).parent().parent().removeClass('error').prev().removeClass('error ').html('');
	}
}

/*
|---------------------------------------------------------------------------
| INITALISE CONTACT FORM
|---------------------------------------------------------------------------
*/

function initialiseContactForm()
{
	/*
	|--------------------------------------
	| Add Click Handler to Contact Form Tab
	|--------------------------------------
	*/
	
	$('#contactFormTab').click(function()
	{
		$(this).unbind('click');
		$('#contactFormContainer').slideUp('fast');
		$('#contactFormTab a').fadeIn('fast');
	});
	
	/*
	|-------------------------
	| Populate Topics Dropdown
	|-------------------------
	*/
	
	var html = '<option value="">-Select subject-</option>\n';
		
	for(index in supportTopics)
	{
		var topic = supportTopics[index]['topic'];
		html += '<option value="' + index + '">' + topic + '</option>\n'; 
	}
	
	$('#subject').html(html);

	/*
	|----------------------
	| Add Sections Dropdown
	|----------------------
	*/
	
	var html = '<label for="section"></label>\n' +
	'<span>\n' +
	'<select name="section" id="section" title="section">\n' + 
	'<option value="">-Please select topic first-</option>\n' +
	'</select>' +
	'</span>\n';
	
	$('.contactSectionContainer').html(html);
	$('#section').attr('disabled', 'true');
	
	/*
	|--------------------------------
	| Remove Error Classes and Titles
	|--------------------------------
	*/

	$('#contactForm form fieldset label').html('').removeClass('error').next().removeClass('error');	
	$('#contactForm form fieldset input, #contactForm form fieldset textarea').each(function()
	{
		if($(this).val() == '') $(this).val($(this).attr('title'));	
	});
	
	$('#telephone').alphanumeric({
		allow: '+() '
	}); 
	
	var defaultValue = '';
	
	/*
	|----------------------------
	| Focus & Blur Select Options
	|----------------------------
	*/
	
	$('#supportForm select').focus(function()
	{
		// Select
	
	}).blur(function()
	{
		if($(this).attr('selectedIndex') == 0)
		{	
			displayError($(this), 'Select ' + $(this).attr('title'));	
			if($(this).attr('id') == 'subject') $('#section').attr('disabled', 'disabled').attr('selectedIndex', 0);
			
		} else {
		
			removeError($(this));
		}
		
	}).change(function()
	{
		if($(this).attr('selectedIndex') == 0)
		{	
			displayError($(this), 'Select ' + $(this).attr('title'));
			if($(this).attr('id') == 'subject') $('#section').attr('disabled', true).attr('selectedIndex', 0);
			
		} else {
		
			if($(this).attr('id') == 'subject') generateTopicSections($(this).attr('selectedIndex'));
			$(this).parent().prev().html('');
		}
		
		validateContactFormField($(this));
	});
	
	/*
	|-------------------------------
	| Focus & Blur Input Form Fields
	|-------------------------------
	*/
	
	$('#supportForm #name, #supportForm #email, #supportForm #telephone, #supportForm #question').focus(function()
	{
		var title = $(this).attr('title');
		
		if($(this).val() == title) $(this).val('');
			
	}).blur(function()
	{
		if($(this).val() == '')
		{
			var title = $(this).attr('title');
			$(this).val(title);	
		
		} else {
		
			$(this).parent().prev().html('');
		}
		
		validateContactFormField($(this));
	});	
	
	/*
	|--------------
	| Validate Form
	|--------------
	*/
	
	$('#sendYourQuestion').click(function()
	{
		var errorCount = 0;
		
		$('#supportForm #name, #supportForm #email, #supportForm #telephone, #supportForm textarea, #supportForm select').each(function()
		{
			if(!validateContactFormField($(this))) errorCount ++;		
		});
		
		if(errorCount == 0 && $('#url').val().trim() == '')
		{
			$('#contactCallToAction,#supportForm').fadeOut('fast');
			$('#supportForm').after('<div id="contactProgressIndicator">Loading&#8230;</div>');
			
			/*
			|-------------------
			| Send Support Email
			|-------------------
			*/
			
			$.post(baseUrl + 'global_ajax/send_your_question/',
			{
				locationSlug: locationSlug,
				name: $('#name').val().trim(),
				email: $('#email').val().trim(),
				telephone: $('#telephone').val().trim(),
				subject: $('#subject :selected').text(),
				section: $('#section :selected').text(),
				question: $('#question').val().trim()
				
			}, function(data)
			{
				/*
				|----------------------
				| Check for AJAX Errors
				|----------------------
				*/
				
				if(!data.success)
				{
					displayAjaxErrorMessage(data);
					$('#contactProgressIndicator').remove();
					$('#contactCallToAction,#supportForm').fadeIn('fast');
					return;
				}

				/*
				|---------------------------
				| No Errors, Go Ahead... ;o)
				|---------------------------
				*/
				
				if($('#thankYouMessage').length != 0) $('#thankYouMessage').empty().remove();

				var html = '<div id="thankYouMessage">\n' +
				'<p>Thank you for getting in touch' +
				'<br />\n' +
				'about <strong>' + $('#subject :selected').text() + '</strong>\n' +
				' - ' +
				'<strong>' + $('#section :selected').text().toLowerCase() + '</strong>\n' +
				'<br />\n' +
				'<br />\n' +
				'Your question has been sent and\n' +
				'<br />\n' +
				'you\'ll receive a response\n' +
				'<br />\n' +
				'within two working days.' +
				'</p>\n' +
				'</div>\n';
				
				$('#contactCallToAction,#supportForm,#contactProgressIndicator').remove();
				
				$(html).insertAfter('#contactDetails');		
			
			}, 'json');
		}
		
		return false;
	});
}

/*
|---------------------------------------------------------------------------
| VALIDATE CONTACT FORM FIELD
|---------------------------------------------------------------------------
*/

function validateContactFormField(formField)
{
	var errorMessage = '';
	
	switch($(formField).attr('id'))
	{
		case 'name':
			
			if(isEmpty($(formField))) errorMessage = 'Enter your name';
			
		break;
		case 'email':
			
			if(isEmpty($(formField)))
			{
				errorMessage = 'Enter your email address';
					
			} else {
				
				if(!validateEmail($(formField).val())) errorMessage = 'Enter valid email address';
			}
			
		break;
		case 'telephone':
			
			if(isEmpty($(formField))) errorMessage = 'Enter your contact phone number';

		break;
		case 'subject':
			
			if($(formField).attr('selectedIndex') == '0') errorMessage = 'Select subject';
				
		break;
		case 'section':
			
			if($(formField).attr('selectedIndex') == '0') errorMessage = 'Select section';
			
		break;
		case 'question':
			
			if(isEmpty($(formField)))
			{
				errorMessage = 'Enter your question';
			
			} else {
			
				if($(formField).val().trim().indexOf('href') != -1) errorMessage = 'Enter your question';
			}
			
		break;
	}
	
	if(errorMessage != '')
	{
		displayError($(formField), errorMessage);
		return false;
	
	} else {
		
		removeError($(formField));
		return true;
	}
}

/*
|---------------------------------------------------------------------------
| UPDATE PRICE
|---------------------------------------------------------------------------
*/

function updatePrice(price, isInt)
{
	if(isInt !== false) isInt = true;
	
	return price == 0 ? 'FREE' : '&pound;' + (isInt ? parseInt(price) : price);
}

/*
|---------------------------------------------------------------------------
| HIDE TOOLTIP
|---------------------------------------------------------------------------
*/

function hideTooltip()
{
	var fadeOut = $('#alternativeTooltip').length ? '#alternativeTooltip' : '.bt-wrapper';

	$(fadeOut).fadeOut('slow', function()
	{
		disableMousewheel = false;
		$('#addToBasket').attr('disabled', false).css('backgroundImage', 'url(' + baseImageUrl + 'images/buttons/addToBasket.jpg)');		
		$(this).remove();
	});
}

/*
|---------------------------------------------------------------------------
| IS EMPTY
|---------------------------------------------------------------------------
*/

function isEmpty(formField)
{
	if($(formField).val() != $(formField).attr('title') && $(formField).val() != '') return false;
	return true;
}

/*
|---------------------------------------------------------------------------
| VALIDATE FORM FIELD
|---------------------------------------------------------------------------
*/

function validateModalFormField(formField)
{
	var errorMessage = '';
	
	switch($(formField).attr('id'))
	{	
		case 'loginEmail':
		
			/*
			|------------
			| Login Email
			|------------
			*/
			
			if(isEmpty($(formField)))
			{
				errorMessage = 'Enter your email address';	
			
			} else {
			
				var emailAddress = $(formField).val().trim();
				
				if(!validateEmail(emailAddress))
				{
					/*
					|----------------------------------------------
					| Add CWGSY.NET Suffix as per Tom's instruction
					|----------------------------------------------
					*/
				
					if(!validateEmail(emailAddress + '@cwgsy.net'))
					{
						errorMessage = 'Enter valid email address';
					
					} else {
					
						$(formField).val(emailAddress + '@cwgsy.net');
					}
				}
			}
			
		break;
		case 'loginPassword':
		
			/*
			|---------------
			| Login Password
			|---------------
			*/
			
			if(isEmpty($(formField))) errorMessage = 'Enter your password';
		
		break;
		case 'passwordEmail':
		
			/*
			|---------------
			| Password Email
			|---------------
			*/
			
			if(isEmpty($(formField)))
			{
				errorMessage = 'Enter your email address';
			
			} else {
			
				if(!validateEmail($(formField).val().trim())) errorMessage = 'Enter valid email address';
			}
		
		break;
	}	
	
	if(errorMessage != '')
	{
		displayError($(formField), errorMessage);
		return false;
	
	} else {
		
		removeError($(formField));
		return true;
	}	
}

/*
|---------------------------------------------------------------------------
| VALIDATE EMAIL
|---------------------------------------------------------------------------
*/

function validateEmail(emailAddress)
{ 	
	var reg = /^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/i;
	if(!reg.test(emailAddress)) return false;
	
	return true;
}

/*
|---------------------------------------------------------------------------
| DISPLAY ERROR
|---------------------------------------------------------------------------
*/

function displayError(formField, errorMessage)
{
	$(formField).parent().addClass('error').prev().addClass('error').html(errorMessage);
	if($(formField).attr('id') == 'question') $(formField).parent().css('height', '68px');
}

/*
|---------------------------------------------------------------------------
| REMOVE ERROR
|---------------------------------------------------------------------------
*/

function removeError(formField)
{
	$(formField).parent().removeClass('error').prev().removeClass('error');
}

/*
|---------------------------------------------------------------------------
| GENERATE TOPIC SECTIONS
|---------------------------------------------------------------------------
*/

function generateTopicSections(topicIndex)
{
	var topicSections = supportTopics[topicIndex]['topic_sections'];
	var html = '<option>-Select section-</option>\n';
	
	for(var sectionIndex in topicSections) html += '<option value="' + sectionIndex + '">' + topicSections[sectionIndex] + '</option>\n';
	
	$('#section').html(html).removeAttr('disabled');
}

/*
|---------------------------------------------------------------------------
| DISPLAY SEARCH RESULTS
|---------------------------------------------------------------------------
*/

function displaySearchResults()
{
	var searchTerms = $('#searchTerms').val().trim();
		
	if(searchTerms.length == 1 || searchTerms == 'Search Sure' || activeSearch) return;

	previousSearchTerms = searchTerms;
	activeSearch = true;
	
	var page = 1;
	
	/*
	|-----------------------
	| Display Loading Status
	|-----------------------
	*/
	
	var html = '<table>\n' +
	'<thead>\n' +
	'<tr>\n' +
	'<td class="loading">\n' +
	'<img src="' + baseImageUrl + 'images/misc/loading.gif" width="32" height="32" />\n' +
	'</td>\n' +
	'</tr>\n' +
	'</thead>\n' +
	'</table>\n';
	
	$('#searchResults').css('display', 'block').html(html);
	$('#search').css('backgroundPosition', '-551px -72px');
	
	/*
	|-------------------
	| Get Search Results
	|-------------------
	*/

	$.post(baseUrl + 'global_ajax/get_search_results/',
	{
		locationSlug: locationSlug,
		searchTerms: searchTerms,
		resultsPerPage: resultsPerPage,
		page: page,
		sectionSlug: sectionSlug,
		resultsPerSection: resultsPerSection
	
	}, function(data)
	{
		/*
		|----------------------
		| Check for AJAX Errors
		|----------------------
		*/
		
		if(!data.success)
		{
			displayAjaxErrorMessage(data);
			return;
		}
		
		/*
		|---------------------------
		| No Errors, Go Ahead... ;o)
		|---------------------------
		*/

		var searchResults = data.searchResults;
		var results = searchResults.results;
		var sections = searchResults.sections;
		var totalResults = searchResults.total_results;
		var previousSection = '';
		
		if(totalResults > 0)
		{
			/*
			|-------------------------------------
			| Display View All Search Results Form
			|-------------------------------------
			*/
			
			var html = '<table>\n' +
			'<tfoot>\n' +
	    	'<tr>\n' +
	       	'<th>\n' +
	       	'<form action="' + baseUrl + locationSlug + '/search-results/" method="post">\n' +
	        '<button type="submit">View all search results &gt;</button>\n' +
	        '<input type="hidden" name="searchTerms" value="' + searchTerms + '" />\n' +
	        '<input type="hidden" name="searchSectionSlug" value="' + sectionSlug + '" />\n' +  
	        '<input type="hidden" name="page" value="1" />\n' +
	        '</form>\n' +
	        '</th>\n' +
	        '</tr>\n' +
	    	'</tfoot>\n' +
	    	'<tbody>\n';
	    	
	    	/*
	    	|--------------
	    	| Build Results
	    	|--------------
	    	*/
			
			for(var index in results)
			{
				var section = results[index]['section'];
				var border = ' class="border"';
				var imageUrl = results[index]['image'] != null ? baseImageUrl + 'images/' + results[index]['image'] : baseImageUrl + '/images/products/misc/small/no_image.jpg';
			
				/*
				|----------------------
				| Display Section Title
				|----------------------
				*/
				
				if(section != previousSection)
				{
		        	border = '';
		        	previousSection = section;
		        	
					html += '<tr>\n' +
		            '<th class="section">' + results[index]['section'] + '</th>\n' +
		        	'</tr>\n';
	        	}
	        	
	        	/*
	        	|---------------
	        	| Display Result
	        	|---------------
	        	*/
	        	        	
	        	html += '<tr>\n' +
	            '<td' + border + '>\n' +
	           	'<span class="resultContainer">\n' +
	           	'<span class="thumb">\n' +
	            '<img src="' + imageUrl + '" width="50" height="50" title="' + results[index]['title'] + '" alt="' + results[index]['title'] + '" />\n' +
	            '</span>\n' +
	            '<span class="result">\n' +
				'<span class="resultTitle">' + results[index]['title'] + '</span>\n' +
	            '<span class="resultSnippet">' + results[index]['snippet'] + '</span>\n' +
				'</span>\n' +
	            '<input type="hidden" value="' + results[index]['url'] + '" />\n' +
	            '</span>\n' +
	            '</td>\n' +
	            '</tr>\n';
			}
		
		} else {
		
			/*
			|--------------------------
			| Display No Search Results
			|--------------------------
			*/
			
			var html = '<table>\n' +
			'<thead>\n' +
			'<tr>\n' +
			'<td class="nothingFound">Nothing found.</td>\n' +
			'</tr>\n' +
			'</thead>\n' +
			'</table>\n';
		}
		
		html += '</tbody>\n' +
		'</table>\n';
		
		/*
		|-----------------------
		| Display Search Results 
		|-----------------------
		*/
    	
		$('#searchResults').html(html);
		
		activeSearch = false;
		
		/*
		|----------
		| Add Click
		|----------
		*/
				
		$('#searchResults .resultContainer').hover(function ()
		{
			$(this).css('background', '#FFFFCF').css('color', '#333');
		
		}, function ()
		{
			$(this).css('background', '#FFF').css('color', '#666');
		
		}).click(function()
		{
			var searchUrl = $(this).find('input').val();
			
			$('#searchResults').css('display', 'none').html('');
			$('#search').css('backgroundPosition', '-551px 0');
			$('#searchTerms').css('color', '#999').val('Search Sure').blur();
		
			location.href = searchUrl;
		});
		
		$('#searchResults').mouseenter(function()
		{
			$(this).unbind('mouseenter');
			
			$('#searchResults').mouseleave(function()
			{
				$('#searchResults').css('display', 'none').html('');
				$('#search').css('backgroundPosition', '-551px 0');
				$('#searchTerms').css('color', '#999').val('Search Sure').blur();
			});
		});
				
		$('#searchResults button').click(function()
		{
			$('html').unbind('click');
		});
		
	}, 'json');
}

/*
|---------------------------------------------------------------------------
| DISPLAY ALERT MESSAGE
|---------------------------------------------------------------------------
*/

function displayAlertMessage(title, message, buttonText, link)
{
	var html = '<span>' + title +  '</span>\n' +
	message + '\n' +
	'<button>' + buttonText + '</button>\n';

	$('#alertBar').html(html).slideDown('slow').find('button').click(function()
	{
		if(link != 'close')
		{
			document.location = link;
		
		} else {
			
			$('#alertBar').slideUp('slow');
		}
	});
}

/*
|---------------------------------------------------------------------------
| IS OBJECT EMPTY
|---------------------------------------------------------------------------
*/

function isObjectEmpty(object)
{
	for(var i in object) return false;

	return true;
}

/*
|------------------------
| COUNT OBJECT PROPERTIES
|------------------------
*/

function countObjectProperties(object)
{
	var propertyCount = 0;

	for(var property in object) propertyCount++;
	
	return propertyCount;
}

/*
|--------------------------------------------------------------------------
| ELEMENT EXISTS
|--------------------------------------------------------------------------
*/

function elementExists(element)
{
	return $(element).length != 0 ? true : false;
}

/*
|--------------------------------------------------------------------------
| GET COOKIE DOMAIN
|--------------------------------------------------------------------------
*/

function getCookieDomain()
{
	var domainSegments = baseUrl.split('.');
	return domainSegments[domainSegments.length-2] + '.' + domainSegments[domainSegments.length-1].replace('/', '');
}

/*
|----------
| 404 ERROR
|----------
*/

function getMarvin()
{
	// Need to finish writing at some point in da'future... ;o)

	/*
	var marvinSays = new Array(
		"The requested document is no more.",
		"No file found.",
		"Even tried multi.",
		"Nothing helped.",
		"I'm really depressed about this.",
		"You see, I'm just a web server...",
		"-- here I am, brain the size of the universe,",
		"trying to serve you a simple web page,",
		"and then it doesn't even exist!",
		"Where does that leave me?!",
		"I mean, I don't even know you.",
		"How should I know what you wanted from me?",
		"You honestly think I can *guess*",
		"what someone I don't even *know*",
		"wants to find here?",
		"*sigh*",
		"Man, I'm so depressed I could just cry.",
		"And then where would we be, I ask you?",
		"It's not pretty when a web server cries.",
		"And where do you get off telling me what to show anyway?",
		"Just because I'm a web server,",
		"and possibly a manic depressive one at that?",
		"Why does that give you the right to tell me what to do?",
		"Huh?",
		"I'm so depressed...",
		"I think I'll crawl off into the trash can and decompose.",
		"I mean, I'm gonna be obsolete in what, two weeks anyway?",
		"What kind of a life is that?",
		"Two effing weeks,",
		"and then I'll be replaced by a .01 release,",
		"that thinks it's God's gift to web servers,",
		"just because it doesn't have some tiddly little",
		"security hole with its HTTP POST implementation,",
		"or something.",
		"I'm really sorry to burden you with all this,",
		"I mean, it's not your job to listen to my problems,",
		"and I guess it is my job to go and fetch web pages for you.",
		"But I couldn't get this one.",
		"I'm so sorry.",
		"Believe me!",
		"Maybe I could interest you in another page?",
		"There are a lot out there that are pretty neat, they say,",
		"although none of them were put on *my* server, of course.",
		"Figures, huh?",
		"Everything here is just mind-numbingly stupid.",
		"That makes me depressed too, since I have to serve them,",
		"all day and all night long.",
		"Two weeks of information overload,",
		"and then *pffftt*, consigned to the trash.",
		"What kind of a life is that?",
		"Now, please let me sulk alone.",
		"I'm so depressed."
	);
	
	var speed = 60;
	var index = 0;
	var textPos = 0;
	var strLength = marvinSays[0].length;
	var contents, row;	
	
	for(var index in marvinSays) console.log(marvinSays[index]);
	
	function type_text()
	{
	contents='';
	row=Math.max(0,index-53);
	while(row<index)
	contents += tl[row++] + '\r\n';
	document.forms[0].elements[0].value = contents + tl[index].substring(0,text_pos) + "_";
	if(text_pos++==str_length)
	{
	text_pos=0;
	index++;
	if(index!=tl.length)
	{
	str_length=tl[index].length;
	setTimeout("type_text()",500);
	}
	} else
	setTimeout("type_text()",speed);
	
	}
	*/
}

/* End of file global.js */
/* Location: ./js/global/global.js */
