var Sound = 0;
var Swf = 0;
var Ra = 0;
var Rm = 0;
var text_enter_text     ="請輸入文字";
var text_enter_url      = "請輸入連接網址";
var text_enter_txt      = "請輸入連接說明";
var text_enter_image    = "請輸入圖片網址";
var text_enter_sound    = "請輸入音樂聲音文件網址";
var text_enter_swf      = "請輸入Flash動畫網址";
var text_enter_ra      = "請輸入Real音樂網址";
var text_enter_rm      = "請輸入Real影片網址";
var text_enter_wmv      = "請輸入Media影片網址";
var text_enter_wma      = "請輸入Media音樂網址";
var text_enter_mov      = "請輸入QuickTime音樂網址";
var text_enter_sw      = "請輸入shockwave音樂網址";
var text_enter_email    = "請輸入電郵網址";
var text_enter_guang1   = "文字的長度、顏色和邊界大小";
var text_enter_guang2   = "要產生效果的文字";


function sd_FormatText(Command,value) {
document.getElementById('sd_Content').contentWindow.document.body.focus();
document.getElementById('sd_Content').contentWindow.document.execCommand(Command,false,value);
}


function openLink(URI){
win = window.open(URI);

}


function sd_link(sdsd,iidd)
{
var iidd;
var enterURL;
if (iidd==0)
{
enterURL   = prompt('請輸入連接地址：', 'http://');

}
else if (iidd==1)
{
enterURL   = "mailto:"+prompt('請輸入電子郵件地址：','');
}
else
{
enterURL=prompt('請輸入圖片地址', 'http://');
}
if (!enterURL) {
alert("注意!您沒有輸入連接");
}
else
{

sd_FormatText(sdsd, enterURL);
}
}

function DoTitle(addTitle){
var submain=document.form1.submain.value;
document.form1.submain.value=addTitle+submain;
document.form1.submain.focus();
return (false);
}

function DoEmot(addEmot){
var ly=document.form1.detail.value;
document.form1.detail.value=ly+addEmot;
document.form1.detail.focus();
return (false);
}

function FontChange(NameValue,FontValue){
	var ly=document.form1.detail.value;
	if (NameValue == "font")
	{
		document.form1.detail.value="[face="+FontValue+"]"+ly+"[/face]"	;
	}
	if (NameValue == "size")
	{
		document.form1.detail.value="[size="+FontValue+"]"+ly+"[/size]"	;
	}
	if (NameValue == "color")
	{
		document.form1.detail.value="[color="+FontValue+"]"+ly+"[/color]";	
	}
	document.form1.detail.focus();
	return (false);
}

function FontType(HeadValue,FooterValue){
var FoundErrors = '';
var enterTxT   = prompt(text_enter_text, "");
if (!enterTxT)    {
FoundErrors = "True"
}
if (FoundErrors)  {
return;
}
var ToAdd = HeadValue+enterTxT+FooterValue;
document.form1.detail.value+=ToAdd;
document.form1.detail.focus();
}

function Validator(theForm)
{
  if (theForm.name.value == "")
  {
    alert("請寫上您的姓名");
    theForm.name.focus();
    return (false);
  }
  if (theForm.submain.value == "")
  {
    alert("請寫上文章主題");
    theForm.submain.focus();
    return (false);
  }      
  if (theForm.detail.value == "")
  {
    alert("請寫上您的文章");
    theForm.detail.focus();
    return (false);
  }
  return (true);
}
function AddText(text) {
	//if (document.form1.detail.createTextRange && document.form1.detail.caretPos) {      
		//var caretPos = document.form1.detail.caretPos;      
		//caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?
		//text + ' ' : text;
	//}
	//else 
	document.getElementById('sd_Content').contentWindow.document.body.innerHTML += text;
	//document.form1.detail.focus(caretPos);
}
function inputs(str)
{
AddText(str);
}
function Curl() {
var FoundErrors = '';
var enterURL   = prompt(text_enter_url, "http://");
var enterTxT   = prompt(text_enter_txt, enterURL);
if (!enterURL)    {
FoundErrors = "True"
}
if (!enterTxT)    {
FoundErrors = "True"
}
if (FoundErrors)  {
return;
}
var ToAdd = "[URL="+enterURL+"]"+enterTxT+"[/URL]";
document.form1.detail.value+=ToAdd;
document.form1.detail.focus();
}
function Cimage() {
var FoundErrors = '';
var enterURL   = prompt(text_enter_image, "http://");
if (!enterURL) {
FoundErrors = "True"
}
if (FoundErrors) {
return;
}
var ToAdd = "<br>[IMG]"+enterURL+"[/IMG]";
document.getElementById('sd_Content').contentWindow.document.body.innerHTML +=ToAdd;
}



function Cyoutube() 
{
var enterURL   = prompt("請輸入Youtube代碼：", "");
if (!enterURL)
{
alert("無效代碼輸入，請重新輸入");
}
else
{
if (!enterURL.match("youtube.com")) {
alert("沒有輸入輸入YOUTUBE代碼，或者輸入的代碼不是YOUTUBE Video");
}
else
{
var youtube=enterURL.split("src=\"");
if (youtube[1])
{
var youtube=youtube[1].split("\" type=");
if (youtube[0])
{
var ToAdd = "[Youtube]"+youtube[0]+"[/Youtube]";
document.getElementById('sd_Content').contentWindow.document.body.innerHTML+=ToAdd;
document.getElementById('sd_Content').contentWindow.document.body.focus();
}
else
{
	alert("輸入的代碼不正確，請重新輸入");
}
}
else
{
	alert("輸入的代碼不正確，請重新輸入");
}
}
}
}



function Cyahoo() {
var enterURL   = prompt("請輸入Yahoo!Video代碼：", "");
if (!enterURL)
{
alert("無效代碼輸入");
}
else
{
if (!enterURL.match("yahoo.com")) 
{
alert("沒有輸入輸入Yahoo!Video代碼，或者輸入的代碼不是Yahoo！Video"); 
}
else
{
var youtube=enterURL.split("<param name=\"flashVars\" value=\"");
if(youtube[1])
{
var youtube=youtube[1].split("\" /><embed src=\"");
if(youtube[0])
{
var ToAdd = "[vyahoo]"+youtube[0]+"[/vyahoo]";
document.getElementById('sd_Content').contentWindow.document.body.innerHTML+=ToAdd;
document.getElementById('sd_Content').contentWindow.document.body.focus();
}
else
{
	alert("代碼輸入不正確，請重新輸入")
}
}
else
{
alert("無效代碼輸入");
}
}
}
}
function Cgoogle() {
var enterURL   = prompt("請輸入Google Video代碼：", "");
if (!enterURL)
{
alert("無效代碼輸入");
}
else
{
if (!enterURL.match("google.com")) 
{
alert("沒有輸入輸入Google Video代碼，或者輸入的代碼不是Google Video"); 
}
else
{
var youtube=enterURL.split("<embed id=\"VideoPlayback\" src=\"");
if(youtube[1])
{
var youtube=youtube[1].split("\" style=\"width:400px;height:326px\"");
if(youtube[0])
{
var ToAdd = "[flash=400,326]"+youtube[0]+"[/flash]";
document.getElementById('sd_Content').contentWindow.document.body.innerHTML+=ToAdd;
document.getElementById('sd_Content').contentWindow.document.body.focus();
}
else
{
	alert("代碼輸入不正確，請重新輸入")
}
}
else
{
alert("無效代碼輸入");
}
}
}
}


function Cemail() {
var emailAddress = prompt(text_enter_email,"");
if (!emailAddress) { 
return;
 }
var ToAdd = "[EMAIL]"+emailAddress+"[/EMAIL]";
document.form1.detail.value+=ToAdd;
document.form1.detail.focus();
}
function Csound() {
var FoundErrors = '';
var enterURL   = prompt(text_enter_sound, "http://");
if (!enterURL) {
FoundErrors = "True"
}
if (FoundErrors) {
return;
}
var ToAdd = "[SOUND]"+enterURL+"[/SOUND]";
document.getElementById('sd_Content').contentWindow.document.body.innerHTML+=ToAdd;
//document.form1.detail.focus();
}

helpstat = false;
stprompt = true;
basic = false;
function thelp(swtch){
	if (swtch == 1){
		basic = false;
		stprompt = false;
		helpstat = true;
	} else if (swtch == 0) {
		helpstat = false;
		stprompt = false;
		basic = true;
	} else if (swtch == 2) {
		helpstat = false;
		basic = false;
		stprompt = true;
	}
}

function Cswf() {
 	if (helpstat){
		alert("Flash\nFlash 動畫.\n用法： [flash=寬度, 高度]Flash 文件的地址[/flash]");
	} else if (basic) {
		AddTxt="[flash=500,350][/flash]";
		AddText(AddTxt);
	} else {                  
		txt2=prompt("flash寬度，高度","500,350"); 
		if (txt2!=null) {
                txt=prompt("Flash 文件的地址","http://");
		if (txt!=null) {
                          if (txt2=="") {             
			AddTxt="[flash=500,350]"+txt;
			AddText(AddTxt);
			AddTxt="[/flash]";
			AddText(AddTxt);
               } else {
		        AddTxt="[flash="+txt2+"]"+txt;
			AddText(AddTxt);
			AddTxt="[/flash]";
			AddText(AddTxt);
		 }        
	    }  
       }
    }
}

function Crm() {
	if (helpstat) {
               alert("realplay\n播放realplay文件.\n用法： [rm=寬度, 高度]文件地址[/rm]");
	} else if (basic) {
		AddTxt="[rm=500,350][/rm]";
		AddText(AddTxt);
	} else { 
		txt2=prompt("視頻的寬度，高度","500,350"); 
		if (txt2!=null) {
			txt=prompt("視頻文件的地址","輸入");
			if (txt!=null) {
				if (txt2=="") {
					AddTxt="[rm=500,350]"+txt;
					AddText(AddTxt);
					AddTxt="[/rm]";
					AddText(AddTxt);
				} else {
					AddTxt="[rm="+txt2+"]"+txt;
					AddText(AddTxt);
					AddTxt="[/rm]";
					AddText(AddTxt);
				}         
			} 
		}
	}
}

function Cwmv() {
	if (helpstat) {
               alert("Media Player\n播放Media Player文件\n用法： [mp=寬度, 高度]文件地址[/mp]");
	} else if (basic) {
		AddTxt="[mp=500,350][/mp]";
		AddText(AddTxt);
	} else { 
		txt2=prompt("視頻的高度、寬度","500,350"); 
		if (txt2!=null) {
			txt=prompt("視頻文件的地址","請輸入");
			if (txt!=null) {
				if (txt2=="") {
					AddTxt="[mp=500,350]"+txt;
					AddText(AddTxt);
					AddTxt="[/mp]";
					AddText(AddTxt);
				} else {
					AddTxt="[mp="+txt2+"]"+txt;
					AddText(AddTxt);
					AddTxt="[/mp]";
					AddText(AddTxt);
				}         
			} 
		}
	}
}

function Cmov() {
	if (helpstat) {
               alert("QuickTime\n播放QuickTime文件.\n用法： [qt=寬度, 高度]文件地址[/qt]");
	} else if (basic) {
		AddTxt="[qt=500,350][/qt]";
		AddText(AddTxt);
	} else { 
		txt2=prompt("視頻的寬度，高度","500,350"); 
		if (txt2!=null) {
			txt=prompt("視頻文件的地址","請輸入");
			if (txt!=null) {
				if (txt2=="") {
					AddTxt="[qt=500,350]"+txt;
					AddText(AddTxt);
					AddTxt="[/qt]";
					AddText(AddTxt);
				} else {
					AddTxt="[qt="+txt2+"]"+txt;
					AddText(AddTxt);
					AddTxt="[/qt]";
					AddText(AddTxt);
				}         
			} 
		}
	}
}

function Cdir() {
	if (helpstat) {
               alert("Shockwave\n插入Shockwave文件.\n用法： [dir=寬度，高度]文件地址[/dir]");
	} else if (basic) {
		AddTxt="[dir=500,350][/dir]";
		AddText(AddTxt);
	} else { 
		txt2=prompt("Shockwave文件的寬度，高度","500,350"); 
		if (txt2!=null) {
			txt=prompt("Shockwave文件的地址","請輸入");
			if (txt!=null) {
				if (txt2=="") {
					AddTxt="[dir=500,350]"+txt;
					AddText(AddTxt);
					AddTxt="[/dir]";
					AddText(AddTxt);
				} else {
					AddTxt="[dir="+txt2+"]"+txt;
					AddText(AddTxt);
					AddTxt="[/dir]";
					AddText(AddTxt);
				}         
			} 
		}
	}
}



function Cra() {
var FoundErrors = '';
var enterURL   = prompt(text_enter_ra, "http://");
if (!enterURL) {
FoundErrors = "True"
}
if (FoundErrors) {
return;
}
var ToAdd = "[RA]"+enterURL+"[/RA]";
document.form1.detail.value+=ToAdd;
document.form1.detail.focus();
}

function Cwma() {
var FoundErrors = '';
var enterURL   = prompt(text_enter_wma, "http://");
if (!enterURL) {
FoundErrors = "True"
}
if (FoundErrors) {
return;
}
var ToAdd = "[wma]"+enterURL+"[/wma]";
document.form1.detail.value+=ToAdd;
document.form1.detail.focus();
}
function Cguang() {
var FoundErrors = '';
var enterSET   = prompt(text_enter_guang1, "255,red,2");
var enterTxT   = prompt(text_enter_guang2, "文字");
if (!enterSET)    {
FoundErrors = "True"
}
if (!enterTxT)    {
FoundErrors = "True"
}
if (FoundErrors)  {
return;
}
var ToAdd = "[glow="+enterSET+"]"+enterTxT+"[/glow]";
document.form1.detail.value+=ToAdd;
document.form1.detail.focus();
}

function Cying() {
var FoundErrors = '';
var enterSET   = prompt(text_enter_guang1, "255,blue,1");
var enterTxT   = prompt(text_enter_guang2, "文字");
if (!enterSET)    {
FoundErrors = "True"
}
if (!enterTxT)    {
FoundErrors = "True"
}
if (FoundErrors)  {
return;
}
var ToAdd = "[SHADOW="+enterSET+"]"+enterTxT+"[/SHADOW]";
document.form1.detail.value+=ToAdd;
document.form1.detail.focus();
}

ie = (document.all)? true:false
if (ie){
function ctlent(eventobject){if(event.ctrlKey && window.event.keyCode==13){this.document.form1.submit();}}
}

function showpic(pic,ddd)
{
var imgg=new Image();
var picwidth,picheight,pic,ddd;
imgg.src=pic;
if ((imgg.width)>ddd)
{
picwidth=ddd;
picheight=parseInt(ddd*(imgg.height)/(imgg.width));
document.write ("<a href="+pic+" target=_blank><img src="+pic+" width="+picwidth+" height="+picheight+" border=0></img></a>");
}
else
{
document.write ("<img src="+pic+" width="+(imgg.width)+" height="+(imgg.height)+" border=0></img>");
}
}

function CopyDate()
{
document.form1.content.value=document.getElementById('sd_Content').contentWindow.document.body.innerHTML;
}
function submitPreview()
{
if (document.form1.name.value=="")
{
alert("您沒有輸入發表人稱呼，請重新輸入!");
}
else if (document.form1.topic.value=="")
{
alert("您沒有輸入發表主題，請重新輸入!");
}
else if (document.form1.authorname.value=="" && document.form1.author[0].checked)
{
alert("您選擇了轉載，請輸入轉載自何處！");
}
else
{
CopyDate();
document.form1.target="_blank";
document.form1.action="temp.php";
document.form1.submit();
}
}
function submitForm(dname)
{
if (document.form1.name.value=="")
{
alert("您沒有輸入發表人稱呼，請重新輸入!");
}
else if (document.form1.topic.value=="")
{
alert("您沒有輸入發表主題，請重新輸入!");
}
else if (document.form1.authorname.value=="" && document.form1.author[0].checked)
{
alert("您選擇了轉載，請輸入轉載自何處！");
}
else
{
CopyDate();
document.form1.target="_parent";
if(dname=="press")
{
document.form1.action="pressok.php";
}
else if (dname=="update")
{
document.form1.action="updateok.php";
}
document.form1.submit();
}
}
function mediaplay() {
var mediaAddress = prompt("請輸入影音或圖片連接","http://");
if (!mediaAddress) 
{ 
alert("沒有輸入影音或圖片連接"); 
}
else
{
if(document.form1.linklink.value=="")
{
document.form1.linklink.value=mediaAddress;
}
else
{
document.form1.linklink.value=document.form1.linklink.value+","+mediaAddress;
}
}
}
function youtubeplay() {
var mediaAddress = prompt("請輸入YOUTUBE代碼：","");
if(!mediaAddress)
{
	alert("無效代碼輸入");
}
else
{
if (!mediaAddress.match("youtube.com")) 
{ 
alert("沒有輸入輸入YOUTUBE代碼，或者輸入的代碼不是YOUTUBE Video"); 
}
else
{
var youtube=mediaAddress.split("src=\"");
if (youtube[1])
{
if (youtube[1].match("\" frameborder="))
{
var youyoutube=youtube[1].replace("embed","v");
var youtube=youyoutube.split("\" frameborder=");

}
else
{
var youtube=youtube[1].split("\" type=");
}
if (youtube[0])
{
var youtube=youtube[0]+".vyoutube";
if(document.form1.linklink.value=="")
{
document.form1.linklink.value=youtube;
}
else
{
document.form1.linklink.value=document.form1.linklink.value+","+youtube;
}
}
else
{
alert("無效代碼輸入，請重新輸入");
}
}
}
}
}
function vyahooplay() {
var mediaAddress = prompt("請輸入Yahoo!Video代碼：","");
if(!mediaAddress)
{
	alert("無效代碼輸入");
}
else
{
if (!mediaAddress.match("yahoo.com")) 
{ 
alert("沒有輸入輸入Yahoo!Video代碼，或者輸入的代碼不是Yahoo！Video"); 
}
else
{
var youtube=mediaAddress.split("<param name=\"flashVars\" value=\"");
if(youtube[1])
{
var youtube=youtube[1].split("\" /><embed src=\"");
if(youtube[0])
{
var youtube=youtube[0]+".vyahoo";
if(document.form1.linklink.value=="")
{
document.form1.linklink.value=youtube;
}
else
{
document.form1.linklink.value=document.form1.linklink.value+","+youtube;
}
}
else
{
alert("無效代碼輸入，請重新輸入");
}
}
}
}
}


function vflashplay() {
var mediaAddress = prompt("請輸入Google Video代碼：","");
if(!mediaAddress)
{
	alert("無效代碼輸入");
}
else
{
if (!mediaAddress.match("google.com")) 
{ 
alert("沒有輸入輸入Google Video代碼，或者輸入的代碼不是Google Video"); 
}
else
{
var youtube=mediaAddress.split("<embed id=\"VideoPlayback\" src=\"");
if(youtube[1])
{
var youtube=youtube[1].split("\" style=\"width:400px;height:326px\"");
if(youtube[0])
{
var youtube=youtube[0]+".vflash";
if(document.form1.linklink.value=="")
{
document.form1.linklink.value=youtube;
}
else
{
document.form1.linklink.value=document.form1.linklink.value+","+youtube;
}
}
else
{
alert("無效代碼輸入，請重新輸入");
}
}
}
}
}

function submitNewsPreview()
{
if (document.form1.topic.value=="")
{
alert("您沒有輸入發表主題，請重新輸入!");
}
else if (document.form1.authorname.value=="" && document.form1.author[0].checked)
{
alert("您選擇了轉載，請輸入轉載自何處！");
}
else
{
CopyDate();
document.form1.target="_blank";
document.form1.action="newstemp.php";
document.form1.submit();
}
}

function submitNewsForm(dname)
{
if (document.form1.topic.value=="")
{
alert("您沒有輸入發表主題，請重新輸入!");
}
else if (document.form1.authorname.value=="" && document.form1.author[0].checked)
{
alert("您選擇了轉載，請輸入轉載自何處！");
}
else
{
CopyDate();
document.form1.target="_parent";
if(dname=="press")
{
document.form1.action="newsok.php";
}
else if (dname=="update")
{
document.form1.action="modnewsok.php";
}
document.form1.submit();
}
}

function addEmbed()
{
var embedname=prompt("Please input Embed code：","");
if (embedname.match("<embed"))
 {
embstr=embedname.split("<embed");
embfinal=embstr[1].split("</embed>");
embedfinal=embfinal[0].replace("allowscriptaccess=\"always\"","");
document.getElementById('sd_Content').contentWindow.document.body.innerHTML="<div align=center><table border=1><tr><td><embed"+embedfinal+"</embed></td></tr></table></div>"+document.getElementById('sd_Content').contentWindow.document.body.innerHTML;
document.getElementById('sd_Content').contentWindow.document.body.focus();		
 }
 else
 {
alert("The codes you inputed isn't Embed codes, Please input again"); 
 }
}

function addiframe()
{
var iframename=prompt("Please enter the iframe target link：","");
if(iframename != '' && iframename != null)
 {
if(!iframename.match("<iframe"))
{
document.getElementById('sd_Content').contentWindow.document.body.innerHTML="<div align=center><table border=1 bgcolor=#000000 width=650 height=1000><tr><td><iframe align=\"left\" scrolling=\"no\" width=\"700\" height=\"1000\" frameborder=\"0\" src=\""+iframename+"\"></td></tr></table></div>"+document.getElementById('sd_Content').contentWindow.document.body.innerHTML;
document.getElementById('sd_Content').contentWindow.document.body.focus();
}
else
{
document.getElementById('sd_Content').contentWindow.document.body.innerHTML=iframename+document.getElementById('sd_Content').contentWindow.document.body.innerHTML;
document.getElementById('sd_Content').contentWindow.document.body.focus();
}		
 }
 else
 {
alert("The iframe target link you entered is not correct. Please enter again!"); 
 }
}
	 
	 
