/* javascript function to update form field
 *  field		form field that is being counted
 *  count		form field that will show characters left
 *  maxchars 	maximum number of characters
*/
function characterCount(field, count, maxchars) {
  var realchars = field.value.replace(/\t|\r|\n|\r\n/g,'');
  var excesschars = realchars.length - maxchars;
  if (excesschars > 0) {
		field.value = field.value.substring(0, excesschars);
		alert("Error:\n\n- You are only allowed to enter up to"+maxchars+" characters.");
	} else {
		count.value = maxchars - realchars.length;
	}
}


function findPos(obj) {
    return [$(obj).offset().left, $(obj).offset().top];
}
function loadImage(url, callback, id) {
    var img = new Image();
    img.src = url;
    if (img.complete) {
        callback.call(img, id);
    } else {
        $(img).bind("load", function() {
            callback.call(img, id);
        });
    }
}
function chUrl(id) {
    $(id).attr({
        src: this.src
    });
};
function isNone(str) {
    return str == null || $.trim(str) == "" ? true: false;
};
String.prototype.trim = function() {
    return this.replace(/(^[\s]*)|([\s]*$)/g, "");
};
String.prototype.inc = function(k1, k2) {
    if (k2 == null) {
        k2 = ","
    };
    return (k2 + this + k2).indexOf(k2 + k1 + k2) > -1 ? true: false;
};
String.prototype.sub = function(k1, k2) {
    if (k2 == null) {
        k2 = ","
    };
    var tmp = k2 + this + k2;
    var size = tmp.indexOf(k1);
    if (size == -1) {
        return 0;
    }
    var i = 0;
    while (tmp.charAt(size + 3 + i) != '/') {
        i++;
    }
    return tmp.substring(size + 3, size + 3 + i);
};
function efocu(obj) {
    try {
        $(obj).focus();
    } catch(e) {}
};
