$(document).ready(function() {
	$('div.tabs').tabs();
	cookievalue = getCookie('nav_tab');
	$('div.tabs').tabs('select', parseInt(cookievalue));
	
	$('#login-nav-1').click(function(event){
		document.cookie = 'nav_tab=0';
	});
	
	$('#login-nav-2').click(function(event){
		document.cookie = 'nav_tab=1';
	});

});

function getCookie(name)
{
	//Without this, it will return the first value 
	//in document.cookie when name is the empty string.
	if(name == '') return('');
	
	name_index = document.cookie.indexOf(name + '=');
	
	if(name_index == -1) return('');
	
	cookie_value =  document.cookie.substr(name_index + name.length + 1, document.cookie.length);
	
	//All cookie name-value pairs end with a semi-colon, except the last one.
	end_of_cookie = cookie_value.indexOf(';');
	if(end_of_cookie != -1)
		cookie_value = cookie_value.substr(0, end_of_cookie);
	
	//Restores all the blank spaces.
	space = cookie_value.indexOf('+');
	while(space != -1) { 
		cookie_value = cookie_value.substr(0, space) + ' ' + 
		cookie_value.substr(space + 1, cookie_value.length);
		space = cookie_value.indexOf('+');
	}
	
	return(cookie_value);
}

