var emoPopUp_lastMode = '';
var emoPopUp_lastImg = '';
var emoPopUp_lastForm = '';
var emoPopUp_lastField = '';
var emoForTinyMCE = 0;

var emoWin = false;

window.onunload = function() { if(emoWin) if (!emoWin.closed) emoWin.close() };

function showEmoticons(mode,img,form,field) {
	if(!emoWin || emoWin.closed) {
		emoWin = openWindow('/emoticons/default.asp?mode='+mode+'&img='+img+'&form='+form+'&field='+field+'&tinymce='+emoForTinyMCE, 580, 270);
	} else if (mode != emoPopUp_lastMode || img != emoPopUp_lastImg || form != emoPopUp_lastForm || field != emoPopUp_lastField) {
		emoWin.frames['main'].document.location.replace('/emoticons/show_emoticons.asp?mode='+mode+'&img='+img+'&form='+form+'&field='+field);
	}
	emoWin.focus();
	emoPopUp_lastMode = mode;
	emoPopUp_lastImg = img;
	emoPopUp_lastForm = form;
	emoPopUp_lastField = field;
}

function showEmoticonsEx(mode,img,form,field,category,postaction) {
	if(!emoWin || emoWin.closed) {
		emoWin = openWindow('/emoticons/default.asp?category='+category+'&postaction='+postaction+'&mode='+mode+'&img='+img+'&form='+form+'&field='+field, 580, 270);
	} else if (mode != emoPopUp_lastMode || img != emoPopUp_lastImg || form != emoPopUp_lastForm || field != emoPopUp_lastField) {
		emoWin.frames['main'].document.location.replace('/emoticons/show_emoticons.asp?category='+category+'&postaction='+postaction+'&mode='+mode+'&img='+img+'&form='+form+'&field='+field);
	}
	emoWin.focus();
	emoPopUp_lastMode = mode;
	emoPopUp_lastImg = img;
	emoPopUp_lastForm = form;
	emoPopUp_lastField = field;
}

function storeCaret (textEl) {
  if (textEl.createTextRange) 
    textEl.caretPos = document.selection.createRange().duplicate();
}
function insertAtCaret (textEl, text) {
  textEl.focus();
  if (textEl.createTextRange && textEl.caretPos) {
    var caretPos = textEl.caretPos;
    caretPos.text =
      caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?
        text + ' ' : text;
  }
  else
    textEl.value  = text;
}


