function is_email(str)
{
	var filtro = /^[A-Za-z][A-Za-z0-9_.-]*@[A-Za-z0-9_.-]+\.[A-Za-z0-9_.]+[A-za-z]$/;
	if (filtro.test(str)) return true;
	else return false;
}
function is_date(date_string)
{
	// matches DD/MM/Y or DD/MM/YYYY or D/M/Y or DD/M/YYYY Leap years treated.
	reg_expr = /^(((0?[1-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}|\d))|((0?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}|\d))|((0?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}|\d))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00|[048])))$/;
	if (!reg_expr.test(date_string)) {
		return false;
	}
	return true;
}
function popup_locked(url, w, h)
{
	win = window.open(url, '', 'width='+w+',height='+h+',toolbar=no,menubar=no,scrollbars=yes,resizable=no');
	win.moveTo(window.screen.availWidth / 2 - w / 2, window.screen.availHeight / 2 - h / 2);
}

function text_optimize(str)
{
	// replace with unicode characters:
	str = str.replace('á', '\u00E1');
	str = str.replace('é', '\u00E9');
	str = str.replace('í', '\u00ED');
	str = str.replace('ó', '\u00F3');
	str = str.replace('ú', '\u00FA');
	return str;
}

function urlencode(str)
{
	var result = "";
	str = str.replace("+", "%2B");
	str = str.replace("/", "%2F");
    for (i = 0; i < str.length; i++) {
        if (str.charAt(i) == " ") result += "+";
        else result += str.charAt(i);
    }
    return escape(result);
}

function url_optimize(str)
{
	str = str.replaceAll(" ", "-");
	str = str.toLowerCase();
        str = str.replace('á', 'a');
	str = str.replace('é', 'e');
	str = str.replace('í', 'i');
	str = str.replace('ó', 'o');
	str = str.replace('ú', 'u');
	return str;
}

String.prototype.replaceAll = function(strTarget, strSubString)
{
	var strText = this;
	var intIndexOfMatch = strText.indexOf( strTarget );

	while (intIndexOfMatch != -1){
		strText = strText.replace( strTarget, strSubString )
		intIndexOfMatch = strText.indexOf( strTarget );
	}
	return( strText );
}

/**************** Efectos Inputbox ****************/
// Inicializar un input con un texto predeterminado
function _initInput(input_id, text_ini)
{	
	input = $("#"+input_id);
	if (!input.val()) input.val(text_ini);
	input.attr("text_ini", text_ini);
	input.focus(function() {
		if ($(this).val() == $(this).attr("text_ini")) $(this).val("") 
	});
	input.blur(function() {
		if ($(this).val() == "") $(this).val($(this).attr("text_ini"));
	});
	input.getTexto = function()
	{
		return $(this).val();
	};
}

function inputIsEmpty(input_id)
{
	input = $("#"+input_id);
	return (input.val() == "" || input.val() == input.attr("text_ini"));
}


// Borrar el texto del input box.
function text_focus(id_input, default_text)
{
	if ($F(id_input) == default_text) {
		$(id_input).value = '';
	}
}
// Devolver texto original del input box.
function text_blur(input_text, text)
{
	if (input_text.value == '') input_text.value = text;
}


var IE = navigator.appName.toLowerCase().indexOf("microsoft") > -1;

function only_numbers(evt){

// NOTE: Backspace = 8, Enter = 13, '0' = 48, '9' = 57, '.'=46, ','  = 44
	var key = IE ? evt.keyCode : evt.which;
	return (key <= 13 || (key >= 48 && key <= 57));
}

//Limpiar un formulario: los input del tipo hidden NO los borra =)
function clean_form(id_form){
	var all_inputs = $("#"+id_form+" :input");
	all_inputs.each(function(){
		if($(this).attr('type') != 'hidden'){
			$(this).val('');
			$(this).blur();
		}
	});
}
/**************** Fin Efectos Inputbox ****************/

String.prototype.trim = function() {
  return this.replace(/^\s+/, '').replace(/\s+$/, '');
};



/******************* Popup con Ajax **********************/
function ajax_div(url, callback)
{
	if (!jQuery.isReady) return;
	$("<div id='ajax_div'></div>").appendTo("#full");	
	$.ajax({
		type: "GET",
		url: url,
		data: {PHPSESSID : PHPSESSID},
		success: function(response) {
			$('#ajax_div').html(response);
			show_div("ajax_div");
			if (callback) eval(callback).call();
		},
		error: function (errorCode, textStatus, errorThrown) {
			if (errorCode.status == 450) session_perdida();
		} 
	});
}

function div_load(div, url)
{
	if (!jQuery.isReady) return;
	$.ajax({
		type: "GET",
		url: url,
		async: false,
		success: function(response) {
			$('#'+div).html(response);
		},
		error: function (errorCode, textStatus, errorThrown) {
			if (errorCode.status == 450) session_perdida();
		}
	});
}

