/**
 * Copyright (C) 2002-2003, CodeHouse.com. All rights reserved.
 *
 * THIS SOURCE CODE MAY NOT BE MODIFIED, DISTRIBUTED, OR EXECUTED
 * FROM OUTSIDE THE CONTEXT OF CODEHOUSE.COM
 *
 * Written by: EID#2
 *
 * Created: 9/14/02
 *
 * Last Revision Date: 9/14/02
 */



/**
 * Returns a string which contains the Unicode equivalent of param s
 *
 * Params:
 *    s: Target String
 */
function convertString2Unicode(s)
{
   var uniString = "", hexVal, uniChar;

   for(var i = 0; i < s.length; ++i)
   {
      //Convert char to hex
      hexVal = Number(s.charCodeAt(i)).toString(16);

      //Convert to unicode by making sure hex is 4 chars long, padding with 0's if less
      uniChar = "\\u" + ("000" + hexVal).match(/.{4}$/)[0];

      uniString += uniChar;
   }

   return uniString;
}


IN_REQ = "Veuillez coller ou taper vos codes pour l'encodage dans la partie \"HTML SOURCE\" pour commencer. "

TMPL = "<script type=\"text/javascript\">document.write('__UNI__')<\/script>"


function submitHndlr()
{
   if( ! window.eIn )
   {
      eIn = document.getElementById("input");
      eOut = document.getElementById("output");
      eSelect = document.getElementById("select");
      eReset = document.getElementById("reset");
   }

   if( ! eIn.value.length )
   {
      alert(IN_REQ);
      eIn.focus();
   }
   else
   {
      eSelect.disabled = eReset.disabled = eOut.disabled = false;

      eOut.value = TMPL.replace(/__UNI__/, convertString2Unicode(eIn.value));
   }

   return false;
}

function resetHndlr()
{
   eSelect.disabled = eReset.disabled = eOut.disabled = true;
   eIn.value = eOut.value = "";
}
