
//Copyright Mangolab Ltd. 2008. All rights reserved.
//SUMMARY:
// - This is a module for string functions.
//HISTORY:
// 23.10.08 Version 1.0 - <FC> - Reviewd / FB ref: CASE:1496

function SearchAndReplace(Content, SearchFor, ReplaceWith) {
   var tmpContent = Content;
   var tmpBefore = new String();   
   var tmpAfter = new String();
   var tmpOutput = new String();
   var intBefore = 0;
   var intAfter = 0;
   if (SearchFor.length == 0){
      return;}
   while (tmpContent.toUpperCase().indexOf(SearchFor.toUpperCase()) > -1) {  
      // Get all content before the match
      intBefore = tmpContent.toUpperCase().indexOf(SearchFor.toUpperCase());
      tmpBefore = tmpContent.substring(0, intBefore);
      tmpOutput = tmpOutput + tmpBefore;
      // Get the string to replace
      tmpOutput = tmpOutput + ReplaceWith;
      // Get the rest of the content after the match until
      // the next match or the end of the content
      intAfter = tmpContent.length - SearchFor.length + 1;
      tmpContent = tmpContent.substring(intBefore + SearchFor.length);
   }
   return tmpOutput + tmpContent;
}
