// AJAX SETUP

// first set up IE/Moz javascript xml object
// http://jibbering.com/2002/4/httprequest.html
var fader;
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 "Find Us In Your County"
function getProgramsForCounty(county) {
	document.body.style.cursor='wait';
	xmlhttp.open("GET", "county_map.php?get_programs_for_county="+escape(county), true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			document.getElementById('program_descriptions').innerHTML = xmlhttp.responseText;
			document.body.style.cursor='auto';
		}
	}
	xmlhttp.send(null);
}

// for "Document Archive"
function flipDocumentCategoryState(cat_id) {
	if (document.getElementById('cat_container_'+cat_id).style.display == 'none') {
		document.body.style.cursor = 'wait';
		xmlhttp.open("GET", "docs.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 = 'images/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 = 'images/doc-arrow-right.gif';
		document.getElementById('cat_container_'+cat_id).style.display = 'none';
		setCookie('doc_cat_status['+cat_id+']', 0);
	}
}

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));
}

