var win = "width=400,height=500,left=100,top=100,copyhistory=no,directories=no,menubar=no,location=no,resizable=no,scrollbars=yes";
function get_gallery(id_prof)
{
   window.open("photos_gallery.php?ID="+id_prof,'gallery',win);
}

function ShowShowHide ( show_name, show_name2, hide_name )
{
    if (hide_name) hide_name.style.display = 'none';
    if (show_name) show_name.style.display = 'inline';
    if (show_name2) show_name2.style.display = 'inline';
}

function ShowHideHide ( show_name, hide_name, hide_name2 )
{
    if (hide_name) hide_name.style.display = 'none';
    if (hide_name2) hide_name2.style.display = 'none';
    if (show_name) show_name.style.display = 'inline';
}


/**
 * change images onHover mouse action
 */
function show(FileName,jpg1Name)
{
	document.images[FileName].src = jpg1Name;
}

/**
 * set status of the browser window to 's'
 */
function ss(s) 
{
	window.status = s;
	return true;
}

/**
 * set status of the browser window to empty
 */
function ce()
{
	window.status='';
}


/**
 * insert emotion item
 */
function emoticon( txtarea, text ) {
//	var txtarea = document.post.message;
	text = ' ' + text + ' ';
	if (txtarea.createTextRange && txtarea.caretPos) {
		var caretPos = txtarea.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
		txtarea.focus();
	} else {
		txtarea.value  += text;
		txtarea.focus();
	}
}

function launchAddToIM (id)
{
    var win = "width=600,height=160,left=100,top=100,copyhistory=no,directories=no,menubar=no,location=no,resizable=no,scrollbars=yes";
    window.open("explanation.php?explain=imadd&ID="+id,'add_to_im',win);
    return false;
}

function launchTellFriend ()
{
	var win = "width=300,height=300,left=100,top=100,copyhistory=no,directories=no,menubar=no,location=no,resizable=no,scrollbars=yes";
	window.open("../tellfriend.php",'html',win);
	return false;
}

/**
 * Checks/unchecks all tables
 *
 * @param   string   the form name
 * @param   boolean  whether to check or to uncheck the element
 *
 * @return  boolean  always true
 */
function setCheckboxes(the_form, do_check)
{
    var elts      = document.forms[the_form].elements;
    var elts_cnt  = elts.length;
	
    for (var i = 0; i < elts_cnt; i++) {
        elts[i].checked = do_check;
		if (the_form + "_submit" == elts[i].name) {
			elts[i].disabled = !do_check;
		}
    } // end for

    return true;
} // end of the 'setCheckboxes()' function

/**
 * Remove bookmark
 *
 * @param int id_item item ID
 * @param string type bookmark type - account, article or subitem
 */
function rm_bookmark(id_item, type)
{
	var h = function(result)
	{
		if (result == '1')
		{
			document.getElementById(type + '_' + id_item).style.display = 'none';
			$('#notification').slideDown();
		}
	}

	$.ajax ({
		type: "POST",
		url: "ajax.php",
		data: 'action=rm_bookmark_' + type + '&id_' + type + '=' + id_item,
		success: h
	});
}

function setArticleAvatar(id_picture)
{
	var h = function(result)
	{
		if (result > 0)
		{
			alert('Avatar changed.');
		}
	}

	$.ajax({
		type: "post",
		url: "ajax.php",
		data: "action=makeArticleAvatar&id_picture="+id_picture,
		success: h
	});
}

/**
* It's appears/disapperas hidden div
* Use as <a href="#" onclick="popup_menu(this,'dlg1');">
*
* @param element - ID of hidden DIV
*/
function popup_menu(cur, element, page_tmpl)
{
	// VALIDATE USER INPUT
	document.getElementById('pagenate').onsubmit = function()
	{
		var value = $('#pagenate input').val();
		if (value.match(/^\d+$/))
		{
			location.href=page_tmpl.replace(/%1/g, value);
			return false;
		}
		else
			return false;
	}
	// END VALIDATE
	var offset = findPos(cur);
	var el = document.getElementById(element);
	el.style.left = offset.x+"px";
	el.style.top = offset.y+cur.offsetHeight+"px";
	$(el).slideToggle('fast');
	document.onclick = function(e) {
		var obj = document.all ? event.srcElement : e.target;
		if (el.style.display == 'block' && obj != el && obj != cur && checkParent(obj,element)) {
			$(el).slideUp('fast');
		}
	}

	function checkParent(t, parent)
	{
		while(t.parentNode){ 
			if(t==document.getElementById(parent)){ 
				return false 
			}
			t=t.parentNode 
		}
		return true 
	};

	function findPos(obj)
	{
		var curleft = obj.offsetLeft || 0;
		var curtop = obj.offsetTop || 0;
		while (obj = obj.offsetParent)
		{
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
		return {x:curleft,y:curtop};
	};
};
/* END */

// change timezone for user via AJAX //
function change_timezone(elem)
{
	var f = function(result)
	{
		result = eval('(' + result + ')');
		$('#mess').html(result['msg']);
	}
	$.post('edit-account.php', 
			{action: 'change_timezone', account_id: $.cookie('xaid'), offset: elem.value},
			f);
}

function count_link(id)
{
	i = new Image();
	h = Math.random();

	i.src= root + 'click-count.php?id='+id+'&h='+h;

	return true;
}

function ConvertRowsToLinks(tableId)
{
	var rows = document.getElementById(tableId).getElementsByTagName("tr");

	for (i = 0; i < rows.length; i++)
	{
		var link = rows[i].getElementsByTagName("a");
		if (link.length == 1)
		{
	//		rows[i].onclick = new Function("document.location.href='" + link[0].href +"'");
			rows[i].onmouseover = new Function("this.className='highlight'");
			rows[i].onmouseout = new Function("this.className=''");
		}
	}
}

// jQuery plugins //
/**
* Cookies
* http://www.stilbuero.de/2006/09/17/cookie-plugin-for-jquery/
*/
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?"":e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('j.5=u(9,a,2){6(h a!=\'v\'){2=2||{};6(a===m){a=\'\';2.3=-1}4 3=\'\';6(2.3&&(h 2.3==\'n\'||2.3.k)){4 7;6(h 2.3==\'n\'){7=w C();7.B(7.z()+(2.3*A*o*o*E))}l{7=2.3}3=\'; 3=\'+7.k()}4 8=2.8?\'; 8=\'+2.8:\'\';4 b=2.b?\'; b=\'+2.b:\'\';4 c=2.c?\'; c\':\'\';d.5=[9,\'=\',q(a),3,8,b,c].t(\'\')}l{4 g=m;6(d.5&&d.5!=\'\'){4 e=d.5.x(\';\');D(4 i=0;i<e.f;i++){4 5=j.r(e[i]);6(5.p(0,9.f+1)==(9+\'=\')){g=y(5.p(9.f+1));s}}}F g}};',42,42,'||options|expires|var|cookie|if|date|path|name|value|domain|secure|document|cookies|length|cookieValue|typeof||jQuery|toUTCString|else|null|number|60|substring|encodeURIComponent|trim|break|join|function|undefined|new|split|decodeURIComponent|getTime|24|setTime|Date|for|1000|return'.split('|'),0,{}))
