
before_search_result="";
after_search_result="";

exclude_words=",a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,1,2,3,4,5,6,7,8,9,0,about,above,after,again,all,also,am,an,and,any,are,as,at,back,be,been,before,behind,being,below,but,by,can,click,do,does,done,each,else,etc,ever,every,few,for,from,generally,get,go,gone,has,have,hello,here,how,if,in,into,is,it,just,keep,later,let,like,lot,lots,made,make,makes,many,may,me,more,most,much,must,my,need,no,not,now,of,often,on,only,or,other,others,our,out,over,please,put,so,some,such,than,that,the,their,them,then,there,these,they,this,try,to,up,us,very,want,was,we,well,what,when,where,which,why,will,with,within,you,your,yourself,";

default_match_policy=0;
default_case_sensitive=false;
default_sort_policy=0;
default_whole_word=false;

whole_word=false;
case_sensitive=0;
sort_policy=0;
search_match_policy=0;
search_section_policy=0;
search_file_policy=0;
search_within_policy=0;

target_window_target="";
set_new_win=false;
target_window_property="";

display_num=true;
result_num_mode=2;
result_num_css="";
result_num_size=2;
result_num_face='Arial';
result_num_shape=0;
result_num_color='#000000';

display_title=true;
result_title_mode=2;
result_title_css="";
result_title_size=2;
result_title_face='Arial';
result_title_shape=0;
result_title_color='#0000FF';

match_title_mode=2;
match_title_css="";
match_title_size=2;
match_title_face='Arial';
match_title_shape=0;
match_title_color='#FF8080';
match_title_high=true;

display_text=true;
result_text_mode=2;
result_text_css="";
result_text_size=2;
result_text_face='Arial';
result_text_shape=0;
result_text_color='#000000';

match_text_mode=2;
match_text_css="";
match_text_size=2;
match_text_face='Arial';
match_text_shape=0;
match_text_color='#FF8080';
match_text_high=false;

display_url=true;
result_link_mode=2;
result_link_css="";
result_link_size=2;
result_link_face='Arial';
result_link_shape=0;
result_link_color='#008000';

display_date=false;
result_date_mode=2;
result_date_css="";
result_date_size=2;
result_date_face='Arial';
result_date_shape=0;
result_date_color='#008000';

search_item_num=5;
display_newsearch=true;
display_powered=false;
display_valid=true;

tran_yoursearch="Your Search:";
tran_found="Found";
tran_items="Items";
tran_goback="Go Back";
tran_resultpages="Result Pages:";
tran_previous="Prev";
tran_next="Next";

search_words="";
array_search_words=new Array();
search_words_count=0;
array_search_result=new	Array();
search_result_count=0;
sorted_array_search_result=new Array();
search_url_count=0;
search_title_count=0;
search_keywords_count=0;
search_description_count=0;
search_text_count=0;
match_within_text="";
match_text_result=false;
max_match_title=120;
max_match_text_before=80;
max_match_text=240;

function trim_before(str)
{
	while(str.length>0)
	{
		if(str.charAt(0)==' ')
			str=str.substring(1,str.length);
		else 
			break;
	}
	return str;
}

function trim_after(str)
{
	while(str.length>0)
	{
		if(str.charAt(str.length-1)==' ')
			str=str.substring(0,str.length-1);
		else break;
	} 
	return str;
}

function trim_middle(str)
{
	var ret_str="";
	var index = str.indexOf(' ');
	while( index != -1 )
	{
		ret_str += str.substring(0, index) + ' '; 
		str=trim_before(str.substring(index,str.length));
		index=str.indexOf(' ');
	}
	ret_str+=str;
	return ret_str;
}

function trim_string(str)
{
	str=trim_before(str);
	str=trim_after(str);
	str=trim_middle(str);
	return str;
}
	
function insert_string(dest_str,ins_str,ins_pos)
{
	var str;
	str=dest_str.substring(0,ins_pos);
	str+=ins_str;
	str+=dest_str.substring(ins_pos,dest_str.length);
	return str;
}

function get_search_words_array()
{
	var i_index, j_index;
	var index_word;
	var rmquo_words;
	
	if (!case_sensitive)
		search_words=search_words.toLowerCase();
	rmquo_words = search_words.replace(/'|"/g,'');
	
	if (search_match_policy==2)
	{
		array_search_words[0]=rmquo_words;
		search_words_count=1;
	}
	else 
	{
		array_search_words=rmquo_words.split(" ");
		search_words_count=array_search_words.length;
	}
	
	if (exclude_words.length>0)
	{
		j_index=0;
		for(i_index=0;i_index<search_words_count;i_index++)
		{
			index_word=","+array_search_words[i_index].toLowerCase()+",";
			if (exclude_words.indexOf(index_word) == -1)
			{
				array_search_words[j_index]=array_search_words[i_index];
				j_index++;
			}
		}
		search_words_count=j_index;
	}
}

function search_file(file_index){
	file_section=array_files[file_index][0];
	file_type=array_files[file_index][1];
	file_name=array_files[file_index][2];
	file_date=array_files[file_index][3];
	file_size=array_files[file_index][4];	
	file_title=array_files[file_index][5];
	file_keywords=array_files[file_index][6];
	file_description=array_files[file_index][7];
	file_text=array_files[file_index][8];
	match_count=0;
	result_title="";
	result_text="";
	i_matched=-1;
	
	if (search_section_policy!=0)
		if ((file_section & search_section_policy) == 0) 
			return;
			
	if (search_file_policy!=0)
		if ((file_type & search_file_policy) == 0)
			return;
	
	if (search_within_policy==1)
	{
		search_within_text(file_title);
		if (match_text_result)
		{
			i_matched=1;	
			search_title_count++;
		}
	}
	else if (search_within_policy==2)
	{
		search_within_text(file_keywords);
		if (match_text_result)
		{
			i_matched=2;	
			result_text=match_within_text;
			search_keywords_count++;
		}
	}
	else if (search_within_policy==4)
	{
		search_within_text(file_description);
		if (match_text_result)
		{
			i_matched=3;
			result_text=match_within_text;
			search_description_count++;
		}
	}
	else 
	{
		search_within_text(file_keywords);
		if (match_text_result)
		{
			i_matched=2;
			result_text=match_within_text;
			search_keywords_count++;
		}
		else	
		{
			search_within_text(file_description);
			if (match_text_result)
			{
				i_matched=3;
				result_text=match_within_text;
				search_description_count++;
			}
			else
			{
				search_within_text(file_text);
				if (match_text_result)
				{
					i_matched=4;
					result_text=match_within_text;
					search_text_count++;
				}
			}
		}
		search_within_text(file_title);	
		if (match_text_result)
		{
			if (i_matched==2) 
				search_keywords_count--;
			else if (i_matched==3) 
				search_description_count--;
			else if (i_matched==4) 
				search_text_count--;
				
			i_matched=1;
			search_title_count++;
		}
		
		search_within_text(file_name);
		if (match_text_result)
		{
			if (i_matched==1) 
				search_title_count--;
			else if (i_matched==2) 
				search_keywords_count--;
			else if (i_matched==3) 
				search_description_count--;
			else if (i_matched==4) 
				search_text_count--;
			
			i_matched=0;
			search_url_count++;
		}
	}
	
	if (i_matched>=0)
	{
		if (file_title.length>max_match_title)
			result_title=file_title.substring(0,max_match_title)+"...";
		else 
			result_title=file_title;
			
		array_search_result[search_result_count]=new Array(i_matched,file_index,match_count,file_type,file_name,result_title,result_text,file_date,file_size);
		search_result_count++;
	}
}

function is_num_letter(ch_code)
{
	if ((ch_code >= "a") && (ch_code <= "z"))
		return true;
	else if ((ch_code >= "A") && (ch_code <= "Z"))
		return true;
	else if ((ch_code >= "0") && (ch_code <= "9"))
		return true;
	else
		return false;
}

function search_within_text(search_text)
{
	var words_index;
	var match_offset;
	var match_text_begin;
	var match_text_end;
	
	var is_code_before, is_code_after;
	var index_begin;

	if (search_words_count<=0)
	{
		match_text_result=false;
		return;
	}
	
	for (words_index=0;words_index<search_words_count;words_index++)
	{	
		index_begin=0;
		while(true)
		{
			if (!case_sensitive)
				match_offset=search_text.toLowerCase().indexOf(array_search_words[words_index],index_begin);
			else
				match_offset=search_text.indexOf(array_search_words[words_index],index_begin);
			
			if (!whole_word)
				break;
			
			if (match_offset==-1)
				break;
				
			is_code_before=false;
			is_code_after=false;
			if (match_offset > 0)
				is_code_before = is_num_letter(search_text.charAt(match_offset-1));
			if ((match_offset + array_search_words[words_index].length) < search_text.length)
				is_code_after = is_num_letter(search_text.charAt(match_offset + array_search_words[words_index].length));
				
			if (!is_code_before && !is_code_after)
				break;	
			index_begin = index_begin + match_offset + array_search_words[words_index].length;
			if (index_begin > search_text.length)
			{
				match_offset = -1;
				break;
			}		
		}			
		if (match_offset!=-1)
		{
			match_text_begin=(match_offset>max_match_text_before)?(match_offset-max_match_text_before):0;
			match_text_end=(search_text.length-match_text_begin>max_match_text)?(match_text_begin+max_match_text):search_text.length;
			match_within_text=search_text.substring(match_text_begin,match_text_end);
			if (match_text_begin>0)	
				match_within_text="..."+match_within_text;
			if (match_text_end<search_text.length)
				match_within_text+="...";
				
			if (search_match_policy==1)
			{
				match_text_result=true;
				break;
			}
			else 
				match_text_result=true;
		}
		else
		{
			if (search_match_policy!=1)	
			{
				match_text_result=false;
				break;
			}
			else 
				match_text_result=false;
		}
	}	
}

function sort_search_result()
{

	if (sort_policy==1)
	{
		sorted_array_search_result=array_search_result;	
		return;
	}
	
	i=0;
	url_pos=0;
	title_pos=search_url_count;
	keywords_pos=search_url_count+search_title_count;
	description_pos=search_url_count+search_title_count+search_keywords_count;
	text_pos=search_url_count+search_title_count+search_keywords_count+search_description_count;
	
	for(i=0;i<search_result_count;i++)
	{
		if (array_search_result[i][0]==0) 
			sorted_array_search_result[url_pos++]=array_search_result[i];
		else if (array_search_result[i][0]==1) 
			sorted_array_search_result[title_pos++]=array_search_result[i];
		else if (array_search_result[i][0]==2) 
			sorted_array_search_result[keywords_pos++]=array_search_result[i];
		else if (array_search_result[i][0]==3) 
			sorted_array_search_result[description_pos++]=array_search_result[i];
		else if (array_search_result[i][0]==4) 
			sorted_array_search_result[text_pos++]=array_search_result[i];
	}
}

function match_color_search_result(page_index)
{
	var item_index;	
	var words_index;
	var match_title_before="";
	var match_title_after="";
	var match_text_before="";
	var match_text_after="";
	var match_offset;
	var tmp_match_text;
	var tmp_match_result;
	var current_match_text;
	var is_code_before, is_code_after;
		
	if (match_title_mode==1)
	{
		match_title_before="<span class=\""+match_title_css+"\">";
		match_title_after="</span>";	
	}
	else if (match_title_mode==2)
	{
		match_title_before="<font ";
		if (match_title_high)
			match_title_before=match_title_before+"style=\"BACKGROUND-COLOR: yellow\" ";
		match_title_before=match_title_before+"face=\""+match_title_face+"\" color=\""+match_title_color+"\" size=\""+match_title_size+"\">";
		if (match_title_shape==1)
		{
			match_title_before=match_title_before+"<b>";
			match_title_after="</b>";
		}
		else if (match_title_shape==2)
		{	
			match_title_before=match_title_before+"<i>";
			match_title_after="</i>";
		}
		else if (match_title_shape==3)
		{	
			match_title_before=match_title_before+"<b><i>";
			match_title_after="</i></b>";
		}	
		match_title_after=match_title_after+"</font>";
	}
	else
	{
		match_title_before="";
		match_title_after="";		
	}

	if (match_text_mode==1)
	{
		match_text_before="<span class=\""+match_text_css+"\">";
		match_text_after="</span>";	
	}
	else if (match_text_mode==2)
	{
		match_text_before="<font ";
		if (match_text_high)
			match_text_before=match_text_before+"style=\"BACKGROUND-COLOR: yellow\" ";
		match_text_before=match_text_before+"face=\""+match_text_face+"\" color=\""+match_text_color+"\" size=\""+match_text_size+"\">";
		if (match_text_shape==1)
		{
			match_text_before=match_text_before+"<b>";
			match_text_after="</b>";
		}
		else if (match_text_shape==2)
		{	
			match_text_before=match_text_before+"<i>";
			match_text_after="</i>";
		}
		else if (match_text_shape==3)
		{	
			match_text_before=match_text_before+"<b><i>";
			match_text_after="</i></b>";
		}	
		match_text_after=match_text_after+"</font>";
	}
	else
	{
		match_text_before="";
		match_text_after="";		
	}	

	for(item_index=page_index*search_item_num;item_index<(eval(page_index)+1)*search_item_num;item_index++)
	{
		if (item_index>=search_result_count) 
			break;		
		tmp_match_text=sorted_array_search_result[item_index][5];
		tmp_match_result="";
		for (words_index=0;words_index<search_words_count;words_index++)
		{
			if (!case_sensitive)
				current_match_text=tmp_match_text.toLowerCase();
			else
				current_match_text=tmp_match_text;	
			while ((match_offset=current_match_text.indexOf(array_search_words[words_index]))!=-1)
			{	
				is_code_before=false;
				is_code_after=false;
				if (whole_word)
				{
					if (match_offset > 0)
						is_code_before = is_num_letter(current_match_text.charAt(match_offset-1));
					if ((match_offset + array_search_words[words_index].length) < current_match_text.length)
						is_code_after = is_num_letter(current_match_text.charAt(match_offset + array_search_words[words_index].length));
				}
				if (!is_code_before && !is_code_after)
				{
					tmp_match_text=insert_string(tmp_match_text,match_title_after,match_offset+array_search_words[words_index].length);
					tmp_match_text=insert_string(tmp_match_text,match_title_before,match_offset);
					tmp_match_result+=tmp_match_text.substring(0,match_offset+match_title_before.length+match_title_after.length+array_search_words[words_index].length);
					tmp_match_text=tmp_match_text.substring(match_offset+match_title_before.length+match_title_after.length+array_search_words[words_index].length,tmp_match_text.length);
				}					
				else
				{
					tmp_match_result+=tmp_match_text.substring(0,match_offset+array_search_words[words_index].length);
					tmp_match_text=tmp_match_text.substring(match_offset+array_search_words[words_index].length,tmp_match_text.length);	
				}
				if (!case_sensitive)
					current_match_text=tmp_match_text.toLowerCase();
				else
					current_match_text=tmp_match_text;
			}
			tmp_match_text=tmp_match_result+tmp_match_text;	
			tmp_match_result="";
		}
		sorted_array_search_result[item_index][5]=tmp_match_text;
		tmp_match_text=sorted_array_search_result[item_index][6];
		tmp_match_result="";
		for (words_index=0;words_index<search_words_count;words_index++)
		{
			if (!case_sensitive)
				current_match_text=tmp_match_text.toLowerCase();
			else
				current_match_text=tmp_match_text;			
			while ((match_offset=current_match_text.indexOf(array_search_words[words_index]))!=-1)
			{

				is_code_before=false;
				is_code_after=false;
				if (whole_word)
				{
					if (match_offset > 0)
						is_code_before = is_num_letter(current_match_text.charAt(match_offset-1));
					if ((match_offset + array_search_words[words_index].length) < current_match_text.length)
						is_code_after = is_num_letter(current_match_text.charAt(match_offset + array_search_words[words_index].length));
				}
				if (!is_code_before && !is_code_after)
				{
					tmp_match_text=insert_string(tmp_match_text,match_text_after,match_offset+array_search_words[words_index].length);
					tmp_match_text=insert_string(tmp_match_text,match_text_before,match_offset);
					tmp_match_result+=tmp_match_text.substring(0,match_offset+match_text_before.length+match_text_after.length+array_search_words[words_index].length);
					tmp_match_text=tmp_match_text.substring(match_offset+match_text_before.length+match_text_after.length+array_search_words[words_index].length,tmp_match_text.length);
				}					
				else
				{
					tmp_match_result+=tmp_match_text.substring(0,match_offset+array_search_words[words_index].length);
					tmp_match_text=tmp_match_text.substring(match_offset+array_search_words[words_index].length,tmp_match_text.length);	
				}
				if (!case_sensitive)
					current_match_text=tmp_match_text.toLowerCase();
				else
					current_match_text=tmp_match_text;
			}
			tmp_match_text=tmp_match_result+tmp_match_text;	tmp_match_result="";
		}
		
		sorted_array_search_result[item_index][6]=tmp_match_text;
	}
}

function get_output_search_result(page_index)
{
	var item_index;
	var page_num,page_num_index;
	var output_string="";
	var min_item,max_item;
	var newsearch_string="";
	var powered_string="";
	var min_num,max_num;
	var result_num_before="";
	var result_num_after="";
	var result_title_before="";
	var result_title_after="";
	var result_text_before="";
	var result_text_after="";
	var result_link_before="";
	var result_link_after="";
	var result_date_before="";
	var result_date_after="";
	
	var self_url;
	var param_index;
	
	
	if (display_newsearch) 
		newsearch_string="&nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript:history.back();'>"+tran_goback+"</a>&nbsp;";
		
	if (display_powered)
	{
		powered_string="Powered By <a href='http://www.mtopsoft.com'>Search Engine Composer</a>.";
	}
	
	if (result_text_mode==1)
	{
		result_text_before="<span class=\""+result_text_css+"\">";
		result_text_after="</span>";	
	}
	else if (result_text_mode==2)
	{
		result_text_before="<font face=\""+result_text_face+"\" color=\""+result_text_color+"\" size=\""+result_text_size+"\">";
		if (result_text_shape==1)
		{
			result_text_before=result_text_before+"<b>";
			result_text_after="</b>";
		}
		else if (result_text_shape==2)
		{	
			result_text_before=result_text_before+"<i>";
			result_text_after="</i>";
		}
		else if (result_text_shape==3)
		{	
			result_text_before=result_text_before+"<b><i>";
			result_text_after="</i></b>";
		}	
		result_text_after=result_text_after+"</font>";
	}

	if (result_title_mode==1)
	{
		result_title_before="<span class=\""+result_title_css+"\">";
		result_title_after="</span>";	
	}
	else if (result_title_mode==2)
	{
		result_title_before="<font face=\""+result_title_face+"\" color=\""+result_title_color+"\" size=\""+result_title_size+"\">";
		if (result_title_shape==1)
		{
			result_title_before=result_title_before+"<b>";
			result_title_after="</b>";
		}
		else if (result_title_shape==2)
		{	
			result_title_before=result_title_before+"<i>";
			result_title_after="</i>";
		}
		else if (result_title_shape==3)
		{	
			result_title_before=result_title_before+"<b><i>";
			result_title_after="</i></b>";
		}	
		result_title_after=result_title_after+"</font>";
	}
	
	min_item=eval(eval(page_index*search_item_num)+1);
	max_item=(((eval(page_index)+1)*search_item_num)>search_result_count)?search_result_count:((eval(page_index)+1)*search_item_num);
	output_string+="<p>"+result_text_before+tran_yoursearch+"&nbsp;<b>"+search_words+"</b>,&nbsp;"+tran_found+"&nbsp;<b>"+search_result_count+"</b>&nbsp;"+tran_items+"."+newsearch_string+result_text_after+"<hr></p>";
			
	if (search_result_count>0)
	{ 
		
		for (item_index=page_index*search_item_num;item_index<(eval(page_index)+1)*search_item_num;item_index++)
		{
			if (item_index>=search_result_count) 
				break;
				
			output_string=output_string+"<p>";
			if (display_num==true)
			{				
				if (result_num_mode==1)
				{
					result_num_before="<span class=\""+result_num_css+"\">";
					result_num_after="</span>";	
				}
				else if (result_num_mode==2)
				{
					result_num_before="<font face=\""+result_num_face+"\" color=\""+result_num_color+"\" size=\""+result_num_size+"\">";
					if (result_num_shape==1)
					{
						result_num_before=result_num_before+"<b>";
						result_num_after="</b>";
					}
					else if (result_num_shape==2)
					{	
						result_num_before=result_num_before+"<i>";
						result_num_after="</i>";
					}
					else if (result_num_shape==3)
					{	
						result_num_before=result_num_before+"<b><i>";
						result_num_after="</i></b>";
					}	
					result_num_after=result_num_after+"</font>";
				}				
				output_string=output_string+result_num_before+eval(eval(item_index)+1)+"."+result_num_after;
			}		
			
			if (set_new_win)
			{
				output_string=output_string+"<a href=javascript:resultwin=window.open(\""+sorted_array_search_result[item_index][4]+"\",\""+target_window_target+"\",\""+target_window_property+"\");resultwin.focus();>";
			}
			else
			{
				output_string=output_string+"<a href=\""+sorted_array_search_result[item_index][4]+"\"";
				if (target_window_target!="")
					output_string=output_string+" target="+target_window_target;
				output_string+=">";
			}
				
			output_string=output_string+result_title_before;
			if (display_title)
				output_string=output_string+sorted_array_search_result[item_index][5];	
			else
				output_string=output_string+sorted_array_search_result[item_index][4];
			output_string+=result_title_after;
		
			output_string+="</a>";

			
			if ((sorted_array_search_result[item_index][6].length > 0) && (display_text==true))
			{
				output_string+="<br>";
				output_string=output_string+result_text_before+sorted_array_search_result[item_index][6]+result_text_after;
			}
			
			if (display_url == true)
			{
				if (result_link_mode==1)
				{
					result_link_before="<span class=\""+result_link_css+"\">";
					result_link_after="</span>";	
				}
				else if (result_link_mode==2)
				{
					result_link_before="<font face=\""+result_link_face+"\" color=\""+result_link_color+"\" size=\""+result_link_size+"\">";
					if (result_link_shape==1)
					{
						result_link_before=result_link_before+"<b>";
						result_link_after="</b>";
					}
					else if (result_link_shape==2)
					{	
						result_link_before=result_link_before+"<i>";
						result_link_after="</i>";
					}
					else if (result_link_shape==3)
					{	
						result_link_before=result_link_before+"<b><i>";
						result_link_after="</i></b>";
					}	
					result_link_after=result_link_after+"</font>";
				}
				output_string+="<br>";	
				output_string=output_string+result_link_before+sorted_array_search_result[item_index][4]+result_link_after;
			} 
			
			if (display_date == true)
			{
				if (result_date_mode==1)
				{
					result_date_before="<span class=\""+result_date_css+"\">";
					result_date_after="</span>";	
				}
				else if (result_date_mode==2)
				{
					result_date_before="<font face=\""+result_date_face+"\" color=\""+result_date_color+"\" size=\""+result_date_size+"\">";
					if (result_date_shape==1)
					{
						result_date_before=result_date_before+"<b>";
						result_date_after="</b>";
					}
					else if (result_date_shape==2)
					{	
						result_date_before=result_date_before+"<i>";
						result_date_after="</i>";
					}
					else if (result_date_shape==3)
					{	
						result_date_before=result_date_before+"<b><i>";
						result_date_after="</i></b>";
					}	
					result_date_after=result_date_after+"</font>";
				}	
				output_string=output_string+result_date_before+"&nbsp;&nbsp;Date:&nbsp;"+sorted_array_search_result[item_index][7]+"&nbsp;&nbsp;Size:&nbsp;"+sorted_array_search_result[item_index][8]+result_date_after;
			} 
			
			output_string=output_string+"</p>";
		}	


		page_num=search_result_count/search_item_num;
		output_string=output_string+"<p><hr>"+result_text_before;
		
    		self_url = document.location.href;
		param_index = self_url.indexOf("?");    
    		if (param_index > -1)
        		self_url = self_url.substr(0, param_index);
    		param_index = self_url.indexOf("#");
    		if (param_index > -1)
        		self_url = self_url.substr(0, param_index); 		
		
		href_string=self_url+"?sw="+encodeURIComponent(search_words)+"&ss="+search_section_policy+"&sin="+search_within_policy+"&sm="+search_match_policy+"&ssort="+sort_policy+"&sf="+search_file_policy;
		output_string=output_string+tran_resultpages+"&nbsp;&nbsp;";
		if (page_index>0)
			output_string=output_string+"<a href="+href_string+"&page="+eval(eval(page_index)-1)+">"+tran_previous+"</a>&nbsp;&nbsp;"	
		if (page_index>=5) 
			min_num=eval(eval(page_index)-5); 
		else 
			min_num=0;
		if (page_index<eval(eval(page_num)-5)) 
			max_num=eval(eval(page_index)+5); 
		else 
			max_num=page_num;
			
		for(page_num_index=min_num;page_num_index<max_num;page_num_index++)
		{
			if (page_num_index!=page_index) 
			{
				output_string=output_string+"<a href="+href_string+"&page="+page_num_index+">"+eval(eval(page_num_index)+1)+"</a>&nbsp;&nbsp;";
			}
			else 
				output_string=output_string+eval(eval(page_num_index)+1)+"&nbsp;&nbsp;";
		}
		if (page_index<eval(page_num-1))
			output_string=output_string+"<a href="+href_string+"&page="+eval(eval(page_index)+1)+">"+tran_next+"</a>&nbsp;&nbsp;";
		output_string=output_string+result_text_after+"</p>";
	}
	
	output_string=output_string+"<p>"+result_text_before+ powered_string+result_text_after+"</p>";
	output_string=before_search_result+output_string+after_search_result;
	return output_string;
}

function auto_run_search()
{
	var str_param;
	var param_arg;
	var iParam;
	var match_is_set, case_is_set, sort_is_set, word_is_set;
	
	str_param=document.location.search;
	if (str_param=="")	
		return;
	
	if(str_param.charAt(0)=="?") 
		str_param=str_param.substring(1,str_param.length);	
	
	param_arg=str_param.split("&");	
	
	search_words="";
	case_sensitive=0;
	sort_policy=0;
	search_match_policy=0;
	search_section_policy=0;
	search_file_policy=0;
	search_within_policy=0;
	page_index=0;

	match_is_set=false;
	case_is_set=false;
	sort_is_set=false;
	word_is_set=false;
	for(iParam=0;iParam<param_arg.length;iParam++) 
	{
		param_arg_values=param_arg[iParam].split("=");
		param_name=unescape(param_arg_values[0]);	
		if (param_name=="sw")
			search_words=decodeURIComponent(param_arg_values[1]);
		else if (param_name=="ss")
			search_section_policy=eval(search_section_policy)+eval(param_arg_values[1]);
		else if (param_name=="sm")
		{
			search_match_policy=param_arg_values[1];
			match_is_set=true;
		}
		else if (param_name=="sin")
			search_within_policy=eval(search_within_policy)+eval(param_arg_values[1]);
		else if (param_name=="ssort")
		{
			sort_policy=param_arg_values[1];
			sort_is_set=true;
		}
		else if (param_name=="sf")
			search_file_policy=eval(search_file_policy)+eval(param_arg_values[1]);			
		else if (param_name=="page")
			page_index=param_arg_values[1];	
	}
	if (match_is_set==false)
		search_match_policy=default_match_policy;
	if (case_is_set==false)
		case_sensitive=default_case_sensitive;
	if (sort_is_set==false)
		sort_policy=default_sort_policy;
	if (word_is_set==false)
		whole_word=default_whole_word;
		
	search_words=search_words.replace(/\+/g, " ");
	search_words=trim_string(search_words);
	if (search_words=="") 
		return; 
	get_search_words_array();
	
	for(file_index=0;file_index<file_count;file_index++) 
		search_file(file_index); 
	sort_search_result(); 	
	match_color_search_result(page_index); 
	document.write(get_output_search_result(page_index));
	
}

auto_run_search();

