function refreshRank(){
	var box = document.getElementById("faavContainer");
	var d=1;
	for(i=0;i<box.childNodes.length;i++){
			//alert(box.childNodes[i].className);
			//if(box.childNodes[i].style.display != 'none' && box.childNodes[i].style.visibility != 'hidden'){
			if(box.childNodes[i].className != "hidden"){
				//handles all types of browsers this way
				if(box.childNodes[i].childNodes[1].className == 'itemCntr'){
					box.childNodes[i].childNodes[1].innerHTML = "#" + (d);
				}else{
					if(box.childNodes[i].childNodes[3].className == 'itemCntr'){
						box.childNodes[i].childNodes[3].innerHTML = "#" + (d); 
					}
				}		
				d++;
			}
	}

	if(d==1){
		//no items left
		document.getElementById("ulContainer").innerHTML = "<center><div style='float;none; cursor:pointer;'><br><a onclick='sampleRefresh()'><b>Reset</b><br><img src='images/refresh.png'></a></div></center>";
	}
}

function sampleRefresh(){
	new Ajax.Updater("ulContainer","ajax/sampleFaav.php", {
		onComplete: function(){ reSortNoNum(); }
	});
}

function reSort(){
	//recreate sortable list
	Sortable.create("faavContainer",{
				handle: "handle",
				onUpdate: function() {
					refreshRank();
					new Ajax.Request("ajax/userOrder.php", {
						method: "post",
						parameters: { data: Sortable.serialize("faavContainer") },
						onSuccess: function(transport){
							//refreshRank();
						}
			  		});
				}
		 	});
}

function reSortNoNum(){
	//recreate sortable list
	Sortable.create("faavContainer",{
		handle: "handle",
		onUpdate: function() {
			refreshRank();
		}

	});
}

function sliderConstrain(min, max, id, lst){
	slideParams = "ajax/slidePrice.php?min=" + min + "&max=" + max + "&id=" + id + "&lst=" + lst;
	//Sortable.destroy("faavContainer");
	new Ajax.Updater("faavContainer",slideParams);
}

function remove(lstId, rmvId){
	Effect.DropOut("faav_" + lstId + "v" + rmvId);
	var remLoc = "ajax/remove.php" + "?iid=" + rmvId;
	
	new Ajax.Updater("faavContainer","ajax/remove.php?iid="+rmvId+"&lst="+lstId,
		{onComplete: function(){
			reSort();
			refreshRank();
			linkEdit();
			noteEdit();
			//*******SEND NEW RANKING TO SERVER************/
			new Ajax.Request("ajax/userOrder.php", {
						method: "post",
						parameters: { data: Sortable.serialize("faavContainer") }
			  		});
			//**********************************************/
		}
	});
}

function shareItem(itmID){
	new Ajax.Updater("shareBar","ajax/sharebar.php", {
		method: 'post',
		parameters: {iid: itmID},
		onComplete: function(){ Effect.SlideDown("shareBar"); }
	});
}

function shareMe(itm,frnd){
	var shareMsg = document.getElementById("shareMsg").value;
	document.getElementById("shareBar").innerHTML = "<h2><img style='margin-right: 4px;' src='images/ajax-loader-jumboDark.gif'>Sharing...</h2>";
	new Ajax.Request("ajax/share.php?itm="+itm+"&frnd="+frnd, {
						method: "post",
						parameters: {msg: shareMsg},
						onSuccess: function(transport){
							Effect.SlideUp("shareBar");
						}
			  		});
}

function newMessages(){
	document.getElementById("entry").innerHTML = "<br><br><br><center><img style='display:inline;padding-left: 10px; padding-right: 10px;' src='images/ajax-loader-jumbo.gif'><h1 style='display:inline;'>Loading Messages...</h1></center>";
	
	new Ajax.Updater("entry","ajax/messages.php?stat=0");
}

function suggestMgr(act,itmID, suggID){
	new Ajax.Updater("entry","ajax/suggest.php?act=" + act + "&itmid=" + itmID + "&suggid="+suggID);
}

function suggDelete(rmvID, itmID){
	Effect.DropOut("sugg_" + rmvID);
	var remLoc = "ajax/suggest.php?act=1" + "?itmid=" + itmID + "&suggid=" + rmvID;
	new Ajax.Request(remLoc);
}

function suggAdd(addID, itmID){
	Effect.Puff("sugg_" + addID);
	var addLoc = "ajax/suggest.php?act=2" + "?itmid=" + itmID + "&suggid=" + addID;
	new Ajax.Request(addLoc);
}

function loginModal(logid){
	new Ajax.Updater("thumb_src","login.php?id=" + logid);
}

function fullThumb(thumbSrc){
	itmwindow=dhtmlmodal.open('agebox', 'div', 'thumb_popup', 'Item Info', 'width=600px,height=300px,left=150px,top=100px,resize=0,scrolling=0');
	itmwindow.moveTo('middle','middle');
	
	new Ajax.Updater("thumb_src","ajax/getitem.php?id="+thumbSrc);
}

function addFromZoom(id){
	document.getElementById("itmStat").innerHTML = "<img style='display: inline; margin-right: 4px;' src='images/ajax-loader-iconButton.gif'>Adding...";
	new Ajax.Updater("itmStat","ajax/addexisting.php?id="+id);
}

function addFromSide(id){
	document.getElementById("sidebarAd").innerHTML = "<img style='display: inline; margin-right: 4px;' src='images/ajax-loader-mini.gif'>Adding...";
	new Ajax.Updater("sidebarAd","ajax/addexisting.php?id="+id);
}

function saveStar(event){
	new Ajax.Request('ajax/savestar.php', {
		parameters: event.memo,
		onComplete: function(transport) {
			//optional callback
			alert(transport.responseText);
		}
	});
}

function faavSearch(){
	//document.getElementById("post").innerHTML = "<br><br><br><center><h1 class='title'>Searching...</h1></center>";
	document.getElementById("entry").innerHTML = "<br><br><br><center><img style='display:inline;padding-left: 10px; padding-right: 10px;' src='images/ajax-loader-jumbo.gif'><h1 style='display:inline;'>Searching For " + $('searchform').serialize(true)['q'] + "...</h1></center>";
	new Ajax.Updater("entry","searchAjax.php", {
		parameters: $('searchform').serialize(true)
	});
	return false;
}

function buyIt(thumbSrc, uid){
	itmwindow=dhtmlmodal.open('agebox', 'div', 'thumb_popup', 'Item Info', 'width=600px,height=300px,left=150px,top=100px,resize=0,scrolling=0');
	itmwindow.moveTo('middle','middle');
	
	new Ajax.Updater("thumb_src","ajax/buyitem.php?id="+thumbSrc+"&uid="+uid);
}

function boughtIt(id, uid){
	var box = document.getElementById("thumb_src");
	box.innerHTML = "<br><br><br><br><center><h1 style='color: #ffffff;'>Registering<br><img src='images/ajax-loader-jumbo.gif'><br>Purchase...</h1><br><br><br><br><br></center>";
	new Ajax.Updater("thumb_src","ajax/confirmItem.php?id="+id+"&uid="+uid);
}

function linkEdit(){
	var box = document.getElementById("faavContainer");
	for(i=0;i<box.childNodes.length;i++){
			
			//if(box.childNodes[i].style.display != 'none' && box.childNodes[i].style.visibility != 'hidden'){
				//handles all types of browsers this way

				if(box.childNodes[i].childNodes[1].className == 'itemCntr'){
					//IE
					new Ajax.InPlaceEditor(box.childNodes[i].childNodes[2],'ajax/nameEdit.php?id='+box.childNodes[i].childNodes[3].id, {
						okControl: "button",
						externalControlOnly: "true",
						externalControl: box.childNodes[i].childNodes[3].id,
						cancelControl: "button",
						savingText: "Saving Name...",
						clickToEditText: "Edit Item Name...",
						highlightcolor: "#2A416A",
						highlightendcolor: "#253C5E",
						rows: 2
					});
				}else{
					if(box.childNodes[i].childNodes[3].className == 'itemCntr'){
						//FIREFOX
						new Ajax.InPlaceEditor(box.childNodes[i].childNodes[5],'ajax/nameEdit.php?id='+box.childNodes[i].childNodes[7].id, {
							okControl: "button",
							externalControlOnly: "true",
							externalControl: box.childNodes[i].childNodes[7].id,
							cancelControl: "button",
							savingText: "Saving Name...",
							clickToEditText: "Edit Item Name...",
							highlightcolor: "#2A416A",
							highlightendcolor: "#253C5E",
							rows: 2
						});
					}
				}		
			//}
	}
}

function noteEdit(){
	var box = document.getElementById("faavContainer");
	for(i=0;i<box.childNodes.length;i++){
		
		//if(box.childNodes[i].style.display != 'none' && box.childNodes[i].style.visibility != 'hidden'){
			//handles all types of browsers this way

			if(box.childNodes[i].childNodes[1].className == 'itemCntr'){
				//IE
				new Ajax.InPlaceEditor(box.childNodes[i].childNodes[6],'ajax/noteEdit.php?id='+box.childNodes[i].childNodes[3].id, {
					okControl: "button",
					cancelControl: "button",
					savingText: "Saving Notes...",
					clickToEditText: "Add Some Notes...",
					highlightcolor: "#2A416A",
					highlightendcolor: "#253C5E",
					rows: 2,
					formClassName: "itmNoteEdit"
				});
			}else{
				if(box.childNodes[i].childNodes[3].className == 'itemCntr'){
					//FIREFOX
					new Ajax.InPlaceEditor(box.childNodes[i].childNodes[13],'ajax/noteEdit.php?id='+box.childNodes[i].childNodes[7].id, {
						okControl: "button",
						cancelControl: "button",
						savingText: "Saving Notes...",
						clickToEditText: "Add Some Notes...",
						highlightcolor: "#2A416A",
						highlightendcolor: "#253C5E",
						rows: 2,
						formClassName: "itmNoteEdit"
					});
				}
			}		
		//}
	}
}

function rmFriend(id){
	var answer=confirm("Are you sure you want to remove this friendship?\nTo add them back, you will have to initiate a new friend request...");
		if(answer){
			new Ajax.Request("ajax/friend.php", {
						method: "post",
						parameters: { frKey: id },
						onSuccess: function(transport){ 
							new Ajax.Updater("entry","ajax/friendList.php");
						}
			  		});
		}
}

function sendList(){
	new Ajax.Updater("shareBar","ajax/faavshare.php", {
		onComplete: function(){ Effect.SlideDown("shareBar"); }
	});
}

function sendListBox(){
	itmwindow=dhtmlmodal.open('agebox', 'div', 'thumb_popup', 'Item Info', 'width=600px,height=300px,left=150px,top=100px,resize=0,scrolling=0');
	itmwindow.moveTo('middle','middle');
	
	new Ajax.Updater("thumb_src","ajax/faavshareBox.php");
}

function confirmSend(){
	new Ajax.Request("ajax/faavsender.php", {
		method: "post",
		parameters: $('faavShare').serialize(true),
		onSuccess: function(transport){
			if(transport.responseText=='1'){ alert('List Sent Successfully!'); }else{ alert('Sorry, we had a problem sending the list.\nThe address you entered may not be a valid e-mail address.\nPlease try again later.'); }
			itmwindow.hide();
		},
		onFailure: function(){
			alert('Sorry, we had a problem sending the list.\nThe address you entered may not be a valid e-mail address.\nPlease try again later.');
			itmwindow.hide();
		}
	});
	
	return false;
}

function gotBar(id){
	//document.getElementById("entry").innerHTML="test";
	new Ajax.Updater("entry", "ajax/toolbar_process.php?id="+id);
}

function addFromSrch(id){
	var box = document.getElementById("prdStat_"+id);
	box.innerHTML = "Adding...";
	new Ajax.Updater(box,"ajax/addexisting.php?id="+id+"&src=search");
}

//***********************************
// LIST MANAGEMENT
//************************************
function addListBox(){
	itmwindow=dhtmlmodal.open('agebox', 'div', 'thumb_popup', 'Add New List', 'width=600px,height=300px,left=150px,top=100px,resize=0,scrolling=0');
	itmwindow.moveTo('middle','middle');
	
	new Ajax.Updater("thumb_src","ajax/addListBox.php");
}

function addList(){
	new Ajax.Request("ajax/newList.php", {
		method: "post",
		parameters: $('faavShare').serialize(true),
		onSuccess: function(transport){
			if(transport.responseText=='1'){ 
				new Ajax.Updater("listDiv","ajax/myLists.php");
			}else{ 
				alert(transport.responseText);
				//alert('Sorry, we had a problem sending the list.\nPlease try again later.'); 
			}
		},
		onFailure: function(){
			alert('Sorry, we had a problem adding the list.\nPlease try again later.');
		}
	});
	
	itmwindow.hide();
	return false;
}

function rmvList(lstID){
	if(lstID != undefined && lstID != null && lstID != 0){
		var answer=confirm("Are you sure you want to PERMANANTLY delete this list and all of it's contents?");
		if(answer){
			new Ajax.Request("ajax/rmvList.php?lst="+lstID, {
				onSuccess: function(){
					new Ajax.Updater("listDiv","ajax/myLists.php");
				},
				onFailure: function(){
					alert("Sorry, the list could not be deleted.\nPlease try again later.");
				}
			});
		}
	}
}

function togglePriv(lstID){
	if(lstID != undefined && lstID != null){
		if(lstID == 0){
			alert("Your Main list will always be public.\nCreate a new list if you want it to be private.");
		}else{
			new Ajax.Request("ajax/togglePriv.php?lst="+lstID, {
				onSuccess: function(){
					new Ajax.Updater("listDiv","ajax/myLists.php");
				}
			});
		}
	}
}

function moveItem(lstID, itmID){
	itmwindow=dhtmlmodal.open('agebox', 'div', 'thumb_popup', 'Move or Copy Item', 'width=600px,height=300px,left=150px,top=100px,resize=0,scrolling=0');
	itmwindow.moveTo('middle','middle');
	
	new Ajax.Updater("thumb_src","ajax/moveItemBox.php?lst="+lstID+"&itm="+itmID);
}

function moveList(){
	new Ajax.Request("ajax/moveList.php", {
		method: "post",
		parameters: $('faavMove').serialize(true),
		onSuccess: function(){alert('Item moved/copied successfully!');},
		onFailure: function(){alert('Sorry, we had a problem adding the list.\nPlease try again later.');}
	});
	
	itmwindow.hide();
	return false;
}

function switchFeed(feedID){
	switch(feedID){
	case 0:
		document.getElementById("feedTab0").style.backgroundColor = "white";
		document.getElementById("feedTab0").style.color = "black";
		document.getElementById("feedTab1").style.backgroundColor = "transparent";
		document.getElementById("feedTab1").style.color = "white";
		document.getElementById("feedTab2").style.backgroundColor = "transparent";
		document.getElementById("feedTab2").style.color = "white";
		break;

	case 1:
		document.getElementById("feedTab0").style.backgroundColor = "transparent";
		document.getElementById("feedTab0").style.color = "white";
		document.getElementById("feedTab1").style.backgroundColor = "white";
		document.getElementById("feedTab1").style.color = "black";
		document.getElementById("feedTab2").style.backgroundColor = "transparent";
		document.getElementById("feedTab2").style.color = "white";
		break;

	case 2:
		document.getElementById("feedTab0").style.backgroundColor = "transparent";
		document.getElementById("feedTab0").style.color = "white";
		document.getElementById("feedTab1").style.backgroundColor = "transparent";
		document.getElementById("feedTab1").style.color = "white";
		document.getElementById("feedTab2").style.backgroundColor = "white";
		document.getElementById("feedTab2").style.color = "black";
		break;
	}
	new Ajax.Updater("feedBox","itmFeeds.php?fdid=" + feedID);
}