// Cross-Browser Rich Text Editor
// http://www.kevinroth.com/rte/demo.htm
// Written by Kevin Roth (kevin@NOSPAMkevinroth.com - remove NOSPAM)

//init variables
var isRichText = false;
var rng;
var currentRTE;
var allRTEs = "";

var isIE;
var isGecko;
var isSafari;
var isKonqueror;

var imagesPath;
var includesPath;
var cssFile;
var increase=43;
var tabindex = "";
var initalized = false;

function initRTE(imgPath, incPath, css) {
	
	if(initalized){
		return ;
	}
	initalized = true;

    //set browser vars
    var ua = navigator.userAgent.toLowerCase();
    isIE = ((ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1)); 
	isGecko = (ua.indexOf("gecko") != -1);
    isSafari = (ua.indexOf("safari") != -1);
    isKonqueror = (ua.indexOf("konqueror") != -1);
    if(!isOpera) tabindex = 'tabindex="-1"';
    //check to see if designMode mode is available
  //  if (document.getElementById && document.designMode && !isSafari && !isKonqueror) {
	    if (document.getElementById && document.designMode && !isKonqueror) {
        isRichText = true;
    }
    
    if(!isIE) document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT | Event.MOUSEDOWN | Event.MOUSEUP);
    document.onmouseover = raiseButton;
    document.onmouseout  = normalButton;
    document.onmousedown = lowerButton;
    document.onmouseup   = raiseButton;
    
    //set paths vars
    imagesPath = imgPath;
    includesPath = incPath;
    cssFile = css;
    
    //for testing standard textarea, uncomment the following line
    //isRichText = false;
	if(isIE || isMozilla)increase=43;
	if(isOpera)increase=45;
	if(isSafari)increase=50;
}

//function writeRichText(rte, html, width, height, buttons, readOnly) { // old code 
	function writeRichText(rte, html, width, height, buttons, readOnly, imageFileArray,ignoreImgGal) {
		if(!ignoreImgGal)ignoreImgGal="";
	// alert(" 54 writeRichText rte == "+rte+"  html == "+html+"  width  =="+width+"  height == "+height+"  buttons =="+buttons+" readOnly == "+readOnly+"   imageFileArray length  == "+imageFileArray.length);

//    if (width == null) width = (isIE) ?375 :377;
    if (width == null) width = (isIE) ?382 :377;
    if (height == null) height = 100;
    if (buttons == null) buttons = true;
    if (readOnly == null) readOnly = false;
    if (isRichText) {
        if (allRTEs.length > 0) allRTEs += ";";
        allRTEs += rte;
	//	alert(" Before  writeRTEsss  ");
    //    writeRTE(rte, html, width, height, buttons, readOnly); // old code
        writeRTE(rte, html, width, height, buttons, readOnly, imageFileArray,ignoreImgGal); 
    } else {
        writeDefault(rte, html, width, height, buttons, readOnly);
    }
}

function writeDefault(rte, html, width, height, buttons, readOnly) {
    if (!readOnly) {
        document.writeln('<textarea name="' + rte + '" id="' + rte + '" style="width: ' + width + 'px; height: ' + height + 'px;" class="textfield">' + html + '</textarea>');
    } else {
        document.writeln('<textarea name="' + rte + '" id="' + rte + '" style="width: ' + width + 'px; height: ' + height + 'px;" readonly class="textfield">' + html + '</textarea>');
    }
}

function raiseButton(e) {

    if (isIE) {
        var el = window.event.srcElement;
		e = window.event;
    } else {
        var el= e.target;
    }
    
	if(e && e.type=='mouseover' && IsClicked(el.id)){
		if(el.className == 'btnImageLowered'){
		return;
		}
	}else if(e && e.type=='mouseup'){
		return;
	}


   if(el!=null){//guna added to avoid the script error(All Publish wizard) while moving the mouse over navigation button in select templet
    className = el.className;

    if (className == 'btnImage' || className == 'btnImageLowered') {
        el.className = 'btnImageRaised';
    }
  }
}

function normalButton(e) {
    if (isIE) {
        var el = window.event.srcElement;
		e = window.event;
    } else {
        var el= e.target;
    }
    
	if(e && e.type=='mouseout' && IsClicked(el.id)){
		if(el.className == 'btnImageLowered'){
		return;
		}
	}
    if(el!=null){ //guna added to avoid the script error(All Publish wizard) while moving the mouse over navigation button in select templet    
    className = el.className;
    if (className == 'btnImageRaised' || className == 'btnImageLowered') {
        el.className = 'btnImage';
    }
}
}

function lowerButton(e) {
    if (isIE) {
        var el = window.event.srcElement;
		e = window.event;
    } else {
        var el= e.target;
    }
    
	if(e && e.type=='mousedown' && IsClicked(el.id)){
		if(el.className == 'btnImageRaised'){
			el.className = 'btnImageLowered';
			unselect(el.id);
		}else if(el.className == 'btnImageLowered'){
			el.className = 'btnImage';
		}
	return;
	}

    className = el.className;
    if (className == 'btnImage' || className == 'btnImageRaised') {
        el.className = 'btnImageLowered';
    }
}

//function writeRTE(rte, html, width, height, buttons, readOnly) { // old functions 
function writeRTE(rte, html, width, height, buttons, readOnly, imageFileArray,ignoreImgGal) { 
	//	alert(" 127  writeRTEss  == "+rte+"  ImagePath  == "+imagesPath+"  imageFileArray size  == "+imageFileArray.length);

    if (isIE) {
        var tablewidth = width + 2;
    } else {
        var tablewidth = width + 2;
    }
    
    if (readOnly) buttons = false;
    if (buttons == true) {
        document.writeln('<table border="0" cellpadding=0 cellspacing=0 id="head" width="' + tablewidth + '">');
        document.writeln('  <tr>');
        document.writeln('      <td>');
        document.writeln('<table class="btnBack" cellpadding=2 cellspacing=0 id="Buttons1_' + rte + '" width="' + tablewidth + '">');
        document.writeln('  <tr>');
        document.writeln('      <td>');
        document.writeln('          <select id="formatblock_' + rte + '" onchange="Select(\'' + rte + '\', this.id);">');
        document.writeln('              <option value="">['+richtextVariables.Style+']</option>');
        document.writeln('              <option value="<p>">'+richtextVariables.Paragraph+'</option>');
        document.writeln('              <option value="<h1>">'+richtextVariables.Heading1+' <h1></option>');
        document.writeln('              <option value="<h2>">'+richtextVariables.Heading2+' <h2></option>');
        document.writeln('              <option value="<h3>">'+richtextVariables.Heading3+' <h3></option>');
        document.writeln('              <option value="<h4>">'+richtextVariables.Heading4+' <h4></option>');
        document.writeln('              <option value="<h5>">'+richtextVariables.Heading5+'<h5></option>');
        document.writeln('              <option value="<h6>">'+richtextVariables.Heading6+'<h6></option>');
        document.writeln('              <option value="<address>">'+richtextVariables.Address+'<ADDR></option>');
        document.writeln('              <option value="<pre>">'+richtextVariables.Formatted+' <pre></option>');
        document.writeln('          </select>');
        document.writeln('      </td>');
        document.writeln('      <td>');
        document.writeln('          <select id="fontname_' + rte + '" onchange="Select(\'' + rte + '\', this.id)">');
        document.writeln('              <option value="Font" selected>['+richtextVariables.Font+']</option>');
        document.writeln('              <option  value="Arial,Helvetica,sans-serif ">'+richtextVariables.Arial+'</option>');
        document.writeln('              <option  value="Courier New,Courier,mono">'+richtextVariables.CourierNew+'</option>');
        document.writeln('              <option  value="Times New Roman,Times,serif">'+richtextVariables.TimesNewRoman+'</option>');
        document.writeln('              <option  value="Verdana,Arial,Helvetica,sans-serif " selected>'+richtextVariables.Verdana+'</option>');
		document.writeln('              <option  value="comic sans ms,cursive">'+richtextVariables.ComicSansMS+'</option>');
		document.writeln('              <option  value="georgia,serif ">'+richtextVariables.Georgia+'</option>');
		document.writeln('              <option  value="lucida sans unicode,lucida grande,sans-serif">'+richtextVariables.LucidaSansUnicode+'</option>');
		document.writeln('              <option  value="tahoma,geneva,sans-serif ">'+richtextVariables.Tahoma+'</option>');
		document.writeln('              <option  value="trebuchet ms,helvetica,sans-serif">'+richtextVariables.TrebuchetMS+'</option>');
        document.writeln('          </select>');
        document.writeln('      </td>');
        document.writeln('      <td>');
        document.writeln('          <select unselectable="on" id="fontsize_' + rte + '" onchange="Select(\'' + rte + '\', this.id);">');
        document.writeln('              <option value="Size" selected>['+richtextVariables.Size+']</option>');
        document.writeln('              <option value="8">8</option>');
        document.writeln('              <option value="9">9</option>');
        document.writeln('              <option value="10">10</option>');
        document.writeln('              <option value="11" selected>11</option>');
        document.writeln('              <option value="12">12</option>');
        document.writeln('              <option value="13">13</option>');
        document.writeln('              <option value="14">14</option>');
        document.writeln('              <option value="15">15</option>');
        document.writeln('              <option value="16">16</option>');
        document.writeln('              <option value="17">17</option>');
        document.writeln('              <option value="18">18</option>');
        document.writeln('              <option value="19">19</option>');
        document.writeln('              <option value="20">20</option>');
        document.writeln('              <option value="22">22</option>');
        document.writeln('              <option value="24">24</option>');
        document.writeln('              <option value="26">26</option>');
        document.writeln('              <option value="28">28</option>');
        document.writeln('              <option value="36">36</option>');
        document.writeln('              <option value="48">48</option>');
        document.writeln('              <option value="72">72</option>');
        document.writeln('          </select>');
        document.writeln('      </td>');
        document.writeln('      <td width="100%">');
        document.writeln('      </td>');
        document.writeln('  </tr>');
        document.writeln('</table>');
        document.writeln('      </td>');
        document.writeln('  </tr>');
        document.writeln('  <tr>');
        document.writeln('      <td>');

        document.writeln('<table onmousedown="return false;" class="btnBack" cellpadding="0" cellspacing="0" id="Buttons2_' + rte + '" width="' + tablewidth + '">');
        document.writeln('  <tr>');
        document.writeln('      <td><img id="bold_' + rte + '" class="btnImage" src="' + imagesPath + 'bold.gif" alt="Bold" title="'+richtextVariables.Bold+'" onClick="FormatText(\'' + rte + '\', \'bold\', \'\')"></td>');
        document.writeln('      <td><img id="italic_' + rte + '" class="btnImage" src="' + imagesPath + 'italic.gif" alt="Italic" title="'+richtextVariables.Italic+'" onClick="FormatText(\'' + rte + '\', \'italic\', \'\')"></td>');
        document.writeln('      <td><img id="underline_' + rte + '" class="btnImage" src="' + imagesPath + 'underline.gif" alt="Underline" title="'+richtextVariables.Underline+'" onClick="FormatText(\'' + rte + '\', \'underline\', \'\')"></td>');
      //  document.writeln('      <td><span class="vertSep"></span></td>');
        document.writeln('      <td><img id="left_' + rte + '" class="btnImage" src="' + imagesPath + 'left_just.gif" alt="Align Left" title="'+richtextVariables.AlignLeft+'" onClick="FormatText(\'' + rte + '\', \'justifyleft\', \'\')"></td>');
        document.writeln('      <td><img id="center_' + rte + '" class="btnImage" src="' + imagesPath + 'centre.gif" alt="Center" title="'+richtextVariables.Center+'" onClick="FormatText(\'' + rte + '\', \'justifycenter\', \'\')"></td>');
        document.writeln('      <td><img id="right_' + rte + '" class="btnImage" src="' + imagesPath + 'right_just.gif" alt="Align Right" title="'+richtextVariables.AlignRight+'" onClick="FormatText(\'' + rte + '\', \'justifyright\', \'\')"></td>');
        if (false) document.writeln('      <td><img class="btnImage" src="' + imagesPath + 'justifyfull.gif" alt="Justify Full" title="'+richtextVariables.JustifyFull+'" onclick="FormatText(\'' + rte + '\', \'justifyfull\', \'\')"></td>');
        //document.writeln('      <td><span class="vertSep"></span></td>');
        document.writeln('      <td><img class="btnImage" src="' + imagesPath + 'hr.gif" alt="Horizontal Rule" title="'+richtextVariables.HorizontalRule+'" onClick="FormatText(\'' + rte + '\', \'inserthorizontalrule\', \'\')"></td>');
        //document.writeln('      <td><span class="vertSep"></span></td>');
        document.writeln('      <td><img id="ordered_' + rte + '" class="btnImage" src="' + imagesPath + 'numbered_list.gif" alt="Ordered List" title="'+richtextVariables.OrderedList+'" onClick="FormatText(\'' + rte + '\', \'insertorderedlist\', \'\')"></td>');
        document.writeln('      <td><img id="unordered_' + rte + '" class="btnImage" src="' + imagesPath + 'list.gif" alt="Unordered List" title="'+richtextVariables.UnorderedList+'" onClick="FormatText(\'' + rte + '\', \'insertunorderedlist\', \'\')"></td>');
        //document.writeln('      <td><span class="vertSep"></span></td>');
        document.writeln('      <td><img class="btnImage" src="' + imagesPath + 'outdent.gif" alt="Outdent" title="'+richtextVariables.Outdent+'" onClick="FormatText(\'' + rte + '\', \'outdent\', \'\')"></td>');
        document.writeln('      <td><img class="btnImage" src="' + imagesPath + 'indent.gif" alt="Indent" title="'+richtextVariables.Indent+'" onClick="FormatText(\'' + rte + '\', \'indent\', \'\')"></td>');
        document.writeln('      <td><div id="forecolor_' + rte + '"><img class="btnImage" src="' + imagesPath + 'textcolor.gif" alt="Text Color" title="'+richtextVariables.TextColor+'" onClick="FormatText(\'' + rte + '\', \'forecolor\', \'\')"></div></td>');
        document.writeln('      <td><div id="hilitecolor_' + rte + '"><img class="btnImage" src="' + imagesPath + 'bgcolor.gif" alt="Background Color" title="'+richtextVariables.BackgroundColor+'" onClick="FormatText(\'' + rte + '\', \'hilitecolor\', \'\')"></div></td>');
    //    document.writeln('      <td><span class="vertSep"></span></td>');
        document.writeln('      <td><img class="btnImage" src="' + imagesPath + 'hyperlink.gif" alt="Insert Link" title="'+richtextVariables.InsertLink+'" onClick="FormatText(\'' + rte + '\', \'createlink\')"></td>');
       // document.writeln('      <td><img class="btnImage" src="' + imagesPath + 'image.gif" alt="Add Image" title="'+richtextVariables.AddImage+'" onClick="AddImage(\'' + rte + '\')"></td>');

		// ------- palani  this below part is deals image gallary process  --------
//		document.writeln(' 	<td> <a name="ImageGallery" href= " " target="self" rel="lightbox" Class="galary_imagesized" value=" " >');
//		document.writeln(' <img class="btnImage" src="' + imagesPath + 'imageGallery.gif" title="Image Gallery"></a></td>');

	//	if((imageFileArray != 'null') && (imageFileArray != null) && (imageFileArray !=""))
		if((imageFileArray != 'null') && (imageFileArray != null))
		{
			if(imageFileArray.length > 0)
			{
				for(i=0; i<imageFileArray.length; i++)
				{
					if(i==0){
						document.writeln(' 	<td> <a '+tabindex+' name="ImageGallery'+ignoreImgGal+'" rel="lightbox" href= '+imageFileArray[i]+'>');
						document.writeln(' <img onClick="initLightbox();setEditorName('+"'"+rte+"'"+')" class="btnImage" src="' + imagesPath + 'image.gif" title="'+richtextVariables.ImageGallery+'"></a></td>');
					    document.writeln(' <input type="hidden" id="frameName_RTE" name="frameName_RTE" value="'+rte+'">');
					} else {				
					document.writeln('	<a '+tabindex+' name="ImageGallery'+ignoreImgGal+'" href= '+imageFileArray[i]+'> </a>'); 
					}
				}
			} else{
				document.writeln(' 	<td> <img class="btnImage" src="' + imagesPath + 'image.gif" title="'+richtextVariables.ImageGallery+'" onClick="NoImagesFoundMessage()"></td>');
			}
		}else {
		
			document.writeln('      <td><img class="btnImage" src="' + imagesPath + 'image.gif" alt="Add Image" title="'+richtextVariables.AddImage+'" onClick="AddImage(\'' + rte + '\')"></td>');
		}
        if (isIE) document.writeln('        <td><img class="btnImage" src="' + imagesPath + 'spellcheck.gif" alt="Spell Check" title="'+richtextVariables.SpellCheck+'" onClick="checkspell()"></td>');
    //  document.writeln('      <td><span class="vertSep"></span></td>');
      document.writeln('      <td><img class="btnImage" src="' + imagesPath + 'cleanup.gif" alt="cleanupMStag" title="'+richtextVariables.RemoveFormating+'" onClick="cleanUp(\'' + rte + '\')"></td>');
      //document.writeln('      <td><img class="btnImage" src="' + imagesPath + 'copy.gif" alt="Copy" title="Copy" onClick="FormatText(\'' + rte + '\', \'copy\')"></td>');
      //document.writeln('      <td><img class="btnImage" src="' + imagesPath + 'paste.gif" alt="Paste" title="Paste" onClick="FormatText(\'' + rte + '\', \'paste\')"></td>');
     // document.writeln('      <td><span class="vertSep"></span></td>');
     // document.writeln('      <td><img class="btnImage" src="' + imagesPath + 'undo.gif" alt="Undo" title="Undo" onClick="FormatText(\'' + rte + '\', \'undo\')"></td>');
      //document.writeln('      <td><img class="btnImage" src="' + imagesPath + 'redo.gif" alt="Redo" title="Redo" onClick="FormatText(\'' + rte + '\', \'redo\')"></td>');
        document.writeln('      <td width="100%"></td>');
        document.writeln('  </tr>');
        document.writeln('</table>');
        document.writeln('      </td>');
        document.writeln('  </tr>');
        document.writeln('  <tr>');
        document.writeln('      <td>');

    }
    document.writeln('<iframe id="' + rte + '" name="' + rte + '" width="' + width + 'px" height="' + height + 'px" src="/dummy.jsp" style="border: 1px solid #006699"></iframe>');
    document.write('<textarea readonly="true" name="HtmlCode' + rte + '" id="HtmlCode' + rte + '" style="display:none; width:' + (width+2) + 'px; height:' + (height+increase) + 'px; border: 1px solid #006699; background-color:#FFFFFF; font-family:courier new; font-size:12px; color:#000000;"></textarea>'); 
	document.writeln('<table class="btnBackHole" onmousedown="return false;" border="0"  cellpadding="0" cellspacing="0" id="Buttons_Buttom' + rte + '" width="' + tablewidth + '">');
    document.writeln('  <tr>');
    document.writeln('      <td width="10"><img class="btnImage" src="' + imagesPath + 'designButton.gif" alt="Design Mode" title="'+richtextVariables.DesignMode+'" onClick="ShowView(\'' + rte + '\',\'' + readOnly + '\', \'designview\')"></td>');
    document.writeln('      <td width="10"><img class="btnImage" src="' + imagesPath + 'codeButton.gif" alt="HTML Code" title="'+richtextVariables.HTMLCode+'" onClick="ShowView(\'' + rte + '\',\'' + readOnly + '\', \'htmlview\')"></td>');
    document.writeln('      <td width="*" align="right"><img   id="handleCorner' + rte + '" style=cursor:Move src="' + imagesPath + 'Drag.gif" alt="drag" title="'+richtextVariables.Drag+'"></td>');
        document.writeln('  </tr>');
        document.writeln('</table>');

    if (false && !readOnly) document.writeln('<br /><input type="checkbox" id="chkSrc' + rte + '" onclick="toggleHTMLSrc(\'' + rte + '\');" />&nbsp;View Source');
    document.writeln('<iframe width="254" height="174" id="cp' + rte + '" src="' + includesPath + 'palette.htm" marginwidth="0" marginheight="0" scrolling="no" style="visibility:hidden; display: none; position: absolute;"></iframe>');

        document.writeln('      </td>');
        document.writeln('  </tr>');
        document.writeln('</table>');

    document.writeln('<input type="hidden" id="hdn' + rte + '" name="' + rte + '" value="">');
    document.getElementById('hdn' + rte).value = html;
	new dragObject('handleCorner' + rte , null, new PositionDrag(382, 105), new PositionDrag(5000, 5000), null, CornerMove, null, false);
    enableDesignMode(rte, html, readOnly);
	new ChangeStyle(rte);

}


function IsClicked(name){
  var names = new Array();
	names[0] = "bold_";
	names[1] = "italic_";
	names[2] = "underline_";
	names[3] = "left_";
	names[4] = "center_";
	names[5] = "right_";
	names[6] = "ordered_";
	names[7] = "unordered_";

	for(var i=0;i<names.length;i++){
		if(name.indexOf(names[i]) != -1){
			return true;		
		}
	}

return false;
}

function unselect(name){

	var switchName = name.slice(0,name.indexOf("_"));
	var rte = name.slice(name.indexOf("_")+1,name.length);
	if(switchName && switchName != ""){
		switch (switchName) {
			case 'left':
					//document.getElementById("left_"+rte).className = 'btnImageLowered';
					document.getElementById("right_"+rte).className = 'btnImage';
					document.getElementById("center_"+rte).className = 'btnImage';
					break;
			case 'right':
					document.getElementById("left_"+rte).className = 'btnImage';
					//document.getElementById("right_"+rte).className = 'btnImageLowered';
					document.getElementById("center_"+rte).className = 'btnImage';
					break;
			case 'center':
					document.getElementById("left_"+rte).className = 'btnImage';
					document.getElementById("right_"+rte).className = 'btnImage';
				//	document.getElementById("center_"+rte).className = 'btnImageLowered';
					break;
			case 'ordered':
					document.getElementById("ordered_"+rte).className = 'btnImageLowered';
					document.getElementById("unordered_"+rte).className = 'btnImage';
					break;
			case 'unordered':
					document.getElementById("unordered_"+rte).className = 'btnImageLowered';
					document.getElementById("ordered_"+rte).className = 'btnImage';
					break;
			}
	}
}

function getDoc(rte) {
	var value = false;
	try {
		if ( document.getElementById(rte).contentWindow.document) {
			value =  document.getElementById(rte).contentWindow.document;
			return value;
		}
	} catch (e) {
		return false;
	}

}

function getSize(size){
	
	var _size = "11";

	if(size == null || size == "" || isNaN(size)) return _size;

	return size;
}

function getfStyle(fontStyle){
  var contain = false;
  var fstyle = new Array();
	fstyle[0] = "Arial,Helvetica,sans-serif ";
	fstyle[1] = "Courier New,Courier,mono";
	fstyle[2] = "Times New Roman,Times,serif";
	fstyle[3] = "Verdana,Arial,Helvetica,sans-serif ";
	fstyle[4] = "comic sans ms,cursive";
	fstyle[5] = "georgia,serif ";
	fstyle[6] = "lucida sans unicode,lucida grande,sans-serif";
	fstyle[7] = "tahoma,geneva,sans-serif ";
	fstyle[8] = "trebuchet ms,helvetica,sans-serif";


	for(var t=0;t<fstyle.length;t++){
		if(fstyle[t] == fontStyle){
			contain=true;
		}else if(fstyle[t].toLowerCase().search(fontStyle.toLowerCase()) != -1){
			contain=true;
		}

		if(contain) return fstyle[t];
	}

	return null;
}

function getWindow(rte) {
		return  document.getElementById(rte).contentWindow;
	}

	function isElement(el, tag) {
		if (el && el.tagName && (el.tagName.toLowerCase() == tag)) {
			return true;
		}
		if (el && el.getAttribute && (el.getAttribute('tag') == tag)) {
			return true;
		}
		return false;
	}

function getDomPath(rte, el) {
		if (!el) {
			el = getSelectedElement(rte);
		}
		var domPath = [];
		while (el !== null) {
			if (el.ownerDocument != getDoc(rte)) {
				el = null;
				break;
			}
			//Check to see if we get el.nodeName and nodeType
			if (el.nodeName && el.nodeType && (el.nodeType == 1)) {
				domPath[domPath.length] = el;
			}

			if (isElement(el, 'body')) {
				break;
			}

			el = el.parentNode;
		}
		if (domPath.length === 0) {
			if (getDoc(rte) && getDoc(rte).body) {
				domPath[0] = getDoc(rte).body;
			}
		}
		return domPath.reverse();
	}

function getSelection(rte) {
	var sel = null;
	var selection = null
	if (getDoc(rte) && getWindow(rte)) {
		if (getDoc(rte).selection) {
			sel = getDoc(rte).selection;
		} else {
			sel = getWindow(rte).getSelection();
		}
		//Handle Safari's lack of Selection Object
		if (isSafari) {//isSafari && webkitVersion<420
			if (sel.baseNode) {
					selection = {};
					selection.baseNode = sel.baseNode;
					selection.baseOffset = sel.baseOffset;
					selection.extentNode = sel.extentNode;
					selection.extentOffset = sel.extentOffset;
			} else if (selection !== null) {
				sel = getWindow(rte).getSelection();
				sel.setBaseAndExtent(
					selection.baseNode,
					selection.baseOffset,
					selection.extentNode,
					selection.extentOffset);
				selection = null;
			}
		}
	}
	return sel;
}

function getRange(rte) {
		var sel = getSelection(rte);

		if (sel === null) {
			return null;
		}

		if (isSafari && !sel.getRangeAt) {
			var range = getDoc(rte).createRange();
			try {
				range.setStart(sel.anchorNode, sel.anchorOffset);
				range.setEnd(sel.focusNode, sel.focusOffset);
			} catch (e) {
				range = getWindow(rte).getSelection(rte)+'';
			}
			return range;
		}

		if (isIE || isOpera) {
			try {
				return sel.createRange();
			} catch (e2) {
				return null;
			}
		}

		if (sel.rangeCount > 0) {
			return sel.getRangeAt(0);
		}
		return null;
	}

 function getSelectedElement(rte) {
	var doc = getDoc(rte),
		range = null,
		sel = null,
		elm = null,
		check = true,
		currentEvent = null;
	if (isIE) {
		currentEvent = getWindow(rte).event; 
		range = getRange(rte);
		if (range) {
			elm = range.item ? range.item(0) : range.parentElement();
			/*if (this._hasSelection()) {
				//TODO
				//WTF.. Why can't I get an element reference here?!??!
			}*/
		/*	if (elm === doc.body) {
				elm = null;
			}*/
		}
		if ((currentEvent !== null) && (currentEvent.keyCode === 0)) {
				var n = currentEvent.target || currentEvent.srcElement;
				try {
					if (n && 3 == n.nodeType) {
						elm =  n.parentNode;
					}
				} catch(e) { }
		}
	} else {
		sel = getSelection(rte);
		range = getRange(rte);

		if (!sel || !range) {
			return null;
		}
		//TODO
		/*if (!this._hasSelection() && this.browser.webkit3) {
			//check = false;
		}*/
		if (isGecko) {
			//Added in 2.6.0
			if (range.startContainer) {
				if (range.startContainer.nodeType === 3) {
					elm = range.startContainer.parentNode;
				} else if (range.startContainer.nodeType === 1) {
					elm = range.startContainer;
				}
				//Added in 2.7.0
				if (currentEvent) {
					var tar = null
				var n = currentEvent.target || currentEvent.srcElement;
				try {
					if (n && 3 == n.nodeType) {
						tar =  n.parentNode;
					}
				} catch(e) { }
					//var tar = Event.getTarget(this.currentEvent);
					if (!isElement(tar, 'html')) {
						if (elm !== tar) {
							elm = tar;
						}
					}
				}
			}
		}

		if (check) {
			if (sel.anchorNode && (sel.anchorNode.nodeType == 3)) {
				if (sel.anchorNode.parentNode) { //next check parentNode
					elm = sel.anchorNode.parentNode;
				}
				if (sel.anchorNode.nextSibling != sel.focusNode.nextSibling) {
					elm = sel.anchorNode.nextSibling;
				}
			}
			if (isElement(elm, 'br')) {
				elm = null;
			}
			if (!elm) {
				elm = range.commonAncestorContainer;
				if (!range.collapsed) {
					if (range.startContainer == range.endContainer) {
						if (range.startOffset - range.endOffset < 2) {
							if (range.startContainer.hasChildNodes()) {
								elm = range.startContainer.childNodes[range.startOffset];
							}
						}
					}
				}
			}
	   }
	}

	if (currentEvent !== null) {
		try {
			switch (currentEvent.type) {
				case 'click':
				case 'mousedown':
				case 'mouseup':
					if (this.browser.webkit) {
//						elm = Event.getTarget(this.currentEvent);
						var n = currentEvent.target || currentEvent.srcElement;
						try {
							if (n && 3 == n.nodeType) {
								elm =  n.parentNode;
							}
						} catch(e) { }
					}
					break;
				default:
					//Do nothing
					break;
			}
		} catch (e) {
		}
	} /*else if ((this.currentElement && this.currentElement[0]) && (!this.browser.ie)) {
		//TODO is this still needed?
		//elm = this.currentElement[0];
	}*/


	if (isOpera || isSafari) {
		currentEvent = getWindow(rte).event; 

		if (currentEvent && !elm) {
			//elm = YAHOO.util.Event.getTarget(this.currentEvent);
			var n = currentEvent.target || currentEvent.srcElement;

			elm =  n;
			try {
				if (n && 3 == n.nodeType) {
					elm =  n.parentNode;
				}
			} catch(e) { }
		}
	}
	if (!elm || !elm.tagName) {
		elm = doc.body;
	}
	if (isElement(elm, 'html')) {
		//Safari sometimes gives us the HTML node back..
		elm = doc.body;
	}
	if (isElement(elm, 'body')) {
		//make sure that body means this body not the parent..
		elm = doc.body;
	}
	if (elm && !elm.parentNode) { //Not in document
		elm = doc.body;
	}
	if (elm === undefined) {
		elm = null;
	}
	return elm;
}

function ChangeStyle(rte){
	
	var rt = document.getElementById(rte).contentWindow
	hookEvent(rt.document, "mouseup", getContent);
	if(isSafari){ hookEvent(rt.document, "keyup", getContent);}
	else { hookEvent(rt.document, "keydown", getContent);}



	function getContent(e){
		
		/*var intialdata = null;
		if (document.all) {
			intialdata = frames[rte].document.body.innerHTML;
		} else {
			intialdata = document.getElementById(rte).contentWindow.document.body.innerHTML;
		}		
	
		if(initalClick && (intialdata==null ||trim(intialdata) =="")){
			if(isOpera){
				document.getElementById(rte).contentWindow.document.body.innerHTML = '<FONT face="Verdana,Arial,Helvetica,sans-serif">&nbsp;</FONT>'
			}else{
				Select(rte,"fontname_"+rte);
			}
			if(isIE) e= frames[rte].window.event;
			if(e.type=='keyup')
			initalClick = false;
			return;
			}
		*/

		var rang= getRange(rte);
		var elm = getSelectedElement(rte);
		var path = getDomPath(rte);

		var tag = null, cmd = null;
		var size=null;
		var style=null;
		var heading=null;
		var bold=false, italic=false, underline=false;
		var ordered=false, unordered=false;
		var align='non';
		var defaultInt=false;
		var defaultInt1=false;
		var charCode = (e.which) ? e.which : getWindow(rte).event.keyCode
		if(charCode == 17) return;
		if(path.length == 1) defaultInt = true;		
		if(path.length > 1) defaultInt1 = true;

		for (var i = 1; i < path.length; i++) {
				tag = path[i].tagName.toLowerCase();

				var fontface = path[i].face;
				//alert(fontface)
				var fontsize = path[i].size;
				//Have any HEADING tag?
				if(heading == null){
				//	alert(path[i].attributes.length)
					heading = getHeader(tag,rte);
					}

				var aAttr = path[i].attributes;
				//alert(aAttr.length)
				for (var j = 0; j < aAttr.length; j++) {
					
					var attName = aAttr[j].name;
						if(attName != null) attName = attName.toLowerCase();

					//Have any Font Style ?
					if(attName != null && attName == 'style'){
					  if(path[i].style.fontFamily)
						  style = path[i].style.fontFamily;
					  if(path[i].style.fontSize)
						  size = path[i].style.fontSize;
					 //Have any Font Style?
					}else if(attName != null && attName == 'size'){
					  size = aAttr[j].value
					}

					 //Find the selected content Have any of the following (BOLD, ITALIC, UNDERLINE)
					if (path[i].style.fontWeight.toLowerCase() == 'bold' || tag=='strong') {
						bold = true;
					}
					if (path[i].style.fontStyle.toLowerCase() == 'italic' || tag=='em') {
						italic = true;
					}
					if (path[i].style.textDecoration.toLowerCase() == 'underline' || tag=='u') {
						underline = true;
					}	
					
					var alignSwitch = path[i].style.textAlign.toLowerCase();
					if((tag=='p' || tag=='div') && attName != null && attName == 'align'){
						alignSwitch = aAttr[j].value;
					} 

//					alert("alignSwitch:"+tag +"==>"+attName)
					// Find for any ALIGNMENT it have?
					switch (alignSwitch) {
						case 'left':
								align = alignSwitch;
								break;
						case 'right':
								align = alignSwitch;
								break;
						case 'center':
								align = alignSwitch;
								break;
						}							

				}
				
				if((tag=='strong' || tag=='b') && !bold) bold= true;
				if((tag=='i' || tag=='em') && !italic) italic= true;
				if(tag=='u' && !underline) underline= true;
				
				// Find it have any LIST attribute?
				if (tag == 'ol') {
				  ordered = true;
				}else if(tag == 'ul'){
				  unordered = true;
				}

				//if(fontface != null && fontface !="" && (style==null || style=="")){
				if(fontface != null && fontface !=""){
					style = fontface;
				} 

				//if(fontsize != null && fontsize !="" && (size==null || size=="")){
				if(fontsize != null && fontsize !=""){
					//alert("fontsize :"+fontsize+" size"+size);
					size = fontsize;
				} 

			}


		if(bold){
			document.getElementById("bold_"+rte).className = 'btnImageLowered';
		}else{
			document.getElementById("bold_"+rte).className = 'btnImage';
		}

		if(italic){
            document.getElementById("italic_"+rte).className = 'btnImageLowered';
		}else{
            document.getElementById("italic_"+rte).className = 'btnImage';
		}

		if(underline){
            document.getElementById("underline_"+rte).className = 'btnImageLowered';
		}else{
			document.getElementById("underline_"+rte).className = 'btnImage';
		}

		if (align=='non') {
			document.getElementById("left_"+rte).className = 'btnImage';
			document.getElementById("right_"+rte).className = 'btnImage';
			document.getElementById("center_"+rte).className = 'btnImage';
		}else if (align=='left') {
			document.getElementById("left_"+rte).className = 'btnImageLowered';
			document.getElementById("right_"+rte).className = 'btnImage';
			document.getElementById("center_"+rte).className = 'btnImage';
		}else if(align=='right'){
			document.getElementById("left_"+rte).className = 'btnImage';
			document.getElementById("right_"+rte).className = 'btnImageLowered';
			document.getElementById("center_"+rte).className = 'btnImage';
		}else if(align=='center'){
			document.getElementById("left_"+rte).className = 'btnImage';
			document.getElementById("right_"+rte).className = 'btnImage';
			document.getElementById("center_"+rte).className = 'btnImageLowered';
		}

		if (ordered) {
				document.getElementById("ordered_"+rte).className = 'btnImageLowered';
				document.getElementById("unordered_"+rte).className = 'btnImage';
		}else if(unordered){
				document.getElementById("ordered_"+rte).className = 'btnImage';
				document.getElementById("unordered_"+rte).className = 'btnImageLowered';
		}else{
				document.getElementById("ordered_"+rte).className = 'btnImage';
				document.getElementById("unordered_"+rte).className = 'btnImage';				
		}

		 if(heading != null){	 
			document.getElementById("formatblock_"+rte).value=heading;
		 }else{
			document.getElementById("formatblock_"+rte).value="";
			 }

		 if(size != null && size != ""){	 
			 while(size.search('"')!=-1){
					size = size.replace('"', '')
				}
			 while(size.search('px')!=-1){
					size = size.replace('px', '')
				}
			defaultInt1=false;
			document.getElementById("fontsize_"+rte).value=getSize(size);
		 }else{
			 document.getElementById("fontsize_"+rte).value="11";
			 }



		 if(style != null && style != ""){			 
			
			 while(style.search("'")!=-1){
					style = style.replace("'", '')
				}

			 while(style.search(', ')!=-1){
					style = style.replace(', ', ',')
				}

			 style = getfStyle(style);
			 if(style == null) style="Verdana,Arial,Helvetica,sans-serif ";
			defaultInt1 = false;
			document.getElementById("fontname_"+rte).value =style;
		 }else{
			 document.getElementById("fontname_"+rte).value ="Verdana,Arial,Helvetica,sans-serif "
		 }
	

			 if(defaultInt || defaultInt1){
				document.getElementById("fontname_"+rte).value="Verdana,Arial,Helvetica,sans-serif ";
				document.getElementById("fontsize_"+rte).value="11";
			}	

			if(charCode == 65 && e.ctrlKey){
				document.getElementById("fontname_"+rte).value="Font";
				document.getElementById("fontsize_"+rte).value="Size";
			}			

	}
	
}

function getHeader(content, rte){
	//alert(content)
		if(!(content && trim(content)!="")) return null;
		content = content.toLowerCase();
		if(content=="p"||content=="address"||content=="pre"||content=="h1"
		||content=="h2"||content=="h3"||content=="h4"||content=="h5"||content=="h6"){
			//alert("HEADING SET AS :"+content);
			//document.getElementById("formatblock_"+rte).value="<"+content+">";
			return "<"+content+">";
		}else{
			return null;
		//document.getElementById("formatblock_"+rte).value="";
		}
} 

// Resizable RichText Editor implemented with the reference of http://blog.paranoidferret.com/index.php/2007/10/02/javascript-tutorial-resizeable-textboxes/
// ********************* Code for Drag Editor Starts ************

function CornerMove(newPos, element)
{
  DoHeight(newPos.Y, element);
  DoWidth(newPos.X, element);
}
function DoHeight(y, element)
{
  if(element != null)
    element.style.top = y + 'px';
  	document.getElementById((element.id).substr(12)).style.height = (y - 5) + 'px';
	document.getElementById("HtmlCode"+(element.id).substr(12)).style.height = ((y - 5)+increase) + 'px';
}

function DoWidth(x, element)
{ 
  if(element != null)
    element.style.left = x + 'px';
	document.getElementById((element.id).substr(12)).style.width = (x - 5) + 'px';
	document.getElementById("HtmlCode"+(element.id).substr(12)).style.width = (x - 5) + 'px';
	document.getElementById("Buttons1_"+(element.id).substr(12)).width = (x - 3) + 'px';
	document.getElementById("Buttons2_"+(element.id).substr(12)).width = (x - 3) + 'px';
	document.getElementById("Buttons_Buttom"+(element.id).substr(12)).width = (x - 3) + 'px';
}
function PositionDrag(x, y)
{
  this.X = x;
  this.Y = y;
  
  this.Add = function(val)
  {
    var newPos = new PositionDrag(this.X, this.Y);
    if(val != null)
    {
      if(!isNaN(val.X))
        newPos.X += val.X;
      if(!isNaN(val.Y))
        newPos.Y += val.Y
    }
    return newPos;
  }
  
  this.Subtract = function(val)
  {
    var newPos = new PositionDrag(this.X, this.Y);
    if(val != null)
    {
      if(!isNaN(val.X))
        newPos.X -= val.X;
      if(!isNaN(val.Y))
        newPos.Y -= val.Y
    }
    return newPos;
  }
  
  this.Min = function(val)
  {
    var newPos = new PositionDrag(this.X, this.Y)
    if(val == null)
      return newPos;
    
    if(!isNaN(val.X) && this.X > val.X)
      newPos.X = val.X;
    if(!isNaN(val.Y) && this.Y > val.Y)
      newPos.Y = val.Y;
    
    return newPos;  
  }
  
  this.Max = function(val)
  {
    var newPos = new PositionDrag(this.X, this.Y)
    if(val == null)
      return newPos;
    
    if(!isNaN(val.X) && this.X < val.X)
      newPos.X = val.X;
    if(!isNaN(val.Y) && this.Y < val.Y)
      newPos.Y = val.Y;
    
    return newPos;  
  }  
  
  this.Bound = function(lower, upper)
  {
    var newPos = this.Max(lower);
    return newPos;
  }
  
  this.Check = function()
  {
    var newPos = new PositionDrag(this.X, this.Y);
    if(isNaN(newPos.X))
      newPos.X = 0;
    if(isNaN(newPos.Y))
      newPos.Y = 0;
    return newPos;
  }
  
  this.Apply = function(element)
  {
    if(typeof(element) == "string")
      element = document.getElementById(element);
    if(element == null)
      return;
    if(!isNaN(this.X))
      element.style.left = this.X + 'px';
    if(!isNaN(this.Y))
      element.style.top = this.Y + 'px';  
  }
}

function hookEvent(element, eventName, callback)
{
  if(typeof(element) == "string")
    element = document.getElementById(element);
  if(element == null)
    return;
  if(element.addEventListener)
  {
    element.addEventListener(eventName, callback, false);
  }
  else if(element.attachEvent)
    element.attachEvent("on" + eventName, callback);
}

function unhookEvent(element, eventName, callback)
{
  if(typeof(element) == "string")
    element = document.getElementById(element);
  if(element == null)
    return;
  if(element.removeEventListener)
    element.removeEventListener(eventName, callback, false);
  else if(element.detachEvent)
    element.detachEvent("on" + eventName, callback);
}

function cancelEvent(e)
{
  e = e ? e : window.event;
  if(e.stopPropagation)
    e.stopPropagation();
  if(e.preventDefault)
    e.preventDefault();
  e.cancelBubble = true;
  e.cancel = true;
  e.returnValue = false;
  return false;
}

function absoluteCursorPostion(eventObj)
{
  eventObj = eventObj ? eventObj : window.event;
  if(isNaN(window.scrollX))
    return new PositionDrag(eventObj.clientX + document.documentElement.scrollLeft + document.body.scrollLeft, 
      eventObj.clientY + document.documentElement.scrollTop + document.body.scrollTop);
  else
    return new PositionDrag(eventObj.clientX + window.scrollX, eventObj.clientY + window.scrollY);
}
       //dragObject(handleCorner, null, new PositionDrag(382, 105), new PositionDrag(5000, 5000), null, CornerMove, null, false);
function dragObject(element, attachElement, lowerBound, upperBound, startCallback, moveCallback, endCallback, attachLater)
{
  if(typeof(element) == "string")
  element = document.getElementById(element);
  if(element == null)
      return;
  
  if(lowerBound != null && upperBound != null)
  {
    var temp = lowerBound.Min(upperBound);
    upperBound = lowerBound.Max(upperBound);
    lowerBound = temp;
  }

  var cursorStartPos = null;
  var elementStartPos = null;
  var dragging = false;
  var listening = false;
  var disposed = false;
  var flaging = false;
  function dragStart(eventObj)
  { 
    if(dragging || !listening || disposed) return;
    dragging = true;
    
    if(startCallback != null)
      startCallback(eventObj, element);
    cursorStartPos = absoluteCursorPostion(eventObj);
    if(element.style.left == "" && element.style.top == ""){
		elementStartPos = new PositionDrag(parseInt('382px'), parseInt('102px'));
		}
	else{
		elementStartPos = new PositionDrag(parseInt(element.style.left), parseInt(element.style.top));
		}
    elementStartPos = elementStartPos.Check();
    
    hookEvent(document, "mousemove", dragGo);
    hookEvent(document, "mouseup", dragStopHook);
	hookEvent(document.getElementById((element.id).substr(12)).contentWindow.document, "mouseup", dragStopHook);
  // document.getElementById((element.id).substr(12)).contentWindow.document.addEventListener("mouseup", dragStopHook, true)
    
    return cancelEvent(eventObj);
  }
  
  function dragGo(eventObj)
  {

    if(!dragging || disposed) return;
    
    var newPos = absoluteCursorPostion(eventObj);
    newPos = newPos.Add(elementStartPos).Subtract(cursorStartPos);
    newPos = newPos.Bound(lowerBound, upperBound)
    newPos.Apply(element);
    if(moveCallback != null)
      moveCallback(newPos, element);
        
    return cancelEvent(eventObj); 
  }
  
  function dragStopHook(eventObj)
  {
    dragStop();
    return cancelEvent(eventObj);
  }
  
  function dragStop()
  {
    if(!dragging || disposed) return;
    unhookEvent(document, "mousemove", dragGo);
    unhookEvent(document, "mouseup", dragStopHook);
    cursorStartPos = null;
    elementStartPos = null;
    if(endCallback != null)
      endCallback(element);
    dragging = false;
  }
  
  this.Dispose = function()
  {
    if(disposed) return;
    this.StopListening(true);
    element = null;
    attachElement = null
    lowerBound = null;
    upperBound = null;
    startCallback = null;
    moveCallback = null
    endCallback = null;
    disposed = true;
  }
  
  this.StartListening = function()
  {
    if(listening || disposed) return;
    listening = true;
    hookEvent(attachElement, "mousedown", dragStart);
  }
  
  this.StopListening = function(stopCurrentDragging)
  {
    if(!listening || disposed) return;
    unhookEvent(attachElement, "mousedown", dragStart);
    listening = false;
    
    if(stopCurrentDragging && dragging)
      dragStop();
  }
  
  this.IsDragging = function(){ return dragging; }
  this.IsListening = function() { return listening; }
  this.IsDisposed = function() { return disposed; }
  
  if(typeof(attachElement) == "string")
    attachElement = document.getElementById(attachElement);
  if(attachElement == null)
    attachElement = element;
    
  if(!attachLater)
    this.StartListening();
}

//********************* Code for Drag Editor End ***************
function ShowView(rte, readOnly, option) {
	if (option == "designview") {
	 //if(!(isSafari && webkitVersion<420))
	   //document.getElementById(rte).contentWindow.document.body.innerHTML =trim(document.getElementById("HtmlCode"+rte).value);
	   document.getElementById(rte).style.display = ""; 
	 if((isSafari && webkitVersion<420)){
		 enableDesignMode(rte, trim(document.getElementById("HtmlCode"+rte).value), readOnly)
			 }
       document.getElementById('Buttons1_'+rte).style.display = ""; 
       document.getElementById('Buttons2_'+rte).style.display = ""; 
       document.getElementById("HtmlCode"+rte).style.display = "none"; 
	}else if(option== "htmlview"){
	  document.getElementById("HtmlCode"+rte).value =trim(document.getElementById(rte).contentWindow.document.body.innerHTML); 
	  document.getElementById("HtmlCode"+rte).style.display = ""; 
	  document.getElementById('Buttons1_'+rte).style.display = "none"; 
	  document.getElementById('Buttons2_'+rte).style.display = "none"; 
	  document.getElementById(rte).style.display = "none"; 
	  if(isIE)document.getElementById("HtmlCode"+rte).focus();
	}
}


function enableDesignMode(rte, html, readOnly) {
//alert("RTE : "+rte+"HTML : "+html+"ReadOnly : "+readOnly);

    var frameHtml = "<html id=\"" + rte + "\">";
    frameHtml += "<head>";
    //to reference your stylesheet, set href property below to your stylesheet path and uncomment
    if (cssFile.length > 0) {
        frameHtml += "<link media=\"all\" type=\"text/css\" href=\"" + cssFile + "\" rel=\"stylesheet\">";
    }
    frameHtml += "<style>";
    frameHtml += "body {";
    frameHtml += "  background: #F7F3F7;";
    frameHtml += "  margin: 0px;";
    frameHtml += "  padding: 0px;";
    frameHtml += "  border: 0px;";
    frameHtml += "}";
    frameHtml += "</style>";
    frameHtml += "</head>";
    frameHtml += "<body class='runningtxt_normal_blk'>";
    frameHtml += html;
    frameHtml += "</body>";
    frameHtml += "</html>";
    
    if (document.all || isSafari) {
		try{
		var i=0;
        var oRTE = frames[rte].document;
        oRTE.open();
        oRTE.write(frameHtml);
        oRTE.close();
        if (!readOnly) oRTE.designMode = "On";
		}catch(e){
			if(isSafari && i<10){
				i++;
		        setTimeout("enableDesignMode('" + rte + "', '" + html + "', " + readOnly + ");", 500);		
				}
			return false;
		}
    } else {
        try {
            if (!readOnly) document.getElementById(rte).contentDocument.designMode = "on";
            try {
                var oRTE = document.getElementById(rte).contentWindow.document;
                oRTE.open();
                oRTE.write(frameHtml);
                oRTE.close();
                if (isGecko && !readOnly) {
                    //attach a keyboard handler for gecko browsers to make keyboard shortcuts work
                    oRTE.addEventListener("keypress", kb_handler, true);
                }
            } catch (e) {
                alert("Error preloading content.");
            }
        } catch (e) {
            //gecko may take some time to enable design mode.
            //Keep looping until able to set.
            if (isGecko) {
                setTimeout("enableDesignMode('" + rte + "', '" + html + "', " + readOnly + ");", 10);
            } else {
                return false;
            }
        }
    }
}

function cleanUp(rte){  //clean up crud inserted by Micro$oft Orifice
 try{
		var formatData;
	 if (document.all) {
		formatData = frames[rte].document.body.innerHTML;
		} else {
		formatData = document.getElementById(rte).contentWindow.document.body.innerHTML;
		}
	// h=h.replace(/<\/?(SPAN|DEL|INS|U|DIR)[^>]*>/gi, "").replace(/\b(CLASS|STYLE)=\"[^\"]*\"/gi, "").replace(/\b(CLASS|STYLE)=\w+/gi, "");
	 formatData=formatData.replace(/<\/?(DEL|INS|DIR)[^>]*>/gi, "").replace(/\b(d)=\"[^\"]*\"/gi, "").replace(/\b(d)=\w+/gi, "");
	  //if(!o('fontname'+idTa) || !o('fontsize'+idTa)) h=h.replace(/<\?FONT[^>]*>/gi, "");
	// h=h.replace(/<\/?(FONT|SPAN|COL|XML|ST1|SHAPE|V:|O:|F:|F |PATH|LOCK|IMAGEDATA|STROKE|FORMULAS)[^>]*>/gi, "")
	 formatData=formatData.replace(/<\/?(COL|XML|ST1|SHAPE|V:|O:|F:|F |PATH|LOCK|IMAGEDATA|STROKE|FORMULAS)[^>]*>/gi, "")
	 .replace(/\bCLASS=\"?MSO\w*\"?/gi, "")
	 .replace(/[–]/g,'-') //long –
	 .replace(/[‘’]/g, "'") //single smartquotes ‘’ 
	 .replace(/[“”]/g, '"') //double smartquotes “”
	 .replace(/align="?justify"?/gi, "") //justify sends some browsers mad
	 .replace(/<(TABLE|TD|TH|COL)(.*)(WIDTH|HEIGHT)=["'0-9A-Z]*/gi, "<$1$2") //no fixed size tables (%OK) [^A-Za-z>]
	 .replace(/<([^>]+)>\s*<\/\1>/gi, ""); //empty tag
	 document.getElementById(rte).contentWindow.document.body.innerHTML=formatData;
 }catch(e){ }
	 alert(richtextVariables.Microsoftremovedtag);

}

function updateRTEs() {
//alert("All RTEs :              "+allRTEs);
    var vRTEs = allRTEs.split(";");
       for (var i = 0; i < vRTEs.length; i++) {
        updateRTE(vRTEs[i]);
    }
}

function updateRTE(rte) {
    if (!isRichText) return;
    
    //set message value
    var oHdnMessage = document.getElementById('hdn' + rte);
    var oRTE = document.getElementById(rte);
    var readOnly = false;
    
    //check for readOnly mode
    if (document.all) {
        if (frames[rte].document.designMode != "On") readOnly = true;
    } else {
        if (document.getElementById(rte).contentDocument != null && document.getElementById(rte).contentDocument.designMode != "on") readOnly = true;
    }
    
    if (isRichText && !readOnly) {
        //if viewing source, switch back to design view
        /*
        if (document.getElementById("chkSrc" + rte).checked) {
            document.getElementById("chkSrc" + rte).checked = false;
            toggleHTMLSrc(rte);
        }
        */
        if (oHdnMessage.value == null) oHdnMessage.value = "";
        if (document.all) {
            oHdnMessage.value = frames[rte].document.body.innerHTML;
        } else if(oRTE.contentWindow != null){
            oHdnMessage.value = oRTE.contentWindow.document.body.innerHTML;
        }
        //if there is no content (other than formatting) set value to nothing
        if (stripHTML(oHdnMessage.value.replace("&nbsp;", " ")) == "" 
            && oHdnMessage.value.toLowerCase().search("<hr") == -1
            && oHdnMessage.value.toLowerCase().search("<img") == -1) oHdnMessage.value = "";
        //fix for gecko
        if (escape(oHdnMessage.value) == "%3Cbr%3E%0D%0A%0D%0A%0D%0A") oHdnMessage.value = "";

		var ss=escape(oHdnMessage.value);
		while(ss.indexOf('%A0')!=-1){  // senthilm 
			ss=ss.replace('%A0','%26nbsp%3B');
		}
		oHdnMessage.value=unescape(ss);

    }
}

function toggleHTMLSrc(rte) {
    //contributed by Bob Hutzel (thanks Bob!)
    var oRTE;
    if (document.all) {
        oRTE = frames[rte].document;
    } else {
        oRTE = document.getElementById(rte).contentWindow.document;
    }
    
    if (document.getElementById("chkSrc" + rte).checked) {
        document.getElementById("Buttons1_" + rte).style.visibility = "hidden";
        document.getElementById("Buttons2_" + rte).style.visibility = "hidden";
        if (document.all) {
            oRTE.body.innerText = oRTE.body.innerHTML;
        } else {
            var htmlSrc = oRTE.createTextNode(oRTE.body.innerHTML);
            oRTE.body.innerHTML = "";
            oRTE.body.appendChild(htmlSrc);
        }
    } else {
        document.getElementById("Buttons1_" + rte).style.visibility = "visible";
        document.getElementById("Buttons2_" + rte).style.visibility = "visible";
        if (document.all) {
            //fix for IE
            var output = escape(oRTE.body.innerText);
            output = output.replace("%3CP%3E%0D%0A%3CHR%3E", "%3CHR%3E");
            output = output.replace("%3CHR%3E%0D%0A%3C/P%3E", "%3CHR%3E");
            
            oRTE.body.innerHTML = unescape(output);
        } else {
            var htmlSrc = oRTE.body.ownerDocument.createRange();
            htmlSrc.selectNodeContents(oRTE.body);
            oRTE.body.innerHTML = htmlSrc.toString();
        }
    }
}

//Function to format text in the text box
function FormatText(rte, command, option) {
    var oRTE;
    if (document.all) {
        oRTE = frames[rte];
        
        //get current selected range
        var selection = oRTE.document.selection; 
        if (selection != null) {
            rng = selection.createRange();
        }
    } else {
        oRTE = document.getElementById(rte).contentWindow;
        
        //get currently selected range
        var selection = oRTE.getSelection();
		if (selection != null && !isSafari) {
        rng = selection.getRangeAt(selection.rangeCount - 1).cloneRange();
		}
	}
    
    try {
        if ((command == "forecolor") || (command == "hilitecolor")) {
            //save current values
            parent.command = command;
            currentRTE = rte;
            
            //position and show color palette
            buttonElement = document.getElementById(command + '_' + rte);
            document.getElementById('cp' + rte).style.left = getOffsetLeft(buttonElement) + "px";
            document.getElementById('cp' + rte).style.top = (getOffsetTop(buttonElement) + buttonElement.offsetHeight) + "px";
            if (document.getElementById('cp' + rte).style.visibility == "hidden") {
                document.getElementById('cp' + rte).style.visibility = "visible";
                document.getElementById('cp' + rte).style.display = "inline";
            } else {
                document.getElementById('cp' + rte).style.visibility = "hidden";
                document.getElementById('cp' + rte).style.display = "none";
            }
        } else if (command == "createlink") {
            var szURL = prompt(richtextVariables.EnterUrl, "");
            try {
                //ignore error for blank urls
                oRTE.document.execCommand("Unlink", false, null);
                oRTE.document.execCommand("CreateLink", false, szURL);
            } catch (e) {
                //do nothing
            }
        } else {
            oRTE.focus();
            oRTE.document.execCommand(command, false, option);
            oRTE.focus();
        }
    } catch (e) {
        alert(e);
    }
}

//Function to set color
function setColor(color) {
    var rte = currentRTE;
    var oRTE;
    if (document.all) {
        oRTE = frames[rte];
    } else {
        oRTE = document.getElementById(rte).contentWindow;
    }
    
    var parentCommand = parent.command;
    if (document.all || isSafari) {
        //retrieve selected range
        var sel = oRTE.document.selection; 
		var ua = navigator.userAgent.toLowerCase();
        if (parentCommand == "hilitecolor" && ua.indexOf("opera")==-1) parentCommand = "backcolor";
        if (sel != null) {
            var newRng = sel.createRange();
            newRng = rng;
            newRng.select();
        }
    }
    oRTE.focus();
    oRTE.document.execCommand(parentCommand, false, color);
    oRTE.focus();
    document.getElementById('cp' + rte).style.visibility = "hidden";
    document.getElementById('cp' + rte).style.display = "none";
}

//Function to add image
function AddImage(rte) {
    var oRTE;
    if (document.all) {
        oRTE = frames[rte];
        
        //get current selected range
        var selection = oRTE.document.selection; 
        if (selection != null) {
            rng = selection.createRange();
        }
    } else {
        oRTE = document.getElementById(rte).contentWindow;
        
        //get currently selected range
        var selection = oRTE.getSelection();
        rng = selection.getRangeAt(selection.rangeCount - 1).cloneRange();
    }
    
    imagePath = prompt(richtextVariables.EnterImageUrl, 'http://');              
    if ((imagePath != null) && (imagePath != "")) {
        oRTE.focus();
        oRTE.document.execCommand('InsertImage', false, imagePath);
        oRTE.focus();
    }
}

/*function upLoadsImageToRichTextWindow(rte, imagePaths){
//	alert("upLoadsImageToRichTextWindow   through New Survey -- >>>>>>>>>>>>>> : "+imagePaths);
	var imagePath = imagePaths;
	alert("  New  image Path  === "+imagePath);*/
/*
	frames[0].focus();
//	frames[0].document.execCommand('InsertImage',false, imagePaths);
	frames[0].document.execCommand('InsertImage',false, imagePath);
	frames[0].focus();
*/
	/*var oRTE;
    if (document.all) {
        oRTE = frames[rte];     
        } else {
        oRTE = document.getElementById(rte).contentWindow;
	}
   if ((imagePath != null) && (imagePath != "")) {
	//	alert(" 2 Executes    == 44 "+ oRTE.document.execCommand('InsertImage', false, imagePath));
		alert("  Framesh Execute  == 66 "+frames[0].document.execCommand('InsertImage',false, imagePath));
		oRTE.focus();
		oRTE.document.execCommand('InsertImage', false, imagePath);
		oRTE.focus();
   }
}*/

function NoImagesFoundMessage()
{
	alert(richtextVariables.noImageFoundMessage);
}
function LoadsImage(ctl, frameNames){
	var newsrc =ctl.substring(ctl.indexOf('/graphics'),ctl.length);
	//if(isIE){

		frames[frameNames.name].focus();
		frames[frameNames.name].document.execCommand('InsertImage', false, newsrc);
		frames[frameNames.name].focus();
	/*
		frames['introductionText'].focus();
		frames['introductionText'].document.execCommand('InsertImage', false, ctl);
		frames['introductionText'].focus();
	*/
/*	}
	else{
			frames[0].focus();
			frames[0].document.execCommand('InsertImage', false, newsrc);
			frames[0].focus();
	}
*/
	
/*
	alert(document.getElementById('introductionText').document.execCommand('InsertImage',false, '/graphics/IMAGE_GALARY/1060'));
	//document.getElementById('hiddenIntroductionText').innerHTML="aa";

	document.getElementById('introductionText').focus();
	document.getElementById('introductionText').document.execCommand('InsertImage',false, '/graphics/IMAGE_GALARY/1060');
	document.getElementById('introductionText').focus();
*/
}


//function to perform spell check
function checkspell() {
    try {
        var tmpis = new ActiveXObject("ieSpell.ieSpellExtension");
        tmpis.CheckAllLinkedDocuments(document);
    }
    catch(exception) {
        if(exception.number==-2146827859) {
            if (confirm(richtextVariables.Spellcheckalert))
                window.open("http://www.iespell.com/download.php","DownLoad");
        } else {
            alert("Error Loading ieSpell: Exception " + exception.number);
        }
    }
}

function getOffsetTop(elm) {
    var mOffsetTop = elm.offsetTop;
    var mOffsetParent = elm.offsetParent;
    
    while(mOffsetParent){
        mOffsetTop += mOffsetParent.offsetTop;
        mOffsetParent = mOffsetParent.offsetParent;
    }
    
    return mOffsetTop;
}

function getOffsetLeft(elm) {
    var mOffsetLeft = elm.offsetLeft;
    var mOffsetParent = elm.offsetParent;
    
    while(mOffsetParent) {
        mOffsetLeft += mOffsetParent.offsetLeft;
        mOffsetParent = mOffsetParent.offsetParent;
    }
    
    return mOffsetLeft;
}

function hasSelection(rte) {
	var sel = getSelection(rte);
	var range = getRange(rte);
	var hasSel = false;

	if (!sel || !range) {
		return hasSel;
	}

	//Internet Explorer
	if (isIE || isOpera) {
		if (range.text) {
			hasSel = true;
		}
		if (range.html) {
			hasSel = true;
		}
	} else {
		if (isSafari) {
			if (sel+'' !== '') {
				hasSel = true;
			}
		} else {
			if (sel && (sel.toString() !== '') && (sel !== undefined)) {
				hasSel = true;
			}
		}
	}
	return hasSel;
}

function setEditorStyle(stat) {
	try {
		this._getDoc().execCommand('useCSS', false, !stat);
	} catch (ex) {
	}
}

function dosized(rte, selected){
	if(hasSelection(rte)){
		var el = getSelectedElement(rte);
		createCurrentElement(rte, 'span', {'fontSize': selected});
	}
}

function createCurrentElement(rte, tagName, tagStyle){
  var tar = null,
	el = [],
	doc = getDoc(rte);
	
	var currentElement = [];

	var elCreate = function(el, tagStyle) {
			var tagName = el.tagName.toLowerCase();
				if(tagName == 'sub'){
					el = doc.createElement('span')
				}
				
				for (var k in tagStyle) {
					//if (YAHOO.lang.hasOwnProperty(tagStyle, k)) {
						el.style[k] = tagStyle[k];
					//}
				}

				//alert("Inside : "+el.style.verticalAlign)
				if(el.style && el.style.verticalAlign =='sub'){
					el.style.verticalAlign = '';
					}


		return el;
	};

	setEditorStyle(true);
	getDoc(rte).execCommand('Subscript', false, null);

	var _tmp = [], __tmp, __els = ['sub', 'span'];

	/*if (!isElement(getSelectedElement(rte), 'body')) {
		__els[__els.length] = getDoc(rte).getElementsByTagName(getSelectedElement(rte).tagName);
		__els[__els.length] = getDoc(rte).getElementsByTagName(getSelectedElement(rte).parentNode.tagName);
	}*/

	for (var _els = 0; _els < __els.length; _els++) {
		var _tmp1 = getDoc(rte).getElementsByTagName(__els[_els]);
		for (var e = 0; e < _tmp1.length; e++) {
			_tmp[_tmp.length] = _tmp1[e];
		}
	}

    for (var i = 0; i < _tmp.length; i++) {

      //  if ((YAHOO.util.Dom.getStyle(_tmp[i], 'font-family') == 'fms-tmp') || (_tmp[i].face && (_tmp[i].face == 'fms-tmp'))) {
//		  alert("HI"+_tmp[i].style.verticalAlign)
//     var alignStyle = YAHOO.util.Dom.getStyle(_tmp[i], 'vertical-align')
 	 var alignStyle = _tmp[i].style.verticalAlign
	 var tagName = _tmp[i].tagName.toLowerCase();

	  if ((alignStyle && alignStyle == 'sub') || tagName == 'sub') {
          el = elCreate(_tmp[i], tagStyle);	

		  var emptysize = _tmp[i].getElementsByTagName('span');
			for (var v = 0; v < emptysize.length; v++) {
				   if(emptysize[v].style)
						emptysize[v].style.fontSize=el.style.fontSize;
				}

		  var emptyfont = _tmp[i].getElementsByTagName('font');
			for (var b = 0; b < emptyfont.length; b++) {
					if(emptyfont[b].style)
						emptyfont[b].style.fontSize=el.style.fontSize;
				}

          el.innerHTML = _tmp[i].innerHTML;

		if (_tmp[i].parentNode) {
			_tmp[i].parentNode.replaceChild(el, _tmp[i]);
			currentElement[currentElement.length] = el;
			currentEvent = null;
			//if (YAHOO.env.ua.webkit) {
				if(isSafari){
				//Force Safari to focus the new element
				getSelection(rte).setBaseAndExtent(el, 0, el, 0);
				if (isSafari && webkitVersion>=420) {
					getSelection(rte).collapseToStart();
				} else {
					getSelection(rte).collapse(true);
				}
			}
			if (isIE && tagStyle && tagStyle.fontSize) {
				getSelection(rte).empty();
			}
			if (isGecko) {
				getSelection(rte).collapseToStart();
			}
		}
}
	}

		var len = currentElement.length;
		for (var o = 0; o < len; o++) {
			if ((o + 1) != len) { //Skip the last one in the list
				if (currentElement[o] && currentElement[o].nextSibling) {
					if (isElement(currentElement[o], 'br')) {
						currentElement[currentElement.length] = currentElement[o].nextSibling;
					}
				}
			}
		}

	selectNode(rte, currentElement);
}

function selectNode(rte, nodeCol, collapse) {
	var node = nodeCol[0]
	if (!node) {
		return false;
	}
	var sel = getSelection(rte),
		range = null;

	if (isIE) {
		try { //IE freaks out here sometimes..
			range = getDoc(rte).body.createTextRange();
			range.moveToElementText(node);
			range.select();
		} catch (e) {
		}
	} else if (isSafari) {
		if (collapse) {
			sel.setBaseAndExtent(nodeCol[0], 1, nodeCol[nodeCol.length-1], nodeCol[nodeCol.length-1].innerText.length);
		} else {
			sel.setBaseAndExtent(nodeCol[0], 0, nodeCol[nodeCol.length-1], nodeCol[nodeCol.length-1].innerText.length);
		}
	} else if (isOpera) {
		sel = getWindow(rte).getSelection();
		range = getDoc(rte).createRange();
		range.selectNode(node);
		sel.removeAllRanges();
		sel.addRange(range);
	} else {
		for(var x=0;x<nodeCol.length;x++){
			range = getDoc(rte).createRange();
			range.selectNodeContents(nodeCol[x]);
			sel.addRange(range);
		}
		//sel.removeAllRanges();
	}
	//TODO - Check Performance
	//this.nodeChange();
}


function Select(rte, selectname) {
    var oRTE;
    if (document.all) {
        oRTE = frames[rte];
        
        //get current selected range
        var selection = oRTE.document.selection; 
        if (selection != null) {
            rng = selection.createRange();
        }
    } else {
        oRTE = document.getElementById(rte).contentWindow;
        
        //get currently selected range
        var selection = oRTE.getSelection();
        rng = selection.getRangeAt(selection.rangeCount - 1).cloneRange();
    }
    
    var idx = document.getElementById(selectname).selectedIndex;
    // First one is always a label
    if (idx != 0) {
        var selected = document.getElementById(selectname).options[idx].value;
        var cmd = selectname.replace('_' + rte, '');
        oRTE.focus();
	//	alert(cmd)
		if(cmd=='fontsize'){
			dosized(rte, selected+'px');
		}else{
			oRTE.document.execCommand(cmd, false, selected);
		}
        oRTE.focus();
        //document.getElementById(selectname).selectedIndex = 0;
    }
}

function kb_handler(evt) {
    var rte = evt.target.id;
  //  alert(rte)
		var cc=document.getElementById(rte).contentWindow.document.body.innerHTML;
    //contributed by Anti Veeranna (thanks Anti!)
    if (evt.ctrlKey) {
        var key = String.fromCharCode(evt.charCode).toLowerCase();
        var cmd = '';
        switch (key) {
            case 'b': cmd = "bold"; break;
            case 'i': cmd = "italic"; break;
            case 'u': cmd = "underline"; break;
        };

        if (cmd) {
            FormatText(rte, cmd, true);
            //evt.target.ownerDocument.execCommand(cmd, false, true);
            // stop the event bubble
            evt.preventDefault();
            evt.stopPropagation();
        }
    }
}

function docChanged (evt) {
    alert('changed');
}

function stripHTML(oldString) {
    var newString = oldString.replace(/(<([^>]+)>)/ig,"");
    
    //replace carriage returns and line feeds
   newString = newString.replace(/\r\n/g," ");
   newString = newString.replace(/\n/g," ");
   newString = newString.replace(/\r/g," ");
    
    //trim string
    newString = trim(newString);
    
    return newString;
}

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") return inputString;
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
    
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
    
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
    
    // Note that there are two spaces in the string - look for multiple spaces within the string
   while (retValue.indexOf("  ") != -1) {
        // Again, there are two spaces in each of the strings
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length);
   }
   return retValue; // Return the trimmed string back to the user
}

//senthilm Start
function addDescriptionForToDo(imageFileArray,holderId,counter,width,height,buttons,readOnly,htmlValue,indication)
{
	var ID="description[" + counter + "].descriptionText";
	var IDAll="descriptionAll_"+counter;
	
	if(!htmlValue) htmlValue = "";
	if (width == null) width = (isIE) ?375 :377;
    if (height == null) height = 100;
    if (buttons == null) buttons = true;
    if (readOnly == null) readOnly = false;
	if(isIE || isMozilla)increase=45;
	if(isOpera)increase=45;
	if(isSafari)increase=50;

	if (isIE) {
        var tablewidth = width + 2;
    } else {
        var tablewidth = width + 2;
    }
    
		var newId = 'description_'+counter;
        str = "";
        comps="";
        
    if (allRTEs.length > 0) {allRTEs += ";"; }
        allRTEs += ID;

       	str += "  <input type='hidden' name='description["+counter+"].displayOrder'  value=''>";

		// str += " <textarea   name='description["+ID+"].descriptionText' rows=\"6\" cols=\"59\"  Class=\"input_field\" ></textarea> ";
		comps+='<table border=0  cellpadding=0 cellspacing=0 id="Outer_' + ID + '" width="' + tablewidth + '">';
        comps+='  <tr>';
        comps+='      <td>';

		comps+='<table class="btnBack" cellpadding=2 cellspacing=0 id="Buttons1_' + ID + '" width="' + tablewidth + '">';
        comps+='  <tr>';
        comps+='      <td>';
        comps+='          <select id="formatblock_' + ID + '" onchange="Select(\'' + ID + '\', this.id);">';
        comps+='              <option value="">['+richtextVariables.Style+']</option>';
        comps+='              <option value="<p>">'+richtextVariables.Paragraph+'</option>';
        comps+='              <option value="<h1>">'+richtextVariables.Heading1+'<h1></option>';
        comps+='              <option value="<h2>">'+richtextVariables.Heading2 +'<h2></option>';
        comps+='              <option value="<h3>">'+richtextVariables.Heading3+' <h3></option>';
        comps+='              <option value="<h4>">'+richtextVariables.Heading4 +'<h4></option>';
        comps+='              <option value="<h5>">'+richtextVariables.Heading5 +'<h5></option>';
        comps+='              <option value="<h6>">'+richtextVariables.Heading6 +'<h6></option>';
        comps+='              <option value="<address>">'+richtextVariables.Address +'<ADDR></option>';
        comps+='              <option value="<pre>">'+richtextVariables.Formatted+' <pre></option>';
        comps+='          </select>';
        comps+='      </td>';
        comps+='      <td>';
        comps+='          <select id="fontname_' + ID + '" onchange="Select(\'' + ID + '\', this.id)">';
        comps+='              <option value="Font" selected>['+richtextVariables.Font+']</option>';
        comps+='              <option value="Arial,Helvetica,sans-serif ">'+richtextVariables.Arial+'</option>';
        comps+='              <option value="Courier New,Courier,mono">'+richtextVariables.CourierNew+'</option>';
        comps+='              <option value="Times New Roman,Times,serif">'+richtextVariables.TimesNewRoman+'</option>';
        comps+='              <option value="Verdana,Arial,Helvetica,sans-serif " selected>'+richtextVariables.Verdana+'</option>';
		comps+='              <option  value="comic sans ms,cursive">'+richtextVariables.ComicSansMS+'</option>';
		comps+='              <option  value="georgia,serif ">'+richtextVariables.Georgia+'</option>';
		comps+='              <option  value="lucida sans unicode,lucida grande,sans-serif">'+richtextVariables.LucidaSansUnicode+'</option>';
		comps+='              <option  value="tahoma,geneva,sans-serif ">'+richtextVariables.Tahoma+'</option>';
		comps+='              <option  value="trebuchet ms,helvetica,sans-serif">'+richtextVariables.TrebuchetMS+'</option>';
        comps+='          </select>';
        comps+='      </td>';
        comps+='      <td>';
        comps+='          <select unselectable="on" id="fontsize_' + ID + '" onchange="Select(\'' + ID + '\', this.id);">';
        comps+='              <option value="Size">['+richtextVariables.Size+']</option>';
        comps+='              <option value="8">8</option>';
        comps+='              <option value="9">9</option>';
        comps+='              <option value="10">10</option>';
        comps+='              <option value="11" selected>11</option>';
        comps+='              <option value="12">12</option>';
        comps+='              <option value="13">13</option>';
        comps+='              <option value="14">14</option>';
        comps+='              <option value="15">15</option>';
        comps+='              <option value="16">16</option>';
        comps+='              <option value="17">17</option>';
        comps+='              <option value="18">18</option>';
        comps+='              <option value="19">19</option>';
        comps+='              <option value="20">20</option>';
        comps+='              <option value="22">22</option>';
        comps+='              <option value="24">24</option>';
        comps+='              <option value="26">26</option>';
        comps+='              <option value="28">28</option>';
        comps+='              <option value="36">36</option>';
        comps+='              <option value="48">48</option>';
        comps+='              <option value="72">72</option>';
        comps+='          </select>';
        comps+='      </td>';
        comps+='      <td width="100%">';
        comps+='      </td>';
        comps+='  </tr>';
        comps+='</table>';
        comps+='<table class="btnBack"  onmousedown="return false;" cellpadding="0" cellspacing="0" id="Buttons2_' + ID + '" width="' + tablewidth + '">';
        comps+='  <tr>';
        comps+='      <td><img id="bold_' + ID + '" class="btnImage" src="' + imagesPath + 'bold.gif" alt="Bold" title="'+richtextVariables.Bold+'" onClick="FormatText(\'' + ID + '\', \'bold\', \'\')"></td>';
        comps+='      <td><img id="italic_' + ID + '" class="btnImage" src="' + imagesPath + 'italic.gif" alt="Italic" title="'+richtextVariables.Italic+'" onClick="FormatText(\'' + ID + '\', \'italic\', \'\')"></td>';
        comps+='      <td><img id="underline_' + ID + '" class="btnImage" src="' + imagesPath + 'underline.gif" alt="Underline" title="'+richtextVariables.Underline+'" onClick="FormatText(\'' + ID + '\', \'underline\', \'\')"></td>';
        comps+='      <td><span class="vertSep"></span></td>';
        comps+='      <td><img id="left_' + ID + '" class="btnImage" src="' + imagesPath + 'left_just.gif" alt="Align Left" title="'+richtextVariables.AlignLeft+'" onClick="FormatText(\'' + ID + '\', \'justifyleft\', \'\')"></td>';
        comps+='      <td><img id="center_' + ID + '" class="btnImage" src="' + imagesPath + 'centre.gif" alt="Center" title="'+richtextVariables.Center+'" onClick="FormatText(\'' + ID + '\', \'justifycenter\', \'\')"></td>';
        comps+='      <td><img id="right_' + ID + '" class="btnImage" src="' + imagesPath + 'right_just.gif" alt="Align Right" title="'+richtextVariables.AlignRight+'" onClick="FormatText(\'' + ID + '\', \'justifyright\', \'\')"></td>';
        if (false) comps+='      <td><img class="btnImage" src="' + imagesPath + 'justifyfull.gif" alt="Justify Full" title="'+richtextVariables.JustifyFull+'" onclick="FormatText(\'' + ID + '\', \'justifyfull\', \'\')"></td>';
      //  comps+='      <td><span class="vertSep"></span></td>';
        comps+='      <td><img class="btnImage" src="' + imagesPath + 'hr.gif" alt="Horizontal Rule" title="'+richtextVariables.HorizontalRule+'" onClick="FormatText(\'' + ID + '\', \'inserthorizontalrule\', \'\')"></td>';
      //  comps+='      <td><span class="vertSep"></span></td>';
        comps+='      <td><img id="ordered_' + ID + '" class="btnImage" src="' + imagesPath + 'numbered_list.gif" alt="Ordered List" title="'+richtextVariables.OrderedList+'" onClick="FormatText(\'' + ID + '\', \'insertorderedlist\', \'\')"></td>';
        comps+='      <td><img id="unordered_' + ID + '" class="btnImage" src="' + imagesPath + 'list.gif" alt="Unordered List" title="'+richtextVariables.UnorderedList+'" onClick="FormatText(\'' + ID + '\', \'insertunorderedlist\', \'\')"></td>';
       // comps+='      <td><span class="vertSep"></span></td>';
        comps+='      <td><img class="btnImage" src="' + imagesPath + 'outdent.gif" alt="Outdent" title="'+richtextVariables.Outdent+'" onClick="FormatText(\'' + ID + '\', \'outdent\', \'\')"></td>';
        comps+='      <td><img class="btnImage" src="' + imagesPath + 'indent.gif" alt="Indent" title="'+richtextVariables.Indent+'" onClick="FormatText(\'' + ID + '\', \'indent\', \'\')"></td>';
        comps+='      <td><div id="forecolor_' + ID + '"><img class="btnImage" src="' + imagesPath + 'textcolor.gif" alt="Text Color" title="'+richtextVariables.TextColor+'" onClick="FormatText(\'' + ID + '\', \'forecolor\', \'\')"></div></td>';
        comps+='      <td><div id="hilitecolor_' + ID + '"><img class="btnImage" src="' + imagesPath + 'bgcolor.gif" alt="Background Color" title="'+richtextVariables.BackgroundColor+'" onClick="FormatText(\'' + ID + '\', \'hilitecolor\', \'\')"></div></td>';
        comps+='      <td><span class="vertSep"></span></td>';
        comps+='      <td><img class="btnImage" src="' + imagesPath + 'hyperlink.gif" alt="Insert Link" title="'+richtextVariables.InsertLink+'" onClick="FormatText(\'' + ID + '\', \'createlink\')"></td>';
        //comps+='      <td><img class="btnImage" src="' + imagesPath + 'image.gif" alt="Add Image" title="'+richtextVariables.AddImage+'" onClick="AddImage(\'' + ID + '\')"></td>';

		if((imageFileArray != 'null') && (imageFileArray != null))
				{
					if(imageFileArray.length > 0)
					{
						for(var i=0; i<imageFileArray.length; i++)
						{
							if(i==0){
								comps+=' 	<td> <a '+tabindex+' name="ImageGallery'+ID+'" href= '+imageFileArray[i]+' target="self" rel="lightbox" Class="galary_imagesized" value="'+imageFileArray[i]+'" >';
								comps+=' <img onClick="initLightbox();setEditorName('+"'"+ID+"'"+')" class="btnImage" src="' + imagesPath + 'image.gif" title="'+richtextVariables.ImageGallery+'"></a></td>';
								comps+=' <input type="hidden" id="frameName_RTE" name="frameName_RTE" value="'+ID+'">';
							} else {				
							comps+='	<a '+tabindex+' name="ImageGallery'+ID+'" href= '+imageFileArray[i]+' target="self" rel="lightbox" Class="galary_imagesized" title="'+richtextVariables.ImageGallery+'" value="'+imageFileArray[i]+'" > </a>'; 
							}
						}
					} else{
						comps+=' 	<td> <img class="btnImage" src="' + imagesPath + 'image.gif" title="'+richtextVariables.ImageGallery+'" onClick="NoImagesFoundMessage()"></td>';
					}
				}else {
				
					comps+='      <td><img class="btnImage" src="' + imagesPath + 'image.gif" alt="Add Image" title="'+richtextVariables.AddImage+'" onClick="AddImage(\'' + ID + '\')"></td>';
				}
		if(isIE)comps+='        <td><img class="btnImage" src="' + imagesPath + 'spellcheck.gif" alt="Spell Check" title="'+richtextVariables.SpellCheck+'" onClick="checkspell()"></td>';
		comps+='      <td><img class="btnImage" src="' + imagesPath + 'cleanup.gif" alt="cleanupMStag" title="'+richtextVariables.RemoveFormating+'" onClick="cleanUp(\'' + ID + '\')"></td>';

		comps+='      <td width="100%"></td>';
        comps+='  </tr>';
        comps+='</table>';

		comps+='<table  onmousedown="return false;" border="0"  cellpadding="0" cellspacing="0" id="Buttons_Buttom" width="100%">';
        comps+='  <tr>';
		comps+='  <td width="1">';
		comps+='<iframe id="' + ID + '" name="' + ID + '" width="' + width + 'px" height="' + height + 'px" src="/dummy.jsp" style="border: 1px solid #006699"></iframe>';
        comps+='<textarea readonly="true" name="HtmlCode' + ID + '" id="HtmlCode' + ID + '" style="display:none; width:' + (width+2) + 'px; height:' + (height+increase) + 'px; border: 1px solid #006699; background-color:#FFFFFF; font-family:courier new; font-size:12px; color:#000000;"></textarea>'; 
		comps+='<table  onmousedown="return false;" border="0"  cellpadding="0" cellspacing="0" id="Buttons_Buttom" width="100%">';
        comps+='  </td>';
		comps+='  </tr>';
		comps+='  <tr>';
        comps+='  <td width="1">';

		comps+='<table class="btnBackHole" onmousedown="return false;" border="0"  cellpadding="0" cellspacing="0" id="Buttons_Buttom' + ID + '" width="' + tablewidth + '">';
        comps+='  <tr>';
	    comps+='      <td width="10"><img class="btnImage" src="' + imagesPath + 'designButton.gif" alt="Design Mode" title="'+richtextVariables.DesignMode+'" onClick="ShowView(\'' + ID + '\',\'' + readOnly + '\', \'designview\')"></td>';
		comps+='      <td width="10"><img class="btnImage" src="' + imagesPath + 'codeButton.gif" alt="HTML Code" title="'+richtextVariables.HTMLCode+'" onClick="ShowView(\'' + ID + '\',\'' + readOnly + '\', \'htmlview\')"></td>';
		comps+='      <td width="*" align="right"><img   id="handleCorner' + ID + '" style=cursor:Move src="' + imagesPath + 'Drag.gif" alt="drag" title="'+richtextVariables.Drag+'"></td>';
        comps+='  </tr>';
        comps+='</table>';
        comps+='  </td>';
        comps+='  </tr>';
        comps+='</table>';
        comps+='  </td>';
        comps+='  </tr>';
        comps+='</table>';
        comps+='  </td>';
		comps+='  <td width="1" valign="bottom">';

		comps+='<table  onmousedown="return false;" border="0"  cellpadding="0" cellspacing="0" id="Buttons_Buttom" width="100%">';
        comps+='  <tr>';
        comps+='  <td width="1"><img src="' + imagesPath + 'white_spacer.gif" width="12" height="1"></td>';
        comps+='  <td width="1">';

		    if (false && !readOnly) comps+='<br /><input type="checkbox" id="chkSrc' + ID + '" onclick="toggleHTMLSrc(\'' + ID + '\');" />&nbsp;View Source';
			comps+='<iframe width="254" height="174" id="cp' + ID + '" src="' + includesPath + 'palette.htm" marginwidth="0" marginheight="0" scrolling="no" style="visibility:hidden; display: none; position: absolute;"></iframe>';
			comps+='<input type="hidden" id="hdn' + ID + '" name="' + ID + '" value="">';
        
        str+=comps;
       // str += "  &nbsp; &nbsp;";
        str += "  <a href='javascript: removeElement1(\"" + ID + "\",\"" + IDAll + "\")' tabindex='1'>";
        str += "    <img src='images/delete.gif' border='0' align='absmiddle'>";
        str += "  </a>";
        str+='  </td>';   
		//str += "  &nbsp;";
		        str+='  <td width="1"><img src="' + imagesPath + 'white_spacer.gif" width="12" height="1"></td>';

        str+='  <td>';
		if(indication!=null && indication=='CreateTDO')
        str += "  <a href='javascript: moveUpElement(\"" + holderId + "\")' tabindex='1'>";
		else
        str += "  <a href='javascript: moveUpElement(\"" + IDAll + "\")' tabindex='1'>";

        str += "    <img src='images/up.gif' border='0' align='absmiddle'>";
        str += "  </a>";
        str+='  </td>';
		        str+='  <td width="1"><img src="' + imagesPath + 'white_spacer.gif" width="6" height="1"></td>';

        str+='  <td>';		
		if(indication!=null && indication=='CreateTDO')
        str += "  <a href='javascript: moveDownElement(\"" + holderId + "\")' tabindex='1'>";
		else
        str += "  <a href='javascript: moveDownElement(\"" + IDAll + "\")' tabindex='1'>";
        str += "    <img src='images/down.gif' border='0' align='absmiddle'>";
        str += "  </a>";
//        str += "  &nbsp;";
        str+='  </td>';
        str+='  </tr>';
        str+='</table>';
        str+='  </td>';
        str+='  </tr>';
        str+='  <tr>';
        str+='  <td width="1">';
        str+='  <td width="1"><img src="' + imagesPath + 'white_spacer.gif" width="1" height="13"></td>';
        str+='  </td>';
        str+='  </tr>';

        str+='</table>';



        var el = document.createElement('div');
        el.id = IDAll;
        el.style.verticalAlign = 'middle';
        el.innerHTML = str;
    
        var tt = document.getElementById(holderId);
        tt.appendChild(el);
		createToDoListForm["description_["+counter+"].descriptionText"];
        document.getElementById('hdn' + ID).value = "";
	    enableDesignMode(ID, htmlValue, readOnly);
 	    new dragObject('handleCorner' + ID, null, new PositionDrag(382, 105), new PositionDrag(5000, 5000), null, CornerMove, null, false);
		new ChangeStyle(ID);
        counter++;
}
//senthilm End
//senthilm Start
function removeElement1(remId,remIds)
{
	var vRTEs = allRTEs.split(";");
	var RTEs="";
       for (var i = 0; i < vRTEs.length; i++) {
        //updateRTE(vRTEs[i]);
        var oHdnMessage = document.getElementById('hdn' + vRTEs[i]);
            if(remId!=oHdnMessage.name)
	       		RTEs+=oHdnMessage.name+";";
       	}
        RTEs=RTEs.substring(0,(RTEs.length-1));
    	
    	allRTEs=RTEs;
    	//alert("Final :  "+allRTEs)
    	removeElement(remIds)

}
//senthilm End

function addDescriptionUP(holderId,counter,width,height,buttons,readOnly,titleT,colorT,textT,imageFileArray)    // Senthilm created
{
//alert(titleT+' : '+colorT+' : '+textT);
var ID="description[" + counter + "].descriptionText";
	
	if (width == null) width = (isIE) ?375 :377;
    if (height == null) height = 100;
    if (buttons == null) buttons = true;
    if (readOnly == null) readOnly = false;
	if(isIE || isMozilla)increase=45;
	if(isOpera)increase=45;
	if(isSafari)increase=50;

	if (isIE) {
        var tablewidth = width + 2;
    } else {
        var tablewidth = width + 2;
    }
    
		var newId = 'description_'+counter;
        str = "";
        comps="";
        
    if (allRTEs.length > 0) {allRTEs += ";"; }
        allRTEs += ID;
		   str+= "<table border='0' cellpadding='2' cellspacing='2' class='form_container_static'><colgroup valign='middle'><col width='11'/><col width='116'/><col width='*%'/><col width='20%'/></colgroup><tr id='titlecont_"+counter+"'><td valign='top'>&nbsp</td><td width='130' valign='top'>"+titleT+"</td><td>";

       	str += "  <input type='hidden' name='description["+counter+"].displayOrder'  value=''>";

      
		comps+='<table class="btnBack" cellpadding=2 cellspacing=0 id="Buttons1_' + ID + '" width="' + tablewidth + '">';
        comps+='  <tr>';
        comps+='      <td>';
        comps+='          <select id="formatblock_' + ID + '" onchange="Select(\'' + ID + '\', this.id);">';
        comps+='              <option value="">['+richtextVariables.Style+']</option>';
        comps+='              <option value="<p>">'+richtextVariables.Paragraph+'</option>';
        comps+='              <option value="<h1>">'+richtextVariables.Heading1+'<h1></option>';
        comps+='              <option value="<h2>">'+richtextVariables.Heading2 +'<h2></option>';
        comps+='              <option value="<h3>">'+richtextVariables.Heading3+'<h3></option>';
        comps+='              <option value="<h4>">'+richtextVariables.Heading4 +'<h4></option>';
        comps+='              <option value="<h5>">'+richtextVariables.Heading5 +'<h5></option>';
        comps+='              <option value="<h6>">'+richtextVariables.Heading6 +'<h6></option>';
        comps+='              <option value="<address>">'+richtextVariables.Address +'<ADDR></option>';
        comps+='              <option value="<pre>">'+richtextVariables.Formatted+'<pre></option>';
        comps+='          </select>';
        comps+='      </td>';
        comps+='      <td>';
        comps+='          <select id="fontname_' + ID + '" onchange="Select(\'' + ID + '\', this.id)">';
        comps+='              <option value="Font" selected>['+richtextVariables.Font+']</option>';
        comps+='              <option value="Arial,Helvetica,sans-serif ">'+richtextVariables.Arial+'</option>';
        comps+='              <option value="Courier New,Courier,mono">'+richtextVariables.CourierNew+'</option>';
        comps+='              <option value="Times New Roman,Times,serif">'+richtextVariables.TimesNewRoman+'</option>';
        comps+='              <option value="Verdana,Arial,Helvetica,sans-serif " selected>'+richtextVariables.Verdana+'</option>';
		comps+='              <option  value="comic sans ms,cursive">'+richtextVariables.ComicSansMS+'</option>';
		comps+='              <option  value="georgia,serif ">'+richtextVariables.Georgia+'</option>';
		comps+='              <option  value="lucida sans unicode,lucida grande,sans-serif">'+richtextVariables.LucidaSansUnicode+'</option>';
		comps+='              <option  value="tahoma,geneva,sans-serif ">'+richtextVariables.Tahoma+'</option>';
		comps+='              <option  value="trebuchet ms,helvetica,sans-serif">'+richtextVariables.TrebuchetMS+'</option>';
        comps+='          </select>';
        comps+='      </td>';
        comps+='      <td>';
        comps+='          <select unselectable="on" id="fontsize_' + ID + '" onchange="Select(\'' + ID + '\', this.id);">';
        comps+='              <option value="Size">['+richtextVariables.Size+']</option>';
        comps+='              <option value="8">8</option>';
        comps+='              <option value="9">9</option>';
        comps+='              <option value="10">10</option>';
        comps+='              <option value="11" selected>11</option>';
        comps+='              <option value="12">12</option>';
        comps+='              <option value="13">13</option>';
        comps+='              <option value="14">14</option>';
        comps+='              <option value="15">15</option>';
        comps+='              <option value="16">16</option>';
        comps+='              <option value="17">17</option>';
        comps+='              <option value="18">18</option>';
        comps+='              <option value="19">19</option>';
        comps+='              <option value="20">20</option>';
        comps+='              <option value="22">22</option>';
        comps+='              <option value="24">24</option>';
        comps+='              <option value="26">26</option>';
        comps+='              <option value="28">28</option>';
        comps+='              <option value="36">36</option>';
        comps+='              <option value="48">48</option>';
        comps+='              <option value="72">72</option>';
        comps+='          </select>';
        comps+='      </td>';
        comps+='      <td width="100%">';
        comps+='      </td>';
        comps+='  </tr>';
        comps+='</table>';
        comps+='<table class="btnBack"  onmousedown="return false;" cellpadding="0" cellspacing="0" id="Buttons2_' + ID + '" width="' + tablewidth + '">';
        comps+='  <tr>';
        comps+='      <td><img id="bold_' + ID + '" class="btnImage" src="' + imagesPath + 'bold.gif" alt="Bold" title="'+richtextVariables.Bold+'" onClick="FormatText(\'' + ID + '\', \'bold\', \'\')"></td>';
        comps+='      <td><img id="italic_' + ID + '" class="btnImage" src="' + imagesPath + 'italic.gif" alt="Italic" title="'+richtextVariables.Italic+'" onClick="FormatText(\'' + ID + '\', \'italic\', \'\')"></td>';
        comps+='      <td><img id="underline_' + ID + '" class="btnImage" src="' + imagesPath + 'underline.gif" alt="Underline" title="'+richtextVariables.Underline+'" onClick="FormatText(\'' + ID + '\', \'underline\', \'\')"></td>';
    //    comps+='      <td><span class="vertSep"></span></td>';
        comps+='      <td><img id="left_' + ID + '" class="btnImage" src="' + imagesPath + 'left_just.gif" alt="Align Left" title="'+richtextVariables.AlignLeft+'" onClick="FormatText(\'' + ID + '\', \'justifyleft\', \'\')"></td>';
        comps+='      <td><img id="center_' + ID + '" class="btnImage" src="' + imagesPath + 'centre.gif" alt="Center" title="'+richtextVariables.Center+'" onClick="FormatText(\'' + ID + '\', \'justifycenter\', \'\')"></td>';
        comps+='      <td><img id="right_' + ID + '" class="btnImage" src="' + imagesPath + 'right_just.gif" alt="Align Right" title="'+richtextVariables.AlignRight+'" onClick="FormatText(\'' + ID + '\', \'justifyright\', \'\')"></td>';
        if (false) comps+='      <td><img class="btnImage" src="' + imagesPath + 'justifyfull.gif" alt="Justify Full" title="'+richtextVariables.JustifyFull+'" onclick="FormatText(\'' + ID + '\', \'justifyfull\', \'\')"></td>';
       // comps+='      <td><span class="vertSep"></span></td>';
        comps+='      <td><img class="btnImage" src="' + imagesPath + 'hr.gif" alt="Horizontal Rule" title="'+richtextVariables.HorizontalRule+'" onClick="FormatText(\'' + ID + '\', \'inserthorizontalrule\', \'\')"></td>';
       // comps+='      <td><span class="vertSep"></span></td>';
        comps+='      <td><img id="ordered_' + ID + '" class="btnImage" src="' + imagesPath + 'numbered_list.gif" alt="Ordered List" title="'+richtextVariables.OrderedList+'" onClick="FormatText(\'' + ID + '\', \'insertorderedlist\', \'\')"></td>';
        comps+='      <td><img id="unordered_' + ID + '" class="btnImage" src="' + imagesPath + 'list.gif" alt="Unordered List" title="'+richtextVariables.UnorderedList+'" onClick="FormatText(\'' + ID + '\', \'insertunorderedlist\', \'\')"></td>';
       // comps+='      <td><span class="vertSep"></span></td>';
        comps+='      <td><img class="btnImage" src="' + imagesPath + 'outdent.gif" alt="Outdent" title="'+richtextVariables.Outdent+'" onClick="FormatText(\'' + ID + '\', \'outdent\', \'\')"></td>';
        comps+='      <td><img class="btnImage" src="' + imagesPath + 'indent.gif" alt="Indent" title="'+richtextVariables.Indent+'" onClick="FormatText(\'' + ID + '\', \'indent\', \'\')"></td>';
        comps+='      <td><div id="forecolor_' + ID + '"><img class="btnImage" src="' + imagesPath + 'textcolor.gif" alt="Text Color" title="'+richtextVariables.TextColor+'" onClick="FormatText(\'' + ID + '\', \'forecolor\', \'\')"></div></td>';
        comps+='      <td><div id="hilitecolor_' + ID + '"><img class="btnImage" src="' + imagesPath + 'bgcolor.gif" alt="Background Color" title="'+richtextVariables.BackgroundColor+'" onClick="FormatText(\'' + ID + '\', \'hilitecolor\', \'\')"></div></td>';
   //     comps+='      <td><span class="vertSep"></span></td>';
        comps+='      <td><img class="btnImage" src="' + imagesPath + 'hyperlink.gif" alt="Insert Link" title="'+richtextVariables.InsertLink+'" onClick="FormatText(\'' + ID + '\', \'createlink\')"></td>';
//        comps+='      <td><img class="btnImage" src="' + imagesPath + 'image.gif" alt="Add Image" title="'+richtextVariables.AddImage+'" onClick="AddImage(\'' + ID + '\')"></td>';
		if((imageFileArray != 'null') && (imageFileArray != null))
				{
					if(imageFileArray.length > 0)
					{
						for(var i=0; i<imageFileArray.length; i++)
						{
							if(i==0){
								comps+=' 	<td> <a '+tabindex+' name="ImageGallery'+ID+'" href= '+imageFileArray[i]+' target="self" rel="lightbox" Class="galary_imagesized" value="'+imageFileArray[i]+'" >';
								comps+=' <img onClick="initLightbox();setEditorName('+"'"+ID+"'"+')" class="btnImage" src="' + imagesPath + 'image.gif" title="'+richtextVariables.ImageGallery+'"></a></td>';
								comps+=' <input type="hidden" id="frameName_RTE" name="frameName_RTE" value="'+ID+'">';
							} else {				
							comps+='	<a '+tabindex+' name="ImageGallery'+ID+'" href= '+imageFileArray[i]+' target="self" rel="lightbox" Class="galary_imagesized" title="'+richtextVariables.ImageGallery+'" value="'+imageFileArray[i]+'" > </a>'; 
							}
						}
					} else{
						comps+=' 	<td> <img class="btnImage" src="' + imagesPath + 'image.gif" title="'+richtextVariables.ImageGallery+'" onClick="NoImagesFoundMessage()"></td>';
					}
				}else {
				
					comps+='      <td><img class="btnImage" src="' + imagesPath + 'image.gif" alt="Add Image" title="'+richtextVariables.AddImage+'" onClick="AddImage(\'' + ID + '\')"></td>';
				}
		if(isIE)comps+='        <td><img class="btnImage" src="' + imagesPath + 'spellcheck.gif" alt="Spell Check" title="'+richtextVariables.SpellCheck+'" onClick="checkspell()"></td>';
		comps+='      <td><img class="btnImage" src="' + imagesPath + 'cleanup.gif" alt="cleanupMStag" title="'+richtextVariables.RemoveFormating+'" onClick="cleanUp(\'' + ID + '\')"></td>';

        comps+='      <td width="100%"></td>';
        comps+='  </tr>';
        comps+='</table>';
		
		comps+='<iframe id="' + ID + '" name="' + ID + '" width="' + width + 'px" height="' + height + 'px" src="/dummy.jsp" style="border: 1px solid #006699"></iframe>';
        comps+='<textarea readonly="true" name="HtmlCode' + ID + '" id="HtmlCode' + ID + '" style="display:none; width:' + (width+2) + 'px; height:' + (height+increase) + 'px; border: 1px solid #006699; background-color:#FFFFFF; font-family:courier new; font-size:12px; color:#000000;"></textarea>'; 
		comps+='<table  onmousedown="return false;" border="0"  cellpadding="0" cellspacing="0" id="Buttons_Buttom" width="80%">';
        comps+='  <tr>';
        comps+='  <td width="1">';

		comps+='<table class="btnBackHole" onmousedown="return false;" border="0"  cellpadding="0" cellspacing="0" id="Buttons_Buttom' + ID + '" width="' + tablewidth + '">';
        comps+='  <tr>';
	    comps+='      <td width="10"><img class="btnImage" src="' + imagesPath + 'designButton.gif" alt="Design Mode" title="'+richtextVariables.DesignMode+'" onClick="ShowView(\'' + ID + '\',\'' + readOnly + '\', \'designview\')"></td>';
		comps+='      <td width="10"><img class="btnImage" src="' + imagesPath + 'codeButton.gif" alt="HTML Code" title="'+richtextVariables.HTMLCode+'" onClick="ShowView(\'' + ID + '\',\'' + readOnly + '\', \'htmlview\')"></td>';
		comps+='      <td width="*" align="right"><img   id="handleCorner' + ID + '" style=cursor:Move src="' + imagesPath + 'Drag.gif" alt="drag" title="'+richtextVariables.Drag+'"></td>';
        comps+='  </tr>';
        comps+='</table>';
        comps+='  </td>';
        comps+='  <td width="1"><img src="' + imagesPath + 'white_spacer.gif" width="15" height="1"></td>';
        comps+='  <td>';
        comps += "  <a href='javascript: removeElementAll(\"" + counter + "\")' tabindex='1'>";
        comps += "    <img src='images/delete.gif' border='0' align='absmiddle'>";
        comps += "  </a>";
        comps+='  </td>';
        comps+='  </tr>';
        comps+='</table>';

		    if (false && !readOnly) comps+='<br /><input type="checkbox" id="chkSrc' + ID + '" onclick="toggleHTMLSrc(\'' + ID + '\');" />&nbsp;View Source';
			comps+='<iframe width="254" height="174" id="cp' + ID + '" src="' + includesPath + 'palette.htm" marginwidth="0" marginheight="0" scrolling="no" style="visibility:hidden; display: none; position: absolute;"></iframe>';
			comps+='<input type="hidden" id="hdn' + ID + '" name="' + ID + '" value="">';
        
        str+=comps;
/*        str += "  &nbsp; &nbsp;";
        str += "  <a href='javascript: removeElementAll(\"" + counter + "\")' tabindex='1'>";
        str += "    <img src='images/delete.gif' border='0' align='absmiddle'>";
        str += "  </a>";
*/
/*        str += "  &nbsp;";
        str += "  <a href='javascript: moveUpElement(\"" + ID + "\")' tabindex='1'>";
        str += "    <img src='images/up.gif' border='0' align='absmiddle'>";
        str += "  </a>";
        str += "  <a href='javascript: moveDownElement(\"" + ID + "\")' tabindex='1'>";
        str += "    <img src='images/down.gif' border='0' align='absmiddle'>";
        str += "  </a><br>";
        str += "  &nbsp;";*/
		   str+= "</td></tr>";
		   //str+="<tr><td >Background Color</td>  <td></td><td></td></table>";
		   	str+="<tr id='colorcont_"+counter+"'><td valign='top'>&nbsp</td><td valign='top' class='form_label' >"+colorT+"</td><td valign='top' >";
var colorID="description[" + counter + "].color";
			str+="<input type='hidden' name='"+colorID+"' id='"+colorID+"'><span class='left' id='colorId"+counter+"' value='' style='width: 50px; height: 20px;border: .1em solid #0A00B0;FLOAT: left;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;<img src='images/bgcolor.gif' onclick="+"showColor(null,'colorId"+counter+"','bcolor"+counter+"','"+colorID+"')>"; 
			str+="<iframe width='254' height='174' id='bcolor"+counter+"' src='selectColor.htm' marginwidth='0' marginheight='0' scrolling='no' style='display: none; position: absolute;'></iframe></td></tr>";


var subID="description[" + counter + "].subTitleText";


       	str += "<tr id='textcont_"+counter+"'><td valign='top'>&nbsp</td><td width='130' valign='top'>"+textT+"</td><td>";

//       	str += "  <input type='hidden' name='description["+counter+"].displayOrder'  value=''>";

        comps="";
		comps+='<table class="btnBack" cellpadding=2 cellspacing=0 id="Buttons1_' + subID + '" width="' + tablewidth + '">';
        comps+='  <tr>';
        comps+='      <td>';
        comps+='          <select id="formatblock_' + subID + '" onchange="Select(\'' + subID + '\', this.id);">';
        comps+='              <option value="">['+richtextVariables.Style+']</option>';
        comps+='              <option value="<p>">'+richtextVariables.Paragraph+'</option>';
        comps+='              <option value="<h1>">'+richtextVariables.Heading1 +' <h1></option>';
        comps+='              <option value="<h2>">'+richtextVariables.Heading2 +'<h2></option>';
        comps+='              <option value="<h3>">'+richtextVariables.Heading3 +' <h3></option>';
        comps+='              <option value="<h4>">'+richtextVariables.Heading4 +'<h4></option>';
        comps+='              <option value="<h5>">'+richtextVariables.Heading5 +'<h5></option>';
        comps+='              <option value="<h6>">'+richtextVariables.Heading6 +'<h6></option>';
        comps+='              <option value="<address>">'+richtextVariables.Address +'<ADDR></option>';
        comps+='              <option value="<pre>">'+richtextVariables.Formatted+'<pre></option>';
        comps+='          </select>';
        comps+='      </td>';
        comps+='      <td>';
        comps+='          <select id="fontname_' + subID + '" onchange="Select(\'' + subID + '\', this.id)">';
        comps+='              <option value="Font" selected>['+richtextVariables.Font+']</option>';
        comps+='              <option value="Arial,Helvetica,sans-serif ">'+richtextVariables.Arial+'</option>';
        comps+='              <option value="Courier New,Courier,mono">'+richtextVariables.CourierNew+'</option>';
        comps+='              <option value="Times New Roman,Times,serif">'+richtextVariables.TimesNewRoman+'</option>';
        comps+='              <option value="Verdana,Arial,Helvetica,sans-serif " selected>'+richtextVariables.Verdana+'</option>';
		comps+='              <option  value="comic sans ms,cursive">'+richtextVariables.ComicSansMS+'</option>';
		comps+='              <option  value="georgia,serif ">'+richtextVariables.Georgia+'</option>';
		comps+='              <option  value="lucida sans unicode,lucida grande,sans-serif">'+richtextVariables.LucidaSansUnicode+'</option>';
		comps+='              <option  value="tahoma,geneva,sans-serif ">'+richtextVariables.Tahoma+'</option>';
		comps+='              <option  value="trebuchet ms,helvetica,sans-serif">'+richtextVariables.TrebuchetMS+'</option>';
        comps+='          </select>';
        comps+='      </td>';
        comps+='      <td>';
        comps+='          <select unselectable="on" id="fontsize_' + subID + '" onchange="Select(\'' + subID + '\', this.id);">';
        comps+='              <option value="Size">['+richtextVariables.Size+']</option>';
        comps+='              <option value="8">8</option>';
        comps+='              <option value="9">9</option>';
        comps+='              <option value="10">10</option>';
        comps+='              <option value="11" selected>11</option>';
        comps+='              <option value="12">12</option>';
        comps+='              <option value="13">13</option>';
        comps+='              <option value="14">14</option>';
        comps+='              <option value="15">15</option>';
        comps+='              <option value="16">16</option>';
        comps+='              <option value="17">17</option>';
        comps+='              <option value="18">18</option>';
        comps+='              <option value="19">19</option>';
        comps+='              <option value="20">20</option>';
        comps+='              <option value="22">22</option>';
        comps+='              <option value="24">24</option>';
        comps+='              <option value="26">26</option>';
        comps+='              <option value="28">28</option>';
        comps+='              <option value="36">36</option>';
        comps+='              <option value="48">48</option>';
        comps+='              <option value="72">72</option>';
        comps+='          </select>';
        comps+='      </td>';
        comps+='      <td width="100%">';
        comps+='      </td>';
        comps+='  </tr>';
        comps+='</table>';
        comps+='<table class="btnBack"  onmousedown="return false;" cellpadding="0" cellspacing="0" id="Buttons2_' + subID + '" width="' + tablewidth + '">';
        comps+='  <tr>';
        comps+='      <td><img id="bold_' + subID + '" class="btnImage" src="' + imagesPath + 'bold.gif" alt="Bold" title="'+richtextVariables.Bold+'" onClick="FormatText(\'' + subID + '\', \'bold\', \'\')"></td>';
        comps+='      <td><img id="italic_' + subID + '" class="btnImage" src="' + imagesPath + 'italic.gif" alt="Italic" title="'+richtextVariables.Italic+'" onClick="FormatText(\'' + subID + '\', \'italic\', \'\')"></td>';
        comps+='      <td><img id="underline_' + subID + '" class="btnImage" src="' + imagesPath + 'underline.gif" alt="Underline" title="'+richtextVariables.Underline+'" onClick="FormatText(\'' + subID + '\', \'underline\', \'\')"></td>';
 //       comps+='      <td><span class="vertSep"></span></td>';
        comps+='      <td><img id="left_' + subID + '" class="btnImage" src="' + imagesPath + 'left_just.gif" alt="Align Left" title="'+richtextVariables.AlignLeft+'" onClick="FormatText(\'' + subID + '\', \'justifyleft\', \'\')"></td>';
        comps+='      <td><img id="center_' + subID + '" class="btnImage" src="' + imagesPath + 'centre.gif" alt="Center" title="'+richtextVariables.Center+'" onClick="FormatText(\'' + subID + '\', \'justifycenter\', \'\')"></td>';
        comps+='      <td><img id="right_' + subID + '" class="btnImage" src="' + imagesPath + 'right_just.gif" alt="Align Right" title="'+richtextVariables.AlignRight+'" onClick="FormatText(\'' + subID + '\', \'justifyright\', \'\')"></td>';
        if (false) comps+='      <td><img class="btnImage" src="' + imagesPath + 'justifyfull.gif" alt="Justify Full" title="'+richtextVariables.JustifyFull+'" onclick="FormatText(\'' + subID + '\', \'justifyfull\', \'\')"></td>';
        //comps+='      <td><span class="vertSep"></span></td>';
        comps+='      <td><img class="btnImage" src="' + imagesPath + 'hr.gif" alt="Horizontal Rule" title="'+richtextVariables.HorizontalRule+'" onClick="FormatText(\'' + subID + '\', \'inserthorizontalrule\', \'\')"></td>';
        //comps+='      <td><span class="vertSep"></span></td>';
        comps+='      <td><img id="ordered_' + subID + '" class="btnImage" src="' + imagesPath + 'numbered_list.gif" alt="Ordered List" title="'+richtextVariables.OrderedList+'" onClick="FormatText(\'' + subID + '\', \'insertorderedlist\', \'\')"></td>';
        comps+='      <td><img id="unordered_' + subID + '" class="btnImage" src="' + imagesPath + 'list.gif" alt="Unordered List" title="'+richtextVariables.UnorderedList+'" onClick="FormatText(\'' + subID + '\', \'insertunorderedlist\', \'\')"></td>';
        //comps+='      <td><span class="vertSep"></span></td>';
        comps+='      <td><img class="btnImage" src="' + imagesPath + 'outdent.gif" alt="Outdent" title="'+richtextVariables.Outdent+'" onClick="FormatText(\'' + subID + '\', \'outdent\', \'\')"></td>';
        comps+='      <td><img class="btnImage" src="' + imagesPath + 'indent.gif" alt="Indent" title="'+richtextVariables.Indent+'" onClick="FormatText(\'' + subID + '\', \'indent\', \'\')"></td>';
        comps+='      <td><div id="forecolor_' + subID + '"><img class="btnImage" src="' + imagesPath + 'textcolor.gif" alt="Text Color" title="'+richtextVariables.TextColor+'" onClick="FormatText(\'' + subID + '\', \'forecolor\', \'\')"></div></td>';
        comps+='      <td><div id="hilitecolor_' + subID + '"><img class="btnImage" src="' + imagesPath + 'bgcolor.gif" alt="Background Color" title="'+richtextVariables.BackgroundColor+'" onClick="FormatText(\'' + subID + '\', \'hilitecolor\', \'\')"></div></td>';
 //       comps+='      <td><span class="vertSep"></span></td>';
        comps+='      <td><img class="btnImage" src="' + imagesPath + 'hyperlink.gif" alt="Insert Link" title="'+richtextVariables.InsertLink+'" onClick="FormatText(\'' + subID + '\', \'createlink\')"></td>';
//        comps+='      <td><img class="btnImage" src="' + imagesPath + 'image.gif" alt="Add Image" title="'+richtextVariables.AddImage+'" onClick="AddImage(\'' + subID + '\')"></td>';
		if((imageFileArray != 'null') && (imageFileArray != null))
				{
					if(imageFileArray.length > 0)
					{
						for(var i=0; i<imageFileArray.length; i++)
						{
							if(i==0){
								comps+=' 	<td> <a '+tabindex+' name="ImageGallery'+subID+'" href= '+imageFileArray[i]+' target="self" rel="lightbox" Class="galary_imagesized" value="'+imageFileArray[i]+'" >';
								comps+=' <img onClick="initLightbox();setEditorName('+"'"+subID+"'"+')" class="btnImage" src="' + imagesPath + 'image.gif" title="'+richtextVariables.ImageGallery+'"></a></td>';
								comps+=' <input type="hidden" id="frameName_RTE" name="frameName_RTE" value="'+subID+'">';
							} else {				
							comps+='	<a '+tabindex+' name="ImageGallery'+subID+'" href= '+imageFileArray[i]+' target="self" rel="lightbox" Class="galary_imagesized" title="'+richtextVariables.ImageGallery+'" value="'+imageFileArray[i]+'" > </a>'; 
							}
						}
					} else{
						comps+=' 	<td> <img class="btnImage" src="' + imagesPath + 'image.gif" title="'+richtextVariables.ImageGallery+'" onClick="NoImagesFoundMessage()"></td>';
					}
				}else {
				
					comps+='      <td><img class="btnImage" src="' + imagesPath + 'image.gif" alt="Add Image" title="'+richtextVariables.AddImage+'" onClick="AddImage(\'' + ID + '\')"></td>';
				}
		if(isIE)comps+='        <td><img class="btnImage" src="' + imagesPath + 'spellcheck.gif" alt="Spell Check" title="'+richtextVariables.SpellCheck+'" onClick="checkspell()"></td>';
		comps+='      <td><img class="btnImage" src="' + imagesPath + 'cleanup.gif" alt="cleanupMStag" title="'+richtextVariables.RemoveFormating+'" onClick="cleanUp(\'' + subID + '\')"></td>';
        comps+='      <td width="100%"></td>';
        comps+='  </tr>';
        comps+='</table>';
		
		comps+='<iframe id="' + subID + '" name="' + subID + '" width="' + width + 'px" height="' + height + 'px" src="/dummy.jsp" style="border: 1px solid #006699"></iframe>';
        comps+='<textarea readonly="true" name="HtmlCode' + subID + '" id="HtmlCode' + subID + '" style="display:none; width:' + (width+2) + 'px; height:' + (height+increase) + 'px; border: 1px solid #006699; background-color:#FFFFFF; font-family:courier new; font-size:12px; color:#000000;"></textarea>'; 
        comps+='<table class="btnBackHole" onmousedown="return false;" border="0"  cellpadding="0" cellspacing="0" id="Buttons_Buttom' + subID + '" width="' + tablewidth + '">';
        comps+='  <tr>';
	    comps+='      <td width="10"><img class="btnImage" src="' + imagesPath + 'designButton.gif" alt="Design Mode" title="'+richtextVariables.DesignMode+'" onClick="ShowView(\'' + subID + '\',\'' + readOnly + '\', \'designview\')"></td>';
		comps+='      <td width="10"><img class="btnImage" src="' + imagesPath + 'codeButton.gif" alt="HTML Code" title="'+richtextVariables.HTMLCode+'" onClick="ShowView(\'' + subID + '\',\'' + readOnly + '\', \'htmlview\')"></td>';
		comps+='      <td width="*" align="right"><img   id="handleCorner' + subID + '" style=cursor:Move src="' + imagesPath + 'Drag.gif" alt="drag" title="'+richtextVariables.Drag+'"></td>';
        comps+='  </tr>';
        comps+='</table>';

		    if (false && !readOnly) comps+='<br /><input type="checkbox" id="chkSrc' + subID + '" onclick="toggleHTMLSrc(\'' + subID + '\');" />&nbsp;View Source';
			comps+='<iframe width="254" height="174" id="cp' + subID + '" src="' + includesPath + 'palette.htm" marginwidth="0" marginheight="0" scrolling="no" style="visibility:hidden; display: none; position: absolute;"></iframe>';
			comps+='<input type="hidden" id="hdn' + subID + '" name="' + subID + '" value="">';
        
        str+=comps;
		
		   str+= "</td></tr><tr id='description[" + counter + "].deleteRow1'><td><img src='" + imagesPath + "white_spacer.gif' width='11' height='1'></td><td><img src='" + imagesPath + "white_spacer.gif' width='116' height='1'></td><td><img src='" + imagesPath + "white_spacer.gif' width='471' height='1'></td><td><img src='" + imagesPath + "white_spacer.gif' width='116' height='1'></td></tr><tr  id='description[" + counter + "].deleteRow2'><td colspan=4 align='left'><hr width='97%'></td></tr>";







        var el = document.createElement('div');
        el.id = ID+'div';
        el.style.verticalAlign = 'middle';
        el.innerHTML = str;

        var tt = document.getElementById(holderId);
//    alert('holderId :'+holderId +" : "+tt);
        tt.appendChild(el);
       // userProfileForm["description_["+counter+"].descriptionText"];
        document.getElementById('hdn' + ID).value = "";
        document.getElementById('hdn' + subID).value = "";
	    enableDesignMode(ID, "", readOnly);
	    enableDesignMode(subID, "", readOnly);
  if (allRTEs.length > 0) {allRTEs += ";"; }
        allRTEs += subID;
        counter++;
	   new dragObject('handleCorner' + ID, null, new PositionDrag(382, 105), new PositionDrag(5000, 5000), null, CornerMove, null, false);
	   new ChangeStyle(ID);
	   new dragObject('handleCorner' + subID, null, new PositionDrag(382, 105), new PositionDrag(5000, 5000), null, CornerMove, null, false);
	   new ChangeStyle(subID);

}
function removeRTEs(index)     // Senthilm created
{
//	alert(allRTEs);
	var vRTEs = allRTEs.split(";");
	var RTEs="";
	remId1='description['+index+'].descriptionText';
	remId2='description['+index+'].subTitleText';
	remId3='description['+index+'].deleteRow1';
	remId4='description['+index+'].deleteRow2';

       for (var i = 0; i < vRTEs.length; i++) {
 //alert(vRTEs[i]);
        var oHdnMessage = document.getElementById('hdn' + vRTEs[i]);
   //     alert("Remove : "+remId1 +"    :  "+oHdnMessage.name+ " : " + i +" : "+(vRTEs.length-1));
            if(remId1==oHdnMessage.name || remId2==oHdnMessage.name)
				RTEs=RTEs;
			else
				RTEs+=oHdnMessage.name+";";


       	}
	//	alert('----------'+RTEs);
        RTEs=RTEs.substring(0,(RTEs.length-1));
    	
    	allRTEs=RTEs;
    //	alert("Final :  "+allRTEs)
	removeElement('titlecont_'+index);
	removeElement('colorcont_'+index);
	removeElement('textcont_'+index);

	removeElement(remId3);
	removeElement(remId4);

}