searchWordHighlighting();
resizeWindow();

function searchWordHighlighting()
{
	var fontName    = "";
	var fontColor   = "";
	var fontSize    = 0;
	var isBold      = 0;
	var isItalic    = 0;
	var isUnderline = 0;
	var backColor   = "#FFFF00";


	if (document.body.createTextRange)
	{

		var div = document.getElementById ("main");
		var range = document.body.createTextRange();
		range.moveToElementText (div);

//		var range = document.body.createTextRange();
		var searchStr = sermoji()

		if (searchStr == "") return;

		range.collapse(true);
		pfrag="false";

		while (range.findText(searchStr))
		{
			if (fontName != "") range.execCommand("fontName", true, fontName);
			if (fontSize > 0) range.execCommand("fontSize", true, fontSize);
			if (fontColor != "") range.execCommand("foreColor", true, fontColor);
			if (isBold != 0) range.execCommand("bold");
			if (isItalic != 0) range.execCommand("italic");
			if (isUnderline != 0) range.execCommand("underline");
			if (backColor != "") range.execCommand("backColor", false, backColor);


			if (pfrag == "false" )
			{
				range.select();
				//--追加 100726
				var offset = 0;
				var current = range.parentElement();
				
			
				while(1)
				{
					offset = offset + current.offsetTop;
					current = current.offsetParent;
					if(current == null) break;
				}
				$("#scroll-area").scrollTop(offset-$('#header').height()-$('#title').height()-70);
				//window.scrollTo(0, offset);
				//追加 100726--
				pfrag="true";
			}

			range.collapse(false);

		}

	}
	else
	{


		var searchStr = sermoji();
		pfrag="false";

		var elemToSelect = document.getElementById ("scroll-area");

		if (searchStr == "") return;


		var strUA = "";
		strUA = navigator.userAgent.toLowerCase();

		if(strUA.indexOf("safari") != -1)
		{

			$(window).load(function()
			{

				while(window.find(searchStr,false,true))
				{

					if (window.getSelection)
					{

						var sel = window.getSelection();
						var range;
						var r;

						r = sel.getRangeAt(0);
						document.designMode = "on";
						sel.removeAllRanges();
						sel.addRange(r);
						document.execCommand("HiliteColor", false, "yellow");
						document.designMode = "off";

					}

				}
			});


		}
		else if(strUA.indexOf("firefox") != -1)
		{


			while(window.find(searchStr,false,true))
			{

				if (window.getSelection)
				{

					var sel = window.getSelection();
					var range;
					var r;

					r = sel.getRangeAt(0);
					document.designMode = "on";
					sel.removeAllRanges();
					sel.addRange(r);
					document.execCommand("HiliteColor", false, "yellow");
					document.designMode = "off";

				}

			}


		}

		//一つ目が選択されているのを解除
		//sel.removeAllRanges();

	}


}



function getSearchStr()
{
	var urlStr = "" + window.location;
	var baseStr = "mySearch=";
	var index = urlStr.indexOf(baseStr);
	if (index == -1) return "";
	return decodeURIComponent(urlStr.substring(index + baseStr.length));
}

function sermoji(){
 var sertxt="";
 var url0=location.href;
 var a=url0.indexOf("?");
 var sertxt;
 var sertxt0="";
 var kno;
 var serno;
	if ( a >= 0 ) { 
  		d1=url0.substr(a+1);
		a=d1.indexOf("=");
		if ( a >=0 ) {
			   sertxt=d1.substr(a+1);
		}
	}
             serno=sertxt.indexOf("_");
             sertxt0="";
             while( serno>0){
                 kno=sertxt.substr(0,serno);
                 sertxt0=sertxt0+String.fromCharCode(kno);
                 sertxt=sertxt.substr(serno+1);
                 serno=sertxt.indexOf("_");
             }
              return sertxt0;
}

