function getURLParam(strParamName){
	  var strReturn = "";
	  var strHref = window.location.href;
	  if ( strHref.indexOf("?") > -1 ){
	    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
	    var aQueryString = strQueryString.split("&");
	    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
	      if (
	aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
	        var aParam = aQueryString[iParam].split("=");
	        strReturn = aParam[1];
	        break;
	      }
	    }
	  }
	  return unescape(strReturn);
}

$(document).observe('dom:loaded', function()
{
	hideForms();
	
	var sPage = window.location.pathname.substring(1);
	
	if (sPage !== 'offerte')
	{
		Cookie.unset('showForm');
	}
	
	var sShowFormCookie = Cookie.get('showForm');
	
	if (sShowFormCookie != null)
	{
		showForm(sShowFormCookie);
	}
	else
	{
		var sFormKey = getURLParam('firstForm');
		
		if (sFormKey != null)
		{
			showForm(sFormKey);
		}
	}
	
	var forms_legend = $('forms_legend');
	
	if ( forms_legend != null )
	{
		forms_legend.select('li a').each(function(oLink)
		{
			oLink.observe('click', function(oEvent)
			{
				oEvent.stop();

				var sFormKey = oLink.hash.substring(1);

				showForm(sFormKey);
			});
		});
	}

	function showForm(sFormKey)
	{	
		hideForms();
		
		var oForm = $(sFormKey);
		
		if (oForm != null)
		{
			oForm.show();
			
			Cookie.set('showForm', sFormKey);
		}
	}

	function hideForms()
	{
		var forms_container = $('forms_container');
		if ( forms_container != null )
		{
			forms_container.childElements().each(function(oForm)
			{
				oForm.hide();
			});
		}
	}
});
