function postForm(servlet, code){
	document.servletForm.action = servlet;
	document.servletForm.code.value = code;
	document.servletForm.submit();
}

function postMultipartForm(servlet, code){
	document.servletForm.action = servlet;
	document.servletForm.code.value = code;
	document.servletForm.encoding = "multipart/form-data";
	document.servletForm.submit();
}

function deleteNewsItem(id) {
	if (confirm("Confirm to delete News " + id + "?")){
		document.servletForm.action = 'news';
		document.servletForm.code.value = '379';
		document.servletForm.id.value = id;
		document.servletForm.submit();
	}
}

function deleteNewsImage(newsID, imageID) {
	if (confirm("Are you sure you want to delete this image?  Deleting image will reset this page and you will lose your changes!")){
		document.servletForm.action = 'news';
		document.servletForm.code.value = '479';
		document.servletForm.id.value = newsID;
		document.servletForm.file.value = imageID;
		document.servletForm.submit();
	}
}

function deleteItem(file, id, type) {
	var itemType;
	
	if(type == 'pto')
		itemType = 'PTO News';
	else if(type == 'ra')
		itemType = 'Recent Activity';
	else if(type == 'newsletter')
		itemType = 'Newsletter';
	else if(type == 'events')
		itemType = 'Upcoming Event';
	else if(type == 'album')
		itemType = 'Photo Album';
	else if(type == 'faculty')
		itemType = 'Faculty Profile';
	else if(type == 'calendar')
		itemType = 'Monthly Calendar';
				
	if (confirm("Confirm to delete " + itemType + " "+ id + "?")){
		document.servletForm.action = type;
		document.servletForm.code.value = '379';
		document.servletForm.id.value = id;
		document.servletForm.file.value = file;
		document.servletForm.submit();
	}
}

function deletePhoto(photoID) {
	if (confirm("Are you sure you want to delete Photo " + photoID + "?  Deleting photos will reset this page and you will lose your changes!")){
		document.servletForm.action = 'album';
		document.servletForm.code.value = '479';
		document.servletForm.id.value = photoID;
		document.servletForm.submit();
	}
}

function deleteFacultyPhoto(facultyID, photoID) {
	if (confirm("Are you sure you want to delete this photo?  Deleting photos will reset this page and you will lose your changes!")){
		document.servletForm.action = 'faculty';
		document.servletForm.code.value = '479';
		document.servletForm.id.value = facultyID;
		document.servletForm.file.value = photoID;
		document.servletForm.submit();
	}
}

function deleteEmployment(id) {
	if (confirm("Confirm to delete Empoyment Opportunity " + id + "?")){
		document.servletForm.action = 'employment';
		document.servletForm.code.value = '379';
		document.servletForm.id.value = id;
		document.servletForm.submit();
	}
}

function deleteFeedback(id) {
	if (confirm("Confirm to delete Feedback " + id + "?")){
		document.servletForm.action = 'feedback';
		document.servletForm.code.value = '379';
		document.servletForm.id.value = id;
		document.servletForm.submit();
	}
}


function getNewsContent(id){ 
	var xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null){
  		alert ("Your browser does not support AJAX!");
  		return;
	} 
	
	var url = "news";
	var params = "code=978&id=" + id;
	
	xmlHttp.open("POST", url, true);

	//Send the proper header information along with the request
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");

	xmlHttp.onreadystatechange = function() {//Call a function when the state changes.
		if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
			//alert(xmlHttp.responseText);
			document.getElementById("newsContent").innerHTML=xmlHttp.responseText;
		}
	};
	
	xmlHttp.send(params);
}


function preview(url, code, div) {
	var title = document.getElementById("title").value;
	var content = document.getElementById("blockContent").value;//document.editForm.content;
	document.getElementById(div).innerHTML="<hr /><h1>"+title+"</h1>"+content;
	window.scrollBy(0,600); 
}

function load(url, code, div) {
	var xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null){
  		alert ("Your browser does not support AJAX!");
  		return;
	} 

	var params = "code=" + code; 
	
	xmlHttp.open("POST", url , true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");

	xmlHttp.onreadystatechange = function() {//Call a function when the state changes.
		if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
			document.getElementById(div).innerHTML=xmlHttp.responseText;
		}
	};
	
	xmlHttp.send(params);
}


function loadItem(url, code, id, div) {
	var xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null){
  		alert ("Your browser does not support AJAX!");
  		return;
	} 
	var params = "code=" + code; 
	xmlHttp.open("POST", url + "?" + "code=" + code + "&id=" + id , true);

	//Send the proper header information along with the request
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");

	xmlHttp.onreadystatechange = function() {//Call a function when the state changes.
		if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
			document.getElementById(div).innerHTML=xmlHttp.responseText;
		}
	};
	
	xmlHttp.send(params);
}


function getContent(id, type){ 
	var xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null){
  		alert ("Your browser does not support AJAX!");
  		return;
	} 
	
	var url = type;
	var params = "code=978&id=" + id;
	
	xmlHttp.open("POST", url, true);

	//Send the proper header information along with the request
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");

	xmlHttp.onreadystatechange = function() {//Call a function when the state changes.
		if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
			document.getElementById( type + "Content").innerHTML=xmlHttp.responseText;
		}
	};
	
	xmlHttp.send(params);
}


function getEmploymentContent(id){ 
	var xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null){
  		alert ("Your browser does not support AJAX!");
  		return;
	} 
	
	var url = "employment";
	var params = "code=978&id=" + id;
	
	xmlHttp.open("POST", url, true);

	//Send the proper header information along with the request
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");

	xmlHttp.onreadystatechange = function() {//Call a function when the state changes.
		if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
			//alert(xmlHttp.responseText);
			document.getElementById("employmentContent").innerHTML=xmlHttp.responseText;
		}
	};
	
	xmlHttp.send(params);
}


function getFacultyProfile(id){ 
	var xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null){
  		alert ("Your browser does not support AJAX!");
  		return;
	} 
	
	var url = "faculty";
	var params = "code=978&id=" + id;
	
	xmlHttp.open("POST", url, true);

	//Send the proper header information along with the request
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");

	xmlHttp.onreadystatechange = function() { //Call a function when the state changes.
		if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
			document.getElementById("facultyContent").innerHTML=xmlHttp.responseText;
		}
	};
	
	xmlHttp.send(params);
}


function GetXmlHttpObject(){
	var xmlHttp = null;
	try{ // Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest(); 
	}catch (e){
  		try{ // Internet Explorer
    		xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
   		}catch (e){
    		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    	}
  	}
	return xmlHttp;
}

function saveVisibility(){
	if(document.changeVisibility.newsVisibility[0].checked == true){
		document.getElementById("showNews").value = "true";
	}else{
		document.getElementById("showNews").value = "false";
	}
	
	if(document.changeVisibility.announcementsVisibility[0].checked == true){
		document.getElementById("showAnnouncements").value = "true";
	}else{
		document.getElementById("showAnnouncements").value = "false";
	}
	
	return true;
}

