
// charset=UTF-8

/**************************************************
	COMMON FUNCTIONS
**************************************************/
var browser = navigator.userAgent;
var isIE = false;
var isFireFox = false;

if(browser.indexOf('MSIE') > 0) isIE = true;
else if(browser.indexOf('Firefox') > 0) isFireFox = true;

//20090831:IE6 keep away background flicker
(function()
{
	/*Use Object Detection to detect IE6*/
	var m = document.uniqueID /*IE*/
	&& document.compatMode /*>=IE6*/
	&& !window.XMLHttpRequest /*<=IE6*/
	&& document.execCommand ;
	try
	{
		if(!!m)
		{
			m("BackgroundImageCache", false, true) /* = IE6 only */
		}
	}
	catch(oh){};
})(); 

function get(id)
{
	return document.all?document.all[id]:document.getElementById(id);
}

function isInt(str)
{ 
	if(isEmpty(str)) return false;
	
	for(var idx=0;idx < str.length;idx++)
	{
		if(str.charAt(idx) < '0' || str.charAt(idx) > '9')
		{
			return false;
		}
	}
	return true;
}

function isNumber(x)
{
	for ( inx=0; inx < x.length; inx++ )
	{
		if ((x.charAt(inx) < '0' || x.charAt(inx) > '9' ) && x.charAt(inx) != '.' &&  x.charAt(inx) != '-')
		{
			return false;
		}
	}
	return true;
}

function isEmpty(pValue)
{
	pValue = pValue.replace(/[ ]+/, '');
	if((pValue == "") || (pValue == null) )
	{
		return true;
	}
	return false;
}

function submitForm(formId)
{
	var fm = document.getElementById(formId);
	
	if(fm == 'undefined' || fm == null)
	{
		return false;
	}
	
	fm.submit();
	return false;
}

Array.prototype.inArray = function(val)
{
	for(var i=0; i<this.length; i++)
	{
		if(this[i] == val)
		{
			return true;
		}
	}
	return false;
}

/**************************************************
	ADDSLASHES/STRIPSLASHES FUNCTIONS
**************************************************/

function addslashes(str)
{
	str=str.replace(/\'/g,'\\\'');
	str=str.replace(/\"/g,'\\"');
	str=str.replace(/\\/g,'\\\\');
	str=str.replace(/\0/g,'\\0');
	return str;
}

function stripslashes(str)
{
	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\\\/g,'\\');
	str=str.replace(/\\0/g,'\0');
	return str;
}

/**************************************************
	全角・半角 FUNCTIONS
**************************************************/

/* 全角英数字を半角英数字に置換する */
function zenToHan(src)
{
	return src.replace(
						/([Ａ-Ｚａ-ｚ０-９＿\　])/g,
						function ($0)
						{
							return String.fromCharCode($0.charCodeAt(0) - 65248);
						}
	);
}

/* 半角英数字を全角英数字に置換する */
function hanToZen(src)
{
	return src.replace(
						/(\w)/g,
						function ($0)
						{
						  return String.fromCharCode($0.charCodeAt(0) + 65248);
						}
	);
}

/**************************************************
	TRIM/RTRIM/LTRIM FUNCTIONS
**************************************************/

function trim(stringToTrim)
{
	return stringToTrim.replace(/^[\　\s]+|[\　\s]+$/g,"");
}

function ltrim(stringToTrim)
{
	return stringToTrim.replace(/^[\　\s]+/,"");
}

function rtrim(stringToTrim)
{
	return stringToTrim.replace(/[\　\s]+$/,"");
}

/**************************************************
	ENTER KEY FUNCTIONS
**************************************************/

var keyCode;

function setKeyCode(e)
{
	if(isIE)
	{
		if(!e) var e = window.event;
		keyCode = e.keyCode;
	}
	else
	{
		keyCode = e.which;
	}
}

if(isIE)
{
	document.onkeydown = setKeyCode
}
else
{
	document.addEventListener('keydown', setKeyCode, false);
}

function enterFocus(nextObjId)
{
	if(keyCode == 13)
	{
		var obj = document.getElementById(nextObjId);
		
		if(obj != null && obj != 'undefined')
		{
			obj.focus();
		}
	}
	return false;
}

function enterSubmit(formId)
{
	if(keyCode == 13)
	{
		submitForm(formId);
	}
	return false;
}

function enterCall(func)
{
	if(keyCode == 13)
	{
		eval(func);
	}
	return false;
}

/**************************************************
	CHECK BOX FUNCTIONS
**************************************************/

function checkAll(id, type)
{
	//var chk = document.all[id];
	var chk = id;
	
	if(chk.length > 1)
	{
		for(var i=0; i<chk.length; i++)
		{
			chk[i].checked = type;
		}
	}
	else chk.checked = type;
}

function checkAll2(formId, checkboxId, type)
{
	this.form = document.getElementById(formId);
	
	if(this.form)
	{
		this.checkboxNodes = this.form.getElementsByTagName('input');
		
		for(this.i = 0; this.i < this.checkboxNodes.length; this.i++)
		{
			if(this.checkboxNodes[i].getAttribute('type') != 'checkbox')   continue;
			if(this.checkboxNodes[i].getAttribute('id') != checkboxId)	 continue;
			
			this.checkboxNodes[i].checked = type;
		}
	}
} 

function isCheckedCheckBox(formId, checkboxId)
{
	this.form = document.getElementById(formId);
	
	if(this.form)
	{
		this.checkboxNodes = this.form.getElementsByTagName('input');
		
		for(this.i = 0; this.i < this.checkboxNodes.length; this.i++)
		{
			if(this.checkboxNodes[i].getAttribute('type') != 'checkbox')   continue;
			if(this.checkboxNodes[i].getAttribute('id') != checkboxId)	 continue;
			{
				if(this.checkboxNodes[i].checked)
				{
					return true;
				}
			}
		}
	}
	
	return false;
}


/**************************************************
	COMMON AJAX FUNCTIONS
**************************************************/

var xmlHttp;											// AJAX XML OBJECT

function getXmlHttpObject()
{
	var tmpXmlHttp = null;
	
	try
	{
		// Firefox, Opera 8.0+, Safari
		tmpXmlHttp = new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			tmpXmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			tmpXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	
	return tmpXmlHttp;
}

/**************************************************
	COOKIE FUNCTIONS
**************************************************/

function setCookie(name, value, day)
{
	if(!value || !day)
	{
		value = "";
		day = -1;
	}
	
	var date = new Date();
	date.setTime(date.getTime()+(day*60*60*24*1000));
	var expires = "; expires="+date.toGMTString();
	document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while(c.charAt(0)==' ')
		{
			c = c.substring(1,c.length);
		}
		if(c.indexOf(nameEQ) == 0)
		{
			return c.substring(nameEQ.length,c.length);
		}
	}
	return null;
}

function delCookie(name)
{
	setCookie(name,"",-1);
}

/**************************************************
	POPUP FUNCTIONS
**************************************************/

function popup(id, url, width, height, option)
{
	var x = (screen.width - width) / 2;
	var y = (screen.height - height) / 2;
	var option = "left="+x+",top="+y+",width="+width+",height="+height+","+option;
	id = window.open(url, id, option);
	id.focus();
}

/**************************************************
	DATE & TIME FUNCTIONS
**************************************************/

function unixtimeToDate(unixtime)
{
	var theDate = new Date(unixtime * 1000);
	var dateString;
	
	// YYYY-MM-DD
	dateString = theDate.getFullYear();
	dateString += '-' + (theDate.getMonth() < 9?'0':'') + (theDate.getMonth()+1);
	dateString += '-' + (theDate.getDate() < 10?'0':'') + theDate.getDate();
	
	// HH:II:SS
	dateString += ' ' + (theDate.getHours() < 10?'0':'') + theDate.getHours();
	dateString += ':' + (theDate.getMinutes() < 10?'0':'') + theDate.getMinutes();
	dateString += ':' + (theDate.getSeconds() < 10?'0':'') + theDate.getSeconds();
	
	return dateString;
}
	
function dateToUnixtime(year, month, day, hour, minute, second)
{
	var utc = 0;
	
	if (utc) // This creates a unixtime in UTC
	{
		var humDate = new Date(
								Date.UTC(
										year,
										month - 1,
										day,
										hour,
										minute,
										second));
	}
	else // This creates a unixtime in localtime (accounting for the local timezone)
	{
		var humDate = new Date(
								year,
								month - 1,
								day,
								hour,
								minute,
								second);
		
	}
	return (humDate.getTime()/1000.0);
}

/**************************************************
	CALENDAR
	
	Example 1 :
		<input name="ADate" onFocus="displayDatePicker(this.name);">
	
	Example 2 : 
		<input name="AnotherDate"> 
		<input type=button value="select" onclick="displayDatePicker('AnotherDate', this);">
	
	Example 3 :
		<input name="YetAnotherDate"> 
		<input type=button value="select" onclick="displayDatePicker('YetAnotherDate', false, 'dmy', '.');">
	
	Style : /www/public/style/common.css  (Line 815 ~ 937)
	
**************************************************/

var datePickerDivID			= "datePicker";
var iFrameDivID				= "datePickerIframe";

var dpAryDay				= new Array('日', '月', '火', '水', '木', '金', '土');
var dpAryMonth				= new Array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12');

var defaultDateSeparator	= "-";
var defaultDateFormat		= "ymd"
var dateSeparator			= defaultDateSeparator;
var dateFormat				= defaultDateFormat;

var dpEndFunction			= null;

function displayDatePicker(dateFieldName, displayBelowThisObject, dtFormat, dtSep, callEndFunction)
{
	var targetDateField = document.getElementsByName(dateFieldName).item(0);
	
	if(!displayBelowThisObject)
	{
		displayBelowThisObject = targetDateField;
	}
	
	if(dtSep)
	{
		dateSeparator = dtSep;
	}
	else
	{
		dateSeparator = defaultDateSeparator;
	}
	
	if(dtFormat)
	{
		dateFormat = dtFormat;
	}
	else
	{
		dateFormat = defaultDateFormat;
	}
	
	if(callEndFunction)
	{
		dpEndFunction = callEndFunction;
	}
	else
	{
		dpEndFunction = null;
	}
	
	var x = displayBelowThisObject.offsetLeft;
	var y = displayBelowThisObject.offsetTop + displayBelowThisObject.offsetHeight ;
	
	var parent = displayBelowThisObject;
	
	while(parent.offsetParent)
	{
		parent = parent.offsetParent;
		x += parent.offsetLeft;
		y += parent.offsetTop ;
	}
	
	drawDatePicker(targetDateField, x, y);
}

function drawDatePicker(targetDateField, x, y)
{
	var dt = getFieldDate(targetDateField.value );
	
	if(!document.getElementById(datePickerDivID))
	{
		var newNode = document.createElement("div");
		newNode.setAttribute("id", datePickerDivID);
		newNode.setAttribute("class", "dpDiv");
		newNode.setAttribute("style", "visibility: hidden;");
		document.body.appendChild(newNode);
	}
	
	var pickerDiv = document.getElementById(datePickerDivID);
	
	if(pickerDiv.style.visibility == "visible")
	{
		pickerDiv.style.visibility = "hidden";
		pickerDiv.style.display = "none";
	}
	
	pickerDiv.style.position = "absolute";
	pickerDiv.style.left = x + "px";
	pickerDiv.style.top = y + "px";
	pickerDiv.style.visibility = "visible";
	pickerDiv.style.display = "block";
	pickerDiv.style.zIndex = 10000;
	
	refreshDatePicker(targetDateField.name, dt.getFullYear(), dt.getMonth(), dt.getDate());
}

function refreshDatePicker(dateFieldName, year, month, day)
{
	var thisDay = new Date();
	
	if((month >= 0) && (year > 0))
	{
		thisDay = new Date(year, month, 1);
	}
	else
	{
		day = thisDay.getDate();
		thisDay.setDate(1);
	}
 
	var crlf = "\r\n";
	var TABLE = "<table cols=7 class='dpTable' border='0' cellspacing='1' cellpadding='2'>" + crlf;
	var xTABLE = "</table>" + crlf;
	var TR = "<tr class='dpTR'>";
	var TR_title = "<tr class='dpTitleTR'>";
	var TR_days = "<tr class='dpDayTR'>";
	var TR_todaybutton = "<tr class='dpTodayButtonTR'>";
	var xTR = "</tr>" + crlf;
	var TD = "<td class='dpTD' onMouseOut='this.className=\"dpTD\";' onMouseOver=' this.className=\"dpTDHover\";' ";	
	var TD_title = "<td colspan=5 class='dpTitleTD'>";
	var TD_buttons = "<td class='dpButtonTD'>";
	var TD_todaybutton = "<td colspan=7 class='dpTodayButtonTD'>";
	var TD_days = "<td class='dpDayTD'>";
	// leave this tag open, because we'll be adding an onClick event
	var TD_selected = "<td class='dpDayHighlightTD' onMouseOut='this.className=\"dpDayHighlightTD\";' onMouseOver='this.className=\"dpTDHover\";' ";	
	var xTD = "</td>" + crlf;
	
	var DIV_title = "<div class='dpTitleText'>";
	var DIV_selected = "<div class='dpDayHighlight'>";
	var xDIV = "</div>";
	
	var html = TABLE;
	
	html += TR;
	
	html += TD_buttons + getButtonCode(dateFieldName, thisDay, -12, "&lt;") + xTD;
	html += TD_buttons + getButtonCode(dateFieldName, thisDay, -1, "&lt;") + xTD;
	
	html += "<td colspan=3>" + DIV_title;
	html += thisDay.getFullYear() + "/" + dpAryMonth[ thisDay.getMonth()];
	html += xDIV + xTD;
	
	html += TD_buttons + getButtonCode(dateFieldName, thisDay, 1, "&gt;") + xTD;
	html += TD_buttons + getButtonCode(dateFieldName, thisDay, 12, "&gt;") + xTD;
	
	html += xTR;
	
	html += TR_days;
	
	for(i=0; i<dpAryDay.length; i++)
	{
		html += TD_days + dpAryDay[i] + xTD;
	}
	
	html += xTR;
	
	html += TR;
	for (i=0; i<thisDay.getDay(); i++)
	{
		html += TD;
		html += ">&nbsp;" + xTD;
	}
	
	do
	{
		dayNum = thisDay.getDate();
		TD_onclick = " onclick=\"updateDateField('" + dateFieldName + "', '" + getDateString(thisDay) + "');\">";
		
		if(dayNum == day)
		{
			html += TD_selected + TD_onclick + DIV_selected + dayNum + xDIV + xTD;
		}
		else
		{
			html += TD + TD_onclick + dayNum + xTD;
		}
		
		if(thisDay.getDay() == 6)
		{
			html += xTR + TR;
		}
		
		thisDay.setDate(thisDay.getDate() + 1);
	}
	while(thisDay.getDate() > 1)
		
	if(thisDay.getDay() > 0)
	{
		for(i = 6; i > thisDay.getDay(); i--)
		{
			html += TD + "&nbsp;" + xTD;
		}
	}
	
	html += xTR;
	
	html += TR_todaybutton + TD_todaybutton;
	html += "<table><tr><td><ol><li class='li_button_middle'>";
	html += "<a class='link_button' href='javascript:refreshDatePicker(\"" + dateFieldName + "\");' style='font-size:11px;'>今月</a>";
	html += "</li></td><td><li class='li_button_middle_gray'>";
	html += "<a class='link_button' href='javascript:updateDateField(\"" + dateFieldName + "\");' style='font-size:11px;'>閉じる</a>";
	html += "</li></ol></td></tr></table>";
	html += xTD + xTR;
	html += xTABLE;
	
	document.getElementById(datePickerDivID).innerHTML = html;
	
	adjustiFrame();
}

function getButtonCode(dateFieldName, dateVal, adjust, label)
{
	var newMonth = (dateVal.getMonth () + adjust) % 12;
	var newYear = dateVal.getFullYear() + parseInt((dateVal.getMonth() + adjust) / 12);
	if(newMonth < 0)
	{
		newMonth += 12;
		newYear += -1;
	}
	
	return "<a href='javascript:refreshDatePicker(\"" + dateFieldName + "\", " + newYear + ", " + newMonth + ");'>" + label + "</a>";
}

function getDateString(dateVal)
{
	var dayString = "00" + dateVal.getDate();
	var monthString = "00" + (dateVal.getMonth()+1);
	dayString = dayString.substring(dayString.length - 2);
	monthString = monthString.substring(monthString.length - 2);
	
	switch(dateFormat)
	{
		case "dmy" :
			return dayString + dateSeparator + monthString + dateSeparator + dateVal.getFullYear();
		case "ymd" :
			return dateVal.getFullYear() + dateSeparator + monthString + dateSeparator + dayString;
		case "mdy" :
		default :
			return monthString + dateSeparator + dayString + dateSeparator + dateVal.getFullYear();
	}
}

function getFieldDate(dateString)
{
	var dateVal;
	var dArray;
	var d, m, y;
	
	try
	{
		dArray = splitDateString(dateString);
		
		if (dArray)
		{
			switch (dateFormat)
			{
				case "dmy" :
					d = parseInt(dArray[0], 10);
					m = parseInt(dArray[1], 10) - 1;
					y = parseInt(dArray[2], 10);
					break;
				case "ymd" :
					d = parseInt(dArray[2], 10);
					m = parseInt(dArray[1], 10) - 1;
					y = parseInt(dArray[0], 10);
					break;
				case "mdy" :
				default :
					d = parseInt(dArray[1], 10);
					m = parseInt(dArray[0], 10) - 1;
					y = parseInt(dArray[2], 10);
					break;
			}
			
			dateVal = new Date(y, m, d);
		}
		else if (dateString)
		{
			dateVal = new Date(dateString);
		}
		else
		{
			dateVal = new Date();
		}
	}
	catch(e)
	{
		dateVal = new Date();
	}
	
	return dateVal;
}

function splitDateString(dateString)
{
	var dArray;
	
	if(dateString.indexOf("/") >= 0)
		dArray = dateString.split("/");
	else if (dateString.indexOf(".") >= 0)
		dArray = dateString.split(".");
	else if (dateString.indexOf("-") >= 0)
		dArray = dateString.split("-");
	else if (dateString.indexOf("\\") >= 0)
		dArray = dateString.split("\\");
	else
		dArray = false;
	
	return dArray;
}

function updateDateField(dateFieldName, dateString)
{
	var targetDateField = document.getElementsByName(dateFieldName).item(0);
	if (dateString)
	{
		targetDateField.value = dateString;
	}
	
	var pickerDiv = document.getElementById(datePickerDivID);
	pickerDiv.style.visibility = "hidden";
	pickerDiv.style.display = "none";
	
	adjustiFrame();
	targetDateField.blur();
	
	if((dateString) && (typeof(datePickerClosed) == "function"))
	{
		datePickerClosed(targetDateField);
	}
	
	if(dpEndFunction)
	{
		eval(dpEndFunction);
	}
}

function adjustiFrame(pickerDiv, iFrameDiv)
{
	if(navigator.userAgent.toLowerCase().indexOf("opera") != -1)
	{
		return;
	}
	
	try
	{
		if(!iFrameDiv && !document.getElementById(iFrameDivID))
		{
			var newNode = document.createElement("iFrame");
			newNode.setAttribute("id", iFrameDivID);
			newNode.setAttribute("src", "");
			newNode.setAttribute("scrolling", "no");
			newNode.setAttribute ("frameborder", "0");
			document.body.appendChild(newNode);
		}
		
		if(!pickerDiv)
		{
			pickerDiv = document.getElementById(datePickerDivID);
		}
		
		if (!iFrameDiv)
		{
			iFrameDiv = document.getElementById(iFrameDivID);
		}
		
		try
		{
			iFrameDiv.style.position = "absolute";
			iFrameDiv.style.width = pickerDiv.offsetWidth;
			iFrameDiv.style.height = pickerDiv.offsetHeight ;
			iFrameDiv.style.top = pickerDiv.style.top;
			iFrameDiv.style.left = pickerDiv.style.left;
			iFrameDiv.style.zIndex = pickerDiv.style.zIndex - 1;
			iFrameDiv.style.visibility = pickerDiv.style.visibility ;
			iFrameDiv.style.display = pickerDiv.style.display;
		}
		catch(e)
		{
		
		}
	}
	catch (ee)
	{
	
	}
}


/**************************************************
	Emoji
**************************************************/

var nowEmoji;

var basici = new Array(
						"sunny",	   "cloudy",	   "rainy",	   "snow",		"thunder",
						"typhoon",	 "foggy",		"umbrella",	"aries",	   "taurus",
						"gemini",	  "cancer",	   "leo",		 "virgo",	   "libra",
						"scorpio",	 "sagittarius",  "capricorn",   "aquarius",	"pisces",
						"runningShirt","baseball",	 "golf",		"tennis",	  "soccer",
						"ski",		 "basketball",   "checkerflag", "pager",	   "train",
						"metro",	   "superexpress1","sedanCar",	"RVcar1",	  "bus",
						"ship",		"plane",		"house",	   "building1",   "postOffice",
						"hospital",	"bank",		 "atm",		 "hotel",	   "conveniStore",
						"gasStation",  "parking",	  "signal",	  "toilet",	  "forkKnife",
						"coffeeCup",   "cocktail",	 "beer",		"fastFood",	"highHeels",
						"scissors",	"karaoke",	  "camcorder1",  "upperRightArrow", "amusementPark",
						"headPhone",   "art",		  "drama",	   "event",	   "ticket",
						"smoking",	 "nosmoking",	"camera",	  "briefcase1",  "book",
						"ribbon",	  "gift",		 "birthday",	"phone",	   "mobilePhone",
						"memo",		"tv",		   "game",		"cd",		  "heart",
						"spade",	   "diamond",	  "clover",	  "eye",		 "ear",
						"fingerStone", "fingerScissors","fingerPaper","lowerRightArrow","upperLeftArrow",
						"footMark",	"shoe",		 "glasses",	 "wheelchair",  "newMoon",
						"13thMoon",	"halfMoon",	 "crescent",	"fullMoon",	"dog1",
						"cat1",		"yacht",		"xmas",		"lowerLeftArrow", "phoneto",
						"mailto",	  "fax",		  "imode",	   "imodeBox",	"envelope",
						"DoCoMoSponsor","DoCoMoPoint", "toll",		"free",		"id",
						"password",	"nextItem",	 "clear",	   "find",		"new",
						"position",	"freeDial",	 "sharpDial",   "movaQ",	   "1square",
						"2square",	 "3square",	  "4square",	 "5square",	 "6square",
						"7square",	 "8square",	  "9square",	 "0square",	 "okay",
						"heartMark",   "shakenHeart",  "brokenHeart", "twoHeart",	"happy1",
						"tutting",	 "discourage",   "disgusted",   "dizzy",	   "upArrow",
						"eighthNote",  "spa",		  "cute",		"lip",		 "shiny",
						"lightBulb",   "anger",		"punch",	   "bomb",		"cheerfull",
						"downArrow",   "sleepy",	   "exclamation1","exclamationAndQ","wExclamation",
						"impact",	  "impatient",	"coldSweat1",  "dash",		"jaggyLine",
						"curcedLine",  "action",	   "sack",		"pen",		 "figure",
						"chair",	   "night",		"soon",		"on",		  "end",
						"clock");


var expandi = new Array(
						"iAppli",	  "iAppliBox",	"shirt",	   "purse",	   "lipstick",
						"jeans",	   "snowboard",	"bell",		"door",		"moneySack",
						"personalComputer","loveLetter","wrench",	 "pencil",	  "crown",
						"ring",		"sandglass2",   "bicycle",	 "teacup",	  "wristwatch",
						"thought",	 "peaceOfMind",  "coldSweat3",  "coldSweat4",  "pout",
						"stupefaction","heartEye",	 "thumbsUp",	"kidding1",	"wink",
						"glad3",	   "endure",	   "cat2",		"crying",	  "tear2",
						"noGood",	  "clip",		 "copyRight",   "trademark",   "running",
						"secret",	  "recycle",	  "registered",  "warning",	 "ban",
						"vacant",	  "pass",		 "allReserved", "rightLeftArrow","upDownArrow",
						"school",	  "wave",		 "mtFuji",	  "fourLeafClover","cherry",
						"tulip",	   "banana",	   "apple",	   "bud",		 "coloredLeaves",
						"cherryTree",  "riceBall",	 "cake",		"sakeBottle",  "bowl",
						"bread",	   "snail",		"chick",	   "penguin",	 "fish",
						"delicious",   "laugh",		"horse",	   "pig",		 "wine",
						"haggard");

var emojiCode = new Array();
emojiCode['sunny']	   = '63647';
emojiCode['cloudy']	  = '63648';
emojiCode['rainy']	   = '63649';
emojiCode['snow']		= '63650';
emojiCode['thunder']	 = '63651';
emojiCode['typhoon']	 = '63652';
emojiCode['foggy']	   = '63653';
emojiCode['umbrella']	= '63654';
emojiCode['aries']	   = '63655';
emojiCode['taurus']	  = '63656';
emojiCode['gemini']	  = '63657';
emojiCode['cancer']	  = '63658';
emojiCode['leo']		 = '63659';
emojiCode['virgo']	   = '63660';
emojiCode['libra']	   = '63661';
emojiCode['scorpio']	 = '63662';
emojiCode['sagittarius'] = '63663';
emojiCode['capricorn']   = '63664';
emojiCode['aquarius']	= '63665';
emojiCode['pisces']	  = '63666';
emojiCode['runningShirt'] = '63667';
emojiCode['baseball']	= '63668';
emojiCode['golf']		= '63669';
emojiCode['tennis']	  = '63670';
emojiCode['soccer']	  = '63671';
emojiCode['ski']		 = '63672';
emojiCode['basketball']  = '63673';
emojiCode['checkerflag'] = '63674';
emojiCode['pager']	   = '63675';
emojiCode['train']	   = '63676';
emojiCode['metro']	   = '63677';
emojiCode['superexpress1'] = '63678';
emojiCode['sedanCar']	= '63679';
emojiCode['RVcar1']	  = '63680';
emojiCode['bus']		 = '63681';
emojiCode['ship']		= '63682';
emojiCode['plane']	   = '63683';
emojiCode['house']	   = '63684';
emojiCode['building1']   = '63685';
emojiCode['postOffice']  = '63686';
emojiCode['hospital']	= '63687';
emojiCode['bank']		= '63688';
emojiCode['atm']		 = '63689';
emojiCode['hotel']	   = '63690';
emojiCode['conveniStore'] = '63691';
emojiCode['gasStation']  = '63692';
emojiCode['parking']	 = '63693';
emojiCode['signal']	  = '63694';
emojiCode['toilet']	  = '63695';
emojiCode['forkKnife']   = '63696';
emojiCode['coffeeCup']   = '63697';
emojiCode['cocktail']	= '63698';
emojiCode['beer']		= '63699';
emojiCode['fastFood']	= '63700';
emojiCode['highHeels']   = '63701';
emojiCode['scissors']	= '63702';
emojiCode['karaoke']	 = '63703';
emojiCode['camcorder1']  = '63704';
emojiCode['upperRightArrow'] = '63705';
emojiCode['amusementPark']   = '63706';
emojiCode['headPhone']   = '63707';
emojiCode['art']		 = '63708';
emojiCode['drama']	   = '63709';
emojiCode['event']	   = '63710';
emojiCode['ticket']	  = '63711';
emojiCode['smoking']	 = '63712';
emojiCode['nosmoking']   = '63713';
emojiCode['camera']	  = '63714';
emojiCode['briefcase1']  = '63715';
emojiCode['book']		= '63716';
emojiCode['ribbon']	  = '63717';
emojiCode['gift']		= '63718';
emojiCode['birthday']	= '63719';
emojiCode['phone']	   = '63720';
emojiCode['mobilePhone'] = '63721';
emojiCode['memo']		= '63722';
emojiCode['tv']		  = '63723';
emojiCode['game']		= '63724';
emojiCode['cd']		  = '63725';
emojiCode['heart']	   = '63726';
emojiCode['spade']	   = '63727';
emojiCode['diamond']	 = '63728';
emojiCode['clover']	  = '63729';
emojiCode['eye']		 = '63730';
emojiCode['ear']		 = '63731';
emojiCode['fingerStone'] = '63732';
emojiCode['fingerScissors'] = '63733';
emojiCode['fingerPaper'] = '63734';
emojiCode['lowerRightArrow'] = '63735';
emojiCode['upperLeftArrow']  = '63736';
emojiCode['footMark']	= '63737';
emojiCode['shoe']		= '63738';
emojiCode['glasses']	 = '63739';
emojiCode['wheelchair']  = '63740';
emojiCode['newMoon']	 = '63808';
emojiCode['13thMoon']	= '63809';
emojiCode['halfMoon']	= '63810';
emojiCode['crescent']	= '63811';
emojiCode['fullMoon']	= '63812';
emojiCode['dog1']		= '63813';
emojiCode['cat1']		= '63814';
emojiCode['yacht']	   = '63815';
emojiCode['xmas']		= '63816';
emojiCode['lowerLeftArrow'] = '63817';
emojiCode['phoneto']	 = '63858';
emojiCode['mailto']	  = '63859';
emojiCode['fax']		 = '63860';
emojiCode['imode']	   = '63861';
emojiCode['imodeBox']	= '63862';
emojiCode['envelope']	= '63863';
emojiCode['DoCoMoSponsor'] = '63864';
emojiCode['DoCoMoPoint']   = '63865';
emojiCode['toll']		= '63866';
emojiCode['free']		= '63867';
emojiCode['id']		  = '63868';
emojiCode['password']	= '63869';
emojiCode['nextItem']	= '63870';
emojiCode['clear']	   = '63872';
emojiCode['find']		= '63873';
emojiCode['new']		 = '63874';
emojiCode['position']	= '63875';
emojiCode['freeDial']	= '63876';
emojiCode['sharpDial']   = '63877';
emojiCode['movaQ']	   = '63878';
emojiCode['1square']	 = '63879';
emojiCode['2square']	 = '63880';
emojiCode['3square']	 = '63881';
emojiCode['4square']	 = '63882';
emojiCode['5square']	 = '63883';
emojiCode['6square']	 = '63884';
emojiCode['7square']	 = '63885';
emojiCode['8square']	 = '63886';
emojiCode['9square']	 = '63887';
emojiCode['0square']	 = '63888';
emojiCode['okay']		= '63920';
emojiCode['heartMark']   = '63889';
emojiCode['shakenHeart'] = '63890';
emojiCode['brokenHeart'] = '63891';
emojiCode['twoHeart']	= '63892';
emojiCode['happy1']	  = '63893';
emojiCode['tutting']	 = '63894';
emojiCode['discourage']  = '63895';
emojiCode['disgusted']   = '63896';
emojiCode['dizzy']	   = '63897';
emojiCode['upArrow']	 = '63898';
emojiCode['eighthNote']  = '63899';
emojiCode['spa']		 = '63900';
emojiCode['cute']		= '63901';
emojiCode['lip']		 = '63902';
emojiCode['shiny']	   = '63903';
emojiCode['lightBulb']   = '63904';
emojiCode['anger']	   = '63905';
emojiCode['punch']	   = '63906';
emojiCode['bomb']		= '63907';
emojiCode['cheerfull']   = '63908';
emojiCode['downArrow']   = '63909';
emojiCode['sleepy']	  = '63910';
emojiCode['exclamation1']	= '63911';
emojiCode['exclamationAndQ'] = '63912';
emojiCode['wExclamation']	= '63913';
emojiCode['impact']	  = '63914';
emojiCode['impatient']   = '63915';
emojiCode['coldSweat1']  = '63916';
emojiCode['dash']		= '63917';
emojiCode['jaggyLine']   = '63918';
emojiCode['curcedLine']  = '63919';
emojiCode['action']	  = '63824';
emojiCode['sack']		= '63825';
emojiCode['pen']		 = '63826';
emojiCode['figure']	  = '63829';
emojiCode['chair']	   = '63830';
emojiCode['night']	   = '63831';
emojiCode['soon']		= '63835';
emojiCode['on']		  = '63836';
emojiCode['end']		 = '63837';
emojiCode['clock']	   = '63838';

// Extends
emojiCode['iAppli']	  = '63921';
emojiCode['iAppliBox']   = '63922';
emojiCode['shirt']	   = '63923';
emojiCode['purse']	   = '63924';
emojiCode['lipstick']	= '63925';
emojiCode['jeans']	   = '63926';
emojiCode['snowboard']   = '63927';
emojiCode['bell']		= '63928';
emojiCode['door']		= '63929';
emojiCode['moneySack']   = '63930';
emojiCode['personalComputer'] = '63931';
emojiCode['loveLetter']  = '63932';
emojiCode['wrench']	  = '63933';
emojiCode['pencil']	  = '63934';
emojiCode['crown']	   = '63935';
emojiCode['ring']		= '63936';
emojiCode['sandglass2']  = '63937';
emojiCode['bicycle']	 = '63938';
emojiCode['teacup']	  = '63939';
emojiCode['wristwatch']  = '63940';
emojiCode['thought']	 = '63941';
emojiCode['peaceOfMind'] = '63942';
emojiCode['coldSweat3']  = '63943';
emojiCode['coldSweat4']  = '63944';
emojiCode['pout']		= '63945';
emojiCode['stupefaction'] = '63946';
emojiCode['heartEye']	= '63947';
emojiCode['thumbsUp']	= '63948';
emojiCode['kidding1']	= '63949';
emojiCode['wink']		= '63950';
emojiCode['glad3']	   = '63951';
emojiCode['endure']	  = '63952';
emojiCode['cat2']		= '63953';
emojiCode['crying']	  = '63954';
emojiCode['tear2']	   = '63955';
emojiCode['noGood']	  = '63956';
emojiCode['clip']		= '63957';
emojiCode['copyRight']   = '63958';
emojiCode['trademark']   = '63959';
emojiCode['running']	 = '63960';
emojiCode['secret']	  = '63961';
emojiCode['recycle']	 = '63962';
emojiCode['registered']  = '63963';
emojiCode['warning']	 = '63964';
emojiCode['ban']		 = '63965';
emojiCode['vacant']	  = '63966';
emojiCode['pass']		= '63967';
emojiCode['allReserved'] = '63968';
emojiCode['rightLeftArrow'] = '63969';
emojiCode['upDownArrow'] = '63970';
emojiCode['school']	  = '63971';
emojiCode['wave']		= '63972';
emojiCode['mtFuji']	  = '63973';
emojiCode['fourLeafClover'] = '63974';
emojiCode['cherry']	  = '63975';
emojiCode['tulip']	   = '63976';
emojiCode['banana']	  = '63977';
emojiCode['apple']	   = '63978';
emojiCode['bud']		 = '63979';
emojiCode['coloredLeaves'] = '63980';
emojiCode['cherryTree']  = '63981';
emojiCode['riceBall']	= '63982';
emojiCode['cake']		= '63983';
emojiCode['sakeBottle']  = '63984';
emojiCode['bowl']		= '63985';
emojiCode['bread']	   = '63986';
emojiCode['snail']	   = '63987';
emojiCode['chick']	   = '63988';
emojiCode['penguin']	 = '63989';
emojiCode['fish']		= '63990';
emojiCode['delicious']   = '63991';
emojiCode['laugh']	   = '63992';
emojiCode['horse']	   = '63993';
emojiCode['pig']		 = '63994';
emojiCode['wine']		= '63995';
emojiCode['haggard']	 = '63996';

/**************************************************
	Editor - SEO
	
	使う方法
	
	#----------------------------------------------
	# Controller source
	#----------------------------------------------
	
	# メニュー設定
	$contentsEditMenu = array('Emoji',
							  'FontSize',	  'FontName',	  
							  'ForeColor',	 'HiliteColor',   'BackColor',
								 'Bold',		  'Italic',		'Underline',	'StrikeThrough',
							  'SubScript',	 'SuperScript',   'InsertHorizontalRule',
							  'CreateLink',	'UnLink',
							  'JustifyLeft',   'JustifyCenter', 'JustifyRight',
								'InsertOrderedList',
							  'InsertUnorderedList',
							  'Outdent',
							  'Indent');
	
	# Controllerの id, width, height とかを設定
	$contentsEditor = array('id'		=> 'favoriteContents',			// id
							   'width'	 => '100%',						// width
							'height'	=> '200px',						// height
							'multiline' => 'true',						// 'false' 場合Enterが出来ない
							'contents'  => $favorite->link_content,	 // 基本文章
							   'menu'	  => $contentsEditMenu);		  // メニュー
		
	$viewData['contentsEditor']['editor'] = &$contentsEditor;			// ニューの変数に設定
	
	#----------------------------------------------
	# View source
	#----------------------------------------------
	#
	# ビューのロード
	#
	# <? $this->view('editorMulti', $contentsEditor) ?>
	#
	# editorMulti : Multi line
	# editorSingle : Single line
	#
	# FormのSubmitする前に "wfEditor.setHtml();"の実行が必要
	#
	# Ex)
	#
	# function submitForm()
	# {
	#	 wfEditor.setHtml();
	#	 
	#	 // チェック
	#	 // FormのSubmit
	# }
	
**************************************************/

var colorWidth = 10;
var colorHeight;
var colorTdSize = 15;

var aryColor = Array(
					"#FFFFFF", "#FFCCCC", "#FFCC99", "#FFFF99", "#FFFFCC",
					"#99FF99", "#99FFFF", "#CCFFFF", "#CCCCFF", "#FFCCFF",
					"#CCCCCC", "#FF6666", "#FF9966", "#FFFF66", "#FFFF33",
					"#66FF99", "#33FFFF", "#66FFFF", "#9999FF", "#FF99FF",
					"#C0C0C0", "#FF0000", "#FF9900", "#FFCC66", "#FFFF00",
					"#33FF33", "#66CCCC", "#33CCFF", "#6666CC", "#CC66CC",
					"#999999", "#CC0000", "#FF6600", "#FFCC33", "#FFCC00",
					"#33CC00", "#00CCCC", "#3366FF", "#6633FF", "#CC33CC",
					"#666666", "#990000", "#CC6600", "#CC9933", "#999900",
					"#009900", "#339999", "#3333FF", "#6600CC", "#993399",
					"#333333", "#660000", "#993300", "#996633", "#666600",
					"#006600", "#336666", "#000099", "#333399", "#663366",
					"#000000", "#330000", "#663300", "#663333", "#333300",
					"#003300", "#003333", "#000066", "#330099", "#330033");

var wfEditor = {
				ins:{},
				nowEditor:null,
				addEditor:function(areaId, editorId, width, height, funcMenu, isMulti)
				{
					if(!(editorId in this.ins))
					{
						this.ins[editorId]={};
					}
					
					if(!width) width = "100%";
					if(!height) height = "200px";
					if(!funcMenu) funcMenu = new Array();
					
					this.ins[editorId]._id = editorId;
					this.ins[editorId]._areaId = areaId;
					this.ins[editorId]._funcMenu = funcMenu;
					this.ins[editorId]._multiline = isMulti;
					
					var multiTag;
					
					if(isMulti != 'true' && !isMulti)
					{
						multiTag = 'scrolling="no"';
					}
					
					var html = '<iframe width="'+width+'" height="'+height+'" name="wfe_'+editorId+'" id="wfe_'+editorId+'" style="border-style:solid; border-width:1px; border-color:#666666; " frameborder="0" src="about:blank" '+multiTag+' ></iframe>';
					html += '<textarea id="wfet_'+editorId+'" name="wfet_'+editorId+'" style="border-style:solid; border-width:1px; border-color:#666666; width:'+width+'; height:'+height+'; display:none; "></textarea>';
					html += '<div id="wfecp_'+editorId+'" name="wfecp_'+editorId+'" style="display:none; position: absolute;"></div>';
					
					document.getElementById(areaId).innerHTML += html;
					
					if(isIE)
					{
						eval("wfEditor.ins[editorId]._editorFrame = document.wfe_" + editorId + ";");
					}
					else
					{
						this.ins[editorId]._editorFrame = document.getElementById("wfe_" + editorId).contentWindow;
					}
					
					this.ins[editorId]._editorFrame.document.designMode = "on";
					this.ins[editorId]._textArea = document.getElementById('wfet_' + editorId);
					this.ins[editorId]._palette = document.getElementById('wfecp_' + editorId);
					
					this.nowEditor = editorId;
					
					
				}};

wfEditor.getSelectionRange =function()
{
	if(isIE)
	{
		return this.ins[this.nowEditor]._editorFrame.document.selection.createRange();
	}
	else
	{
		return this.ins[this.nowEditor]._editorFrame.getSelection().getRangeAt(0);
	}
};

wfEditor.checkEnter = function(e)
{
	var code;
	eval("var obj = document.wfe_" + wfEditor.nowEditor + ";");
	
	if(isIE)
	{
		var evnt = obj.event;
		code = evnt.keyCode;
	}
	else // if(e.which)
	{
		code = e.which;
		
		/*if((e.ctrlKey && code == 118) || (e.shiftKey && !code))
		{
			e.preventDefault();
			e.stopPropagation();
		}*/
		
	}

	if((code == 13 || code == 17) && wfEditor.ins[wfEditor.nowEditor]._multiline == false)
	{
		if(isIE)
		{
			obj.event.returnValue = false;
			obj.event.cancelBubble = true;
			/*
			var range = wfEditor.getSelectionRange();
			//range.pasteHTML("<br />");
			range.collapse(false);
			range.select();
			return false;*/
		}
		else
		{
			//e.preventDefault();
			//e.stopPropagation();
		}

	}
};

wfEditor.detectedPaste = function()
{
	var data=window.clipboardData.getData("Text");	
	
	if( data == null )
	{
		data = '';
	}
	
	window.clipboardData.setData("Text", data);
}

wfEditor.detectedMouse = function(e)
{
	e.preventDefault();
	e.stopPropagation();
	e.returnValue = false;
	return false;
}

wfEditor.doc = function(doc)
{
	var id = wfEditor.nowEditor;
	var margin;
	
	if(this.ins[id]._multiline || this.ins[id]._multiline == 'true')
	{
		margin = "5px 5px 5px 5px";
	}
	else
	{
		margin = "1px 3px 0px 3px";
	}
	
	var initcontents = "<html><head>";
	initcontents += "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">";
	initcontents += "<style>table {border:1 solid C6C3C6;} p {margin:0px 0px 0px 0px;}</style>";
	initcontents += "</head><body style=\"font-size:9pt; margin:"+margin+"; ";
	initcontents += "font-family:MS ゴシック; line-height:150%; background-color:#FFFFFF\">";
	initcontents += doc;
	initcontents += "</body></html>";
	
	this.ins[id]._editorFrame.document.open("text/html");
	this.ins[id]._editorFrame.document.write(initcontents);
	this.ins[id]._editorFrame.document.close();
	
	if(isIE)
	{
		this.ins[id]._editorFrame.document.body.onfocus = function(){ wfEditor.nowEditor = id; }
		this.ins[id]._editorFrame.document.body.onmousedown = function(){ wfEditor.nowEditor = id; }
		this.ins[id]._editorFrame.document.body.onkeypress = wfEditor.checkEnter;
		//this.ins[id]._editorFrame.document.body.oncontextmenu = function(){ return false; }
		//this.ins[id]._editorFrame.document.body.onbeforepaste = wfEditor.detectedPaste;
		this.ins[id]._editorFrame.document.body.ondrop = function(){ return false; }
	}
	else
	{
		this.ins[id]._editorFrame.document.addEventListener('focus', function(){ wfEditor.nowEditor=id; }, false);
		this.ins[id]._editorFrame.document.addEventListener('keypress', wfEditor.checkEnter, false);
		this.ins[id]._editorFrame.document.addEventListener('dragdrop', function(e){ e.preventDefault(); e.stopPropagation(); return false; } , true);
		this.ins[id]._editorFrame.document.addEventListener('contextmenu', function(e){ e.preventDefault(); e.stopPropagation(); return false; }, true);
	}
}

wfEditor.execute = function(command, userInterface, value)
{
	var id = this.nowEditor;
	
	for(var i=0; i<this.ins[id]._funcMenu.length; i++)
	{
		if(command == this.ins[id]._funcMenu[i])
		{
			//this.ins[id]._editorFrame.document.execCommand(command, userInterface, value);
			break;
		}
	}
	
	if(command == 'ForeColor' && !isIE)
	{	
		document.getElementById('wfe_'+id).contentWindow.document.execCommand('forecolor', false, value);
		
		//this.ins[id]._editorFrame.contentWindow.document.execCommand('forecolor', false, value);
	}
	else
	{
		this.ins[id]._editorFrame.focus();
		this.ins[id]._editorFrame.document.execCommand(command, userInterface, value);
	}
};

wfEditor.refreshColor = function(colorType)
{
	var onClickTag;
	var id = wfEditor.nowEditor;
	
	if(colorType == 'ForeColor')
	{
		mouseOverTag = "wfEditor.color(this.bgColor)"
	}
	else if(colorType == 'HiliteColor')
	{
		mouseOverTag = "wfEditor.backColor(this.bgColor)"
	}
	else
	{
		return;
	}
	
	html = '<table border="1" cellpadding="0" width="';
	html += (colorTdSize*colorWidth) + '" height="105" cellspacing="1" bgcolor="#FFFFFF">';
	
	for(var i=0; i<aryColor.length; i+=colorWidth)
	{
		html += '<tr>';
		for(var j=0; j<colorWidth; j++)
		{
			html += '<td bgcolor="'+aryColor[i+j]+'" width="';
			html += colorTdSize+'" height="'+colorTdSize+'" ';
			html += 'onMouseOver="this.style.border=\'0px\'; '+mouseOverTag+'"';
			html += 'onMouseOut="this.style.border=\'1px solid white\'" ';
			html += 'onClick="wfEditor.closeColor()" style="border:1px solid white"></td>';
		}
		html += '</tr>';
		colorHeight++;
	}
	html += '</table>';
	
	this.ins[id]._palette.innerHTML = html;
}

wfEditor.selectColor = function(obj, type)
{
	var id = this.nowEditor;
	
	if(this._isOpenColor)
	{
		this.ins[id]._palette.innerHTML = '';
		this.ins[id]._isOpenColor = false;
	}

	this.refreshColor(type);
	
	var x = obj.offsetLeft;
	var y = obj.offsetTop + obj.offsetHeight;
	
	var parent = obj;
	
	while(parent.offsetParent)
	{
		parent = parent.offsetParent;
		x += parent.offsetLeft;
		y += parent.offsetTop ;
	}
	
	this.ins[id]._palette.style.position = "absolute";
	this.ins[id]._palette.style.left = x + "px";
	this.ins[id]._palette.style.top = y + "px";
	this.ins[id]._palette.style.visibility = "visible";
	this.ins[id]._palette.style.display = "block";
	this.ins[id]._palette.style.zIndex = 10000;
	this.ins[id]._isOpenColor = true;
	adjustiFrame(this.ins[id]._palette, 'pletteFrame');
}

wfEditor.color = function(color)
{
	this.execute('ForeColor', true, color);
};

wfEditor.backColor = function(color)
{
	var command = 'HiliteColor';
	
	if(isIE)
	{
		command = 'BackColor';
	}
	
	this.execute(command, false, color);
	
};

wfEditor.closeColor = function()
{
	this.ins[this.nowEditor]._palette.style.display = "none";
	this.ins[this.nowEditor]._isOpenColor = false;
};

wfEditor.fontSize = function(selectObj)
{
	this.execute('FontSize', false, selectObj.value);
	selectObj.selectedIndex = 0;
}

wfEditor.fontName = function(selectObj)
{
	this.execute('FontName', false, selectObj.value);
	selectObj.selectedIndex = 0;
}

wfEditor.createLink = function()
{
	if(isIE)
	{	  
		this.execute("CreateLink", true, null);
	}
	else
	{
		var url = prompt("URLを入力してください。:", "http://");
		if(url)
		{
			this.execute('CreateLink', false, url);		
		}
	}
}

wfEditor.align = function(align)
{
	var id = this.nowEditor;
	var havePermission = false;
	
	for(var i=0; i<this.ins[id]._funcMenu.length; i++)
	{
		if("Justify" + align == this.ins[id]._funcMenu[i])
		{
			havePermission = true;
			break;
		}
	}
	
	if(!havePermission) return;
	
	if(isIE)
	{
		var range = this.getSelectionRange();
		var prnt  = range.parentElement();
		var div   = document.createElement("DIV");
		
		if(this.ins[id]._editorFrame.document.selectedElement && 
		   this.ins[id]._editorFrame.document.selectedElement.tagName == "IMG")
		{
			switch(this.ins[id]._editorFrame.document.selectedElement.className)
			{
				default:
					this.execute("Justify" + align, false, null);
					break;
			}
		}
		else if(range.htmlText) 
		{
			div.innerHTML = range.htmlText;
			if(div.childNodes.length == 1)
			{
				if(prnt.tagName == "P" || prnt.tagName == "DIV")
				{
					prnt.style.textAlign = align;
				}
				else
				{
					range.pasteHTML('<DIV style="text-align: ' + align + '">' + range.htmlText + "</DIV>");
				}
				//div.childNodes[0].style.textAlign = blockAlign;
				//range.parentElement().outerHTML = div.innerHTML;
			}
			else
			{
				if(div.childNodes[0].tagName == "P" || div.childNodes[0].tagName == "DIV")
				{
					div.childNodes[0].style.textAlign = align;
				}
				else
				{
					range.pasteHTML('<DIV style="text-align: ' + align + '">' + range.htmlText + "</DIV>");
				}
			}
		}
		else
		{
			if(prnt.tagName == "P" || prnt.tagName == "DIV")
			{
				prnt.style.textAlign = align;
			}
		}
	}
	else
	{
		this.execute("Justify" + align, false, null);
	}
}

wfEditor.html = function()
{
	return this.ins[this.nowEditor]._editorFrame.document.body.innerHTML;
}

wfEditor.setHtml = function()
{
	for(var key in this.ins)
	{
		this.ins[key]._textArea.value = this.ins[key]._editorFrame.document.body.innerHTML;
	}
	//alert(this.ins[key]._editorFrame.document.body.innerHTML);
}

wfEditor.getEmptyIds = function()
{
	var result = new Array();
	
	for(var key in this.ins)
	{
		var html = trim(this.ins[key]._textArea.value);
		
		if(html == '&nbsp;' || html == '<p></p>' || html == '<p>&nbsp</p>' || isEmpty(html))
		{
			result[key] = 1;
		}
	}
	return result;
}


wfEditor.openEmoji = function(nowEditor)
{
	this.nowEditor = nowEditor;
	
	if(this.popupEmoji && !this.popupEmoji.closed)
	{
		this.popupEmoji.close();
	}
	
	this.popupEmoji = popup('editorEmoji', "/top/editorEmoji/", 360, 350, "scrollbars=no,resizable=no,");
};

wfEditor.selectEmoji = function(code)
{
	this.ins[this.nowEditor]._editorFrame.focus();
	code = '<img src="' + code + '" title="wfEmojiCode" alt="" border="0" width="12" height="12" />';
	
	if(isIE)
	{
		var range = this.getSelectionRange();
		range.pasteHTML(code);
		range.collapse(false);
		range.select();
		return false;
	}
	else
	{
		this.ins[this.nowEditor]._editorFrame.document.execCommand("insertHTML",false, code);
	}
};


/*
wfEditor.toDesign = function()
{
	var obj = document.getElementById('wfe_'+ wfEditor._id);
	
	if(obj.style.display == 'none')
	{
		wfEditor._editorFrame.document.body.innerHTML = wfEditor._textArea.value;
		obj.style.display = '';
		wfEditor._textArea.style.display = 'none';
	}
}

wfEditor.toText = function()
{
	var obj = document.getElementById('wfe_'+ wfEditor._id);
	
	if(wfEditor._textArea.style.display == 'none')
	{
		wfEditor._textArea.value = wfEditor._editorFrame.document.body.innerHTML;
		wfEditor._textArea.style.display = '';
		//txtHTML.style.width = editorObj.style.width;
		//alert(txtHTML.style.width+" = "+editorObj.width);
		obj.style.display = 'none';
	}
}

*/

/**************************************************
	IMAGES FUNCTIONS
**************************************************/

// Resize image width
function resizeImage(obj, maxWidth)
{
	if(!maxWidth)
	{
		maxWidth = 550;
	}
	
	if(obj.width > 550 )
	{
		obj.width = maxWidth;
	}
}

/*
'layerId' is not id of 'image tag'.
'layerId' is id to have 'image tag'.
*/
function resizeImageAll(layerId, maxWidth)
{
	var obj = document.getElementById(layerId);
	if(obj == 'undefined' || obj == null) return false;
	
	var images = obj.getElementsByTagName('img');
	if(images == 'undefined' || images == null) return false;
	
	for(var i=0; i<images.length; i++)
	{
		var width = images[i].width;
		var height = images[i].height;
		
		if (width > maxWidth)
		{
			f = 1-((width - maxWidth) / width);
			images[i].width = width * f;
			images[i].height = height * f;
			
			width  = images[i].width;
			height = images[i].height;
		}
		if (height > maxWidth)
		{
			f = 1-((height - maxWidth) / height);
			images[i].width  = width  * f;
			images[i].height = height * f;
		}
	}
}

function voidForm()
{
	return;
}

function preview()
{
	var bgDiv = document.createElement("div");
	with (bgDiv.style)
	{
		position = "absolute";
		left = '0px';
		top = '0px';
		width = "100%";
		height = document.body.scrollHeight+'px';
		filter = "Alpha(Opacity=20)";
		opacity = "0.2";
	}
	
	bgDiv.id = "objPreview";
	document.body.appendChild(bgDiv);
	
	var obj = document.getElementsByTagName('a');
	for (i=0;i<obj.length;i++)
	{
		obj[i].href = "#";
	}
	
	var obj = document.getElementsByTagName('form');
	for (i=0;i<obj.length;i++)
	{
		obj[i].action = "javascript:voidForm();";
	}
	
	var obj = document.getElementsByTagName('select');
	for (i=0;i<obj.length;i++)
	{
		obj[i].disabled = true;
	}
}

