function answer(c_id)
{
	if (c_id == opened_answer && document.getElementById('div_answer_'+opened_answer).style.display == 'block')
	{
		document.getElementById('div_answer_'+opened_answer).style.display = 'none';
	}
	else
	{
		document.getElementById('div_comment_body_'+opened_edit_div).style.display = 'block';
		document.getElementById('div_edit_'+opened_edit_div).style.display = 'none';
		opened_edit_div = c_id;
		
		document.getElementById('div_answer_'+opened_answer).style.display = 'none';
		document.getElementById('div_answer_'+c_id).style.display = 'block';
		opened_answer = c_id;
	}
}

function edit(c_id)
{
	document.getElementById('div_answer_'+opened_answer).style.display = 'none';
	opened_answer = c_id;
	
	document.getElementById('div_comment_body_'+opened_edit_div).style.display = 'block';
	document.getElementById('div_edit_'+opened_edit_div).style.display = 'none';
	
	document.getElementById('div_comment_body_'+c_id).style.display = 'none';
	document.getElementById('div_edit_'+c_id).style.display = 'block';
	opened_edit_div = c_id;
}

function cancel_edit(c_id)
{
	document.getElementById('div_comment_body_'+opened_edit_div).style.display = 'block';
	document.getElementById('div_edit_'+opened_edit_div).style.display = 'none';
}

function deleteNode(c_id)
{
	var delete_confirm = confirm ('Вы действительно хотите удалить эту запись? Все комментарии, принадлежащие ей, тоже будут удалены.');
	if (delete_confirm) { document.getElementById('delete_form_'+c_id).submit(); }
}

function view_thread(c_id)
{
	document.myform.event.value = '';
	document.myform.action = '/post/'+document.myform.post_id.value+'.html';
	document.myform.comment_id.value = c_id;
	document.myform.submit();
}

function change_user(id, width)
{
	document.getElementById('user_name_'+id).value = '';
	
	if (document.getElementById('cb_user_name_'+id).checked)
	{
		document.getElementById('email_notify_'+id).style.display = 'none';
		document.getElementById('div_captcha_'+id).style.display = 'none';

		var text_obj = document.getElementById('user_pass_'+id);
		
		var text_parent = text_obj.parentNode;
		var user_text = text_obj.innerHTML;
		
		text_obj.parentNode.removeChild(text_obj);
		pass_obj = document.createElement('input');
		pass_obj.setAttribute('type', 'password');
		pass_obj.setAttribute('name', 'user_pass_'+id);
		pass_obj.setAttribute('id', 'user_pass_'+id);
		
		text_parent.appendChild(pass_obj);
		if (window.ActiveXObject)
		{
			pass_obj.attachEvent('onclick',HideBaloon); //  IE
		}
		else
		{
			pass_obj.setAttribute("onclick","HideBaloon();" ); //MOZ & OPERA
		}
		pass_obj.style.width = width+'px';
		

		document.getElementById('remember_'+id).style.display = 'block';
		document.getElementById('span_login_'+id).innerHTML = "&nbsp;&ndash;&nbsp;Ваш&nbsp;login";
		document.getElementById('span_pass_'+id).innerHTML = "&nbsp;&ndash;&nbsp;Пароль";
	}
	else
	{
		document.getElementById('remember_'+id).style.display = 'none';
		document.getElementById('email_notify_'+id).style.display = 'block';
		document.getElementById('div_captcha_'+id).style.display = 'block';
		
		var pass_obj = document.getElementById('user_pass_'+id);
		var pass_parent = pass_obj.parentNode;
		pass_obj.parentNode.removeChild(pass_obj);
		text_obj = document.createElement('input');
		text_obj.setAttribute('type', 'text');
		text_obj.setAttribute('name', 'user_pass_'+id);
		text_obj.setAttribute('id', 'user_pass_'+id);
		
		pass_parent.appendChild(text_obj);
		if (window.ActiveXObject)
		{
			text_obj.attachEvent('onclick',HideBaloon); //  IE
		}
		else
		{
			text_obj.setAttribute("onclick","HideBaloon();" ); //MOZ & OPERA
		}
		
		text_obj.style.width = width+'px';
		
		document.getElementById('span_login_'+id).innerHTML = "&nbsp;&ndash;&nbsp;Ваше&nbsp;имя";
		document.getElementById('span_pass_'+id).innerHTML = "&nbsp;&ndash;&nbsp;Эл.&nbsp;почта";
	}

		HideBaloon();

	
}

function reload_captcha(c_id)
{
	var now = new Date();
	document.getElementById('cap_'+c_id).src = '/cap/?'+ now.getTime();
}

function change_subscribe(post_id)
{
	var is_subscribed = comment_validate.change_subscribe_status(post_id);
	if (is_subscribed == 'deleted')
	{
		document.getElementById('subscribe_text').innerHTML = "Вы не подписаны на рассылку комментариев по электронной почте";
		document.getElementById('subscribe').checked = false;
	}
	else
	{
		document.getElementById('subscribe_text').innerHTML = "Вы подписаны на рассылку комментариев по электронной почте";
		document.getElementById('subscribe').checked = true;
	}
}

function change_to_anonym(c_id, name, pass)
{
	document.getElementById('anonym_'+c_id).checked = true;
	change_user(c_id);
	document.getElementById('user_name_'+c_id).value = name;
	document.getElementById('user_pass_'+c_id).value = pass;
}

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
