//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//	AJAX Framework / Text
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//	cheltenham software
//	http://cheltenham-software.com/
//	無断配布や二次利用を禁止します。
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// timeComing秒間かけて文字列nameObjectを表示
function cheltenhamText_displayTextGradually( nameObject, textOutput, timeComing, timeRefresh )
{
	// タイマーID
	var timerID;
	// 経過時間
	var timeNow = 0;
	// 行数
	var numberLines = textOutput.split( '\n' ).length;
//	nameObject.style.height = eval( 1.4 * numberLines ) + 'em';
	// 長さlengthTextの文字をIDがnameObjectのオブジェクトに表示する関数
	functionReference = function()
	{
		// 時間がオーバーしたらタイマー解除
		if( timeNow > timeComing )
		{
			clearInterval( timerID );
		}
		// 表示時間による文字数の振り分け
		if( timeComing > 0 )
		{
			var lengthText = Math.ceil( textOutput.length * ( timeNow / timeComing ) );
		}
		else
		{
			var lengthText = textOutput.length;
		}
		if( lengthText > textOutput.length )
		{
			lengthText = textOutput.length;
		}
		// 文字列表示
		document.getElementById( nameObject ).innerHTML = textOutput.substr( 0, lengthText ).replace( "¥n", "<br />" );

		// 時間を経過させる
		timeNow += timeRefresh;
	};

	// 繰り返し関数を実行
	timerID = setInterval( functionReference, timeRefresh );

	return( timerID );
}

// タグ内にHTMLをSETする関数
function cheltenhamText_setHtml( nameObject, textOutput )
{
	if( document.getElementById( nameObject ) )
	{
		document.getElementById( nameObject ).innerHTML = textOutput;
	}
	else
	{
		alert( '[' + nameObject + '] is not defined.' );
	}
}
// タグ内のHTMLをGETする関数
function cheltenhamText_getHtml( nameObject )
{
	if( document.getElementById( nameObject ) )
	{
		return( document.getElementById( nameObject ).innerHTML );
	}
	else
	{
		alert( '[' + nameObject + '] is not defined.' );
	}
}
// Value値をSETする関数
function cheltenhamText_setValue( nameObject, textOutput )
{
	cheltenhamForm_setValue( nameObject, textOutput );
}
// Value値をGETする関数
function cheltenhamText_getValue( nameObject )
{
	return( cheltenhamForm_getValue( nameObject ) );
}
// 改行を改行タグに置き換える関数
function cheltenhamText_getTextWithWrap( textOutput )
{
	while( textOutput.indexOf( '\n', 0 ) != -1 )
	{
		textOutput = textOutput.replace( '\n', '<br/>' );
	}
	return( textOutput );
}

// E-mail
function cheltenhamText_openBlankMail( account, domain )
{
	if( account == '' || domain == '' )
	{
		return( '' );
	}
	var url = 'mailto:' + account + '@' + domain;

	document.location.href = url;
}
// E-mail
function cheltenhamText_getLinkEmailSafe( account, domain )
{
	if( account == '' || domain == '' )
	{
		return( '' );
	}
	var email = account + '@' + domain;
	var textHtml = '<a href = "mailto:' + email + '">' + email + '</a>';

	return( textHtml );
}
function cheltenhamText_printLinkEmailSafe( account, domain )
{
	document.write( cheltenhamText_getLinkEmailSafe( account, domain ) );
}

// E-mailのリンク（要ecl）
function cheltenhamText_getLinkEmail( textLabel, emailAccount, emailDomain, subject, body )
{
//	var subjectConverted = EscapeSJIS( subject );
//	var bodyConverted = EscapeSJIS( body );
	var subjectConverted = subject;
	var bodyConverted = body;
	if( emailAccount == '' || emailDomain == '' )
	{
		var email = '';
	}
	else
	{
		var email = emailAccount + '@' + emailDomain;
	}
	var textHtml = '<a href = "mailto:' + email + '?subject=' + subjectConverted + '&body=' + bodyConverted + '">' + textLabel + '</a>';
	return( textHtml );
}

// Get Star Html
function cheltenhamText_getStar( starNow, starMax )
{
	var textOutputStar = '★';
	var textOutput = '<font class = "StarActive">';
	for( var j = 1 ;  j <= starNow ; j++ )
	{
		textOutput += textOutputStar;
	}
	textOutput += '</font>';
	textOutput += '<font class = "StarInactive">';
	for( ; j <= starMax ; j++ )
	{
		textOutput += textOutputStar;
	}
	textOutput += '</font>\n';
	return( textOutput );
}

