﻿function onSend1()
{

jname = document.forms.commform.name.value;
jemail = document.forms.commform.email.value;
jmessage = document.forms.commform.message.value;
jaction = document.forms.commform.action.value;
jpcomment = document.forms.commform.pcomment.value;
jid = document.forms.commform.id.value;
url = "/poll/commentsg.php?name="+jname+"&email="+jemail+"&message="+jmessage+"&action="+jaction+"&pcomment="+jpcomment+"&id="+jid;
manageattachments (url, 480, 160,'43346');

document.forms.commform.name.value="";
document.forms.commform.email.value="";
document.forms.commform.message.value="";

 }

function onSend2()
{

jto = document.forms.emailform.to.value;
jid = document.forms.emailform.id.value;
jtext = document.forms.emailform.text.value;
url = "/cgi-bin/mail.cgi?to="+jto+"&id="+jid+"&text="+jtext;
manageattachments (url, 480, 160,'43346');

document.forms.emailform.to.value="";
document.forms.emailform.text.value="";

 }

function onSend3()
{

jidn = document.forms.commform.idn.value;
jcommtext = document.forms.commform.commtext.value;

jcommtext = strreplace('\n', '<br>', jcommtext);


url = "/cgi-bin/comm.cgi?idn="+jidn+"&commtext="+jcommtext;
manageattachments (url, 480, 160,'43346');

document.forms.commform.commtext.value="";

 }

function onSend4(jvote)
{

jidn = document.forms.voteform.idn.value;

url = "/cgi-bin/vote.cgi?idn="+jidn+"&vote="+jvote;
manageattachments (url, 480, 160,'43346');


 }

function onSend5()
{

jorgan = document.forms.organform.organ.value;
jkontakt = document.forms.organform.kontakt.value;
jvid = document.forms.organform.vid.value;

url = "/cgi-bin/organ.cgi?organ="+jorgan+"&kontakt="+jkontakt+"&vid="+jvid;
manageattachments (url, 480, 160,'43346');

document.forms.organform.organ.value="";
document.forms.organform.kontakt.value="";
document.forms.organform.vid.value="";

 }

function onSend6()
{

jzametkitext = document.forms.zametkiform.zametkitext.value;
jlink = document.forms.zametkiform.zametkilink.value;
jzametkitext = strreplace('\n', '<br>', jzametkitext);


url = "/cgi-bin/zametki.cgi?zametki="+jzametkitext+"&link="+jlink;
manageattachments (url, 480, 160,'43346');

 }
 
function onSend7(idn,cmd)
{

url = "/cgi-bin/favorite.cgi?idn="+idn+"&cmd="+cmd;
manageattachments (url, 480, 160,'43346');


 }
 
function manageattachments(url, width, height, hash)
{
 window.open(url, "Attach" + hash, "statusbar=no,menubar=no,toolbar=no,scrollbars=yes,resizable=yes,width=" + width + ",height=" + height);
 return false;
}

function getBrowserInfo() {
 var t,v = undefined;
 if (window.opera) t = 'Opera';
 else if (document.all) {
  t = 'IE';
  var nv = navigator.appVersion;
  var s = nv.indexOf('MSIE')+5;
  v = nv.substring(s,s+1);
 }
 else if (navigator.appName) t = 'Netscape';
 return {type:t,version:v};
}
 
function bookmark(a){
 var url = window.document.location;
 var title = window.document.title;
 var b = getBrowserInfo();
 if (b.type == 'IE' && 7 > b.version && b.version >= 4) window.external.AddFavorite(url,title);
 else if (b.type == 'Opera') {
  a.href = url;
  a.rel = "sidebar";
  a.title = url+','+title;
  return true;
 }
 else if (b.type == "Netscape") window.sidebar.addPanel(title,url,"");
 else alert("Нажмите CTRL-D, чтобы добавить страницу в закладки.");
 return false;
}

function show(key)
{

if ((key == '1')&&(newstat.style.display == 'none')){
newstat.style.display='';
newstat.style.left = 180;
return false;
}else{
newstat.style.display='none';
return false;
}

}

function insert_text(text, spaces, popup)
{
	var textarea;
	
	if (!popup) 
	{
	textarea = document.forms[form_name].elements[text_name];
	} 
	else 
	{
		textarea = opener.document.forms[form_name].elements[text_name];
	}
	if (spaces) 
	{
		text = ' ' + text + ' ';
	}
	
	if (!isNaN(textarea.selectionStart))
	{
		var sel_start = textarea.selectionStart;
		var sel_end = textarea.selectionEnd;

		mozWrap(textarea, text, '')
		textarea.selectionStart = sel_start + text.length;
		textarea.selectionEnd = sel_end + text.length;
	}	
	
	else if (textarea.createTextRange && textarea.caretPos)
	{
		if (baseHeight != textarea.caretPos.boundingHeight) 
		{
			textarea.focus();
			storeCaret(textarea);
		}		
		var caret_pos = textarea.caretPos;
		caret_pos.text = caret_pos.text.charAt(caret_pos.text.length - 1) == ' ' ? caret_pos.text + text + ' ' : caret_pos.text + text;
		
	}
	else
	{
		textarea.value = textarea.value + text;
	}
	if (!popup) 
	{
		textarea.focus();
	} 	

}
function mozWrap(txtarea, open, close)
{
	var selLength = txtarea.textLength;
	var selStart = txtarea.selectionStart;
	var selEnd = txtarea.selectionEnd;
	var scrollTop = txtarea.scrollTop;

	if (selEnd == 1 || selEnd == 2) 
	{
		selEnd = selLength;
	}

	var s1 = (txtarea.value).substring(0,selStart);
	var s2 = (txtarea.value).substring(selStart, selEnd)
	var s3 = (txtarea.value).substring(selEnd, selLength);

	txtarea.value = s1 + open + s2 + close + s3;
	txtarea.selectionStart = selEnd + open.length + close.length;
	txtarea.selectionEnd = txtarea.selectionStart;
	txtarea.focus();
	txtarea.scrollTop = scrollTop;

	return;
}
function strreplace(search, replace, subject){
       var ra = replace instanceof Array,
               sa = subject instanceof Array,
               l = (search = [].concat(search)).length,
               replace = [].concat(replace),
               i = (subject = [].concat(subject)).length;
       while(j = 0, i--)
               while(subject[i] = subject[i].split(search[j]).join(ra ? replace[j] || "" : replace[0]), ++j < l);
       return sa ? subject : subject[0];
}
