/*
Name: Google Website Optimizer Google Analytics Integration Tool
Version: 1.1
Original Author: Shawn Purtell
Bugfix: Ophir Prusak
Created: April 2, 2007
Description: Grabs data from Google Website Optimizer tracking cookie (__utmx) and returns the combination
			 number for use in the urchinTracker function.
~~~~~~
Last Modified by Shawn Purtell on June 20, 2007
*/

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

/*
To properly use the getcombo function, you need to pass in a string with the number of variations in each section, seperated with dashes.
For example, if the first section has three variations, the second section has four variations and the third section has two variations you'd call the function as such:

getcombo('3-4-2');

If you do not pass in any paramater, it will use the same calculations as version 1.0, which did not require a parameter
*/ 
function getcombo(variations)
{
	if (document.cookie.indexOf("__utmx=") != -1)
	{
		var utmx_cookie_value = readCookie('__utmx');  
		var cookie_data_array = utmx_cookie_value.split(':');	
		var combination_id = cookie_data_array[2]; 
		var temp = combination_id.split('.');
		var ids = temp[0].split('-');
		var x = ids.length;
		var multiplier = [];
		var factor = 1;
		var sum = 0;
		if (variations != undefined) {
			multiplier = variations.split('-');
		} 
	
		for(i=0; i<x; i++){
			sum += ids[i] * factor;
			factor = (multiplier[i] > 0) ? factor * multiplier[i] : Math.pow(x,i+1) ;
		}
		return sum;
	}
}
