
/**
 * Is a valid email address.
 * @return bool
 */
function isEmail(str) {
	return /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/.test(str);
}

/**
 * Is a valid URL.
 * @return bool
 */
function isURL(str) {
	return /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/.test(str);
}

/**
 * Format decimal number to French number.
 * @example "1250.75" to "1 250,75"
 * @param number Decimal number
 * @return string French number
 */
function format_french_number(number) {
	
	number += '';
	x = number.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ' ' + '$2');
	}
	var with_space = x1 + x2;

	return with_space.replace(".", ",");
}

/**
 * Get current domain name.
 */
function getDomain() {
	return (window.location.href.match(/:\/\/(.[^/]+)/)[1]).replace('www.','');
}

/**
 * Set cookie
 * @param name Cookie name
 * @param value Cookie Value
 * @param expiredays Number of days this cookie expires
 */
function setCookie(name, value, expiredays) {
	var exdate = new Date();
	exdate.setDate(exdate.getDate() + expiredays);
	document.cookie = name + "=" + escape(value) + ";domain=." + getDomain() + ";path=/" + (expiredays == null ? "" : ";expires=" + exdate.toUTCString());
}

/**
 * Get cookie value
 * @param name Cookie name
 */
function getCookie(name) {
	if (document.cookie.length > 0) {
		c_start = document.cookie.indexOf(name + "=");
		if (c_start != -1) {
			c_start = c_start + name.length + 1;
			c_end = document.cookie.indexOf(";", c_start);
			if (c_end == -1) {
				c_end = document.cookie.length;
			}
			return unescape(document.cookie.substring(c_start, c_end));
		}
	}
	return "";
}

