﻿var isIE = (!document.all && document.getElementById) ? 0 : 1;
var text;
var addtxt

function setfocus() {
	var postText = document.getElementById("all_msg");
	postText.focus();
}

function getSel() {
	textarea = document.getElementById('all_msg');
	selection = textarea.value.substr(textarea.selectionStart, textarea.selectionEnd - textarea.selectionStart);
	return selection;
}

function getActiveText(selectedtext) { 
	text = (isIE) ? document.selection.createRange().text : window.getSelection();
	//text = (isIE) ? document.selection.createRange().text : getSel();	
	if (selectedtext.createTextRange) {	
    	selectedtext.caretPos = document.selection.createRange().duplicate(); }
	return true;
}

function AddText(NewCode) {
	setfocus();
	var postText = document.getElementById("all_msg");
	if(isIE) {
		if (postText.createTextRange && postText.caretPos) {
			var caretPos = postText.caretPos;
			caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? NewCode + ' ' : NewCode;
		} else {
			postText.value+=NewCode; 
		}
	} else if (typeof(postText.selectionStart) == "undefined") { // safari fix
		postText.value+=NewCode;
	} else {
		pos = postText.selectionStart;
		postText.value = postText.value.substr(0, pos) + NewCode + postText.value.substr(pos);
		postText.selectionStart = pos + NewCode.length;
		postText.selectionEnd = postText.selectionStart;
	}
	setfocus();
}


function bold() {
        addtxt = '';
		txt=prompt("請輸入設為粗體字的文字。","這裡輸入你要的文字");     
		if (txt!=null) {           
			addtxt = "[b]"+txt+"[/b]";
			if (addtxt) AddText(addtxt);			
		}       

}

function italicize() {
        addtxt = '';
		txt=prompt("請輸入設為斜體字的文字。","這裡輸入你要的文字");     
		if (txt!=null) {           
			addtxt = "[i]"+txt+"[/i]";
			if (addtxt) AddText(addtxt);
		}	        

}

function underline() {
        addtxt = '';
		txt=prompt("請輸入設為底線的文字。","這裡輸入你要的文字");     
		if (txt!=null) {           
			addtxt = "[u]"+txt+"[/u]";
			if (addtxt) AddText(addtxt);
		}	        
}

function delline() {
        addtxt = '';
		txt=prompt("請輸入設為刪除線的文字。","這裡輸入你要的文字");     
		if (txt!=null) {           
			addtxt = "[s]"+txt+"[/s]";
			if (addtxt) AddText(addtxt);
		}	        
}


function center() {
        addtxt = '';
		txt=prompt("請輸入設為置中的文字。","這裡輸入你要的文字");     
		if (txt!=null) {          
			addtxt = "[center]"+txt+"[/center]";
			if (addtxt) AddText(addtxt);
		}	       

}

function hyperlink() {
        addtxt = '';
		txt2=prompt("將文字設為超連結，\n若您想以URL為連結文字則不需輸入任何文字。",""); 
		if (txt2!=null) {
			txt=prompt("欲連結的URL","http://www.17high.com.tw");      
			if (txt!=null) {
				if (txt2=="") {
					addtxt = "[url="+txt+"]"+txt+"[/url]";					
				} else {
					addtxt = "[url="+txt+"]"+txt2+"[/url]";
				}
				if (addtxt) AddText(addtxt);      
			} 
		}

}

function image() {
        addtxt = '';
		txt=prompt("圖片的所在URL。","http://");    
		if(txt!=null) {            
			addtxt = "[img]"+txt+"[/img]";
			if (addtxt) AddText(addtxt);
		}	

}

function email() {
            addtxt = '';
			txt=prompt("請輸入電子郵件位址。","");      
			if (txt!=null) {
				addtxt = "[email]"+txt+"[/email]";
				if (addtxt) AddText(addtxt);
			}		

}

function temper(NewCode) {
                addtxt = '';
				addtxt = "["+NewCode+"]";
				if (addtxt) AddText(addtxt);	

}

function addMovie(){
addtxt = '';	
txt = prompt('請輸入影片連結，目前支援的影片為youtube，例:http://www.youtube.com/v/yY8Wk8mY8_k&hl=zh_TW&fs=1','http://');
if(txt!=null)addtxt = '[movie]' + txt + '[/movie]';
if (addtxt) AddText(addtxt);

}


function addVr(){
addtxt = '';	
txt = prompt('請輸入影片連結，目前支援的檔案為Swf，mov，例:http://www.17high.com.tw/images/demovr.swf','http://');
if(txt!=null)addtxt = '[vr]' + txt + '[/vr]';
if (addtxt) AddText(addtxt);

}

//function addMovie(){
//addtxt = '';	
//ss = prompt('請輸入影片連結，目前支援的影片為youtube，例:http://www.youtube.com/watch?v=RXNwIP2uzts','http://');
//if(null == ss){return false;}
//if( ss.match(/^http:\/\/[^\.]+.youtube.com/) || ss.match(/^http:\/\/youtube.com/)){
//   addtxt = '[movie=' + ss + ']';
//   if (addtxt) AddText(addtxt);
//}
//else{
//alert('請填寫正確影片連結');
//}
//}


function addfont()
{
addtxt = '';
b = prompt('請選擇字型變化，若不需設定請留空白： 1.粗體 2.斜體 3.底線 ','');
ss1 = prompt('請選擇字型大小，若不需設定請留空白： 1.小 2.中 3.大 ','');
ss2 = prompt('請選擇字型顏色，若不需設定請留空白： 1.深紅 2.紅 3.橘 4.棕 5.黃 6.綠 7.橄欖 8.青綠 9.藍色 10.深藍 11.靛 12.紫 13.灰 14.黑','');
ss3 = prompt('請輸入字串！','');
bary = new Array(3);
var b1 = '';
var b2 = '';
bary[1] = 'b';
bary[2] = 'i';
bary[3] = 'u';
if( bary[b] ){b1 = '['+bary[b]+']';b2 = '[/'+bary[b]+']';}
sary = new Array(3);
var size = '';
sary[1] = '2';
sary[2] = '4';
sary[3] = '6';
if( sary[ss1] ) size = sary[ss1];
cary = new Array(3);
var color = '';
cary[1] = 'darkred';
cary[2] = 'red';
cary[3] = 'orange';
cary[4] = 'brown';
cary[5] = 'yellow';
cary[6] = 'green';
cary[7] = 'olive';
cary[8] = 'cyan';
cary[9] = 'blue';
cary[10] = 'darkblue';
cary[11] = 'indigo';
cary[12] = 'violet';
cary[13] = 'gray';
cary[14] = 'black';
if( cary[ss2] ) color = cary[ss2];
if( ss3) addtxt = ss3;
if( ss3 && size) addtxt = '[font size=' + size + ']' + ss3 + '[/font]';
if( ss3 && color) addtxt = '[font color=' + color + ']' + ss3 + '[/font]';
if( ss3 && size && color) addtxt = '[font size=' + size + ' color=' + color + ']' + ss3 + '[/font]';
if(addtxt && b1 && b2) addtxt = b1 + addtxt + b2 
if(addtxt)AddText(addtxt);
}

