
// function ToggleNotesPopup()
// div_id - the id of the notespopup div to toggle
// div_type - the type of popup ('hover' or 'normal'). if 'normal', make sure only one div is open at a time
function ToggleNotesPopup(div_id, div_type){
	//document.getElementById('div_notespopup_'+div_id).style.left = document.getElementById('span_notespopup_'+div_id).style.left;
	if(div_type == null){
		div_type = "hover";
	}
	if(document.getElementById('div_notespopup_'+div_id).style.visibility == 'visible'){
		if(div_type == "normal"){
			document.last_div_normal = null;
		}
		document.getElementById('div_notespopup_'+div_id).style.visibility = 'hidden';
	}
	else{
		if(div_type == "normal"){
			if(document.last_div_normal != null){
				document.getElementById('div_notespopup_'+document.last_div_normal).style.visibility = 'hidden';
			}
			document.last_div_normal = div_id;
		}
		document.getElementById('div_notespopup_'+div_id).style.visibility = 'visible';
	}
}

// Select all text in textarea of text box
function SelectAll(id)
{
    document.getElementById(id).focus();
    document.getElementById(id).select();
}

// AJAX
ajaxObject = function() {
try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch(e){
try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch(e){
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e){
try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e){
try { return new XMLHttpRequest() } catch(e){
throw new Error( "This browser does not support XMLHttpRequest." );
}}}}}}

function ajax_request(url, div_processing){
	if(div_processing != null && div_processing != ""){
		if(document.getElementById(div_processing) != null){
			document.getElementById(div_processing).style.display = "inline";
		}
	}
	
	var response = ajax_request2(url, "GET", "", "", "", "", "");
	
	if(div_processing != null && div_processing != ""){
		if(document.getElementById(div_processing) != null){
			document.getElementById(div_processing).style.display = "none";
		}
	}
	
	return response;
}

function ajax_request2(url, method, params, async, last_modified, optional_headers){
	if(method != "POST"){
		method = "GET";
		params = null;
	}
	if(async == null || async != false){async = true;}
	if(last_modified == ""){last_modified = null;}
	//if(optional_headers == ""){optional_headers = null;}
	
	var request = new ajaxObject();
	request.open(method, url, async);
	
	if(last_modified != null){	
		request.setRequestHeader("If-Modified-Since", last_modified);
	}
	
	if(optional_headers != null && optional_headers != ""){
		for(var i in optional_headers){
			return i;
		}
	}
	
	if(method == "POST"){
		request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		request.setRequestHeader("Content-length", params.length);
		request.setRequestHeader("Connection", "close");	
	}
	
	request.send(params);
	
	if(!request.getResponseHeader("Date") && last_modified == null){
		var cached = request;
		last_modified = cached.getResponseHeader("Last-Modified");
		last_modified = (last_modified) ? last_modified : new Date(0); // January 1, 1970
		request = ajax_request2(url, method, params, async, last_modified);
		if(request.status == 304){
			request = cached;
		}
	}
	
	var response = request.responseText;
	
	return response;
}

// track_url
var tracked_urls = new Array();
function track_url(url, once){
	var track = true;
	if(once != null && once == true){
		if(tracked_urls[url] != null){
			track = false;
		}
		else{
			 tracked_urls[url] = true;
		}
	}
	if(track == true){
		ajax_request('script_tracking.php?url='+url)
	}
}
