/* show messages to browsers not supporting js */
//document.write('<style type="text/css">.js_hide {display: none;}</style>');

// toggle clicking the ability to exist of something 
// and also toggle between the [+] and [-] if the respecting eleement exists
function toggle_show(id)
{
	var arrow_id = id+'_arrow';
	if (document.getElementById(id).style.display != 'block')
	{
		document.getElementById(id).style.display = 'block';	
		if (document.getElementById(arrow_id))
			document.getElementById(arrow_id).innerHTML = '[-]';
			
	}
	else
	{
		document.getElementById(id).style.display = 'none';
		if (document.getElementById(arrow_id))
			document.getElementById(arrow_id).innerHTML = '[+]';
	}
}

// for check/uncheck boxes
function toggle_check(fieldname)
{
	// grab the elements
	var elements = document.getElementsByName(fieldname);

	// go through each one
	for (i = 0; i < elements.length; i++)
	{
		// if it's false, make it true. if it's true, make it false
		elements[i].checked = elements[i].checked == false ? true : false;
	}
}

// hide elements with class="js_hide"
document.write('<style type="text/css">.js_hide{display: none;}</style>');


// thanks, http://www.somacon.com/p355.php
String.prototype.trim = function()
{
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

// cover the site in gray
function gray_in(){
	
	// create div to be gray
	var boxy = document.createElement('div');
	
	// if it already exists, fuck it
	if (document.getElementById('t_bg'))
		return;
		
	// make it the right id
	boxy.setAttribute('id', 't_bg');
	
	// and stick it
	document.body.appendChild(boxy);
}

// remove all gray
function gray_out() {
	
	// if it isn't, ignore
	if (!document.getElementById('t_bg'))
		return;
	
	// kill the gray div
	document.body.removeChild(document.getElementById('t_bg'));
}

// shhow a full screen loading msg
function fs_loading_in(msg) {
	// get all gray
	gray_in();
	
	// if it already exists, fuck it
	if (document.getElementById('fs_loader'))
		return;	
	
	// make it
	var l = document.createElement('div');	

	// give it correct id
	l.setAttribute('id', 'fs_loader');
	
	// position span inside of it
	var s = document.createElement('span');
	
	// stuff text in it
	s.innerHTML = msg;
	
	// stick span in div
	l.appendChild(s);
	
	// stick div in body
	document.body.appendChild(l);
	
	// so it stix
	/*window.onbeforeunload = function() {
		return 'USURP is currently doing something. Are you sure you want to leave? :-(';
	}*/
}

// remove full screen loading msg..
function fs_loading_out() {
	
	// remove gray
	gray_out();
	
	// if it isn't, ignore
	if (!document.getElementById('fs_loader'))
		return;	
	
	// kill it
	document.body.removeChild(document.getElementById('fs_loader'));
}


