
function AskLogout()
{
	if(confirm('Are you sure you want to log out of your account?'))
		window.location='/login.php?do=logout&noTemplate=1';
}

function AjaxRequest(url,params,h_success,h_error)
{
	var aj = new Ajax.Request(
	url, 
	{
		requestTimeout: 1,
		parameters:params, 
		onSuccess: function(t) {
			if(t.responseText.length > 1000000)
			{
				if(!confirm('This request is too big and may cause your computer to slow down or freeze!\n\nDo you want to continue?'))
					return 0;
			}
			h_success(t);
		},
		onFailure: h_error,
		onTimeout: function() {
			alert('Error, request timeout!');
		}
	});	
}

function FadeOutObject(id)
{
	var fd = document.getElementById(id);
	if(fd)
		fd.style.opacity = '.45';
}

function FadeInObject(id)
{
	var fd = document.getElementById(id);
	if(fd)
		fd.style.opacity = '1';
}

function BuildQueryStringFromForm(f)
{
	var inps = f.getElementsByTagName('input'); 
	var sels = f.getElementsByTagName('select'); 
	var txtarea = f.getElementsByTagName('textarea'); 
	var qs = '';
	
	// Do all of the inputs
	for(var i=0;i<inps.length;i++)
	{
		if(!inps[i].name)
			continue;
	
		var l_type = inps[i].type;
		if(l_type == 'checkbox' || l_type == 'radio')
		{
			if(inps[i].checked == true)
			{
				qs += '&' + inps[i].name + '=' + escape(inps[i].value);
			}
		}
		else
		{
			qs += '&' + inps[i].name + '=' + escape(inps[i].value);
		}
	}
	
	// Do all of the selects
	for(var i=0;i<sels.length;i++)
	{
		if(!sels[i].name)
			continue;

		if(sels[i].multiple == true)
		{
			for(var j=0;j<sels[i].length;j++)
			{
				if(sels[i][j].selected == true)
				{
					qs += '&' + sels[i].name + '=' + escape(sels[i][j].value);
				}				
			}
		}
		else
		{
			qs += '&' + sels[i].name + '=' + escape(sels[i][sels[i].selectedIndex].value);
		}
	}
	
	// Do all of the textareas
	for(var i=0;i<txtarea.length;i++)
	{
		qs += '&' + txtarea[i].name + '=' + escape(txtarea[i].value);
	}
	
	// Remove the first &
	qs = qs.replace(/^\&/,"");

	return qs;	
}

function SelectOptionByValue(select,value)
{
	for(var i=0;i<select.length;i++)
	{
		if(select[i].value == value)
		{
			select.selectedIndex = i;
			continue;
		}
	}
}

function GetSelectValue(select)
{
	if(select.selectedIndex >= 0)
		return select[select.selectedIndex].value;
	else
		return false;
}

var currenttime = 'March 10, 2010 09:43:31'
var date_obj = new Date(currenttime);

var add_secs = 0;
var MONTH_NAMES=new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
	
		
function updateTime(id)
{
	if(!id)
		id = 'real_time';

 	// Get our html obj
	var obj = document.getElementById(id);

	//date_obj.setTime(1268232211000 + (add_secs * 1000));
	date_obj.setSeconds(date_obj.getSeconds()+1)

	var month	= date_obj.getMonth()
	var day		= date_obj.getDate();
	var year	= date_obj.getFullYear();
	var hour	= date_obj.getHours();
	var min		= date_obj.getMinutes();
	var sec		= date_obj.getSeconds();

	var ampm	= 'am';
	if(hour > 12)
	{
		hour -= 12;
		ampm = 'pm';
	}
	else if(hour == 12)
	{
		ampm = 'pm';	
	}
	
	if(hour == 0)
		hour = '12';

	// Fix the second and min
	if(min < 10)
		min = "0" + min;
	if(sec < 10)
		sec = "0" + sec;

	var dstr = day.toString();

	var suf = 'th';
	var last_num = dstr.substr(1,dstr.length - 1);
	
	if(last_num == 1)
		suf = 'st';
	else if(last_num == 2)
		suf = 'nd';
	else if(last_num == 3)
		suf = 'rd';

	obj.innerHTML = MONTH_NAMES[month + 12] + ' ' + day + suf + ', ' + year + ' ' + hour + ':' + min + ':' + sec + ' ' + ampm;

	// Add another second
	add_secs++;

	// Keep callin our function
	setTimeout("updateTime('" + id + "')",1000);
}

function PopupViewMember(id)
{
	var popW = 690;
	var popH = 480;

	var leftPos = (window.screen.width / 2) - ((popW + 10) / 2);
	var topPos = (window.screen.height / 2) - ((popH + 50) / 2);
	
	var w = window.open('/interface/admin_members.php?do=edit&noTemplate=1&id=' + id,'admin_members_' + id,'width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos + ',resizable=no,scrollbars=yes');
	w.focus();	
}

function PopupMemberProfile(id)
{
	//alert(id);
}

// ================= Help Popup Mouseovers ======================
OffsetX=15; /* -110 */
OffsetY=15;
var old,skn,iex=(document.all),yyy=-1000;
var ns4=document.layers
var ns6=document.getElementById&&!document.all
var ie4=document.all

function init_helppopup()
{
	var pdq = document.createElement('div');
	pdq.setAttribute('id','pdq');
	document.body.appendChild(pdq);

	if (ns4) skn=document.pdq
	else if (ns6) skn=document.getElementById("pdq").style
	else if (ie4) skn=document.all.pdq.style
	if (ns4) document.captureEvents(Event.MOUSEMOVE);
	else {
		if(typeof(skn) != 'undefined')
		{	
			skn.visibility="visible"
			skn.display="none"
		}
	}
	document.onmousemove=get_mouse;
}


function popup(msg)
{
	var content="<div class=boxpopup>"+msg+"</div>";
	yyy=OffsetY;
	
	if(typeof(skn) == 'undefined')
		return 0;
	
	if(ns4)
	{
		skn.document.write(content);
		skn.document.close();
		skn.visibility="visible";	
	}
	
	if(ns6){
		document.getElementById("pdq").innerHTML=content;
		skn.display='';
	}
	if(ie4){
		document.all("pdq").innerHTML=content;
		skn.display='';
	}
}

function get_mouse(e)
{
	var winW = 630, winH = 460;
	if (parseInt(navigator.appVersion)>3)
	{
		if (navigator.appName=="Netscape")
		{
			winW = window.innerWidth;
			winH = window.innerHeight;
		}
		if (navigator.appName.indexOf("Microsoft")!=-1) 
		{
			winW = document.body.offsetWidth;
			winH = document.body.offsetHeight;
		}
	}
	
	// Make sure we don't go over the bounds of the window
	var x=(ns4||ns6)?e.pageX:event.x+document.body.scrollLeft;
	var new_left = x+OffsetX;
	if(new_left + 290 >= winW)
		new_left = winW - 290;
	else if(new_left <= 10)
		new_left = 10;
		

	if(typeof(skn) == 'undefined')
		return 0;

	skn.left=new_left;

	var y=(ns4||ns6)?e.pageY:event.y+document.body.scrollTop;
	skn.top=y+yyy;
}

function remove_popup()
{
	if(typeof(skn) == 'undefined')
		return 0;

	yyy=-1000;
	if(ns4){skn.visibility="hidden";}
	else if (ns6||ie4)
	skn.display="none"
}