var options = { path: '/', expires: 10 };

function loadCookie(){
	$("* [rel='genItem']").each(function () {
		 inst = $(this).attr("id");
		 if($.cookie(inst) != ""){
		 	$(this).val($.cookie(inst));
		 }
	});

	updatePreview();
	updateHeader();
	updateContent();
	updateSidebar();
	updateFooter();
	updateBgColor();
	updateBgRepeat();
	updateBgAttachement();
	
	if($.cookie("structure") != ""){ updateStructure($.cookie("structure")); }
	if($.cookie("bgImageURL") != ""){ updateBgImageURL();}
	if($.cookie("headBgImage") != ""){ updateBgHeaderImage($.cookie("headBgImage")); }	
	if($.cookie("bgImage") != ""){ updateBgImage($.cookie("bgImage")); }
	pageTracker._trackPageview('/loadcookie.html');
}

function saveCookie(){
	$("* [rel='genItem']").each(function () {
		inst = $(this).attr("id");
		if($(this).val() != ""){
			$.cookie(inst, $(this).val(), options);
		}
	});
	// 
	$.cookie("bgImage",  escape($("#generat #bgImage").val()), options);
	$.cookie("headBgImage", escape($("#generat #headBgImage").val()), options);

	if(structure != ""){ $.cookie("structure", structure, options); }
	$.cookie("savedTheme", "true", options);
	$.unblockUI();
	pageTracker._trackPageview('/savecookie.html');
	return false;
}
 
function deleteCookie(){
	$("*[rel='genItem']").each(function () {
		inst = $(this).attr("id");
		$.cookie(inst, null, options);
	});
	$.cookie("structure", null, options);
	$.cookie("savedTheme", null, options);
	pageTracker._trackPageview('/deletecookie.html');
	return false;
}

function onCookieAction(){
	$.unblockUI();

	var action = $("input[name='cookieAction']:checked").val();
	switch(action){
		case "loadCookie":
			loadCookie();
		break;
		case "deleteCookie":
			deleteCookie();
		break;
	}
	
	return false;
}
