var http3 = new XMLHTTPObject();   //used for restore and save

	
//not used now
function getSessionID(){
	var http4 = new XMLHTTPObject();   //used for restore and save
	http4.onreadystatechange = function()
	{
	if(http4.readyState == 4)
		{
		if(http4.status == 200)
		{
		var sessionID = http4.responseText;  //
	        restorePage(sessionID);
	    
		
	}
	}
}
http4.open("GET","../php/getsession.php",true);
http4.send(null);

}
function savePageDanny() {
//hide everything in the content_box in the hidden form


		var codetosave = document.getElementById("content_box").innerHTML;
		var sessionField =document.getElementById("sessionField");
		sessionField.value = codetosave;
	        
}
function restorePageDanny(){
//copy from hidden form into contentbox
var sessionField =document.getElementById("sessionField").value;

if(sessionField=="empty") fetchData("../content/welcome.html","content_box");
else
	{
	document.getElementById("content_box").innerHTML = sessionField;
	
}
}
var http5 = new XMLHTTPObject();   //used for save page
function savePage(){
	
	var parms = document.getElementById("content_box").innerHTML;
        //alert("savePage before "+parms);
        
	http5.onreadystatechange = function()
	{
        //alert(http5.readyState+" "+http5.status);
	if(http5.readyState == 4) 
		{
		if(http5.status == 200) 
		{
		var result = http5.responseText;     //sent by the server code called
		//just save page in session object
		if (result.indexOf('ERROR:')>=0) {
			//change error message div
			document.getElementById("error_box").innerHTML = unescape(result);
	        }
		}
		}
	}
	try {} catch (e) {alert(e);}
	//sends the contents of the page to the session object, so that it can be redisplayed upon reload
	//had to use a post here because of size of data being saved from the page;other gets in script need testing for size
	
	http5.open("POST","../php/writestate.php",true);
	var nvp = "content="+escape(parms);
	http5.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http5.send(nvp);
	
	
	
	

}





function restorePage(){
	
        
	http3.onreadystatechange = function() 
	{
	if(http3.readyState == 4) 
		{
		if(http3.status == 200) 
		{
		var result = http3.responseText;     //sent by the server code called
		
		
		document.getElementById("content_box").innerHTML = unescape(result);
		}
		}
	}
	
	myurl = "../php/readstate.php";
	
	http3.open("GET",myurl,true);
	http3.send(null);
	
	

}


//used in processing the join.php form
var browser=navigator.userAgent.toLowerCase();
function XMLHTTPObject() {
   
   var xmlhttp=false;
   
   
    try {xmlhttp = new XMLHttpRequest();}
        catch(e) {
            try {xmlhttp = new ActiveXObject("MSXML2.XMLHTTP.3.0");} 
              catch(e) {
                
                try {xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");}

		catch (e) {}
               }
              
    }
   
    return xmlhttp; 
    } 
    
function doSiteSelect(sel,subdomain){
	//alert(sel.value+subdomain);
	//repeat doSecondary and tell them the selected site is the primary site
	//maybe give them a link to view
	var sitename=sel.value;
	//create an XMLHTTPObject
	//done already called http (see below)
	if (!http) {alert("no XMLHTTPObject");return;}
	var url="../php/primary.php";
        url=url+"?sitename="+sitename+"&subdomain="+subdomain;
        
        http.open("GET",url,true);
        http.onreadystatechange=stateChanged2;
        try {} catch (e) {alert(e);}
        http.send(null);
	
}

function stateChanged2(){
	//alert("stateChanged");
	if (http.readyState==4 || http.readyState=="complete"){
     	  
     	  if (http.status==200)
     	   {
     	   //alert(http.responseText);
           document.getElementById("site_form").innerHTML=http.responseText ;
        }
         
    }
} 
 
function doSecondary(sel){
	//alert(sel.value);
	var subdomain=sel.value;
	//create an XMLHTTPObject
	//done already called http (see below)
	if (!http) {alert("no XMLHTTPObject");return;}
	var url="../php/primary.php";
        url=url+"?subdomain="+subdomain;
        
        http.open("GET",url,true);
        http.onreadystatechange=stateChanged;
        try {} catch (e) {alert(e);}
        http.send(null);
}

function stateChanged(){
	//alert("stateChanged");
	if (http.readyState==4 || http.readyState=="complete"){
     	  
     	  if (http.status==200)
     	   {
     	   //alert(http.responseText);
           document.getElementById("secondary_form").innerHTML=http.responseText ;
        }
         
    }
} 

function clearError()
{
	document.getElementById("error_box").innerHTML = "";
	
}

function doSubmit(formname){
	document.getElementsByName(formname)[0].submit();
	return false;
}
function init(formname) {
//formname is the name of the form , assumes only one form per page and we want the first one   
    
    
     //if(browser.indexOf('msie 6.0')>=0){alert("found ie"); document.formname.action="../php/formaction.php";alert(document.formname.action);}
    //document.getElementById(formname).onsubmit = saveData; //The saveData function is attached to the submit action of the form. 
    document.getElementsByName(formname)[0].onsubmit=saveData;
    //above is triggering the onsubmit - which was overriding the ajax in IE6  
    
}
    //window.onload = init; 
    //http://www.openjs.com/ajax/tutorial/contents.php
    //The 'init' function will be called when the page is loaded - now moved to the form submit button
    //This function saveData() will be called when the submit is triggered
function saveData(formname) 
{
//alert("saveData "+formname);	
//must get all of the input elements on the form and return the value
var elems = document.getElementsByTagName("input"); // yes, wildcards do exist

var parms="";
 
//alert(elems.length);

for (var i=0;i<elems.length;i++) {
//alert(elems[i].name+" "+elems[i].value);
//if (elems[i].name == 'mybutton'){ var button=elems[i].value;}    //should be the type of form - not used
//make name value pairs for the submit
if(elems[i].type =='radio'&&!elems[i].checked) continue;           //only take the checked ones of the radio buttons
if(elems[i].type =='checkbox'&&!elems[i].checked) continue;        //only take the checked ones of the check boxes
parms=parms+elems[i].name+"="+elems[i].value+"&";

}

var elems = document.getElementsByTagName("select");
if (elems)
{
	for (var i=0;i<elems.length;i++){
		parms=parms+elems[i].name+"="+elems[i].value+"&";
	}
}

//var action = parms.search('Login');   //save for later, determines what nav to display next
//var join = parms.search('Join');      //save for later, says the join form submitted

//alert(action);

//By calling this file, we process the data, value of button tells how
//need to derive the formaction dynamically????

var myurl ="../php/formaction.php?"+parms+"return=confirm";    //not using return but it finishes the format 

//might be a synchronization issue in IE6.0 -- not sure, but FF doesn't like 'false' (synchronized)
http.open("GET",myurl,true);
http.onreadystatechange = doReadyState;   //order important - form would not chain in IE7
try {} catch (e) {alert(e);}

http.send(null);

return false;//Prevent the form from being submited

}  //end saveData

function changeSideBar() {
	
	parms ="user=yes";
	http.open("GET","../php/login_personal.php?" + parms+"&return=confirm",true);
	http.onreadystatechange = doSideBar; 
	try {} catch (e) {alert(e);}
	http.send(null);
}

function doSideBar(){
	
	if(http.readyState == 4) 
		{
		
		if(http.status == 200) 
		{
		var result = http.responseText;     //sent by the server code called\
		
		document.getElementById("sidebar").innerHTML= result;
		
		}
		}
	
	}
	
	
function changeNav() {
	//builds menu with logout button
	var http2 = new XMLHTTPObject();
	if(!http2) alert("Browser does not support XMLHttpRequest");  
	var parms="in=yes";     //add to createmenu this test
       
	http2.open("GET","../php/createmenu.php?" + parms+"&return=confirm",true);
	
	http2.onreadystatechange = function() {
	
	
		//alert("dochangeNav readyState="+http2.readyState);
	

		if(http2.readyState == 4) 
		{
		//alert("changeNav status="+http2.status)
		if(http2.status == 200) 
		{
		var result = http2.responseText;     //sent by the server code called
		
		document.getElementById("nav").innerHTML = result;
		}
		
		}
		
		
		return true;
		} 
	try {} catch (e) {alert(e);}
	
	http2.send(null);
        
	return true;
}



function doReadyState(){
//main form processing function

if(http.readyState == 4) 
{
if(http.status == 200) 
{
var result = http.responseText;     //sent by the server code called



//only want to change if login successful
//never displays in IE6
//alert("doReadyState "+result);

var status = result.indexOf('ERROR:'); 
var action = result.indexOf('Login');   //really bad because it requires this to be in the message

//action >=0 means the Login button has been found in the parms
//status >=0 means an error message has been returned from the server designated by ERROR:
if (action>=0&&status<0) 
//means we have a login and there are no errors, so change navigation menu and display
{
        var finished = false;
	finished = changeNav();   //change the navigation if successful
	
	//need to build in a serialization methedology - above only works when an alert is used
	while (!finished){}
	document.getElementById("form_elements").innerHTML = result;  //replace form with new content
	
	
	
	changeSideBar();
	//load in an info page du jour via ajax
	
}
  	

//means we have an error, so just display the error without changing the display
if (status>=0) document.getElementById("error_box").innerHTML = result;
else  document.getElementById("error_box").innerHTML = "";   //clear the error box

//if join clicked and no errors
if (status<0) 
{
	document.getElementById("form_elements").innerHTML = result;  //replace form with message
	document.getElementById("error_box").innerHTML = "";
        
        
}
savePage();  //must save the result after the form submitted
}  //end status 200 check
}  //end readystate check

}  //end readystatechange function

//change the navigation back to original
function changeNav2(){
	
	var parms="in=no&logout=yes";     //add to createmenu this test
	http.open("GET","../php/createmenu.php?" + parms+"&return=confirm",true);
	http.onreadystatechange = function() 
	{
	if(http.readyState == 4) 
		{
		if(http.status == 200) 
		{
		var result = http.responseText;     //sent by the server code called
		//alert(result);
		document.getElementById("nav").innerHTML = result;
		}
		}
	}
	http.send(null);
	
	//original code
	//result="<li><a class=\"\" href=\"#\" onclick=\"javascript:fetchData('/content/join.php','content_box');\" >Join</a></li><li class=\"\"><a href=\"#\" onclick=\"javascript:fetchData('/content/login.php','content_box');\" title=\"Login\">Login</a></li><li class=\"\"><a href=\"#\" onclick=\"javascript:fetchData('/content/search.php','content_box');\" title=\"Search\">Search</a></li><li class=\"\"><a href=\"#\" onclick=\"javascript:fetchData('/content/recent.php','content_box');\" title=\"Recent\">Recent</a></li><li class=\"\"><a href=\"#\" onclick=\"javascript:fetchData('/content/community.php','content_box');\" title=\"Community\">Community</a></li>";
        
        
}

function doPublish(thissitename,user){
myurl = "http://"+thissitename+"/bwmu/ui.php";
mychild = window.open('/bwmu/ui.php','new');






}

//general ajax to fetch content in myurl into div indicated by objectID


    function fetchData(myurl,objectID){
        
       
	var pageRequest = false;
	if (window.XMLHttpRequest) {
		pageRequest = new XMLHttpRequest();
	}
	else if (window.ActiveXObject){ 
		try {
			pageRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) {
			try{
				pageRequest = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){}
		}
	}
	else return false;
	pageRequest.onreadystatechange=function() {	
		var object = document.getElementById(objectID);
		object.innerHTML = pageRequest.responseText;
	        
		savePage();    //writes persistant record
	}
	        
		pageRequest.open('GET',myurl,true);
		pageRequest.send(null);
		
			
}




var http = new XMLHTTPObject();
if(!http) alert("Browser does not support XMLHttpRequest");   
    
<!-- Copyright 2002 Bontrager Connection, LLC

function getCalendarDate()
{
   var months = new Array(13);
   months[0]  = "January";
   months[1]  = "February";
   months[2]  = "March";
   months[3]  = "April";
   months[4]  = "May";
   months[5]  = "June";
   months[6]  = "July";
   months[7]  = "August";
   months[8]  = "September";
   months[9]  = "October";
   months[10] = "November";
   months[11] = "December";
   var now         = new Date();
   var monthnumber = now.getMonth();
   var monthname   = months[monthnumber];
   var monthday    = now.getDate();
   var year        = now.getYear();
   if(year < 2000) { year = year + 1900; }
   var dateString = monthname +
                    ' ' +
                    monthday +
                    ', ' +
                    year;
   return dateString;
} // function getCalendarDate()

function getClockTime()
{
   var now    = new Date();
   var hour   = now.getHours();
   var minute = now.getMinutes();
   var second = now.getSeconds();
   var ap = "AM";
   if (hour   > 11) { ap = "PM";             }
   if (hour   > 12) { hour = hour - 12;      }
   if (hour   == 0) { hour = 12;             }
   if (hour   < 10) { hour   = "0" + hour;   }
   if (minute < 10) { minute = "0" + minute; }
   if (second < 10) { second = "0" + second; }
   var timeString = hour +
                    ':' +
                    minute +
                    ':' +
                    second +
                    " " +
                    ap;
   return timeString;
} 

//-->

function checkFormData(formvalue)
{
	//alert(formvalue);
	//badvalues are also found in config.php
	var badvalues = ['/','+',' ','&','*','<','>','"','\'','!','*','@','#','^','(',')'];
	
	for (var i=0;i<badvalues.length;i++){
	if (formvalue.indexOf(badvalues[i])>=0) {alert("Illegal characters");return false;}
	
}

return true;
}


function isMac() {
	 //alert(navigator.userAgent.indexOf('Mac')); 
         if(navigator.userAgent.indexOf('Mac') != -1) alert("Mac Users. Please note that the MAC AOL browser should not be used. Please try the Mac Firefox browser.  The publishing part of application is not available in any Mac environment at the present time.");
	 
	}






