// JavaScript Document
<!--
function searchpost()
{
	document.searchform.submit();
}
function calendar(data)
{
	document.getElementById('startdate').value = data;
	searchpost();
}
function today()
{
	document.getElementById('startdate').value = '';
	searchpost();
}
function reset_category()
{
	document.getElementById('default_category').value = true;
	searchpost();
}
function search_query()
{
	searchpost();
}
function clear_search()
{
	document.getElementById('search').value = '';
	searchpost();
}


function showOverlay(height,width,autoclose){
	if ($.browser.msie ) {
		if ($.browser.version == "6.0") {
			//$('#overlay .background').width('');
			$("#overlay").height( $("body").height()+"px" );
			$("#overlay").width( $(window).width()+"px" );
			$("#overlay .background").height( $("body").height()+"px" );
			$("#overlay .background").width( $(window).width()+"px" );
		}
	}
	if (autoclose == true) {
		$("#overlay .background").click(hideOverlay);
	}
	$("#overlay .content").height(height);
	$("#overlay .content").width(width);
	centerOverlay(height,width);
	$(window).bind("resize", function (){
		centerOverlay(height,width);
	});
	$("#overlay").show();
}

function centerOverlay(height,width){
	var box_top = Math.round(( $(window).height() - height ) / 2);
	var box_left = Math.round(( $(window).width() - width ) / 2);
	$("#overlay .content").css("top",box_top+"px");
	$("#overlay .content").css("left",box_left+"px");
}

function hideOverlay(){
	$("#overlay").hide();	
	$("#overlay .background").unbind("click");
	$(window).unbind("resize");
}
$(document).ready( function(){
	if( getUI('toggle_c') == 'h' ) $(".toggle_c").hide();
	if( getUI('toggle_s') == 'h' ) $(".toggle_s").hide();
	if( getUI('toggle_o') == 'h' ) $(".toggle_o").hide();

	$(".title h2").click( function() {
		$(this).parent("div").next(".toggle_c").toggle('fast', function(){
			if ($(this).is(":visible")){ saveUI('toggle_c','v');
			} else { saveUI('toggle_c','h'); }
		});
		$(this).parent("div").next(".toggle_s").toggle('fast', function(){
			if ($(this).is(":visible")){ saveUI('toggle_s','v');
			} else { saveUI('toggle_s','h'); }
		});
		$(this).parent("div").next(".toggle_o").toggle('fast', function(){
			if ($(this).is(":visible")){ saveUI('toggle_o','v');
			} else { saveUI('toggle_o','h'); }
		});
	});
	
	$("#entries .dayentry").hover(
		function(){ $(this).addClass("ovr"); },
		function(){ $(this).removeClass("ovr"); }
	);
	
	$("#nav a").hover(
		function(){ $(this).addClass("ovr"); },
		function(){ $(this).removeClass("ovr"); }
	);

	$(".reminder").click( function(){
	
		var date_id = $( this ).attr('rel');
		showOverlay(227, 400, false);
		$("#overlay .content").empty();
		var reminder_block = $(".reminder_block").clone().appendTo("#overlay .content");
		$( reminder_block ).show().attr('id','reminder_block');
		$("#reminder_block .close").click( function(){
				$("#overlay .content").empty();
				hideOverlay();
		});
		$("#reminder_block .proto_date").val( date_id );
	});
	/*
	$(".register").click( function(){
	
		var event_id = $( this ).attr('rel');
		var new_height = $(window).height() - 200;
		showOverlay( new_height, 400, false);
		$("#overlay .content").empty();
		var reminder_block = $(".register_block").clone().appendTo("#overlay .content");
		$( reminder_block ).show().attr('id','register_block');
		$("#register_block .close").click( function(){
				$("#overlay .content").empty();
				hideOverlay();
		});
		$("#register_block .proto_event").val( event_id );
	});
	*/

});




function saveUI(key,value)
{
	var cookie_string = readCookie('ccpl_ui');
	if ( cookie_string != null )
	{
		var data_array = cookie_string.split(',');
		var array_pos = jQuery.inArray(key, data_array);

		if ( array_pos != -1 )
		{
			data_array[array_pos+1] = value;
			cookie_string = data_array.toString();
		} else {
			cookie_string = cookie_string +","+ key +","+ value;
		}
		createCookie('ccpl_ui',cookie_string,9);
	} else {
		cookie_value = key +","+ value;
		createCookie('ccpl_ui',cookie_value,9);
	}
}

function getUI(key)
{
	if ( readCookie('ccpl_ui') != null )
	{
		var data_array = readCookie('ccpl_ui').split(',');
		var array_pos = jQuery.inArray(key, data_array);

		if ( array_pos != -1 )
		{
			return data_array[array_pos+1];
		}
	} 
	return null;							
}

function createCookie(name,value,days)
{
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	} else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

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;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

