/* 
 * Last Update: May 6, 2008(Alex)

 * Description:
    common functions used in all pages
    the global myLabCookies array is used to store all the cookies used for the my lab pages.
    the cookies are deleted for any other pages.
   
 * Dependencies:
   - Requires: jquery.js,  jquery.cookie.js 
   - Used in: all pages
 */

 /* The  global myLabCookies array used to store all the cookie names used by the my lab pages */
var myLabCookies = ['workoutId', 'workout', 'date', 'goaltype', 'traineeId', 'login', 'AthleteTrainingProgramCacheDetailID', 'CustomWorkoutExerciseLookupID'];

/* clears the cookies with names given as parameters */
function clearCookies(arrCookies, cookieOptions)
{
	if (cookieOptions)
	{
		for (var i=0; i < arrCookies.length; i++)
			jQuery.cookie(arrCookies[i], null, cookieOptions)
	}
	else
	{
		for (var i=0; i < arrCookies.length; i++)
			jQuery.cookie(arrCookies[i], null)
	}
}

/* clears the cookies with names given as parameters */
function saveCookies(queryParams, cookieOptions)
{	
	if (cookieOptions)
	{
		for (var param in queryParams)
		{
			jQuery.cookie(param, queryParams[param], cookieOptions);
		}
	}
	else
	{
		for (var param in queryParams)
			jQuery.cookie(param, queryParams[param]);
	}
}

/* returns a serialized simple object */
function getSerializedSimpleObject(obj)
{
	var result = new String('');
	for (var i in obj)
		result += i + '=' + obj[i] + '&';
	result = result.substr(0, result.length-1);
	return result;
}

/* runs on document load, check for the my lab links, if not found, clear the cookies used for the my lab pages */
jQuery(function()
{
	if (jQuery('#detail a.addToWorkout, #detail a.addToWorkoutD').size() == 0)
	{
		clearCookies(myLabCookies, {path: '/'});
	}
});