var _unloadprompt = false;


function enableUnloadPrompt() {
	_unloadprompt = true;
	window.onbeforeunload = unloadMessage;
}


function disableUnloadPrompt() {
	_unloadprompt = false;
	window.onbeforeunload = null;
}


function unloadMessage(){
	return ("Your blog post will not be saved.");
}
				





function okBrowser() {
	var ua = navigator.userAgent.toLowerCase();
	
	// returns false if found msie 5.1, netscape 6, or generally macintosh and os9. 
	// as pc browsers generally behave better.
	// this list may grow with time
	
	// g m
			
	var result = 
		!(
			((ua.indexOf('msie') > -1)  && (navigator.appVersion.substring(0,1)<=6))
			|| 
			(ua.indexOf('aol') > -1) 
			|| 
			(ua.indexOf('netscape') > -1)	
			||
			((ua.indexOf('macintosh')> -1) && (ua.indexOf('os x') < 0))	
		)
	;
	
	// alert(result);	// debug
	return (result);
}




function wrapin(boxid, starthtml, endhtml) {
		var dc=document.getElementById(boxid);
		
		if ((dc.selectionStart||dc.selectionEnd) && (dc.selectionStart!=dc.selectionEnd)) {
			dc.value = dc.value.substring(0,dc.selectionStart) 
			+ starthtml
			+ dc.value.substring(dc.selectionStart,dc.selectionEnd)
			+ endhtml
			+ dc.value.substring(dc.selectionEnd,dc.value.length)
		} else 
		{
			alert ('Please select some text to format first'); 
		}
		return (false);
}

function insertat(boxid,html) {
	var dc=document.getElementById(boxid);
	if (html == null) html = '';
	dc.value = dc.value.substring(0,dc.selectionStart)+html+dc.value.substring(dc.selectionStart,dc.value.length);
	return false;
}



function insertimgat(boxid) {
	var dc=document.getElementById(boxid);
	
	var url = prompt("Please enter web address (URL) of image?");
	if (!url) return false;

	html = '<img src="'+url+'" />';
	return (insertat(boxid, html));

}


function linkorinsertlinkat(boxid) {
	var dc=document.getElementById(boxid);
	var wrap = (dc.selectionStart && (dc.selectionStart != dc.selectionEnd));
	
	var url = prompt("Please enter web address (URL) to link to?");
	if (!url) return false;
	
	if (wrap) {
		title = dc.value.substring(dc.selectionStart, dc.selectionEnd);
	} else {
		var title = prompt("Title of link? (optional)");
		if ((title == null) || (!title)) title = url.replace('http://','');
	}
	
	if (url.substring(0,4)=="www.") url = "http://"+url;
	
	html = '<a href="'+url+'">'+title+'</a>';
	if (wrap) return (wrapin(boxid, '<a href="'+url+'">', "</a>"));
	else return (insertat(boxid, html));
}


    
function toggle_inline(what) { 
	var a = document.getElementById(what).style.display;
    document.getElementById(what).style.display = (a=="inline") ? "none" : "inline"; 
	return (false);}

    
function toggle_block(what) { 
	var a = document.getElementById(what).style.display;
    document.getElementById(what).style.display = (a=="block") ? "none" : "block"; 
	return (false);}
