﻿var Selection = null;

function initiFrmContent(scss) 
{
	var HtmlSource = "";
	
	HtmlSource += "<html><head>";
	HtmlSource += "<link href='" + scss + "' rel='stylesheet' type='text/css'>";
	HtmlSource += "</head><body></body></html>";
	
	
	iFrmContent.document.designMode="On";
    	iFrmContent.document.open("text/html");
    	iFrmContent.document.write(HtmlSource);
    	iFrmContent.document.close();

	
	iFrmContent.document.domain = "wpark.com.tw";
	document.domain = "wpark.com.tw";
}

function setFont(oSelect)
{
    if (oSelect.options[oSelect.selectedIndex].value != '')
        iFrmContent.document.execCommand("FontName", true, oSelect.options[oSelect.selectedIndex].value);
                   
    oSelect.selectedIndex = 0;   
}

function setFontSize(oSelect)
{
    if (oSelect.options[oSelect.selectedIndex].value != '')
        iFrmContent.document.execCommand("FontSize", true, oSelect.options[oSelect.selectedIndex].value);
        
    oSelect.selectedIndex = 0;
}

function editContent(act)
{
	Selection = iFrmContent.document.selection.createRange();
	
	if (Selection != null) Selection.select();
    
	switch (act)
	{
		case "Bold" :
		case "Italic" :
		case "Underline" :
		case "StrikeThrough" :        
		case "JustifyLeft" :
		case "JustifyCenter" :
		case "JustifyRight" :
		    iFrmContent.document.execCommand(act, true, '');
		    break;
		case "fontcolor" :
		case "bgcolor" :        
		    showFontColorBox(act);
		    break;
		case "link" :
		    showLinkBox();
	}
}

function showLinkBox()
{
    iFrmContent.focus();
    iFrmContent.document.execCommand("CreateLink",true);
}

function showFontColorBox(act)
{
	var SelectColor = OpenColorSelect();
	
	if(SelectColor != null)
	{
		if(SelectColor.length >= 7)
		{
			if (Selection != null) 
			{
	        		Selection.select();
	        }
	        
			if (act == "fontcolor")
			{
				iFrmContent.document.execCommand("ForeColor", true, SelectColor);
			}
			
			if (act == "bgcolor")
			{
				iFrmContent.document.execCommand("BackColor", true, SelectColor );
			}
		}
	}
}

function OpenColorSelect()
{
	var winW = 425;
	var winH = 315;
	
	var winL = (screen.width - winW) / 2;
	var winT = (screen.height - winH) / 2;
	
	var CheckVal = window.showModalDialog("/Common/SelectColor.html", "winColorSelect", "dialogHeight: " + winH + "px; dialogWidth: " + winW + "px; dialogTop: " + winT + "px; dialogLeft: " + winL + "px; edge: Raised; center: Yes; help: No; resizable: No; scroll : No; status: No;");     
     
     if(CheckVal != null)
     {
     	return CheckVal;
     }
	else
	{
		return null;
	}
}


function LoadAddImage(strImgUrl, strImgPos, blnPopup)
{
	strImgUrl = strImgUrl.replace(/'/g, "\'");

	var strCurImage = "http://upload.wpark.com.tw/UploadTemp" + strImgUrl;
	var strAfterImage = "http://upload.wpark.com.tw/UploadComplate" + strImgUrl;
	
	//alert(strCurImage);
	
	var strPopsc = "";
	
	if(blnPopup)
	{
		strPopsc = " style=\"cursor:hand\" onclick=\"ImageView('" + strAfterImage + "')\"";
	}
	
     var strText = "";
            
	if(strCurImage.match(/.jpg|.jpeg|.gif|.png$/i))
    	{
		var imgid = parseInt((Math.random()*10000000));    
		
		if(blnPopup)
		{
			if (strImgPos == 'top' || strImgPos == 'bottom')
			{
            		strText = "<center><img src=\"" + strCurImage + "\" align='center' id=\"ImgUserUpload" + imgid + "\" onload=\"setTimeout('SetImageSize(" + imgid + ")',200)\" style=\"cursor:hand\" onclick=\"ImageView('" + strAfterImage + "')\"></center>";
			}
        		else
			{
            		strText = "<img src=\"" + strCurImage + "\" align=\"" + strImgPos + "\" id=\"ImgUserUpload" + imgid + "\" onload=\"setTimeout('SetImageSize(" + imgid + ")',200)\" style=\"cursor:hand\" onclick=\"ImageView('" + strAfterImage + "')\">";
			}
		}
		else
		{ 
			if (strImgPos == 'top' || strImgPos == 'bottom')
			{
            		strText = "<center><img src=\"" + strCurImage + "\" align='center' id=\"ImgUserUpload" + imgid + "\" onload=\"setTimeout('SetImageSize(" + imgid + ")',200)\"" + strPopsc + "></center>";
			}
        		else
			{
            		strText = "<img src=\"" + strCurImage + "\" align=\"" + strImgPos + "\" id=\"ImgUserUpload" + imgid + "\" onload=\"setTimeout('SetImageSize(" + imgid + ")',200)\"" + strPopsc + ">";
			}
		}
    	}
	try
	{
		if (strImgPos=='top')
		{
			iFrmContent.document.body.innerHTML =  strText+ "<br>" + iFrmContent.document.body.innerHTML;
		}
		else if (strImgPos=='bottom')
		{
			iFrmContent.document.body.innerHTML =  iFrmContent.document.body.innerHTML + "<br>" + strText + "<br>";
		}
		else
		{
			iFrmContent.focus();
			
			var sText = iFrmContent.document.selection.createRange();
		
			if (sText.parentElement().all.EDITOR == null)
			{
				if (sText.parentElement().outerHTML.indexOf('<BODY') > 0)
				{
				    sText.parentElement().innerHTML = "<P>" + strText + sText.parentElement().innerHTML  +  "</P>"
				}
				else
				{
				    sText.parentElement().innerHTML = strText + sText.parentElement().innerHTML
				}
			}
		     else
		     {
		        	iFrmContent.document.body.innerHTML = "<P>" + strText + iFrmContent.document.body.innerHTML + "</P>";
			}
		}
	}
	catch(e)
	{
		iFrmContent.document.body.innerHTML = "<P>" + strText + iFrmContent.document.body.innerHTML + "</P>";
	}

}

function resizeByContent()
{
	var height = iFrmContent.document.body.scrollHeight + 10;
	
	//alert(height);
	
	if(height < 250)
	{
		height = 250;
	}

	if(height != parseInt( document.all.iFrmContent.style.height ))
	{
		document.all.iFrmContent.style.height = height;
		parent_Resize_Frame('IfrmBoard');
	}
				
	setTimeout( 'resizeByContent()', 1000 );
}

function decodeContent(str)
{
    return str.replace(/&lt;/gi,"<").replace(/&gt;/gi,">").replace(/&amp;/gi,"&");
}

function UpdateContent()
{
    iFrmContent.document.body.innerHTML = decodeContent(document.all.DIVContent.innerHTML);
}

function SetImageSize(num)
{
    var oImg = eval("document.getElementById('ImgUserUpload" + num + "')");
    
    if (oImg.width > 700)
    {
       oImg.width = 700;
       
       parent_Resize_Frame('IfrmBoard');
    }
}

function LoadUploadedFile(sfullfilename, sfilename, sfilesize)
{
	
	var CurFileListLength = document.frmSection.selUploadFileList.length;

	document.frmSection.selUploadFileList.length = CurFileListLength + 1;
	document.frmSection.selUploadFileList.options[CurFileListLength].text = sfilename;
	document.frmSection.selUploadFileList.options[CurFileListLength].value = sfilesize;
	
	document.frmSection.selHiddenList.length = CurFileListLength + 1;
	document.frmSection.selHiddenList.options[CurFileListLength].text = sfullfilename;
	document.frmSection.selHiddenList.options[CurFileListLength].value = sfilesize;
	
	ReSetFileForm();
}

var intModifyPollItemSize = 0;

function AddPollItem(sitem)
{
	intModifyPollItemSize++;
	
	var strInputBox = "";
	
    	strInputBox = "<input type='hidden' name='hidPollItem" + intModifyPollItemSize + "' value='" + sitem + "'>";
     
	document.all.divPollItem.innerHTML += strInputBox;
    
    	document.frmSection.txtAddPollItemCnt.value = intModifyPollItemSize; 
    
}

function AddPollDisplay(intPollCnt, simgsrc)
{
	var intPollItemSize = document.frmSection.txtAddPollItemCnt.value;
	
	if(intPollItemSize > 0)
	{
		var strTbl = "";
		var strItem;
		
		for (var i=1; i<=intPollItemSize; i++)
		{
			strItem = eval("document.frmSection.hidPollItem" + i + ".value");
    		   
			//strTbl += "<tr><td>" + i + ". " + strItem + "</td></tr>";
			
			strTbl += "<tr><td height='20'><strong>" + i + "&gt; " + strItem + "</strong></td></tr>";
		}
    	
    		if(intPollCnt > 0)
    		{	
    			strTbl += "<tr><td align='center'>投票已經進行中，無法修正.</td></tr>";
    		}
    		else
    		{
    			strTbl += "<tr><td align='center'>投票成功.</td></tr>";
    		}
	    	
    		strTbl = "<table cellpadding='0' cellspacing='0' border='0' width='100%' class='board_text'>\r\n<tr><td height='20'><strong>[投票項目]</strong></td></tr>\r\n" + strTbl + "</table>";
    			
    		document.all.divPollTEXT.innerHTML = strTbl;
    		document.all.divPollTEXT.style.display = "";
	    	
    		if(intPollCnt > 0)
    		{	
    			document.all.btnPoll.style.display = "none";
    		}
    		else
    		{
    			document.all.btnPoll.src = simgsrc;
    		}	
	}
	else
	{
		document.all.divPollTEXT.innerHTML = "";
		document.all.divPollTEXT.style.display = "none";
		document.frmSection.btnPoll.value = '投票';
	}
	
	parent_Resize_Frame('IfrmBoard');
}

