//var isIE = (window.ActiveXObject);
var completeTable;
var completeField;
var autocompleteControl;
var autoContainer;
 

var searchString;
var tempString;
var wordCount;



//add onload handler
addEventHandler("load", init );

String.prototype.booleanValue = function() {

	switch(this.toLowerCase()) 
	{
	    case "1":
	    case "true":
	    case "yes":
	        return true;
	    case "0":
	    case "false":
	    case "no":

	        return false;
	    default:
	        return Boolean(this);
	}
}


function trimString()
{
	return this.replace(/^\s+|\s+$/g, '');
}
String.prototype.trim = trimString;

function createElement(type, id, className)

{
    
	 
	var elem = document.createElement(type);
    if (id) elem.id = id;
    if (className) elem.className = className;
    		
    return elem;
}


function findPos(elt) 
{
	var curleft = 0;
	var curtop  = 0;
	
	if (elt.offsetParent) 
	{
		do 
		{
			curleft += elt.offsetLeft;
			curtop  += elt.offsetTop;
		} while (elt = elt.offsetParent);
	}
	
	return 	{
				 left: curleft
				,top:  curtop
			};
};

function init() 
{
	autocompleteControl = document.getElementById("AutocompleteControl");
    completeField 		= document.getElementById("complete-field");    
    setCssPath();	 
	///setEltClass( completeField, textFieldClass );		
    //add the key handler
    //completeField.onkeyup = autoComplete;
     addEventHandler.call( completeField, "keyup", autoComplete );
     
     //add handler for Enter Key
	addEventHandler("keydown", handleEnterKey );
	
	isMaxHeightSupported = testForMaxHeightSupport();
	
	//create the table
    completeTable = document.createElement("table");
    completeTable.id = "completeTable";
		
	//create the containing DIV
    autoContainer = document.createElement("div");
    autoContainer = document.getElementById("autoContainer");
    autoContainer = createElement("div", "autoContainer");
    
    with (autoContainer)
    {
    	 
    	if (scrollbarColorClass) className = scrollbarColorClass;
    	style.left = findPos(completeField).left - findPos(autocompleteControl).left + "px"; 
		style.top  = autocompleteControl.clientHeight + "px";
		 
    	 
    }
	 
	autocompleteControl.appendChild(autoContainer);	
	completeTable = createElement("table", "completeTable" );
	
	autoContainer.appendChild(completeTable);
	 
}



function testForMaxHeightSupport()
{	
	//var outerDiv = document.createElement("div");

	//outerDiv.className = "maxHeightTest";
	var outerDiv = createElement("div", null, "maxHeightTest");

	//var innerDiv = document.createElement("div");
	var innerDiv = createElement("div");

	innerDiv.style.height = "200px";
	
	outerDiv.appendChild(innerDiv);
	autocompleteControl.appendChild(outerDiv);
	
	var isMaxHeightSupported = (innerDiv.clientHeight > outerDiv.clientHeight);


	autocompleteControl.removeChild(outerDiv);
	
	return isMaxHeightSupported;
}


 

function setEltClass( elt, className)
{
	if (  className && elt )
	{
		elt.className = className;
	}
}

function setCssPath()
{
    
    // Commented by Rajrajan.. TODO => we need to fix this
    /*if (cssPath && document.styleSheets) 
    {  
		var styleSheet = document.styleSheets["AutocompleteCSS"]; //AutocompleteControl.css	        	 
	    if ( styleSheet ) 
	    {
	    	if ( styleSheet.setAttribute )
	    	{
	    	 	styleSheet.setAttribute('HREF', cssPath);
	    	}
	    	else
	    	{
	    		styleSheet.href = cssPath;
	    	}
	    }
	} */
}

	
function initRequest(url) 
{
    if (window.XMLHttpRequest) 
    {
        return new XMLHttpRequest();
    } 
    else if (window.ActiveXObject) 
    {
        return new ActiveXObject("Microsoft.XMLHTTP");
    }
}

function autoComplete(e) 
{
	if (!e) e = window.event;
	
	var customTarget=e.target||e.srcElement
	if  (customTarget.id != "complete-field"){
		return false;
	}
	if (handleSpecialKeys(e)) return; 
	searchString = completeField.value.trim();
	 
    if (!searchString) 
    {
        // if(get('country')!=null) 	get('country').style.display='block';
        
         if(get('multiCountryDiv')!=null) 	showMulticountryforAuto();;
         if(get('countrySelect')!=null) 		disableHelperFun(get('countrySelect'),true);  
         if(get('proximitySpan')!=null) 	showCityDivForAuto(document.plSearchForm.country.value); //get('proximitySpan').style.visibility ='visible';
    
        clearTable();
    } 
    else 
    {
    if (searchString.length > 1) {
		tempString=searchString.split(",");
		wordCount=tempString.length;
		var qString=tempString[wordCount-1].trim();
		if (qString.length<=1)
			return false;
		
		if (searchType=="company")
			var url = "getCompanyList.do?text="+encodeURI(qString);
		if (searchType=="keyword")
			var url="getKeywordsList.do?text="+encodeURI(qString);
		
		
        var req = initRequest(url);
        req.onreadystatechange = function() 
        {
            if (req.readyState == 4) 
            {
                if (req.status == 200) //OK 
                {
                    //parseMessages(req.responseText);Added for PDL
                   	parseMessages(decodeURI(req.responseText),searchString);
                } 
                else if (req.status == 204) //No Content
                {
                    clearTable();
                }
            }
       //};
       }.bind( req, searchString);
        req.open("POST", url, true);
        req.send(null);
      }
    }
}

function parseMessages(responseText,searchString) 
{
    clearTable();

	if (!responseText.length)
	{
		return;
	}
	//display error message
	else if ( /^".+"&/.test(responseText) ) 
	{
		alert( responseText.replace(/^"|"$/, "") );
	}
	else
	{
		var jsonObj;
		try
		{
			 jsonObj=JSON.parse(responseText);
		}
		catch(e)
		{
			var prop;
			//var msg = "An error occured while parsing the JSON-formatted responseText:\n";
			//var msg = "An error occured while getting autocomplete results";
			//var msg = '<bean:message key="pl.js.alert.error.autocomplete"/>';
			//caught a SyntaxError exception
			/*for (prop in e)
			{
				msg += prop + ": " + e[prop] + "\n";
			}
			*/
			alert(msg);
			
			return;
		}

   		
   		for (var loop = 0; loop < jsonObj.length; loop++) 
	  		{ 
	    		appendFund.call(jsonObj[loop], searchString); 
	  		} 
        
        //put in a scrollbar if applicable
        setListHeight(jsonObj.length);
   		setListWidth();
   		
     	//autoContainer.style.visibility = "visible";
     	//autoContainer.style.visibility = "visible";
		disableHelperFun(autoContainer,true);
     	//if(get('country')!=null) 	get('country').style.display='none';
     	 if(get('multiCountryDiv')!=null) 	hideMulticountryforAuto();
     	if(get('countrySelect')!=null) 	disableHelperFun(get('countrySelect'),false);
     	if(get('proximitySpan')!=null) 	get('proximitySpan').style.visibility ='hidden';
     
	}
}


function disableHelperFun(Obj,bFlag){

	 if(bFlag){
		 if(Obj!=null ){
				if(Obj.style.display == null || Obj.style.display=='' || Obj.style.display=='none' ){
					Obj.style.display='block';
				}
				if(Obj.style.visilibilty== null  || Obj.style.visilibilty=='' || Obj.style.visilibilty=='hidden'){
					Obj.style.visibility='visible';
				}
			 
		 }
	 }else {
	 

	 	 if(Obj!=null ){
				if(Obj.style.display == null || Obj.style.display=='' || Obj.style.display=='block' ){
					Obj.style.display='none';
				}
				if(Obj.style.visilibilty== null  || Obj.style.visilibilty=='' || Obj.style.visilibilty=='visible'){
					Obj.style.visibility='hidden';
				}
			 
		 }
	 
	 
	 }

}


function setListHeight(actualListSize)
{
	 
	if ( listSize && !isNaN(listSize) ) 

	{		 	  
	 
		var containerHeight = 200; // savita parseInt( completeTable.clientHeight / actualListSize) * listSize;
		 
		if (   autoContainer.setExpression
		   && !isMaxHeightSupported
		   )
		{
			/* savita autoContainer.style.setExpression('height'

										, 'parseInt(document.getElementById("completeTable").clientHeight) > ' + containerHeight 
										  + '?"' + containerHeight + 'px"' 
										  + ':document.getElementById("completeTable").clientHeight'

										, 'JavaScript');*/
										autoContainer.style.setExpression('height'

										,  150+"px"

										, 'JavaScript')
		}
		else
		{
			autoContainer.style.maxHeight = containerHeight + "px";
		}
		autoContainer.className += " scrollbar";
		 
	}

	setListHeight = function() {};

}


function setListWidth() 
	{ 
	     if (  /\bscrollbar\b/.test(autoContainer.className) ) 
	     { 
	             	/* savita autoContainer.style.width = (completeTable.clientHeight > autoContainer.clientHeight 
	                ? completeTable.clientWidth + 16 
	                : completeTable.clientWidth) + "px"; */
					autoContainer.style.width = 250+"px";
	     } 
	} 

function addEventHandler( eventName, eventHandler )
{
	var CAPTURING_PHASE = true, BUBBLING_PHASE = false;

	if( window.addEventListener ) 
	{
		addEventListener( eventName, eventHandler, BUBBLING_PHASE );
	} 
	else if( window.attachEvent ) 
	{	
		attachEvent( 'on' + eventName, eventHandler );
	}
}
	
function clearTable() 
{
    if (completeTable) 
    {
     	//autoContainer.style.visibility = "hidden";
		disableHelperFun(autoContainer,false);
     	//if(get('country')!=null) 	get('country').style.display='block';
     	if(get('multiCountryDiv')!=null) 	showMulticountryforAuto ();
     	if(get('countrySelect')!=null) 	disableHelperFun(get('countrySelect'),true);
		if(get('proximitySpan')!=null) 	showCityDivForAuto(document.plSearchForm.country.value);//get('proximitySpan').style.visibility ='visible';
		//completeTable.parentNode.removeChild(completeTable);
		
		//RowManager.resetRowCount();
		for (var loop = completeTable.childNodes.length -1; loop >= 0 ; loop--) 
		{
			completeTable.removeChild(completeTable.childNodes[loop]);
			RowManager.resetRowCount();
		}
    }
}


function handleMouseEvent(e)
{	
	var row = this;
	if (!e) e = event;
 
	if (/^mouse(over)|(up)|(down)|(out)$/.test(e.type)) {

				if(CUR_ROW_OBJ!=null) CB_LIGHT(CUR_ROW_OBJ.rowIndex,get('completeTable'),0);

 				 CUR_ROW_OBJ=row;

				 RowManager.highlightRow(row, "popupRow", "popupRow " + e.type);		
 
				 R_MOVE=row.rowIndex;
 
	}


	if (/^mouseout$/.test(e.type)) RowManager.setHighlightedRow(null);
		
	//	row.className = "popupRow " + e.type; 
}


function appendFund(searchString) 
{
    var row, symbolCell, nameCell;
    var fund=this;
    
    if (completeTable.insertRow) 
    {
        row = completeTable.insertRow(completeTable.rows.length);
        symbolCell 	= row.insertCell(0);
        nameCell 	= row.insertCell(1);
    } 
    else 
    {
       /* row 		= document.createElement("tr");
        symbolCell 	= document.createElement("td");
        nameCell 	= document.createElement("td");*/
        row 		= createElement("tr");
        symbolCell 	= createElement("td");
        nameCell 	= createElement("td");
        row.appendChild(symbolCell);
        row.appendChild(nameCell);
        completeTable.appendChild(row);
    }

    	row.className   = "popupRow";
	    row.onmouseover = handleMouseEvent;
	    row.onmouseout  = handleMouseEvent;
	    row.onmousedown = handleMouseEvent;
	    row.onmouseup   = handleMouseEvent;
    row.onclick1	    = function() 
    		          { 
    			  		var newKeyword,newQualcd;
	    				newKeyword="";
							 
	    			  		  if (wordCount>1){
								 
		    			  		  for (var count=0;count<wordCount-1;count++)
		    			  		  {
		    			  		  	newKeyword+=tempString[count]+",";
		    			  		 
		    			  		  }
		    			  	 }
      			  		  	 newKeyword+=fund.keyword+",";
      			  		  	 document.getElementById("complete-field").value=newKeyword;
							 clearTable() ;  
    		      	  }; 
   		row.className   = "popupRow";
	    row.onmouseover = handleMouseEvent;
	    row.onmouseout  = handleMouseEvent;
	    row.onmousedown = handleMouseEvent;
	    row.onmouseup   = handleMouseEvent;
	    row.setAttribute('fund.keyword',fund.keyword);
		row.setAttribute('ID-1', completeTable.rows.length);
		//row.setAttribute('fund.qualcd',fund.qualcd);
		row.setAttribute('onclick',"javascript:setSearchValue(this)");		
	    
    	row.onclick	    	= function() 
    		      		{ 
    		      		    
    		      		
	    			  		  var newKeyword,newQualcd;
	    			  		  newKeyword="";
							 if (wordCount>1){
								 for (var count=0;count<wordCount-1;count++)
		    			  		 {
		    			  		  	newKeyword+=tempString[count]+",";
		    			  		 }
		    			  	 }
      			  		  	 newKeyword+=fund.keyword+",";
      			  		  	 document.getElementById("complete-field").value=newKeyword;    			  		 
							 RowManager.addRow(row); 
      			  		  	 clearTable() ;
    		      		}; 
    
    
			   
			var wholeString=fund.keyword;
			var regex = new RegExp("("+tempString[wordCount-1].trim()+")","i");
			 var replacematch= regex.exec(wholeString);
			 if (replacematch!=null)
				 	{var replacement = "<b>"+replacematch[0]+"</b>";
					 var newWholeString = fund.keyword.replace(regex,replacement);
					 symbolCell.innerHTML=newWholeString;
				 	}
			else
			{
			 symbolCell.innerHTML=wholeString;
			 }
   // symbolCell.appendChild(document.createTextNode(fund.keyword));
    
//    symbolCell.className 		= "popupItem";
    symbolCell.id 				= "symbolCell";
    
}


    

     

String.prototype.highlightSearchString = function(cell, searchString, highlightClass) 
	{ 
	  if (highlightClass) 
	  { 
	    var re = new RegExp(searchString, "i"); 
	    var matchedString = this.match(re); 
	    if (matchedString) 
	    { 
	     // var matchSpan = createElement("span", null, highlightClass); 
	      //var matchSpan = document.createElement("span", null, highlightClass); 
	      var matchSpan = document.createElement("span");
	      matchSpan.setAttribute("style", "font-weight: bold;");
	      matchSpan.appendChild(document.createTextNode( matchedString )); 
	      cell.appendChild(matchSpan); 
	      return RegExp.rightContext; 
	    } 
	  } 
	  return this; 
	} 
	
Function.prototype.bind = function(object) 
	{ 
	  var method = this; 
	  arguments.slice = Array.prototype.slice; 
	  var oldArguments = arguments.slice(1); 
	  //return function() { return method.apply(object, oldArguments.concat(Array.prototype.slice.apply(arguments))); }; 
	  return function() { return method.apply(object, oldArguments); }; 
	}
	

//set Search Values 


function setSearchValue(EVT) 	{ 
				try{		

 					 fnVal=EVT.getAttribute('fund.keyword' );			    	 
	    	  		 var newKeyword;			     	
					 newKeyword="";
					  
 	    			 if (wordCount>1){					 	 
		    		 	  for (var count=0;count<wordCount-1;count++)
		    		 		  {
		    			  		  	newKeyword+=tempString[count]+",";
 		    		 		  }
		    		 }
       			  	newKeyword+=fnVal+",";      			  	 
 	    			document.getElementById("complete-field").value=newKeyword;    			  		 

       			  	RowManager.addRow(EVT); 
      			  	clearTable() ;

					var compTable = document.getElementById('completeTable');
					compTable.visibility= false;
					//window.event.keyCode=0;
				
				}catch(e){
						var compTable = document.getElementById('completeTable');
						compTable.visibility= false;
						//window.event.keyCode=0;
				
					 
				}
    		   }	

	
	
	
// keystroke handler function 


function handleEnterKey(e)
{	
	if (!e) e = event;
    
    
       if (e.keyCode == 13)
       {
            var row = RowManager.getHighlightedRow();
            if (row) 
            {
            	if (row.fireEvent)    		//IE
                { 

                	row.fireEvent("onclick");
                }
                else if (row.dispatchEvent) //Mozilla
                {
					var BUBBLES = true, CANCELABLE = true;                	
					var evt = document.createEvent("HTMLEvents");

					evt.initEvent("click", BUBBLES, CANCELABLE);
                
                    row.dispatchEvent(evt);
                }
				//e.stopPropagation();
				e.returnValue = false;
    			e.cancelBubble = true;

    		}
    }
}
function handleSpecialKeys(e)
	{ 
	  switch (e.keyCode) 
	  { 
	      
	      // Escape 
	      case 27: 
	      	clearTable(); 
	      	break; 
	 
	      // Up arrow 
	      case 38: 
			RowManager.highlightPreviousRow("popupRow", "popupRow mouseover"); 
	    	RowManager.scrollList(); 
	        break; 
	 
	      // Down arrow 
	      case 40: 
	 		RowManager.highlightNextRow("popupRow", "popupRow mouseover"); 
	   	    RowManager.scrollList(); 
	        break; 
	 
	      // left & right arrow keys. Absorb them. 
	      case 37: 
	      case 39: 
	          break; 
	 
	      default: 
	          return false; 
	  } 
	 
	  //sets the return value of the event 
    //(if false, the action is canceled). 
	  e.returnValue = false; 
	 
	  //Sets whether or not the current event 
	  //stops bubbling through the document hierarchy. 
	  e.cancelBubble = true; 
	 
	  return true; 
	} 
	
var RowManager = (function()

{
    var counter = 0;
    var firstRow, lastRow, highlightedRow;
    
    //private methods
    function getPreviousRow()		
  	{ 
  		return 	highlightedRow && highlightedRow.previousSibling 	

  				? highlightedRow.previousSibling 	
  				: lastRow;		
  	}
  	
  	function getNextRow()		
  	{ 
  		return 	highlightedRow && highlightedRow.nextSibling 	
  				? highlightedRow.nextSibling 	
  				: firstRow;		
  	}
  	
  	function getHighlightedRow()    {  return highlightedRow; }
  	function setHighlightedRow(row) { highlightedRow = row;  }
  	
    function resetRowCount() 
    {  
    	counter = firstRow = lastRow = highlightedRow = 0;   

    };
    
    function addRow(row)     
    { 
    	if (!counter++) firstRow = row; 
    	
    	lastRow = row;        
    };
	
	function highlightPreviousRow(nonHighlightedStyle, highlightedStyle) 

	{
	    if (highlightedRow !== firstRow)
	    {   
	        highlightRow(getPreviousRow(), nonHighlightedStyle, highlightedStyle);
	    }
	}
	
	function highlightNextRow(nonHighlightedStyle, highlightedStyle) 

	{	
	    if (highlightedRow !== lastRow)
	    {  
	        highlightRow(getNextRow(), nonHighlightedStyle, highlightedStyle);
	    }
	}	
	
	function highlightRow(row, nonHighlightedStyle, highlightedStyle)    

    {
		//turn off current row
		//	row.className = highlightedStyle; 
		//	setHighlightedRow(row);
			if(row!=null && row!=undefined){
					if(highlightedStyle==nonHighlightedStyle+' '+'mouseover'){
					
							 CB_LIGHT(row.rowIndex,get('completeTable'),1);
							 if(get('completeTable').rows[row.rowIndex]!=null)
 								 LAST_CLASS_NAM=get('completeTable').rows[row.rowIndex].className;	
						 	 setHighlightedRow(row);
							 scrollList();
						}
						else if(highlightedStyle==nonHighlightedStyle+' '+'mouseout'){
							//alert('Mouse Out,'+ highlightedStyle);
							CB_LIGHT(row.rowIndex,get('completeTable'),0);				
							scrollList();
						} 
				}
    } 
    
    function scrollList()

	{	
	    var highlightedRow = getHighlightedRow();
	    if (highlightedRow)
	    { 
	        if (  highlightedRow.offsetTop < autoContainer.scrollTop )
	        {   
	            //scroll to the highlighted row

	            autoContainer.scrollTop = highlightedRow.offsetTop;
	        } 
	        else 
	        {
   	            var rowOffsetBottom = highlightedRow.offsetTop + highlightedRow.clientHeight;
	      
	            if ( rowOffsetBottom > autoContainer.scrollTop + autoContainer.clientHeight )

	            {  
	            	autoContainer.scrollTop = rowOffsetBottom - autoContainer.clientHeight;
	            }
	        }
	    }
	}           
	           
    return  ({
                 "resetRowCount": 		 resetRowCount

                ,"addRow":        		 addRow
                ,"highlightPreviousRow": highlightPreviousRow
                ,"highlightNextRow":	 highlightNextRow
                ,"highlightRow":		 highlightRow

                ,"scrollList":			 scrollList
                ,"getHighlightedRow":	 getHighlightedRow
                ,"setHighlightedRow": 	 setHighlightedRow
            });
})();


 

//document.onkeydown=CUR_BLOCK; //Binding onkeydown event to function "cur_block".
//Declaration.
var CURRENT_BLOCK='', R_MOVE=0,R_MOVE_1, LAST_CLASS_NAM='', CUR_ROW_OBJ, START_FROM=0, LAST_VISITED_BLOCK;
 


function CUR_BLOCK_HIGHLIGHT(evt)
{
	var KC=evt.keyCode;
	if(navigator.appName!='Netscape') if(KC!=13) autoComplete(evt);
	// Highlighting the rows on key press of up and down arrow.
	var compTable = document.getElementById('completeTable');
	if(compTable.rows.length<=0) return;

	CURRENT_BLOCK='completeTable'; 

	if(CURRENT_BLOCK!='')
	{
		 
		if(LAST_VISITED_BLOCK!=CURRENT_BLOCK)
		{// last visited table does not match with current focused table then reassign all the variables.
			START_FROM=get(CURRENT_BLOCK).getAttribute('START-FROM');
			if(START_FROM==null){
				START_FROM=0;
				get(CURRENT_BLOCK).setAttribute('START-FROM',START_FROM);
			}
			if(LAST_CLASS_NAM!=null && LAST_CLASS_NAM!='')CB_LIGHT(R_MOVE,get(LAST_VISITED_BLOCK),0);
			LAST_CLASS_NAM='';
			R_MOVE=START_FROM;
 		}

		if(LAST_VISITED_BLOCK!='')LAST_VISITED_BLOCK=CURRENT_BLOCK;
	}

	if((KC!=38 && KC!=40 && KC!=13)  )return;

	// On Enter key call the click event.
	if(KC==13)
	{

		setSearchValue(CUR_ROW_OBJ);     
		R_MOVE=0;
		autoContainer.visibility= false;
		completeTable.visibility= false;
//		window.event.keyCode=0;
		get('complete-field').focus();
		return;
	}
	CURRENT_BLOCK='completeTable';

	//Declaration.
	var oDrpTBl=get(CURRENT_BLOCK),osDiv=get('autoContainer'), RLen=oDrpTBl.rows.length;

	CB_LIGHT(R_MOVE,oDrpTBl,0);//De-selecting the last visited row.
	
	if(KC==38)
	{//On Up key press.		
		if(R_MOVE==START_FROM)R_MOVE=RLen;
		CUR_ROW_OBJ=oDrpTBl.rows[R_MOVE];		
		if(CUR_ROW_OBJ!=null && CUR_ROW_OBJ!=''){
			if(CUR_ROW_OBJ.id=='TEMPLATE')R_MOVE--;
			else 			
				oDrpTBl.setAttribute('RIGHTROWID',CUR_ROW_OBJ.id);
			
		}

		 if(osDiv.scrollTop==0)osDiv.scrollTop=800;
		R_MOVE--;	
		//Scrolling to view the selected row.
		osDiv.scrollTop=osDiv.scrollTop-oDrpTBl.rows[R_MOVE].clientHeight;
					
	}
	
	if(KC==40)
	{//On Down key press.
 	//RowManager.highlightRow(CUR_ROW_OBJ, "popupRow", "popupRow 1" );

 		if(CUR_ROW_OBJ!=null && CUR_ROW_OBJ!=''){
			
			if(CUR_ROW_OBJ.id=='TEMPLATE')R_MOVE++;
			else {
			 //alert(3);
				 oDrpTBl.setAttribute('RIGHTROWID',CUR_ROW_OBJ.id);				

				R_MOVE++;

			} 
			CUR_ROW_OBJ=oDrpTBl.rows[R_MOVE];		
		   	
		}
	}

	if(R_MOVE>=RLen){
		R_MOVE=START_FROM; // Initilize R_MOVE when R_MOVE greater than no of rows in the table.		
	}
	//Scrolling to view the selected row.
	if(R_MOVE==(RLen)) osDiv.scrollTop=oDrpTBl.clientHeight;
	if(KC==40)osDiv.scrollTop=osDiv.scrollTop+oDrpTBl.rows[R_MOVE].clientHeight;
	if(R_MOVE<=START_FROM)osDiv.scrollTop=0;	

	if(oDrpTBl.rows[R_MOVE]!=null)
	LAST_CLASS_NAM=oDrpTBl.rows[R_MOVE].className;	
	CB_LIGHT(R_MOVE,oDrpTBl,1);//Selecting the visited row.
}

function CB_LIGHT(r,oT,s)
{// Selecting and unselecting the row.  
	if(oT.rows[r]==null  ){ return; }
  	if(s==0) {oT.rows[r].className=LAST_CLASS_NAM; 
			oT.rows[r].childNodes[0].style.background='#FFFFFF';
			oT.rows[r].childNodes[0].style.color='#000000';

		 
	}
	else{   
		oT.rows[r].childNodes[0].style.background='lightblue';
		oT.rows[r].childNodes[0].style.color='#FFFFFF';
	   CUR_ROW_OBJ=oT.rows[r];    }
 		
 }


function Initilize_Traverse()
{//On Load function.
//alert('LLLO');
	//Appening an input element with the document tag.
	var oIn=document.getElementById('complete-field');
	//document.body.appendChild(oIn);
	//oIn.id='complete-field';
	//oIn.style.width=0; oIn.style.height=0;
	oIn.onkeydown=CUR_BLOCK_HIGHLIGHT;
}

function CB_OnClick(ROW)
{
	if(CUR_ROW_OBJ!=null) CUR_ROW_OBJ.className='clsTrBack';
	CUR_ROW_OBJ=ROW;
	CUR_ROW_OBJ.className='clsTrTraverse';
	R_MOVE=ROW.rowIndex;
	if(get('complete-field')!=null) get('complete-field').focus();
}

//Common Functions.
function get(strId)
{
	return document.getElementById(strId);
}

