var gBACKCOLOR="#ccf533",gTEXTBACKCOLOR="#e99bff";function CompareById(d,e){var c=document.getElementById(d),b=document.getElementById(e),a=[];a=GetAllTextNodes(c);c=[];c=GetAllTextNodes(b);CompareNodes(a,c)}function Equal(d,e){if(d.data==e.data)return true;return false}
function CompareText(d,e){var c=d.length,b=e.length;if(b==c&&1==b)if(d[0].data.length==e[0].data.length&&1==e[0].data.length)return;if(0==c)for(var a=0;a<b;a++)PaintNode(e[a],gTEXTBACKCOLOR);else if(0==b)for(a=0;a<c;a++)PaintNode(d[a],gTEXTBACKCOLOR);else{a=[];a=GetCharList(d);b=[];b=GetCharList(e);c=[];c=CompareChars(a,b);if(0!=c[0].length||0!=c[1].length){for(a=0;a<d.length;a++)d[a]=PaintNode(d[a],gBACKCOLOR);for(a=0;a<e.length;a++)e[a]=PaintNode(e[a],gBACKCOLOR)}Display(c[0],d);Display(c[1],e)}}
function GetCharList(d){for(var e=[],c=0;c<d.length;c++)for(var b=d[c].data,a=0;a<b.length;a++)e[e.length]=b.charAt(a);return e}function Display(d,e){var c=[];if(0!=d.length)for(var b=0;b<e.length;b++){c.length=0;c=[];if(1==e.length)c=d;else{c=0;if(b>0)for(var a=0;a<b;a++)c+=e[a].data.length;c=GetSplitPosList(d,e[b].data.length,c)}c=SplitTexe(c,e[b].data);PaintText(e[b],c,gTEXTBACKCOLOR)}}
function GetSplitPosList(d,e,c){for(var b=[],a=0,f=0;f<d.length/2;f++)if(d[2*f]<=c){if(!(d[2*f+1]<c))if(d[2*f+1]>c+e-1){b[b.length]=d[2*f]-c+a;b[b.length]=e-1+a;break}else{b[b.length]=a;b[b.length]=d[2*f+1]-c+a;a=a+d[2*f+1]-c+1;e=e-d[2*f+1]+c-1;if(0==e)break;c=d[2*f+1]+1}}else if(d[2*f]>c+e-1)break;else if(d[2*f+1]>=c+e-1){b[b.length]=d[2*f]-c+a;b[b.length]=e-1+a;break}else{b[b.length]=d[2*f]-c+a;b[b.length]=d[2*f+1]-c+a;a=a+d[2*f+1]-c+1;e=e-d[2*f+1]+c-1;if(0==e)break;c=d[2*f+1]+1}return b}
function SplitTexe(d,e){for(var c=[],b=0,a=0;a<d.length/2;a++){c[2*a]=d[2*a]>0?e.substring(b,d[2*a]):null;c[2*a+1]=e.substring(d[2*a],d[2*a+1]+1);b=d[2*a+1]+1}if(b<e.length){c[c.length]=e.substring(b,e.length+1);c[c.length]=null}return c}
function PaintText(d,e,c){for(var b=[],a=0;a<e.length;a+=2){b[a]=e[a]==null?null:document.createTextNode(e[a]);if(e[a+1]==null)b[a+1]=null;else{var f=document.createTextNode(e[a+1]),g=document.createElement("SPAN");g.style.background=c;g.appendChild(f);b[a+1]=g}}e=d.parentNode;e.removeChild(d);for(a=0;a<b.length;a++)b[a]!=null&&e.appendChild(b[a])}
function CompareChars(d,e){var c=[],b=[],a=[],f=0,g=0,j=d.length,h=e.length;if(j==h){for(var i=0;i<j;i++)if(d[i]==e[i]){if(i-g!=0){a[a.length]=g;a[a.length]=i-1;b[b.length]=f;b[b.length]=i-1}g=i+1;f=i+1}if(g!=j){a[a.length]=g;a[a.length]=j-1;b[b.length]=f;b[b.length]=j-1}c[0]=a;c[1]=b;return c}for(;g<j||f<h;){if(g==j){b[b.length]=f;b[b.length]=h-1;break}if(f==h){a[a.length]=g;a[a.length]=j-1;break}if(d[g]==e[f]){g++;f++}else{for(i=f+1;i<h;i++)if(d[g]==e[i]){b[b.length]=f;b[b.length]=i-1;g++;f=i+1;
break}if(i==h){for(i=g+1;i<j;i++)if(e[f]==d[i]){a[a.length]=g;a[a.length]=i-1;f++;g=i+1;break}if(i==j){a[a.length]=g;a[a.length]=g;b[b.length]=f;b[b.length]=f;g++;f++}}}}c[0]=a;c[1]=b;return c}
function CompareNodes(d,e){for(var c=-1,b=-1,a=0,f=0,g=d.length,j=e.length;f<=g||a<=j;){if(f==g){CompareText(GetNodeList(d,b+1,f-b-1),GetNodeList(e,c+1,a-c-1));for(c=a;c<j;c++)e[c]=PaintNode(e[c],gTEXTBACKCOLOR);break}if(a==j){CompareText(GetNodeList(d,b+1,f-b-1),GetNodeList(e,c+1,a-c-1));for(c=f;c<g;c++)d[c]=PaintNode(d[c],gTEXTBACKCOLOR);break}if(Equal(d[f],e[a])){if(d[f].data.length>1){CompareText(GetNodeList(d,b+1,f-b-1),GetNodeList(e,c+1,a-c-1));b=f;c=a}else if(d[f].data.length==1&&d[f].data.charCodeAt(0)>
127){b=f;c=a}f++;a++}else{var h=0;for(h=a+1;h<j;h++)if(Equal(d[f],e[h])){if(d[f].data.length>1){CompareText(GetNodeList(d,b+1,f-b-1),GetNodeList(e,c+1,h-c-1));b=f;c=h;f++;a=h+1}else{if(d[f].data.length==1&&d[f].data.charCodeAt(0)>127){b=f;c=a}a++;f++}break}if(h==j){for(h=f+1;h<g;h++)if(Equal(e[a],d[h])){if(d[h].data.length>1){CompareText(GetNodeList(d,b+1,h-b-1),GetNodeList(e,c+1,a-c-1));b=h;c=a;a++;f=h+1}else{if(d[f].data.length==1&&d[f].data.charCodeAt(0)>127){b=f;c=a}a++;f++}break}if(h==g){f++;
a++}}}}}function GetNodeList(d,e,c){for(var b=[],a=0;a<c;a++)b[a]=d[e+a];return b}function PaintNode(d,e){var c=document.createElement("SPAN");c.style.background=e;var b=d.cloneNode(true);c.appendChild(b);d.parentNode.replaceChild(c,d);return d=b}function LTrim(d){return d.replace(/^\s*/,"")}function RTrim(d){return d.replace(/\s*$/,"")}function Trim(d){return RTrim(LTrim(d))}
function GetAllTextNodes(d){var e=[];d=d.childNodes;for(var c=d.length,b=0;b<c;b++){var a=d[b],f=a.nodeType;if(3==f&&0!=Trim(a.data).length)e[e.length]=a;if(1==f)e=e.concat(GetAllTextNodes(a))}return e};
