// AJAX SETUP

// first set up IE/Moz javascript xml object
// http://jibbering.com/2002/4/httprequest.html
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
		}
	}
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	xmlhttp = new XMLHttpRequest();
}

// for "Document Archive"
function flipDocumentCategoryState(cat_id) {
	if(cat_id!='static'){
		if (document.getElementById('cat_container_'+cat_id).style.display == 'none') {
			document.body.style.cursor = 'wait';
			xmlhttp.open("GET", "employees-resources.php?get_documents_in_category="+cat_id, true);
			xmlhttp.onreadystatechange=function() {
				if (xmlhttp.readyState==4) {
					document.getElementById('cat_container_'+cat_id).innerHTML = xmlhttp.responseText;
					document.getElementById('doc_category_toggle_'+cat_id).src = 'template_graphics/doc-arrow-down.gif';
					document.getElementById('cat_container_'+cat_id).style.display = 'block';
					setCookie('doc_cat_status['+cat_id+']', 1);
					document.body.style.cursor = 'auto';
				}
			}
			xmlhttp.send(null);
		} else {
			document.getElementById('doc_category_toggle_'+cat_id).src = 'template_graphics/doc-arrow-right.gif';
			document.getElementById('cat_container_'+cat_id).style.display = 'none';
			setCookie('doc_cat_status['+cat_id+']', 0);
		}
	//working with something we hacked it
	} else {
		if (document.getElementById('cat_container_'+cat_id).style.display == 'none') {
			document.getElementById('doc_category_toggle_'+cat_id).src = 'template_graphics/doc-arrow-down.gif';
			document.getElementById('cat_container_'+cat_id).style.display = 'block';
			setCookie('doc_cat_status['+cat_id+']', 1);
			document.body.style.cursor = 'auto';
		} else {
			document.getElementById('doc_category_toggle_'+cat_id).src = 'template_graphics/doc-arrow-right.gif';
			document.getElementById('cat_container_'+cat_id).style.display = 'none';
			setCookie('doc_cat_status['+cat_id+']', 0);
		}
	}
}
function getContinuedStory(newsletter_continued_story_id) {
	if (document.getElementById('continued_story_'+newsletter_continued_story_id).style.display == 'none') {
		document.body.style.cursor = 'wait';
		xmlhttp.open("GET", "employees-newsletter.php?get_continued_story_id="+newsletter_continued_story_id, true);
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {
				document.getElementById('continued_story_'+newsletter_continued_story_id).innerHTML = xmlhttp.responseText;
				document.getElementById('continued_story_'+newsletter_continued_story_id).style.display = 'block';
				document.body.style.cursor = 'auto';
			}
		}
		xmlhttp.send(null);
	} else {
		document.getElementById('continued_story_'+newsletter_continued_story_id).style.display = 'none';
	}
}

function setCookie(cookieName,cookieValue) {
	var today = new Date();
	var expire = new Date();
	var nDays=365;
	expire.setTime(today.getTime() + 3600000*24*nDays);
	document.cookie = cookieName+"="+escape(cookieValue)
				 + ";expires="+expire.toGMTString();
}
function getCookie(name) { // use: getCookie("name");
	var index = document.cookie.indexOf(name + "=");
	if (index == -1) return null;
	index = document.cookie.indexOf("=", index) + 1;
	var endstr = document.cookie.indexOf(";", index);
	if (endstr == -1) endstr = document.cookie.length;
	return unescape(document.cookie.substring(index, endstr));
}


//EMPLOYEE DIRECTORY SELECT FUNCTIONS
function changeDivisions(which){
/*	var value = which.value;
	var opts = value.split("***");
	
	document.getElementById('division').value = opts[0];
	document.getElementById('program_id').value = opts[1];
*/
	document.divisions.submit();
}
