
// common.js - common javascript functions

function click_Category(oCatg) {	
	var sCatg = oCatg.value;
	document.contdata.Category.value = sCatg;
	document.contdata.disCategory.value = sCatg;
}

function click_LastResults(oResults) {	
	var sResults = oResults.value;
	//alert (">"+sResults+"<")
	if (sResults != "")
		document.contdata.HistComment.value = sResults;
	//document.contdata.HistComment.focus();
}


// -------------------------
// common string functions
// -------------------------

function left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function trimStr(strText) {
	// Get rid of leading spaces 
	while (strText.substring(0,1) == " ") {
		strText = strText.substring(1, strText.length);
	}

	// Get rid of trailing spaces 
	while (strText.substring(strText.length-1, strText.length) == " ") {
		strText = strText.substring(0, strText.length-1);
	}
	return strText;
}

// String.rtrim()
String.prototype.rtrim=function()
{
   var whitespace = new String(" \t\n\r");
   var s = this.valueOf();
   if (whitespace.indexOf(s.charAt(s.length-1)) != -1)
   {
      var i = s.length - 1;      
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;
      s = s.substring(0, i+1);
   }
   return s;
}

// String.ltrim()
String.prototype.ltrim=function()
{
   var whitespace = new String(" \t\n\r");
   var s = this.valueOf();
   if (whitespace.indexOf(s.charAt(0)) != -1) 
   {
      var j=0, i = s.length;
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;
      s = s.substring(j, i);
   }
   return s;
}

// String.trim()
String.prototype.trim=function()
{
	var s = this.valueOf();
	return s.rtrim().ltrim();
}

