function deleteConfirm() {
	confirm_message = "Are you sure you would like to delete this item?";
	if (confirm(confirm_message)) {
		return true;
	}
	return false;
}

function addLoadListener(fn) {
	if (typeof window.addEventListener != 'undefined') 	{
		window.addEventListener('load', fn, false);
	} else if (typeof document.addEventListener != 'undefined') {
		document.addEventListener('load', fn, false);
	} else if (typeof window.attachEvent != 'undefined') {
		window.attachEvent('onload', fn);
	} else {
		var oldfn = window.onload;
		if (typeof window.onload != 'function')	{
			window.onload = fn;
		} else {
			window.onload = function() {
				oldfn();
				fn();
			};
		}
	}
}

document.onclick = function(e) {
  var target = e ? e.target : window.event.srcElement;
  while (target && !/^(a|body)$/i.test(target.nodeName)) {
    target = target.parentNode;
  }

  if (target && target.getAttribute('rel') && target.rel == 'external') {
    var external = window.open(target.href);
    return external.closed;
  }
return e;
}


//Used in the search.php page.
function toggleLayer( whichLayer )
{
var full, small, visF, visS;
if( document.getElementById ) // this is the way the standards work
{
  full = document.getElementById( "full_" + whichLayer );
  small = document.getElementById( "small_" + whichLayer );
}
else if( document.all ) // this is the way old msie versions work
{
	  full = document.all( "full_" + whichLayer );
    small = document.all( "small_" + whichLayer );
}
visF = full.style;
visS = small.style;
if (visF.display==''||visF.display=='block')
{
	  visF.display='none';
	  visS.display='block';
}
else
{
	  visF.display='block';
	  visS.display='none';
}

}

function changeDisplay(id) {
	var element = document.getElementById(id);
	if (element.style.display != 'block')
		$("#"+id).show();
	else
		$("#"+id).hide();
}

function changeScheduleDisplay(id) {
	changeDisplay(id);
	if (document.getElementById(id).style.display == "block")
		//document.getElementById('schedule_add_new').scrollTop = document.getElementById('schedule_add_new').offsetTop;
		window.scroll(0, document.getElementById('schedule_add_new').offsetTop);
}

function changeCheckboxStatus(field) {
	list = document.getElementsByName(field);
	for (i = 0; i < list.length; i++)
		if (list[i].checked)
			list[i].checked = false;
		else
			list[i].checked = true;
}

function alternateElementHighlighting(containerID, elementID, highlightColour){
	var bgColour;
	
	if(highlightColour != null){
		bgColour = highlightColour;
	} else {
		bgColour = '#FC0';
	}
	
	$(containerID).find(elementID+':even').css('background-color',bgColour);
}

function addPDFIcons(containerID, attribute, iconURL){
	/*this function's output is dependant upon
	  the style for "div.content_right ul.pdf_list li.pdf" 
	  in screen.css*/
	$(containerID).find(attribute).addClass('pdf');
}

function textInputSelection (elementID) {
	$(elementID).each(function(){
		var elm = $(this);
		var preFill = elm.val();
		elm.focus(function(){
			if($(this).val() == preFill){$(this).val('').css({color:'#898989'});}
		}).blur(function(){
			if($(this).val() == ''){$(this).val(preFill).css({color:'#dbdbdb'});}
		})
	});
}

function addActiveClass (opt) {
	if(opt.className == null){
		opt.className = 'active';
	}
	$(opt.elm).each(function(){
		var e = $(this);
		if(e.attr('href')){
			if(e.attr('href') == document.location.href)
			{
				e.addClass(opt.className)
			}
		}
	});
}

/*Init for Cufon*/
Cufon.replace('#main-navigation li a, #main-navigation li.active, ul#top-nav-tel li, .hvt-light, .hvt-thin,'+
				'.footer-navigation.newsletter h4, #content_left h2:not(#content.homepage div.video-area .float-right h2),'+
				' #content_left h3, #content_left h4, #content_left h5, #content_left h6, #content_right .bmi-calculator h3,' +
				'.widget-container h2',
							{'fontFamily' : 'Helvetica Neue Light', 'hover' : true});

Cufon.replace('a.grd-btn, #content_left h1, #content.homepage div.video-area .float-right, #content_right .bmi-calculator h2',
							{'fontFamily' : 'Helvetica Neue Roman', 'hover' : true});

/*Tabbing on home page "Upcoming Events" and "Recent News".*/
$(document).ready(function(){
    $('.contact-us-book-consultation-date-input').datepicker();

    $('.contact-us-submit').click( function() {
        var radioOptions = $('input[type="radio"]');
        var radioValidates = false;
        for(i = 0; i < $('input[type="radio"]').length; i++) {
            if(radioOptions[i].checked) {
                return true;
            }
        }
        alert('You must select to either Book a Consultation or Request Information.');
        return false;
    });
});
