var w = screen.width;
var h = screen.height;

function getRef(id) 	{ return $("#"+id); }
function getSty(id) 	{ return $("#"+id).css(); } 
function toggleDiv(id)	{ $("#"+id).toggle(); } // ('display', 'toggle'); } // v = $("#"+id).css('display'); v = (v == 'none') ? 'block' : 'none'; $("#"+id).css('display', v); }
function showDiv(id)	{ $("#"+id).show(); }
function hideDiv(id)	{ $("#"+id).hide(); }
function toggleVisibility(id) { v = $('#'+id).css('visibility') == 'hidden' ? 'visible' : 'hidden'; $('#'+id).css('visibility',$v); }
function is_defined(variable)	{ return (typeof(window[variable]) == "undefined") ? false: true; }
function in_array(id, array)	{ for (i=0; i < array.length; i++) { if (id == array[i]) { return true; } } return false; }

function askSubmit (frm, msg) { if (confirm(msg)) { document.forms[frm].submit(); } }
function askConfirmation (msg, url) { if (confirm(msg)) { self.location.href = url; } }

function toggleMore (n) { $('#'+n+'Less').hide(); $('#'+n+'More').show(); }
function toggleDisplay (container_id, link_id, text_on, text_off)
{
	$("#"+container_id).toggle();
	s = $("#"+container_id).css('display') == 'none' ? text_on : text_off; 
	$("#"+link_id).html(s);
}

function openWin(windowURL,windowName,windowFeatures) { return window.open(windowURL,windowName,windowFeatures); }

function PopWin (url,width,height,name)
{
	var left = (w - width) / 2;
	var top = (h - height) / 2;
	options = "left="+left+",top="+top+",width="+width+",height="+height;
	options += ",toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=0,resizable=0,fullscreen=no"
	openWin (url, name, options );
}

function PopWinScroll (url,width,height,name)
{
	if (height <= 0) 	{ var top = 10; var height = h-80; }
	else 				{ var top = (h - height) / 2; }
	if (width <= 0) 	{ var left = 10; var width = w-20; }
	else 				{ var left = (w - width) / 2; }
	options = "left="+left+",top="+top+",width="+width+",height="+height;
	options +=",toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=1,resizable=0,fullscreen=no"
	openWin (url, name, options );
}

friends_actions = function(username, section, option)
{
	var temp = section + '_' + username;
	var elem =  document.getElementById(temp);
	
	var load = document.getElementById(temp + '_loader');
	load.innerHTML= '<img src="/images/loading.gif" alt="loading" />';
	
	$.ajax({
	   url: '/async/ajax_friends.php?act=action&section=' + section + '&option=' + option + '&username=' + username,
	   success: function(msg){ $("#"+temp).html(msg); }
	 });
}

friends_message = function(username, section, option, temp)
{
	$.ajax({
	   url: '/async/ajax_friends.php?act=action&section=' + section + '&option=' + option + '&username=' + username,
	   success: function(msg){ $("#"+temp).html(msg); }
	 });
}

var form;
var checkflag = false;

function toggleInputs(form_name, input_name, link_id)
{
	if (typeof (document.forms[form_name]) != "undefined")
	{
		form 	= document.forms[form_name];
		inputs 	= form.elements[input_name];
		link 	= document.getElementById(link_id);
		
		if (checkflag == false) 
		{
			for (i=0; i < inputs.length; i++)
			{	
				form.elements[input_name][i].checked = true;
			}
			checkflag = true;
			link.innerHTML = "Unselect All";
		}
		else
		{
			for (i=0; i < inputs.length; i++)
			{	
				form.elements[input_name][i].checked = false;
			}
			checkflag = false;
			link.innerHTML = "Select All";
		}
	}
}

function showTagOptions (id)
{
	h = $("#tagOptions"+id).html();
	if (h)
	{
		$("#tag_action").html(h);
		$("#tag_action").css('left', mouseX+'px');
		$("#tag_action").css('top', mouseY+15+'px');
		$("#tag_action").css('visibility', 'visible');
		$("#tag_action").click (function() { $("#tag_action").css('visibility', 'hidden'); });
	}
}
function hideTagOptions (id) { $("#tagOptions"+id).hide(); }

document.onmousemove = getMouseXY;

var mouseX = 0;
var mouseY = 0;

function getMouseXY (e)
{
	if (document.all)	{ mouseX = event.clientX + document.body.scrollLeft; mouseY = event.clientY + document.body.scrollTop; }
	else 				{ mouseX = e.pageX; mouseY = e.pageY; }
	if (mouseX < 0)		{ mouseX = 0;}
	if (mouseY < 0)		{ mouseY = 0;}
	return true;
}

// http://docs.jquery.com/Cookbook/wait // EXTRA :)
$.fn.wait = function(time, type) 
{
    time = time || 1000;
    type = type || "fx";
    return this.queue(type, function() {
        var self = this;
        setTimeout(function() {
            $(self).dequeue();
        }, time);
    });
}


function getUnreadMessages()
{
	$.ajax({
	type: "POST",
	url: "/unread-messages",
	data: "",
	success: function(msg){
	  	msg = jQuery.trim(msg);
	    if (msg > 0)
	    {
	    	$("#unread-messages").html(" ("+msg+" new)");
	    }
	  }
	});
}

function setTopicStatus(element_id, cat_url, topic_id, option)
{
	$.ajax({
	   url: '/tag-'+cat_url+'-whiz/'+topic_id+'/'+option,
	   success: function(msg) { $("."+element_id).html(msg); }
	 });
}

function loadGigya()
{
	$.ajax({
		url: '/?act=widget-code&c='+$("#select_gigya").val(),
		success: function(msg) { 
			$("#gigya_code").val(msg);
			$.ajax({
				type: "GET",
				url: "/_gigya.html",
				data: "",
				success: function(msg2){ $("#gigya_content").html(msg2); }
			});
		}
	});
	
	
	
}


