var commentFormCookie = {

	conf : {
		cookieName  : "metaCorderBlog",
		cookieLimit : 30
	},
	
	main : function(){
		commentFormCookie.setSavedValue();
		commentFormCookie.saveValue();
	},
	
	setSavedValue : function(){
		if(commentFormCookie.getCookie()){
			var author     = document.getElementById("commentAuthor");
			var url        = document.getElementById("commentUrl");
			var saveCookie = document.getElementById("saveCookie");

			data = commentFormCookie.getCookie().split("||");
			author.value = data[0];
			url.value    = data[1];
			saveCookie.checked = true;
		}
	},
	
	saveValue : function(){
		var form       = document.getElementById("comments-form");
		var author     = document.getElementById("commentAuthor");
		var url        = document.getElementById("commentUrl");
		var saveCookie = document.getElementById("saveCookie");
		var data,savedData;
		form.onsubmit = function(){
			if(saveCookie.checked){
				//save cookie
				data = author.value+"||"+url.value;
				commentFormCookie.setCookie(data);
			}
			else{
				//del cookie
				savedData = commentFormCookie.getCookie()
				if(savedData){
					document.cookie = commentFormCookie.conf.cookieName + '=' + encodeURIComponent(savedData) + '; path=/; expires=Thu, 01-Jan-70 00:00:01 GMT';
					alert(document.cookie)
				}
			}
		}
	},
	
	setCookie: function(data) {
		var today = new Date();
		today.setTime(today.getTime() + (1000 * 60 * 60 * 24 * Number(this.conf.cookieLimit)));
		document.cookie = this.conf.cookieName + '=' + encodeURIComponent(data) + '; path=/; expires=' + today.toGMTString();
	},
	
	getCookie: function(m) {
		return (m = ('; ' + document.cookie + ';').match('; ' + this.conf.cookieName + '=(.*?);')) ? decodeURIComponent(m[1]) : null;
	},
	
	addEvent : function(){
		if(window.addEventListener) {
			window.addEventListener("load", this.main, false);
		}
		else if(window.attachEvent) {
			window.attachEvent("onload", this.main);
		}
	}
	
}

commentFormCookie.addEvent();
