/* ®RM500¯®PL100¯®TS3,6,9,12,15¯ */
myprog="/cgi-bin/archhttp.exe";
var srv_cmd=0;
var cursave;
var my_year="";
var now_rad=0;
var xmlOb=false;

/* ®MDBO¯-------- MY_ESCAPE ---------®MDNM¯ */
function my_escape(what) {
what=escape(what);
/*
what = what.replace(/[+]/gi,"&#043;");
*/
what = what.replace(/[+]/gi,"%2b");
return(what);
}

/* ®MDBO¯---------- REPLY_200 --------®MDNM¯ */
function reply_200(retstr) {
document.getElementById('arch_clear').style.display='';
document.getElementById('arch_display').innerHTML=retstr;
document.getElementById('arch_display').style.display='';
window.scrollTo(0,100);
}

/* ®MDBO¯---------- REPLY_100 ------®MDNM¯ */
function reply_100(retstr) {
var myid=document.getElementById('arch_year');
var got=retstr.split(String.fromCharCode(2));
var now=-1;
if ( (got) && (got.length>0) ) {
	for (var i=0;i<got.length;i++) {
		opt=document.createElement("OPTION");
		opt.text=got[i];
		opt.value=got[i];
		myid.options.add(opt);
		if (got[i]==my_year)
			now=i;
		}
	}
if (now>-1)
	myid.selectedIndex=now;
else
	myid.selectedIndex=0;
switch_all();
}

/* ®MDBO¯---------- REPLY_101 --------®MDNM¯ */
function reply_101(retstr) {
var got=retstr.split(String.fromCharCode(4));
for (i=0;i<3;i++) {
	line=got[i].split(String.fromCharCode(3));
	switch (i) {
		case 0:myid=document.getElementById('arch_months');	break;
		case 1:myid=document.getElementById('arch_subj');	break;
		case 2:myid=document.getElementById('arch_staff');	break;
		}
	myid.options.length=0;
	for (n=0;n<line.length;n++) {
		myitem=line[n].split(String.fromCharCode(2));
		opt=document.createElement("OPTION");
		opt.value=myitem[0];
		opt.text=myitem[1];
		myid.options.add(opt);
		}
	}
}

/* ®MDBO¯---------- SERVER_REPLY ----------®MDNM¯ */
function server_reply() {
if (xmlOb.readyState==4) {
	document.body.style.cursor=cursave;
	var gotstr=xmlOb.responseText;
	if (gotstr.indexOf("Internal Server Error",0)!=-1) {
		alert("There was an error on the server by the MDNEdit program. Let Phill know, this should not have happened.");
		return;
		}
	t=gotstr.split(String.fromCharCode(1));
	if (t.length==1) {
		rc=0;
		retstr=t;
		}
	else {
		rc=t[0];
		retstr=t[1];
		}
	if (rc=='0') {
		alert("ERROR: "+retstr);
		return;
		}
	switch (srv_cmd) {
		case 100:
			reply_100(retstr);
			break;
		case 101:
			reply_101(retstr);
			break;
		case 200:
		case 201:
		case 202:
		case 203:
			reply_200(retstr);
			break;
		}
	}
}


/* ®MDBO¯---------- SERVER_POST ----------®MDNM¯ */
function server_post(what) {
what=what+"&ne_time="+Date();
try { xmlOb = new ActiveXObject("Msxml2.XMLHTTP.DOMDocument.4.0"); }
catch (e) {
	try { xmlOb = new ActiveXObject("Microsoft.XMLHTTP"); }
	catch (e) {
		try { xmlOb = new XMLHttpRequest(); }
		catch (e) {
			alert("Your browser does not support XMLHTTP that is required for communication with the server.");
			return false;
			}
		}
	}
cursave=document.body.style.cursor;
document.body.style.cursor="wait";
xmlOb.open("POST",myprog,true);
xmlOb.onreadystatechange=server_reply;
xmlOb.send(what);
}

/* ®MDBO¯--------- SETUP ------®MDNM¯ */
function setup(who,how) {
if (!how)
	document.getElementById('arch_close').style.display='none';
set_rad(0);
document.getElementById('arch_text').value="";
srv_cmd=100;
my_year=who;
do_clear();
server_post("ne_cmd=100");
}
/* ®MDBO¯------ mylist ------®MDNM¯ */
function mylist(obj,all) {
	var names=new Array();
	var count=0;
if (all==0) {
	for (var i in obj) {
		names[count] = i;
		count++;
		}
	names.sort();
	tstr="count="+count+"\r\n"+names.join("|      ");
	alert(tstr);
	return;
   }
count=0;
for (var i in obj) {
	if (   (i!="fileModifiedDate") && 
   	          (i!="fileCreatedDate") &&
   	          (i!="fileUpdatedDate") &&
   	          (i!="fileModifiedDate") &&
   	          (i!="fileSize") &&
			       (i!="embed") &&
      	       (i!="mimeType") )
		names[count]=i+"="+obj[i];
	else
		names[count]=i+"=[cannot display]";
   count++;
	}
names.sort();
tstr="count="+count+"\r\n"+names.join("|      ");
alert(tstr);
}

/* ®MDBO¯------ SET_RAD -----®MDNM¯ÿ20*/
function set_rad(who) {
if (who=='3')
	document.getElementById('tr_case').style.display='block';
else
	document.getElementById('tr_case').style.display='none';
now_rad=who;
mybut=document.getElementsByTagName('INPUT');
/*
mylist(mybut,0);
arch_how[who].checked=true;
*/
mybut[who].checked=true;
}


/* ®MDBO¯----------- DO_CLEAR ------®MDNM¯ÿ20*/
function do_clear() {
document.getElementById('arch_display').innerHTML="";
document.getElementById('arch_display').style.display="none";
document.getElementById('arch_clear').style.display="none";
}

/* ®MDBO¯--------- DO_FULL_TEXT ------®MDNM¯ */
function do_full_text() {
ne_seek=document.getElementById('arch_text').value;
if (ne_seek=="") {
	alert("Nothing entered for the search.");
	return;
	}
ne_seek=my_escape(ne_seek);
ne_year=document.getElementById('arch_year').value;
if (document.getElementById('arch_case').checked==true)
	ne_case='Y';
else
	ne_case='N';
tstr="ne_cmd=203&ne_year="+ne_year+"&ne_seek="+ne_seek+"&ne_case="+ne_case;
srv_cmd=203;
server_post(tstr);
}

/* ®MDBO¯--------- DOIT --------®MDNM¯ */
function doit() {
if (now_rad==3) {
	do_full_text();
	return;
	}
switch (now_rad) {
	case 0:myid=document.getElementById('arch_months');break;
	case 1:myid=document.getElementById('arch_subj');break;
	case 2:myid=document.getElementById('arch_staff');break;
	}
i=myid.selectedIndex;
my_head=myid.options[i].text;
my_head=my_escape(my_head);
my_file=myid.value;
my_file=my_escape(my_file);
my_year=document.getElementById('arch_year').value;
srv_cmd=200+now_rad;
tstr="ne_cmd="+srv_cmd+"&ne_file="+my_file+"&ne_head="+my_head+"&ne_year="+my_year;
server_post(tstr);
}

/* ®MDBO¯--------- SWITCH_ALL ----------®MDNM¯ */
function switch_all() {
var myid=document.getElementById('arch_year');
var i=myid.selectedIndex;
now_year=myid.options[i].text;
srv_cmd=101;
tstr="ne_cmd=101&ne_year="+now_year;
server_post(tstr);
}

/* ®MDBO¯-------- ARCH_HELP ---------®MDNM¯ÿ20®RM75¯*/
function arch_help() {
alert("Click on the type of search you want to conduct: by date, subject, reporter or full text.\n\n"+
	"Pick the search criteria from the drop-down list, or "+
	"for a full-text search, enter the word or words you wish to search.\n\n"+
	"With a full-text search, only stories with each word (separated by a space) will be displayed. To search for a phrase, put the phrase in quote marks.\n\n"+
	"Then click on the Search button.\r\n\r\n"+
	"If any stories are found, the list of stories that match your search will be displayed below and a new button, Clear, will be displayed.\n\n"+
	"Click on a story link to display the story. Click the clear button to hide the display list.");
}

//