// seimei.js by Tsukasa Jitoh 2002/ 4/10 (Wed) 20:00:56

//seiei-handan Class
function TSeimei()
{
	function TSeimei_asGetSei()
	{
		return this.asSei;
	}
	function TSeimei_asGetMei()
	{
		return this.asMei;
	}
	function TSeimei_aiGetSei()
	{
		return this.aiSei;
	}
	function TSeimei_aiGetMei()
	{
		return this.aiMei;
	}
	function TSeimei_aiGetUnsu()
	{
		return this.aiUnsu;
	}
	function TSeimei_asGetComment()
	{
		return this.asComment;
	}
	function TSeimei_afGetPoint()
	{
		return this.afPoint;
	}
	function TSeimei_vSetReisuType(iType)
	{
		this.iReisuType = iType;
	}
	function TSeimei_iGetReisuType()
	{
		return this.iReisuType;
	}
	function TSeimei_vAnalyze(sSei, sMei, asKakusu, asComment, asUnsuName, afPoint)
	{
		//画数 姓
		var cCh;
		var i = 0;
		while((cCh = sSei.charAt(i)) != "")
		{
			this.asSei[i] = cCh;
			this.aiSei[i++] = TSeimei_iGetKakusu(asKakusu, cCh);
		}
		//画数 名
		i = 0;
		while((cCh = sMei.charAt(i)) != "")
		{
			this.asMei[i] = cCh;
			this.aiMei[i++] = TSeimei_iGetKakusu(asKakusu, cCh);
		}
		this.vAnalyzeBase(asComment, asUnsuName, afPoint);
	}
	function TSeimei_vAnalyzeC(aiSei, aiMei, asComment, asUnsuName, afPoint)
	{
		//画数 姓
		var j = 0;
		for(var i = 0; i < aiSei.length; i++)
		{
			if(parseInt(aiSei[i]) > 0)
			{
				this.asSei[j] = "";
				this.aiSei[j++] = parseInt(aiSei[i]);
			}
		}
		//画数 名
		j = 0;
		for(var i = 0; i < aiMei.length; i++)
		{
			if(parseInt(aiMei[i]) > 0)
			{
				this.asMei[j] = "";
				this.aiMei[j++] = parseInt(aiMei[i]);
			}
		}
		this.vAnalyzeBase(asComment, asUnsuName, afPoint);
	}
	function TSeimei_vAnalyzeBase(asComment, asUnsuName, afPoint)
	{
		//総運 姓
		var iKaku = 0;
		for(i = 0; i < this.aiSei.length; i++)
			iKaku += this.aiSei[i];
		//総運 名
		for(i = 0; i < this.aiMei.length; i++)
			iKaku += this.aiMei[i];
		i = TSeimei_iGetUnsu(iKaku);
		this.aiUnsu[0] = i;
		this.asComment[0] = TSeimei_sGetComment(i, asComment, asUnsuName);

		//天運
		iKaku = 0;
		if(this.iReisuType == 2 && this.aiSei.length == 1)
			iKaku++;	//霊数1
		for(i = 0; i < this.aiSei.length; i++)
			iKaku += this.aiSei[i];
		i = TSeimei_iGetUnsu(iKaku);
		this.aiUnsu[1] = i;
		this.asComment[1] = TSeimei_sGetComment(i, asComment, asUnsuName);

		//地運
		iKaku = 0;
		if(this.iReisuType == 2 && this.aiMei.length == 1)
			iKaku++;	//霊数1
		for(i = 0; i < this.aiMei.length; i++)
			iKaku += this.aiMei[i];
		i = TSeimei_iGetUnsu(iKaku);
		this.aiUnsu[2] = i;
		this.asComment[2] = TSeimei_sGetComment(i, asComment, asUnsuName);

		//人運
		iKaku = 0;
		// 姓の最後の文字
		iKaku += this.aiSei[this.aiSei.length - 1];
		// 名の最初の文字
		iKaku += this.aiMei[0];
		i = TSeimei_iGetUnsu(iKaku);
		this.aiUnsu[3] = i;
		this.asComment[3] = TSeimei_sGetComment(i, asComment, asUnsuName);

		//外運
		iKaku = 0;
		if(this.aiSei.length == 1)
		{
			if(this.iReisuType > 0)
				iKaku++;	//霊数1
			else
				iKaku += this.aiSei[0];
		}
		else
		{
			// 姓の最後の文字を除いた残り
			for(i = 0; i < this.aiSei.length - 1; i++)
				iKaku += this.aiSei[i];
		}
		if(this.aiMei.length == 1)
		{
			if(this.iReisuType > 0)
				iKaku++;	//霊数1
			else
				iKaku += this.aiMei[0];
		}
		else
		{
			// 名の最初の文字を除いた残り
			for(i = 1; i < this.aiMei.length; i++)
				iKaku += this.aiMei[i];
		}
		i = TSeimei_iGetUnsu(iKaku);
		this.aiUnsu[4] = i;
		this.asComment[4] = TSeimei_sGetComment(i, asComment, asUnsuName);

		//point
		if(afPoint)
		{
			var fSogo = afPoint[this.aiUnsu[0]];
			var fTen = afPoint[this.aiUnsu[1]];
			var fChi = afPoint[this.aiUnsu[2]];
			var fJin = afPoint[this.aiUnsu[3]];
			var fGai = afPoint[this.aiUnsu[4]];
			var fSoJin = fRndVal(Math.sqrt(fSogo * fJin) * 70.0, 10);
			var fTenChiGai = fRndVal(Math.pow(fTen * fChi * fGai,
				(1.0 / 3.0)) * 30.0, 10);
			var fTotal = fRndVal(fSoJin + fTenChiGai, 10);
			this.afPoint[0] = fSoJin;
			this.afPoint[1] = fTenChiGai;
			this.afPoint[2] = fTotal;
		}
	}
	function TSeimei_iGetKakusu(asTable, cChar)
	{
		var i = 0;
	
		if(cChar == "")
			return 0;
	
		i = asTable.length - 1;
		while(i >= 0 && asTable[i].indexOf(cChar) == -1)
			i--;
	
		return i + 1;
	}
	function TSeimei_iGetUnsu(iKakusu)
	{
		var i = iKakusu;
		if(i > 81)
			i -= 80;
		return i;
	}
	function TSeimei_sGetComment(i, asComment, asUnsuName)
	{
		return (asUnsuName? (asUnsuName[i] + ":"):"") + asComment[i];
	}

	this.iReisuType = 2;
	this.asSei = new Array();
	this.asMei = new Array();
	this.aiSei = new Array();
	this.aiMei = new Array();
	this.aiUnsu = new Array(5);
	this.asComment = new Array(5);
	this.afPoint = new Array(3);

	this.vAnalyze = TSeimei_vAnalyze;
	this.vAnalyzeC = TSeimei_vAnalyzeC;
	this.vAnalyzeBase = TSeimei_vAnalyzeBase;
	this.asGetSei = TSeimei_asGetSei;
	this.asGetMei = TSeimei_asGetMei;
	this.aiGetSei = TSeimei_aiGetSei;
	this.aiGetMei = TSeimei_aiGetMei;
	this.aiGetUnsu = TSeimei_aiGetUnsu;
	this.asGetComment = TSeimei_asGetComment;
	this.afGetPoint = TSeimei_afGetPoint;
	this.vSetReisuType = TSeimei_vSetReisuType;
	this.iGetReisuType = TSeimei_iGetReisuType;
}
