function getPageIds(page){
	document.getElementById('response_text').innerHTML = '';
	url = 'ajax_actions.php?action=getids&page='+page;
	 var http_request = false;

        if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
                // See note below about this line
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
      //  alert(url);
        http_request.onreadystatechange = function() { setIds(http_request); };
        http_request.open('GET', url, true);
        http_request.send(null);
}

function setIds(http_request){
	if (http_request.readyState == 4) {
            if (http_request.status == 200) {
				//alert(http_request.responseText);
				document.getElementById('ids').options.length = 0;
				var ids = http_request.responseText.split(',');
				document.getElementById('ids').options[0] = new Option('', '');
            	for(i=0;i<ids.length;i++){
            		var theindex = i+ 1;
            		id = ids[i];

            		document.getElementById('ids').options[theindex]= new Option(id,id);
            		//opt = new Option(id,id,false,false);
            		//document.getElementById('ids').add(opt);
            	}
            	document.getElementById('contentx').value = '';
            } else {
                alert('There was a problem with the request.');
            }
        }
}

function getHelpContent(page,id){
	document.getElementById('response_text').innerHTML = '';
	url = 'ajax_actions.php?action=get_help_content&page='+page+'&id='+id;
	 var http_request = false;

        if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
                // See note below about this line
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
      //  alert(url);
        http_request.onreadystatechange = function() { setHelpContent(http_request); };
        http_request.open('GET', url, true);
        http_request.send(null);
}

function setHelpContent(http_request){
	if (http_request.readyState == 4) {
            if (http_request.status == 200) {
				document.getElementById('contentx').value = http_request.responseText;
            } else {
                alert('There was a problem with the request.');
            }
        }
}

function writeHelpContent(page, id, text){
url = 'ajax_actions.php?action=write_help_content&page='+page+'&id='+id+'&content='+text;
	 var http_request = false;

        if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
                // See note below about this line
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
      //  alert(url);
        http_request.onreadystatechange = function() { confirmWrite(http_request); };
        http_request.open('GET', url, true);
        http_request.send(null);
}
function confirmWrite(http_request){
	if (http_request.readyState == 4) {
            if (http_request.status == 200) {
			//	alert(http_request.responseText);
			document.getElementById('response_text').innerHTML = http_request.responseText;
            } else {
                alert('There was a problem with the request.');
            }
        }
}

function updateDivisions(text){
    selectbox = document.getElementById('divisions');
    selectbox.options.length = 0;
    lines = text.split("\n");
    for(var i = 0; i<lines.length;i++){
        data = lines[i].split(",");
        var opt = new Option(data[1],data[0]);
        if (window.ActiveXObject){
            selectbox.add(opt);
        }else{
            selectbox.add(opt,null);
        }

    }
}
function showNarratives(project){
    id = 'narrative_' + project;
    imgx = 'img_' + project;

    display = document.getElementById(id).style.display;
    if(display == 'none'){
        document.getElementById(id).style.display = '';
        document.getElementById(imgx).src = 'assets/images/subtract.gif';
    }else{
        document.getElementById(id).style.display='none';
        document.getElementById(imgx).src = 'assets/images/add.gif';
    }
}
function setHeight(){
	/*height = (document.getElementById('footer').offsetTop - 85) + 'px';*/
	header_bottom = 86;
	footer_top = document.getElementById('footer').offsetTop;
	height = footer_top - header_bottom
	height += 'px';
	foo = footer_top-header_bottom+'px';
	if(document.getElementById('left').style.height == ''){
		document.getElementById('left').style.height = height;
	}
	//alert('footertop: '+(footer_top-header_bottom) + ',left.height: ' + (document.getElementById('left').style.height));

}
window.onload = function(){setHeight();}
window.onresize = function(){setHeight();}

