function getQueryStr(name)
{
  name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
  var regexS = "[\\?&]" + name + "=([^&#]*)";
  var regex = new RegExp(regexS);
  var results = regex.exec(window.location.href);
  if(results == null)
    return "";
  else
    return decodeURIComponent(results[1].replace(/\+/g, " "));
}

$( document ).ready( function(){
	
		$("#nav ul ul ").css({display: "none"}); // Opera Fix
		$("#nav li").hover(function(){
			$(this).find('ul:first').parent('li').addClass("active");
			$(this).find('ul:first').css({visibility: "visible",display: "none"}).slideDown(300);
			},function(){
			$(this).find('ul:first').parent('li').removeClass("active");
			$(this).find('ul:first').css({visibility: "hidden"});
			});
		
		if($('p.form-thank-you').html() != null && $('p.form-thank-you').html() != ""){
			$('#header').before('<div class="messagetop">'+$('p.form-thank-you').html()+'</div>');
		}
		
		// DONATE FORM
		// convert form module to a donation form
		var formid = 410;
		var formaction = 'https://youcanhelp.pscharities.org/cart?cart=checkout';
		var formhasname = true;
		var formproductname = 'cause';
		var defaultname = "General Donation";
		
		$('form#form-'+formid).addClass('foxycart').attr('action',formaction);
		$('form#form-'+formid+' input[name="formid"]').remove();
		$('form#form-'+formid+' input[name="returl"]').remove();
		$('form#form-'+formid+' input[name="siteurl"]').remove();
		
		$('form#form-'+formid+' .form-field-amount input').attr('name','price');
		$('form#form-'+formid+' .form-field-frequency select').attr('name','sub_frequency');
		$('form#form-'+formid+' .form-field-frequency select option:eq(0)').remove();
		$('form#form-'+formid+' .form-field-frequency select option').each(function(){
			// set up all the possible frequencies for foxy
			switch($(this).attr('value').toLowerCase()){
				case "one-time": $(this).attr('value',''); break;	
				case "weekly": $(this).attr('value','1w'); break;	
				case "monthly": $(this).attr('value','1m'); break;	
				case "annually": $(this).attr('value','1y'); break;	
				case "yearly": $(this).attr('value','1y'); break;	
				default: $(this).attr('value','');
			}
		});
		
		// extra fields
		$('form#form-'+formid+' .form-field-item-description input').attr('name','description');

		if(formhasname){
			// the form has a dropdown box for a product name
			$('form#form-'+formid+' .form-field-'+formproductname+' select').attr('name','name');
			$('form#form-'+formid+' .form-field-'+formproductname+' select option:eq(0)').remove();
			var productselected = getQueryStr(formproductname);
			if(productselected != ""){
				$('form#form-'+formid+' .form-field-'+formproductname+' select option').each(function(){
					if($(this).attr('value') == productselected){
						$(this).attr('selected','selected');
						return false;
					}
				});	
			}
		}
		else{
			$('form#form-'+formid).prepend('<input type="hidden" name="name" value="'+defaultname+'" />');	
		}
		
});



