    //	Description: 
//		Searches the query string for the supplied parameter name.
//	Arguments:
//		[IN]
//			key - the parameter name to search for
//	Returns:
//		The unescaped parameter value (or null if not found)
//	Modification History:
//		17/07/2006	Paul Harrop		Created
function getSearch(key) {
	var src = window.location.search;
	var sArr;
	if (src == '' || src.indexOf(key+'=') == -1) return null;
	if (src.indexOf('?') == 0) src = src.substr(1);
	if (src.indexOf('&') != -1) sArr = src.split('&');
	else sArr = new Array(src);
	for (var i=0;i<sArr.length;i++) {
		if (sArr[i].indexOf(key+'=') == 0) {
			return unescape(sArr[i].split(key+'=')[1]);
		}
	}
	return null;
}

//	Description: 
//		Searches the query string for colour cards
//	Arguments:
//      maxLength - (Number) Truncate list to this many cards
//                - [optional - default is to not truncate]
//	Returns:
//		A string, prefixed with an '&' suitable for appending to a URL
//	Modification History:
//		15/09/2006	Ben Lings	Created
//      19/09/2006  Ben Lings   Added optional argument maxLength
function getPCCs(maxLength) {

    var pccArray = new Array();
    var pccString = null;
    // Get most recent colour card ('pcc')
    if ((pccString = getSearch('pcc')) != null) {
        pccArray.push(escape(pccString));
    }
    // Get historic colour cards ('pcc' + i)
    var i = 1;
    while ((pccString = getSearch('pcc' + (i++))) != null) {
        pccArray.push(escape(pccString));
    }
    // Number of PCCs to return
    var numPCCs = maxLength || pccArray.length;
    // Make a copy of array
    pccArray = pccArray.slice(0, numPCCs);
    // Replace elements with colour card keys and values
    for (i = 0; i < pccArray.length; i++) {
        pccArray[i] = 'pcc' + (i+1) + '=' + pccArray[i];
    }
    // Set query string
    return (pccArray.length > 0) ? '&' + pccArray.join('&') : '';
}

//	Description: 
//		Searches the query string for information about decoration
//	Arguments:
//      None
//	Returns:
//		A string, prefixed with an '&' suitable for appending to a URL
//	Modification History:
//		15/09/2006	Ben Lings	Created
function getSchemeInfo() {

    var query = new Array();

    if (getSearch('imagecode') != null) {
        query.push("imagecode=" + escape(getSearch('imagecode')));
    }
    if (getSearch('schemecode') != null) {
        query.push("schemecode=" + escape(getSearch('schemecode')));
    }
    if (getSearch('userpalette') != null) {
        query.push("userpalette=" + escape(getSearch('userpalette')));
    }
    
    // Set query string
    return (query.length > 0) ? '&' + query.join('&') : '';
}

if (typeof(encodeURIComponent)!="function") {
    encodeURIComponent = escape;
}

