// JavaScript Document

var toolTip = null;
var cityDataSet = null;
var cityAutoComplete = null;
var FilterModule = null;
var SortModule = null;
var showSortRegion = null;
var showFilterRegion = null;
var hiddenField = null; // for city auto complete submit
var LocationModule = null; 
var showLocationRegion = null; 
var PictureModule = null;
var startComment = -1;

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 uploadDialog = null;
var uploadWarningDialog = null;
var imageUploaded = false;

var startWinery = -1;

var MagModule = null;
var bigImageOut = 1;
var overImage = 0;

var wineryDataSet = null;
var wineryAutoComplete = null;
var wineryDataSetAdd = null;
var wineryAutoCompleteAdd = null;

var CityPickerModule = null;

var promptWarningDialog = null;

// ----------------------------------------------------For Loading Container --------------------------------------------
var LoadingContainer = 
		new YAHOO.widget.Panel("loadingDialog",  
			{ width:"80px", 
			  fixedcenter:true, 
			  close:false, 
			  draggable:false, 
			  zindex:15000,
			  modal:false,
			  visible:false
			} 
	);

// ---- For Error Output----------------

var Error = false;
var ErrorText = "";
function addError(Message)
{
	Error = true;
	ErrorText += "<p>* " + Message + "</p>"
}


var buildHour = function(hour, ampm)
{
	if (hour == 12)  // 12pm stays as 12, 12am should be 0, 1am = 1, and so on
	{
		if (ampm == "am")
			return 0;
		else 
			return hour;
 	}
	else
	{
		if (ampm == "pm")
			return hour + 12;
		else
			return hour;
	}
}



// -------------------------- get comments (using summarized links on bottom of page------------------------------------
function getComments(winery_id)
{
	startWinery = winery_id;
	prepareFilter();
}


		
// -----------------------------------------------Wine Warning -------------------------------------------------------
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 }]
						});	


var wineWarning = function(warningText)
{
	wineWarningDialog.setHeader("<div class=\"hd\"><div class=\"tl\"></div><span>Event Search 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();
};


// ----------------------------------------------- Filter --------------------------------------------

var filterStart = function(o)
{ 
	LoadingContainer.show();
};
var filterSuccess = function(o)
{ 
	LoadingContainer.hide();
	var Response = o.responseText;
	if (Response.substring(0,7) == "[error]")
	{
		wineWarning(Response.substring(7,Response.length));	
	}
	else
	{
		document.getElementById("wineryResults").innerHTML = o.responseText;

		if (!browserIE6)
		{
			wineryAutoComplete = new YAHOO.widget.AutoComplete("WineryNameEdit", "wineryAutoContainer", wineryDataSet);
			wineryAutoComplete.resultTypeList = false; 
		}		
	}
	window.location = "#restoreBack";
};
var filterFailure = function(o)
{ 
	wineWarning("There was a communication error on the WineMcGee servers. Please try again later.");
};

// --------------------------------------------- change zip code ----------------------------------------

function zipSubmit()
{
	zipValue = document.getElementById("ZipEdit").value;
	cityValue = document.getElementById("CityEdit").value;
	
	if (zipValue.match(/^[0-9]{5}$/))
		window.location = "/wineries/"+zipValue;
	else if (cityValue != 'Enter City' && cityValue.match(/^[a-zA-Z](([a-zA-Z])|(\s))+$/))  // starts with a letter, then can include letters or spaces
		window.location = "/wineries/"+escape(cityValue);	
	else
		wineWarning("The zip code or city you entered appears to be invalid. When entering a city name, please do not enter the state as well, but rather select the appropriate city from the autocomplete drop down box.");
}

// --------------------------------------------- search / filter ----------------------------------------
function prepareFilter()
{
	var formObject = document.getElementById('filterForm');
	YAHOO.util.Connect.setForm(formObject); 
	var callback = 
	{
		success:filterSuccess,
		failure:filterFailure,
		customevents: { onStart: filterStart },
		timeout: 10000
	};
	
	var postText = "";
	
	if (zipCodeSet)
		postText = postText + "zip=" + zipCode + "&";
		
	if (startWinery != -1)
	{
		postText = postText + "wineryStart=" + startWinery + "&";		
		startWinery = -1;
	}

	YAHOO.util.Connect.initHeader('X-Signature', transaction_sig); 
	var cObj = YAHOO.util.Connect.asyncRequest('POST', '/wineryfilter_s.php', callback, postText); 
	return false;
}

// ------------------------------------ show / hide Filter section ----------------------------------------------

function showEventFilter()  
{
	if (!FilterModule.cfg.getProperty("visible"))
	{
		FilterModule.show();
		document.getElementById("showFilterRegion").innerHTML = "<img id=\"upArrowFilter\" src=\"/Images/uparrow.gif\" alt=\"up arrow\"/>Remove Search Filter";
		YAHOO.util.Event.addListener("showFilterRegion", "mouseover", regionMouseOverUp, document.getElementById("upArrowFilter"));
		YAHOO.util.Event.addListener("showFilterRegion", "mouseout", regionMouseOutUp, document.getElementById("upArrowFilter"));
	}
	else
	{
		FilterModule.hide();
		document.getElementById("showFilterRegion").innerHTML = "<img id=\"downArrowFilter\" src=\"/Images/downarrow.gif\" alt=\"down arrow\"/>Show Search Filter";
		YAHOO.util.Event.addListener("showFilterRegion", "mouseover", regionMouseOver, document.getElementById("downArrowFilter"));
		YAHOO.util.Event.addListener("showFilterRegion", "mouseout", regionMouseOut, document.getElementById("downArrowFilter"));
	}
	document.getElementById("showFilterRegion").className = 'tabText';
}

// ------------------------------------ show / hide Location section ----------------------------------------------

function showEventLocation()  
{
	if (!LocationModule.cfg.getProperty("visible"))
	{
		LocationModule.show();
		document.getElementById("showLocationRegion").innerHTML = "<img id=\"upArrowLocation\" src=\"/Images/uparrow.gif\" alt=\"up arrow\"/>Remove Location Selection";
		YAHOO.util.Event.addListener("showLocationRegion", "mouseover", regionMouseOverUp, document.getElementById("upArrowLocation"));
		YAHOO.util.Event.addListener("showLocationRegion", "mouseout", regionMouseOutUp, document.getElementById("upArrowLocation"));
	}
	else
	{
		LocationModule.hide();
		document.getElementById("showLocationRegion").innerHTML = "<img id=\"downArrowLocation\" src=\"/Images/downarrow.gif\" alt=\"down arrow\"/>Show Location Selector";
		YAHOO.util.Event.addListener("showLocationRegion", "mouseover", regionMouseOver, document.getElementById("downArrowLocation"));
		YAHOO.util.Event.addListener("showLocationRegion", "mouseout", regionMouseOut, document.getElementById("downArrowLocation"));
	}
	document.getElementById("showLocationRegion").className = 'tabText';
}

// ------------------------------------ show / hide functionality ----------------------------------------------

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;
}

// ------------------------------------ Autoformat display ----------------------------------------------

// format text display in autocomplete select box
var cityFormat = function(oResultData, sQuery, sResultMatch) 
{ 
	return oResultData.city + ", " + oResultData.state;
}
var dataErrorHandler  = function( oSelf , sQuery ) 
{
	wineWarning("There was a communication error or your session timed out. Please refresh the page and try again.");
};
// call page with new zip when an autocomplete selection is made
var itemSelected = function (sTyle, aArgs)
{
	var DataObj = aArgs[2]; // 0 is the AC instance, 1 the LI element
	document.getElementById("hiddenField").value = DataObj.zip; // don't seem to need this line...
	window.location = "/wineries/"+DataObj.zip;
};

// ------------------------------------ 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 Image Preview ------------------------------------------------

function uploadWineImageIn(imageElement, 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);
		
	PictureModule.setBody("<div id=\"picMod\" class=\"pictureModule\"><img style=\"cursor: pointer;\" id=\"bigImage\" onmouseout=\"wineImageOut();\" src=\""+bigImage+"\" alt=\"Click here to upload your image\"/></div>");
	YAHOO.util.Event.addListener("bigImage", "click", uploadDialog.show, uploadDialog, true);		
	YAHOO.util.Event.addListener("bigImage", "load", wineImageLoaded);   // once the wine image is loaded, we're good to show
	document.getElementById("picMod").style.cursor = "pointer";
}


// ------------------------------------ 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', '/winelabelupload_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();
	uploadWarning("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]")
	{
		uploadWarning(Response.substring(7,Response.length));	
	}
	else
	{
		imageUploaded = true;
		document.getElementById("wineThumb").innerHTML = o.responseText;
		YAHOO.util.Event.addListener("showFileUpload", "click", uploadDialog.show, uploadDialog, true);
	}
}


// ------------------------------------ Simple Dialog for Upload Warnings / Errors ----------------------------------------------

var uploadWarning = function(warningText)
{
	uploadWarningDialog.setHeader("<div class=\"hd\"><div class=\"tl\"></div><span>Image Upload Error</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>';

	uploadWarningDialog.setBody(bodyText);
	uploadWarningDialog.render(document.body);		
	uploadWarningDialog.show();
}

var handleYes = function() 
{
	uploadWarningDialog.hide();
	uploadDialog.show();
}
var handleNo = function() 
{
	uploadWarningDialog.hide();
}


// ------------------------------------ Wine Submit Prompt ----------------------------------------------

var promptWarning = function(warningText)
{
	promptWarningDialog.setHeader("<div class=\"hd\"><div class=\"tl\"></div><span>Where to?</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() 
{
	promptWarningDialog.hide();
	window.location = '/winery/' + wineryPage;
}
var promptNo = function() 
{
	promptWarningDialog.hide();
	window.location = "/wineries";
}

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} ]
						});	

// --------------------------------------------- new winery submit----------------------------------------

var winerySubmitStart = function(o)
{ 
	LoadingContainer.show();
};
var winerySubmitSuccess = function(o)
{ 
	LoadingContainer.hide();
	var Response = o.responseText;
	if (Response.substring(0,7) == "[error]")
	{
		wineWarning(Response.substring(7,Response.length));	
	}
	else
	{
		//		prepareWineAdd(o.responseText);  //add the wine to the event list.
		wineryPage = o.responseText;		
		promptWarning("Thank you for submitting a new winery to our database! Would you like to continue to the winery's new profile page on WineMcGee? Choose Yes to continue and Cancel to stay put.", "Submit Complete");	
		
	}
};
var winerySubmitFailure = function(o)
{ 
	wineWarning("There was a communication error on the WineMcGee servers. Please try again later.");
};

function prepareWinerySubmit()
{
	var Email = document.getElementById("EmailEdit").value;
	var Phone = document.getElementById("PhoneEdit").value;
	var ZipCode = document.getElementById("ZipEdit").value;
	var Address = document.getElementById("AddressEdit").value;
	var City = document.getElementById("WineryCityEdit").value;
	var Website = document.getElementById("WebsiteEdit").value;

	var	MonStartHour = document.getElementById("MonStartHour").value;
	var	TueStartHour = document.getElementById("TueStartHour").value;
	var	WedStartHour = document.getElementById("WedStartHour").value;
	var	ThuStartHour = document.getElementById("ThuStartHour").value;
	var	FriStartHour = document.getElementById("FriStartHour").value;
	var	SatStartHour = document.getElementById("SatStartHour").value;
	var	SunStartHour = document.getElementById("SunStartHour").value;

	var	MonStartMin = document.getElementById("MonStartMin").value;
	var	TueStartMin = document.getElementById("TueStartMin").value;
	var	WedStartMin = document.getElementById("WedStartMin").value;
	var	ThuStartMin = document.getElementById("ThuStartMin").value;
	var	FriStartMin = document.getElementById("FriStartMin").value;
	var	SatStartMin = document.getElementById("SatStartMin").value;
	var	SunStartMin = document.getElementById("SunStartMin").value;

	var	MonStartAM = document.getElementById("MonStartAM").value;
	var	TueStartAM = document.getElementById("TueStartAM").value;
	var	WedStartAM = document.getElementById("WedStartAM").value;
	var	ThuStartAM = document.getElementById("ThuStartAM").value;
	var	FriStartAM = document.getElementById("FriStartAM").value;
	var	SatStartAM = document.getElementById("SatStartAM").value;
	var	SunStartAM = document.getElementById("SunStartAM").value;

	var	MonEndHour = document.getElementById("MonEndHour").value;
	var	TueEndHour = document.getElementById("TueEndHour").value;
	var	WedEndHour = document.getElementById("WedEndHour").value;
	var	ThuEndHour = document.getElementById("ThuEndHour").value;
	var	FriEndHour = document.getElementById("FriEndHour").value;
	var	SatEndHour = document.getElementById("SatEndHour").value;
	var	SunEndHour = document.getElementById("SunEndHour").value;

	var	MonEndMin = document.getElementById("MonEndMin").value;
	var	TueEndMin = document.getElementById("TueEndMin").value;
	var	WedEndMin = document.getElementById("WedEndMin").value;
	var	ThuEndMin = document.getElementById("ThuEndMin").value;
	var	FriEndMin = document.getElementById("FriEndMin").value;
	var	SatEndMin = document.getElementById("SatEndMin").value;
	var	SunEndMin = document.getElementById("SunEndMin").value;

	var	MonEndAM = document.getElementById("MonEndAM").value;
	var	TueEndAM = document.getElementById("TueEndAM").value;
	var	WedEndAM = document.getElementById("WedEndAM").value;
	var	ThuEndAM = document.getElementById("ThuEndAM").value;
	var	FriEndAM = document.getElementById("FriEndAM").value;
	var	SatEndAM = document.getElementById("SatEndAM").value;
	var	SunEndAM = document.getElementById("SunEndAM").value;

	var MonStartDate = new Date();
	MonStartDate.setHours(buildHour(MonStartHour, MonStartAM));
	MonStartDate.setMinutes(MonStartMin);  // javascipt months are 0-11
	var TueStartDate = new Date();
	TueStartDate.setHours(buildHour(TueStartHour, TueStartAM));
	TueStartDate.setMinutes(TueStartMin);  // javascipt months are 0-11
	var WedStartDate = new Date();
	WedStartDate.setHours(buildHour(WedStartHour,WedStartAM));
	WedStartDate.setMinutes(WedStartMin);  // javascipt months are 0-11
	var ThuStartDate = new Date();
	ThuStartDate.setHours(buildHour(ThuStartHour, ThuStartAM));
	ThuStartDate.setMinutes(ThuStartMin);  // javascipt months are 0-11
	var FriStartDate = new Date();
	FriStartDate.setHours(buildHour(FriStartHour, FriStartAM));
	FriStartDate.setMinutes(FriStartMin);  // javascipt months are 0-11
	var SatStartDate = new Date();
	SatStartDate.setHours(buildHour(SatStartHour, SatStartAM));
	SatStartDate.setMinutes(SatStartMin);  // javascipt months are 0-11
	var SunStartDate = new Date();
	SunStartDate.setHours(buildHour(SunStartHour, SunStartAM));
	SunStartDate.setMinutes(SunStartMin);  // javascipt months are 0-11

	var MonEndDate = new Date();
	MonEndDate.setHours(buildHour(MonEndHour, MonEndAM));
	MonEndDate.setMinutes(MonEndMin);  // javascipt months are 0-11
	var TueEndDate = new Date();
	TueEndDate.setHours(buildHour(TueEndHour, TueEndAM));
	TueEndDate.setMinutes(TueEndMin);  // javascipt months are 0-11
	var WedEndDate = new Date();
	WedEndDate.setHours(buildHour(WedEndHour,WedEndAM));
	WedEndDate.setMinutes(WedEndMin);  // javascipt months are 0-11
	var ThuEndDate = new Date();
	ThuEndDate.setHours(buildHour(ThuEndHour, ThuEndAM));
	ThuEndDate.setMinutes(ThuEndMin);  // javascipt months are 0-11
	var FriEndDate = new Date();
	FriEndDate.setHours(buildHour(FriEndHour, FriEndAM));
	FriEndDate.setMinutes(FriEndMin);  // javascipt months are 0-11
	var SatEndDate = new Date();
	SatEndDate.setHours(buildHour(SatEndHour, SatEndAM));
	SatEndDate.setMinutes(SatEndMin);  // javascipt months are 0-11
	var SunEndDate = new Date();
	SunEndDate.setHours(buildHour(SunEndHour, SunEndAM));
	SunEndDate.setMinutes(SunEndMin);  // javascipt months are 0-11

	if (MonEndDate < MonStartDate)
		addError("The open hours are after the closing hours on Monday.");						
	if (TueEndDate < TueStartDate)
		addError("The open hours are after the closing hours on Tuesday.");						
	if (WedEndDate < WedStartDate)
		addError("The open hours are after the closing hours on Wednesday.");						
	if (ThuEndDate < ThuStartDate)
		addError("The open hours are after the closing hours on Thursday.");						
	if (FriEndDate < FriStartDate)
		addError("The open hours are after the closing hours on Friday.");						
	if (SatEndDate < SatStartDate)
		addError("The open hours are after the closing hours on Saturday.");						
	if (SunEndDate < SunStartDate)
		addError("The open hours are after the closing hours on Sunday.");						

	/*
	if ((MonStartHour == 1 && MonStartAM == "am" && TueStartHour == 1 && TueStartAM == "am" && WedStartHour == 1 && WedStartAM == "am" && ThuStartHour == 1 && ThuStartAM == "am" && FriStartHour == 1 && FriStartAM == "am" && SatStartHour == 1 && SatStartAM == "am" &&  SunStartHour == 1 && SunStartAM == "am" && document.getElementById("CountrySelectAdd").value == 38 && !document.getElementById("notAvail").checked) || (MonEndHour == 1 && MonEndAM == "pm" && TueEndHour == 1 && TueEndAM == "pm" && WedEndHour == 1 && WedEndAM == "pm" && ThuEndHour == 1 && ThuEndAM == "pm" && FriEndHour == 1 && FriEndAM == "pm" && SatEndHour == 1 && SatEndAM == "pm" && SunEndHour == 1 && SunEndAM == "pm" && document.getElementById("CountrySelectAdd").value == 38 && !document.getElementById("notAvail").checked))
	{
		addError("Please ensure you complete the Hours section to define when the winery is open.");				
	}*/


    if (Email.length != 0 && !Email.match(/^[-_a-zA-Z0-9]{1,}(\.{0,1}[-_a-zA-Z0-9]){0,}@[-_a-zA-Z0-9]{1,}(\.{0,1}[-_a-zA-Z0-9]){0,}\.[a-z0-9]{2,4}$/))
		addError("Please enter a valid email address or leave this field blank.");
	 
    if (Phone.length != 0 && !Phone.match(/^(1\s*[-\/\.]?)?(\((\d{3})\)|(\d{3}))\s*[-\/\.]?\s*(\d{3})\s*[-\/\.]?\s*(\d{4})\s*(([xX]|[eE][xX][tT])\.?\s*(\d+))*$/))
		addError("Please enter a valid phone number or leave this field blank.");
		
	if (document.getElementById("CountrySelectAdd").value == -1 && document.getElementById("RegionSelectAdd").value == -1 && document.getElementById("SubRegionSelectAdd").value == -1)
	{
		addError("Please be as specific as possible with the winery's appellation.  You must at least enter the country if you don't know the other details.");
	}
	if (document.getElementById("WineryName").value.length < 1)
	{
		addError("Please enter the name of the Winery.  You left this field blank.");	
	}
	
	if (Website.length != 0 && !Website.match(/^(http(s)?:\/\/)?([\w-]+\.)+[\w-]+(\/[\w- ;,.\/?%&=]*)?$/))
	{
		addError("Please enter a valid URL in the website field or optionally leave this field blank.");	
	}
	else if (Website.length != 0)  // if it was a match for the regex function
	{
		if (Website.substring(0,4) != "http" && Website.substring(0,5) != "https")
		{
			Website = "http://" + Website;
			document.getElementById("WebsiteEdit").value = Website;
		}
	}	
	if (ZipCode.length == 0 || Address.length == 0 || City.length == 0)
	{
		addError("Please enter the full address for this winery.");	
	}
	if (Error)
	{
		window.location = "#ErrorAnchor";
		document.getElementById("ErrorDiv").innerHTML = ErrorText;
		Error = false;
		ErrorText = "";
		return false;
	}

	else
	{	
	
		var formObject = document.getElementById('wineryForm');
		YAHOO.util.Connect.setForm(formObject); 
		var callback = 
		{
			success:winerySubmitSuccess,
			failure:winerySubmitFailure,
			customevents: { onStart: winerySubmitStart },
				timeout: 50000
		};
		
		var postText = "";
				
		if (imageUploaded)
			postText += "imageUpload=1&";				
	
		YAHOO.util.Connect.initHeader('X-Signature', transaction_sig); 		
		var cObj = YAHOO.util.Connect.asyncRequest('POST', '/winerysubmit_s.php', callback, postText); 
		return false;
	}
}




// ----------------------------------- Back Button ------------------------------------------------------------------------
var backResultsLoadStart = function(o)
{ 
	LoadingContainer.show();
}
var backResultsLoadSuccess = function(o)
{ 
	LoadingContainer.hide();
	var Response = o.responseText;
	if (Response.substring(0,7) == "[error]")
	{
		wineWarning(Response.substring(7,Response.length));	
	}
	else
	{
		document.getElementById("wineryResults").innerHTML = o.responseText;
	}
}

var backLoadStart = function(o)
{ 
	LoadingContainer.show();
}
var backLoadSuccess = function(o)
{ 
	LoadingContainer.hide();
	var Response = o.responseText;
	if (Response.substring(0,7) == "[error]")
	{
		wineWarning(Response.substring(7,Response.length));	
	}
	else
	{
		document.getElementById("eventFilter").innerHTML = o.responseText;
		YAHOO.util.Event.addListener("filterSubmit", "click", prepareFilter);
		
		// now load results section
		
		var callback = 
		{
			success:backResultsLoadSuccess,
			failure:backLoadFailure,
			customevents: { onStart: backResultsLoadStart },
			timeout: 10000
		}
		
		YAHOO.util.Connect.initHeader('X-Signature', transaction_sig); 
		var cObj = YAHOO.util.Connect.asyncRequest('POST', '/getwineriesresultback_s.php', callback); 			
	}	
}
var backLoadFailure = function(o)
{ 
	wineWarning("There was a communication error on the WineMcGee servers. Please try again later.");
}

// ----------------------------------------------------For Ajax Region Change --------------------------------------------
var regionChangeStart = function(o)
{ 
	LoadingContainer.show();
}
var regionChangeSuccess = function(o)
{ 
	LoadingContainer.hide();
	var Response = o.responseText;
	if (Response.substring(0,7) == "[error]")
	{
		wineWarning(Response.substring(7,Response.length));	
	}
	else
		document.getElementById("subRegionDiv").innerHTML = o.responseText;
}
var regionChangeFailure = function(o)
{ 
	wineWarning("There was a communication error on the WineMcGee servers. Please try again later.");
}

function regionChange(regionID)
{
	var callback = 
	{
		success:regionChangeSuccess,
		failure:regionChangeFailure,
		customevents: { onStart: regionChangeStart },
		timeout: 5000
	}
	
	YAHOO.util.Connect.initHeader('X-Signature', transaction_sig); 
	var cObj = YAHOO.util.Connect.asyncRequest('POST', '/regionchange_s.php', callback, 'regionID='+regionID); 
	return false;
}

function regionChangeAdd(regionID)
{
	var callback = 
	{
		success:regionChangeAddSuccess,
		failure:regionChangeFailure,
		customevents: { onStart: regionChangeStart },
		timeout: 50000
	}
	
	YAHOO.util.Connect.initHeader('X-Signature', transaction_sig); 
	var cObj = YAHOO.util.Connect.asyncRequest('POST', '/regionchangeadd_s.php', callback, 'regionID='+regionID); 
	return false;
}
var regionChangeAddSuccess = function(o)
{ 
	LoadingContainer.hide();
	var Response = o.responseText;
	if (Response.substring(0,7) == "[error]")
	{
		wineWarning(Response.substring(7,Response.length));	
	}
	else
		document.getElementById("subRegionDivAdd").innerHTML = o.responseText;
}

// ----------------------------------------------------For Ajax Country Change --------------------------------------------
var countryChangeStart = function(o)
{ 
	LoadingContainer.show();
}
var countryChangeSuccess = function(o)
{ 
	LoadingContainer.hide();
	var Response = o.responseText;
	if (Response.substring(0,7) == "[error]")
	{
		wineWarning(Response.substring(7,Response.length));	
	}
	else
	{
		document.getElementById("regionDiv").innerHTML = o.responseText;
		document.getElementById("subRegionDiv").innerHTML = "<select class=\"smallText\" name=\"SubRegionSelect\" id=\"SubRegionSelect\"><option value=\"-1\">Choose the SubRegion</option></select>";
		
	}
}
var countryChangeFailure = function(o)
{ 
	wineWarning("There was a communication error on the WineMcGee servers. Please try again later.");
}

function countryChange(countryID)
{
	var callback = 
	{
		success:countryChangeSuccess,
		failure:countryChangeFailure,
		customevents: { onStart: countryChangeStart },
		timeout: 5000
	}
	
	YAHOO.util.Connect.initHeader('X-Signature', transaction_sig); 
	var cObj = YAHOO.util.Connect.asyncRequest('POST', '/countrychange_s.php', callback, 'countryID='+countryID); 
	return false;
}

function countryChangeAdd(countryID)
{
	var callback = 
	{
		success:countryChangeAddSuccess,
		failure:countryChangeFailure,
		customevents: { onStart: countryChangeStart },
		timeout: 50000
	}
	
	YAHOO.util.Connect.initHeader('X-Signature', transaction_sig); 
	var cObj = YAHOO.util.Connect.asyncRequest('POST', '/countrychangeadd_s.php', callback, 'countryID='+countryID); 
	return false;
}
var countryChangeAddSuccess = function(o)
{ 
	LoadingContainer.hide();
	var Response = o.responseText;
	if (Response.substring(0,7) == "[error]")
	{
		wineWarning(Response.substring(7,Response.length));	
	}
	else
	{
		document.getElementById("regionDivAdd").innerHTML = o.responseText;
		document.getElementById("subRegionDivAdd").innerHTML = "<select class=\"smallText\" name=\"SubRegionSelectAdd\" id=\"SubRegionSelectAdd\"><option value=\"-1\">Choose the SubRegion</option></select>";
		
	}
}

function searchChange(radioBox)
{
	if (radioBox.value == 0)
	{
		document.getElementById("eventFilter").style.display = "none";
		document.getElementById("regionSearch").style.display = "none";
		document.getElementById("nameSearch").style.display = "none";
		prepareFilter();
	}
	if (radioBox.value == 1)
	{
		document.getElementById("eventFilter").style.display = "block";
		document.getElementById("regionSearch").style.display = "block";
		document.getElementById("nameSearch").style.display = "none";
	}
	if (radioBox.value == 2)
	{
		document.getElementById("eventFilter").style.display = "block";
		document.getElementById("regionSearch").style.display = "none";
		document.getElementById("nameSearch").style.display = "block";
	}
}

var noHoursAvail = function()
{
	var Day = "";
	doEnable = false;
	
	if (this.checked == false)
		doEnable = true;

	for (var i = 0; i < 7; i++)
	{
		if (i == 0)
			Day = "Mon";
		if (i == 1)
			Day = "Tue";
		if (i == 2)
			Day = "Wed";
		if (i == 3)
			Day = "Thu";
		if (i == 4)
			Day = "Fri";
		if (i == 5)
			Day = "Sat";
		if (i == 6)
			Day = "Sun";

		if (!doEnable)
		{
			document.getElementById(Day + "StartHour").disabled=true;
			document.getElementById(Day + "StartMin").disabled=true;
			document.getElementById(Day + "StartAM").disabled=true;
			document.getElementById(Day + "EndHour").disabled=true;
			document.getElementById(Day + "EndMin").disabled=true;
			document.getElementById(Day + "EndAM").disabled=true;	
			document.getElementById(Day + "Closed").disabled=true;	
		}
		else
		{
			document.getElementById(Day + "StartHour").disabled=false;
			document.getElementById(Day + "StartMin").disabled=false;
			document.getElementById(Day + "StartAM").disabled=false;
			document.getElementById(Day + "EndHour").disabled=false;
			document.getElementById(Day + "EndMin").disabled=false;
			document.getElementById(Day + "EndAM").disabled=false;				
			document.getElementById(Day + "Closed").disabled=false;				
		}
	}
}

var closeHourAll = function()
{
	var Day = "";
	var doEnable = false;

	if (document.getElementById("CountrySelectAdd").value == 38) // USA
		doEnable = true;

	if (doEnable)
	{
		document.getElementById("notAvail").disabled=false;				
	}
	else
	{
		document.getElementById("notAvail").disabled=true;				
	}

	for (var i = 0; i < 7; i++)
	{
		if (i == 0)
			Day = "Mon";
		if (i == 1)
			Day = "Tue";
		if (i == 2)
			Day = "Wed";
		if (i == 3)
			Day = "Thu";
		if (i == 4)
			Day = "Fri";
		if (i == 5)
			Day = "Sat";
		if (i == 6)
			Day = "Sun";

		if (!doEnable)
		{
			document.getElementById(Day + "StartHour").disabled=true;
			document.getElementById(Day + "StartMin").disabled=true;
			document.getElementById(Day + "StartAM").disabled=true;
			document.getElementById(Day + "EndHour").disabled=true;
			document.getElementById(Day + "EndMin").disabled=true;
			document.getElementById(Day + "EndAM").disabled=true;	
			document.getElementById(Day + "Closed").disabled=true;	
		}
		else
		{
			document.getElementById(Day + "StartHour").disabled=false;
			document.getElementById(Day + "StartMin").disabled=false;
			document.getElementById(Day + "StartAM").disabled=false;
			document.getElementById(Day + "EndHour").disabled=false;
			document.getElementById(Day + "EndMin").disabled=false;
			document.getElementById(Day + "EndAM").disabled=false;				
			document.getElementById(Day + "Closed").disabled=false;		
			
		}
	}
}
var closeHour = function()
{
	var Hide = false;
	var Day = "";

	if (this.checked == true)
		Hide = true;

	if (this.id == "MonClosed")
		Day = "Mon";		
	else if (this.id == "TueClosed")
		Day = "Tue";
	else if (this.id == "WedClosed")
		Day = "Wed";
	else if (this.id == "ThuClosed")
		Day = "Thu";
	else if (this.id == "FriClosed")
		Day = "Fri";
	else if (this.id == "SatClosed")
		Day = "Sat";
	else if (this.id == "SunClosed")
		Day = "Sun";
	
	if (Hide)
	{
		document.getElementById(Day + "StartHour").disabled=true;
		document.getElementById(Day + "StartMin").disabled=true;
		document.getElementById(Day + "StartAM").disabled=true;
		document.getElementById(Day + "EndHour").disabled=true;
		document.getElementById(Day + "EndMin").disabled=true;
		document.getElementById(Day + "EndAM").disabled=true;	
	}
	else
	{
		document.getElementById(Day + "StartHour").disabled=false;
		document.getElementById(Day + "StartMin").disabled=false;
		document.getElementById(Day + "StartAM").disabled=false;
		document.getElementById(Day + "EndHour").disabled=false;
		document.getElementById(Day + "EndMin").disabled=false;
		document.getElementById(Day + "EndAM").disabled=false;	
	}
}

function hoursTableShow(element)
{
	if (element.checked)
	{
		document.getElementById("hoursTable").style.display = "block";
	}
	else
	{
		document.getElementById("hoursTable").style.display = "none";
	}
	
}

function toursTableShow(element)
{
	if (element.checked)
	{
		document.getElementById("toursTable").style.display = "block";
	}
	else
	{
		document.getElementById("toursTable").style.display = "none";
	}
	
}



// ----------------------------------Add a new winery to the database--------------------------------------------

var addWineryStart = function(o)
{ 
	LoadingContainer.show();
};

var addWinerySuccess = function(o)
{ 
	LoadingContainer.hide();
	var Response = o.responseText;
	if (Response.substring(0,7) == "[error]")
	{
		wineWarning(Response.substring(7,Response.length));	
	}
	else
	{
		document.getElementById("addRegion").innerHTML = o.responseText;	
		window.location = "#AddAnchor";
		window.location = "#restoreBack";		
		YAHOO.util.Event.addListener("showFileUpload", "click", uploadDialog.show, uploadDialog, true);
		
		YAHOO.util.Event.addListener("MonClosed", "click", closeHour);
		YAHOO.util.Event.addListener("TueClosed", "click", closeHour);
		YAHOO.util.Event.addListener("WedClosed", "click", closeHour);	
		YAHOO.util.Event.addListener("ThuClosed", "click", closeHour);	
		YAHOO.util.Event.addListener("FriClosed", "click", closeHour);	
		YAHOO.util.Event.addListener("SatClosed", "click", closeHour);	
		YAHOO.util.Event.addListener("SunClosed", "click", closeHour);		

		YAHOO.util.Event.addListener("notAvail", "change", noHoursAvail);	
		YAHOO.util.Event.addListener("CountrySelectAdd", "change", closeHourAll);		
		
		YAHOO.util.Event.addListener("MonStartHour", "change", updateTimes);
		YAHOO.util.Event.addListener("MonStartMin", "change", updateTimes);
		YAHOO.util.Event.addListener("MonStartAM", "change", updateTimes);
		YAHOO.util.Event.addListener("MonEndHour", "change", updateTimes);
		YAHOO.util.Event.addListener("MonEndMin", "change", updateTimes);
		YAHOO.util.Event.addListener("MonEndAM", "change", updateTimes); 		
		
		
		wineryDataSetAdd = new YAHOO.util.XHRDataSource("/wineryauto_s.php");
			
		wineryDataSetAdd.responseType = YAHOO.util.DataSource.TYPE_XML;
		wineryDataSetAdd.responseSchema = 
		{
			resultNode: "winery",
			fields: 
			[ 
				"wineryName" 
			]
		};
		
		wineryAutoCompleteAdd = new YAHOO.widget.AutoComplete("WineryName", "wineryAutoContainerAdd", wineryDataSetAdd);
		wineryAutoCompleteAdd.resultTypeList = false; 
		if (browserIE6)
		{
			wineryAutoCompleteAdd.useIFrame = true;
		}

		
	}
};
var addWineryFailure = function(o)
{ 
	wineWarning("There was a communication error on the WineMcGee servers. Please try again later.");
};

function addWinery()
{
	var callback = 
	{
		success:addWinerySuccess,
		failure:addWineryFailure,
		customevents: { onStart: addWineryStart },
		timeout: 10000
	}
	
	YAHOO.util.Connect.initHeader('X-Signature', transaction_sig); 
	var cObj = YAHOO.util.Connect.asyncRequest('POST', '/wineryaddprocess_s.php', callback);
	return false;
}


// ------------------------- function to show date/time selectors ---------------------------------------
var updateTimes = function()
{
	if (this.id == "MonStartHour")
	{
		document.getElementById("TueStartHour").value = this.value;
		document.getElementById("WedStartHour").value = this.value;
		document.getElementById("ThuStartHour").value = this.value;
		document.getElementById("FriStartHour").value = this.value;
		document.getElementById("SatStartHour").value = this.value;
		document.getElementById("SunStartHour").value = this.value;
	}
	else if (this.id == "MonStartMin")
	{
		document.getElementById("TueStartMin").value = this.value;
		document.getElementById("WedStartMin").value = this.value;
		document.getElementById("ThuStartMin").value = this.value;
		document.getElementById("FriStartMin").value = this.value;
		document.getElementById("SatStartMin").value = this.value;
		document.getElementById("SunStartMin").value = this.value;
	}
	else if (this.id == "MonStartAM")
	{
		document.getElementById("TueStartAM").value = this.value;
		document.getElementById("WedStartAM").value = this.value;
		document.getElementById("ThuStartAM").value = this.value;
		document.getElementById("FriStartAM").value = this.value;
		document.getElementById("SatStartAM").value = this.value;
		document.getElementById("SunStartAM").value = this.value;
	}
	else if (this.id == "MonEndHour")
	{
		document.getElementById("TueEndHour").value = this.value;
		document.getElementById("WedEndHour").value = this.value;
		document.getElementById("ThuEndHour").value = this.value;
		document.getElementById("FriEndHour").value = this.value;
		document.getElementById("SatEndHour").value = this.value;
		document.getElementById("SunEndHour").value = this.value;
	}
	else if (this.id == "MonEndMin")
	{
		document.getElementById("TueEndMin").value = this.value;
		document.getElementById("WedEndMin").value = this.value;
		document.getElementById("ThuEndMin").value = this.value;
		document.getElementById("FriEndMin").value = this.value;
		document.getElementById("SatEndMin").value = this.value;
		document.getElementById("SunEndMin").value = this.value;
	}
	else if (this.id == "MonEndAM")
	{
		document.getElementById("TueEndAM").value = this.value;
		document.getElementById("WedEndAM").value = this.value;
		document.getElementById("ThuEndAM").value = this.value;
		document.getElementById("FriEndAM").value = this.value;
		document.getElementById("SatEndAm").value = this.value;
		document.getElementById("SunEndAm").value = this.value;
	}
}
function yourCity()
{
	LocationModule.show();
	showLocationRegion.show();
}


// --------------------------------------------------------------------------------
function cityChoose(cityImage)
{
	if (CityPickerModule.cfg.getProperty("visible"))
		CityPickerModule.hide();
	else
	{
		xyID = cityImage.id;
		x = YAHOO.util.Dom.getX(xyID);
		y = YAHOO.util.Dom.getY(xyID);
		
		CityPickerModule.cfg.setProperty("x", x+1);
		CityPickerModule.cfg.setProperty("y", y+17);
		CityPickerModule.render();
		CityPickerModule.show();		
	}
}
function cityPickerOut()
{
	CityPickerModule.hide();
};

function otherRegions()
{
	var wineReg = document.getElementById("byWineRegion");
	wineReg.checked = "checked";
	searchChange(wineReg);	
};
// -------------------------------------------------------- main init -------------------------------------------
function init()
{
	LoadingContainer.setBody('<img src="/Images/ajaxload.gif" />');
	LoadingContainer.render(document.body);

	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 } ] 
	             } ); 


	// Set the connection manager callback object to onUpload
	uploadDialog.callback.failure = onFailure;
	uploadDialog.callback.upload = onUpload;
	uploadDialog.callback.timeout = 100000;
	uploadDialog.callback.cache = false;

	uploadDialog.render(document.body);

	document.getElementById("sig").value = transaction_sig; // set the form security signature for image uploads

// ---------- Simple Dialog for Upload Warnings / Errors ---------


	uploadWarningDialog = 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:"Retry", handler:handleYes, isDefault:true },
					  				   { text:"Cancel", handler:handleNo} ]
						});	



	LocationModule = new YAHOO.widget.Module("getLocalRegion", { visible: false });  
	LocationModule.render();   
	showLocationRegion = new YAHOO.widget.Module("showLocationRegion", { visible: false });  
	showLocationRegion.render();   
	YAHOO.util.Event.addListener("showLocationRegion", "mouseover", regionMouseOverUp, document.getElementById("upArrowLocation"));
	YAHOO.util.Event.addListener("showLocationRegion", "mouseout", regionMouseOutUp, document.getElementById("upArrowLocation"));

	YAHOO.util.Event.addListener("zipSubmit", "click", zipSubmit);
	YAHOO.util.Event.addListener("filterSubmit", "click", prepareFilter);

    cityDataSet = new YAHOO.util.XHRDataSource("/citysearch.php");
    cityDataSet.responseType = YAHOO.util.DataSource.TYPE_XML;
    cityDataSet.responseSchema = 
	{
        resultNode: "location",
		fields: 
		[ 
			"city" ,
			"state",
			"zip" 	
		]
    };
	
	cityAutoComplete = new YAHOO.widget.AutoComplete("CityEdit", "cityAutoContainer", cityDataSet);
	cityAutoComplete.resultTypeList = false; 
	cityAutoComplete.formatResult = cityFormat;
	cityAutoComplete.dataErrorEvent.subscribe(dataErrorHandler);
	cityAutoComplete.itemSelectEvent.subscribe(itemSelected);	


	// --------------- auto complete for winery  ----------
	if (!browserIE6)
	{
		
		wineryDataSet = new YAHOO.util.XHRDataSource("/wineryauto_s.php");
			
		wineryDataSet.responseType = YAHOO.util.DataSource.TYPE_XML;
		wineryDataSet.responseSchema = 
		{
			resultNode: "winery",
			fields: 
			[ 
				"wineryName" 
			]
		};
		
		wineryAutoComplete = new YAHOO.widget.AutoComplete("WineryNameEdit", "wineryAutoContainer", wineryDataSet);
		wineryAutoComplete.resultTypeList = false; 
	}


// -------- 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);													  

	var docHash = window.location.hash;
	if (docHash.indexOf("restoreBack") != -1)
	{
		var callback = 
		{
			success:backLoadSuccess,
			failure:backLoadFailure,
			customevents: { onStart: backLoadStart },
			timeout: 10000
		}
		
		YAHOO.util.Connect.initHeader('X-Signature', transaction_sig); 
		var cObj = YAHOO.util.Connect.asyncRequest('POST', '/getwineriesfilterback_s.php', callback); 				
	}		
	

// -------- city picker ------------------------

    CityPickerModule = new YAHOO.widget.Overlay("cityPicker", { 
										  xy:[-2000,-2000],	
										  visible:false 
  	 								      });   	

	CityPickerModule.setBody("<div id=\"cityPickerMod\" onclick=\"cityPickerOut();\" class=\"tweetCities\"><p class=\"glo underDark\"><a href=\"/wineries/00000\">NATIONAL</a></p><div class=\"wineRegSep\"><p class=\"winereg under\"><a href=\"/wineries/94574\">NAPA VALLEY</a></p><p class=\"winereg under\"><a href=\"/wineries/95476\">SONOMA</a></p><p class=\"winereg underDark\"><a href=\"#\" onclick=\"otherRegions(); return false;\">OTHER REGIONS</a></p></div><p class=\"chi under\"><a href=\"/wineries/chicago\">CHICAGO</a></p><p class=\"det under\"><a href=\"/wineries/detroit\">DETROIT</a></p><p class=\"hou under\"><a href=\"/wineries/houston\">HOUSTON</a></p><p class=\"la under\"><a href=\"/wineries/los-angeles\">LOS ANGELES</a></p><p class=\"nyc under\"><a href=\"/wineries/new-york\">NEW YORK</a></p><p class=\"phi under\"><a href=\"/wineries/philadelphia\">PHILLY</a></p><p class=\"por under\"><a href=\"/wineries/portland\">PORTLAND</a></p><p class=\"sa under\"><a href=\"/wineries/san-antonio\">SAN ANTONIO</a></p><p class=\"sd under\"><a href=\"/wineries/san-diego\">SAN DIEGO</a></p><p class=\"sf underDark\"><a href=\"/wineries/san-francisco\">SAN FRANCISCO</a></p><p class=\"yourZip\"><a href=\"#\" onclick=\"yourCity(); return false;\">OR YOUR CITY</a></p><p class=\"yourZipExplain\">Click to localize WineMcGee by entering your city or zip code.</p><div class=\"cityClose\"><img src=\"/Images/xclose.gif\" /></div>");
	CityPickerModule.render(document.body);													  
	CityPickerModule.cfg.setProperty("zindex", 99999);


	if (winerySearch != null)
	{
		var wineReg = document.getElementById("byWineryName");
		wineReg.checked = "checked";
		searchChange(wineReg);	
		
		document.getElementById("WineryNameEdit").value = winerySearch;
		prepareFilter();
	}
}
YAHOO.util.Event.onDOMReady(init);

