// JavaScript Document

var map = null;
var geocoder = null;

var WineListModule = null;
var showWineListRegion = null;

var AttendeeModule = null;
var showAttendeeRegion = null;
var AttendeeModuleTwo = null;
var showAttendeeRegionTwo = null;

var PhotoModule = null;
var showPhotoRegion = null;
var QuickViewModule = null;
var uploadDialog = null;
var toolTip = null;
var PictureModule = null;

var MagModule = null;
var bigImageOut = 1;
var overImage = 0;
var lastWineSearch = "";

function regionMouseOver(e, imageElement)
{
	this.className = 'tabTextOver'; 
	imageElement.src = DownArrowGray.src;
}
function regionMouseOut(e, imageElement)
{
	this.className = 'tabText'; 
	imageElement.src = DownArrow.src;
}
function regionMouseOverUp(e, imageElement)
{
	this.className = 'tabTextOver'; 
	imageElement.src = UpArrowGray.src;
}
function regionMouseOutUp(e, imageElement)
{
	this.className = 'tabText'; 
	imageElement.src = UpArrow.src;
}
function showWineList()  
{
	if (!WineListModule.cfg.getProperty("visible"))
	{
		WineListModule.show();
		document.getElementById("showWineListRegion").innerHTML = "<img id=\"upArrowWineList\" src=\"/Images/uparrow.gif\" alt=\"up arrow\"/>Hide Wine List Details";
		YAHOO.util.Event.addListener("showWineListRegion", "mouseover", regionMouseOverUp, document.getElementById("upArrowWineList"));
		YAHOO.util.Event.addListener("showWineListRegion", "mouseout", regionMouseOutUp, document.getElementById("upArrowWineList"));
	}
	else
	{
		WineListModule.hide();
		document.getElementById("showWineListRegion").innerHTML = "<img id=\"downArrowWineList\" src=\"/Images/downarrow.gif\" alt=\"down arrow\"/>Show Full Wine List";
		YAHOO.util.Event.addListener("showWineListRegion", "mouseover", regionMouseOver, document.getElementById("downArrowWineList"));
		YAHOO.util.Event.addListener("showWineListRegion", "mouseout", regionMouseOut, document.getElementById("downArrowWineList"));
	}
	document.getElementById("showWineListRegion").className = 'tabText';
}
function showAttendeeList()  
{
	if (!AttendeeModule.cfg.getProperty("visible"))
	{
		AttendeeModule.show();
		document.getElementById("showAttendeeRegion").innerHTML = "<img id=\"upArrowAttendee\" src=\"/Images/uparrow.gif\" alt=\"up arrow\"/>Hide Guest List";
		YAHOO.util.Event.addListener("showAttendeeRegion", "mouseover", regionMouseOverUp, document.getElementById("upArrowAttendee"));
		YAHOO.util.Event.addListener("showAttendeeRegion", "mouseout", regionMouseOutUp, document.getElementById("upArrowAttendee"));
	}
	else
	{
		AttendeeModule.hide();
		document.getElementById("showAttendeeRegion").innerHTML = "<img id=\"downArrowAttendee\" src=\"/Images/downarrow.gif\" alt=\"down arrow\"/>Show Full Guest List";
		YAHOO.util.Event.addListener("showAttendeeRegion", "mouseover", regionMouseOver, document.getElementById("downArrowAttendee"));
		YAHOO.util.Event.addListener("showAttendeeRegion", "mouseout", regionMouseOut, document.getElementById("downArrowAttendee"));
	}
	document.getElementById("showAttendeeRegion").className = 'tabText';
}
function showAttendeeListTwo()  
{
	if (!AttendeeModuleTwo.cfg.getProperty("visible"))
	{
		AttendeeModuleTwo.show();
		document.getElementById("showAttendeeRegionTwo").innerHTML = "<img id=\"upArrowAttendeeTwo\" src=\"/Images/uparrow.gif\" alt=\"up arrow\"/>Hide Sounds-Cool List";
		YAHOO.util.Event.addListener("showAttendeeRegionTwo", "mouseover", regionMouseOverUp, document.getElementById("upArrowAttendeeTwo"));
		YAHOO.util.Event.addListener("showAttendeeRegionTwo", "mouseout", regionMouseOutUp, document.getElementById("upArrowAttendeeTwo"));
	}
	else
	{
		AttendeeModuleTwo.hide();
		document.getElementById("showAttendeeRegionTwo").innerHTML = "<img id=\"downArrowAttendeeTwo\" src=\"/Images/downarrow.gif\" alt=\"down arrow\"/>Show Full Sounds-Cool List";
		YAHOO.util.Event.addListener("showAttendeeRegionTwo", "mouseover", regionMouseOver, document.getElementById("downArrowAttendeeTwo"));
		YAHOO.util.Event.addListener("showAttendeeRegionTwo", "mouseout", regionMouseOut, document.getElementById("downArrowAttendeeTwo"));
	}
	document.getElementById("showAttendeeRegionTwo").className = 'tabText';
}
function showPhotos()  
{
	if (!PhotoModule.cfg.getProperty("visible"))
	{
		PhotoModule.show();
		document.getElementById("showPhotoRegion").innerHTML = "<img id=\"upArrowPhoto\" src=\"/Images/uparrow.gif\" alt=\"up arrow\"/>Hide Additional Photos";
		YAHOO.util.Event.addListener("showPhotoRegion", "mouseover", regionMouseOverUp, document.getElementById("upArrowPhoto"));
		YAHOO.util.Event.addListener("showPhotoRegion", "mouseout", regionMouseOutUp, document.getElementById("upArrowPhoto"));
	}
	else
	{
		PhotoModule.hide();
		document.getElementById("showPhotoRegion").innerHTML = "<img id=\"downArrowPhoto\" src=\"/Images/downarrow.gif\" alt=\"down arrow\"/>Show All Photos";
		YAHOO.util.Event.addListener("showPhotoRegion", "mouseover", regionMouseOver, document.getElementById("downArrowPhoto"));
		YAHOO.util.Event.addListener("showPhotoRegion", "mouseout", regionMouseOut, document.getElementById("downArrowPhoto"));
	}
	document.getElementById("showPhotoRegion").className = 'tabText';
}

var wineListStart = function(o)
{ 
	LoadingContainer.show();
};
var wineListSuccess = function(o)
{ 
	var Response = o.responseText;
	if (Response.substring(0,7) == "[error]")
	{
		wineWarning(Response.substring(7,Response.length));	
	}
	else
	{
		document.getElementById("wineListDiv").innerHTML = o.responseText;
		LoadingContainer.hide();

		if (!WineListModule)
		{
			WineListModule = new YAHOO.widget.Module("WineListRegion", { visible: false });  
			WineListModule.render();   
			showWineListRegion = new YAHOO.widget.Module("showWineListRegion", { visible: true });  
			showWineListRegion.render();   
			YAHOO.util.Event.addListener("showWineListRegion", "mouseover", regionMouseOver, document.getElementById("downArrowWineList"))	;
			YAHOO.util.Event.addListener("showWineListRegion", "mouseout", regionMouseOut, document.getElementById("downArrowWineList"));		
		}
	}
};
var wineListFailure = function(o)
{ 
	wineWarning("There was a communication error when trying to load the event wine list. Please try again later.");
};

var LoadingContainer = 
		new YAHOO.widget.Panel("loadingDialog",  
			{ width:"80px", 
			  fixedcenter:true, 
			  close:false, 
			  draggable:false, 
			  zindex:15000,
			  visible:false
			} 
	);

var wineWarning = function(warningText)
{
	wineWarningDialog.setHeader("<div class=\"hd\"><div class=\"tl\"></div><span>Wine Event Issue</span><div class=\"tr\"></div></div>");

	var bodyText = '<div class="dialogWrap"><div class="column_D"><table class="warningFormat" border="0" cellspacing="0" cellpadding="0"><tr><td>' + warningText + '</td></tr></table></div></div>';
	
	wineWarningDialog.setBody(bodyText);
	wineWarningDialog.render(document.body);		
	wineWarningDialog.show();
}
var handleOK = function() 
{
	wineWarningDialog.hide();
	LoadingContainer.hide();
}

var wineWarningDialog = new YAHOO.widget.SimpleDialog("warningDialog", 
						{	 
						width: "350px", 
//							effect:{effect:YAHOO.widget.ContainerEffect.FADE, duration:0.25}, 
							fixedcenter:true,
					    	zIndex:15000,
					  		modal: true,
	              			constraintoviewport : true, 
						    visible:false,
							draggable:false, 
							buttons: [ { text:"OK", handler:handleOK, isDefault:true }]
						});	

// ----------------Full View - link to wine page-------------------------------------------------------------

function fullView(wineID)
{
	window.location = '/wine/'+wineID;
}

// ----------------------------------------------------For QuickView --------------------------------------------
function quickViewOut()
{
	QuickViewModule.hide();
}
var quickViewLoaded = function(o)
{
	LoadingContainer.hide();
	QuickViewModule.show();	
};
var quickViewStart = function(o)
{ 
	LoadingContainer.show();
};
var quickViewSuccess = function(o)
{ 
	var Response = o.responseText;
	if (Response.substring(0,7) == "[error]")
	{
		wineWarning(Response.substring(7,Response.length));	
	}
	else
	{
		QuickViewModule.setBody(o.responseText);
		YAHOO.util.Event.addListener("QVWineImage", "load", quickViewLoaded);   // once the wine image is loaded, we're good to show
	}
};
var quickViewFailure = function(o)
{ 
	LoadingContainer.hide();
	wineWarning("There was a communication error on the WineMcGee servers. Please try again later.");
};
var quickViewAbort = function(o)
{ 
	LoadingContainer.hide();
	wineWarning("There was a communication error on the WineMcGee servers. Please try again later.");
};

function quickView(wineID)
{
	var callback = 
	{
		success:quickViewSuccess,
		failure:quickViewFailure,
		customevents: { onStart: quickViewStart },
		timeout: 5000
	}
	
	YAHOO.util.Connect.initHeader('X-Signature', transaction_sig); 
	var cObj = YAHOO.util.Connect.asyncRequest('POST', '/quickview_s.php', callback, 'wineID='+wineID); 
	return false;
}
// ------------------------------------ Delete Photo -----------------------------------------------------------

var deletePhotoStart = function(o)
{ 
	LoadingContainer.show();
};
var deletePhotoSuccess = function(o)
{ 
	var Response = o.responseText;
	if (Response.substring(0,7) == "[error]")
	{
		wineWarning(Response.substring(7,Response.length));	
	}
	else
	{
		// now call photo layout script		
		var callback = 
		{
			success: photoLayoutSuccess,
			failure: photoLayoutFailure,
			customevents: { onStart: photoLayoutStart },
			timeout: 5000
		}
		
		YAHOO.util.Connect.initHeader('X-Signature', transaction_sig); 
		var cObj = YAHOO.util.Connect.asyncRequest('POST', '/photolayout_s.php', callback, 'type=4&uniqueID='+eventID);	
	}
};
var deletePhotoFailure = function(o)
{ 
	LoadingContainer.hide();
	wineWarning("There was a communication error on the WineMcGee servers. Please try again later.");
};

function deletePhoto(photo_id)
{
	var callback = 
	{
		success: deletePhotoSuccess,
		failure: deletePhotoFailure,
		customevents: { onStart: deletePhotoStart },
		timeout: 5000
	}
		
	YAHOO.util.Connect.initHeader('X-Signature', transaction_sig); 
	var cObj = YAHOO.util.Connect.asyncRequest('POST', '/deletephoto_s.php', callback, 'photoID='+photo_id); 	
}

// ------------------------------------ Delete Comment -----------------------------------------------------------
var deleteCommentStart = function(o)
{ 
	LoadingContainer.show();
};
var deleteCommentSuccess = function(o)
{ 
	var Response = o.responseText;
	if (Response.substring(0,7) == "[error]")
	{
		wineWarning(Response.substring(7,Response.length));	
	}
	else
	{
		// now call load comments script		
		callback = 
		{
			success: commentsSuccess,
			failure: commentsFailure,
			customevents: { onStart: commentsStart },
			timeout: 5000
		}
		
		YAHOO.util.Connect.initHeader('X-Signature', transaction_sig); 
		var cObj = YAHOO.util.Connect.asyncRequest('POST', '/loadcomments_s.php', callback, 'uniqueID='+eventID+'&type=0'); 								
	}
};
var deleteCommentFailure = function(o)
{ 
	LoadingContainer.hide();
	wineWarning("There was a communication error on the WineMcGee servers. Please try again later.");
};

function deleteComment(comment_id)
{
	var callback = 
	{
		success: deleteCommentSuccess,
		failure: deleteCommentFailure,
		customevents: { onStart: deleteCommentStart },
		timeout: 5000
	}
		
		YAHOO.util.Connect.initHeader('X-Signature', transaction_sig); 
		var cObj = YAHOO.util.Connect.asyncRequest('POST', '/deletecomment_s.php', callback, 'commentID='+comment_id); 	
}

// ------------------------------------ Report Abuse -----------------------------------------------------------
var reportAbuseStart = function(o)
{ 
	LoadingContainer.show();
};
var reportAbuseSuccess = function(o)
{ 
	var Response = o.responseText;
	if (Response.substring(0,7) == "[error]")
	{
		wineWarning(Response.substring(7,Response.length));	
	}
	else
	{
		wineWarning("Thank you for reporting abuse.  We will review this posting.");	
	}
};
var reportAbuseFailure = function(o)
{ 
	LoadingContainer.hide();
	wineWarning("There was a communication error on the WineMcGee servers. Please try again later.");
};

function reportAbuse(comment_id)
{
	var callback = 
	{
		success: reportAbuseSuccess,
		failure: reportAbuseFailure,
		customevents: { onStart: reportAbuseStart },
		timeout: 5000
	}
	
	YAHOO.util.Connect.initHeader('X-Signature', transaction_sig); 
	var cObj = YAHOO.util.Connect.asyncRequest('POST', '/reportabuse_s.php', callback, 'commentID='+comment_id+'&type=0'); 	
}
// ------------------------------------ Post Comment -----------------------------------------------------------
var postCommentStart = function(o)
{ 
	LoadingContainer.show();
};
var postCommentSuccess = function(o)
{ 
	var Response = o.responseText;
	if (Response.substring(0,7) == "[error]")
	{
		wineWarning(Response.substring(7,Response.length));	
	}
	else
	{
		// now call load comments script		
		callback = 
		{
			success: commentsSuccess,
			failure: commentsFailure,
			customevents: { onStart: commentsStart },
			timeout: 5000
		}
		
		YAHOO.util.Connect.initHeader('X-Signature', transaction_sig); 
		var cObj = YAHOO.util.Connect.asyncRequest('POST', '/loadcomments_s.php', callback, 'uniqueID='+eventID+'&type=0'); 								
		
		document.getElementById("commentText").value = ""; // clear comment text
	}
};
var postCommentFailure = function(o)
{ 
	LoadingContainer.hide();
	wineWarning("There was a communication error on the WineMcGee servers. Please try again later.");
};

function postComment()
{
	comment = document.getElementById("commentText").value;
	if (comment.length > 0 && comment!="Enter your comment")
	{
		var callback = 
		{
			success: postCommentSuccess,
			failure: postCommentFailure,
			customevents: { onStart: postCommentStart },
			timeout: 5000
		}
		
		YAHOO.util.Connect.initHeader('X-Signature', transaction_sig); 
		var cObj = YAHOO.util.Connect.asyncRequest('POST', '/postcomment_s.php', callback, 'comment='+comment+'&uniqueID='+eventID+'&type=0'); 	
 	
	}
}

// -------------------------- get comments (using summarized links on bottom of page------------------------------------
function getComments(comment_id)
{
	callback = 
	{
		success: commentsSuccess,
		failure: commentsFailure,
		customevents: { onStart: commentsStart },
		timeout: 5000
	}
		
	YAHOO.util.Connect.initHeader('X-Signature', transaction_sig); 
	var cObj = YAHOO.util.Connect.asyncRequest('POST', '/loadcomments_s.php', callback, 'uniqueID='+eventID+'&type=0&commentStart='+comment_id); 								
		
	document.getElementById("commentText").value = ""; // clear comment text
}

// ------------------------------------ Comments -----------------------------------------------------------
	
var commentsStart = function(o)
{ 
	LoadingContainer.show();
};
var commentsSuccess = function(o)
{ 
	var Response = o.responseText;
	if (Response.substring(0,7) == "[error]")
	{
		wineWarning(Response.substring(7,Response.length));	
	}
	else
	{
		document.getElementById("comments").innerHTML = o.responseText;
		
		// set up tool tips
		
		/*
		var elements = YAHOO.util.Dom.getElementsByClassName('theEventImage', 'img'); 	
		// img is optional and speeds up the search		
		var imgElementArray = new Array();
		var a = 0;
		for (a = 0; a < elements.length; a++)
		{
			imgElementArray[a] = elements[a].id;
		}	
		
		if (toolTip)
		{
			toolTip.cfg.setProperty("context", imgElementArray);
			toolTip.forceUnderlayRedraw();
		}
		else if (imgElementArray.length > 0)
		{
			toolTip = new YAHOO.widget.Tooltip("tooltip", 
											{ context: imgElementArray,
									  		  effect: {effect:YAHOO.widget.ContainerEffect.FADE,duration:0.20}
											});					
		}
		*/
/*		if (toolTip)
		{
			toolTip.destroy();
		}
		if (imgElementArray.length > 0)
		{
			toolTip = new YAHOO.widget.Tooltip("tooltip", 
										{ context: imgElementArray,
								  		  effect: {effect:YAHOO.widget.ContainerEffect.FADE,duration:0.20}
										});					
		}
	*/	
	}
	LoadingContainer.hide();
};
var commentsFailure = function(o)
{ 
	LoadingContainer.hide();
	wineWarning("There was a communication error on the WineMcGee servers. Please try again later.");
};
	
// ------------------------------------ Photo Layout -----------------------------------------------------------
	
var photoLayoutStart = function(o)
{ 
	LoadingContainer.show();
};
var photoLayoutSuccess = function(o)
{ 
	var Response = o.responseText;
	if (Response.substring(0,7) == "[error]")
	{
		wineWarning(Response.substring(7,Response.length));	
	}
	else
	{
		document.getElementById("photoArea").innerHTML = o.responseText;
		
		// set up tool tips
			/*
		var elements = YAHOO.util.Dom.getElementsByClassName('theEventImage', 'img'); 	
		// img is optional and speeds up the search		
		var imgElementArray = new Array();
		var a = 0;
		for (a = 0; a < elements.length; a++)
		{
			imgElementArray[a] = elements[a].id;
		}	

		if (toolTip)
		{
			toolTip.cfg.setProperty("context", imgElementArray);
			toolTip.forceUnderlayRedraw();
		}
		else if (imgElementArray.length > 0)
		{
			toolTip = new YAHOO.widget.Tooltip("tooltip", 
											{ context: imgElementArray,
									  		  effect: {effect:YAHOO.widget.ContainerEffect.FADE,duration:0.20}
											});					
		}
		*/
/*
		if (toolTip)
		{
			toolTip.destroy();
		}
		if (imgElementArray.length > 0)
		{	
			toolTip = new YAHOO.widget.Tooltip("tooltip", 
												{ context: imgElementArray,
										  		  effect: {effect:YAHOO.widget.ContainerEffect.FADE,duration:0.20}
												});					
		}
		
		*/
	}
	LoadingContainer.hide();
};
var photoLayoutFailure = function(o)
{ 
	LoadingContainer.hide();
	wineWarning("There was a communication error on the WineMcGee servers. Please try again later.");
};
	
// ------------------------------------ Zoom for Images ----------------------------------------------

// when they clicked on a zoomed in event image
function wineImageOut()
{
	bigImageOut = 1;
	document.getElementById("bigImage").style.cursor = "default";
	document.getElementById("picMod").style.cursor = "default";
	PictureModule.hide();
}

var magnifyOver = function()
{
	timeoutID = setTimeout("magnifyStillIn()",500);
	overImage = 1;
	document.getElementById("magnifyImg").src='/wineempty.gif';
};
var magnifyOut = function(o)
{
	document.getElementById("magnifyImg").style.cursor = "url('/magcursor.cur'), default";
	document.getElementById("magnifyImg").src='/wineempty.gif';
	overImage = 0;
	clearTimeout(timeoutID);
};
function magnifyStillIn()
{
	wineBigImageIn();
	overImage = 2;
}

var wineSmallImageOut = function(o)
{
	document.getElementById("magnifyImg").src='/wineempty.gif';
};

var wineImageLoaded = function(o)
{
	PictureModule.show();	
};
// show zoomed in event image
function wineImageIn(imageElement, bigImage)
{
	bigImageFile = bigImage;
	xyID = imageElement.id;
	x = YAHOO.util.Dom.getX(xyID);
	y = YAHOO.util.Dom.getY(xyID);
	
	PictureModule.cfg.setProperty("x", x);
	PictureModule.cfg.setProperty("y", y);
	
	if (bigImageOut == 0)  // if it's 0, then we never left the zoom feature, so load the new image.
	{
		wineBigImageIn();
	}
	else
	{
		MagModule.cfg.setProperty("x",x+50);
		MagModule.cfg.setProperty("y",y+50);	
	MagModule.setBody("<div class=\"magModule\"><img id='magnifyImg' onmouseover='magnifyOver();' onmouseout='magnifyOut();' onclick='wineBigImageIn();' src='/macgif2.gif'></div>");
		MagModule.render(document.body);													  
		MagModule.show();
	}
}
var wineBigImageIn = function()
{		
	bigImageOut = 0;
	PictureModule.setBody("<div id=\"picMod\" class=\"pictureModule\"><img id=\"bigImage\" src=\""+bigImageFile+"\" /></div>");
	document.getElementById("bigImage").style.cursor = "url('/zoomout.cur'), default";
	document.getElementById("picMod").style.cursor = "url('/zoomout.cur'), default";
	YAHOO.util.Event.addListener("bigImage", "load", wineImageLoaded);   // once the wine image is loaded, we're good to show
	document.getElementById("magnifyImg").style.cursor = "url('/zoomout.cur'), default";
};
	
// ------------------------------------ Upload Dialog -----------------------------------------------------------

var handleSubmit = function()   //when the submit button is clicked, submit the form
{   
	var formObject = document.getElementById("imageform");  
	YAHOO.util.Connect.setForm(formObject, true);  
	
	var callback = 
	{
		upload: onUpload,
		failure: onFailure,
		timeout: 25000,
		cache: false
	};
		
	var cObj = YAHOO.util.Connect.asyncRequest('POST', '/eventimageuploadweb.php', callback, 'eventID='+eventID); 
	uploadDialog.hide();
	LoadingContainer.show();
};   
var handleCancel = function()   // if the cancel button is clicked, cancel the form
{   
    uploadDialog.cancel();   
};   
var onFailure = function(o)
{
	LoadingContainer.hide();
	wineWarning("Your upload timed out and was aborted. Your image may be too big, slick.");
};

// onUpload is called upon completion of upload transaction
var onUpload = function(o)
{
	LoadingContainer.hide();
	var Response = o.responseText;
	if (Response.substring(0,7) == "[error]")
	{
		wineWarning(Response.substring(7,Response.length));	
	}
	else
	{	
		// now call photo layout script		
		var callback = 
		{
			success: photoLayoutSuccess,
			failure: photoLayoutFailure,
			customevents: { onStart: photoLayoutStart },
			timeout: 5000
		}
		
		YAHOO.util.Connect.initHeader('X-Signature', transaction_sig); 
		var cObj = YAHOO.util.Connect.asyncRequest('POST', '/photolayout_s.php', callback, 'type=4&uniqueID='+eventID);	
	}
}

// ------------------------------------ Guest List  -----------------------------------------------------------


var guestListStart = function(o)
{ 
	LoadingContainer.show();
};
var guestListSuccess = function(o)
{ 
	var Response = o.responseText;
	if (Response.substring(0,7) == "[error]")
	{
		wineWarning(Response.substring(7,Response.length));	
	}
	else
	{
		document.getElementById("guestList").innerHTML = o.responseText; 
	}
	LoadingContainer.hide();
};
var guestListFailure = function(o)
{ 
	LoadingContainer.hide();
	wineWarning("There was a communication error on the WineMcGee servers. Please try again later.");
};


// ------------------------------------ RSVP  -----------------------------------------------------------


var rsvpStart = function(o)
{ 
	LoadingContainer.show();
};
var rsvpSuccess = function(o)
{ 
	var Response = o.responseText;
	if (Response.substring(0,7) == "[error]")
	{
		wineWarning(Response.substring(7,Response.length));	
	}
	else
	{
		// now call load comments script		
		callback = 
		{
			success: guestListSuccess,
			failure: guestListFailure,
			customevents: { onStart: guestListStart },
			timeout: 5000
		}
		
		YAHOO.util.Connect.initHeader('X-Signature', transaction_sig); 
		var cObj = YAHOO.util.Connect.asyncRequest('POST', '/eventguestlist.php', callback, 'eventID='+eventID); 		
	}
};
var rsvpFailure = function(o)
{ 
	LoadingContainer.hide();
	wineWarning("There was a communication error on the WineMcGee servers. Please try again later.");
};


function rsvpClicked()
{
	var sortGroup = document.getElementsByName("rsvp");
	var rsvp = 0;
	for( i = 0; i < sortGroup.length; i++ )
	{
		if( sortGroup[i].checked == true )
		{
			rsvp = sortGroup[i].value;
			break;
		}
	}	
	
	var callback = 
	{
		success: rsvpSuccess,
		failure: rsvpFailure,
		customevents: { onStart: rsvpStart },
		timeout: 5000
	}
		
	YAHOO.util.Connect.initHeader('X-Signature', unique_sig); 
	var cObj = YAHOO.util.Connect.asyncRequest('POST', '/eventrsvp.php', callback, 'rsvp='+rsvp+'&eventID='+eventID); 	
	
}

// -------------------------- get next/prev wines (using summarized links on bottom of page------------------------------------
function getWines(wine_id)
{
	callback = 
	{
		success: wineSearchSuccess,
		failure: wineSearchFailure,
		customevents: { onStart: wineSearchStart },
		timeout: 5000
	}
		
	var postData = "eventID=" + eventID;
	postData+= "&winesearch="+lastWineSearch;		
	postData+= "&wineStart="+wine_id;		
		
	YAHOO.util.Connect.initHeader('X-Signature', transaction_sig); 
	var cObj = YAHOO.util.Connect.asyncRequest('POST', '/winesearchnew_s.php', callback, postData); 
}

// --------------------- search for wines in this event wine list -----------------------------------------------

var wineSearchStart = function(o)
{ 
	LoadingContainer.show();
};
var wineSearchSuccess = function(o)
{ 
	var Response = o.responseText;
	if (Response.substring(0,7) == "[error]")
	{
		wineWarning(Response.substring(7,Response.length));	
	}
	else
	{
		document.getElementById("wineSearchResults").innerHTML = o.responseText;	
	}
	LoadingContainer.hide();
};

var wineSearchFailure = function(o)
{ 
	wineWarning("There was a communication error on the WineMcGee servers. Please try again later.");
}

function prepareSubmit()
{
	var formObject = document.getElementById('wineForm');
	YAHOO.util.Connect.setForm(formObject); 
	lastWineSearch = document.getElementById('wineSearchEdit').value;
	
	var callback = 
	{
		success:wineSearchSuccess,
		failure:wineSearchFailure,
		customevents: { onStart: wineSearchStart },
		timeout: 10000
	}
	
	var postData = "eventID=" + eventID;
	
	YAHOO.util.Connect.initHeader('X-Signature', transaction_sig); 
	var cObj = YAHOO.util.Connect.asyncRequest('POST', '/winesearchnew_s.php', callback, postData); 
	return false;
}

// ------------------------------------ Show Ticket Desc-----------------------------------------------------------

function showDescription(ticket)
{
	disp = document.getElementById("desc"+ticket).style.display;
	if (disp == "block")
	{
		document.getElementById("desc"+ticket).style.display = "none";
	}
	else
	{
		document.getElementById("desc"+ticket).style.display = "block";		
	}
}

// ------------------------------------ Register for Event ----------------------------------------------

var registerSuccess = function(o)
{ 
	var Response = o.responseText;
	if (Response.substring(0,7) == "[error]")
	{
		wineWarning(Response.substring(7,Response.length));	
	}
	else
	{
		document.getElementById("ticketRest").innerHTML = o.responseText;	
	}
	LoadingContainer.hide();
};

function register()
{
	var formObject = document.getElementById('ticketForm');
	YAHOO.util.Connect.setForm(formObject); 
	
	var callback = 
	{
		success:registerSuccess,
		failure:wineSearchFailure,
		customevents: { onStart: wineSearchStart },
		timeout: 10000
	}
	
	var postData = "eventID=" + eventID;
	postData += "&inviteCode=" + inviteCode;
	
	YAHOO.util.Connect.initHeader('X-Signature', transaction_sig); 
	var cObj = YAHOO.util.Connect.asyncRequest('POST', '/eventregister_s.php', callback, postData); 
	return false;
}

// ------------------------------------ Register Process and Checkout------------------------------------

var registerProcessSuccess = function(o)
{ 
	var Response = o.responseText;
	if (Response.substring(0,7) == "[error]")
	{
		wineWarning(Response.substring(7,Response.length));	
		LoadingContainer.hide();		
	}
	else if (Response.substring(0,7) == "[regis]")
	{
		var loc = '/eventrsvpconfirm.php?eventID='+eventID;
		if (inviteCode.length > 0)
		{
			loc = locl + '&inviteCode='+inviteCode;					
		}				   
		window.location = loc; 
	}
	else
	{
		LoadingContainer.setBody('<img src="/Images/ajaxload.gif" /> Preparing Payment...');
		document.getElementById("loadingDialog").style.backgroundColor = "white";
		document.getElementById("loadingDialog").style.border = "1px solid #999999";
		LoadingContainer.render(document.body);
		LoadingContainer.show(); 
			
		document.getElementById("ticketPay").innerHTML = o.responseText;			
		document.getElementById("ticketPayment").submit();		
	}
};

function regCheckout()
{
	var formObject = document.getElementById('registerForm');
	YAHOO.util.Connect.setForm(formObject); 
	
	var callback = 
	{
		success:registerProcessSuccess,
		failure:wineSearchFailure,
		customevents: { onStart: wineSearchStart },
		timeout: 10000
	}
	
	var postData = "eventID=" + eventID;
	postData += "&inviteCode=" + inviteCode;
	
	YAHOO.util.Connect.initHeader('X-Signature', transaction_sig); 
	var cObj = YAHOO.util.Connect.asyncRequest('POST', '/regcheckout_s.php', callback, postData); 
	return false;

	
}

var checkoutProcessSuccess = function(o)
{ 
	var Response = o.responseText;
	if (Response.substring(0,7) == "[error]")
	{
		wineWarning(Response.substring(7,Response.length));	
		LoadingContainer.hide();		
	}
	else
	{
		LoadingContainer.setBody('<img src="/Images/ajaxload.gif" /> Preparing Payment...');
		document.getElementById("loadingDialog").style.backgroundColor = "white";
		document.getElementById("loadingDialog").style.border = "1px solid #999999";
		LoadingContainer.render(document.body);
		LoadingContainer.show(); 
			
		document.getElementById("ticketPay").innerHTML = o.responseText;			
		document.getElementById("ticketPayment").submit();		
	}
};

function checkout()
{
	var formObject = document.getElementById('ticketForm');
	YAHOO.util.Connect.setForm(formObject); 
	
	var callback = 
	{
		success:checkoutProcessSuccess,
		failure:wineSearchFailure,
		customevents: { onStart: wineSearchStart },
		timeout: 10000
	}
	
	var postData = "eventID=" + eventID;
	postData += "&inviteCode=" + inviteCode;
	
	YAHOO.util.Connect.initHeader('X-Signature', transaction_sig); 
	var cObj = YAHOO.util.Connect.asyncRequest('POST', '/checkout_s.php', callback, postData); 
	return false;

	
}
// ------------------------------------ RSVP (non-ticketed event)--------------------------------

var rsvpBlankSuccess = function(o)
{ 
	var Response = o.responseText;
	if (Response.substring(0,7) == "[error]")
	{
		wineWarning(Response.substring(7,Response.length));	
		LoadingContainer.hide();		
	}
	else
	{
		wineWarning("Thank you for submitting your RSVP. You should receive an email shortly to confirm your RSVP. You may wish to follow up directly with the event host to confirm your reservation or ask any questions you may have.");	
	}
}

function rsvpBlankFormSubmit()
{
	var formObject = document.getElementById('rsvpBlankForm');
	YAHOO.util.Connect.setForm(formObject); 
	
	var callback = 
	{
		success:rsvpBlankSuccess,
		failure:wineSearchFailure,
		customevents: { onStart: wineSearchStart },
		timeout: 10000
	}
	
	var postData = "eventID=" + eventID;
	
	YAHOO.util.Connect.initHeader('X-Signature', transaction_sig); 
	var cObj = YAHOO.util.Connect.asyncRequest('POST', '/rsvpblank_s.php', callback, postData); 
	return false;

	
}

// ------------------------------------ Google Maps ----------------------------------------------------

function addAddressToMap(response)
{
	map.clearOverlays();
	if (!response || response.Status.code != 200) // address not found
	{
		wineWarning("The event address could not be found.  Please alert WineMcGee support of the problem.  We'll ensure the event host corrects the address!");
	}
	else
	{
		var place = response.Placemark[0];
		var point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
		var marker = new GMarker(point);
		map.addOverlay(marker);
//		marker.openInfoWindowHtml(place.address);
		map.setCenter(point, 13);
	}
}
	
function showLocation()
{		  
	geocoder.getLocations(fullEventAddress, addAddressToMap);			  
}

// ------------------------------------ Init -----------------------------------------------------------

function init()
{
	LoadingContainer.setBody('<img src="/Images/ajaxload.gif" />');
	LoadingContainer.render(document.body);
	
	AttendeeModule = new YAHOO.widget.Module("AttendeeRegion", { visible: false });  
	AttendeeModule.render();   
	showAttendeeRegion = new YAHOO.widget.Module("showAttendeeRegion", { visible: true });  
	showAttendeeRegion.render();   
	YAHOO.util.Event.addListener("showAttendeeRegion", "mouseover", regionMouseOver, document.getElementById("downArrowAttendee"));
	YAHOO.util.Event.addListener("showAttendeeRegion", "mouseout", regionMouseOut, document.getElementById("downArrowAttendee"));

	AttendeeModuleTwo = new YAHOO.widget.Module("AttendeeRegionTwo", { visible: false });  
	AttendeeModuleTwo.render();   
	showAttendeeRegionTwo = new YAHOO.widget.Module("showAttendeeRegionTwo", { visible: true });  
	showAttendeeRegionTwo.render();   
	YAHOO.util.Event.addListener("showAttendeeRegionTwo", "mouseover", regionMouseOver, document.getElementById("downArrowAttendeeTwo"));
	YAHOO.util.Event.addListener("showAttendeeRegionTwo", "mouseout", regionMouseOut, document.getElementById("downArrowAttendeeTwo"));

	PhotoModule = new YAHOO.widget.Module("PhotoRegion", { visible: false });  
	PhotoModule.render();   
	showPhotoRegion = new YAHOO.widget.Module("showPhotoRegion", { visible: true });  
	showPhotoRegion.render();   
	YAHOO.util.Event.addListener("showPhotoRegion", "mouseover", regionMouseOver, document.getElementById("downArrowPhoto"));
	YAHOO.util.Event.addListener("showPhotoRegion", "mouseout", regionMouseOut, document.getElementById("downArrowPhoto"));
	
	if (!browserIE)
	{
	    QuickViewModule = new YAHOO.widget.Panel("QVPanel", { 
										  fixedcenter:true,	
										  effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.25},
										  width: "600px", 
										  visible:false 
  	 								      });   	
		// fade causes text to not anti-alias in IE (<= 7)
	}
	else
	{
	    QuickViewModule = new YAHOO.widget.Panel("QVPanel", { 
										  fixedcenter:true,	
										  width: "600px", 
										  visible:false 
  	 								      });   		
	}

	QuickViewModule.setHeader("<div class=\"hd\"><div class=\"tl\"></div><span>Wine Quick View</span><div class=\"tr\"></div></div>");
	QuickViewModule.setBody("");
	QuickViewModule.render(document.body);													  
	YAHOO.util.Event.addListener("QVPanel", "click", quickViewOut);
			
	uploadDialog = new YAHOO.widget.Dialog("uploadDialog",  
	            { width : "350px", 
	              fixedcenter : true, 
	              visible : false,  
				  zIndex:15000,
				  modal: true,
	              constraintoviewport : true, 
	              buttons : [ { text:"Submit", handler:handleSubmit, isDefault:true }, 
	                          { text:"Cancel", handler:handleCancel } ] 
	             } ); 

	uploadDialog.render(document.body);
	
	document.getElementById("sig").value = unique_sig; // set the form security signature for image uploads
	
// -------- overlay for picture expand ------------------------
    PictureModule = new YAHOO.widget.Overlay("picture1", { 
										  xy:[-2000,-2000],	
								  		  effect: {effect:YAHOO.widget.ContainerEffect.FADE,duration:0.40},
										  visible:false 
  	 								      });   	
										  												  
	PictureModule.setBody("<div id=\"picMod\" class=\"pictureModule\"></div>");
	PictureModule.render(document.body);													  
	YAHOO.util.Event.addListener("picture1", "click", wineImageOut);
	YAHOO.util.Event.addListener("picture1", "mouseOut", wineImageOut);
	PictureModule.cfg.setProperty("zindex", 99999);
	
    MagModule = new YAHOO.widget.Overlay("magnify", { 
										  xy:[-2000,-2000],	
										  visible:false 
  	 								      });   	

	MagModule.cfg.setProperty("zindex", 88888);
	MagModule.setBody("<div class=\"magModule\"><img id='magnifyImg' onmouseover='magnifyOver();' onmouseout='magnifyOut();' onclick='wineBigImageIn();' src='/macgif2.gif'></div>");
	MagModule.render(document.body);	

/*
	// load toolTips
	var elements = YAHOO.util.Dom.getElementsByClassName('theEventImage', 'img'); 	
	// img is optional and speeds up the search		
	var imgElementArray = new Array();
	var a = 0;
	for (a = 0; a < elements.length; a++)
	{
		imgElementArray[a] = elements[a].id;
	}	

	if (toolTip)
	{
		toolTip.cfg.setProperty("context", imgElementArray);
		toolTip.forceUnderlayRedraw();
	}
	else if (imgElementArray.length > 0)
	{
		toolTip = new YAHOO.widget.Tooltip("tooltip", 
										{ context: imgElementArray,
								  		  effect: {effect:YAHOO.widget.ContainerEffect.FADE,duration:0.20}
										});					
	}	

*/
	// load wine list expander
	WineListModule = new YAHOO.widget.Module("WineListRegion", { visible: false });  
	WineListModule.render();   
	showWineListRegion = new YAHOO.widget.Module("showWineListRegion", { visible: true });  
	showWineListRegion.render();   
	YAHOO.util.Event.addListener("showWineListRegion", "mouseover", regionMouseOver, document.getElementById("downArrowWineList"))	;
	YAHOO.util.Event.addListener("showWineListRegion", "mouseout", regionMouseOut, document.getElementById("downArrowWineList"));		
	
	
	YAHOO.util.Event.addListener("rsvp1", "click", rsvpClicked);
	YAHOO.util.Event.addListener("rsvp2", "click", rsvpClicked);
	YAHOO.util.Event.addListener("rsvp3", "click", rsvpClicked);

	YAHOO.util.Event.addListener("searchSubmit", "click", prepareSubmit);
	
	if (!notFound)  // only do the map if we've found the event
	{
	
		if (GBrowserIsCompatible())
		{
			map = new GMap2(document.getElementById("map_canvas"));
	//		map.setCenter(new GLatLng(34,0), 8);
	        map.setUIToDefault();
			map.disableScrollWheelZoom();

			geocoder = new GClientGeocoder();
		
			showLocation();

		}
	}
}

YAHOO.util.Event.onDOMReady(init);

var DownArrowGray = new Image;
var DownArrow = new Image;
DownArrow.src="/Images/downarrow.gif";
DownArrowGray.src="/Images/downarrowgray.gif";
var UpArrowGray = new Image;
var UpArrow = new Image;
UpArrow.src="/Images/uparrow.gif";
UpArrowGray.src="/Images/uparrowgray.gif";

var uploadImage = new Image;
var uploadImageOff = new Image;
uploadImage.src="/Images/uploadButton.gif";
uploadImageOff.src="/Images/uploadButtonOff.gif";


