

function isUndefined(variable) {
	return typeof variable == 'undefined' ? true : false;
}
function isString(object) {
    return typeof object == "string";
}
function isElement(object) {
	return object && object.nodeType == 1;
}
function isFunction(object) {
	return typeof object == "function";
}
function isObject(object) {
	return typeof object == "object";
}
function isArray(object) {
	return object !== null && typeof object == "object" &&'splice' in object && 'join' in object;
}
function isNumber(object){
	return typeof object == 'number';
}
function isJSON(str){
	if (!isString(str) || str === '') {return false;}
	str = replace(/\\./g, '@').replace(/"[^"\\\n\r]*"/g, '');
	return (/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/).test(str);
}

function fetchOffset(obj) {
	var left_offset = obj.offsetLeft;
	var top_offset = obj.offsetTop;
	while(obj = obj.offsetParent) {
		left_offset += obj.offsetLeft;
		top_offset += obj.offsetTop;
	}
	return { 'left' : left_offset, 'top' : top_offset };
}

//read/wirte cookie
var KLCookie = {
	get:function(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 decodeURIComponent(c.substring(nameEQ.length,c.length));
		}
		return null;
	},
	
	set:function(name,value,days,path,domain,secure){
		var expires;
		if(isNumber(days)){
			var date = new Date();
			date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
			expires = date.toGMTString();
		}else if(isString(days)){
			expires = days;
		}else{
			expires = false;
		}
		document.cookie = name + '=' + encodeURIComponent(value) +
				(expires ? ';expires=' + expires  : '') +
				(path ? ';path=' + path : ';path=/') +
				(domain ? ';domain=' + domain : '') +
				(secure ? ';secure' : '');
	},

	/**
	 * Return true if cookie functionnalities are available
	 * @return boolean
	 */
	test: function() {
		KLCookie.set('b49f729efde9b2578ea9f00563d06e57', 'true');
		if (KLCookie.get('b49f729efde9b2578ea9f00563d06e57') == 'true') {
			KLCookie.unset('b49f729efde9b2578ea9f00563d06e57');
			return true;
		}
		return false;
	},

	del:function(key, path, domain) {
		path   = (!path   || typeof path   != 'string') ? '' : path;
        domain = (!domain || typeof domain != 'string') ? '' : domain;
        if (KLCookie.get(key)) KLCookie.set(name, '', 'Thu, 01-Jan-70 00:00:01 GMT', path, domain);
	}
};
