// JavaScript Document

function newCookie(name,value,days) {
 var days = 1;   // the number at the left reflects the number of days for the cookie to last
                 // modify it according to your needs
 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 nameSG = name + "=";
	var nuller = '';
	var ca = document.cookie.split(';');

	if (document.cookie.indexOf(nameSG) == -1)
    	return nuller;

	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(nameSG) == 0) return c.substring(nameSG.length,c.length); 
	}
	return null; 
}

function eraseCookie(name) {
  newCookie(name,"",1); }

function toMem(a) {
	newCookie('theLogin', $('#login').val());     // add a new cookie as shown at left for every
    newCookie('thePass', $('#pass').val());   // field you wish to have the script remember
}

function delMem(a) {
  eraseCookie('theLogin');   // make sure to add the eraseCookie function for every field
  eraseCookie('thePass');

   //$('#login').val('');   // add a line for every field
  // $('#pass').val(''); 
}

$(document).ready(function(){
  /* register any elements that need validation 
	*	force validation on field change*/
	
	$("#navigation > li > a").click(function(e) {
		/*close any already open ones*/
		thisone = $(this).parent().find("ul");
		if(thisone.html()){
			e.preventDefault();
		}
		$("#navigation ul").not(this).each(function(e){
			$(this).parent().find(" > a").css("font-weight","normal");
			if ($(this).css("display") != 'none' && $(this).html() != thisone.html())
				$(this).hide('slow');
		});
		if ($(this).parent().find("ul").css("display") != 'none'){
			$(this).parent().find("ul").hide('slow');
		}else{
			$(this).parent().find(" > a").css("font-weight","bold");
			$(this).parent().find("ul").show('slow');
		}	

	});
	
	$('#login').val(readCookie("theLogin"));  // Change the names of the fields at right to match the ones in your form.
	$('#pass').val(readCookie("thePass"));
	if (readCookie("theLogin") != ''){
		$("#checker").attr("checked","checked");	
	}

});