/*
Author Nandish@
functionality:  Provide selection, based on arrow keys (up and down )
Date 2-06-2009
*/
//----------------------------------------------------------------------------------------------------------
//this function which can be used to highlight the row based on key up and down ->arrow keys
//----------------------------------------------------------------------------------------------------------

function highlight(searchfield,ulDiv,classname) {
    $(function() {
	var pointer = null;
	var search = document.getElementById(searchfield);
	var ulTag =  document.getElementById(ulDiv);
	var listTags = ulTag.getElementsByTagName("li");
	var list = listTags.length;
								 
        search.onkeydown  = function(e) {
                e = (!e)? window.event : e;
	          switch( e.keyCode ) {
	              case 38:  //ARROW KEY UP
                      traverse(-1);  //first list tag li tag from bottom to top
                      break;
		      case 40:     //ARROW KEY DOWN                 
                      traverse(1);
		      break;
                      case 13:    //ENTER KEY OR RETURN KEY
                      for(i=0;i<list;i++){
                        if($.trim(listTags[i].className)!= "") {
                          $(listTags[i]).trigger("click"); //set an event dynamically
                        } // if statement closed
                      }  //for loop closed

                     break;
                     
                      
                  } //switch statement closed
          }; //function closed


              
       
       //inc is increment
       traverse = function(inc) {
        if(pointer !== null && pointer+inc >= 0 && pointer+inc < list)  {
	       listTags[pointer].className = '';
	       pointer += inc;
	       listTags[pointer].className = classname;
               
        }//if statement closed
           
	if(pointer===null) {
	     pointer=0;
	     listTags[pointer].className = classname;
             
             
     }//if statement closed
}//traverse function closed     
       
});
//closing hgihtlight function	
}
					
//----------------------------------------------------------------------------------------------------------

