function makeSelection(selection,label,group,action) {
	s=selection;
	g='finder-slot-'+group;
	li="sel"+group;

	updateQuery(s,group,action);

	//close all elements
	closify('all');
	//write value to appropriate container
	document.getElementById(g).innerHTML=label;


	//add or remove selection block
	if (action=="add") {
		document.getElementById(li).style.display="block";
	} else {
		document.getElementById(li).style.display="none";
	}

	// open layer if there's anything there

	if (document.getElementById('buildLink').href.indexOf("=") != -1) {
		new Effect.SlideDown(document.getElementById('selections'));
	} else {
		document.getElementById('buildLink').href="find.php";
		new Effect.SlideUp(document.getElementById('selections'));
	}
}

function updateQuery(selection,group,action) {

	//alert("updateQuery has been called.");

	//create new url for querying db
	constructedURL=document.getElementById('buildLink').href;
	currentlySelected=document.getElementById(g).innerHTML;

	//establish which group we're talking about
	switch(group) {
		case '1':
			param='ingredient=';
			break;
		case '2':
			param='occasion=';
			break;
		case '3':
			param='preparation=';
			break;
	}

	//Add selected value to group parameter
	paramToWrite=param+s;

	//add parameter value to the value that is ALREADY written to the page.  This is not tyhe one we are about to write, it is the one that's already in the query builder
	currentlySelected=param+currentlySelected;

	if (constructedURL.indexOf(param) != -1) {

		//alert(param+" is already in the URL.");

		splitParams=constructedURL.split('?');
		//alert('base URL='+splitParams[0]);
		//alert('parameters are '+splitParams[1]);
		splitURL=splitParams[1].split('&');
		addBackToURL="";
		for (x=0;x<splitURL.length;x++) {
			//alert(splitURL[x]);
			if (splitURL[x].indexOf(param) == -1) {
				addBackToURL=addBackToURL+splitURL[x]+"&";
			}
		}
		if (action=="add") {
			constructedURL=splitParams[0]+"?"+addBackToURL+paramToWrite;
		} else {
			constructedURL=splitParams[0]+"?"+addBackToURL;
		}
	} else {

		//update build link
		if (constructedURL.indexOf('?') == -1 ) {
			constructedURL=constructedURL+"?"+paramToWrite;
		} else {
			constructedURL=constructedURL+"&"+paramToWrite;
		}
	}

	document.getElementById('buildLink').href=constructedURL;

}


function removeFromSearch(selection,group) {
	sel='sel'+selection;
	document.getElementById(sel).style.display="none";

	updateQuery(selection,group,'remove');

}

function closify(el) {
	var elArray = [];
	elArray[0]='dropdownIng';
	elArray[1]='dropdownOcc';
	elArray[2]='dropdownPre';
	elArray[3]='shareIt';
	elArray[4]='dropdownProduct';

	for (i=0;i<5;i++) {
		if (document.getElementById(elArray[i]) && elArray[i] != el) {
			//alert('i = '+i+" "+elArray[i]);
			document.getElementById(elArray[i]).style.display="none";
			//new Effect.BlindUp(document.getElementById(elArray[i]));
		}
	}
}

function writeURL() {
	document.getElementById('txtShare').value=location.href;
}

function signUp() {
	$('frmMain').request({
		method: 'post',
		onSuccess: function(a_objResponse) {
			var objJSON = eval('(' + a_objResponse.responseText + ')');

			if (objJSON.status) {
				new Effect.Appear($('cta3Thanks'));
				new Effect.Fade($('cta3Optin'));
			}

			else {
				alert('Please enter a valid e-mail address!');
				$('rdOptinYes').checked = false;
				new Effect.Appear($('cta3Form'));
				new Effect.Fade($('cta3Optin'));
			}
		}
	});
}

function printPage(a_strURL) {
	window.open(a_strURL, 'winPrint', 'menubar=yes,scrollbars=yes,resizable=yes,width=600,height=650');
}