function replaceText(text, textarea)
{
	if (typeof(textarea.caretPos) != "undefined" && textarea.createTextRange)
	{
		var caretPos = textarea.caretPos;

		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
		caretPos.select();
	}
	else if (typeof(textarea.selectionStart) != "undefined")
	{
		var begin = textarea.value.substr(0, textarea.selectionStart);
		var end = textarea.value.substr(textarea.selectionEnd);
		var scrollPos = textarea.scrollTop;

		textarea.value = begin + text + end;

		if (textarea.setSelectionRange)
		{
			textarea.focus();
			textarea.setSelectionRange(begin.length + text.length, begin.length + text.length);
		}
		textarea.scrollTop = scrollPos;
	}
	else
	{
		textarea.value += text;
		textarea.focus(textarea.value.length - 1);
	}
	return true;
}

function storeCaret(text)
{
	if (typeof(text.createTextRange) != "undefined")
		text.caretPos = document.selection.createRange().duplicate();
}
function f_sendmail(name, domain_1, domain_2,text) {
	if (text) {
		document.write('<a title="Написать письмо" href="mailto:'+name+'@'+domain_1+'.'+domain_2+'?Subject=Письмо с сайта">'+text+'</a>');
	} else {
		document.write('<a title="Написать письмо" href="mailto:'+name+'@'+domain_1+'.'+domain_2+'?Subject=Письмо с сайта">'+name+'@'+domain_1+'.'+domain_2+'</a>');
	}
}
function f_select(fl) {
	inputs = document.getElementsByTagName('input');
	for (i = 1; i < inputs.length; i++){
		if (inputs[i].type=='checkbox') {
			inputs[i].checked = fl;
		}
	}
	return;
}
function my_popup(src, width, height,title) {
	popup_w=window.open("about:blank", "_blank", "width="+(width+20)+", height="+(height+20));
	popup_w.document.write("<html><head><title>"+title+"</title><link rel='stylesheet' type='text/css' href='/css/layout.css' /><link rel='stylesheet' type='text/css' href='/css/common.css' /></head><body>");
	popup_w.document.write("<img class='image' src="+src+" width='"+width+"' height='"+height+"' alt='"+title+"' title='Карта проезда'>");
	popup_w.document.write("</body></html>");
}
function my_flash (filename, id, width, height) {
	document.write("<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='"+width+"' height='"+height+"' id='"+id+"' align='middle'>");
	document.write("<param name='FlashVars' value='' />");
	document.write("<param name='allowScriptAccess' value='sameDomain' />");
	document.write("<param name='wmode' value='window' />");
	document.write("<param name='bgcolor' value='' />");
	document.write("<param name='salign' value='lt' />");
	document.write("<param name='movie' value='"+filename+"' /><param name='menu' value='true' /><param name='quality' value='high' /><embed src='"+filename+"' wmode='window' menu='true' quality='high' FLashVars='' salign='lt' width='"+width+"' height='"+height+"' bgcolor='' name='"+id+"' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />");
	document.write("</object>");
}
