var pre1="@", post1=".";
var pre2="%", post2="@";

function mail(ad,expre){
	num=0;
	for(i=0; i<ad.length; i++)
		if(ad.charAt(i)==pre1)num++;
	for(i=0; i<num; i++)
		ad=ad.replace(pre1,post1);
	num=0;
	for(i=0; i<ad.length; i++)
		if(ad.charAt(i)==pre2)num++;
	for(i=0; i<num; i++)
		ad=ad.replace(pre2,post2);
	if(expre==""){
		expre=ad;
	}
	document.write("<A HREF='mailto:" + ad + "'>" + expre + "</A>");
}

function formatStr (v) {
    if (!document.selection) return;
    var str = document.selection.createRange().text;
    if (!str) return;
    document.selection.createRange().text = '<' + v + '>' + str + '</' + v + '>';
}

function midashi () {
    if (!document.selection) return;
    var str = document.selection.createRange().text;
    if (!str) return;
    document.selection.createRange().text = '<h="' + str + '">';
}

function insertLink () {
    if (!document.selection) return;
    var str = document.selection.createRange().text;
    if (!str) return;
    var my_link = prompt('URL: ', 'http://');
    if (my_link != null)
        document.selection.createRange().text = '<a href="' + my_link + '">' + str + '</a>';
}
