/*
+-------------------------------------------
|
|   Technology of Wane netware
|   ========================================
|   Powered by wan-e.net inc 
|   (c) 2004 wane.net Power Services
|   http://www.wan-e.net
|   ========================================
|   Web: http://www.wan-e.net
|
+-------------------------------------------
|   Autohr	:	wsfuyibing
+-------------------------------------------
*/
var image_help = "插入图像\n\n在文本中插入一幅图像。\n例如：[img]http://www.domain.com/images/logo.gif[/img]";
var image_normal = "请输入图像的 URL。";

var link_normal = "请输入链接显示的文字，如果留空则直接显示链接。";
var link_normal_input = "请输入 URL。";

var email_normal = "请输入链接邮箱显示的文字，如果留空则直接显示链接。";
var email_normal_input = "请输入 邮箱地址。";

var left_normal = "请输入要左对齐文本 或 先选中要对齐的文本";
var center_normal = "请输入要居中对齐文本 或 先选中要对齐的文本";
var right_normal = "请输入要右对齐文本 或 先选中要对齐的文本";

var	zise_normal	=	"请输入要改变字号的文字";
var	color_normal	=	"请输入要改变颜色的文字";


var row_normal = "请输入水平线颜色 如: #666666";

function AddText(NewCode) 
{
	if(document.all)
	{
		insertAtCaret(document.wane_post.context, NewCode);
        setfocus();
    } 
	else
	{
    	document.wane_post.context.value += NewCode;
        setfocus();
	}
}
function storeCaret (textEl)
{
	if(textEl.createTextRange)
	{
		textEl.caretPos = document.selection.createRange().duplicate();
	}
}
function insertAtCaret (textEl, text)
{
	if (textEl.createTextRange && textEl.caretPos)
	{
    	var caretPos = textEl.caretPos;
        caretPos.text += caretPos.text.charAt(caretPos.text.length - 2) == ' ' ? text + ' ' : text;
	} 
	else if(textEl) 
	{
		textEl.value += text;
    } 
	else 
	{
		textEl.value = text;
    }
}
function hyperlink() 
{
	txt2=prompt(link_normal,""); 
    if (txt2!=null) 
	{
    	txt=prompt(link_normal_input,"http://");      
        if (txt!=null) 
		{
        	if (txt2=="") 
			{
            	AddTxt="[url]"+txt;
                AddText(AddTxt);
                AddText("[/url]");
            } 
			else 
			{
            	AddTxt="[url="+txt+"]"+txt2;
                AddText(AddTxt);
                AddText("[/url]");
           }         
       	} 
	}
}
function image() 
{
	txt=prompt(image_normal,"http://");    
    if(txt!=null) 
	{            
    	AddTxt="[img]"+txt;
        AddText(AddTxt);
        AddText("[/img]");
    }       
}
function email() 
{
	txt2=prompt(email_normal,""); 
    if (txt2!=null) 
	{
    	txt=prompt(email_normal_input,"yourname@domain.com");      
        if (txt!=null) 
		{
        	if (txt2=="") 
			{
            	AddTxt="[email]"+txt;
                AddText(AddTxt);
                AddText("[/email]");
            } 
			else 
			{
            	AddTxt="[email="+txt+"]"+txt2;
                AddText(AddTxt);
                AddText("[/email]");
           }         
       	} 
	}       
}
function bold() 
{
	if (document.selection && document.selection.type == "Text") 
	{
		var range = document.selection.createRange();
		range.text = "[b]" + range.text + "[/b]";
    }
	else 
	{  
        txt=prompt(bold_normal,text_input);     
		if (txt!=null) 
		{           
			AddTxt="[b]"+txt;
            AddText(AddTxt);
            AddText("[/b]");
        }       
    }
}
function italicize() 
{
	if (document.selection && document.selection.type == "Text") 
	{
		var range = document.selection.createRange();
		range.text = "[i]" + range.text + "[/i]";
	} 
	else 
	{   
		txt=prompt(italicize_normal,text_input);     
        if (txt!=null) 
		{           
        	AddTxt="[i]"+txt;
            AddText(AddTxt);
            AddText("[/i]");
        }               
	}
}
function underline() 
{
	if (document.selection && document.selection.type == "Text") 
	{
		var range = document.selection.createRange();
		range.text = "[u]" + range.text + "[/u]";
	}
	else 
	{  
		txt=prompt(underline_normal,text_input);
        if (txt!=null) 
		{           
        	AddTxt="[u]"+txt;
            AddText(AddTxt);
            AddText("[/u]");
        }               
	}
}
function align_left() 
{
	if (document.selection && document.selection.type == "Text") 
	{
		var range = document.selection.createRange();
		range.text = "[align=left]" + range.text + "[/align]";
	}
	else 
	{  
		txt=prompt(left_normal,"words for left align");     
		if (txt!=null) 
		{          
			AddTxt="[align=left]"+txt;
			AddText(AddTxt);
            AddText("[/align]");
		}              
	}
}
function center() 
{
	if (document.selection && document.selection.type == "Text") 
	{
		var range = document.selection.createRange();
		range.text = "[center]" + range.text + "[/center]";
	}
	else 
	{  
		txt=prompt(center_normal,"words for align center");     
		if (txt!=null) 
		{          
			AddTxt="[align=center]"+txt;
			AddText(AddTxt);
            AddText("[/align]");
		}              
	}
}
function align_right() 
{
	if (document.selection && document.selection.type == "Text") 
	{
		var range = document.selection.createRange();
		range.text = "[align=right]" + range.text + "[/align]";
	}
	else 
	{  
		txt=prompt(right_normal,"words for align right");     
		if (txt!=null) 
		{          
			AddTxt="[align=right]"+txt;
			AddText(AddTxt);
            AddText("[/align]");
		}              
	}
}

function size() 
{
	if (document.selection && document.selection.type == "Text") 
	{
		var range = document.selection.createRange();
		range.text = "[size=4]" + range.text + "[/size]";
	}
	else 
	{  
		txt=prompt(zise_normal,"words for size");     
		if (txt!=null) 
		{          
			AddTxt="[size=4]"+txt;
			AddText(AddTxt);
            AddText("[/size]");
		}              
	}      
}
function color() 
{
	if (document.selection && document.selection.type == "Text") 
	{
		var range = document.selection.createRange();
		range.text = "[color=#ff0000]" + range.text + "[/color]";
	}
	else 
	{  
		txt=prompt(color_normal,"words for color");     
		if (txt!=null) 
		{          
			AddTxt="[color=#ff0000]"+txt;
			AddText(AddTxt);
            AddText("[/color]");
		}              
	}       
}
function list() 
{
	AddTxt="[list]\r[*]\r[/list]";
    AddText(AddTxt);
}
function row() 
{
	txt=prompt(row_normal,"#666666");    
    if(txt!=null) 
	{            
    	AddTxt="[rowline="+txt+"]";
        AddText(AddTxt);
    }  
}
function setfocus() 
{
	document.wane_post.context.focus();
}