
isNS4 = (document.layers) ? true : false;
isIE4 = (document.all && !document.getElementById) ? true : false;
isIE5 = (document.all && document.getElementById) ? true : false;
isNS6 = (!document.all && document.getElementById) ? true : false;
isGecko = false;
if(navigator){
    if(navigator.userAgent){
        if(navigator.userAgent.indexOf("Gecko/") != -1){
            isGecko = true;
        }
    }
}

function getObj(idname) {
	if (isNS4){
		elm = document.layers[idname];
	}
	else if (isIE4) {
		elm = document.all[idname];
	}
	else if (isIE5 || isNS6) {
		elm = document.getElementById(idname);
	}
	return elm;
}


function changeDisplay(id) {
	var tb = getObj(id);

	if (tb.style.display == 'none' ) {
		tb.style.display = 'block';
	} else {
		tb.style.display = 'none';
	}
}


function confirmDelete() {
if (window.confirm('削除してもよろしいですか？')) {		return true;
	} else {
		return false;
	}
}

function openWithSelfMain(url, name, width, height, returnwindow) {
    var options = "width=" + width + ",height=" + height + "toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=no,left=" + (window.screen.width - width);
    new_window = window.open(url, name, options);
    window.self.name = "main";
    new_window.document.clear();
    new_window.focus();
    if (returnwindow != null) {
        return new_window;
    }
}


function insertStr(e, str) {
    if(document.selection) {
        e.focus();
        var r = document.selection.createRange();
        r.text = str;
        e.focus();
    } else if(isGecko){
		var start = e.selectionStart;
		var head = e.value.substring(0, start);
		var foot = e.value.substring(start, e.textLength);
		e.value = head + str + foot;
	} else {
		e.value = e.value + str;
	}
}






function loadEmojiImage() {
	if (emojiImages != null) {
		return;
	}
	emojiImages = new Object();
	for(var i = 0; i < emojiList.length; i++) {
		var image = new Image();
		var imageUrl = xoopsUploadUrl + "/" + emojiUrlList[i];
		image.src = imageUrl;
		emojiImages[emojiList[i]] = image;
	}
}


function setEmojiTag(targetId, emoji) {
    var e = getObj(targetId);
    insertStr(e, emoji);
}


function loadEmojiPanelHTML(targetID) {
	loadEmojiImage();
    var html = 
	'<table cellpadding="0" cellspacing="0" border="0" style="padding:0px;">';
    var iside = 24;
    for(i = 0; i < emojiList.length + 1; i++) {
		var image = emojiImages[emojiList[i]];
		if(i % iside == 0) {
		    html += '<tr style="padding:0px;">';
		}
		if(image) {
		    var imageUrl = image.src;
		    html += '<td align="center" style="padding:0px;"><img src="' + imageUrl + '" onClick="setEmojiTag(\'' + targetID + '\',\'' + emojiList[i] + '\')"></td>';	    
		}
		if((i + 1) % iside == 0) {
		    html += '</tr>';
		}
    }
    if (emojiList.length % iside != 0) {
		for (i = emojiList.length % iside; i < iside; i++) {
			html += '<td>&nbsp;</td>';
		}
		html += '</tr>';
    }
    html += '</table>';
    return html;
}



function loadFormatPanelHTML(targetID) {
    var html = 
	'<table cellpadding="0" cellspacing="0" border="0" style="padding:0px;"><tr style=\"padding:0px;\"><td>';

	html += "<select id='" + targetID + "Size' onchange='setVisible(\"xoopsHiddenText\");setElementSize(\"xoopsHiddenText\",this.options[this.selectedIndex].value);'><option value='SIZE'>大きさ</option><option value='xx-small'>xx-small</option><option value='x-small'>x-small</option><option value='small'>small</option><option value='medium'>medium</option><option value='large'>large</option><option va//e='x-large'>x-large</option><option value='xx-large'>xx-large</option></select>";

	html += "<select id='" + targetID + "Font' onchange='setVisible(\"xoopsHiddenText\");setElementFont(\"xoopsHiddenText\",this.options[this.selectedIndex].value);'><option value='FONT'>フォント</option><option value='Arial'>Arial</option><option value='Courier'>Courier</option><option value='Georgia'>Georgia</option><option value='Helvetica'>Helvetica</option><option value='Impact'>Impact</option><option value='Verdana'>Verdana</option></select>";

	html += "<select id='" + targetID + "Color' onchange='setVisible(\"xoopsHiddenText\");setElementColor(\"xoopsHiddenText\",this.options[this.selectedIndex].value);'><option value='COLOR'>色</option><option value='000000' style='background-color:#000000;color:#000000;'>#000000</option><option value='808080' style='background-color:#808080;color:#808080;'>#808080</option><option value='C0C0C0' style='background-color:#C0C0C0;color:#C0C0C0;'>#C0C0C0</option><option value='FFFFFF' style='background-color:#FFFFFF;color:#FFFFFF;'>#FFFFFF</option><option value='800000' style='background-color:#800000;color:#800000;'>#800000</option><option value='FF0000' style='background-color:#FF0000;color:#FF0000;'>#FF0000</option><option value='800080' style='background-color:#800080;color:#800080;'>#800080</option><option value='FF00FF' style='background-color:#FF00FF;color:#FF00FF;'>#FF00FF</option><option value='008000' style='background-color:#008000;color:#008000;'>#008000</option><option value='00FF00' style='background-color:#00FF00;color:#00FF00;'>#00FF00</option><option value='808000' style='background-color:#808000;color:#808000;'>#808000</option><option value='FFFF00' style='background-color:#FFFF00;color:#FFFF00;'>#FFFF00</option><option value='000080' style='background-color:#000080;color:#000080;'>#000080</option><option value='0000FF' style='background-color:#0000FF;color:#0000FF;'>#0000FF</option><option value='008080' style='background-color:#008080;color:#008080;'>#008080</option><option value='00FFFF' style='background-color:#00FFFF;color:#00FFFF;'>#00FFFF</option></select>";
	html += "<span id='xoopsHiddenText'>サンプル</span>";
	html += "</td></tr><tr style=\"padding:0px;\"><td>";
	
	html += "<img src='" + xoopsUrl + "/images/bold.gif' alt='bold' onmouseover='style.cursor=\"hand\"' onclick='setVisible(\"xoopsHiddenText\");makeBold(\"xoopsHiddenText\");' />&nbsp;<img src='" + xoopsUrl + "/images/italic.gif' alt='italic' onmouseover='style.cursor=\"hand\"' onclick='setVisible(\"xoopsHiddenText\");makeItalic(\"xoopsHiddenText\");' />&nbsp;<img src='" + xoopsUrl + "/images/underline.gif' alt='underline' onmouseover='style.cursor=\"hand\"' onclick='setVisible(\"xoopsHiddenText\");makeUnderline(\"xoopsHiddenText\");'/>&nbsp;<img src='" + xoopsUrl + "/images/linethrough.gif' alt='linethrough' onmouseover='style.cursor=\"hand\"' onclick='setVisible(\"xoopsHiddenText\");makeLineThrough(\"xoopsHiddenText\");' />&nbsp;"
	
	html += "<input type='text' id='" + targetID + "Addtext' size='20' />&nbsp;<input type='button' onclick='xoopsCodeText(\"" + targetID + "\", \"xoopsHiddenText\", \"テキストボックスに入力してください。\")' value='追加' class='button' />";

	html += "</td></tr></table>";

	return html;
}


function showEmojiPanel(callerId, targetId) {
	var panel = getObj(callerId);
	if (panel.style.display == "none" || panel.style.width != "0px") {
	    panel.innerHTML = loadEmojiPanelHTML(targetId);
		panel.style.display = 'block';
		panel.style.width = "0px";

	} else {
	    panel.style.display = "none";
	}
}

function showFormatPanel(callerId, targetId) {
	var panel = getObj(callerId);

	if (panel.style.display == "none" || panel.style.width != "100%") {
	    panel.innerHTML = loadFormatPanelHTML(targetId);
		panel.style.display = 'block';
		panel.style.width = "100%";

	} else {
	    panel.style.display = "none";
	}
}

