////////////////////////////////////////////////////////////////////////////
// NYCRx Javascript Calls
////////////////////////////////////////////////////////////////////////////

// include other JS...
document.write('<script src="/toolkit/assets/javascript/prototype.js"><\/script>');
document.write('<script src="/toolkit/assets/javascript/scriptaculous.js"><\/script>');

// call a global variable  (rather than sending it out and parsing it back in)
var theID = '';

// this function toggles between two visible divs
function toggleLayer(whichLayerShow, whichLayerHide)
{
	document.getElementById(whichLayerHide).style.display = "none";
	//document.getElementById(whichLayerShow).style.display = "";
	new Effect.Appear( document.getElementById(whichLayerShow));
}

// this function allows the visible toggle for just one div
function showHideLayer(whichLayer)
{
	theLayer = document.getElementById(whichLayer);
	theLayer.style.display = (theLayer.style.display != "none") ? "none" : "";
}

// this function hides one div
function hideLayer(whichLayer)
{
	//document.getElementById(whichLayer).style.display = "none";
	new Effect.Fade( document.getElementById(whichLayer));
}
function hideLayerPlain(whichLayer)
{
	document.getElementById(whichLayer).style.display = "none";
}

// this function shows a div
function showLayer(whichLayer)
{
	//document.getElementById(whichLayer).style.display = "block";
  new Effect.Appear( document.getElementById(whichLayer));
}
// this function shows a div
function showLayerPlain(whichLayer)
{
	document.getElementById(whichLayer).style.display = "block";
}


// functions for the person viewer


// browser check
if (navigator.appName.indexOf("Microsoft")!=-1&&parseInt(navigator.appVersion)>=4) {
	var ie = 1;
}
else {
	var ie = null;
}
if (navigator.userAgent.indexOf("Safari")!=-1) {
	var safari = 1;
}
else {
	var safari = null;
}

// these are generic AJAX functions
var req;

function aj(data,div) 
{
	// here, we assign a universal variable  for the div id
	theID = div;
	// add the div to the variable... slick, yes
	data = data+'&d[div]='+div;
	if (div !='') {
		document.getElementById(theID).innerHTML = '<br /><br /><img src="/toolkit/assets/images/spinner.gif" alt="loading..." alt="loading..." />';
	}
	// branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.open("POST", "/toolkit/assets/ajax/ajax.php", true);
				req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        req.send(data);
        req.onreadystatechange = processReqChange;
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("POST", "/toolkit/assets/ajax/ajax.php", true);
						req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
            req.send(data);
        }
    }
}
function processReqChange() 
{
	// only if req shows "complete"
	if (req.readyState == 4) {
		// only if "OK"
		if (req.status == 200 && theID !='') {
			// set the id's HTML to the result
			document.getElementById(theID).innerHTML = req.responseText;
		} 
		if (req.status != 200) {
			// explain the problem (we need error checking here)
			alert("Ajax Javascript Request Error\n" + req.statusText);
		}
	}
}