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


var Cookies = {
	init: function () {
		var allCookies = document.cookie.split('; ');
		for (var i=0;i<allCookies.length;i++) {
			var cookiePair = allCookies[i].split('=');
			this[cookiePair[0]] = cookiePair[1];
		}
	},
	create: function (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=/";
		this[name] = value;
	},
	erase: function (name) {
		this.create(name,'',-1);
		this[name] = undefined;
	}
};

function saveIt(name) {
	var x = document.forms['kinform'].kinvalue.value;
	if (!x)
		alert('Please fill in a value in the input box.');
	else {
		Cookies.create(name,x,720);
		// alert('Kin '+x+' added to calculator. Formatting page..done.');
		window.location.reload();
	}
}

function saveIt2(name) {
	var x = document.forms['kinform2'].kinvalue.value;
	if (!x)
		alert('Please fill in a value in the input box.');
	else {
		Cookies.create(name,x,720);
		// alert('Kin '+x+' added to calculator. Formatting page..done.');
		window.location.reload();
	}
}

function saveLook(name) {
	var x = document.forms['lookform'].lookvalue.value;
	if (!x)
		alert('Please fill in a value in the input box.');
	else {
		Cookies.create(name,x,720);
		window.location.reload();
	}
}

function readIt(name) {
	alert('The value of the kin is ' + Cookies[name]);
}

function eraseIt(name) {
        // var kin = readCookie(name);
	Cookies.erase(name);
	// alert('Kin '+kin+' removed from calculator. Formatting page..done.');
	window.location.reload();
}

function init() {
	for (var i=1;i<13;i++) {
		var x = Cookies['kincookie' + i];
		if (x) alert('Calculations for kin ' + i + '\nthat you set on a previous visit, is still active.\nTheir values are ' + x);
	}
}

Cookies.init();

