/* --------------------------------------------------------------------------------------------
Javascript functionality that enables the following:
- it will capture any parameters send to the page as a GET request with specified name
- it will set a session cookie with the value of the specified name, session cookie to be available on the whole of the top level domain
- reservations links are now called by javascript. They will go through weblet relocate and will have a specified parameter appended with the value of the cookie
- the reservations link function will also be called from Flash movies.

Functionality written by idekoninck.

version 1, 02/08/2004

Copyright (c) Open World Ltd.
-----------------------------------------------------------------------------------------------*/

// REQUIRES /owshare/jslibrary/cookie.js to be included in the html page before this file.

/**
 * findString()
 * desc: finds parameter with name paramName in GET request for page. If param exists, session cookie is set with value of param
 * 
 * param - paramName, parameter to look for in GET request
 * param - domain, string - domain to set cookie for
 */
function findString(paramName,domain) {
	var request = (window.location).toString();
	if( request.indexOf(paramName) != -1 ) {
		var requestChunks = request.split(paramName + '=');
		if( requestChunks[1].indexOf('&') != -1 ) {
			var paramChunks = requestChunks[1].split('&');
			setCookie(paramName,paramChunks[0],'yes','/',domain); 
		} else {
			setCookie(paramName,requestChunks[1],'yes','/',domain);
		}
	}
}

/**
 * doReservations()
 * desc: takes the reservations link and appends the value of the cookie as a parameter. name of the parameter is paramName
 *
 * param findParamName - name of the parameter that was found in the URL
 * param appendParamName - string, name of the parameter to be appended to the URL
 * param resLink - link to append to, string
 * param escaped - boolean, whether the string is escaped or not (for weblet relocate)
 */
function doReservations(findParamName, appendParamName, resLink, escaped) {
	var theURL = resLink;
	var cookieValue = getCookie(findParamName);
	if (cookieValue != 'empty') {
		if (escaped) {
			theURL += escape('&' + appendParamName + '=' + getCookie(findParamName));
		} else {
			theURL += '&' + appendParamName + '=' + getCookie(findParamName);
		}
	}
	window.location = theURL;
}

/**
 * getAppend()
 * desc: returns the string for a cookie with name paramName. If the cookie has not been set, an empty string is returned.
 *
 * param paramName - the name of the cookie to look for
 */
function getAppend(paramName) {
	var append = getCookie(paramName);
	if(append == 'empty') {
		append = '';
	}
	return append;
}
