sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

isChrome = function() {
    return Boolean(window.chrome);
}

function providerSearch(method) {
	
	if(method == 'name') {
	
		var firstName = $('#firstName').val();
		var lastName = $('#lastName').val();
		
		if(firstName == '' && lastName == '') {
			alert("Please enter last name, first name, or the first letter of first or last name.");
			return false;
		}
		
		$.ajax({
			url: '/ayejax/providers',
			type: 'POST',
			data: ({first: firstName, last: lastName, searchMethod: 'name'}),
			cache: false,
			dataType: 'html',
			success: function(data) {
				$('#searchResults').html(data);
				$('.search').hide();
				$('.results').show();
			},
			error: function(type,msg) {
				alert(msg);
			}
		});
	}
	
	if(method == 'location') {
	
		var location = $('#location').val();
		
		if(location == '') {
			alert("Please select a location from the dropdown menu and then click search.");
			return false;
		}
				
		$.ajax({
			url: '/ayejax/providers',
			type: 'POST',
			data: ({searchLocation: location, searchMethod: 'location'}),
			cache: false,
			dataType: 'html',
			success: function(data) {
				$('#searchResults').html(data);
				$('.search').hide();
				$('.results').show();
			},
			error: function(type,msg) {
				alert(msg);
			}
		});
	}
	
}

$(document).ready(function(){
	
	/*
	$('#firstName, #lastName').keyup(function(event) {
		if(event.keyCode != "32") {
			providerSearch();
		}
	});
	*/
	
	$("#text_up").fontscale("#right","up",{unit:"px",increment:1});
	$("#text_down").fontscale("#right","down",{unit:"px",increment:1});
	$("#text_reset").fontscale("#right","reset");
	
	//bookmark
	if(window.opera) {
		if ($("a.jqbookmark").attr("rel") != ""){
			$("a.jqbookmark").attr("rel","sidebar");
		} 
	}

	$("a.jqbookmark").click(function(event){
		event.preventDefault();
		var url = this.href;
		var title = this.title;
		
		if (window.sidebar) { // Mozilla Firefox Bookmark
			window.sidebar.addPanel(title, url,"");
		} else if( window.external && !isChrome() ) { // IE Favorite
			window.external.AddFavorite( url, title);
		} else if(window.opera) { // Opera 7+
			return false; // do nothing
		} else { 
			 alert('Unfortunately, this browser does not support the requested action.\n'
			 + '\nPlease bookmark this page manually by pressing CTRL + D on your keyboard.');
		}
	
	});

})
