/**
 * static help function.
 * 
 * @author listiki.com
 */

function jqCallback () {
	
}

/**
 * Logs data into browsers console
 * 
 * @param mixed data Data to be logged
 * @return void
 */
function log(data) {
	if (typeof(console) != "undefined")
		console.log(data);
}

/**
 * Validates string to represent correct url address
 * 
 * @param String urlToTest String to be tested for url compability
 * @returns Boolean "true" if string is correct url adress, "false" otherwise
 */
function testUrl(urlToTest){
	return /^https?:\/\/(www\.)?[A-Za-z0-9\.-]{1,}\.[A-Za-z0-9]{2,4}/.test(urlToTest);
}

/**
 * Validates string to represent correct email address
 * 
 * @param String emailToTest String to be tested for email compability
 * @returns Boolean "true" if string is correct email adress, "false" otherwise
 */
function testEmail(emailToTest) {
	return /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/.test(trim(emailToTest));
}

/**
 * Removes specified characters at the end and at the begining of the string
 * If characters aren't specified, removes whitespace characters
 * 
 * @param String str String to be trimmed
 * @param String chars Characters to remove
 * @returns String trimmed string
 */
function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}

/**
 * Removes specified characters at the begining of the string
 * If characters aren't specified, removes whitespace characters
 * 
 * @param String str String to be trimmed
 * @param String chars Characters to remove
 * @returns String trimmed string
 */
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

/**
 * Removes specified characters at the end of the string
 * If characters aren't specified, removes whitespace characters
 * 
 * @param String str String to be trimmed
 * @param String chars Characters to remove
 * @returns String trimmed string
 */
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

/**
 * Sets browsers coookie
 * 
 * @param String name Cookie name
 * @param String value Cookie value
 * @param Integer days Number of days cookie will live
 */
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=/";
}
