// JavaScript Document
function DocumentPreview() {
 	var post_array = new Array('id', 'name', 'link', 'file_loc', 'doc_post');
	Preview(post_array);
}
function LecturePreview() {
 	var post_array = new Array('id', 'name', 'class_num', 'month', 'mday', 'year', 'description', 'file_loc', 'lecture_post');
	Preview(post_array);
}
function LinkPreview() {
 	var post_array = new Array('id', 'link_text', 'url', 'title', 'new_win', 'link_post');
	Preview(post_array);
}
function NewsPreview() {
 	var post_array = new Array('id', 'title', 'posttext', 'postdate', 'update_postdate', 'news_post');
	Preview(post_array);
}
function PersonPreview() {
 	var post_array = new Array('id', 'type', 'prefix', 'first', 'middle', 'last', 'title', 'email', 'phone', 'office', 'hours', 'url', 'bio', 'picture', 'person_post');
	Preview(post_array);
}
function SyllabusPreview() {
 	var post_array = new Array('id', 'name', 'syllabus_text', 'file_loc', 'syllabus_post');
	Preview(post_array);
}


// general purpose preview
// matches the variables in the given post array from the postform to the preview form, and submits them to the preview document
function Preview(post_array) {
    preview = window.open('preview.php','preview','width=700,height=480,scrollbars=yes,status=yes');
	for (var post_val in post_array) {
		document.preview.elements[post_array[post_val]].value = document.postform.elements[post_array[post_val]].value;
	}
	document.preview.submit();
}

function toggleVisible (elName) { 
	var el = document.getElementById (elName); 
	var isVisible = (el.style.visibility == "hidden") ? true : false; 
	el.style.visibility = isVisible ? "visible" : "hidden"; 
	el.style.display = isVisible ? "inline" : "none"; 
} 
function togglePlusMinus (imgID) {
	var img = document.getElementById (imgID);
	var imgSrc = img.getAttribute("src");
	if(imgSrc == 'images/minus.png') {
		img.setAttribute("src", "images/plus.png");
	}
	if(imgSrc == 'images/plus.png') {
		img.setAttribute("src", "images/minus.png");
	}	
}

