function doCheck(w, value) {
	var checks = document.getElementById(w).getElementsByTagName('input');

	for (i = 0; i < checks.length; i++)
		checks[i].checked = value;
	return false;
}

function popup(where, w, h) {
	l = (screen.width - w)/2;
	t = (screen.availHeight - h) /2;
	win = window.open(where,
		 'popup', 'menubar=no,status=no,toolbar=no,titlebar=no,location=no,scrollbars=yes,' +
		 'width=' + w + ', height=' + h + ',top=' + t + ',left=' + l);	

	return false;
}


function selectSchool(where) {
	popup('school_select.php?update=' + where);
	return false;
}

function changeItem(item, change) {
	items = item.split(",");
	for(x = 0; x < items.length; x++) {
		i = self.opener.document.getElementById(items[x]);
		i.value = change;
		i.innerHTML = change;
		//alert(items[x] + ":" + change);
	}
	self.close();
	return false;
}

function updateFilter(x) {
	window.location = 'outlines.php?filter=' + x[x.selectedIndex].value;
}

function checkTerm(x) {
	year = window.document.getElementById('year');
	na = x[x.selectedIndex].cloneNode(true);

	if (x.value == "N/A")
		year.appendChild(na);
	else if (year[year.length -1].value == 'N/A')
		year.remove(year.length -1);
}

function checkEdit(item, def) {
	p = document.getElementById('professor_select');
	c = document.getElementById('course_select');

	if (item.value == def) {
		item.value = '';
		item.style.color = 'black';
		if (item.id == "course_input")
			c.style.color = 'gray';
		else if (item.id == "professor_input")
			p.style.color = 'gray';
	} else if (item.value == '') {
		item.value = def
		item.style.color = 'gray';

		if (item.id == "course_input")
			c.style.color = 'black';
		else if (item.id == "professor_input")
			p.style.color = 'black';
	}


}

function hide(id) {
	document.getElementById(id).style.visibility='hidden';
}

function login() {
	document.loginForm.submit();
	//return false;
}

function showAnswer(input,id) {
	$(input).parent().parent().next().find('*').show();
	$(input).parent().parent().next().toggle()
	$.ajax({
		url: 'qna_ajax.php?viewed=1&id=' + id
	});
}	

function voteUp(id) {
	$.ajax({url: 'qna_ajax.php?vote=up&id=' + id});
	$('.votes_' + id).slideUp(500, function() {$(this).html('You voted this item up.').parent().parent().toggle()});
}

function voteDown(id) {
	$.ajax({url: 'qna_ajax.php?vote=down&id=' + id});
	$('.votes_' + id).slideUp(500, function() {$(this).html('You voted this item down.').parent().parent().toggle()});
}

function tip_voteUp(id) {
        $.ajax({url: 'tip_ajax.php?vote=up&id=' + id});
        $('.votes_' + id).slideUp(500, function() {$(this).html('You voted this item up.').parent().parent().toggle()});
}       
        
function tip_voteDown(id) {
        $.ajax({url: 'tip_ajax.php?vote=down&id=' + id});
        $('.votes_' + id).slideUp(500, function() {$(this).html('You voted this item down.').parent().parent().toggle()});
}

function tip_front_voteUp(id) {
	$.ajax({url: 'tip_ajax.php?vote=up&id=' + id});
	$('.votes_' + id).slideUp(500);
}

function tip_front_voteDown(id) { 
	$.ajax({url: 'tip_ajax.php?vote=down&id=' + id});
	$('.votes_' + id).slideUp(500);
}
