Number.prototype.formatMoney = function(c, d, t){ // c=decimal places (3), d=decimal separator (,), t=thousand separator (.)
	var n = this, c = isNaN(c = Math.abs(c)) ? 2 : c, d = d == undefined ? "," : d, t = t == undefined ? "." : t, s = n < 0 ? "-" : "", i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
	return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
};

String.prototype.htmlEncode = function(){
	var tmp = this;
	tmp=tmp.rep("&","&amp;");
	tmp=tmp.rep("'","&apos;");
	return tmp;
}

String.prototype.cap = function(){
	return this.substring(0,1).toUpperCase()+this.substring(1).toLowerCase();
}

String.prototype.capAll = function(){
	var str = this.toLowerCase();
	var len = str.length;
	if (len>0){
		for(x=0; x<len; x++){
			if (x==0){
				var tmpchar = str.substring(0, 1).toUpperCase();
				var poststr = str.substring(1, len);
				str = tmpchar+poststr;
			} else {
				var tmpchar = str.substring(x, x+1);
				if (tmpchar==" " && x<(len-1)){
					tmpchar = str.substring(x+1, x+2).toUpperCase();
					var prestr = str.substring(0, x+1);
					var poststr = str.substring(x+2, len);
					str = prestr+tmpchar+poststr;
				}
			}
		}
	}
	return str;
}

String.prototype.left = function(chars){
	if (this.indexOf(chars)>- 1 && chars.length>0){
		var init = this.indexOf(chars);
		return this.substring(0, init);
	} return null;
}

String.prototype.right = function(chars){
	if (this.lastIndexOf(chars)>- 1 && chars.length>0){
		var init = this.lastIndexOf(chars);
		return this.substring(init+chars.length);
	} return null;
}

String.prototype.rep = function(buscar, reemplazar){
	var temp=""+this;
	if (typeof(reemplazar)=="undefined") reemplazar="";
	while(temp.indexOf(buscar)>- 1){
		var pos=temp.indexOf(buscar);
		temp=""+(temp.substring(0, pos)+reemplazar+temp.substring((pos+buscar.length), temp.length));
	}
	return temp;
}

String.prototype.toDb = function(){
	var Html=this.rep("\r\n","");
	Html=Html.rep("\n","");
	Html=Html.rep("\t","");
	Html=Html.rep(" "," ");
	Html=Html.rep("> <","><");
	Html=Html.rep("<tbody>","").rep("</tbody>","");
	Html=Html.rep("alt=\"\"","");
	return Html;
}

String.prototype.contains = function(tosearch){
	if (this!=null && this.length>0) if (this.indexOf(tosearch)>-1) return true; return false;
}

String.prototype.replaceAll = function(esta, porEsta){
	var strText = this;
	var intIndexOfMatch = strText.indexOf(esta);
	while (intIndexOfMatch!=-1){
		strText = strText.replace(esta, porEsta)
		intIndexOfMatch = strText.indexOf(esta);
	}
	return( strText );
}

String.prototype.trim = function() {
	return $.trim(this).replaceAll('  ',' ');
}

$.fn.format = function(f) {
	return this.each(function(){
		var type = this.type, tag = this.tagName.toLowerCase();
		if (tag=="input" && type == 'text'){
			var el = $(this);
			el.blur(function(e){
				el.val(eval("el.val().trim()."+f+"()"));
			});
		}
	});
};

$.fn.clear = function(controls) {
    if (controls && controls.length > 0) {
        $(':input', this.id)
             .not(':button, :submit, :reset, :hidden')
             .not(controls.join(','))
             .val('')
             .removeAttr('checked')
             .removeAttr('selected');
        $('div[id^="divFile"]').each(function(index) {
            this.innerHTML = this.innerHTML;
        });
    }
    else {
        $(':input', this.id)
             .not(':button, :submit, :reset, :hidden')
             .val('')
             .removeAttr('checked')
             .removeAttr('selected');
        $('div[id^="divFile"]').each(function(index) {
            this.innerHTML = this.innerHTML;
        });
    }

};

function getIEVersion() {
	var rv = -1; 
	if (navigator.appName == 'Microsoft Internet Explorer') {
		var ua = navigator.userAgent;
		var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
		if (re.exec(ua) != null) rv = parseFloat(RegExp.$1);
	}
	return rv;
}

$().ready(function(){
	if ($.browser.msie){
		$("iframe").each(function(i) { $(this).attr("allowtransparency","true"); });
	}

	$("a,map,area,input:radio,input:checkbox,object,embed").each(function(i) {
		$(this).focus(function(e){ if (this.blur) this.blur() });
	});
});

function doIframe() {
    o = document.getElementsByTagName('iframe');
    for (i = 0; i < o.length; i++) {
        if (/\bautoHeight\b/.test(o[i].className)) {
            setHeight(o[i]);
            removeEvent(o[i], 'load', doIframe)
            addEvent(o[i], 'load', doIframe);
        }
    }
}

function setHeight(e) {
    if (e.contentDocument) {
        e.height = e.contentDocument.documentElement.scrollHeight;
    } else {
        e.height = e.contentWindow.document.body.scrollHeight;
    }
}

function a_entero(valor) {
    valor = parseInt(valor);

    if (isNaN(valor)) {
        return 0;
    } else {
        return valor;
    }
}

//function setHeight(e) {
//    if (e.Document) //ie5+ syntax
//         e.height = e.contentWindow.document.body.scrollHeight;

//    else if (e.contentDocument && e.contentDocument.body.scrollHeight) //ns6+ & opera syntax
//        e.height = e.contentDocument.body.scrollHeight + 35;

//    else if(e.contentDocument && e.contentDocument.body.offsetHeight) //standards compliant syntax – ie8
//    e.height = e.contentDocument.body.offsetHeight + 35;
//}

function addEvent(obj, evType, fn) {
    if (obj.addEventListener) {
        obj.addEventListener(evType, fn, false);
        return true;
    } else if (obj.attachEvent) {
        var r = obj.attachEvent("on" + evType, fn);
        return r;
    } else {
        return false;
    }
}

function removeEvent(obj, evType, fn) {
    if (obj.removeEventListener) {
        obj.removeEventListener(evType, fn, false);
        return true;
    } else if (obj.detachEvent) {
        var r = obj.detachEvent("on" + evType, fn);
        return r;
    } else {
        return false;
    }
}

//if (document.getElementById && document.createTextNode) {
    //addEvent(window, 'load', doIframe);
//}





