
	var changeMade = 0;
	window.onbeforeunload = checkChanged;	
	function checkChanged ()
	{
		if (changeMade)
			return "Changes made to this record will be lost.";
	}	
	
	
	tab_active = new Array();	

	var plus = new Image();
	plus.src = "/assets/admin/icons/plus.gif";

	var minus = new Image();
	minus.src = "/assets/admin/icons/minus.gif";

	function submitMainForm(after)
	{
		if (!document.getElementById('mainform'))
			return;
			
		/*
		if (document.getElementById('mainform')['required[0]'])
		{
			req = document.getElementById('mainform')
			for (x in req)
			{
				if (document.getElementById(req[x]))
					if (!document.getElementById(req[x].value).value)
					{
						alert('Please supply a '+document.getElementById('mainform').required_msg[x].value);
						return false;
					}
			}
		}
		*/
			
		if (document.getElementById('after'))
			document.getElementById('after').value = after;
			
		changeMade = 0;
		document.getElementById('mainform').submit();
	}
	
	function showAnotherRow (prefix)
	{
		var i = 0;
		
		while (document.getElementById(prefix+'row_'+i))
		{
			if (document.getElementById(prefix+'row_'+i).style.display == 'none')
			{				
				document.getElementById(prefix+'row_'+i).style.display = '';
				
				i++;
				if (!document.getElementById(prefix+'row_'+i))
					document.getElementById(prefix+'addrow').style.display = 'none';
					
				return;
			}
			
			i++;
		}
	}
	
	function tabDisplay (family, tab, setfocus)
	{
		document.getElementById('tab_'+family+'_'+tab_active[family]+'_tab').className = '';
		document.getElementById('tab_'+family+'_'+tab_active[family]).style.display = 'none';	

		document.getElementById('tab_'+family+'_'+tab+'_tab').className = 'active';
		document.getElementById('tab_'+family+'_'+tab).style.display = '';	
		tab_active[family] = tab;
		
		if (document.getElementById(setfocus))
			document.getElementById(setfocus).focus();
	}
	
	function contactCheckExistingShowBox (anchorTo)
	{
		theAnchor = document.getElementById(anchorTo);
	
		var fieldbox = YAHOO.util.Region.getRegion(theAnchor);
		var pos = Array();
		pos[0] = fieldbox.left + theAnchor.offsetWidth;
		pos[1] = fieldbox.top;
		document.getElementById('contactCheckExistingBox').style.display = '';		
		YAHOO.util.Dom.setXY('contactCheckExistingBox', pos);
	}

	var contactCheckExistingSuccess = function(o)
	{
		if (o.responseText == '0')
		{
			document.getElementById('contactCheckExistingBox').style.display = 'none';
			return;
		}
		
		bits = o.responseText.split('|||');
		
		document.getElementById('contactCheckExistingResult').innerHTML = bits[1];
		contactCheckExistingShowBox(bits[0]);
	}
	
	var contactCheckExistingFailure = function(o)
	{
		return;
	}
	
	var contactCheckExistingCallback =
	{
		success: contactCheckExistingSuccess,
		failure: contactCheckExistingFailure
	}

	function contactCheckExisting (name_first, name_last)
	{
		first = document.getElementById(name_first);
		last = document.getElementById(name_last);
		
		if (!first.value || !last.value)
			return;
					
		var cObj = YAHOO.util.Connect.asyncRequest('GET','/lib/request/contactCheckExisting.php?field='+name_first+'&name_first='+URLEncode(first.value)+'&name_last='+URLEncode(last.value),contactCheckExistingCallback,null);
	}
	
	var deleteGenericSuccess = function(o)
	{
		if (o.responseText == '0')
		{
			alert('Delete failed, please try again.');
			return;
		}
		
		if (o.responseText == '1')
			return;
		else if (document.getElementById(o.responseText))
			deleteBox2(o.responseText);
	}
	
	var deleteGenericFailure = function(o)
	{
		alert('Delete failed, please try again.');
	}
	
	var deleteGenericCallback =
	{
		success: deleteGenericSuccess,
		failure: deleteGenericFailure
	}
	
	function deleteGeneric (table, idfield, id, hide, file)
	{
		if (document.getElementById(hide))
		{
			var oldcolor = document.getElementById(hide).style.backgroundColor;
			document.getElementById(hide).style.backgroundColor = '#FF5555';
		}
		
		if (!confirm('Are you sure you want to delete this item?'))
		{
			if (document.getElementById(hide))
				document.getElementById(hide).style.backgroundColor = oldcolor;

			return false;
		}
			
		var cObj = YAHOO.util.Connect.asyncRequest('GET','/core/request/deleteGeneric.php?table='+table+'&idfield='+idfield+'&id='+id+'&hide='+hide+'&file='+file,deleteGenericCallback,null);
	}
	
	function deleteGenericURL (url, hide)
	{
		if (document.getElementById(hide))
		{
			var oldcolor = document.getElementById(hide).style.backgroundColor;
			document.getElementById(hide).style.backgroundColor = '#FF5555';
		}
		
		if (!confirm('Are you sure you want to delete this item?'))
		{
			if (document.getElementById(hide))
				document.getElementById(hide).style.backgroundColor = oldcolor;

			return false;
		}
			
		var cObj = YAHOO.util.Connect.asyncRequest('GET',url+'&hide='+hide,deleteGenericCallback,null);
	}		
	
	function superRadioChange (theForm, theRadio)
	{
		if (!theForm[theRadio])
		{
			console.log('radio '+theRadio+' not found');
			return;
		}
		
		for (y in theForm[theRadio])
		{
			var x = theForm[theRadio][y].value;
			
			if (!document.getElementById('superRadio_'+theRadio+'['+x+']'))
				continue;
			
			radio = document.getElementById(theRadio+'['+x+']');
			
			if (!radio)
				continue;
			
			if (radio.checked)
				document.getElementById('superRadio_'+theRadio+'['+x+']').style.opacity = '1';
			else
				document.getElementById('superRadio_'+theRadio+'['+x+']').style.opacity = '0.4';
		}
	}	
	