function cur_ins(field, startTag, endTag, offset) {
	field.focus();
	if (document.getSelection) { //FF, NS
		selStart = field.selectionStart;
		selEnd = field.selectionEnd;
		text = field.value.substring(selStart, selEnd);
		field.value = field.value.substring(0, selStart) + startTag + text + endTag + field.value.substring(selEnd);
		if (text.length > 0) {
			if (offset != 0) {
				field.selectionStart = selStart + startTag.length + text.length - offset;
			} else {
				field.selectionStart = selStart + startTag.length + text.length + endTag.length;
			}
		} else {
			field.selectionStart = selStart + startTag.length;
		}
		field.selectionEnd = field.selectionStart;
	} 
	else if (document.selection) 
	{ //IE
		marker = document.selection.createRange();
		text = marker.text;
		marker.text = startTag+text+endTag;
		marker = document.selection.createRange();
		if (text.length > 0) {
			if (offset != 0) {
				marker.move('character', startTag.length + text.length - offset);
			} else {
				marker.move('character', startTag.length + text.length + endTag.length + offset);
			}
		} else {
			marker.move('character', -(endTag.length));
		}
		marker.select();
	}
}

function checkText(input, element) {
	if(document.getElementsByName(input)[0].value != "")
	{
		document.getElementById(element).style.visibility = 'visible';
		document.images[element].src = 'images/check.gif';
	} else {
		document.getElementById(element).style.visibility = 'visible';
		document.images[element].src = 'images/error.gif';
	}
}

function checkMail(input, element) {
	if(validEmail(document.getElementById(input).value))
	{
		document.getElementById(element).style.visibility = 'visible';
		document.images[element].src = 'images/check.gif';
	} else {
		document.getElementById(element).style.visibility = 'visible';
		document.images[element].src = 'images/error.gif';
	}
}

function validEmail(email) {
  var strReg = "^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$";
  var regex = new RegExp(strReg);
  return(regex.test(email));
}
