﻿/******
 * Guava, www.guava.com
 * Dan Pahlen [dan.pahlen@guava.com], Hans Peter Nielsen [hans.nielsen@guava.com] 
 *
 * This script solves the problem with _linkByPost() not working on GET forms
 * 
 * The script will find all forms in the document of the class "ga_tracking"
 * When either form is submitted, an url string will be generated with the form action + 
 * the form data + Google Analytics data (via _getLinkerUrl())
 *  
 * The resulting URL is used in a location.href, which loads the url as a new page.
 * 
 * If the form uses POST method, the script will call _linkByPost() instead
 * 
 * REQUIREMENTS:
 * -------------
 * - jquery
 * - pageTracker must be initialized with proper UA-number
 *
 ******/

(function($){$(document).ready(function(){

	if (pageTracker) {
		pageTracker._setAllowLinker(true);
	
		$("form.ga_tracking").submit(function (){
			var method = $(this).attr("method").toLowerCase();
			if (!method || "get" == method) {
				var str = $(this).serialize();
				url = $(this).attr('action') + "?" + str;
				url = pageTracker._getLinkerUrl(url);
				location.href = url;
				return false;
			} else {
				pageTracker._linkByPost(this);
			}
		});
	
	}
});})(jQuery);