

function email(name, domain) {
	var address = name + "\u0040" + domain;
	var url = "mailto:" + address;
	document.write("<a href=\"" + url + "\">Send Email</a>");
}


$.fn.wait = function(time, type) {
	time = time || 1000;
	type = type || "fx";
	return this.queue(type, function() {
		var self = this;
		setTimeout(function() {
			$(self).dequeue();
		}, time);
	});
};


function quickFinderGetProgram(id, searchtype) {
	if (id != '') {
		$("#quick-finder-ajax-program-url").html('<option value="">Loading...please wait</option>');
		$.getJSON("http://www.amerispan.com/ajax/quick_finder.asp",{search_id: id, search_type: searchtype}, function(j){
			var options = '<option value="">Show All Programs</option>';
			for (var i = 0; i < j.length; i++) {
				options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
			}
			$("#quick-finder-ajax-program-url").html(options);   // fill in program select
		})
	}
}


function quickFinderGo(selval) {
	if (selval == '') {
		window.location = $("#quick-finder-ajax-default-url").val();
	} else {
		window.location = selval;
	}
}


function quickFinderGoCategory() {
	if ($("#quick-finder-ajax-category-id").val() == '') {
		window.location = $("#quick-finder-ajax-default-url").val();
	} else {
		window.location = $("#quick-finder-ajax-default-url").val() + "?Category_ID=" + $("#quick-finder-ajax-category-id").val();
	}
}


function quickFinderGoLanguage() {
	if ($("#quick-finder-ajax-language-id").val() == '') {
		window.location = $("#quick-finder-ajax-default-url").val();
	} else {
		window.location = $("#quick-finder-ajax-default-url").val() + "?Language_ID=" + $("#quick-finder-ajax-language-id").val();
	}
}


function resetQuickFinder() {
	$("#quick-finder-ajax-program-url").html('<option value="">Show All Programs</option>');
}

function fixGoogleTranslate(googLoop) {
	if (googLoop < 5) {
		setTimeout(function(){
			$(".goog-te-gadget").css('fontSize','8px');
			$(".goog-te-gadget").css('whiteSpace','normal');
			$(".goog-te-combo").css('width','120px');
			googLoop++;
			fixGoogleTranslate(googLoop);
		},1000);	
	}
}


$(document).ready(function(){
	//fix font size on google translate text
	var googLoop = 0;
	fixGoogleTranslate(googLoop);
	
	// reset quick finder
	resetQuickFinder();
	
	//show quick finder box on sections' default pages
	//$("#quick-finder-ajax").wait().slideDown("slow");
	
	//if type is chosen in quick finder, get programs thru ajax
	$("select#quick-finder-ajax-search-id").change(function(){
		quickFinderGetProgram($(this).val(), $("#quick-finder-ajax-type").val());
	});
	
	//if a program is chosen in quick finder, go to the ajax supplied url
	$("select#quick-finder-ajax-program-url").change(function(){
		quickFinderGo();
	});
	
	//if go button is clicked in quick finder, go to the url
	$("#quick-finder-ajax-go").click(function(){
		quickFinderGo();
	});
	
	//open new window if vol options box is clicked
	$(".voltypehelp").click(function(){
		window.open("http://www.amerispan.com/volunteer_intern/placement_options.asp","VolunteerTypes");
	});
	
	//if a category is chosen in quick finder, go to the ajax supplied url
	$("#quick-finder-ajax-category-id").change(function(){
		quickFinderGoCategory();
	});
	
	//if a language is chosen in quick finder, go to the ajax supplied url
	$("#quick-finder-ajax-language-id").change(function(){
		quickFinderGoLanguage();
	});
	
	//
	$(".quick-finder-ajax-select").change(function() {
		quickFinderGo($(this).val());
	});
	
}); // end ready()