﻿// JScript File

// limit the number of chanracters that 
// can be entered in the input field
// can be called onkeypress / onkeydown / etc
function limitlenght(obj, maxL)
{
    if (obj.value && obj.value.length && obj.value.length > maxL-1) 
    {
        if (event.keyCode) event.keyCode=0; 
        return false; 
    }
    
    return true;
}

// resizes the image to fit the 
// canvas only if it is bigger 
// than the canvas
function bestfit(img, maxW, maxH) 
{
    w = img.width;
    h = img.height;
    
    // resize only if the image is 
    // bigger than the canvas
    if (w > maxW || h > maxH)
    {
	    //find aspect ratio
	    aspectRatio = Math.min(maxW/w, maxH/h);

        img.width = w * aspectRatio;
        img.height = h * aspectRatio;
    }
    
    if (img.style)
    {
        img.style.visibility = "visible";
    }
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}

String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}