// JavaScript Document browse award winners

function initSelectScrolls(selectObj)
{
//Check if items in selectbox is greater than the max size,
if (selectObj.options.length >selectObj.size)
{
var divObj = selectObj.parentNode;
//alert(divObj);
divObj.selectboxSize = selectObj.size;//making the size of the selectbox to count of items in selectbox,so that vertival scrollbar won't appear in selectbox
//when a key is pressed on the div it should be passed to the select box
//make note that the focus function cause the scrollTop to change to 0, this can we workaround using a timeout function
divObj.onkeydown=function(){
setTimeout("syncSelect(document.getElementById('" + divObj.id+ "'),document.getElementById('" + selectObj.id+ "')," + divObj.scrollTop + ")","5");
selectObj.focus();
};
//set the selected object events and style to work with the extra div object.
selectObj.size=selectObj.options.length;
//selectObj.style.position = "relative";
selectObj.style.top = "0px";
selectObj.style.left = "-3px";
//selectObj.onkeydown=function(){event.cancelBubble = true;return true;};
//selectObj.onchange=function(){syncSelect(divObj,selectObj);event.cancelBubble = true;return true;};
//set the div stlye acording to the selected object size.
/*divObj.style.overflow = "auto";
divObj.style.width = "300px";*/
//divObj.style.height = (divObj.selectboxSize * 18) + "px";
divObj.style.border = "solid 1px #7F9DB9"; //make the div border as if they where the select object borders.
}
}
function syncSelect(divObj,selectObj,realScrollTop)
{
if (realScrollTop == null)
realScrollTop = divObj.scrollTop;
var scrollStepHeight = divObj.scrollHeight / selectObj.size;
//find out what are the visible options from the select box
var minVisibleIdx = Math.round(realScrollTop / scrollStepHeight);
var maxVisibleIdx = minVisibleIdx + divObj.selectboxSize;

if (selectObj.selectedIndex >= maxVisibleIdx)
divObj.scrollTop = (selectObj.selectedIndex - divObj.selectboxSize + 1) * scrollStepHeight;
else if (selectObj.selectedIndex < minVisibleIdx)
divObj.scrollTop = selectObj.selectedIndex * scrollStepHeight;
else
divObj.scrollTop = realScrollTop;
}


function search_detail()
{		
	//alert($("#select_box1").val());
	if(document.getElementById('select_box1').selectedIndex==-1)
	{
		alert('Please select a valid data');
	}
	else
	{
		var selObj = document.getElementById("select_box1");
        seltext  = selObj.options[selObj.selectedIndex].text;
		document.location =basepath+'about_the_pick/A/'+$("#select_box1").val()
	}
}
		
function post_bestseller(a)
{
	document.location =basepath+'about_the_bestseller/'+a;
}

function OnDivScroll()
{
	var lstCollegeNames = document.getElementById("select_box1");

	//The following archives two things while scrolling
	//a) On horizontal scrolling: To avoid vertical scroll bar in select box when the size of 
	//	 the selectbox is 8 and the count of items in selectbox is greater than 8.
	//b) On vertical scrolling:	To view all the items in selectbox
				
	//Check if items in selectbox is greater than 8, if so then making the size of the selectbox to count of
	//items in selectbox,so that vertival scrollbar won't appear in selectbox
	if (lstCollegeNames.options.length > 15)
	{
		lstCollegeNames.size=lstCollegeNames.options.length;
	}
	else
	{
		lstCollegeNames.size=15;
	}
}
			
//On focus of Selectbox
function OnSelectFocus(listobj)
{
	//alert();
	//On focus of Selectbox, making scroll position of DIV to very left i.e 0 if it is not. The reason behind
	//is, in this scenario we are fixing the size of Selectbox to 8 and if the size of items in Selecbox is greater than 8 
	//and to implement downarrow key and uparrow key functionality, the vertical scrollbar in selectbox will
	//be visible if the horizontal scrollbar of DIV is exremely right.
	if (document.getElementById("divCollegeNames").scrollLeft != 0)
	{
		document.getElementById("divCollegeNames").scrollLeft = 0;
	}
				
	var lstCollegeNames = document.getElementById('select_box1');
	//Checks if count of items in Selectbox is greater than 8, if yes then making the size of the selectbox to 8.
	//So that on pressing of downarrow key or uparrowkey, the selected item should also scroll up or down as expected.
	if( lstCollegeNames.options.length >listobj.length)
	{
	 	lstCollegeNames.focus();
	 	lstCollegeNames.size=listobj.length;
	}
}
