
//=====================================================================================
//================================== Tags =============================================
//=====================================================================================

/**************************************************************************************
 * Author: spe (february 2006)
 * How to use: include this script in the <head> section:
 *			   <script language="JavaScript" src="tools.js"><!----></script>
 **************************************************************************************/

/*
 * Add a tag in a html textarea named "HtmlContentField" in a form named "EditTag"
 */
function AddText(id,startTag,defaultText,endTag) 
{
   /*with(document.EditTag)
   {*/
	  var HtmlContentField = document.getElementById(id);
      if (HtmlContentField.createTextRange) 
      {
         var text;
         HtmlContentField.focus(HtmlContentField.caretPos);
         HtmlContentField.caretPos = document.selection.createRange().duplicate();
         if(HtmlContentField.caretPos.text.length>0)
         {
            //gère les espace de fin de sélection. Un double-click sélectionne le mot
            //+ un espace
            var sel = HtmlContentField.caretPos.text;
            var fin = '';
            while(sel.substring(sel.length-1, sel.length)==' ')
            {
               sel = sel.substring(0, sel.length-1)
               fin += ' ';
            }
            HtmlContentField.caretPos.text = startTag + sel + endTag + fin;
         }
         else
            HtmlContentField.caretPos.text = startTag+defaultText+endTag;
      }
      else HtmlContentField.value += startTag+defaultText+endTag;
   /*}*/
}

/*
 * Open a centered html window
 * Return: the reference of the new window
 * Example of use: <a href="javascript:void(win = LaunchCenterWindow("child.html",null,250,250))">open a window</a>
 */
function LaunchCenterWindow(url, name, height, width) 
{
  var str = "height=" + height + ",innerHeight=" + height;
  str += ",width=" + width + ",innerWidth=" + width;
  if (window.screen) {
    var ah = screen.availHeight - 30;
    var aw = screen.availWidth - 10;

    var xc = (aw - width) / 2;
    var yc = (ah - height) / 2;

    str += ",left=" + xc + ",screenX=" + xc;
    str += ",top=" + yc + ",screenY=" + yc;
  }
  return window.open(url, name, str);
}


/*
 *   Close the child window open
 *   Example of use: <body onUnload="CloseChildWindow()">
 */
function CloseChildWindow() 
{
  if (win && win.open && !win.closed) 
	win.close();
}

/*
 * Add a tag in a textarea named EditTagHtmlContentField in a fomr named EditTag from a child window
 */
function ModifParent (startTag,defaultText,endTag)
{
	var HtmlContentField = parent.opener.frames['DesktopText_rEdit'].document.selection.createRange();
 	if (window.opener && !window.opener.closed)
	{
		alert(window.opener.parent.frames['DesktopText_rEdit'].document.value);
//		window.opener.parent.frames['DesktopText_rEdit'].document.EditTag.HtmlContentField.value += startTag+defaultText+endTag;
	}
}