// JoDo functions

function buildQueryString( obj )
{
	var qs = '';
	var v, i;
	
   for( var e in obj )
	{
		v = obj[e];
		
		if( v instanceof Function )
		{
			continue;	
		}
		
		if( v instanceof Array  )
		{
			for( i = 0; i < v.length; ++i )
			{
				if( v[i] !== undefined )
				{
					qs += ( qs == '' ) ? '' : '&' ;
					qs += e+'[]='+escape( v[i] );
				}
			}
		}
		else
		{
			qs += ( qs == '' ) ? '' : '&' ;
			qs += e + '=' + escape( v );
		}
	}
	
	return qs;
}

function setValues( menu, arr )
{
	//remove all existing options
	for( var i = menu.options.length - 1; i >=0; i-- )
	{
		menu.options[i] = null;
	}
	
	if( arr )
	{
		menu.disabled = false;
		
		menu.options[0] = new Option( '- select subcategory -', '' );
		
		for( var i = 0; i < arr.length; i++ )
		{
			menu.options[i+1] = new Option( arr[i].cat, arr[i].id );
		}
	}
	else
	{
		menu.options[0] = new Option( 'none', '' );
		menu.disabled = true;
	}
}

function checkSplit( form, keys )
{
	var t;
	
	var total = 0;
	
	for( var i = 0; i < keys.length; ++i )
	{
		t = form['setSplit_'+keys[i]];//
		
		total += Number( t.value );
	}
	
	if( total === 100 )
	{
		return true;
	}
	else
	{
		if( isNaN( total ) )
		{
			alert( 'The percentages must be numbers' );
		}
		else
		{
			alert( 'The total split percentages must add up to 100 (current '+total+')' );
		}
		
		return false
	}
}

function toggleDetails( id, row )
{
	if( id.style.display != 'none' )//the id is visible, so close it
	{
		id.style.display = 'none';//so hide it
		row.className = row.oldClass;//unselect the parent row (will probably be set to over now)
		row.oldClass = '';//will remove any class on this row.. implicity sets it as read...
		
		//remove from open rows
		delete openRows[id.id.split( '_' )[1]];
	}
	else//the id is not visible, so show it
	{
		id.style.display = '';
		
		//and make the parent row selected
		row.oldClass = row.className;
		row.className = 'selected';
		
		openRows[id.id.split( '_' )[1]] = id.id.split( '_' )[1];
	}//end show row
}

function getOpenRows()
{
	var str = '';
	
	for( var i=0; i < openRows.length; i++ )
	{
		if( openRows[i] )
		{
			str += '&show[]='+openRows[i];
		}
	}
	
	return str.substr( 1 );
}

function setAsRead( id, read )
{
	if( read == 'n' )
	{
		//need to record this message as read (ajax!)
		var iframe = getElement( 'frame' );
		iframe.src = '?m=read&id='+id;
	}
}

function getElement( id )
{
	var x = null;
	
	if( document.getElementById )
	{
		x = document.getElementById( id );
	}
	else if( !( x = document[id] ) && document.all )
	{
		x = document.all[id];
	}
	
	return x;
}

function rowSelect( id, key )
{
	var checkbox = document.forms.basket['jobs_'+key];
	
	if( id.className == 'selected' )
	{
		id.className = id.oldClass;
		id.oldClass = '';
		
		checkbox.checked = false;
	}
	else
	{
		id.oldClass = id.className;
		id.className = 'selected';
		
		checkbox.checked = true;
	}
}

function rowOver( id )
{
	if( id.className != 'selected' )
	{
		id.oldClass = id.className;
		id.className  = 'over';
		
	}
	
	id.style.cursor = 'pointer';
}

function rowOut( id )
{
	if( id.className != 'selected' )
	{
		id.className = id.oldClass;
	}
}