//allows only digits,backspace to be entered in a textbox 
function onlyNumbers(e)
{
var keynum;
var keychar;
var numcheck,special;

if(window.event) // IE
  {
  keynum = e.keyCode;
  }
else if(e.which) // Netscape/Firefox/Opera
  {
  keynum = e.which;
  }
keychar = String.fromCharCode(keynum);
numcheck = /\d/;

return (numcheck.test(keychar)  ||(keynum==8 )) ;
}


function removeDollar(elementid)
{
	if(elementid.value.charAt(0)=='$')
		elementid.value=elementid.value.substr(1);
}

//appends a dollar sign in front of numeric data entered
function appendDollar(elementid)
{     
     var str=""+elementid.value;
     if(str == "" || str.charAt(0) == '$' || str == "DNP")
		{
			//do nothing
			return;
		}
     //Set the value to DNP if it contains D, N or P characters
	 for(var i=0;i<str.length;i++)
		{
			 if(str.charAt(i)=="D" || str.charAt(i)=="N" || str.charAt(i)=="P")
			 {
				 elementid.value="DNP";
				 return;
			 }
		 }
	var n =  parseInt(str,10);
	if(n==0)
		{
			str="0";
		 }
	 else if(n>0)
		{
			 str=n+"";
		}
	 elementid.value='$'+str;  
}


function imageCorrection(thumbWidth,thumbHeight,elementid)
{
   
	// Make sure the aspect ratio is maintained, so the image is not skewed
	 var thumbRatio = thumbWidth / thumbHeight;
     imageWidth =elementid.width;
	 imageHeight =elementid.height;
	 imageRatio = imageWidth / imageHeight;
	
	if(imageWidth < thumbWidth && imageHeight < thumbHeight)
	{
		thumbHeight = imageHeight;
		thumbWidth = imageWidth;
	}
	else
	{
		if (thumbRatio < imageRatio)
		{
	    	thumbHeight =(thumbWidth / imageRatio);
		}
		else
		{
	    	thumbWidth =(thumbHeight * imageRatio);
		}
	}
  elementid.height=thumbHeight;
  elementid.width=thumbWidth;
  elementid.style.visibility = 'visible';
}
