/**
* Обрамляет выделение в поле с ИД=fieldId формы с NAME=formName
* текстами text1, text2
*/
function inpos(text1, text2, fieldId, formName) {
var field = document.getElementById(fieldId)
var f = document.getElementsByName(formName)
var forma = f[0]
// field.focus(); с фокусом в NN потом курсор в конец улетает
!text2 ? text2 = \'\' : true;
// для NN
var decrement = 0
if ( ! document.all && ! field.selectionStart){
field.selectionStart = 1
decrement = 1
}
if (field.selectionStart){
var val = field.value
var val1 = val.substring(0, field.selectionStart - decrement)
var val2 = val.substring(field.selectionStart - decrement, field.selectionEnd)
var val3 = val.substring(field.selectionEnd, val.length)
field.value = val1 + text1 + val2 + text2 + val3
return;
}
// для IE
if (document.selection) {
var sText = forma.document.selection.createRange().text;
if (!sText) {
field.focus();
}
forma.document.selection.createRange().text = text1 + sText + text2;
// для прочих
} else {
field.value = field.value + text1 + text2;
}
}