/******************readme.js*********************
*	Reads in README.html form current 	*
*	directory, then adds the Information	*
*	to the tab display.  Gray's tab if no	*
*	file found.				*
*************************************************/

function readme() {
	this.showREADME = 0;
	this.displayed = "";
	this.ajaxComm = new ajaxObj();
	this.domain = document.domain;
	this.ie = 0;

	this.show_readme = function(){
		if( showREADME ){
			show_content( "README_popup" );
		}
	}

	// close the div tags
	this.hide_readme = function(){
		if( showREADME ){
			show_content( "README_popup" );
		}
	}

	// add header information to the page
	this.write_header = function(){
		var text = "";
		var url = location.href;
		var directory = url.split( this.domain );
		var dirs = directory[1].split( "/" );
		var current_dir = "";
		var hasSlash = 0;
		if( dirs[dirs.length-1] == "" ){
			hasSlash = 1;
		}
		for( var i in dirs){
			if( dirs[i] ){
				current_dir += "/" + dirs[i];
				if( dirs[i].indexOf('?') < 0  &&  (i != dirs.length - hasSlash)){
					dirs[i] = dirs[i].replace(/casil/, "CaSIL");
					dirs[i] = dirs[i].replace( /^./, dirs[i].charAt(0).toUpperCase() );
					if( i != (dirs.length - 1 - hasSlash) ){
						text = "<a href=http://"+this.domain+current_dir+" style='color: #002666; text-decoration: none;'>"+dirs[i]+"</a> &raquo; ";
					} else {
						text = dirs[i];
					}
					document.getElementById("breadcrumbs").innerHTML += text;
				}
			}
		}
	}


	// add the readme html to popup div
	this.write_readme = function(){
		var parsedlocation = location.href.split('?')[0];
		function onSuccess(resp, mirrorObj) {
			mirrorObj.showREADME = 1;
			document.getElementById("readmeDiv").innerHTML = resp;
			mirrorObj.write_header();
		}
		function onFailure(resp, mirrorObj) {
			document.getElementById("readmeDiv").innerHTML = "There is currently no info for this directory.";
			mirrorObj.write_header();
			mirrorObj.showREADME = 0;
		}
		parsedlocation = parsedlocation.replace( /\/$/, "" );
		this.ajaxComm.localRequest( parsedlocation+"/README.html", onSuccess, null, onFailure, this);
	}
}



// this is a DOM Obj creater
/* DOM Parser, create a DOM object */
function mkDOMObj (text){
	if (typeof DOMParser != "undefined") {
		// Mozilla, Firefox, and related browsers
        	return (new DOMParser()).parseFromString(text, "application/xml");
        } else if (typeof ActiveXObject != "undefined") {
        	// Internet Explorer.
                var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
                xmlDoc.async="false";
                xmlDoc.loadXML(text);
                return xmlDoc;                   // Return it
        } else {
        	// As a last resort, try loading the document from a data: URL
                // This is supposed to work in Safari. Thanks to Manos Batsis and
                // his Sarissa library (sarissa.sourceforge.net) for this technique.
                var url = "data:text/xml;charset=utf-8," + encodeURIComponent(text);
                var request = new XMLHttpRequest();
                request.open("GET", url, false);
                request.send(null);
                return request.responseXML;
        }
}
