
var window_background = "white"; // the color of the pop-up window
var window_border = "blue"; // the border color of pop-up window
var text_color = "black"; // the color of the text in window
var title_color = "white"; // color of window title text
var window_width = 190; // width of window
var window_height = 150; // height of window
var mozilla_opt = 1; // change to 0 to use Netscape and Firefox built-in search window
var start_at = 0; // Change to which character you want to start with on the page if IE gives an error because of searching in menus
/* Do not edit anything below this line */

var ie = (document.all)
if (window.find)
	var nav = 1; // to detect if netscape or firefox
else 
	var nav = 0;
var t = 0;  // used for timer to move window in IE when scrolling

var sel; // Selection object needed for Firefox
var range; // range object needed for Firefox
if (!ie) 
{
	document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
}

document.onmousedown = MouseDown;
document.onmousemove = MouseMove;
document.onmouseup = MouseUp;

var mousex = 0;
var mousey = 0;

if (ie)
{
	var txt = document.body.createTextRange();

	var bookmark = new Array();
}
var finds = 0;

function findit() 
{
	try{
	var string = document.getElementById('fwtext').value;

	if (ie)
	{
	bookmark[finds] = txt.getBookmark();
	if (string)
		if (txt.findText(string)) // if found
		{	
			txt.select();
			txt.scrollIntoView();
			txt.collapse(false);
		
			//alert( "Found");
		}
	}
		else // Netscape or firefox
		{
			if (finds > 0)
			{
				sel = window.getSelection(); // get selection
				if(sel.rangeCount > 0) sel.removeAllRanges();
				sel.addRange(range);		
			}	
			if (string != "")	
				test.innerHTML = window.find(string, false, false);
			sel = window.getSelection(); // get selection
			range = sel.getRangeAt(0); // get object
		}
		finds++;	
	}
	catch(e){
	alert("No Such Keyword found on Page");
	}
}  // end function findit()

function findprev()
{
	var string = document.getElementById('fwtext').value;
	
	if (ie)
	{
	if (finds < 2)
		return;  
	finds = finds - 2;

	txt.moveToBookmark(bookmark[finds]);
	findit();
	}
	else // if netscape or firefox
	{
			if (finds > 0)
			{
				sel = window.getSelection(); // get selection
				if(sel.rangeCount > 0) sel.removeAllRanges();
				sel.addRange(range);		
			}
		if (string != "")
			test.innerHTML = window.find(string, false, true);	
			sel = window.getSelection(); // get selection
			range = sel.getRangeAt(0); // get object
	}
	
	
} // end findprev()

function checkkey(e)
{	
	var keycode;
	if (window.event)  // if ie
		keycode = window.event.keyCode;
	else // if Firefox or Netscape
		keycode = e.which;
	
	if (keycode == 13) // if ENTER key
	{	
		if (ie)
			document.getElementById('btn').focus();
		findit(); 
	}
}

function showsearch()
{
	if (ie || mozilla_opt == 1)
	{

	var textbox = document.getElementById('fwtext');
	
	if(findwindow.style.display=="none"){
	findwindow.style.display = 'block';
	}
	else{
		findwindow.style.display="none";
		}

	//textbox.focus();

	t = setInterval('move_window();', 500); 	

	document.onkeydown = checkkey;
	
	}
	else  // if netscape or firefox
		window.find();	
} 

function hide()
{
	findwindow.style.visibility = 'hidden';

	clearTimeout(t);

	document.onkeydown = null;
	
}

function resettext()
{
	if (ie)
	{
		txt = document.body.createTextRange();
		txt.moveStart("character", start_at);
	}
	finds = 0;
}

function move_window()
{

	fwtop = parseFloat(findwindow.style.top);
	fwleft = parseFloat(findwindow.style.left);
	fwheight = parseFloat(findwindow.style.height);
	
	if (document.documentElement.scrollTop) // Needed if you use doctype loose.htm
		current_top = document.documentElement.scrollTop;
	else 
		current_top = document.body.scrollTop;
	if (document.documentElement.clientHeight)
	{
		if (document.documentElement.clientHeight > document.body.clientHeight)
			current_bottom = document.body.clientHeight + current_top;
		else
			current_bottom = document.documentElement.clientHeight + current_top;
	}
	else
		current_bottom = document.body.clientHeight + current_top;
	
	if (document.documentElement.scrollLeft) 
		current_left = document.documentElement.scrollLeft;
	else 
		current_left = document.body.scrollLeft;
	if (document.documentElement.clientWidth)
	{
		if (document.documentElement.clientWidth > document.body.clientWidth)
			current_right = document.body.clientWidth + current_left;
		else
			current_right = document.documentElement.clientWidth + current_left;
	}
	else
		current_right = document.body.clientWidth + current_left;

	if (fwtop < current_top)
	{	
		findwindow.style.top = current_top + 'px';	 
	}
	else if (fwtop > current_bottom - fwheight)
	{
		findwindow.style.top = current_bottom - fwheight + 'px';	 
	}

	if (fwleft < current_left ||
		fwleft > current_right)
	{
	findwindow.style.left = current_left + 'px';
	}
}

function MouseDown(e) 
{
    if (over == 1)
    	DivID = 'findwindow';
	
	if (over)
    {    
		if (ie) 
		{
            objDiv = document.getElementById(DivID);
            objDiv = objDiv.style;
            mousex=event.offsetX;
            mousey=event.offsetY;
        }
        else 
		{
            objDiv = document.getElementById(DivID);
            mousex=e.layerX;
            mousey=e.layerY;
            return false;
        }
    }
}



function MouseMove(e) 
{
    
	if (document.documentElement.scrollTop) // Needed if you use doctype loose.htm
		current_top = document.documentElement.scrollTop;
	else 
		current_top = document.body.scrollTop;
	if (document.documentElement.scrollLeft) // Needed if you use doctype loose.htm
		current_top = document.documentElement.scrollLeft;
	else 
		current_left = document.body.scrollLeft;
	
	
	if (objDiv) 
	{
        if (ie) 
        {
            objDiv.pixelLeft = event.clientX-mousex + current_left;
            objDiv.pixelTop = event.clientY-mousey + current_top;
            return false;
        }
		else
		{
            objDiv.style.left = (e.pageX-mousex) + 'px';
            objDiv.style.top = (e.pageY-mousey) + 'px';
            return false;
        }
    }
}  
function MouseUp() 
{
    objDiv = null;
}
document.write('<a href="javascript:void(0);" onclick="showsearch();">Search in Page</a>');
document.write('<div id="findwindow" style="display: none' 
	+ ';background-color: ' + window_background
	+ ';width: ' + window_width + 'px'
	+ ';color: ' + text_color
	+ ';padding: 0px'
	+ ';"'
	+ '>');
document.write('<div id="window_body" style="padding: 5px 5px 5px 0;">'
	+ '<input type="text" size="13" maxlength="25" id="fwtext" onchange="resettext();" style="margin-right:10px;float:left;margin-top:0px;height:21px">'
	+ '<input id="btn" type="image" src="/assets/image/h1_en/find-in-page.gif" onclick="findit();">'
	+ '</div>\n'
	+ '<div id="test" style="visibility:hidden"><br /></div>');
document.write('</div>');
var findwindow = document.getElementById('findwindow');
var over = 0;
var objDiv = null;
var DivID = null;
var test = document.getElementById('test');

