function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}

function is_numeric(mixed_var) {
    return !isNaN(mixed_var);
}

function empty(mixed_var) {
    return (mixed_var === "" || mixed_var === null || mixed_var === false);
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}

function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

// Elimina texto innecesario de un componente TinyMCE
function cleanTextTinyMCE(componentTinyMCE) {
	if (!empty(componentTinyMCE)) {
		text = tinyMCE.get(componentTinyMCE).getContent();
		if (!empty(text)) {
	  		//Limpiamos el texto
	  		text = trim(text.replace(/<p>&nbsp;<\/p><br \/>/g, ''));
			text = trim(text.replace(/<p>&nbsp;<\/p>/g, ''));
			tinyMCE.get(componentTinyMCE).setContent(text);
			result = true;
		}
		else {
			result = false;
		}
	}
	else {
		result = false;
	}
	return result;
}

// Controla si el texto de un componente TinyMCE esta vacio
function isEmptyTinyMCE(componentTinyMCE) {
	if (!empty(componentTinyMCE)) {
		text = tinyMCE.get(componentTinyMCE).getContent();
		if (!empty(text)) {
	  		result = true;
		}
		else {
			result = false;
		}
	}
	else {
		result = false;
	}
	return result;
}
		
function formReload(form_submit, url, params_id) {
	counter = 0;
	var arrayId=new Array();
	var arrayTipo=new Array();
	for(id in params_id) {
		arrayId[counter] = id;
		arrayTipo[counter] = params_id[id];
		counter ++;
	}
	
	params = '';
	for (i = 0; i < counter; i ++) {
		switch (arrayTipo[i]) {
			case 'select' : 
				params += '/' + document.getElementById(arrayId[i]).options[document.getElementById(arrayId[i]).selectedIndex].value;
			break;
			case 'input' : 
				params +=  '/' + document.getElementById(arrayId[i]).value;
			break;
		}
	}
	
	var formVar = document.getElementById(form_submit);
	formVar.action = url + params;
	formVar.submit();
}

function validarUrl(url) {
	(url.value.substr(0, 11) != 'http://www.' || url.value.substr(0, 15) == 'http://www.www.' || url.value.substr(0, 18) == 'http://www.http://') ? url.value = 'http://www.' : false;
}

function actionAjax(url, updateContent, idLoading) {
    jQuery.ajax({
        url: url,
        cache: false,
        success: function(html) {
            jQuery("#" + updateContent).html(html);
        }
    });
}