//********************************************************************************
//********************************************************************************
// Version 01.00 - 28/04/2006
//
// This file contains some general string handling routines
//********************************************************************************
// PadL           : Pad a value with leading characters
// PadR           : Pad a value with trailing characters
// Trim           : Removes leading and trailing spaces 
// TrimL          : Removes leading spaces 
// TrimR          : Removes trailing spaces
//********************************************************************************
//********************************************************************************


//********************************************************************************
//    Author: Steve Betts
//      Date: Mar 2006
//      Desc: PadL
//            Pad a value with leading characters
//
// Amendment:
//********************************************************************************
function PadL(p_sValue, p_nDigits, p_sChar) {
 var sFormatted = p_sValue.substr(0, p_nDigits);
 for(i=0;i<(p_nDigits-p_sValue.length);i++) sFormatted = p_sChar + sFormatted;
 return sFormatted;
} 


//********************************************************************************
//    Author: Steve Betts
//      Date: Mar 2006
//      Desc: PadR
//            Pad a value with trailing characters
//
// Amendment:
//********************************************************************************
function PadR(p_sValue, p_nDigits, p_sChar) {
 var sFormatted = p_sValue.substr(0, p_nDigits);
 for(i=0;i<(p_nDigits-p_sValue.length);i++) sFormatted = sFormatted + p_sChar;
 return sFormatted;
} 


//********************************************************************************
//    Author: Steve Betts
//      Date: Oct 2005
//      Desc: Trim
//            Removes leading and trailing spaces
//            (Does not use regular expressions so are suitable for pre 1.2 js)
//
// Amendment:
//********************************************************************************
function Trim(p_sValue) {
 if (p_sValue.length < 1) {
    return"";
 }
 p_sValue = TrimR(p_sValue);
 p_sValue = TrimL(p_sValue);
 if (p_sValue=="") {
    return "";
    }
 else {
   return p_sValue;
 }
}


//********************************************************************************
//    Author: Steve Betts
//      Date: Oct 2005
//      Desc: TrimL
//            Removes leading spaces
//            (Does not use regular expressions so are suitable for pre 1.2 js)
//
// Amendment:
//********************************************************************************
function TrimL(p_sValue) {
 var sSpace = String.fromCharCode(32);

 if (nLen < 1) {
    return"";
 }

 var nLen = p_sValue.length;
 var sTemp = "";
 var iTemp = 0;

 while (iTemp < nLen) {
   if (p_sValue.charAt(iTemp) == sSpace) {
   }
   else {
     sTemp = p_sValue.substring(iTemp,nLen);
     break;
   }
   iTemp = iTemp + 1;
 } 
 return sTemp;
}


//********************************************************************************
//    Author: Steve Betts
//      Date: Oct 2005
//      Desc: TrimR
//            Removes trailing spaces
//            (Does not use regular expressions so are suitable for pre 1.2 js)
//
// Amendment:
//********************************************************************************
function TrimR(p_sValue) {
 var sSpace = String.fromCharCode(32);
 var nLen = p_sValue.length;
 var sTemp = "";

 if (nLen < 0) {
    return"";
 }

 var iTemp = nLen -1;

 while (iTemp > -1) {
   if (p_sValue.charAt(iTemp) == sSpace) {
   }
   else {
     sTemp = p_sValue.substring(0,iTemp +1);
     break;
   }
   iTemp = iTemp-1;
 }
 return sTemp;
}


