<!--
var id1 = null;

function getXmlHttpRequestObject() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest(); //Not IE
	} else if(window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP"); //IE
	} else {
		//Display error message here and inform the user they might want to upgrade their browser.
		alert("Your browser doesn't support the XmlHttpRequest object.  Better upgrade to Firefox.");
	}
}
//Get our browser specific XmlHttpRequest object.
var receiveReq  = getXmlHttpRequestObject();
//Initiate the asyncronous request.
function updateDivs(id) {
        id1 = id
	//If our XmlHttpRequest object is not in the middle of a request, start the new asyncronous call.
	if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
		//Setup the connection as a GET call to getpercent.php.
		//True explicity sets the request to asyncronous (default).
		receiveReq.open("GET", '/ajax/reply_prog_comment.php?'+formVars, true);
		//Set the function that will be called when the XmlHttpRequest objects state changes.
		receiveReq.onreadystatechange = handlePercent;

		//Make the actual request.
		receiveReq.send(null);
	}

}

function nupdateDivs(id) {
        id1 = id
	//If our XmlHttpRequest object is not in the middle of a request, start the new asyncronous call.
	if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
		//Setup the connection as a GET call to getpercent.php.
		//True explicity sets the request to asyncronous (default).
		receiveReq.open("GET", '/ajax/reply_news_comment.php?'+formVars, true);
		//Set the function that will be called when the XmlHttpRequest objects state changes.
		receiveReq.onreadystatechange = handlePercent;

		//Make the actual request.
		receiveReq.send(null);
	}

}

//Initiate the asyncronous request.
function aupdateDivs(id) {
        id1 = id
	//If our XmlHttpRequest object is not in the middle of a request, start the new asyncronous call.
	if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
		//Setup the connection as a GET call to getpercent.php.
		//True explicity sets the request to asyncronous (default).
		receiveReq.open("GET", '/ajax/answer.php?'+formVars, true);
		//Set the function that will be called when the XmlHttpRequest objects state changes.
		receiveReq.onreadystatechange = handlePercent;

		//Make the actual request.
		receiveReq.send(null);
	}

}
function load_reasonwin(id)
{
        id1 = id
	//If our XmlHttpRequest object is not in the middle of a request, start the new asyncronous call.
	if (receiveReq.readyState == 4 || receiveReq.readyState == 0)
	{
		//Setup the connection as a GET call to getpercent.php.
		//True explicity sets the request to asyncronous (default).
		receiveReq.open("GET", '/ajax/reasonwin.php?'+formVars, true);
		//Set the function that will be called when the XmlHttpRequest objects state changes.
		receiveReq.onreadystatechange = handlePercent;

		//Make the actual request.
		receiveReq.send(null);
	}
}
function load_renameguidwin(id)
{
        id1 = id
	//If our XmlHttpRequest object is not in the middle of a request, start the new asyncronous call.
	if (receiveReq.readyState == 4 || receiveReq.readyState == 0)
	{
		//Setup the connection as a GET call to getpercent.php.
		//True explicity sets the request to asyncronous (default).
		receiveReq.open("GET", '/ajax/renameguidwin.php?'+formVars, true);
		//Set the function that will be called when the XmlHttpRequest objects state changes.
		receiveReq.onreadystatechange = handlePercent;

		//Make the actual request.
		receiveReq.send(null);
	}
}

/**
* function update_reason_div(id)
* {
*         id1 = id
* 	//If our XmlHttpRequest object is not in the middle of a request, start the new asyncronous call.
* 	if (receiveReq.readyState == 4 || receiveReq.readyState == 0)
* 	{
* 		//Setup the connection as a GET call to getpercent.php.
* 		//True explicity sets the request to asyncronous (default).
* 		receiveReq.open("GET", '/ajax/reasonwin.php?'+formVars, true);
* 		//Set the function that will be called when the XmlHttpRequest objects state changes.
* 		receiveReq.onreadystatechange = handlePercent;

* 		//Make the actual request.
* 		receiveReq.send(null);
* 	}
* }
* function update_soft_reason_div(id)
* {
*         id1 = id
* 	//If our XmlHttpRequest object is not in the middle of a request, start the new asyncronous call.
* 	if (receiveReq.readyState == 4 || receiveReq.readyState == 0)
* 	{
* 		//Setup the connection as a GET call to getpercent.php.
* 		//True explicity sets the request to asyncronous (default).
* 		receiveReq.open("GET", '/ajax/reasonwin.php?'+formVars, true);
* 		//Set the function that will be called when the XmlHttpRequest objects state changes.
* 		receiveReq.onreadystatechange = handlePercent;

* 		//Make the actual request.
* 		receiveReq.send(null);
* 	}
* }
* function update_mostsoft_reason_div(id)
* {
*         id1 = id
* 	//If our XmlHttpRequest object is not in the middle of a request, start the new asyncronous call.
* 	if (receiveReq.readyState == 4 || receiveReq.readyState == 0)
* 	{
* 		//Setup the connection as a GET call to getpercent.php.
* 		//True explicity sets the request to asyncronous (default).
* 		receiveReq.open("GET", '/ajax/reasonwin.php?'+formVars, true);
* 		//Set the function that will be called when the XmlHttpRequest objects state changes.
* 		receiveReq.onreadystatechange = handlePercent;

* 		//Make the actual request.
* 		receiveReq.send(null);
* 	}
* }
* function prog_update_reason_div(id)
* {
*         id1 = id
* 	//If our XmlHttpRequest object is not in the middle of a request, start the new asyncronous call.
* 	if (receiveReq.readyState == 4 || receiveReq.readyState == 0)
* 	{
* 		//Setup the connection as a GET call to getpercent.php.
* 		//True explicity sets the request to asyncronous (default).
* 		receiveReq.open("GET", '/ajax/reasonwin.php?'+formVars, true);
* 		//Set the function that will be called when the XmlHttpRequest objects state changes.
* 		receiveReq.onreadystatechange = handlePercent;

* 		//Make the actual request.
* 		receiveReq.send(null);
* 	}
* }
*/
function prog_wrong_vers_div(id)
{
        id1 = id
	//If our XmlHttpRequest object is not in the middle of a request, start the new asyncronous call.
	if (receiveReq.readyState == 4 || receiveReq.readyState == 0)
	{
		//Setup the connection as a GET call to getpercent.php.
		//True explicity sets the request to asyncronous (default).
		receiveReq.open('GET', '/ajax/wrong_vers_alias.php?'+formVars, true);
		//Set the function that will be called when the XmlHttpRequest objects state changes.
		receiveReq.onreadystatechange = handlePercent;

		//Make the actual request.
		receiveReq.send(null);
	}
}

//Called every time our XmlHttpRequest objects state changes.
function handlePercent() {
	//Check to see if the XmlHttpRequests state is finished.
	if (receiveReq.readyState == 4) {
		//Set the contents of our span element to the result of the asyncronous call.
//		document.getElementById(id1).innerHTML = receiveReq.responseText;
		id1.innerHTML = receiveReq.responseText;
	}
}

//crossbrowser load function
function addEvent(elm, evType, fn, useCapture)
{
  if (elm.addEventListener){
    elm.addEventListener(evType, fn, useCapture);
    return true;
  } else if (elm.attachEvent){
    var r = elm.attachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Please upgrade your browser to use full functionality on this page");
  }
}


//sets post/get vars for update

function setVarsForm(vars){
    formVars  = vars;
}

function prog_open_subscribe_win(uid, pid, d)
{
	var d1 = d.parentNode.getElementsByTagName('div')[1];

	if (d1.style.display == 'none')
	{

		if (lastdiv!=null)
			lastdiv.style.display = 'none';

		d1.style.display = 'block';

		setVarsForm("uid="+uid+"&pid="+pid);
		prog_update_subscribe_div(d1);

		lastdiv=d1;
	}

	return false;
}

function show_version_edit(suid, d)
{
	var div = d.parentNode.parentNode.parentNode.getElementsByTagName('div');
	div = div[0];

	if (div.style.display == 'none')
	{
		if (lastdiv!=null)
			lastdiv.style.display = 'none';

		div.style.display = 'block';

		setVarsForm("suid="+suid);

		prog_wrong_vers_div(div);

		lastdiv=div;
	}
}

function prog_approve_curr_version(suid, suggest_vers, d, isforbid)
{
	if (isforbid == 1)
	{
		alert("Your installed version 0.0 is not recognized. Please, check the actual version number.")
		return;
	}

	setVarsForm('suid='+suid+'&suggest_vers='+suggest_vers);
	var div = d.parentNode.parentNode.parentNode;
	update_version_alias(div);
}

function prog_set_right_version(suid, d)
{
	var suggest_vers = d.parentNode.parentNode.getElementsByTagName('input')[0].value;
	var comment = d.parentNode.parentNode.getElementsByTagName('textarea')[0].value;

	if (suggest_vers.length < 1)
	{
		alert("Please enter right version number!");
	}
	else
	{
		setVarsForm('suid='+suid+'&suggest_vers='+escape(suggest_vers)+"&comm="+escape(comment));

		var div = d.parentNode.parentNode.parentNode.parentNode;

		update_version_alias(div)

		hide_reasonwin(d);
		return true;
	}
}

function update_version_alias(d)
{
	new Ajax.Request('/ajax/version_alias.php?'+formVars,
		{
			method: "GET",
			onSuccess: function(transport)
			{
				d.innerHTML = transport.responseText;
			}
		}
	);

	return true;
}

function prog_update_subscribe_div(id)
{
  id1 = id;
  //If our XmlHttpRequest object is not in the middle of a request, start the new asyncronous call.
  if (receiveReq.readyState == 4 || receiveReq.readyState == 0)
  {
  	//Setup the connection as a GET call to getpercent.php.
  	//True explicity sets the request to asyncronous (default).
  	receiveReq.open("GET", '/ajax/program_subscribe.php?'+formVars, true);
  	//receiveReq.open("GET", '/ajax/reasonwin.php?'+formVars, true);
  	//Set the function that will be called when the XmlHttpRequest objects state changes.
  	receiveReq.onreadystatechange = handlePercent;

  	//Make the actual request.
  	receiveReq.send(null);
  }
}

function comment_subscribe(cid, uid, pid, d)
{
	var vars = 'pid='+pid+'&uid='+uid+'&cid='+cid;
  	var c = new Ajax.Updater(d.parentNode, '/ajax/subscribe_branch_comm.php?', {method: "get", parameters: vars});
}

function prog_set_user_subscr_comm(uid, pid, id)
{
	formVars = 'uid='+uid+'&pid='+pid+'&id='+id;
}

function prog_set_user_subscr(uid, pid, d)
{
  var subscr1 = d.parentNode.parentNode.getElementsByTagName('input')[0].checked;
  var subscr2 = d.parentNode.parentNode.getElementsByTagName('input')[1].checked;
  var subscr3 = d.parentNode.parentNode.getElementsByTagName('input')[2].checked;
  //у нас есть подписки.
  //теперь надо отправить запрос с открытием файла
  formVars = 'uid='+uid+'&pid='+pid;

  if (subscr1)
  {
  	formVars += '&subscr_ver=1';
  }

  if (subscr2)
  {
  	formVars += '&subscr_comm=1';
  }

  if (subscr3)
  {
  	formVars += '&subscr_quest=1';
  }

  var c = new Ajax.Request('/ajax/subscribe.php?'+formVars, {method: "get"});

  prog_hide_subscribe_win(d);

  //var d4 = document.getElementById("notify");
  //var p = d4.childNodes[0];

  //p.innerHTML = 'You succesfully changed your subscriptions.';

  return true;
}

function prog_hide_subscribe_win(d)
{
	d = d.parentNode.parentNode.parentNode;
	if (d.style.display != 'none')
	{
		d.style.display = 'none';
		lastdiv=null;
	}
}

var lastdiv = null;
function sa_alert_win(uid, vid, t, d)
{
	if (lastdiv!=null)
		lastdiv.style.display = 'none';

	var d1 = d.parentNode.getElementsByTagName('div')[0];
	d1.style.display = 'block';
	lastdiv=d1;

	setVarsForm("uid="+uid+"&vid="+vid+"&t="+t);
	sa_update_div(d1);

	return false;
}

function sa_update_div(id)
{
  id1 = id;
  if (receiveReq.readyState == 4 || receiveReq.readyState == 0)
  {
  	receiveReq.open("GET", '/ajax/sa_confirm.php?'+formVars, true);
  	receiveReq.onreadystatechange = handlePercent;
  	receiveReq.send(null);
  }
}

function friend_user(friend_id, act, d1)
{
	var vars = 'fr_id='+friend_id+'&act='+act;
	setVarsForm(vars);
	var c = new Ajax.Request('/ajax/friend.php?'+formVars,
		{
			method: "get",

			onSuccess: function(transport)
			{
				var response = transport.responseText;
				var d = document.getElementById('action_friend');

				if (response.indexOf('confirm') == 0)
					d.innerHTML = '<img id="friend" src="http://img.informer.com/images/add_friend.gif">&nbsp;<a href="#" onclick="friend_user('+friend_id+', \'remove\'); return false">Remove my request</a>';

				if (response.indexOf('add') == 0)
					d.innerHTML = '<img id="friend" src="http://img.informer.com/images/add_friend.gif">&nbsp;<a href="#" onclick="friend_user('+friend_id+', \'remove\'); return false">Remove from friends</a>';

				if (response.indexOf('remove') == 0)
				{
					if (d != null)
						d.innerHTML = '<img id="friend" src="http://img.informer.com/images/add_friend.gif">&nbsp;<a href="#" onclick="friend_user('+friend_id+', \'add\'); return false">Add as a friend</a>';
					else
						if (d1 != null)
							d1.parentNode.parentNode.innerHTML = 'The request was canceled.';
				}

				if (response.indexOf('already') == 0)
					d.innerHTML = '<img id="friend" src="http://img.informer.com/images/add_friend.gif">&nbsp;This user is already your friend';

				if (response == 'accept')
				{
					d = $('request_msg');
					if (d1 != null)
						d1.parentNode.parentNode.innerHTML = 'The request was accepted.';
					else
						d.innerHTML = 'The request was accepted.';
				}

				if (response == 'decline')
				{
					d = $('request_msg');
					if (d1 != null)
						d1.parentNode.parentNode.innerHTML =  'The request was rejected.';
					else
						d.innerHTML =  'The request was rejected.';
				}
			}
		}
	);
}

function updateContacts(user_id, unread ,d)
{
	if (unread > 0)
	{
		id1 = document.getElementById('requests_friends');
		var btns = document.getElementById('requests_buttons');
		d.parentNode.parentNode.parentNode.removeChild(btns);
	}
	else
		id1 = d.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;

  if (receiveReq.readyState == 4 || receiveReq.readyState == 0)
  {
  	receiveReq.open("GET", '/ajax/update_contacts.php?id='+user_id, true);
  	receiveReq.onreadystatechange = handlePercent;
  	receiveReq.send(null);
  }
}

function updateNotification()
{
	id1 = $('notifications');

	if (receiveReq.readyState == 4 || receiveReq.readyState == 0)
	{
		receiveReq.open("GET", '/ajax/update_notifications.php', true);
		receiveReq.onreadystatechange = Effect.Shrink(id1, {direction: 'top-left'});
		receiveReq.send(null);
	}
}

function deleteContact(person_id, d)
{
	id1 = d.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;

  if (receiveReq.readyState == 4 || receiveReq.readyState == 0)
  {
  	receiveReq.open("GET", '/ajax/update_contacts.php?id='+person_id, true);
  	receiveReq.onreadystatechange = function()
  	{
  		if (receiveReq.readyState == 4)
  		{
			if (receiveReq.responseText != '')
				id1 = id1.parentNode.parentNode.parentNode.parentNode;

			if (receiveReq.responseText == '')
			{
				id1.innerHTML += '<p id="dlab'+person_id+'" class="gray" style="display:none; text-align: center; color: gray; font-weight: bold; margin-top: 30px">The user has been removed from your friend list</p>';
				new Effect.Fade('user'+person_id, {duration: 0.5, queue: 'front' });
				new Effect.Appear('dlab'+person_id, {duration: 0, queue: 'end' });
			}
			else
				id1.innerHTML = receiveReq.responseText;
  		}
  	}
  	receiveReq.send(null);
  }
}

function message_popup(mylink, windowname, reciever_id, message_id)
{
	if (message_id == undefined)
		message_id = 0;

	if (!window.focus)
		return true;

	var href;

	if (typeof(mylink) == 'string')
	   href=mylink;
	else
	   href=mylink.href;

	window.open(href + '?reciever_id='+reciever_id+'&message='+message_id, 'Test window', 'width=760,height=200,scrollbars=no');
	return false;
}

function delete_message(message_id, type, d)
{
	var tr = $('reply_'+message_id);

	new Ajax.Request('/ajax/messages.php?id='+message_id+'&type='+type,
		{
			method: "GET",
			onSuccess: function(transport)
			{
				d.parentNode.parentNode.parentNode.parentNode.removeChild(tr);

				if (transport.responseText == 0)
				{
					if (type == 'inbox')
						$('messages_list').innerHTML = '<p class="nomess">Your inbox is empty.</p>'
					if (type == 'outbox')
						$('messages_list').innerHTML = '<p class="nomess">Your outbox is empty.</p>'
				}
			}
		}
	);
}

function show_message(message_id, act ,d)
{
	var pm_block = document.getElementById('pm_'+message_id);
	var message_tr = d.parentNode.parentNode.parentNode.parentNode;

	if (act == 'show_in')
	{
		d.parentNode.innerHTML = '<a style="color: grey" href="#" onclick="show_message('+message_id+', \'hide\', this); return false;">Hide message</a>';
		id1 = pm_block;
		message_tr.className = 'read';
	}
	else if (act == 'show_out')
	{
		d.parentNode.innerHTML = '<a style="color: grey" href="#" onclick="show_message('+message_id+', \'hide\', this); return false;">Hide message</a>';
		id1 = pm_block;
	}
	else if (act == 'hide')
	{
		d.parentNode.innerHTML = '<a style="color: grey" href="#" onclick="show_message('+message_id+', \'show_out\', this); return false;">Show message</a>';
	}
	else if (act == 'read')
	{
		id1 = d;
		message_tr.className = 'read';
	}


	if (receiveReq.readyState == 4 || receiveReq.readyState == 0)
	{
		receiveReq.open("GET", '/ajax/messages.php?id='+message_id+'&type='+act, true);
		receiveReq.onreadystatechange = handlePercent;
		receiveReq.send(null);
	}
}

function show_pm_reply(message_id, is_outbox, d)
{
	var message_tr = d.parentNode.parentNode.parentNode.parentNode;

	if (!is_outbox)
		message_tr.className = 'read';

	d.parentNode.innerHTML = '<a style="color: grey" href="#" onclick="hide_pm_reply('+message_id+', '+is_outbox+',this); return false;">Close</a>';
	var vars = 'message_id='+message_id+'&out='+is_outbox;

	var span = document.getElementById('reply_'+message_id);
	span.style.display = 'block';
	var c = new Ajax.Updater(span, '/ajax/reply_private_message.php?', {method: "get", parameters: vars});
}

function hide_pm_reply(message_id, is_outbox)
{
	var span = document.getElementById('reply_link_'+message_id);
	span.innerHTML = '<a style="color: grey" href="#" onclick="show_pm_reply('+message_id+', ' + is_outbox + ', this); return false;">'+(is_outbox ? 'Another one' : 'Reply')+'</a>';
	var span = document.getElementById('reply_'+message_id);
	span.style.display = 'none';
}

function show_sendmessage(user_id, reply ,d)
{
	if (reply > 0)
	{
		var message_tr = d.parentNode.parentNode.parentNode.parentNode;
		message_tr.className = 'read';
	}

	vars = 'user_id=' + user_id + '&reply=' + reply;

	new Ajax.Request('/ajax/send_message.php?'+vars,
		{
			method: "GET",
			onSuccess: function(transport)
			{
			    var div = document.createElement('div');
			    div.id = 'pm_html_code';
			    document.body.appendChild(div);

				var pm_html = document.getElementById('pm_html_code');
				pm_html.innerHTML = transport.responseText;

				var pm_div = $('bgfrm');
				if (window.innerHeight  > 469)
				{
					pm_div.parentNode.style.marginTop  = "205px";
				}
				else
				{
					var temp = (window.innerHeight - 264) / 2;
					if (temp < 0) temp = 0;
					temp+= "px";
					pm_div.parentNode.style.marginTop = temp;
				}

				return false;
			}
		}
	);
}

function close_sendmessage()
{
	//var body = document.getElementsByTagName('body');
	document.body.removeChild($('pm_html_code'));
}

function spam_message(d)
{
	var message = d.parentNode.parentNode.parentNode;
	var id = 0;

	if (message.id.indexOf('reply') == 0)
	{
		id = message.id.substring(6);
	}
	var tr = $('reply_'+id);
	vars = 'id=' + id + '&type=spam';

	if (id != 0)
		new Ajax.Request('/ajax/messages.php?'+vars,
			{
				method: "GET",
				onSuccess: function(transport)
				{
					d.parentNode.parentNode.parentNode.parentNode.removeChild(tr);
				}
			}
		);
}

//pm smiles
function moretime_sm()
{
  if (idsm) clearTimeout(idsm);
}

function onout_sm(ob)
{
  this.smilestab = ob;
  idsm = setTimeout( "sm_close()", 500); // seconds delay to close div
}


function sm_open (ob)
{
	var div1 = ob.parentNode.getElementsByTagName('div')[0];

	if (div1.style.display=='none')
	{
		div1.style.display = 'block';
		moretime_sm();
	}
	else
		div1.style.display = 'none';

}
function sm_close2 ()
{
	var div1 = smilestab.parentNode;
	div1.style.display = 'none';
}
function sm_close (ob)
{
//	TODO //	try to close all smiles boxes

	if (ob)
		ob.style.display = 'none';
	else
		smilestab.style.display = 'none';
}

function sm_more (ob)
{
	var div1 = ob.parentNode.getElementsByTagName('div')[0];
	var div2 = ob.parentNode.getElementsByTagName('span')[0];
	if (div1.style.display == 'none')
	{
		div2.innerHTML = 'Hide extra emotions'
		div1.style.display = 'block';
	}
	else
	{
		div2.innerHTML = 'More emotions'
		div1.style.display = 'none';
	}
}
function addsmile(ob, abr)
{
	div1 = ob.parentNode.parentNode.parentNode.parentNode.parentNode;
	div1.style.display = 'none';
	txtar = div1.parentNode.parentNode.getElementsByTagName('textarea')[0];
	alert(txtar.cursor);
	txtar.value += abr;

}

function emoticon(ob, text, tip)
{
	if (tip == '1') var smdiv = ob.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
	else var smdiv = ob.parentNode.parentNode.parentNode.parentNode.parentNode;
	smdiv.style.display = 'none';

	var txtarea = smdiv.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('textarea')[0];
	text = ' ' + text + ' ';
	// for Opera and IE
	if (txtarea.createTextRange && txtarea.caretPos)
	{
		var caretPos = txtarea.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;

	}
	else
	{
		// for Firefox
		var es = txtarea.selectionStart; // define coordinates of the cursor
		if (es)
		{
			var txt1 = txtarea.value.substring(0, es); // assign txt1 part of text before cursor
			var txt2 = txtarea.value.substring(es, txtarea.value.length); // assign txt2 part of text after cursor
			txtarea.value = txt1 + text + txt2;  // concatenate	all parts
		}
		else if (es == '0') // cursor on start
		{
			txtarea.value = text + txtarea.value;
		}
		else
		{
			txtarea.value += text;
		}
	}
	txtarea.focus();
}

//


-->
