<!--

	//================================================================================================
	// VARIABLES DECLARATION
	//================================================================================================	
	var submitcount = 0;

	function checkFields(){
		if (submitcount == 0) {
			submitcount ++;
			return true;
		}
		else {
			alert("Transaction is in progress.");
			return false;
		}
	}	
	
	//================================================================================================
	// AJAX FUNCTIONS
	//================================================================================================		
	function addToCart(stockID, qty)
	{
		var url = "process.asp";

		var data = "process=stock";
		data = data + "&action=add";
		data = data + "&stockID=" + stockID;
		data = data + "&qty=" + qty;
		data = data + "&sid=" + Math.random();		
		
		var req = new Request( {method: 'get', url: '' + url, 

			onSuccess: function(txt) {			
				if (txt == 'OK')
				{
					window.location = 'checkout.asp';
				}
			},
			
			onFailure: function() {
				alert("Error connecting to server. Please refresh this page...");
			}
			
		}).send(data);
	}
	
	function showBagItems(action, stockID)
	{
		var form = document.checkoutform;
		var div = "div_checkout";
		var qty, info;
		
		if (action == "update")
		{		
			qty = form['qty_' + stockID].value;
		}
		else
		{
			qty = 0;
		}
		
		info = 0;
		if (action == "update" || action == "remove")
		{
			info = form['info_' + stockID].value;
		}

		var url = "get_bagitems.asp";
		var data = "action=" + action;
		data = data + "&stockID=" + stockID;
		data = data + "&qty=" + qty;
		data = data + "&info=" + info;
		data = data + "&sid=" + Math.random();		
		
		var req = new Request( {method: 'get', url: '' + url, 

			onSuccess: function(txt) {
				$(div).set('html', txt);
				calculateTotals();
				// checkDelivery();
			},
			
			// onRequest: function() {
				// $(div).set('html', '<em>Loading items in the shopping bag...</em>');
			// },

			onFailure: function() {
				alert("Error connecting to server. Please refresh this page...");
			}
			
		}).send(data);
	}	
	
	function getComboPickup(infoID, stockID)
	{
		var div = "div_combo_redemption";
		
		var url = "get_pickup.asp";
		var data = "infoID=" + infoID;
		data = data + "&stockID=" + stockID;
		data = data + "&sid=" + Math.random();		
		
		var req = new Request( {method: 'get', url: '' + url, 

			onSuccess: function(txt) {
				$(div).set('html', txt);
			},

			onRequest: function() {
				$(div).set('html', '<em>Please wait...</em>');
			},
			
			onFailure: function() {
				alert("Error connecting to server. Please refresh this page...");
			}
			
		}).send(data);
	}	
	
	function sendEnquiry(listID, fullname, email, phone, address, reason, subscribe, comment)
	{
		var url = "process.asp";

		var data = "process=contact";
		data = data + "&listID=" + listID;
		data = data + "&fullname=" + fullname;
		data = data + "&email=" + email;
		data = data + "&phone=" + phone;
		data = data + "&address=" + escape(address);
		data = data + "&reason=" + reason;
		data = data + "&subscribe=" + subscribe;
		data = data + "&comment=" + escape(comment);
		data = data + "&sid=" + Math.random();		
		
		var req = new Request( {method: 'get', url: '' + url, 

			onSuccess: function(txt) {			
				$('txt_message').set('text', 'Success. Your message has been submitted.');
				alert(txt);
				$('txt_message').set('text', '');
				
				var form = document.contactform;
				form.fullname.value = "";
				form.email.value = "";
				form.phone.value = "";
				form.address.value = "";
				form.reason.value = "";
				form.subscribe.checked = true;
				form.comment.value = "";			
			},
			
			onRequest: function() {
				$('txt_message').set('text', 'Submitting your request. Please wait...');
			},

			onFailure: function() {
				$('txt_message').set('text', '');
				alert("Error connecting to server. Please refresh this page...");
			}
			
		}).send(data);
	}	
	
	function submitPasswordRetrieval(email)
	{
		var url = "process.asp";

		var data = "process=password";
		data = data + "&email=" + email;
		data = data + "&sid=" + Math.random();		
		
		var req = new Request( {method: 'get', url: '' + url, 

			onSuccess: function(txt) {
				alert(txt);				
			},
			
			onFailure: function() {
				alert("Error connecting to server. Please refresh this page...");
			}
			
		}).send(data);
	}	
  
	function signupNewsletter(listID, fullname, email)
	{
		var url = "process.asp";

		var data = "process=recipient";
		data = data + "&action=add-jax";
		data = data + "&listID=" + listID;
		data = data + "&fullname=" + fullname;
		data = data + "&email=" + email;
		data = data + "&sid=" + Math.random();

		var req = new Request( {method: 'get', url: '' + url, 

			onSuccess: function(txt) {
				$('txt_message_signup').set('html', 'Success!');
				alert(txt);
				$('txt_message_signup').set('html', '');
				
				//reset form
				document.signupform.reset();
			},

			onRequest: function() { 
				$('txt_message_signup').set('html', 'Processing...');
			},
			
			onFailure: function() { 
				alert("Error connecting to server. Please refresh this page and try again.");					
				$('txt_message_signup').set('html', '');
			}

		}).send(data);
	}  
	
	//================================================================================================
	// FORM FUNCTIONS
	//================================================================================================
	function submitBuy()
	{
		var form = document.buyform;

		var c_stockID = form.stockID.value;
		var c_qty = form.qty.value;

		var valid = true;

		if (c_stockID.toInt() < 1)
		{
			valid = false;
			alert("Please make sure you have selected ticket option.");
		}
		else if (c_qty.toInt() < 1)
		{
			valid = false;
			alert("Please make sure you have entered quantity.");
		}

		if (valid == true)
		{
			//check if there's date and redemption point
			if ($chk($('event_date')))
			{
				var c_evt_date = form.event_date.value;
				
				if (c_evt_date.toInt() < 1)
				{
					valid = false;
					alert("Please make sure you have selected event date you'd like to attend.");
				}
				else
				{
					var c_pickup = form.pickup.value;
					
					if (c_pickup == '')
					{
						valid = false;
						alert("Please make sure you have selected the ticket redemption point.");
					}				
				}
			}
			
			if (valid == true)
			{
				form.submit();
				//addToCart(c_stockID, c_qty);
			}
		}
	}
	
	function submitEnquiry()
	{
		var form = document.contactform;

		var c_listID = form.listID.value;
		var c_fullname = form.fullname.value;
		var c_email = form.email.value;
		var c_phone = form.phone.value;
		var c_address = form.address.value;
		var c_reason = form.reason.value;
		var c_subscribe;
		var c_comment = form.comment.value;

		var valid = true;

		if (c_fullname == "")
		{
			valid = false;
			alert("Please make sure you have entered your name.");
		}
		else if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(c_email)))
		{
			valid = false;
			alert("Please make sure you have entered a valid e-mail address.");
		}
		else if (c_reason == "")
		{
			valid = false;
			alert("Please make sure you have selected reason for inquiry.");
		}
		else if (c_comment == "")
		{
			valid = false;
			alert("Please make sure you have entered your message.");
		}

		if (form.subscribe.checked == true)
		{
			c_subscribe = "Yes"
		}
		else
		{
			c_subscribe = "No"
		}
		
		if (valid == true)
		{
			sendEnquiry(c_listID, c_fullname, c_email, c_phone, c_address, c_reason, c_subscribe, c_comment);
		}
	}
	
	function calculateTotals()
	{
		var form = document.checkoutform;
		var stock_totals = parseInt(form['stock_totals'].value);
		var total_price = stock_totals;
		var num_stocks = parseFloat(form['num_stocks'].value);
		
		//$('txt_stock_totals').set('html', stock_totals.toFixed(2));		
		$('txt_total_price').set('html', total_price.toFixed(2));
		//$('txt_bag_items').set('html', num_stocks);
		
		if (stock_totals == 0)
		{
			$('cart_checkout_box').setStyle('display', 'none');
			$('empty_cart_box').setStyle('display', 'block');
		}
		else
		{
			$('cart_checkout_box').setStyle('display', 'block');
			$('empty_cart_box').setStyle('display', 'none');
		}
	}	
	
	function submitCustomerLogin()
	{
		var form = document.loginform;
		
		var login_email = form.login_email.value;
		var login_pwd = form.login_pwd.value;
		
		var valid = true;
		
		if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(login_email)))
		{
			valid = false;
			alert("Please make sure you have entered a valid e-mail address.");
		}		
		else if (login_pwd == "")
		{
			valid = false;
			alert("Please make sure you have entered your password.");
		}

		if (valid == true) 
		{
			form.submit();
		}	
	}	

	function submitCustomerDetails()
	{
		var form = document.customerform;
		
		var b_firstname = form.b_firstname.value;
		var b_surname = form.b_surname.value;
		var b_address = form.b_address.value;
		var b_suburb = form.b_suburb.value;
		var b_state = form.b_state.value;
		var b_postcode = form.b_postcode.value;
		var b_phone = form.b_phone.value;
		var b_country = form.b_countryID.value;
		var b_email = form.b_email.value;
		var confirm_email = form.confirm_email.value;
		var b_pwd = form.b_pwd.value;
		var confirm_pwd = form.confirm_pwd.value;
		
		var valid = true;
		var string_alert = "";
		
		if (b_firstname == "")
		{
			valid = false;
			string_alert = string_alert + "Please make sure you have entered your first name for billing.\n"
		} 
		
		if (b_surname == "") 
		{
			valid = false;
			string_alert = string_alert + "Please make sure you have entered your last name for billing.\n"
		} 
		
		if (b_address == "") 
		{
			valid = false;
			string_alert = string_alert + "Please make sure you have entered your street address for billing.\n"
		} 
		
		if (b_suburb == "") 
		{
			valid = false;
			string_alert = string_alert + "Please make sure you have entered your suburb for billing.\n"
		} 
		
		if (b_state == "") 
		{
			valid = false;
			string_alert = string_alert + "Please make sure you have entered your state for billing.\n"
		} 
		
		if (b_postcode == "") 
		{
			valid = false;
			string_alert = string_alert + "Please make sure you have entered your postcode for billing.\n"
		} 		
		
		if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(b_email)))
		{
			valid = false;
			string_alert = string_alert + "Please make sure you have entered a valid e-mail address.\n"
		}		
		else 
		{		
			if (b_email != confirm_email) 
			{
				valid = false;
				string_alert = string_alert + "Confirm email does not match.\n"
			} 				
		}
		
		if (b_pwd == "") 
		{
			valid = false;
			string_alert = string_alert + "Please make sure you have entered a password.\n"
		} 			
		else
		{
			if (b_pwd != confirm_pwd) 
			{
				valid = false;
				string_alert = string_alert + "Confirm password does not match.\n"
			} 				
		}
		
		if (b_phone == "") 
		{
			valid = false;
			string_alert = string_alert + "Please make sure you have entered your phone to enable us to contact you.\n"
		} 		
		
		if (valid == true) 
		{
			form.submit();
		}	
		else
		{
			alert(string_alert);
		}
	}	
	
	function submitForgotPassword()
	{
		var form = document.loginform;
		
		var c_email = form.login_email.value;
		
		var valid = true;
		
		if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(c_email)))
		{
			valid = false;
			alert("Please make sure you have entered a valid e-mail address.");		
		}
		
		if (valid == true) 
		{
			submitPasswordRetrieval(c_email);
		}		
	}		
	
	function submitPayment()
	{
		var form = document.paymentform;
		
		var c_name = form.card_name.value;
		var c_number = form.card_number.value;
		var c_cvv = form.card_cvv.value;
		var c_terms = form.terms;
		
		var valid = true;
		
		if (c_name == "") 
		{
			valid = false;
			alert("Please make sure you have entered the card holder name.");		
		}
		else if (c_number == "") 
		{
			valid = false;
			alert("Please make sure you have entered the card number.");		
		} 
		else if (c_cvv == "") 
		{
			valid = false;
			alert("Please make sure you have entered the card security number. It's the last 3 digits on the back of the card.");		
		} 
		else if (c_terms.checked == false) 
		{
			valid = false;
			alert("Please make sure you have read and agreed with our terms and conditions.");		
		} 
		
		if (valid == true) 
		{
			form.submit();
			checkFields();
		}		
	}	
	
	function submitSubscription()
	{
		var form = document.signupform;

		var c_listID = form.listID.value;
		var c_name = form.fullname.value;
		var c_email = form.email.value;

		var valid = true;

		if ((c_name == "") || (c_name == "Your name"))
		{
			valid = false;
			alert("Please make sure you've entered your name.");
		}
		else if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(c_email)))
		{
			valid = false;
			alert("Please make sure you've entered valid e-mail address.");
		}

		if (valid) 
		{
			signupNewsletter(c_listID, c_name, c_email);
		}
	}
  
	//================================================================================================
	// LAYOUT FUNCTIONS 
	//================================================================================================			
	function resetMenuPositions()
	{
		var w = window.getWidth() / 2 - 575;
		$('wineregionContainer').setStyle('left', (w + 260) + 'px');
		$('winesContainer').setStyle('left', (w + 580) + 'px');
		$('newsContainer').setStyle('left', (w + 740) + 'px');
		$('associationContainer').setStyle('left', (w + 900) + 'px');
	}		
	
	function initOpacity()
	{
		if ($chk($('header_bg')))
		{
			$('header_bg').setStyle('opacity', 0.7);
		}
	}
	
	function setupSlideshows()
	{
		if ($chk($('home_banner')))
		{			
			var homeShow = new Slideshow('home_banner', false, {delay: 4000, width: 1150, height: 385});
		}	
	}	
	
	//================================================================================================
	// EVENTS FUNCTIONS
	//================================================================================================		
	function setupActions()
	{
		if ($chk($$('.nav_hover')[0])) 
		{				
			$$('.nav_hover').addEvents({
			
				'mouseover' : function(e) {
					var srcURL = this.getProperty('src');
					if ($chk(srcURL))
						this.setProperty('src', srcURL.replace('.gif', '_hover.gif'));
				},
			
				'mouseout' : function(e) {
					var srcURL = this.getProperty('src');
					if ($chk(srcURL))
						this.setProperty('src', srcURL.replace('_hover.gif', '.gif'));					
				}
				
			});					
		}
		
		if ($chk($$('.img_hover')[0])) 
		{				
			$$('.img_hover').setStyle('opacity', 0.75);
			$$('.img_hover').addEvents({
			
				'mouseover' : function(e) {
					this.setStyle('opacity', 1);
				},
			
				'mouseout' : function(e) {
					this.setStyle('opacity', 0.75);
				}
				
			});					
		}
		
		if ($chk($$('.date_item')[0])) 
		{				
			$$('.date_item').addEvents({
			
				'mouseover' : function(e) {
					if (this.hasClass('bg_event_odd'))
					{
						this.addClass('bg_event_odd_hover');
					}
					else
					{
						this.addClass('bg_event_even_hover');
					}
				},
			
				'mouseout' : function(e) {
					if (this.hasClass('bg_event_odd'))
					{
						$$('.date_item').removeClass('bg_event_odd_hover');
					}
					else
					{
						$$('.date_item').removeClass('bg_event_even_hover');
					}
				}
				
			});					
		}		
		
		if ($chk($$('.img_protect')))
		{
			$$('.img_protect').addEvents({								
				'contextmenu' : function(e) {
					e.stop();
				}									
			});
		}		
	}	
	
	function backToTop()
	{
		new Fx.Scroll($(window)).toTop();
	}
	
	function setupCufons()
	{
		Cufon.replace('.tstar, .calendar_heading', { fontFamily: 'TSTAR' });
	}	
	
	//================================================================================================
	// START THIS WHEN PAGE DOM READY
	//================================================================================================		
	window.addEvents({
	
		'domready' : function(e) {
			initOpacity();
			setupSlideshows();
			setupActions();
			setupCufons();
			resetMenuPositions();
			
			if ($chk($('div_checkout')))
			{	
				showBagItems('default', 0);
			}				
		},
		
		'resize' : function() {
			resetMenuPositions();
		}
		
	});
	

//-->
