/*
 * Qwoff Main JS and custom functions 
 * Copyright 2008 Qwoff Ltd
 * Author - Benjamin Dry  - ben@enpresiv.com
 * 
*/

	function getregions(objid){
		ajaxURL = "/ajax/regionSelect.cfm?countryId="+objid;
		new Ajax.Request(ajaxURL, {
			method: 'get',
			onSuccess: function (response) {
				parseAjaxRegionData(response.responseText.evalJSON());
			},
			onFailure: function (response) {
				 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
			}
		});
			
	}
	
	function parseAjaxRegionData(responseObj)
	{
		SHTML = responseObj.SHTML;
		document.getElementById("regionSelect").innerHTML = SHTML;	
	}
	
	


	function saveWishListData(wineid){
		var wishListNotes = document.getElementById("wishListNotes").value;
		ajaxURL =  "&Note="+wishListNotes+"&wineid="+wineid;
		ajaxURL = webroot+"/ajax/wishListDataSave.cfm?sRequest="+requestKey+ajaxURL;

		new Ajax.Request(ajaxURL, {
			method: 'get',
			onSuccess: function (response) {
				showSuccess("The wine has been added to your wishlist",wishlistPageId);	
				// do nothing;
			},
			onFailure: function (response) {
				 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
			}
		});					

		return false;
	}

	function leftColSearchFilter(filterBy){
		var formObj = document.leftColSearchForm;
		var currFilter = formObj.searchFilter.value;
		formObj.searchFilter.value = filterBy;
		formObj.searchStr.value = 'find a '+filterBy;
		var pageId = "";
		if(filterBy=="wine"){
			pageId = winePageId;
		} else if(filterBy=="winery"){
			pageId = wineryPageId;
		} else if(filterBy=="qwoffer"){
			pageId = communityPageId;
		}
		formObj.action="/index.cfm?objectId="+pageId+"&debug=1";
		if (document.getElementById("leftColFilterBy_"+currFilter))
			document.getElementById("leftColFilterBy_"+currFilter).className = "";
		if (document.getElementById("leftColFilterBy_"+currFilter))
			document.getElementById("leftColFilterBy_"+filterBy).className = "leftColFilterBySel";
	}

	function saveCellarData(wineid){
		var cellarQuantity = document.getElementById("cellarQuantity").value;
		var cellarlocation = document.getElementById("cellarLocation").value;
		var recommendedDrinkingStart = document.getElementById("cellarRecommendedDrinkingStart").value;
		var recommendedDrinkingEnd = document.getElementById("cellarRecommendedDrinkingEnd").value;
		var source = document.getElementById("cellarSource").value;
		var cellarNotes = document.getElementById("cellarCellarNotes").value;

		document.getElementById("addToCellar").style.display = "none";
		document.getElementById("addToCellarOff").style.display = "inline";

		ajaxURL =  "&cellarQuantity="+cellarQuantity+"&wineId="+wineid+"&cellarlocation="+cellarlocation+"&recommendedDrinkingStart="+recommendedDrinkingStart+"&recommendedDrinkingEnd="+recommendedDrinkingEnd+"&cellarsource="+source+"&cellarNotes="+cellarNotes;
		ajaxURL = webroot+"/ajax/cellarDataSave.cfm?sRequest="+requestKey+ajaxURL;

		new Ajax.Request(ajaxURL, {
			method: 'get',
			onSuccess: function (response) {
				showSuccess("The wine has been added to your cellar",cellarPageId);	
				// do nothing;
			},
			onFailure: function (response) {
				 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
			}
		});					

		return false;
	}

	function saveReviewData(wineid){
		var tastingtags = URLEncode(document.getElementById("tastingtags").value);
		var rating = document.getElementById("rating").value;
		var points = document.getElementById("points").value;
		var comments = URLEncode(document.getElementById("comments").value);
		ajaxParams=  "&points="+points+"&tastingtags="+tastingtags+"&wineId="+wineid+"&rating="+rating+"&comments="+comments;
		ajaxURL = webroot+"/ajax/reviewDataSave.cfm?sRequest="+requestKey;

		document.getElementById("addToReview").style.display = "none";
		document.getElementById("addToReviewOff").style.display = "inline";

		
		new Ajax.Request(ajaxURL, {
			method: 'post',
			parameters: ajaxParams,
			onSuccess: function (response) {
				showSuccess("The wine has been added to your reviews",reviewPageId);	
				// do nothing;
			},
			onFailure: function (response) {
				 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
			}
		});					

		return false;
	}

		
	function showSuccess(msg,redirectId){
		document.getElementById("lightBoxData").innerHTML = "<p>"+msg+"</p><p><br /><input onclick='myLightbox.end();showPost(\""+redirectId+"\");' type='image' src='"+webroot+"/wsimages/continueGeenBTN.gif' /></p>";	
	}
	
	function linebreak(obj){
		repStr = ",\n";		
		var newval = obj.value.replace(/\,/g, repStr);
		obj.value = newval.replace(/\,\n\n/g, repStr);
//		obj.value = newval;
//		obj.value = newval.replace(/findStr2/g, repStr);
	}
	
	function inviteFriend(clientId){
		var friendsList = document.getElementById("friendsList").value;
		var friendMessage = URLEncode(document.getElementById("friendMessage").value);
		
		aFriendsEmailAddresses = friendsList.split(",");
		if(aFriendsEmailAddresses.length > 25){
			
			errorHTML = "You can only enter a maximum of 25 friends at one time. Please remove "+(aFriendsEmailAddresses.length-25)+" addresses and try again. You can invite more people after inviting this list first.";
			document.getElementById("friendsList").className = "errorField";				
			document.getElementById("lbErrors").innerHTML = '<h2>just a few errors:</h2><ul>'+errorHTML+'</ul>';							

		} else {
		
			ajaxURL =  "&friendMessage="+friendMessage+"&friendsList="+friendsList;
			ajaxURL = webroot+"/ajax/inviteFriends.cfm?sRequest="+requestKey+ajaxURL;
	
			document.getElementById("addToFriends").style.display = "none";
			document.getElementById("addToFriendsOff").style.display = "inline";
	
			new Ajax.Request(ajaxURL, {
				method: 'get',
				onSuccess: function (response) {
					showSuccess("An invite has been sent to your friends");	
					// do nothing;
				},
				onFailure: function (response) {
					 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
				}
			});					
		}
		return false;
	}
	
	function showPost(redirectId){
		location.href= '/index.cfm?objectId='+redirectId+'&postReview=1';
	}

	function toggleReviewDetails(objId,wineid){
		if(document.getElementById('reviewDetails'+objId).style.display == "none"){
			document.getElementById('reviewDetails'+objId).style.display = "block";
			document.getElementById('detailsIcon'+objId).src = webroot+"/wsimages/smallBlueArrowBorderUp.gif";
			getReviews(objId,wineid);
		} else {
			document.getElementById('detailsIcon'+objId).src = webroot+"/wsimages/smallBlueArrowBorderDown.gif";
			document.getElementById('reviewDetails'+objId).style.display = "none";
		}
	}
		
	function orderBy(orderby,orderbydir){
		document.wineListForm.orderby.value = orderby;
		document.wineListForm.orderbydir.value = orderbydir;
		document.wineListForm.submit();
	}
	
	function changeMaxRows(maxRows){
		document.wineListForm.maxRows.value = maxRows;
		document.wineListForm.submit();
	}

			
	function createFilter(){
		var aFormFields = formFields.split(",");
		var filterData = "";
		for(i=0;i<aFormFields.length;i++){
			filterData = filterData+"&"+aFormFields[i]+"="+eval("document.wineListForm."+aFormFields[i]+".value");
		}
		if(document.wineFilter.inStock && document.wineFilter.inStock.length > 0){
			filterData = filterData+"&inStock="+document.wineFilter.inStock[1].checked;
		}
		return filterData;
	}

	function getReviewsByWine(page){
		

		document.getElementById("ajaxPagingLoader").style.visibility = "visible";
		ajaxURL = webroot+"/ajax/getReviews.cfm?sRequest="+sRequest2+"&currentPage="+page;
		document.wineListForm.maxRows.currentPage =	page;		
		new Ajax.Request(ajaxURL, {
			method: 'get',
			onSuccess: function (response) {
				parseAjaxContentRecs(response.responseText.evalJSON());
			},
			onFailure: function (response) {
				 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
			}
		});		
	}
	
	function getFeed(page){
		ajaxURL = webroot+"/ajax/feedList.cfm?&sRequest="+sFeedRequest+"&currentPage="+page;	
		new Ajax.Request(ajaxURL, {
			method: 'get',
			onSuccess: function (response) {
				parseAjaxFeed(response.responseText.evalJSON());
			},
			onFailure: function (response) {
				 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
			}
		});
		
	}

	function parseAjaxFeed(responseObj)
	{
		SHTML = responseObj.SHTML;
		SPAGINGHTML = responseObj.SPAGINGHTML;
		document.getElementById("infoListsPagingBottom").innerHTML = 	SPAGINGHTML;
		document.getElementById("infoListContentWrapper").innerHTML = 	SHTML;
	}
	
	function getWinesWineries(page)
	{			
		
		// define the url
		try{
			document.getElementById("ajaxPagingLoader").style.visibility = "visible";
		} catch(e){
			//nada
		}
		searchType = document.wineListForm.searchType.value;
		searchStr = document.wineListForm.searchStr.value;
		
		ajaxURL = webroot+"/ajax/wineWinerySearchList.cfm?searchStr="+searchStr+"&searchType="+searchType+"&sRequest="+sRequest+"&currentPage="+page+createFilter();
		document.wineListForm.maxRows.currentPage =	page;		
		new Ajax.Request(ajaxURL, {
			method: 'get',
			onSuccess: function (response) {
				parseAjaxContentWineSearch(response.responseText.evalJSON());
			},
			onFailure: function (response) {
				 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
			}
		});
		
	}

	function parseAjaxContentWineSearch(responseObj)
	{

		SHTML = responseObj.SHTML;
		SPAGINGHTML = responseObj.SPAGINGHTML;
		SVIEWING = responseObj.SVIEWING;
		STOTALRECSHTML = responseObj.STOTALRECSHTML;

		document.getElementById("wineListsPagingTop").innerHTML = 	SPAGINGHTML;
		document.getElementById("wineListsPagingBottom").innerHTML = 	SPAGINGHTML;
		document.getElementById("wineListsContentWrapper").innerHTML = 	SHTML;
		document.getElementById("wineListscurrentPage").innerHTML = 	SVIEWING;
		document.getElementById("wineListsTotals").innerHTML = 	STOTALRECSHTML;	
	}
	
	function toggleFriendsList(recommendationID){
		if(document.getElementById('extraFriends_'+recommendationID).style.display == "none"){
			document.getElementById('contractedFriends_'+recommendationID).style.display = "none";
			document.getElementById('extraFriends_'+recommendationID).style.display = "block";
		} else {
			document.getElementById('contractedFriends_'+recommendationID).style.display = "block";
			document.getElementById('extraFriends_'+recommendationID).style.display = "none";
		}
	}

	function orderBy(orderby,orderbydir){
		document.wineListForm.orderby.value = orderby;
		document.wineListForm.orderbydir.value = orderbydir;
		document.wineListForm.submit();
	}
	
	function changeMaxRows(maxRows){
		document.wineListForm.maxRows.value = maxRows;
		document.wineListForm.submit();
	}

	function changeView(view){
		document.wineListForm.view.value = view;
		document.wineListForm.submit();
	}
	
	function toggleRecDetails(recommendationID,friendID,qwoffWineId){
		if(document.getElementById('reviewDetails'+recommendationID).style.display == "none"){
			document.getElementById('reviewDetails'+recommendationID).style.display = "block";
			document.getElementById('detailsIcon'+recommendationID).src = webroot+"/wsimages/smallBlueArrowBorderUp.gif";
			getRecs(recommendationID,friendID,qwoffWineId);
		} else {
			document.getElementById('detailsIcon'+recommendationID).src = webroot+"/wsimages/smallBlueArrowBorderDown.gif";
			document.getElementById('reviewDetails'+recommendationID).style.display = "none";
		}
	}

	function getRecs(recommendationID,friendID,qwoffWineId)
	{			
		// define the url

		ajaxURL = webroot+"/ajax/wineRecommendationData.cfm?sRequest="+sRequest+"&recommendationID="+recommendationID+"&friendID="+friendID+"&wineId="+qwoffWineId;

		new Ajax.Request(ajaxURL, {
			method: 'get',
			onSuccess: function (response) {
				parseAjaxRecContent(response.responseText.evalJSON());
			},
			onFailure: function (response) {
				 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
			}
		});
		
	}

	function parseAjaxRecContent(responseObj)
	{

		RECOMMENDATIONID = responseObj.RECOMMENDATIONID;
		DETAILSHTML = responseObj.DETAILSHTML;

		document.getElementById("reviewDetails"+RECOMMENDATIONID).innerHTML = 	DETAILSHTML;
		
	}

	function getInboxMessages(page)
	{			
		// define the url
		document.getElementById("ajaxPagingLoader").style.visibility = "visible";
		ajaxURL = webroot+"/ajax/messages.cfm?sRequest="+sRequest+"&currentPage="+page;
		document.wineListForm.maxRows.currentPage =	page;		
		new Ajax.Request(ajaxURL, {
			method: 'get',
			onSuccess: function (response) {
				parseAjaxMessageData(response.responseText.evalJSON());
			},
			onFailure: function (response) {
				 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
			}
		});
		
	}
	
	function parseAjaxMessageData(responseObj)
	{

		SHTML = responseObj.SHTML;
		SPAGINGHTML = responseObj.SPAGINGHTML;
		SVIEWING = responseObj.SVIEWING;
		
		
		document.getElementById("infoListContentWrapper").innerHTML = 	SHTML;

		document.getElementById("wineListsPagingTop").innerHTML = 	SPAGINGHTML;
		document.getElementById("wineListsPagingBottom").innerHTML = 	SPAGINGHTML;
		document.getElementById("wineListscurrentPage").innerHTML = 	SVIEWING;
	}

	function getInboxMessagesView(page)
	{			
		// define the url
		document.getElementById("ajaxPagingLoader").style.visibility = "visible";
		ajaxURL = webroot+"/ajax/messagesView.cfm?sRequest="+sRequest+"&currentPage="+page;
		document.wineListForm.maxRows.currentPage =	page;		
		new Ajax.Request(ajaxURL, {
			method: 'get',
			onSuccess: function (response) {
				parseAjaxMessageViewData(response.responseText.evalJSON());
			},
			onFailure: function (response) {
				 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
			}
		});
		
	}
	
	function parseAjaxMessageViewData(responseObj)
	{

		SHTML = responseObj.SHTML;
		SPAGINGHTML = responseObj.SPAGINGHTML;
		SVIEWING = responseObj.SVIEWING;
		SRECIPIENTS = responseObj.SRECIPIENTS;
		SREPLYMESSAGEID = responseObj.SREPLYMESSAGEID;
		SSUBJECT = responseObj.SSUBJECT;
//		alert(SREPLYMESSAGEID);
		
		document.getElementById("infoListContentWrapper").innerHTML = 	SHTML;
		document.getElementById("wineListsTotals").innerHTML = 	SRECIPIENTS;
		
		document.getElementById("wineListsPagingTop").innerHTML = 	SPAGINGHTML;
		document.getElementById("wineListsPagingBottom").innerHTML = 	SPAGINGHTML;
		document.getElementById("messageSubject").innerHTML = 	SSUBJECT;
		document.getElementById("replymessageId").value = 	SREPLYMESSAGEID;
		
	}

	
	function getRecWines(page)
	{			
		// define the url
		document.getElementById("ajaxPagingLoader").style.visibility = "visible";
		ajaxURL = webroot+"/ajax/wineRecommendations.cfm?sRequest="+sRequest2+"&currentPage="+page;
		document.wineListForm.maxRows.currentPage =	page;		
		new Ajax.Request(ajaxURL, {
			method: 'get',
			onSuccess: function (response) {
				parseAjaxContentRecs(response.responseText.evalJSON());
			},
			onFailure: function (response) {
				 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
			}
		});
		
	}
	
	function parseAjaxContentRecs(responseObj)
	{

		SHTML = responseObj.SHTML;
		SPAGINGHTML = responseObj.SPAGINGHTML;
		SVIEWING = responseObj.SVIEWING;

		document.getElementById("wineListsPagingTop").innerHTML = 	SPAGINGHTML;
		document.getElementById("wineListsPagingBottom").innerHTML = 	SPAGINGHTML;
		document.getElementById("wineListsContentWrapper").innerHTML = 	SHTML;
		document.getElementById("wineListscurrentPage").innerHTML = 	SVIEWING;
	}

	
	function showReviewDetails(objid,reviewNo,reviewCnt){
		for(i=0;i<reviewCnt;i++){
			document.getElementById("reviewText_"+(i+1)+"_"+objid).style.display = "none";				
			document.getElementById("reviewLink_"+(i+1)+"_"+objid).className = "reviewLinkOff";				
		}
		document.getElementById("reviewText_"+reviewNo+"_"+objid).style.display = "block";	
		document.getElementById("reviewLink_"+reviewNo+"_"+objid).className = "reviewLinkOn";				
	}
	
	function deleteRecommendation(){
		
	}

	function getReviews(objId,wineId)
	{			
		// define the url

		ajaxURL = webroot+"/ajax/wineReviewData.cfm?requestKey="+requestKey+"&sRequest="+sRequest+"&wineId="+wineId+"&objectid="+objId;

		
		new Ajax.Request(ajaxURL, {
			method: 'get',
			onSuccess: function (response) {
				parseAjaxReviewContent(response.responseText.evalJSON());
			},
			onFailure: function (response) {
				 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
			}
		});
		
	}

	function parseAjaxReviewContent(responseObj)
	{

		OBJECTID = responseObj.OBJECTID;
		DETAILSHTML = responseObj.DETAILSHTML;

		document.getElementById("reviewDetails"+OBJECTID).innerHTML = 	DETAILSHTML;
		
	}

	function getWineReviews(page)
	{			
		// define the url
		document.getElementById("ajaxPagingLoader").style.visibility = "visible";
		ajaxURL = webroot+"/ajax/wineList.cfm?sRequest="+sRequest2+"&currentPage="+page;
		document.wineListForm.maxRows.currentPage =	page;		
		new Ajax.Request(ajaxURL, {
			method: 'get',
			onSuccess: function (response) {
				parseAjaxContent(response.responseText.evalJSON());
			},
			onFailure: function (response) {
				 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
			}
		});
		
	}

	function parseAjaxContent(responseObj)
	{

		SHTML = responseObj.SHTML;
		SPAGINGHTML = responseObj.SPAGINGHTML;
		SVIEWING = responseObj.SVIEWING;

		document.getElementById("wineListsPagingTop").innerHTML = 	SPAGINGHTML;
		document.getElementById("wineListsPagingBottom").innerHTML = 	SPAGINGHTML;
		document.getElementById("wineListsContentWrapper").innerHTML = 	SHTML;
		document.getElementById("wineListscurrentPage").innerHTML = 	SVIEWING;
		
	}
				
	
	function showReviewDetails(objid,reviewNo,reviewCnt){
		for(i=0;i<reviewCnt;i++){
			document.getElementById("reviewText_"+(i+1)+"_"+objid).style.display = "none";				
			document.getElementById("reviewLink_"+(i+1)+"_"+objid).className = "reviewLinkOff";				
		}
		document.getElementById("reviewText_"+reviewNo+"_"+objid).style.display = "block";	
		document.getElementById("reviewLink_"+reviewNo+"_"+objid).className = "reviewLinkOn";				
	}

	function toggleWishListDetails(objId,wineid){
		if(document.getElementById('reviewDetails'+objId).style.display == "none"){
			document.getElementById('reviewDetails'+objId).style.display = "block";
			document.getElementById('detailsIcon'+objId).src = webroot+"/wsimages/smallBlueArrowBorderUp.gif";
			getNotes(objId,wineid);
		} else {
			document.getElementById('detailsIcon'+objId).src = webroot+"/wsimages/smallBlueArrowBorderDown.gif";
			document.getElementById('reviewDetails'+objId).style.display = "none";
		}
	}

	function getNotes(objId,wineId)
	{			
		// define the url

		ajaxURL = webroot+"/ajax/wineWishListData.cfm?sRequest="+sRequest+"&wineId="+wineId+"&objectid="+objId;

		new Ajax.Request(ajaxURL, {
			method: 'get',
			onSuccess: function (response) {
				parseAjaxWishListContentData(response.responseText.evalJSON());
			},
			onFailure: function (response) {
				 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
			}
		});
		
	}

	function parseAjaxWishListContentData(responseObj)
	{

		OBJECTID = responseObj.OBJECTID;
		DETAILSHTML = responseObj.DETAILSHTML;

		document.getElementById("reviewDetails"+OBJECTID).innerHTML = 	DETAILSHTML;
		
	}
			
	function getWishList(page)
	{			
		// define the url
		document.getElementById("ajaxPagingLoader").style.visibility = "visible";
		ajaxURL = webroot+"/ajax/wineWishList.cfm?sRequest="+sRequest2+"&currentPage="+page;
		document.wineListForm.maxRows.currentPage =	page;		
		new Ajax.Request(ajaxURL, {
			method: 'get',
			onSuccess: function (response) {
				parseAjaxWishListContent(response.responseText.evalJSON());
			},
			onFailure: function (response) {
				 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
			}
		});
		
	}

	function parseAjaxWishListContent(responseObj)
	{

		SHTML = responseObj.SHTML;
		SPAGINGHTML = responseObj.SPAGINGHTML;
		SVIEWING = responseObj.SVIEWING;

		document.getElementById("wineListsPagingTop").innerHTML = 	SPAGINGHTML;
		document.getElementById("wineListsPagingBottom").innerHTML = 	SPAGINGHTML;
		document.getElementById("wineListsContentWrapper").innerHTML = 	SHTML;
		document.getElementById("wineListscurrentPage").innerHTML = 	SVIEWING;
		
	}	
	
	function toggleEditCellarDetails(objId){
		if(document.getElementById('cellarData_'+objId).style.display == "none"){
			document.getElementById('cellarData_'+objId).style.display = "block";		
			document.getElementById('cellarDataFormContainer_'+objId).style.display = "none";		
		} else {
			document.getElementById('cellarData_'+objId).style.display = "none";		
			document.getElementById('cellarDataFormContainer_'+objId).style.display = "block";
		}
		
	}
	
	function toggleEditReviewDetails(objId){
		if(document.getElementById('reviewText_'+objId).style.display == "none"){
			document.getElementById('reviewText_'+objId).style.display = "block";		
			document.getElementById('reviewTextFormContainer_'+objId).style.display = "none";		
		} else {
			document.getElementById('reviewText_'+objId).style.display = "none";		
			document.getElementById('reviewTextFormContainer_'+objId).style.display = "block";
		}
		
	}

	function toggleCellarDetails(objId,wineid){
		if(document.getElementById('cellarDetails'+objId).style.display == "none"){
			document.getElementById('cellarDetails'+objId).style.display = "block";
			document.getElementById('detailsIcon'+objId).src = webroot+"/wsimages/smallBlueArrowBorderUp.gif";
			getCellarData(objId,wineid);
		} else {
			document.getElementById('detailsIcon'+objId).src = webroot+"/wsimages/smallBlueArrowBorderDown.gif";
			document.getElementById('cellarDetails'+objId).style.display = "none";
		}
	}
	
	function getCellarData(objId,wineId)
	{			
		// define the url

		ajaxURL = webroot+"/ajax/wineCellarData.cfm?sRequest="+sRequest+"&wineId="+wineId+"&objectid="+objId;

		new Ajax.Request(ajaxURL, {
			method: 'get',
			onSuccess: function (response) {
				parseAjaxCellarDataContent(response.responseText.evalJSON());
			},
			onFailure: function (response) {
				 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
			}
		});
		
	}

	function parseAjaxCellarDataContent(responseObj)
	{

		OBJECTID = responseObj.OBJECTID;
		DETAILSHTML = responseObj.DETAILSHTML;

		document.getElementById("cellarDetails"+OBJECTID).innerHTML = 	DETAILSHTML;
		
	}

	function getCellarList(page)
	{			
		// define the url
		document.getElementById("ajaxPagingLoader").style.visibility = "visible";
		ajaxURL = webroot+"/ajax/wineCellar.cfm?sRequest="+sRequest2+"&currentPage="+page;
		document.wineListForm.maxRows.currentPage =	page;		
		new Ajax.Request(ajaxURL, {
			method: 'get',
			onSuccess: function (response) {
				parseAjaxCellarContent(response.responseText.evalJSON());
			},
			onFailure: function (response) {
				 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
			}
		});
		
	}

	function parseAjaxCellarContent(responseObj)
	{

		SHTML = responseObj.SHTML;
		SPAGINGHTML = responseObj.SPAGINGHTML;
		SVIEWING = responseObj.SVIEWING;

		document.getElementById("wineListsPagingTop").innerHTML = 	SPAGINGHTML;
		document.getElementById("wineListsPagingBottom").innerHTML = 	SPAGINGHTML;
		document.getElementById("wineListsContentWrapper").innerHTML = 	SHTML;
		document.getElementById("wineListscurrentPage").innerHTML = 	SVIEWING;
		
	}
	
	var inventoryUpdateChk = 0;
	function updateInventory(objid){
		newVal = document.getElementById("cellarQuantity_"+objid).value;
		if(inventoryUpdateChk == 0){
			inventoryUpdateChk = 1;
			if(IsNumeric(newVal,"Quantity must be numeric")){
				document.getElementById("updateQuantity_"+objid).style.visibility = "visible";	
				ajaxURL = webroot+"/ajax/cellarInventory.cfm?sRequest="+sRequest+"&objid="+objid+"&quantity="+newVal;
				new Ajax.Request(ajaxURL, {
					method: 'get',
					onSuccess: function (response) {
						document.getElementById("updateQuantity_"+objid).style.visibility = "hidden";
						// do nothing;
					},
					onFailure: function (response) {
						 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
					}
				});					
			}
		}
		inventoryUpdateChk = 0;
		return false;
	}
	
	function updateCellarData(objid,wineid){
		cellarlocation = document.getElementById("location_"+objid).value;
		recommendedDrinkingStart = document.getElementById("recommendedDrinkingStart_"+objid).value;
		recommendedDrinkingEnd = document.getElementById("recommendedDrinkingEnd_"+objid).value;
		source = document.getElementById("source_"+objid).value;
		cellarNotes = document.getElementById("cellarNotes_"+objid).value;
		ajaxURL = "&cellarlocation="+cellarlocation+"&recommendedDrinkingStart="+recommendedDrinkingStart+"&recommendedDrinkingEnd="+recommendedDrinkingEnd+"&cellarsource="+source+"&cellarNotes="+cellarNotes+"&objid="+objid;
		ajaxURL = webroot+"/ajax/cellarDataUpdate.cfm?sRequest="+sRequest+ajaxURL;

		new Ajax.Request(ajaxURL, {
			method: 'get',
			onSuccess: function (response) {
				getCellarData(objid,wineid);	
//					toggleEditCellarDetails(objId);
				// do nothing;
			},
			onFailure: function (response) {
				 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
			}
		});					

		return false;
	}		
	
	function updateReviewData(objid,textareaid,wineid,reviewsId,clientId,divid){
		
		document.getElementById("editReviewOff_"+textareaid).style.display = "inline";
		document.getElementById("editReviewOn_"+textareaid).style.display = "none";
		
		reviewNotes = URLEncode(document.getElementById("reviewText_"+textareaid).value);
		reviewRating = URLEncode(document.getElementById("rating_"+textareaid).value);
		reviewPoints = URLEncode(document.getElementById("points_"+textareaid).value);

		ajaxURL = "&reviewNotes="+reviewNotes+"&reviewId="+objid+"&clientId="+clientId+"&reviewRating="+reviewRating+"&reviewPoints="+reviewPoints;
		ajaxURL = webroot+"/ajax/reviewDataUpdate.cfm?sRequest="+requestKey+ajaxURL;

		new Ajax.Request(ajaxURL, {
			method: 'get',
			onSuccess: function (response) {
			parseAjaxReviewEditData(response.responseText.evalJSON(),reviewsId,wineid,divid);

			//				getCellarData(objid,wineid);	
//					toggleEditCellarDetails(objId);
				// do nothing;
			},
			onFailure: function (response) {
				 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
			}
		});					

		return false;
	}		
	
	function parseAjaxReviewEditData(responseObj,reviewsId,wineid,divid)
	{

		SPOINTS = responseObj.SPOINTS;
		SRATING = responseObj.SRATING;

		document.getElementById("rating_"+divid).innerHTML = 	SRATING;
		document.getElementById("points_"+divid).innerHTML = 	SPOINTS;
		
		getReviews(reviewsId,wineid);
	}

	
	function IsNumeric(sText,ErrMsgToDsply)

	{
	   var ValidChars = "0123456789.";
	   var IsNumber=true;
	   var Char;

	 
	   for (i = 0; i < sText.length && IsNumber == true; i++) 
	      { 
	      Char = sText.charAt(i); 
	      if (ValidChars.indexOf(Char) == -1) 
	         {
	         IsNumber = false;
	         }
	      }
	   
	   if(!IsNumber && ErrMsgToDsply.length > 0){
		   alert(ErrMsgToDsply);
	   }
	   
	   return IsNumber;
	   
	   }
	

	function toggleEditStatus(){
		if(document.getElementById('profileStatusText').style.display == "none"){
			document.getElementById('profileStatusText').style.display = "block";		
			document.getElementById('profileStatusFormContainer').style.display = "none";		
		} else {
			document.getElementById('profileStatusText').style.display = "none";		
			document.getElementById('profileStatusFormContainer').style.display = "block";
			document.getElementById("statusText").focus();
		}
		
	}
	
	var statusUpdateChk = 0;
	function updateStatus(objid){
		newVal = document.getElementById("statusText").value;
		if(statusUpdateChk == 0){
			statusUpdateChk = 1;
		
			document.getElementById("updateStatus").style.visibility = "visible";	
			ajaxURL = webroot+"/ajax/statusUpdate.cfm?sRequest="+sStatusRequest+"&status="+newVal;
			new Ajax.Request(ajaxURL, {
				method: 'get',
				onSuccess: function (response) {
					document.getElementById("updateStatus").style.visibility = "hidden";	
					document.getElementById("profileStatusTextContainer").innerHTML = newVal;
					toggleEditStatus();	
					
					// do nothing;
				},
				onFailure: function (response) {
					 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
				}
			});					
		}
		statusUpdateChk = 0;
		return false;
	}
	
	function delCellarData(wineId){
		ajaxURL = webroot+"/ajax/deleteFromCellar.cfm?sRequest="+sRequest+"&wineid="+wineId;
		new Ajax.Request(ajaxURL, {
			method: 'get',
			onSuccess: function (response) {
				myLightbox.end();
				getCellarList(document.wineListForm.currentPage.value);				
			},
			onFailure: function (response) {
				 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
			}
		});					
	}	

	function delWishListData(wineId){
		ajaxURL = webroot+"/ajax/deleteFromWishList.cfm?sRequest="+sRequest+"&wineid="+wineId;
		new Ajax.Request(ajaxURL, {
			method: 'get',
			onSuccess: function (response) {
				myLightbox.end();
				getWishList(document.wineListForm.currentPage.value);				
			},
			onFailure: function (response) {
				 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
			}
		});					
	}	
	
	function buildFilterData(){
		var aFormFields = formFields.split(",");
		for(i=0;i<aFormFields.length;i++){
		//	alert(aFormFields[i]+" - "+eval("document.wineFilter."+aFormFields[i]))
			if(eval("document.wineFilter."+aFormFields[i])){
				var fieldsLen = eval("document.wineFilter."+aFormFields[i]+".length");
				var fieldData = '';
				if(fieldsLen>1){
					for(j=0;j<fieldsLen;j++){
						if(j>0){
							fieldData = fieldData+',';
						}
						fieldVal = eval("document.wineFilter."+aFormFields[i]+"["+j+"].value");
						if(fieldVal!='undefined'){
							fieldData = fieldData+fieldVal;
						}
					}				
				} else {
					fieldVal = eval("document.wineFilter."+aFormFields[i]+".value");	
					if(fieldVal!='undefined'){
						fieldData = fieldVal;
					}
				}
				eval("document.wineListForm."+aFormFields[i]+".value = fieldData");
			} else {
				eval("document.wineListForm."+aFormFields[i]+".value = ''");			
			}
		}
		 getWinesWineries(1);
	}
	
	
	function openFilter(filterNo,datatype){
		var posTop = document.getElementById("searchFilterItemWrapper"+filterNo).offsetTop;
		if(document.all){
			posTop = posTop - 187; // ie offset
			document.getElementById("filterPanel"+filterNo).style.marginTop = posTop+"px";
		}else{
			document.getElementById("filterPanel"+filterNo).style.top = posTop+"px";		
		}
		
		$j(".filterPanel").css("display","none");
		$j("#filterPanel"+filterNo).animate({"width": "toggle"}, { duration: "normal" });
		
		filterLoaded = $j('#filterPanelScroll'+filterNo).children(".filterLoad");
		
		if(filterLoaded.length>0 && datatype!= 'region'){
			lAlreadySelectedItems = eval("document.wineListForm.l"+datatype+".value");
			populateFilterData(filterNo,lAlreadySelectedItems,datatype);
		}
	}
	
	function populateFilterData(filterNo,lAlreadySelectedItems,datatype){			
		// define the url
		
		ajaxURL = "/ajax/qwoffBrowserData.cfm?datatype="+datatype+"&filterNo="+filterNo+"&lAlreadySelectedItems="+lAlreadySelectedItems;	
		new Ajax.Request(ajaxURL, {
			method: 'get',
			onSuccess: function (response) {
				parseFilterData(response.responseText.evalJSON(),filterNo);
			},
			onFailure: function (response) {
				 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
			}
		});
		
	}	
	
	function parseFilterData(responseObj,filterNo)
	{
		SHTML = responseObj.SHTML;
		document.getElementById('filterPanelScroll'+filterNo).innerHTML = 	SHTML;			
	}	
	
	
	function openRegionFilter(countryNo,panelNo){
	
		var posTop = document.getElementById("filterPanelItem_"+panelNo+"_"+countryNo).offsetTop;
		posTop = posTop + 195; // ie offset
		if(document.all){
			posTop = posTop - 187; // ie offset
			document.getElementById("filterPanel"+panelNo+"_"+countryNo).style.marginTop = posTop+"px";
		}else{
			document.getElementById("filterPanel"+panelNo+"_"+countryNo).style.top = posTop+"px";		
		}
		
		$j(".filterPanel2").css("display","none");
		$j("#filterPanel"+panelNo+"_"+countryNo).animate({"width": "toggle"}, { duration: "normal" });
	}
	
	function resetFilter(filterNo,filterItemCnt){
		for(i=0;i<filterItemCnt;i++){
			document.getElementById("filterPanelItem_"+filterNo+"_"+(i+1)).style.display = 'block';		
		}
		document.getElementById("searchFiltersApplied"+filterNo).innerHTML = '';
		buildFilterData();
	}
	
	
	function delCountryFilter(filterNo,filterItemNo){
	//	alert("#filterPanel"+filterNo+"_"+filterItemNo);
		
		$j("#filterRegion_"+filterItemNo+" .filterPanelRegionWrapper").css({ display : "block" });	
	//	alert("#filterPanel"+filterNo+"_"+filterItemNo+"  -  "+$j("#filterPanel"+filterNo).css("display"));
		if($j("#filterPanel"+filterNo+"_"+filterItemNo).css("display")=='block'){
			closeFilter(filterNo+'_'+filterItemNo);
		}
		delFilter(filterNo,filterItemNo);
	}
	
	function delFilter(filterNo,filterItemNo){
		document.getElementById("filterPanelItem_"+filterNo+"_"+filterItemNo).style.display = 'block';		
		var child = document.getElementById("filterItemSelected_"+filterNo+"_"+filterItemNo);
		var parent = document.getElementById("searchFiltersApplied"+filterNo);
		child.getElementsByTagName("input")[0].value = '';
		parent.removeChild(child);
		buildFilterData();
	}
	
	function delRegionFilter(filterNo,filterItemNo){
		//alert("filterPanelItem_"+filterNo+"_"+filterItemNo);
		try{
			document.getElementById("filterPanelItem_"+filterNo+"_"+filterItemNo).style.display = 'block';
		} catch(e){
			//nada
		}
		var child = document.getElementById("filterItemSelected_"+filterNo+"_"+filterItemNo);
		var parent = document.getElementById("country_"+filterNo);
		child.getElementsByTagName("input")[0].value = '';
		parent.removeChild(child);
		buildFilterData();
	}
	
	function selectFilter(filterName,filterNo,filterItemNo,label,data){	
		sHTML = drawFilterHTML(filterNo,filterItemNo,label,filterName,data);
		sHTML = document.getElementById("searchFiltersApplied"+filterNo).innerHTML+sHTML;
		document.getElementById("filterPanelItem_"+filterNo+"_"+filterItemNo).style.display = 'none';
		document.getElementById("searchFiltersApplied"+filterNo).innerHTML = sHTML;
		buildFilterData();
	}
	
	function addRegion(filterName,filterNo,filterItemNo,label,data){	
		sHTML = drawRegionHTML(filterNo,filterItemNo,label,filterName,data);
		//alert(label);
		document.getElementById("country_"+filterNo).innerHTML = document.getElementById("country_"+filterNo).innerHTML+sHTML;
		document.getElementById("filterPanelItem_"+filterNo+"_"+filterItemNo).style.display = 'none';
		buildFilterData();
	}
	
	function drawRegionHTML(filterNo,filterItemNo,label,filterName,data){
		sHTML = '<div id="filterItemSelected_'+filterNo+'_'+filterItemNo+'" class="filterItemRegionSelected"><div class="filterItemSelectedDel">';
		sHTML = sHTML+'<a class="delFilter" href="javascript:delRegionFilter(\''+filterNo+'\','+filterItemNo+')">';
		sHTML = sHTML+'<img src="'+webroot+'/wsimages/closeWindowCross.gif" alt="close filter"/></a></div>';
		sHTML = sHTML+'<div class="filterItemSelectedLabel">'+label.substring(0,17)+'</div>';
		sHTML = sHTML+'<input type="hidden" name="lsubregion" value="'+data+'" /><div class="clear"></div>';
		sHTML = sHTML+'</div>';		
		return sHTML;		
	}
	
	
	function selectCountry(filterName,filterNo,filterItemNo,label,data){
		var sHTML;
		if(!document.getElementById("filterItemSelected_"+filterNo+"_"+filterItemNo)){
			sHTML = document.getElementById("searchFiltersApplied"+filterNo).innerHTML+drawFilterHTML(filterNo,filterItemNo,label,filterName,data);	
			document.getElementById("searchFiltersApplied"+filterNo).innerHTML = sHTML;
		}
		buildFilterData();
	}
	
	function drawFilterHTML(filterNo,filterItemNo,label,filterName,data){
		sHTML = '<div id="filterItemSelected_'+filterNo+'_'+filterItemNo+'" class="filterItemSelected"><div class="filterItemSelectedDel">';
		if(filterName=='country'){
			sHTML = sHTML+'<a class="delFilter" href="javascript:delCountryFilter('+filterNo+','+filterItemNo+')">';
		} else {
			sHTML = sHTML+'<a class="delFilter" href="javascript:delFilter('+filterNo+','+filterItemNo+')">';	
		}
		sHTML = sHTML+'<img src="'+webroot+'/wsimages/closeWindowCross.gif" alt="close filter"/></a></div>';
		sHTML = sHTML+'<div class="filterItemSelectedLabel">'+label.substring(0,17)+'</div>';
		sHTML = sHTML+'<input type="hidden" name="l'+filterName+'" value="'+data+'" /><div class="clear"></div>';
		if(filterName=='country'){
			sHTML = sHTML+'<div id="country_'+filterNo+'_'+filterItemNo+'"></div>';
		}
		sHTML = sHTML+'</div>';		
		return sHTML;		
	}
	
	function closeFilter(obj){
		filterNo = $j(obj).attr("filterNo");
		$j("#filterPanel"+filterNo).animate({"width": "toggle"}, { duration: "normal" });
	}
	
	function filterPanelRegionData(obj){
		filterName = $j(obj).attr("filterName");
		filterNo = $j(obj).attr("filterNo");
		filterItemNo = $j(obj).attr("filterItemNo");
		label = $j(obj).attr("label");
		data = $j(obj).attr("data");
		addRegion(filterName,filterNo,filterItemNo,label,data);
//		selectCountry(filterName,filterNo,filterItemNo,label,data);
	}
	
	function filterPanelCountryData(obj){
		filterName = $j(obj).attr("filterName");
		filterNo = $j(obj).attr("filterNo");
		filterItemNo = $j(obj).attr("filterItemNo");
		label = $j(obj).attr("label");
		data = $j(obj).attr("data");
		filterLoaded = $j('#filterRegion_'+filterItemNo).children(".filterLoad");
		if(filterLoaded.length>0){
			lAlreadySelectedItems = document.wineListForm.lsubregion.value;
			populateRegionFilterData(filterItemNo,data,lAlreadySelectedItems);
		}
		selectCountry(filterName,filterNo,filterItemNo,label,data);
	}
	
	function populateRegionFilterData(filterItemNo,data,lAlreadySelectedItems){			
		// define the url
		
		ajaxURL = "/ajax/qwoffRegionsAjax.cfm?regionNo="+filterItemNo+"&countryId="+data+"&lAlreadySelectedItems="+lAlreadySelectedItems;	
		new Ajax.Request(ajaxURL, {
			method: 'get',
			onSuccess: function (response) {
				parseRegionFilterData(response.responseText.evalJSON(),filterItemNo);
			},
			onFailure: function (response) {
				 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
			}
		});
		
	}	
	
	function parseRegionFilterData(responseObj,filterItemNo)
	{
		SHTML = responseObj.SHTML;
		
		document.getElementById('filterRegion_'+filterItemNo).innerHTML = 	SHTML;			
	}	

	
	
	function filterPanelItemData(obj){
		filterName = $j(obj).attr("filterName");
		filterNo = $j(obj).attr("filterNo");
		filterItemNo = $j(obj).attr("filterItemNo");
		label = $j(obj).attr("label");
		data = $j(obj).attr("data");
		selectFilter(filterName,filterNo,filterItemNo,label,data);
	}
	
	function filterTerms(obj){
		filterNo = $j(obj).attr("filterNo");
		termsLen = $j(obj).attr("termsLen");
		termsFilter(obj, filterNo, termsLen);
	}
	
	function filterTermsFocus(obj){
		if(obj.value=='start typing or scroll down')
    	{
			obj.value=''
    	}
 	}	
	
	
	function termsFilter (phrase, filterNo, termsLen){
		var words = phrase.value.toLowerCase().split(" ");
 		var ele;
 		for (var r = 0; r < (termsLen); r++){
			ele = document.getElementById("filterPanelItem_"+filterNo+"_"+(r+1)).innerHTML.replace(/<[^>]+>/g,"");
			//alert(ele);
			var displayStyle = 'none';
			for (var i = 0; i < words.length; i++) {
				if (ele.toLowerCase().indexOf(words[i])>=0)
					displayStyle = '';
				else {
					displayStyle = 'none';
					break;
				}
			}
			document.getElementById("filterPanelItem_"+filterNo+"_"+(r+1)).style.display = displayStyle;
		}
	}

	
	aRatingData = new Array(1);
	
	aRatingData[1] = new Array(1);
	aRatingData[1][1] = 50;
	aRatingData[1][2] = 54;
	aRatingData[1][3] = "I truly regret having ever tasted this wine. Avoid skin contact.";

	aRatingData[2] = new Array(1);
	aRatingData[2][1] = 55;
	aRatingData[2][2] = 59;
	aRatingData[2][3] = "Unacceptable. Offensive. I've tasted better dishwater.";

	aRatingData[3] = new Array(1);
	aRatingData[3][1] = 60;
	aRatingData[3][2] = 64;
	aRatingData[3][3] = "Getting pretty crap here. Drinkable but only if you are desperate.";

	aRatingData[4] = new Array(1);
	aRatingData[4][1] = 65;
	aRatingData[4][2] = 69;
	aRatingData[4][3] = "Below average wine. Something's just not quite right about it.";

	aRatingData[5] = new Array(1);
	aRatingData[5][1] = 70;
	aRatingData[5][2] = 74;
	aRatingData[5][3] = "Pretty average actually. Didn't particularly enjoy it. Save for relatives.";

	aRatingData[6] = new Array(1);
	aRatingData[6][1] = 75;
	aRatingData[6][2] = 79;
	aRatingData[6][3] = "Not bad, okay, so so. Soundly made but with little distinction.";
	
	aRatingData[7] = new Array(1);
	aRatingData[7][1] = 80;
	aRatingData[7][2] = 84;
	aRatingData[7][3] = "Quite enjoyed this wine, actually. Above average, no noticeable flaws.";

	aRatingData[8] = new Array(1);
	aRatingData[8][1] = 85;
	aRatingData[8][2] = 89;
	aRatingData[8][3] = "Now that's more like it. A very good wine. Really delicious.";

	aRatingData[9] = new Array(1);
	aRatingData[9][1] = 90;
	aRatingData[9][2] = 94;
	aRatingData[9][3] = "Outstanding wine. Exceptional in its class. Awesome. Stunning.";

	aRatingData[10] = new Array(1);
	aRatingData[10][1] = 95;
	aRatingData[10][2] = 100;
	aRatingData[10][3] = "Truly extraordinary wine. Wow! Better than sex. I can die happy now.";

	var starRatingNo = 0;
	var starRatingText = 0;	
	var setStars = 0;	
	
	function checkForValidRatingEdit(val,objid){
		if(val > 50 && val < 101){
			getRatingEdit(val,objid);
		}
	}
	
	function getRatingEdit(val,objid){
		setStars = 1;
		if(val.length > 0 && IsNumeric(val,"Rating points must be numeric")){
			if(val > 50 && val < 101){
				pointsdefArrayLen = aRatingData.length;
				
				for(i=1;i<pointsdefArrayLen;i++){
					
					if(val >= aRatingData[i][1] && val <= aRatingData[i][2]){
						starRatingEdit(i,objid);
						break;
					}
				}
				
			} else {
				alert("Rating points must be a number more than 49 and less than 101")
			}
		}
	}
	
	function setStarRatingEdit(no,objid){
		setStars = 1;
		starRatingEdit(no,objid);		
	}
	
	function hoverStarRatingEdit(no,objid){
		//if(setStars==0){
		//	starRatingEdit(no,objid);
		//}
	}

	function starRatingEdit(no,objid){

		for(i=10;i>no;i--){
			if(i%2){
				starImg = "starRatingGreyLeft.gif";
			} else {
				starImg = "starRatingGreyRight.gif";				
			}
//			alert("starRating"+i+"_"+objid);
			document.getElementById("starRating"+i+"_"+objid).src = webroot+"/wsimages/"+starImg;
		}
		
		for(i=1;i<(no+1);i++){
			if(i%2){
				starImg = "starRatingBlueLeft.gif";
				starsTxt = ((no/2)-.5);
				if(starsTxt==0){
					starRatingText = " &frac12; a star";
				} else {
					starRatingText = ((no/2)-.5)+" &frac12; stars";
				}
			} else {
				starsTxt = (no/2);
				if(starsTxt==1){
					starRatingText = "1 star";
				} else {				
					starRatingText = starsTxt+" stars";
				}
				starImg = "starRatingBlueRight.gif";				
			}
			document.getElementById("starRating"+i+"_"+objid).src = webroot+"/wsimages/"+starImg;			
		}
		document.getElementById("starRatingText_"+objid).innerHTML = starRatingText;
		document.getElementById("rating_"+objid).value = no;
		document.getElementById("ratingExplanation_"+objid).innerHTML = aRatingData[no][3]+"<span class='pointsForExplanation'>"+aRatingData[no][1]+"-"+aRatingData[no][2]+"<span>pts</span></span>";
		if(document.getElementById("points_"+objid).value>=parseInt(aRatingData[no][1]) && document.getElementById("points_"+objid).value<=parseInt(aRatingData[no][2])){
			// do nada
		} else {
			document.getElementById("points_"+objid).value = parseInt((parseInt(aRatingData[no][1])+parseInt(aRatingData[no][2]))/2);
		}
	}		
	
	
	
	
	function checkForValidRating(val){
		if(val > 50 && val < 101){
			getRating(val);
		}
	}
	
	function getRating(val){
		setStars = 1;
		if(val.length > 0 && IsNumeric(val,"Rating points must be numeric")){
			if(val > 50 && val < 101){
				pointsdefArrayLen = aRatingData.length;
				
				for(i=1;i<pointsdefArrayLen;i++){
					
					if(val >= aRatingData[i][1] && val <= aRatingData[i][2]){
						starRating(i);
						break;
					}
				}
				
			} else {
				alert("Rating points must be a number more than 49 and less than 101")
			}
		}
	}
	

	function setStarRating(no){
		setStars = 1;
		starRating(no);		
	}
	
	function hoverStarRating(no){
		if(setStars==0){
			starRating(no);
		}
	}

	function starRating(no){

		for(i=10;i>no;i--){
			if(i%2){
				starImg = "starRatingGreyLeft.gif";
			} else {
				starImg = "starRatingGreyRight.gif";				
			}
//			alert(i);
			document.getElementById("starRating"+i).src = webroot+"/wsimages/"+starImg;
		}
		
		for(i=1;i<(no+1);i++){
			if(i%2){
				starImg = "starRatingBlueLeft.gif";
				starsTxt = ((no/2)-.5);
				if(starsTxt==0){
					starRatingText = " &frac12; a star";
				} else {
					starRatingText = ((no/2)-.5)+" &frac12; stars";
				}
			} else {
				starsTxt = (no/2);
				if(starsTxt==1){
					starRatingText = "1 star";
				} else {				
					starRatingText = starsTxt+" stars";
				}
				starImg = "starRatingBlueRight.gif";				
			}
			document.getElementById("starRating"+i).src = webroot+"/wsimages/"+starImg;			
		}
		document.getElementById("starRatingText").innerHTML = starRatingText;
		document.getElementById("rating").value = no;
		document.getElementById("ratingExplanation").innerHTML = aRatingData[no][3]+"<span class='pointsForExplanation'>"+aRatingData[no][1]+"-"+aRatingData[no][2]+"<span>pts</span></span>";
		if(document.getElementById("points").value>=parseInt(aRatingData[no][1]) && document.getElementById("points").value<=parseInt(aRatingData[no][2])){
			// do nada
		} else {
			document.getElementById("points").value = parseInt((parseInt(aRatingData[no][1])+parseInt(aRatingData[no][2]))/2);
		}
	}	
	
	function toggleFriendSelect(cnt){
		
		
		var selectedDiv = document.getElementById("friendCheckBox"+cnt).checked ;
		if(selectedDiv){
			selectedFriends = selectedFriends-1;
			document.getElementById("friend"+cnt).className="friendDisplaySmall";
			document.getElementById("friendCheckBox"+cnt).checked = false;
		} else {
			if(maxFriendsSelectable){
				if(selectedFriends==maxFriendsSelectable){
					alert('You can only select '+maxFriendsSelectable+' friends to send this wine recommendation to.');
				} else {
					selectedFriends = selectedFriends+1;
					document.getElementById("friend"+cnt).className="friendDisplaySmallSelected";
					document.getElementById("friendCheckBox"+cnt).checked = true;			
				}
			}else{
				document.getElementById("friend"+cnt).className="friendDisplaySmallSelected";
				document.getElementById("friendCheckBox"+cnt).checked = true;							
			}
		}
	}
	
	function selectAllFriends(cnt){
		for(i=0;i<cnt;i++){
			document.getElementById("friend"+(i+1)).className="friendDisplaySmallSelected";
			document.getElementById("friendCheckBox"+(i+1)).checked = true;							
		}
	}
	
	function saveRecommendationData(wineid){
		lenLFriends = document.recommendationDataForm.lfriends.length;
		var lFriends = "";
		if(lenLFriends>0){
			for(i=0;i<lenLFriends;i++){
				if(document.recommendationDataForm.lfriends[i].checked){
					comma = "";
					if(lFriends.length>0){
						comma = ",";
					}
					lFriends = lFriends+comma+document.recommendationDataForm.lfriends[i].value;
				}
			}
		}
		
		if(lFriends.length < 1){
			document.getElementById("friendsList").className = "addWineField friendList errorField";
			errorHTML = '<li>Select atleast one friend to recommend this wine to.</li>';
			document.getElementById("lbErrors").innerHTML = '<h2>just a few errors:</h2><ul>'+errorHTML+'</ul>';		
		} else {

			document.getElementById("addToRecommendation").style.display = "none";
			document.getElementById("addToRecommendationOff").style.display = "inline";

			var Comments = document.getElementById("Comments").value;			
			ajaxURL =  "&Comments="+Comments+"&wineid="+wineid+"&lFriends="+lFriends;
			ajaxURL = webroot+"/ajax/recommendDataSave.cfm?sRequest="+requestKey+ajaxURL;
	
			new Ajax.Request(ajaxURL, {
				method: 'get',
				onSuccess: function (response) {
					showSuccess("The wine recommendation has been sent.",recommendationsPageId);	
					// do nothing;
				},
				onFailure: function (response) {
					 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
				}
			});					
					
		}
		return false;
	}
	
	function findWineMatches(defineType,clientId){
		
		
		document.getElementById("wineTypeSelector").className = "addWineField";
		document.getElementById("wineName").className = "largeField";
		var errorHTML = "";
		var selectedWineType = 0;
		wineTypes =  document.addWineDataForm.wineType.length;
		for(i=0;i<wineTypes;i++){
			if(document.addWineDataForm.wineType[i].checked){
				selectedWineType = document.addWineDataForm.wineType[i].value;
			}
		}

		wineName =  document.addWineDataForm.wineName.value;
		wineVintage =  document.addWineDataForm.wineVintage.value;

		if(selectedWineType == 0){
			document.getElementById("wineTypeSelector").className = "addWineField errorField";
			errorHTML = errorHTML+'<li>Select a wine type</li>';
		} 
		if(wineName.length == 0){
			document.getElementById("wineName").className = "largeField errorField";
			errorHTML = errorHTML+'<li>Enter a wine name</li>';
		} 
		
		if(errorHTML.length > 0){
			document.getElementById("lbErrors").innerHTML = '<h2>just a few errors:</h2><ul>'+errorHTML+'</ul>';			
		} else {
			
			document.getElementById("continueAddWineBTNGrey").style.display = 'inline';
			document.getElementById("continueAddWineBTN").style.display = 'none';
			document.getElementById("searchQwoffAjaxLoader").style.display = 'block';
			document.getElementById("wineMatches").innerHTML = '';
			
			ajaxURL =  "?winetype="+selectedWineType+"&wineName="+wineName+"&wineVintage="+wineVintage+"&defineType="+defineType+"&clientId="+clientId;
			ajaxURL = webroot+"/ajax/findWineMatches.cfm"+ajaxURL;
			new Ajax.Request(ajaxURL, {
				method: 'get',
				onSuccess: function (response) {
					parseAjaxFindWine(response.responseText.evalJSON());	
					// do nothing;
				},
				onFailure: function (response) {
					 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
				}
			});					
				
		}
		return false;
	}
	
	function parseAjaxFindWine(responseObj)
	{
		
		EXACTMATCHID = responseObj.EXACTMATCHID;
		
	//	alert(EXACTMATCHID);
		if(EXACTMATCHID!=0){
			//
			ajaxLoadLB(responseObj.STEP3FORM,'&wineId='+EXACTMATCHID+'&clientId='+responseObj.CLIENTID)
		} else {
			document.getElementById("continueAddWineBTNGrey").style.display = 'none';
			document.getElementById("continueAddWineBTN").style.display = 'inline';
			document.getElementById("searchQwoffAjaxLoader").style.display = 'none';
			SHTML = responseObj.SHTML;
			document.getElementById("wineMatches").innerHTML = 	SHTML;			
		}
	}	
	
	function moveStep2(action,dataParams){			
		// define the url
		
		ajaxURL = "/ajax/lbAction.cfm?action="+action+dataParams;	
		new Ajax.Request(ajaxURL, {
			method: 'get',
			onSuccess: function (response) {
				parseStep2Content(response.responseText.evalJSON());
			},
			onFailure: function (response) {
				 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
			}
		});
		
	}
	
	function parseStep2Content(responseObj){
		SHTML = responseObj.SHTML;
		STITLE = responseObj.STITLE;
		STITLECLASS = responseObj.STITLECLASS;
		document.getElementById("lbTitle").innerHTML = "<h1 class='"+STITLECLASS+"'>"+STITLE+"</h1>";
		document.getElementById("lightBoxData").innerHTML = SHTML;
		initStep2AutoCompletes();
	
	}	
	
	function initStep2AutoCompletes(){
		initAutoComplete('wineryName','wineryName');
//		initAutoComplete('varietyName','varietyName');
//		initAutoComplete('regionName','regionName');
	}
	
	function initAutoComplete(fieldId,fieldData){
		new AutoComplete(fieldId, '/ajax/autoCompleteData.cfm?fieldData='+fieldData+'&s=', { delay: 0.25, resultFormat: AutoComplete.Options.RESULT_FORMAT_JSON }); 	
	}
	
	function addVariety(){
		addedVarietalsLen = 0;
		varietyName = document.addWineDataForm.varietyName.value;
		if(varietyName.length>0){
			if(document.addWineDataForm.lVarietal){
				addedVarietalsLen = document.addWineDataForm.lVarietal.length;
			}
			addVarietyHTML = '<div id="varietal'+(addedVarietalsLen+1)+'"><div class="varietyDelBtn"><img alt="Delete Varietal" onclick="delVariety('+(addedVarietalsLen+1)+')" src="'+webroot+'/wsimages/smallDelBTN.gif" /></div><div class="varietyLabel">'+varietyName+'</div><div class="clear"></div><input type="hidden" name="lVarietal" id="varietalField'+(addedVarietalsLen+1)+'" value="'+varietyName+'" /></div>';
			document.getElementById("varietalList").innerHTML = document.getElementById("varietalList").innerHTML+addVarietyHTML;
		}
	}	
	
	function delVariety(no){
		var child = document.getElementById("varietal"+no);
		var parent = document.getElementById("varietalList");
		child.getElementsByTagName("input")[0].value = '';
		parent.removeChild(child)	
	}
	
	function addRegionToWine(){
		addedRegionsLen = 0;
		regionName =  document.addWineDataForm.regionName[document.addWineDataForm.regionName.selectedIndex].text;
		regionId = document.addWineDataForm.regionName.value;
		if(regionId.length>0){
			if(document.addWineDataForm.lRegion){
				addedRegionsLen = document.addWineDataForm.lRegion.length;
			}
			addRegionHTML = '<div id="region'+(addedRegionsLen+1)+'"><div class="regionDelBtn"><img alt="Delete Region" onclick="delRegion('+(addedRegionsLen+1)+')" src="'+webroot+'/wsimages/smallDelBTN.gif" /></div><div class="regionLabel">'+regionName+'</div><div class="clear"></div><input type="hidden" name="lRegion" id="regionField'+(addedRegionsLen+1)+'" value="'+regionId+'" /></div>';
			document.getElementById("regionList").innerHTML = document.getElementById("regionList").innerHTML+addRegionHTML;
		}
	}	
	
	function delRegion(no){
		var child = document.getElementById("region"+no);
		var parent = document.getElementById("regionList");
		child.getElementsByTagName("input")[0].value = '';
		parent.removeChild(child)	
	}
	
	function saveWineDetails(){

		document.getElementById("wineryName").className = "largeField";
		document.getElementById("varietyName").className = "largeField";
		document.getElementById("regionName").className = "largeField";

		var errorHTML = "";		
		var defineType = document.addWineDataForm.defineType.value;
		var wineName = document.addWineDataForm.wineName.value;
		var wineType = document.addWineDataForm.wineType.value;
		var wineVintage = document.addWineDataForm.wineVintage.value;
		var wineryName = document.addWineDataForm.wineryName.value;
		var winePrice = document.addWineDataForm.winePrice.value;
		var clientId = document.addWineDataForm.clientId.value;
		var wineActualPrice = document.addWineDataForm.wineActualPrice.value;
		var bottleSize = document.addWineDataForm.bottleSize.value;
		
		
		var requestKeyLocal = requestKey;

		var lRegion = "";
		if(document.addWineDataForm.lRegion){
			if(document.addWineDataForm.lRegion.length){
				for(i=0;i<document.addWineDataForm.lRegion.length;i++){
					comma = "";
					if(lRegion.length>0){
						comma = ",";
					}
					lRegion = lRegion+comma+document.addWineDataForm.lRegion[i].value;
				}
			} else {
				lRegion = document.addWineDataForm.lRegion.value;
			}
		}
		if(lRegion.length>0){
			lRegion = lRegion+","+document.addWineDataForm.regionName.value;
		} else{
			lRegion	= document.addWineDataForm.regionName.value;
		}

		var lVarietal = "";
		if(document.addWineDataForm.lVarietal){
			if(document.addWineDataForm.lVarietal.length){
				for(i=0;i<document.addWineDataForm.lVarietal.length;i++){
					comma = "";
					if(lVarietal.length>0){
						comma = ",";
					}
					lVarietal = lVarietal+comma+document.addWineDataForm.lVarietal[i].value;
				}
			} else {
				lVarietal = document.addWineDataForm.lVarietal.value;
			}
		}
		if(lVarietal.length==0){
			lVarietal = document.addWineDataForm.varietyName.value;
		}
				
		
		if(wineActualPrice.length>0 & !IsNumeric(wineActualPrice)){
			document.getElementById("wineActualPrice").className = "smallField errorField";
			errorHTML = errorHTML+'<li>If you are going to enter a price make sure it is numeric.</li>';
		}
		
		if(wineryName.length==0){
			document.getElementById("wineryName").className = "largeField errorField";
			errorHTML = errorHTML+'<li>You need to enter a winery name.</li>';
		}
		if(lVarietal.length==0){
			document.getElementById("varietyName").className = "largeField errorField";
			errorHTML = errorHTML+'<li>You need to add one or more varietals.</li>';
		}

		if(lRegion.length==0){
			document.getElementById("regionName").className = "largeField errorField";
			errorHTML = errorHTML+'<li>You need to add one or more regions.</li>';
		}
		
		
		
		if(errorHTML.length > 0){
			document.getElementById("lbErrors").innerHTML = '<h2>just a few errors:</h2><ul>'+errorHTML+'</ul>';			
		
		} else {
			
			document.getElementById("continueAddWineBTNGrey").style.display = 'inline';
			document.getElementById("continueAddWineBTN").style.display = 'none';
			document.getElementById("searchQwoffAjaxLoader").style.display = 'block';
			ajaxURL = "&bottleSize="+bottleSize+"&wineActualPrice="+wineActualPrice+"&defineType="+defineType+"&winePrice="+winePrice+"&lVarietal="+lVarietal+"&lRegion="+lRegion+"&requestKey="+requestKeyLocal;
			
			ajaxURL =  "?winetype="+wineType+"&wineName="+wineName+"&wineVintage="+wineVintage+"&wineryName="+wineryName+"&clientId="+clientId+ajaxURL;
			ajaxURL = webroot+"/ajax/addWineData.cfm"+ajaxURL;
			new Ajax.Request(ajaxURL, {
				method: 'get',
				onSuccess: function (response) {
					parseAjaxWineAdd(response.responseText.evalJSON());	
					// do nothing;
				},
				onFailure: function (response) {
					 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
				}
			});					
		}
		return false;
	}
	
	function parseAjaxWineAdd(responseObj){
		ajaxLoadLB(responseObj.STEP3FORM,'&wineId='+responseObj.WINEID+'&clientId='+responseObj.CLIENTID)
	}	
	
	function delMessage(messageId){
		ajaxURL = webroot+"/ajax/deleteMessage.cfm?requestKey="+requestKey+"&messageId="+messageId;
		new Ajax.Request(ajaxURL, {
			method: 'get',
			onSuccess: function (response) {
				myLightbox.end();
				getInboxMessages(1);
//				getCellarList(document.wineListForm.currentPage.value);				
			},
			onFailure: function (response) {
				 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
			}
		});					
	}	

	function markMessageRead(messageId){
		ajaxURL = webroot+"/ajax/markMessageRead.cfm?requestKey="+requestKey+"&messageId="+messageId;
		new Ajax.Request(ajaxURL, {
			method: 'get',
			onSuccess: function (response) {
				myLightbox.end();
				getInboxMessages(1);
				parseAjaxMarkMessage(response.responseText.evalJSON());	
//				getCellarList(document.wineListForm.currentPage.value);				
			},
			onFailure: function (response) {
				 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
			}
		});					
	}
	
	function parseAjaxMarkMessage(responseObj){
		UNREADMSG = responseObj.UNREADMSG;
		document.getElementById("unreadeMessageCount").innerHTML = UNREADMSG;
	
	}	
	
	function searchCommunityList(search){
		document.friendListForm.searchStr.value=searchStr;
		searchStr = search;
	}
	
	
	function getActionLog(page)
	{			
		
		// define the url
		try{
			document.getElementById("ajaxPagingLoader").style.visibility = "visible";
		} catch(e){
			//nada
		}
		ajaxURL = webroot+"/ajax/actionHistoryList.cfm?sRequest="+sRequest+"&currentPage="+page;

		//		document.wineListForm.maxRows.currentPage =	page;		
		new Ajax.Request(ajaxURL, {
			method: 'get',
			onSuccess: function (response) {
				parseAjaxActionHistoryList(response.responseText.evalJSON());
			},
			onFailure: function (response) {
				 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
			}
		});
		
	}

	function parseAjaxActionHistoryList(responseObj)
	{

		SHTML = responseObj.SHTML;
		SPAGINGHTML = responseObj.SPAGINGHTML;
		SVIEWING = responseObj.SVIEWING;
//		STOTALRECSHTML = responseObj.STOTALRECSHTML;

		document.getElementById("wineListsPagingTop").innerHTML = 	SPAGINGHTML;
		document.getElementById("wineListsPagingBottom").innerHTML = 	SPAGINGHTML;
		document.getElementById("actionLogItems").innerHTML = 	SHTML;
		document.getElementById("wineListscurrentPage").innerHTML = 	SVIEWING;
//		document.getElementById("wineListsTotals").innerHTML = 	STOTALRECSHTML;	
	}
	
	function getCommunity(page)
	{			
		
		// define the url
		try{
			document.getElementById("ajaxPagingLoader").style.visibility = "visible";
		} catch(e){
			//nada
		}
		ajaxURL = webroot+"/ajax/communityList.cfm?sRequest="+sRequest+"&currentPage="+page+"&searchStr="+searchStr;

		//		document.wineListForm.maxRows.currentPage =	page;		
		new Ajax.Request(ajaxURL, {
			method: 'get',
			onSuccess: function (response) {
				parseAjaxCommunityList(response.responseText.evalJSON());
			},
			onFailure: function (response) {
				 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
			}
		});
		
	}

	function parseAjaxCommunityList(responseObj)
	{

		SHTML = responseObj.SHTML;
		SPAGINGHTML = responseObj.SPAGINGHTML;
		SVIEWING = responseObj.SVIEWING;
//		STOTALRECSHTML = responseObj.STOTALRECSHTML;

		document.getElementById("wineListsPagingTop").innerHTML = 	SPAGINGHTML;
		document.getElementById("wineListsPagingBottom").innerHTML = 	SPAGINGHTML;
		document.getElementById("infoListContentWrapper").innerHTML = 	SHTML;
		document.getElementById("wineListscurrentPage").innerHTML = 	SVIEWING;
//		document.getElementById("wineListsTotals").innerHTML = 	STOTALRECSHTML;	
	}

	function searchFriendsList(search){
		document.friendListForm.searchStr.value=searchStr;
		searchStr = search;
	}
	
	function getFriends(page)
	{			
		
		// define the url
		try{
			document.getElementById("ajaxPagingLoader").style.visibility = "visible";
		} catch(e){
			//nada
		}
		ajaxURL = webroot+"/ajax/friendsList.cfm?sRequest="+sRequest+"&currentPage="+page+"&searchStr="+searchStr;

		//		document.wineListForm.maxRows.currentPage =	page;		
		new Ajax.Request(ajaxURL, {
			method: 'get',
			onSuccess: function (response) {
				parseAjaxFriendsList(response.responseText.evalJSON());
			},
			onFailure: function (response) {
				 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
			}
		});
		
	}

	function parseAjaxFriendsList(responseObj)
	{

		SHTML = responseObj.SHTML;
		SPAGINGHTML = responseObj.SPAGINGHTML;
		SVIEWING = responseObj.SVIEWING;
//		STOTALRECSHTML = responseObj.STOTALRECSHTML;

		document.getElementById("wineListsPagingTop").innerHTML = 	SPAGINGHTML;
		document.getElementById("wineListsPagingBottom").innerHTML = 	SPAGINGHTML;
		document.getElementById("infoListContentWrapper").innerHTML = 	SHTML;
		document.getElementById("wineListscurrentPage").innerHTML = 	SVIEWING;
//		document.getElementById("wineListsTotals").innerHTML = 	STOTALRECSHTML;	
	}

	function toggleFriendDetails(friendId){
		if(document.getElementById('friendDetails'+friendId).style.display == "none"){
			document.getElementById('friendDetails'+friendId).style.display = "block";
			document.getElementById('friendDetailsBasic'+friendId).style.display = "none";
			document.getElementById('detailsIcon'+friendId).src = webroot+"/wsimages/smallBlueArrowBorderUp.gif";
			getFriendData(friendId);
		} else {
			document.getElementById('detailsIcon'+friendId).src = webroot+"/wsimages/smallBlueArrowBorderDown.gif";
			document.getElementById('friendDetails'+friendId).style.display = "none";
			document.getElementById('friendDetailsBasic'+friendId).style.display = "block";
		}
	}
	
	function getFriendData(friendId)
	{			
		// define the url

		ajaxURL = webroot+"/ajax/friendData.cfm?sRequest="+sRequest+"&friendId="+friendId;

		new Ajax.Request(ajaxURL, {
			method: 'get',
			onSuccess: function (response) {
				parseAjaxFriendData(response.responseText.evalJSON());
			},
			onFailure: function (response) {
				 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
			}
		});
		
	}

	function parseAjaxFriendData(responseObj)
	{

		OBJECTID = responseObj.OBJECTID;
		DETAILSHTML = responseObj.DETAILSHTML;

		document.getElementById("friendDetails"+OBJECTID).innerHTML = 	DETAILSHTML;
		
	}
	
	function delFriend(friendId){
		ajaxURL = webroot+"/ajax/deleteFriend.cfm?requestKey="+requestKey+"&friendId="+friendId;
		new Ajax.Request(ajaxURL, {
			method: 'get',
			onSuccess: function (response) {
				myLightbox.end();
				getFriends(1);
			},
			onFailure: function (response) {
				 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
			}
		});					
	}	
	
	function toggleFriendMessage(){
		if(document.getElementById("friendMessageContainer").style.display ='none'){
			document.getElementById("friendMessageLink").style.display ='none';
			document.getElementById("friendMessageContainer").style.display ='block';
		} else {
			document.getElementById("friendMessageLink").style.display ='block';
			document.getElementById("friendMessageContainer").style.display ='none';
		}
	}

	function sendFriendRequest(friendId){
		var friendMessage = URLEncode(document.friendRequestForm.friendMessage.value);
		var requestKeyLocal = requestKey;
//		document.getElementById("addToFriendsOff").style.display = 'inline';
		document.getElementById("friendRequestForm").style.display = 'none';
		document.getElementById("searchQwoffAjaxLoader").style.display = 'block';
		
		ajaxURL =  "?friendId="+friendId+"&requestKey="+requestKeyLocal+"&friendMessage="+friendMessage;
		ajaxURL = webroot+"/ajax/sendFriendRequest.cfm"+ajaxURL;
		
	//	alert(ajaxURL);
		
		new Ajax.Request(ajaxURL, {
			method: 'get',
			onSuccess: function (response) {
				myLightbox.end();
				// do nothing;
			},
			onFailure: function (response) {
				 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
			}
		});					
		return false;
	}

	function passwordReminder(){
		var emailaddress = document.passwordReminderForm.emailaddress.value;
		document.getElementById("passwordReminderForm").style.display = 'none';
		document.getElementById("searchQwoffAjaxLoader").style.display = 'block';
		
		ajaxURL =  "?emailaddress="+emailaddress;
		ajaxURL = webroot+"/ajax/passwordReminder.cfm"+ajaxURL;
		new Ajax.Request(ajaxURL, {
			method: 'get',
			onSuccess: function (response) {
				myLightbox.end();
				// do nothing;
			},
			onFailure: function (response) {
				 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
			}
		});					
		return false;
	}

	function contactus(){		
		var message = URLEncode(document.contactUsForm.message.value);
		var clientId = document.contactUsForm.clientId.value;
		var emailaddress = URLEncode(document.contactUsForm.emailaddress.value);

		document.getElementById("contactUsForm").style.display = 'none';
		document.getElementById("searchQwoffAjaxLoader").style.display = 'block';
		
		ajaxURL =  "?emailaddress="+emailaddress+"&message="+message+"&clientId="+clientId;
		ajaxURL = webroot+"/ajax/contactus.cfm"+ajaxURL;
		new Ajax.Request(ajaxURL, {
			method: 'get',
			onSuccess: function (response) {
				myLightbox.end();
				// do nothing;
			},
			onFailure: function (response) {
				 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
			}
		});					
		return false;
	}

	
	function openMyMenu(filterNo){
		var posLeft = document.getElementById("myNewMenuLink"+filterNo).offsetLeft;
		if(document.all){
			posLeft = posLeft - 500; // ie offset
			document.getElementById("myNewMenu"+filterNo).style.marginLeft = posLeft+"px";
		}else{
			document.getElementById("myNewMenu"+filterNo).style.left = posLeft+"px";		
		}
		
		toggleMyMenu(filterNo);
		
		$j("body").click(function(){toggleMyMenu(0);});
		
		//		toggleMyMenu(filterNo)
		if($j("#myNewMenu"+filterNo).css("display")=='none'){
			$j("#myNewMenu"+filterNo).slideDown("normal");
		}
	}
	
	function toggleMyMenu(filterNo){
		if(filterNo==0){
			$j("#myNewMenu1").slideUp("normal");			
			$j("#myNewMenu2").slideUp("normal");			
			$j("#myNewMenu3").slideUp("normal");			
		}
		if(filterNo==1){
			$j("#myNewMenu2").slideUp("normal");			
			$j("#myNewMenu3").slideUp("normal");			
		}
		if(filterNo==2){
			$j("#myNewMenu1").slideUp("normal");			
			$j("#myNewMenu3").slideUp("normal");			
		}
		if(filterNo==3){
			$j("#myNewMenu1").slideUp("normal");			
			$j("#myNewMenu2").slideUp("normal");			
		}
	}
	
	function toggleMutualFriendDetails(customerId){
		if(document.getElementById('mutualFriends'+customerId).style.display == "none"){
			document.getElementById('mutualFriends'+customerId).style.display = "block";
			document.getElementById('detailsIcon'+customerId).src = webroot+"/wsimages/smallBlueArrowBorderUp.gif";
			getMutualFriends(customerId);
		} else {
			document.getElementById('detailsIcon'+customerId).src = webroot+"/wsimages/smallBlueArrowBorderDown.gif";
			document.getElementById('mutualFriends'+customerId).style.display = "none";
		}
	}

	function getMutualFriends(customerId)
	{			
		// define the url

		ajaxURL = webroot+"/ajax/mutualFriendsData.cfm?sRequest="+sRequest+"&customerId="+customerId;

		new Ajax.Request(ajaxURL, {
			method: 'get',
			onSuccess: function (response) {
				parseAjaxMutualFriends(response.responseText.evalJSON());
			},
			onFailure: function (response) {
				 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
			}
		});		
	}

	function parseAjaxMutualFriends(responseObj)
	{

		OBJECTID = responseObj.OBJECTID;
		DETAILSHTML = responseObj.DETAILSHTML;

		document.getElementById("mutualFriends"+OBJECTID).innerHTML = 	DETAILSHTML;
		
	}
	
	function processFriendRequest(friendObjectId,action)
	{			
		// define the url

		ajaxURL = webroot+"/ajax/processFriendRequest.cfm?sRequest="+sRequest+"&friendObjectId="+friendObjectId+"&action="+action;

		new Ajax.Request(ajaxURL, {
			method: 'get',
			onSuccess: function (response) {
				location.href=location.href;
			},
			onFailure: function (response) {
				 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
			}
		});		
	}
	
	function searchWines(searchStr){
		document.getElementById("searchStringDisplayWrapper").style.display = 'block';
		document.getElementById("searchStringDisplay").innerHTML = searchStr;
		document.wineListForm.searchStr.value = searchStr;
		getWinesWineries(1);
	}
	
	function resetSearch(){
		document.getElementById("searchStringDisplayWrapper").style.display = 'none';
		document.wineListForm.searchStr.value = '';
		getWinesWineries(1);
	}
	

	function addTopicData(){		
		var topictitle = URLEncode(document.forumTopicForm.topictitle.value);
		var categoryid = document.forumTopicForm.categoryid.value;
		var forumMessage = URLEncode(document.forumTopicForm.forumMessage.value);
		var topicSubscribe = 0;
		if(document.forumTopicForm.topicSubscribe.checked){
			topicSubscribe = 1;
		}
		document.getElementById("forumTopicForm").style.display = 'none';
		document.getElementById("searchQwoffAjaxLoader").style.display = 'block';
		
		ajaxParams =  "topictitle="+topictitle+"&categoryid="+categoryid+"&forumMessage="+forumMessage+"&topicSubscribe="+topicSubscribe+"&requestKey="+requestKey;
		ajaxURL = webroot+"/ajax/addTopic.cfm";
		new Ajax.Request(ajaxURL, {
			method: 'post',
			parameters: ajaxParams,
			onSuccess: function (response) {
				myLightbox.end();
				getForumData(1);
				// do nothing;
			},
			onFailure: function (response) {
				 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
			}
		});					
		return false;
	}

	function toggleSubsciption(chk,topicid){
		ajaxURL = webroot+"/ajax/toggleForumTopicSub.cfm?sRequest="+sRequest+"&chk="+chk+"&topicid="+topicid;
		new Ajax.Request(ajaxURL, {
			method: 'get',
			onSuccess: function (response) {
				//do nothing;
			},
			onFailure: function (response) {
				 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
			}
		});
	}
	
	function getForumData(page)
	{			
		// define the url
		document.getElementById("ajaxPagingLoader").style.visibility = "visible";
		ajaxURL = webroot+"/ajax/getForumTopics.cfm?sRequest="+sRequest+"&currentPage="+page;
//		document.wineListForm.maxRows.currentPage =	page;		
		new Ajax.Request(ajaxURL, {
			method: 'get',
			onSuccess: function (response) {
				parseAjaxForumTopics(response.responseText.evalJSON());
			},
			onFailure: function (response) {
				 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
			}
		});
		
	}
	
	function parseAjaxForumTopics(responseObj)
	{

		SHTML = responseObj.SHTML;
		SPAGINGHTML = responseObj.SPAGINGHTML;
		SVIEWING = responseObj.SVIEWING;

		document.getElementById("wineListsPagingTop").innerHTML = 	SPAGINGHTML;
		document.getElementById("wineListsPagingBottom").innerHTML = 	SPAGINGHTML;
		document.getElementById("infoListContentWrapper").innerHTML = 	SHTML;
		document.getElementById("wineListscurrentPage").innerHTML = 	SVIEWING;
		document.getElementById("wineListscurrentPageBottom").innerHTML = 	SVIEWING;
	}

	function addPostData(){		
		var topicid = document.forumTopicForm.topicReplyForm.value;
		var postMessage = URLEncode(document.topicReplyForm.postMessage.value);

		document.getElementById("forumTopicForm").style.display = 'none';
		document.getElementById("searchQwoffAjaxLoader").style.display = 'block';
		
		ajaxParams =  "topictitle="+topictitle+"&categoryid="+categoryid+"&forumMessage="+forumMessage+"&requestKey="+requestKey;
		ajaxURL = webroot+"/ajax/addTopic.cfm";
		new Ajax.Request(ajaxURL, {
			method: 'post',
			parameters: ajaxParams,
			onSuccess: function (response) {
				myLightbox.end();
				location.href=location.href;
				// do nothing;
			},
			onFailure: function (response) {
				 alert("status: " + response.status + "; statusText: " + response.statusText + "; ");
			}
		});					
		return false;
	}
	
	function openpostEdit(id){
		$j("#forumPostEditor_"+id).css("display","block");
		$j("#forumPostData_"+id).css("display","none");
	}
	function closepostEdit(id){
		$j("#forumPostEditor_"+id).css("display","none");
		$j("#forumPostData_"+id).css("display","block");
	}

    $j(document).ready(function(){
    	var defPostStr = 'Post your reply'
		$j("#postMessage").attr("value",defPostStr);
		$j("#postMessage").focus(function(){
			if($j("#postMessage").attr("value")==defPostStr){
				$j("#postMessage").attr("value",'');
			}
		});

		$j("#postMessage").blur(function(){
			if($j("#postMessage").attr("value")==''){
				$j("#postMessage").attr("value",defPostStr);
			}
		});
    });
	
	function URLEncode (clearString) {
		  var output = '';
		  var x = 0;
		  clearString = clearString.toString();
		  var regex = /(^[a-zA-Z0-9_.]*)/;
		  while (x < clearString.length) {
		    var match = regex.exec(clearString.substr(x));
		    if (match != null && match.length > 1 && match[1] != '') {
		    	output += match[1];
		      x += match[1].length;
		    } else {
		      if (clearString[x] == ' ')
		        output += '%20';
		      else {
		        var charCode = clearString.charCodeAt(x);
		        var hexVal = charCode.toString(16);
		        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
		      }
		      x++;
		    }
		  }
		  return output;
		}
	

	
