function nl2br (str) {
    var breakTag = '<br />';
 
    return (str + '').replace(/([^>]?)\n/g, '$1'+ breakTag +'\n');
}
function ReplaceAll(Source,stringToFind,stringToReplace)
{
  var temp = Source;
    var index = temp.indexOf(stringToFind);
        while(index != -1){
            temp = temp.replace(stringToFind,stringToReplace);
            index = temp.indexOf(stringToFind);
        }
        return temp;
}
function gastenboek_preview (value)
{
   var textSmileys = new Array(
        ":)",
        ":(",
        ":p",
        ":lol:",
        ":@",
        ":heartbeat:",
        "(l)",
        ":eprop:",
        ":wave:",
        ":sunny:",
        ":wha:",
        ":yes:",
        ":sleepy:",
        ":rolleyes:",
        ":lookaround:",
        ":O",
        ":confused_2:",
        ":nono:",
        ":fun:",
        ":goodjob:",
        ":giggle:",
        ":cry:",
        ":$",
        ":jealous:",
        ":whocares:",
        ":spinning:",
        ":coolman:",
        ":littlekiss:",
        ":laugh:");
    // *** add the url's from the corresponding images below
    var realSmileys = new Array(
        "http://www.xanga.com/Images/smiley1.gif",
        "http://www.xanga.com/Images/smiley2.gif",
        "http://www.xanga.com/Images/smiley4.gif",
        "http://i.xanga.com/Alice/Smileylol.gif",
        "http://i.xanga.com/Alice/7_mad.gif",
        "http://i.xanga.com/Alice/heartbeating.gif",
        "http://i.xanga.com/Alice/SmileLove.gif",
        "http://i.xanga.com/Alice/eProp.gif",
        "http://i.xanga.com/Alice/SmileyWave.gif",
        "http://i.xanga.com/Alice/sunnySmiley.gif",
        "http://i.xanga.com/Alice/wha.gif",
        "http://i.xanga.com/Alice/yes.gif",
        "http://i.xanga.com/Alice/Smileysleep.gif",
        "http://i.xanga.com/Alice/Smileyrolleyes.gif",
        "http://i.xanga.com/Alice/SmileyLookaround.gif",
        "http://i.xanga.com/Alice/Smileyeek.gif",
        "http://i.xanga.com/Alice/Smileyconfused.gif",
        "http://i.xanga.com/Alice/SmileyAnimatedNoNo.gif",
        "http://i.xanga.com/Alice/propeller.gif",
        "http://i.xanga.com/Alice/goodjob.gif",
        "http://i.xanga.com/Alice/emot-giggle.gif",
        "http://i.xanga.com/Alice/blueAnimatedCry.gif",
        "http://i.xanga.com/Alice/Animatedshysmile.gif",
        "http://i.xanga.com/Alice/AliceJealous.gif",
        "http://i.xanga.com/Alice/19_indifferent.gif",
        "http://i.xanga.com/Alice/Smileyspinning.gif",
        "http://i.xanga.com/Alice/25_coolguy.gif",
        "http://i.xanga.com/Alice/AliceSmileyAnimatedBlinkKiss.gif",
        "http://i.xanga.com/Alice/LaughingAgua.gif");
    var preloadedImages = new Array(realSmileys.length);
    for (i = 0; i < preloadedImages.length; ++i)
    {
        preloadedImages[i] = new Image();
        preloadedImages[i].src = realSmileys[i];
    }
    // *** number of smileys that will be displayed per row
    var maxNumberOfSmileysPerRow = 10;
    // *** button size in pixels
    var buttonSize = 30;
    // preloading images

	var input 	=value;
	var output	=document.getElementById("preview");
	var hidden	=document.getElementById("hiddenfield");
	for (var i =0; i < textSmileys.length; i++)
	{
		input = ReplaceAll (input, textSmileys[i], "<img src=" + realSmileys[i] + ">");
	}
	output.innerHTML 	="<div class='gastenboek_input_preview'>" + nl2br(input) + "</div>" ;
	hidden.value		=nl2br(input);
}
