/* Top N functionality */
var dragsort = ToolMan.dragsort();
var junkdrawer = ToolMan.junkdrawer();
var A=1,B=1,i,j,N,f;
function myTrigger(myN) {
	for (i=1;i<11;i++) {
	document.PageForm.topNumber.options[i-1] = new Option("Top " + 4*i,4*i);
	}
	changeTopNumber(myN);
	mF();
	dragsort.makeListSortable(document.getElementById("boxes"), saveOrder);
	fB();
	setTimeout(maxHeightImages, 1200);
	}
function myTrigger1(myN,topText) {
	for (i=1;i<11;i++) {
	document.PageForm.topNumber.options[i-1] = new Option(topText + ' ' + 4*i,4*i);
	}
	changeTopNumber(myN);
	mF();
	dragsort.makeListSortable(document.getElementById("boxes"), saveOrder);
	fB();
	setTimeout(maxHeightImages, 1200);
	}
	function myTrigger11(myN,topText) {
	for (i=1;i<7;i++) {
	document.PageForm.topNumber.options[i-1] = new Option(topText + ' ' + 4*i,4*i);
	}
	changeTopNumber1(myN);
	mF();
	dragsort.makeListSortable(document.getElementById("boxes"), saveOrder);
	fB();
	setTimeout(maxHeightImages, 1200);
	}
function saveOrder(item) {
	var group = item.toolManDragGroup;
	var list = group.element.parentNode;
	var id = list.getAttribute("id");
	if (id === null) {return;}
	group.register('dragend', mF);
}
function fB() {
	var l =document.getElementById("boxes");
	var t =l.getElementsByTagName("li");
	f =t.length;
	for ( i =0; i <f; i++) {
	for (j =f-1; j >0; j--) {
	if ((t[j].title==t[i].title)&&(j!=i)) {
	document.getElementById("boxes").removeChild(t[j]);
	f--; }}}
}
function mF() {
	var l =document.getElementById("boxes");
	var t =l.getElementsByTagName("li");
	var myTopID =[];
	f =Math.min(t.length, N);
	//k =Math.max(t.length, N);
	for (i =0; i <f; i++) {
	myTopID[i] =t[i].title;
	t[i].style.backgroundColor = "#FFEEEE";
	}
	/*
	for (j =0; j <k; j++) {
	myTopIDNew[j] =t[j].title;
	//t[i].style.backgroundColor = "red";
	}
	*/
	document.PageForm.myTopFriends.value = myTopID.join(",");
	//document.PageForm.newVal.value = myTopIDNew.join("***");
	
	for (i =N; i <t.length; i++){
	t[i].style.backgroundColor = "eeeeff";
	}
	//alert(f);
	//alert(document.PageForm.myTopFriends.value);
	//dd();
}
function dd(){
	var l =document.getElementById("boxes");
	var t =l.getElementsByTagName("li");
	var myTopIDNew =[];
	//f =Math.min(t.length, N);
	k =Math.max(t.length, N);
	/*for (i =0; i <f; i++) {
	myTopID[i] =t[i].title;
	t[i].style.backgroundColor = "red";
	}*/
	
	for (j =0; j <k; j++) {
	myTopIDNew[j] =t[j].title;
	//t[i].style.backgroundColor = "red";
	}
	
	//document.PageForm.myTopFriends.value = myTopID.join(",");
	document.PageForm.newVal.value = myTopIDNew.join(",");
	/*
	for (i =N; i <t.length; i++){
	t[i].style.backgroundColor = "eeeeff";
	}
	*/
}
function bigSave() {
	
	if (A == 1) {
	A =0;
	document.PageForm.fuseaction.value = "user.SaveTopFriends";
	alert(PageForm);
	document.PageForm.submit();
	}
}
function mySearch() {
	if (B == 1) {
	B = 0;
	document.theSearch.myTopFriends.value = document.PageForm.myTopFriends.value;
	document.theSearch.submit();
	}
}
function newSearch() {
	document.theSearch.PREVPageLASTONERETURENED.value = 0;
	document.theSearch.PREVPageFirstONERETURENED.value = 0;
}
function myBrowse() {
	if (A == 1) {
	A = 0;
	document.theSearch.myTopFriends.value = document.PageForm.myTopFriends.value;
	document.theSearch.f_search.value = "";
	document.theSearch.submit();
	}
}
function maxImage(w) {
	if (w.height > 90) {
	var r = w.width *(90 / w.height);
	w.height = 90;
	w.style.height = 90;
	w.width = r;
	w.style.width = r;
	}
}
function maxHeightImages() {
	if (document.all) {
	var liCollection = document.getElementById("boxes").childNodes;
	var r = '';
	for (i = 0; i< liCollection.length; i=i+1) {
	var iC = liCollection[i].getElementsByTagName("IMG");
	for (j = 0; j< iC.length; j= j+1) {
	if (iC[j].height > 90) {
	r = iC[j].width *(90 / iC[j].height);
	iC[j].style.height = 90;
	iC[j].style.width = r;
	}}}}
}
function changeTopNumber(to) {
	//if (to%4 === 0) {
	N=to;
	document.getElementById("currentNumber").innerHTML = to.toString();
	document.getElementById("currentNumber11").value = to.toString();
	document.PageForm.topNumber.value = to;
	for (i = 0; i < document.PageForm.topNumber.length; i++) {
	if (document.PageForm.topNumber[i].value == N) {
	document.PageForm.topNumber[i].selected = true;
	}}
	//}
	mF();
	//hide();
}
function changeTopNumber1(to) {
	//if (to%4 === 0) {
	N=to;
	document.getElementById("currentNumber").innerHTML = to.toString();
	document.getElementById("currentNumber11").value = to.toString();
	document.PageForm.topNumber.value = to;
	for (i = 0; i < document.PageForm.topNumber.length; i++) {
	if (document.PageForm.topNumber[i].value == N) {
	document.PageForm.topNumber[i].selected = true;
	}}
	//}
	mF();
	hide();
}
function helpFriends() {eval("pageOF = window.open('http://zonechill.com/Modules/User/TopFriendsHelp.aspx','helper','toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,resizable=0,width=700,height=200,left=387,top=324');");}

