// JavaScript Document
var isIE=/*@cc_on!@*/false;  //IE detector

function AjaxRequest()
{
	var xmlhttp = false;
	
	if(isIE)
	{
		try {
			//If the Javascript version is greater than 5.
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			//If not, then use the older active x object.
			try {
				//If we are using MS.
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (E) {
				//Else we must be using a non-IE browser.
				xmlhttp = false;
			}
		}
	}
	
	//If we are using a non-IE browser, create a javascript instance of the object.
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	
	return xmlhttp;
}
	

function makerequest(ajax, serverPage, destination, CancelLoading) 
{
	//var obj = document.getElementById(linkID);	
	var obj = document;	
	if(destination){
		obj = document.getElementById(destination);	
		if(CancelLoading)
			obj.innerHTML = '<center><img src="/facilities/images/nav/Loading1.gif" alt="Loading" width="260" height="100"/></center>';
	}
	
	ajax.open("GET", serverPage);
	ajax.onreadystatechange = function() {
		if(ajax.readyState == 4 && ajax.status == 200){
		obj.innerHTML = ajax.responseText;
		}
	}
	ajax.send(null);
}

function processajax(serverPage, getOrPost, parameters, destination) 
{
	  var ajax = AjaxRequest();
	  var obj = document.getElementById(destination);
	  
      if(getOrPost == "get")
	  {
	  	ajax.open("GET", serverPage);
		ajax.onreadystage = function(){
			if(ajax.readyState == 4 && ajax.status == 200){
				obj.innerHTML = ajax.responseText;
			}
		}
		ajax.send(null);
	  }else{
		ajax.open("POST", serverPage, true);
		ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");		
		ajax.onreadystage = function(){			
			if(ajax.readyState == 4 && ajax.status == 200){
				obj.innerHTML = ajax.responseText;
			}
		}
		ajax.send(parameters);	
		obj.innerHTML = ajax.responseText;
		
	  }
}
function getformvalues(form, valfunc)
{
  	var str = "";
	var aok = true;
	var val = "";
	var formVal = "";
	
	for(var i=0; i<form.elements.length; i++)
	{
		if(valfunc)
		{
			if(aok == true)
			{
				val = valfunc(form.elements[i].value,form.elements[i].name);
				if(val == false)
					aok = false;
			}
		}
		
		
		if((form.elements[i].type=='radio' || form.elements[i].type=='checkbox') && form.elements[i].checked==false)
			aok =1;
		else
			str += form.elements[i].name + "=" + escape(form.elements[i].value) + "&";
		
	}
	
	return str;
}
function hideDiv(divID) {
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(divID).style.visibility = 'hidden';
	}
	else {
		if (document.layers) { // Netscape 4
			document.divID.visibility = 'hidden';
		}
		else { // IE 4
			document.all.divID.style.visibility = 'hidden';
		}
	}
}

function showDiv(divID) {
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(divID).style.visibility = 'visible';
	}
	else {
		if (document.layers) { // Netscape 4
			document.divID.visibility = 'visible';
		}
		else { // IE 4
			document.all.divID.style.visibility = 'visible';
		}
	}
} 				

function ToggleDiv(theDiv)
{
	
	var obj = document.getElementById(theDiv);
	if(obj.style.visibility == 'hidden')
		obj.style.visibility = 'visible';
	else if(obj.style.visibility == 'visible')
		obj.style.visibility = 'hidden';
		
}
function getStyleObject(objectId) {
	  if (document.getElementById && document.getElementById(objectId)) {
		return document.getElementById(objectId).style;
	  } else if (document.all && document.all(objectId)) {
		return document.all(objectId).style;
	  } else {
		return false;
	  }
	}
	
function Querystring(qs) { // optionally pass a querystring to parse
	this.params = {};
	
	if (qs == null) qs = location.search.substring(1, location.search.length);
	if (qs.length == 0) return;

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ');
	var args = qs.split('&'); // parse out name/value pairs separated via &
	
// split out each name=value pair
	for (var i = 0; i < args.length; i++) {
		var pair = args[i].split('=');
		var name = decodeURIComponent(pair[0]);
		
		var value = (pair.length==2)
			? decodeURIComponent(pair[1])
			: name;
		
		this.params[name] = value;
	}
}

Querystring.prototype.get = function(key, default_) {
	var value = this.params[key];
	return (value != null) ? value : default_;
}

Querystring.prototype.contains = function(key) {
	var value = this.params[key];
	return (value != null);
}

function ShowAlert()
{
	if(getCookie('FDC_HideAlert')!='NewBRC') {
		
		if (getCookie('facilities_alert') != 'displayed') {					
			
			// lets only show this once a day
			var exp = new Date();
			// 1 day
			exp.setTime(exp.getTime() + (1*24*60*60*1000));
			SetCookie("facilities_alert", "displayed", exp);
			
			window.open('Alert.html', "_blank", "status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1,height=530, width=520");
		}
	}
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

function SetCookie (name, value) {
  var argv = SetCookie.arguments;
  var argc = SetCookie.arguments.length;
  var expires = (argc > 2) ? argv[2] : null;
  var path = (argc > 3) ? argv[3] : null;
  var domain = (argc > 4) ? argv[4] : null;
  var secure = (argc > 5) ? argv[5] : false;
  document.cookie = name + "=" + escape (value) +
    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
    ((path == null) ? "" : ("; path=" + path)) +
    ((domain == null) ? "" : ("; domain=" + domain)) +
    ((secure == true) ? "; secure" : "");
}
