jQuery(document).ready(function() {
	$("#searchField").bind("focus", function() {
		t = $(this);
		if (t.val() == $("#searchDefValue").val())
		{
			$(this).val('');
		}
	})
	$("#searchField").bind("blur", function() {
		t = $(this);
		if (trim(t.val()).length == "") 
		{
			$(this).val($("#searchDefValue").val());
		}
	})
});

/**
 * This functions is to debug variables.
 * NB! Only works with browsers that have a console, usualy firefox with firebug
 * @param {Mixed} value
 */
function debug(value) {

	if (typeof console == "object" && console && console.log) 
	{
		console.debug(value);
	}
	else 
	{
		//alert(value);
	}
}

/**
 * Function to round numbers
 * @param integer num -
 * @param integer dec - how many decimals after comma
 */
function roundNumber(number, dec) {
	var result = Math.round(number * Math.pow(10, dec)) / Math.pow(10, dec);
	return result;
}




/**
 * Finds whether a variable is a number or a numeric string
 *
 * @param {Mixed} value
 * @return {Boolean}
 */
function isNumeric(value) {
	if (value === null) 
	{
		return false;
	}
	if (value === undefined) 
	{
		return false;
	}
	if (value == "") 
	{
		return false;
	}
	value = value.toString().replace(/,/g, ".");
	if (isNaN(value) == true) 
	{
		return false;
	}
	else 
	{
		return true;
	}
}

/**
 * Finds whether a variable is a number or a numeric string
 *
 * @param {Mixed} value
 * @return {Boolean}
 */
function isNumber(value) {
	return isNumeric(value);
}


/**
 * Converts variable to numeric
 * @param {Mixed} v
 */
function toNumber(v) {
	if (v == undefined) 
	{
		return false;
	}
	v = v.toString().replace(/,/g, ".");
	if (isNumeric(v)) 
	{
		if (v.match(/\./)) 
		{
			return parseFloat(v);
		}
		else 
		{
			return parseInt(v);
		}
	}
	return 0;
}

/**
 * Converts number to positive number
 * @param {Object} nr
 * @return {number}
 */
function toPositive(nr) {
	if (nr != undefined) 
	{
		nr = nr.toString().replace("-", "")
		return toNumber(nr);
	}
	return "";
}

/**
 * Converts number to negative number
 * @param {Object} nr
 * @return {number}
 */
function toNegative(nr) {
	if (nr != undefined) 
	{
		nr = nr.toString().replace(/-/g, "")
		nr = '-' + nr;
		return toNumber(nr);
	}
	return "";
	
}

function trim(str, chars) {
	if (str) 
	{
		str.toString();
		return ltrim(rtrim(str, chars), chars);
	}
	return str;
	
}

function ltrim(str, chars) {
	str = str.toString();
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
	str = str.toString();
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

