﻿	var iSearchIndex=-1;
	var objLast;
	var txtWordForSearch='';
	document.namespaces.add('campSearch','');
	if (!document.all["imgForSearch"]) document.all["celForSearch"].innerHTML+='<map name="mapSearch"><area shape="CIRCLE" coords="18,18,12" title="پایان جستجو" language="javascript" onclick="hideSearchBar()"><area shape="CIRCLE" coords="53,18,12" title="بعدی" language="javascript" onclick="nextWord()"><area shape="CIRCLE" coords="88,18,12" title="قبلی" language="javascript" onclick="previousWord()"></map><img style="Z-INDEX: 100; CURSOR: hand; POSITION: absolute; display:none;" id="imgForSearch" border="0" src="masir_Client/Searchbtn.jpg" width="105" height="35" usemap="#mapSearch">';	//FILTER: progid: DXImageTransform.Microsoft.AlphaImageLoader(src=btnSearch.png);
	if (requestQuery('word')) {		
		//celForSearch.innerHTML=celForSearch.innerHTML.replace(new RegExp(requestQuery('word'),'g'),"<campSearch:Word style='background-color:red; color:yellow'>"+requestQuery('word')+"<input type='button' onclick='return nextWord()' value='بعدی' id='btnNextWord'></campSearch:Word>");				
		//celForSearch.innerHTML=celForSearch.innerHTML.replace(new RegExp(requestQuery('word'),'g'),"<campSearch:Word style='background-color:red; color:yellow'>"+requestQuery('word')+"</campSearch:Word>");				
		//celForSearch.innerHTML=celForSearch.innerHTML.replace(new RegExp(requestQuery('word'),'g'),"<campSearch:Word style='background-color:red; color:yellow'>"+requestQuery('word')+"<input type='button' onclick='return nextWord()' value='"+requestQuery('word')+"' id='btnNextWord'></campSearch:Word>");
		txtWordForSearch=requestQuery('word');	
		searchDocument();
	}
	function searchDocument() {
		iSearchIndex=-1;
		objLast=null;
		celForSearch.innerHTML=celForSearch.innerHTML.replace(new RegExp(txtWordForSearch,'g'),"<campSearch:Word class='Word1'>"+txtWordForSearch+"<input type='button' style='width:0px; height:0px;'></campSearch:Word>");		
		document.all["txtSearchKeyWord"].value=txtWordForSearch;
		window.onscroll=window_onscroll;
		if (document.getElementsByTagName("Word").length>0) {
			document.all["imgForSearch"].style.display='';
			nextWord();			
			window_onscroll();
		} else {
			alert('جستجوی عبارت '+'('+txtWordForSearch+')'+' در این صفحه نتیجه‌ای نداشت.'+String.fromCharCode(13)+'شما می‌توانید این موضوع را با واژه‌های دیگر جستجو کنید.');
		}
	}
	function doSearch() {
		document.all["imgForSearch"].style.display='none';
		iLength=document.getElementsByTagName("Word").length;
		for (iCounter=0;iCounter<iLength;iCounter++) {
			iLastElement=document.getElementsByTagName("Word").length-1;		
			document.getElementsByTagName("Word").item(iLastElement).className='';		
			document.getElementsByTagName("Word").item(iLastElement).outerHTML=txtWordForSearch;
		}
		txtWordForSearch=document.all["txtSearchKeyWord"].value;	
		searchDocument();
	}
	function previousWord() {
		if (iSearchIndex==0) return false;
		iSearchIndex=iSearchIndex-1;		
		objLast.className='Word1';
		objHTML=document.getElementsByTagName("Word").item(iSearchIndex);			
		objLast=objHTML;
		objLast.className='Word2';
		objHTML.all.item(0).focus();
	}	
	function nextWord() {		
		if (document.getElementsByTagName("Word").length<=(iSearchIndex+1)) return false;		
		iSearchIndex=iSearchIndex+1;		
		if (objLast) objLast.className='Word1';
		objHTML=document.getElementsByTagName("Word").item(iSearchIndex);			
		objLast=objHTML;
		objLast.className='Word2';		
		objHTML.all.item(0).focus();		
	}	
	function hideSearchBar() {
		document.all["imgForSearch"].style.display='none';
		iLength=document.getElementsByTagName("Word").length;
		for (iCounter=0;iCounter<iLength;iCounter++) {
			iLastElement=document.getElementsByTagName("Word").length-1;		
			document.getElementsByTagName("Word").item(iLastElement).className='';		
			document.getElementsByTagName("Word").item(iLastElement).outerHTML=txtWordForSearch;
		}
		document.all["txtSearchKeyWord"].value='';
	}	
	function window_onscroll() {
		document.all["imgForSearch"].style.top=document.body.scrollTop+0;	
	}