﻿function ReplaceAll(Source,stringToFind,stringToReplace){

  var temp = Source;

    var index = temp.indexOf(stringToFind);

        while(index != -1){

            temp = temp.replace(stringToFind,stringToReplace);

            index = temp.indexOf(stringToFind);

        }

        return temp;

}

function getInternetExplorerVersion()
// Returns the version of Windows Internet Explorer or a -1
// (indicating the use of another browser).
{
   var rv = -1; // Return value assumes failure.
   if (navigator.appName == 'Microsoft Internet Explorer')
   {
      var ua = navigator.userAgent;
      var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
      if (re.exec(ua) != null)
         rv = parseFloat( RegExp.$1 );
   }
   return rv;
   
}


function fixLists(html) {
	var vers = getInternetExplorerVersion();
	
	if ( vers != -1 && vers < 8 ) {
	// Convert <li> to </li><li>

	html = html.replace (/<li(\s+[^>]*)?>/gi, "</li><li$1>");

	// Then remove any that double up with the opening tag

	html = html.replace (/(<(ul|ol)(\s+[^>]*)?>)\s*<\/li>/gi, "$1");

	}
	// And relax

	return html;

}

function ieInnerHTML(obj) { return fixLists( ReplaceAll( ieInnerHtmlFix(obj), '<br>', '<br />') ) };
function ieInnerHtmlFix(obj) { var zz = obj.innerHTML,     z =    zz.match(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/g);  if (z){    for (var i=0;i<z.length;i++){      var y, zSaved = z[i];      z[i] = z[i].replace(/(<?\w+)|(<\/?\w+)\s/,                          function(a){return a.toLowerCase();});      y = z[i].match(/\=\w+[?\s+|?>]/g);       if (y){        for (var j=0;j<y.length;j++){          z[i] = z[i].replace(y[j],y[j]                     .replace(/\=(\w+)([?\s+|?>])/g,'="$1"$2'));        }       }       zz = zz.replace(zSaved,z[i]);     }   }  return zz; }