function isNull(v){
	if( v=="null" ) return true;
	if( v==null ) return true;
	if( v=="" ) return true;
	return false;
}

var doc=App.ActiveDoc;
function Simple()
{
	var pos=doc.CaretPos;
	var txt=doc.GetLineText( pos.Line );

	var txt2="";
	if( pos.Line>0 )
		txt2 = doc.GetLineText( pos.Line-1 );
	var head=txt2.match(/^\s*[\*\-\+] /) + "";
	if( isNull(head) )
		head="* ";

	doc.InsertAt(pos.Line, 0, head);
}

if( !doc.HasSel() ){
	Simple();
}
else{
	var spos=doc.SelStartPos();
	var epos=doc.SelEndPos();
	if( spos.Line==epos.Line )
		Simple();
	else{
		spos.Col=0;
		epos.Col=10000000;
		var sel=doc.GetText(spos, epos, 2); //2 is unix style EOL
		sel = sel.replace(/^\n/gm, "");
		sel = sel.replace(/^(\s*)[\*\-\+] (.*)$/gm, function($1, $2){
			return $1 + "" + $2;
		});
		sel = sel.replace(/^(\s*)/gm, "$1* ");		
		doc.Delete(spos, epos);
		doc.Insert( sel );
		doc.SetSel(epos, spos);
	}
}

