
function IsNumeric(S) { return S > '' && ! isNaN(S) }

function setError(divName) {
	$("#"+divName).removeClass('info').removeClass('ok').addClass('alert').show();
}
function setOK(divName) {
		$("#"+divName).removeClass('info').removeClass('alert').addClass('ok').show();
}
function setInfo(divName) {
	$("#"+divName).removeClass('ok').removeClass('alert').addClass('info').show();	
}

function showError(divName,Text) {
	setError(divName);
	$("#"+divName).html(Text);
}	
function showOK(divName,Text) {
	setOK(divName);
	$("#"+divName).html(Text);
}
function showInfo(divName,Text) {
	setInfo(divName);
	$("#"+divName).html(Text);
}

function initBtnDiv(parentDivName) {
	
	$(parentDivName+' .btn').each(function(){
		var b = $(this);
		var tt = b.text() || b.val();		
		if ($(':submit,:button',this)) {
			//b = $('<a>').insertAfter(this).addClass(this.className).attr('id',this.id); 
			//$(this).remove();
		}
		b.text('').css({cursor:'pointer','text-decoration':'none'}).prepend('<i></i>').append($('<span></span>').
			text(tt).prepend('<span></span><i></i>')).attr('href',this.href);
	});	
}

function initBtn() {
	
	$('.btn').each(function(){
		var b = $(this);
		var tt = b.text() || b.val();		
		if ( $(this).is(':button,:submit') ) {
			//b = $('<a>').insertAfter(this).addClass(this.className).attr('id',this.id); 
			//$(this).remove();
		} else {
			b.text('').css({cursor:'pointer','text-decoration':'none'}).prepend('<i></i>').append($('<span></span>').
			text(tt).prepend('<span></span><i></i>')).attr('href',this.href);
		}
		
	});	

	$('.button').each(function(){
		var b = $(this);
		var tt = b.text() || b.val();		
		if ($(':submit,:button',this)) {
			//b = $('<a>').insertAfter(this).addClass(this.className).attr('id',this.id); 
			//$(this).remove();
		}
		b.text('').css({cursor:'pointer','text-decoration':'none'}).append($('<span></span>').
			text(tt)).attr('href',this.href);
	});	
	

	/*
	$('.btn').livequery('click',
		function(){ 
        	$(this).css({cursor:'pointer','text-decoration':'none'});		
	    }
   ); 
	*/
}

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
