// JavaScript Document

var PhotoModule = null;
var showPhotoRegion = null;
var toolTip = null;
var PictureModule = null;
var uploadDialog = null;
var showPhotoRegion = null;

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";

var messageOut = new Image;
var messageOver = new Image;
var followOut = new Image;
var followOver = new Image;
var praiseOut = new Image;
var praiseOver = new Image;

messageOut.src="/Images/messageme.gif";
messageOver.src="/Images/messageme2.gif";
followOut.src="/Images/followme.gif";
followOver.src="/Images/followme2.gif";
praiseOut.src="/Images/praiseme.gif";
praiseOver.src="/Images/praiseme2.gif";

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;
}

var messageDialog = null;
var messageUser = 0;

var MagModule = null;
var bigImageOut = 1;
var overImage = 0;


// ----------------------------------------------------- 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';
}

// ------------------------------------ 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.");
};
	
// -------------------------- loading -------------------------------------------------------------------------------

var LoadingContainer = 
		new YAHOO.widget.Panel("loadingDialog",  
			{ width:"80px", 
			  fixedcenter:true, 
			  close:false, 
			  draggable:false, 
			  zindex:15000,
			  visible:false
			} 
	);

// -------------------------- 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', '/loadanswers_s.php', callback, 'uniqueID='+uniqueID+'&commentStart='+comment_id); 	
//	document.getElementById("commentText").value = ""; // clear comment text
}

// ------------------------------------ Warning Dialog -----------------------------------------------------------

var wineWarning = function(warningText, header)
{
	if (!header)
	{
		header = "Question, Answer, Learn Issue"
	}
	wineWarningDialog.setHeader("<div class=\"hd\"><div class=\"tl\"></div><span>" + header + "</span><div class=\"tr\"></div></div>");

	var bodyText = '<div class="dialogWrap"><table class="popupTable" border="0" cellspacing="0" cellpadding="0"><tr><td>' + warningText + '</td></tr></table></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 }]
						});	

// ------------------------------------ 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";
};

// ------------------------------------ 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.");
};

// ------------------------------------ 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', '/loadanswers_s.php', callback, 'uniqueID='+uniqueID); 
	}
};
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.", "Report Abuse");	
	}
};
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=3'); 	
}


// ------------------------------------ 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', '/loadanswers_s.php', callback, 'uniqueID='+uniqueID); 
		
		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 answer")
	{
		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='+uniqueID+'&type=3'); 	
	}
}

function prePostComment()
{
	if (userID == -1)
	{
		childWindow = window.open ("/twittersubmitanswer.php", "mywindow",  "width=800,height=410");						
	}
	else
	{
		postComment();
	}	
}

// ---------------------------------- 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)
{
	if (questionText.length > 35)
		questionText = questionText.substr(0,35) + "...?";
		
	document.getElementById("subjectEdit").value = "Your answer to '" + questionText + "'";
	messageUser = userID;

	var callback = 
	{
		success: getMcGeeNameSuccess,
		failure: postCommentFailure,
		customevents: { onStart: postCommentStart },
		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: postCommentFailure,
		customevents: { onStart: postCommentStart },
		timeout: 5000
	}
		
	YAHOO.util.Connect.initHeader('X-Signature', transaction_sig); 
	var cObj = YAHOO.util.Connect.asyncRequest('POST', '/followme_s.php', callback, 'userID='+followID); 	
}
// ------------------------------------ Praise -----------------------------------------------------------

var praiseSuccess = function(o)
{ 
	LoadingContainer.hide();
	var Response = o.responseText;
	if (Response.substring(0,7) == "[error]")
	{
		wineWarning(Response.substring(7,Response.length), "Praise Issue");	
	}
	else
	{
		wineWarning("Thank you for recognizing a great answer! Sending praise on WineMcGee is a great way to reward other users for a job well done.<p>Giving praise also increases your McGee Points and Popularity. Users that acheive high Popularity levels can gain additional privileges on WineMcGee - like the ability to update wine detail and become The Boss of certain WineMcGee pages.</p><p>We also like to reward our best users with discounted or free wine!</p>", "Praise Sent!");			
	}
};

function praiseMe(commentID)
{
	var callback = 
	{
		success: praiseSuccess,
		failure: postCommentFailure,
		customevents: { onStart: postCommentStart },
		timeout: 5000
	}
		
	YAHOO.util.Connect.initHeader('X-Signature', transaction_sig); 
	var cObj = YAHOO.util.Connect.asyncRequest('POST', '/givepraise_s.php', callback, 'type=0&uniqueID='+commentID); 	
}

// ------------------------------------ Upload Dialog -----------------------------------------------------------

var handleUploadSubmit = 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: onUploadFailure,
		timeout: 25000,
		cache: false
	};
		
	var cObj = YAHOO.util.Connect.asyncRequest('POST', '/questionphotoupload_s.php', callback, 'questionID='+uniqueID); 
	uploadDialog.hide();
	LoadingContainer.show();
};   
var handleUploadCancel = function()   // if the cancel button is clicked, cancel the form
{   
    uploadDialog.cancel();   
};   
var onUploadFailure = 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, 'uniqueID='+uniqueID+'&type=7'); 						
	}
}

// ------------------------------------ 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, 'uniqueID='+uniqueID+'&type=7'); 												
	}
};
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); 	
}

// ------------------------------------ Init -----------------------------------------------------------

function init()
{
	LoadingContainer.setBody('<img src="/Images/ajaxload.gif" />');
	LoadingContainer.render(document.body);
			
// -------- 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);					

	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"));
	}
	
	uploadDialog = new YAHOO.widget.Dialog("uploadDialog",  
	            { width : "350px", 
	              fixedcenter : true, 
	              visible : false,  
				  zIndex:15000,
				  modal: true,
	              constraintoviewport : true, 
	              buttons : [ { text:"Submit", handler:handleUploadSubmit, isDefault:true }, 
	                          { text:"Cancel", handler:handleUploadCancel } ] 
	             } ); 

	uploadDialog.render(document.body);
	
	document.getElementById("sig").value = transaction_sig; // set the form security signature for image uploads

/*
	// 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}
										});					
	}	
	*/	
	// ------------------------------------ Message Dialog -----------------------------------------------------------

	var handleSubmit = 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: onSuccess,
			failure: onFailure,
			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 handleCancel = function()   // if the cancel button is clicked, cancel the form
	{   
		messageDialog.cancel();   
	};   
	var onFailure = function(o)
	{
		LoadingContainer.hide();
		wineWarning("There was an error when submitting your message.  Please try again or contact WineMcgee support.");
	};
	
	var onSuccess = 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:handleSubmit, isDefault:true }, 
								  { text:"Cancel", handler:handleCancel } ] 
					 } ); 
	
	messageDialog.render(document.body);
	

}

YAHOO.util.Event.onDOMReady(init);

