// Search Toggler	
function toggleSearch()
{
	if(document.getElementById("search-box").style.display == 'block')
	{
		hideSearch();
	}
	else
	{
		showSearch();
	}
}

function hideSearch() {
		document.getElementById("search-box").style.display = 'none';
	
}
function showSearch(e) {
	document.getElementById("search-box").style.display = 'block';
	if (!e) var e = window.event;
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
	return false;
}

function hideEnews() {
	document.getElementById("newsletter-dropdown").style.display = 'none';	
}

function showEnews(e) {
	document.getElementById("newsletter-dropdown").style.display = 'block';
	if (!e) var e = window.event;
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
	
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;
		
	if(targ.type == 'checkbox' || targ.id == 'ceng' || targ.id == 'cenm' || targ.id == 'cenb')
	{	
		//targ.checked = true;
	}
	else
	{
		return false;
	}	
}

// Search postcode-to-coords
function processAddress(form, address) {
	var geocoder = null;
	if (GBrowserIsCompatible()) {
		geocoder = new GClientGeocoder();			
		geocoder.getLatLng(address+',UK', function(point) {
			
			if (!point) {
				alert("Postcode Not Found");
			} 
			else {
				document.getElementById('lat').value = point.lat();
				document.getElementById('long').value = point.lng();						
				
				document.getElementById('search_postcode').submit();

			}
		});				
	}		
	
	return false;
}

// Map location animator
function animate(nlat, nlong, title)
{
	map.panTo(new GLatLng(nlat, nlong));
	map.openInfoWindow(new GLatLng(nlat, nlong), document.createTextNode(title));
}

// Toggle event tables
function toggleTable(id)
{
	if(document.getElementById(id+'-t').style.display != 'block')
	{
		document.getElementById(id+'-t').style.display = 'block';
		document.getElementById(id+'-a').innerHTML = 'hide';
	}
	else
	{
		document.getElementById(id+'-t').style.display = 'none';
		document.getElementById(id+'-a').innerHTML = 'show';
	}
}

// Delete a forum post
function deleteReply(id)
{
	if(confirm('Are you sure you wish to delete this reply?')) window.location = '/members/forum/delete/'+id;
	else return false;
}

// Delete a whole thread
function deleteThread(id)
{
	if(confirm('Are you sure you wish to delete this entire thread?')) window.location = '/members/forum/delete/'+id;
	else return false;
}

// to fix the horizontal scrolling issue we check the users window size on page
// load.  If the size is below 1024 then we show the horizontal scroll bar
function windowSize() {
	var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && document.documentElement.clientWidth ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && document.body.clientWidth ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }

	if(myWidth >= 1008) {
		$('html body').css('overflow-x', 'hidden');
	}
	else {
		$('html body').css('overflow-x', 'scroll');
	}
}

if(window.jQuery) {
	$(document).ready( function() {
		windowSize();
		window.onresize = windowSize;
	});
}
