// JavaScript Document

var WineListModule = null;
var showWineListRegion = null;
var AttendeeModule = null;
var showAttendeeRegion = null;
var showNewsRegion = null;
var PhotoModule = null;
var showPhotoRegion = null;
var QuickViewModule = null;
var uploadDialog = null;
var toolTip = null;
var toolTip2 = null;
var PictureModule = null;
var promptWarningDialog = null;
var promptPath = 0;

var messageDialog = null;
var messageUser = 0;

var MagModule = null;
var bigImageOut = 1;
var overImage = 0;

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;
}

// ---------------------------------- Get McGeeName --------------------------------------------------

var getMcGeeNameSuccess = function(o)
{ 
	LoadingContainer.hide();
	var Response = o.responseText;
	if (Response.substring(0,7) == "[error]")
	{
		wineWarning(Response.substring(7,Response.length), "Message Error");	
	}
	else
	{
		document.getElementById("toName").innerHTML = o.responseText;		
		messageDialog.show();
	}
};

function messageMe(userID)
{
	document.getElementById("subjectEdit").value = "";
	messageUser = userID;

	var callback = 
	{
		success: getMcGeeNameSuccess,
		failure: quickViewFailure,
		customevents: { onStart: quickViewStart },
		timeout: 5000
	}
		
	YAHOO.util.Connect.initHeader('X-Signature', transaction_sig); 
	var cObj = YAHOO.util.Connect.asyncRequest('POST', '/getmcgeename_s.php', callback, 'userID='+userID); 	
}

// ------------------------------------ Follow Me -----------------------------------------------------------

var followMeSuccess = function(o)
{ 
	LoadingContainer.hide();
	var Response = o.responseText;
	if (Response.substring(0,7) == "[error]")
	{
		wineWarning(Response.substring(7,Response.length), "Follow Issue");	
	}
	else
	{
		wineWarning("You are now following this user.  Updates on wine reviews, wine talk, questions and answers will appear within the Recent Happenings section on your profile.", "Follow Me");			
	}
};

function followMe(followID)
{
	var callback = 
	{
		success: followMeSuccess,
		failure: quickViewFailure,
		customevents: { onStart: quickViewStart },
		timeout: 5000
	}
		
	YAHOO.util.Connect.initHeader('X-Signature', transaction_sig); 
	var cObj = YAHOO.util.Connect.asyncRequest('POST', '/followme_s.php', callback, 'userID='+followID); 	
}

// ------------------------------ News Region - to expand and contract ---------------------------
function showNewsList()  
{
	if (!NewsModule.cfg.getProperty("visible"))
	{
		NewsModule.show();
		document.getElementById("showNewsRegion").innerHTML = "<img id=\"upArrowNews\" src=\"/Images/uparrow.gif\" alt=\"up arrow\"/>Show Less Happenings";
		YAHOO.util.Event.addListener("showNewsRegion", "mouseover", regionMouseOverUp, document.getElementById("upArrowNews"));
		YAHOO.util.Event.addListener("showNewsRegion", "mouseout", regionMouseOutUp, document.getElementById("upArrowNews"));
	}
	else
	{
		NewsModule.hide();
		document.getElementById("showNewsRegion").innerHTML = "<img id=\"downArrowNews\" src=\"/Images/downarrow.gif\" alt=\"down arrow\"/>Show More Happenings";
		YAHOO.util.Event.addListener("showNewsRegion", "mouseover", regionMouseOver, document.getElementById("downArrowNews"));
		YAHOO.util.Event.addListener("showNewsRegion", "mouseout", regionMouseOut, document.getElementById("downArrowNews"));
	}
	document.getElementById("showNewsRegion").className = 'tabText';
}
// ------------------------------ Attendee list is Friends List - to expand and contract ---------------------------
function showAttendeeList()  
{
	if (!AttendeeModule.cfg.getProperty("visible"))
	{
		AttendeeModule.show();
		document.getElementById("showAttendeeRegion").innerHTML = "<img id=\"upArrowAttendee\" src=\"/Images/uparrow.gif\" alt=\"up arrow\"/>Show Less Friends";
		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 More Friends";
		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';
}

// ----------------------------------------------------- Photo expand and contract ---------------------------
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 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>Profile 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, 'userID='+viewUserID+'&type=6&uniqueID=-1'); 						
	}
};
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='+viewUserID+'&type=1'); 								
	}
};
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=1'); 	
}

// ------------------------------------ Accept Friend -----------------------------------------------------------
	
var loadFriendRequestsStart = function(o)
{ 
	LoadingContainer.show();
};
var loadFriendRequestsSuccess = function(o)
{ 
	var Response = o.responseText;
	if (Response.substring(0,7) == "[error]")
	{
		wineWarning(Response.substring(7,Response.length));	
	}
	else
	{		
		document.getElementById("friendRequests").innerHTML = o.responseText;		
		getFriends(0);
	}
	LoadingContainer.hide();
};
var loadFriendRequestsFailure = function(o)
{ 
	LoadingContainer.hide();
	wineWarning("There was a communication error on the WineMcGee servers. Please try again later.");
};
// ------------------------------------ Accept Friend -----------------------------------------------------------
	
var acceptFriendStart = function(o)
{ 
	LoadingContainer.show();
};
var acceptFriendSuccess = function(o)
{ 
	var Response = o.responseText;
	if (Response.substring(0,7) == "[error]")
	{
		wineWarning(Response.substring(7,Response.length));	
	}
	else
	{		
		wineWarning("Friend request accepted!", "You have a new friend");		
	}
	LoadingContainer.hide();
};
var ignoreFriendSuccess = function(o)
{ 
	var Response = o.responseText;
	if (Response.substring(0,7) == "[error]")
	{
		wineWarning(Response.substring(7,Response.length));	
	}
	else
	{		
		wineWarning("The friend request will be ignored and discarded.", "Ignore Complete");		
	}
	LoadingContainer.hide();
};
var acceptFriendFailure = function(o)
{ 
	LoadingContainer.hide();
	wineWarning("There was a communication error on the WineMcGee servers. Please try again later.");
};
function acceptFriend(friendID)
{
	callback = 
	{
		success: acceptFriendSuccess,
		failure: acceptFriendFailure,
		customevents: { onStart: acceptFriendStart },
		timeout: 5000
	}	
	
	YAHOO.util.Connect.initHeader('X-Signature', transaction_sig); 
	var cObj = YAHOO.util.Connect.asyncRequest('POST', '/acceptfriend_s.php', callback, 'userID='+friendID); 										
}
function ignoreFriend(friendID)
{
	callback = 
	{
		success: ignoreFriendSuccess,
		failure: acceptFriendFailure,
		customevents: { onStart: acceptFriendStart },
		timeout: 5000
	}	
	
	YAHOO.util.Connect.initHeader('X-Signature', transaction_sig); 
	var cObj = YAHOO.util.Connect.asyncRequest('POST', '/ignorefriend_s.php', callback, 'userID='+friendID); 										
}

// ------------------------------------ Friend Request -----------------------------------------------------------
var friendRequestStart = function(o)
{ 
	LoadingContainer.show();
};
var friendRequestSuccess = function(o)
{ 
	var Response = o.responseText;
	if (Response.substring(0,7) == "[error]")
	{
		wineWarning(Response.substring(7,Response.length));	
	}
	else
	{
		wineWarning("Your Friend Request has been sent!  Once your friend approves the request, you'll be able to interact via WineMcGee.");	
	}
};
var friendRequestFailure = function(o)
{ 
	LoadingContainer.hide();
	wineWarning("There was a communication error on the WineMcGee servers. Please try again later.");
};

function friendRequest()
{
	var callback = 
	{
		success: friendRequestSuccess,
		failure: friendRequestFailure,
		customevents: { onStart: friendRequestStart },
		timeout: 5000
	}
	
	YAHOO.util.Connect.initHeader('X-Signature', transaction_sig); 
	var cObj = YAHOO.util.Connect.asyncRequest('POST', '/friendrequest_s.php', callback, '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='+viewUserID+'&type=1&commentStart='+comment_id); 
		
	
	if (document.getElementById("commentText"))
	{
		document.getElementById("commentText").value = ""; // clear comment text
	}
}


// ------------------------------------ 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='+viewUserID+'&type=1'); 
		
		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
		}
		
		comment = comment.replace("&", "%26");
		YAHOO.util.Connect.initHeader('X-Signature', transaction_sig); 
		var cObj = YAHOO.util.Connect.asyncRequest('POST', '/postcomment_s.php', callback, 'comment='+comment+'&uniqueID='+viewUserID+'&type=1'); 	
	}
}

// ------------------------------------ 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}
											});					
		}
	*/
	
	}
	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 (typeof(document.getElementById("PhotoRegion")) != 'undefined')
		{
			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"));
		}		
	}
	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: 180000,
		cache: false
	};
		
	var cObj = YAHOO.util.Connect.asyncRequest('POST', '/profilephotoupload_s.php', callback); 
	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, 'userID='+viewUserID+'&type=6&uniqueID=-1'); 						
	}
}

// ------------------------------------ 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.");
};


// ------------------------------------ Prompt for successful message send----------------------------------------------

var promptWarning = function(warningText, header)
{
	if (!header)
	{
		header = "Where to?"
	}
	
	promptWarningDialog.setHeader("<div class=\"hd\"><div class=\"tl\"></div><span>" + header + "</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>';
	
	promptWarningDialog.setBody(bodyText);
	promptWarningDialog.render(document.body);		
	promptWarningDialog.show();
}

var promptYes = function() 
{
	if (promptPath == 0)
	{
		// now call photo layout script		
		var callback = 
		{
			success: friendRemoveSuccess,
			failure: photoLayoutFailure,
			customevents: { onStart: photoLayoutStart },
			timeout: 5000
		}
		
		YAHOO.util.Connect.initHeader('X-Signature', transaction_sig); 
		var cObj = YAHOO.util.Connect.asyncRequest('POST', '/removefriend_s.php', callback, 'userID='+viewUserID);		
		
		promptWarningDialog.hide();		
	}
}
var promptNo = function() 
{
	if (promptPath == 0)
	{
		promptWarningDialog.hide();		
	}
}

promptWarningDialog = 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:"Yes", handler:promptYes, isDefault:true },
					  				   { text:"Cancel", handler:promptNo} ]
						});	

var friendRemoveSuccess = function(o)
{ 
	LoadingContainer.hide();
	var Response = o.responseText;
	if (Response.substring(0,7) == "[error]")
	{
		wineWarning(Response.substring(7,Response.length));	
	}
	else
	{
		window.location = '/viewprofile/' + userID;
	}
};

function friendRemove()
{
	promptPath = 0;
	promptWarning("Are you sure you want to remove this user from your Friends list?  You may not have the ability to view their profile and communicate with them once this is completed.", "Are you Sure?");		
}

var permissionResult = function(permissions)
{
	window.location = '/viewprofile/' + userID;
};

var fullyConnect = function()
{
	FB.Connect.showPermissionDialog('publish_stream', permissionResult, true, null);
}

var facebook_onlogin = function()
{
	window.location = "https://www.winemcgee.com/connect.php";
}


// ----------------------------------------------------------------------------------------------------

var questionSubscribeSuccess = function(o)
{ 
	LoadingContainer.hide();
	var Response = o.responseText;
	if (Response.substring(0,7) == "[error]")
	{
		wineWarning(Response.substring(7,Response.length));	
	}
	else
	{
		wineWarning("You are now subscribed to the Question of The Day!  Look for the first email tomorrow.");
	}
};

function questionSubscribe()
{
	var callback = 
	{
		success: questionSubscribeSuccess,
		failure: submitAnswerFailure,
		customevents: { onStart: submitAnswerStart },
		timeout: 10000
	}
	
	YAHOO.util.Connect.initHeader('X-Signature', transaction_sig); 
	var cObj = YAHOO.util.Connect.asyncRequest('POST', '/questionofdaysubscribe_s.php', callback); 	
}

var submitAnswerStart = function(o)
{ 
	LoadingContainer.show();
};
var submitAnswerSuccess = function(o)
{ 
	LoadingContainer.hide();
	var Response = o.responseText;
	if (Response.substring(0,7) == "[error]")
	{
		wineWarning(Response.substring(7,Response.length));	
	}
	else
	{
		document.getElementById("dailyQuestion").innerHTML = Response;
	}
};
var submitAnswerFailure = function(o)
{ 
	LoadingContainer.hide();
	wineWarning("There was a communication error on the WineMcGee servers. Please try again later.");
};

function submitAnswer(element)
{
	var callback = 
	{
		success: submitAnswerSuccess,
		failure: submitAnswerFailure,
		customevents: { onStart: submitAnswerStart },
		timeout: 10000
	}
	
	YAHOO.util.Connect.initHeader('X-Signature', transaction_sig); 
	var cObj = YAHOO.util.Connect.asyncRequest('POST', '/submitquizanswer_s.php', callback, 'answer='+element.value); 	

}

// ------------------------------------ Init -----------------------------------------------------------

function init()
{
	LoadingContainer.setBody('<img src="/Images/ajaxload.gif" />');
	LoadingContainer.render(document.body);
	
	
	// ----------------------------- Message Dialog -----------------------

	var handleMessageSubmit = function()   //when the submit button is clicked, submit the form
	{   
		var Subject = document.getElementById("subjectEdit").value;
		var Message = document.getElementById("messageText").value;
		
		var callback = 
		{
			success: onMessageSuccess,
			failure: onMessageFailure,
			timeout: 80000,
			cache: false
		};
				
		postlist = "";
		postlist += "subject=" + Subject + "&";
		postlist += "message=" + Message + "&";
		postlist += "type=0&";
		postlist += "con0=" + messageUser + "&";
		
		YAHOO.util.Connect.initHeader('X-Signature', transaction_sig); 
		var cObj = YAHOO.util.Connect.asyncRequest('POST', '/messagesend_s.php', callback, postlist); 
			
		messageDialog.hide();
		LoadingContainer.show();
	};   
	var handleMessageCancel = function()   // if the cancel button is clicked, cancel the form
	{   
		messageDialog.cancel();   
	};   
	var onMessageFailure = function(o)
	{
		LoadingContainer.hide();
		wineWarning("There was an error when submitting your message.  Please try again or contact WineMcgee support.");
	};
	
	var onMessageSuccess = function(o)
	{
		LoadingContainer.hide();
		var Response = o.responseText;
		if (Response.substring(0,7) == "[error]")
		{
			wineWarning(Response.substring(7,Response.length));	
		}
		else
		{
			wineWarning("Your message has been successfully sent!", "Message Sent");	
		}
	};
	
	messageDialog = new YAHOO.widget.Dialog("messageDialog",  
					{ width : "350px", 
					  fixedcenter : true, 
					  visible : false,  
					  zIndex:15000,
					  modal: true,
					  constraintoviewport : true, 
					  buttons : [ { text:"Submit", handler:handleMessageSubmit, isDefault:true }, 
								  { text:"Cancel", handler:handleMessageCancel } ] 
					 } ); 
	
	messageDialog.render(document.body);
	
	// ---------------------- Expand Regions -------------------------------------
	
	if (typeof(document.getElementById("AttendeeRegion")) != 'undefined')
	{
		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"));
	}
	if (typeof(document.getElementById("newsRegion")) != 'undefined')
	{
		NewsModule = new YAHOO.widget.Module("newsRegion", { visible: false });  
		NewsModule.render();   
		showNewsRegion = new YAHOO.widget.Module("showNewsRegion", { visible: true });  
		showNewsRegion.render();   
		YAHOO.util.Event.addListener("showNewsRegion", "mouseover", regionMouseOver, document.getElementById("downArrowNews"));
		YAHOO.util.Event.addListener("showNewsRegion", "mouseout", regionMouseOut, document.getElementById("downArrowNews"));
	}
	if (typeof(document.getElementById("PhotoRegion")) != 'undefined')
	{
		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: "560px", 
										  visible:false 
  	 								      });   	
		// fade causes text to not anti-alias in IE (<= 7)
	}
	else
	{
	    QuickViewModule = new YAHOO.widget.Panel("QVPanel", { 
										  fixedcenter:true,	
										  width: "560px", 
										  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 = transaction_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 toolTips for popTitle
	var elements = YAHOO.util.Dom.getElementsByClassName('popHelp'); 	
	var imgElementArray = new Array();
	var a = 0;
	for (a = 0; a < elements.length; a++)
	{
		imgElementArray[a] = elements[a].id;
	}	

	if (toolTip2)
	{
		toolTip2.cfg.setProperty("context", imgElementArray);
		toolTip2.forceUnderlayRedraw();
	}
	else if (imgElementArray.length > 0)
	{
		toolTip2 = new YAHOO.widget.Tooltip("tooltip2", 
										{ context: imgElementArray,
										  autodismissdelay: 15000,
								  		  effect: {effect:YAHOO.widget.ContainerEffect.FADE,duration:0.20}
										});					
	}	
}

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";

