var xmlhttp;
var browser;
var params;
var responseText;
var responseHeader;
var newContent;
var IE = false;

browser = navigator.appName;
if (browser == "Microsoft Internet Explorer") {
	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	IE = true;	
} else {
	// all other browsers - create an instance of the XMLHttpRequest javascript object
	xmlhttp = new XMLHttpRequest();
}

function createHTTPRequest() {
	if (browser == "Microsoft Internet Explorer") {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		// all other browsers - create an instance of the XMLHttpRequest javascript object
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

function loadDegreeTab(tab) {
	var wait_html = '<div class="ajax-loading">';
	wait_html += '<img src="http://www.oneonta.edu/home/images/loading.gif" alt="loading" />';
	$('.degree-tab-content').html(wait_html);
	params = "tab="+tab;
    if (IE) {
    	xmlhttp = createHTTPRequest();
    }
    xmlhttp.onreadystatechange = function() {
       	if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
       		responseText = xmlhttp.responseText;
       		newContent = $(responseText).find("#"+tab);
       		newContent = newContent.prevObject[0].innerHTML;
			$('.degree-tab-content').show();
			$('.degree-tab-content').html(newContent);
		}
	}
	
	$(".degree-tabs ul li a").each(function() {
		var id = $(this).attr('id');
		if (id == tab) {
			$(this).parent().addClass('active');
		} else {
			$(this).parent().removeClass('active');
		}
	});
	
	xmlhttp.open("GET", "http://dev09.zone5dev.net/ajax/degreetabs.html?tab="+tab);
	xmlhttp.send(null);
}

$(document).ready(function() {
	// make first tab default
	// onfocus="if (this.value == 'SEARCH') this.value = ''" onblur="if (this.value == '') this.value = 'SEARCH'"
	$("#tab-content-freshmen").show();
	$("#tab-content-freshmen").addClass('visible');
	$(".degree-tabs a#freshmen").parent('li').addClass('active');
		
	$(".degree-tabs ul li a").click(function() {
		//loadDegreeTab($(this).attr('id'));
		$(".each-tab").each(function() {
			if ($(this).hasClass('visible')) {
				$(this).removeClass('visible');
				$(this).hide();
			}
		});
		var value = $(this).attr('id');
		$(".degree-tabs ul li a").each(function() {
			var id = $(this).attr('id');
			if (id == value) {
				$(this).parent().addClass('active');
			} else {
				$(this).parent().removeClass('active');
			}
		});
		$("#tab-content-"+value).show();
		$("#tab-content-"+value).addClass('visible');
		
	});
});
