function str_replace(busca, repla, orig)
{
	str 	= new String(orig);
	rExp	= "/"+busca+"/g";
	rExp	= eval(rExp);
	newS	= String(repla);
	str = new String(str.replace(rExp, newS));
	return str;
}
function print_r(theObj){
  if(theObj.constructor == Array ||
     theObj.constructor == Object){
    document.write("<ul>")
    for(var p in theObj){
      if(theObj[p].constructor == Array||
         theObj[p].constructor == Object){
document.write("<li>["+p+"] => "+typeof(theObj)+"</li>");
        document.write("<ul>")
        print_r(theObj[p]);
        document.write("</ul>")
      } else {
document.write("<li>["+p+"] => "+theObj[p]+"</li>");
      }
    }
    document.write("</ul>")
  }
}


$(document).ready(function(){

    
jQuery.Mmensaje = function(options) {
	 var defaults = {  
     data: 'Ha ocurrido un error inesperado. Cont\u00e1ctese con el administrador.<br>Gracias',  
     tiempo: 2500
    };  
    var options = $.extend(defaults, options); 
    var data= options.data;
    var tiempo = options.tiempo;
	$('body').prepend('<div id="errorI"><div></div></div>');
	$('#errorI div').html(data);
	$('#errorI').slideDown("slow").delay(tiempo).slideUp("slow");

};
						   
	jQuery.Cargando = function(options) {
		var defaults = {  
		 ver: true
		};  
		var options = $.extend(defaults, options); 
		var ver=options.ver;
		if (ver){
			$('body').prepend('<div id="Loader"><div>Cargando</div></div>');
		}else{
			$('#Loader').remove();
		}
	}
});	
function number_format(a, b, c, d) {
 a = Math.round(a * Math.pow(10, b)) / Math.pow(10, b);
 e = a + '';
 f = e.split('.');
 if (!f[0]) {
  f[0] = '0';
 }
 if (!f[1]) {
  f[1] = '';
 }
 if (f[1].length < b) {
  g = f[1];
  for (i=f[1].length + 1; i <= b; i++) {
   g += '0';
  }
  f[1] = g;
 }
 if(d != '' && f[0].length > 3) {
  h = f[0];
  f[0] = '';
  for(j = 3; j < h.length; j+=3) {
   i = h.slice(h.length - j, h.length - j + 3);
   f[0] = d + i +  f[0] + '';
  }
  j = h.substr(0, (h.length % 3 == 0) ? 3 : (h.length % 3));
  f[0] = j + f[0];
 }
 c = (b <= 0) ? '' : c;
 return f[0] + c + f[1];
}

function eliminarMasivo(){
	$('input[type=checkbox]').click(function(){
		if($(this).attr('id')=='padreCHK'){
			checked=$(this).attr('checked');
			$(':checkbox').each(function(){
				$(this).attr('checked',checked);
			})
			$('.tSelec').text($('.hijo:checked').length);
		}else{
			$('#padreCHK').attr('checked','');
			$('.tSelec').text($('.hijo:checked').length);
		}
	});
	$('.eliminar').click(function(){
		aQuien=$(this).attr('title');
		comboS();
		if((total=$('.hijo:checked').length)>0){
			coma='';
			if(confirm("Eliminar\u00e1 "+total+" elementos.\nEsto no puede ser deshecho. Desea continuar?")){
				$('.hijo:checked').each(function(){
					$(this).parent().parent('tr').animate({ opacity: 0.25},500, function() {$(this).hide();});
					$('#txt_aEliminar').val($('#txt_aEliminar').val()+coma+$(this).val());
					coma='-||-';
				});
				txtElemento=$('#txt_aEliminar').val();
				$.post('includes/ax/eliminador.php',{data:aQuien,elemento:txtElemento},function(data){})
				$('#padreCHK').attr('checked','');
			}
		}
		return false;
	});
	function comboS(){
		coma="";
		eliminar="";
		$('.hijo:checked').each(function(){
			eliminar=eliminar+coma+$(this).val();
			coma="||";
		})
		return eliminar;
	}
}


