function OpenPopup(url,w,h)
{
	window.open(url, '', 'scrollbars=yes,resizable=yes,width='+w+',height='+h+',screenX=100,screenY=100');
	return(false);
}

function _getFormAction(e)
{
    for (var i = 0; i < e.attributes.length; i++) 
    {
    	var a = e.attributes[i];
        var k = a.nodeName;
        if (k == 'action') 	
	{
        	return(a.value);
       	}
    }
    return(false);
}
function _setFormAction(e,action)
{
    for (var i = 0; i < e.attributes.length; i++) 
    {
    	var a = e.attributes[i];
        var k = a.nodeName;
        if (k == 'action') 	
	{
		a.value=action;
        	return(true);
       	}
    }
    return(false);
}
function swap_ssl(c)
{
	var f=document.getElementById('login_form');
	if (!f) return;
	var action=_getFormAction(f);
	if (c) _setFormAction(f, action.replace('http://', 'https://'));
	else _setFormAction(f, action.replace('https://', 'http://'));
}

var xajaxRequestUri="/index.php";
var xajaxDebug=false;
var xajaxStatusMessages=false;
var xajaxWaitCursor=true;
var xajaxDefinedGet=0;
var xajaxDefinedPost=1;
var xajaxLoaded=false;
selected_user=0;

function align_user_menu(menu)
{
	var card_width = 290;
	var card_height = menu.height();
	var left=parseInt(menu.css('left'));
	var top=parseInt(menu.css('top'));
	
	if (left+card_width > document.documentElement.clientWidth-10)
	{
		//menu.css('left', (document.documentElement.clientWidth - card_width - 20)+'px');
		menu.css('left', (left-card_width-10)+'px');
	}	
	if (top+card_height > (jQuery(window).scrollTop() + document.documentElement.clientHeight - 10))
	{
		//menu.css('top', (jQuery(window).scrollTop() + document.documentElement.clientHeight - card_height - 20)+'px');
		menu.css('top', (top-card_height-10)+'px');
	}
}




function process_user_link(link_obj)
{
link_obj.find('a.UserLink').bind('click', function(){selected_user=jQuery(this).attr('uid');return false;}).contextMenu('UserMenu',{
	onShowMenu: function(e,menu) {
		var id=selected_user;
		var m=false;
		eval('if (typeof(user_menu'+id+')!="undefined") m=user_menu'+id+';');
		//if (typeof(m)!='undefined' && m!=false) {
		//	jQuery('#jqContextMenu').html(m);
		//}
		//else {
			jQuery('#jqContextMenu').html('<img src="/image/ajax-loader.gif" width="16" height="16">');
			xajax_user_menu(id);
			
			
		//}
        return menu;
      }
});
}
jQuery(document).ready(function(){ process_user_link(jQuery(this)); });

/*jQuery(document).ready(function(){ 
	
	
	jQuery('a.UserLink').bind('click', function(){selected_user=jQuery(this).attr('uid');return false;}).contextMenu('UserMenu',{
	onShowMenu: function(e,menu) {
		var id=selected_user;
		var m=false;
		eval('if (typeof(user_menu'+id+')!="undefined") m=user_menu'+id+';');
		if (typeof(m)!='undefined' && m!=false) {
			jQuery('#jqContextMenu').html(m);
		}
		else {
			jQuery('#jqContextMenu').html('<img src="/image/ajax-loader.gif" width="16" height="16">');
			xajax_user_menu(id);
		}
        return menu;
      }
});  

});*/

function xajax_user_menu(){xajaxRequestUri='/index.php';return xajax.call("user_menu",arguments,1);}
function xajax_link_viewed(){xajaxRequestUri='/story.php';return xajax.call("link_viewed",arguments,1);}
function set_user_menu(id,html)
{
	eval('user_menu'+id+'=html;');
		
	jQuery('#jqContextMenu').html(html);
	
	var card_width = 250;
	var card_height =  $('#jqContextMenu').height();
	var left=parseInt( $('#jqContextMenu').css('left'));
	var top=parseInt( $('#jqContextMenu').css('top'));
	
	if (left+card_width > document.documentElement.clientWidth-10)
	{
		//menu.css('left', (document.documentElement.clientWidth - card_width - 20)+'px');
		 $('#jqContextMenu').css('left', (left-card_width-10)+'px');
	}	
	if (top+card_height > (jQuery(window).scrollTop() + document.documentElement.clientHeight - 10))
	{
		//menu.css('top', (jQuery(window).scrollTop() + document.documentElement.clientHeight - card_height - 20)+'px');
		 $('#jqContextMenu').css('top', (top-card_height-10)+'px');
	}	 
}
