function checkRadioStatus()
{
	var element = document.getElementById("local");
	if(!element) { return; }
	if (!document.conference.local.checked)
	{
		document.conference.radius.disabled = true;
	}
	else
	{
		document.conference.radius.disabled = false;
	}
}

function cssjs(a,o,c1,c2)
{
	switch (a)
	{
		case 'swap':
			o.className=!cssjs('check',o,c1)?o.className.replace(c2,c1):o.className.replace(c1,c2);
		break;
		case 'add':
			if(!cssjs('check',o,c1)){o.className+=o.className?' '+c1:c1;}
		break;
		case 'remove':
			var rep=o.className.match(' '+c1)?' '+c1:c1;
			o.className=o.className.replace(rep,'');
		break;
		case 'check':
			return new RegExp("(^|\\s)" + c1 + "(\\s|$)").test(o.className)
		break;
	}
}

function checkRadioStatusUser()
{
	var element = document.getElementById("local");
	if(!element) { return; }
	if (!document.account.local.checked)
	{
		document.account.radius.disabled = true;
		cssjs('add', document.getElementById('location-container'), "hide");	

	}
	else
	{
		document.account.radius.disabled = false;
		if(cssjs('check', document.getElementById('location-container'), "hide")) {
			cssjs('remove', document.getElementById('location-container'), "hide");
		}
	}
}
function toggleAlertField()
{
	if (!document.account.delegate_new_email_weekly.checked && !document.account.delegate_new_email_monthly.checked)
	{
		cssjs('add', document.getElementById('new-and-saved-email'), "hide");	
	}
	else if (document.account.delegate_new_email_weekly.checked || document.account.delegate_new_email_monthly.checked)
	{
		if(cssjs('check', document.getElementById('new-and-saved-email'), "hide")) {
			cssjs('remove', document.getElementById('new-and-saved-email'), "hide");
		}
	}
}
// Eliminate flicker. This uses the DOM model to build the style for the javascript-hide-me class.
function flickerControl() {
	js = document.createElement('style');
	js.appendChild(document.createTextNode('.javascript-hide-me{display:none;}'));
	js.type = 'text/css';
	document.getElementsByTagName('head').item(0).appendChild(js);
}

// Used on the conference-info page
function dispHandle() 
{
	if (document.getElementById('inside-email-friend').style.display == "none")
	{
		document.getElementById('inside-email-friend').style.display = "";
	}
	else
	{
		document.getElementById('inside-email-friend').style.display = "none";
	}
	// Need this because the below code doesnt workin IE. Checks to see
	// if browser is firefox and if so uses the DOM to display hide class (eliminates flicker)
    if(navigator.userAgent.indexOf("Firefox") != -1) 
	{
		js = document.createElement('style');
		js.appendChild(document.createTextNode('.javascript-hide-me{display:block;}'));
		js.type = 'text/css';
		document.getElementsByTagName('head').item(0).appendChild(js);
	}
}

function doNothing() { // Intentionally empty
}

function checkEnter(e) // Enable forms to be submitted with 'enter' even if the buttons a graphic
{ //e is event object passed from function invocation
	var characterCode
	if(e && e.which)
	{ //if which property of event object is supported (NN4)
		e = e
		characterCode = e.which //character code is contained in NN4's which property
	}
	else
	{
		e = event
		characterCode = e.keyCode //character code is contained in IE's keyCode property
	}
	
	if(characterCode == 13)
	{ //if generated character code is equal to ascii 13 (if enter key)
		document.forms[0].submit() //submit the form
		return false 
	}
	else
	{
		return true 
	}
}

// fill in end date for adding conference and date searches
function pupulateEndDate(form_name) 
{
	if (form_name.date_end.value =='') 
	{
		form_name.date_end.value = form_name.date_start.value
	}
}

// Change dates when a dropdown is edited
// Custom function to format numeric value so it includes a leading zero (if less than 10)
function format_00(value)
{
	if (value<10)
	{
		var new_value = 0+value;
		return new_value;
	}
	return value;
}
function changeStartDay() 
{
	var value = document.getElementById('start_day').value;
	if (value != 0)
	{
		var date = document.getElementById('date_start').value;
		var date_array = new Array();
		date_array = date.split('/');
		
		var newValue = format_00(value)+'/'+date_array[1]+'/'+date_array[2];
		
		document.getElementById('date_start').value = newValue;
	}
}

function changeStartMonth() 
{
	var value = document.getElementById('start_month').value;
	if (value != 0)
	{
		var date = document.getElementById('date_start').value;
		var date_array = new Array();
		date_array = date.split('/');
		
		var newValue = date_array[0]+'/'+format_00(value)+'/'+date_array[2];
		
		document.getElementById('date_start').value = newValue;
	}
}

function changeStartYear() 
{
	var value = document.getElementById('start_year').value;
	if (value != 0)
	{
		var date = document.getElementById('date_start').value;
		var date_array = new Array();
		date_array = date.split('/');
		
		var newValue = date_array[0]+'/'+date_array[1]+'/'+format_00(value);
		
		document.getElementById('date_start').value = newValue;
	}
}

function changeEndDay() 
{
	var value = document.getElementById('end_day').value;
	if (value != 0)
	{
		var date = document.getElementById('date_end').value;
		var date_array = new Array();
		date_array = date.split('/');
		
		var newValue = format_00(value)+'/'+date_array[1]+'/'+date_array[2];
		
		document.getElementById('date_end').value = newValue;
	}
}

function changeEndMonth() 
{
	var value = document.getElementById('end_month').value;
	if (value != 0)
	{
		var date = document.getElementById('date_end').value;
		var date_array = new Array();
		date_array = date.split('/');
		
		var newValue = date_array[0]+'/'+format_00(value)+'/'+date_array[2];
		
		document.getElementById('date_end').value = newValue;
	}
}

function changeEndYear() 
{
	var value = document.getElementById('end_year').value;
	if (value != 0)
	{
		var date = document.getElementById('date_end').value;
		var date_array = new Array();
		date_array = date.split('/');
		
		var newValue = date_array[0]+'/'+date_array[1]+'/'+format_00(value);
		
		document.getElementById('date_end').value = newValue;
	}
}


//////////////////////////////////////////////////////////////////////////////
/////////////////////// Used to validate blog post form
function checkForm() 
{
	var field_names = new Array("searchtext","country_id");
	var status = true;

	for (i=0;i<field_names.length;i++) 
	{
		if (document.getElementById(field_names[i])) 
		{
			if (document.getElementById(field_names[i]).value.length==0 || document.getElementById(field_names[i]).value =='Please Select') 
			{
				document.getElementById(field_names[i]).parentNode.className = "invalid";
				status = false;
			} else 
			{
				document.getElementById(field_names[i]).parentNode.className = "";
			}
		}
	}
	
	if (!status) 
	{
		document.getElementById("issues").innerHTML = "Please specify search criteria using text field or dropdown";
	}
	return status;
}

// Check for commentform
function checkSearchForm() 
{
	if (document.getElementById) 
	{ 
		if (document.getElementById("organiser_search_country")) // If the page contains the commentform, attach the checkForm function
		{
			document.getElementById("organiser_search_country").onsubmit = checkForm;
		}
	}
}
// This function runs the funtion (defined as an argument) after the page has loaded (it is used so we dont overwrite additional onLoad functions that could be located in the body tag
function onPageLoad(func) 
{
	var oldonLoad = window.onload; // Set variable to the window.onload event
	// If the window.onload event does not already have a function attached, run checkCommentForm() function (or whatever the argument is)
	if (typeof window.onload != 'function') 
	{
		window.onload = func;
	} 
	else  // If the onload event has functions attached to it, run them first before runnning the checkCommentForm() function
	{
		window.onload = function() 
		{
			oldonLoad();
			func();
		}
	}
}



             



