<!--

	//================================================================================================
	// VARIABLES DECLARATION
	//================================================================================================	
	var openWhereToBuy = false, openDistributors = false, openContactUs = false, openTradeLogin = false;
	var flagLatestNews = true;

	//================================================================================================
	// AJAX FUNCTIONS
	//================================================================================================		
	function sendEnquiry(fullname, email, address, suburb, state, postcode, phone, comment)
	{
		var url = "process.asp";

		var data = "process=contact";
		data = data + "&fullname=" + fullname;
		data = data + "&email=" + email;
		data = data + "&address=" + address;
		data = data + "&suburb=" + suburb;
		data = data + "&state=" + state;
		data = data + "&postcode=" + postcode;
		data = data + "&phone=" + phone;
		data = data + "&comment=" + comment;
		data = data + "&sid=" + Math.random();		

		var req = new Request( {method: 'get', url: '' + url, 

			onSuccess: function(txt) {
				alert(txt);
        hideContactUs();
        document.contactform.reset();        
			},

			onFailure: function() {
				//alert("Message sent. Thanks for your enquiry.");
				alert("Error connecting to server. Please refresh this page...");
			}

		}).send(data);
	}	

	function sendSignup(email, pwd, company, contact, address, suburb, state, postcode, phone, hr)
	{
		var url = "process.asp";

		var data = "process=register";
		data = data + "&email=" + email;
		data = data + "&pwd=" + pwd;
		data = data + "&company=" + company;
		data = data + "&contact=" + contact;
		data = data + "&address=" + address;
		data = data + "&suburb=" + suburb;
		data = data + "&state=" + state;
		data = data + "&postcode=" + postcode;
		data = data + "&phone=" + phone;
		data = data + "&hr=" + hr;
		data = data + "&sid=" + Math.random();		
		
		var btn_submit = $('btn_submit_register');
		
		var req = new Request( {method: 'get', url: '' + url, 

			onSuccess: function(txt) {	
				
				if (txt.indexOf("Success") >= 0)
				{
          alert(txt);
          $(btn_submit).disabled = 0;
          $(btn_submit).set('value', $(btn_submit).get('title'));
          document.registerform.reset();
				}
				else
				{
					alert(txt);
					$(btn_submit).disabled = 0;
					$(btn_submit).set('value', $(btn_submit).get('title'));
				}        
			},
			
			onRequest: function() { 
				$(btn_submit).disabled = 1;
				$(btn_submit).set('value', 'Processing...');
			},
			
			onFailure: function() { 
				alert("Error connecting to server. Please refresh this page and try again.");					
				$(btn_submit).disabled = 0;
				$(btn_submit).set('value', $(btn_submit).get('title'));
			}	
			
		}).send(data);
	}  
  
	function sendUpdateProfile(email, pwd, company, contact, address, suburb, state, postcode, phone)
	{
		var url = "process.asp";

		var data = "process=profile";
		data = data + "&email=" + email;
		data = data + "&pwd=" + pwd;
		data = data + "&company=" + company;
		data = data + "&contact=" + contact;
		data = data + "&address=" + address;
		data = data + "&suburb=" + suburb;
		data = data + "&state=" + state;
		data = data + "&postcode=" + postcode;
		data = data + "&phone=" + phone;
		data = data + "&sid=" + Math.random();		
		
		var btn_submit = $('btn_submit_profile');
		
		var req = new Request( {method: 'get', url: '' + url, 

			onSuccess: function(txt) {	
        alert(txt);
        $(btn_submit).disabled = 0;
        $(btn_submit).set('value', $(btn_submit).get('title'));
			},
			
			onRequest: function() { 
				$(btn_submit).disabled = 1;
				$(btn_submit).set('value', 'Processing...');
			},
			
			onFailure: function() { 
				alert("Error connecting to server. Please refresh this page and try again.");					
				$(btn_submit).disabled = 0;
				$(btn_submit).set('value', $(btn_submit).get('title'));
			}	
			
		}).send(data);
	}   
  
	function requestLogin(email, password)
	{
		var url = "process.asp";

		var data = "process=login";
		data = data + "&email=" + email;
		data = data + "&pwd=" + password;
		data = data + "&sid=" + Math.random();		
		
		var btn_submit = $('btn_submit_login');
		
		var req = new Request( {method: 'get', url: '' + url, 

			onSuccess: function(txt) {

				if (txt.indexOf("Success") >= 0)
				{
					$(btn_submit).disabled = 0;
					$(btn_submit).set('value', 'Redirecting...');
          var temp = $(window).location + "";
					$(window).location = "main.asp";
				}
				else
				{
					alert(txt);
					$(btn_submit).disabled = 0;
					$(btn_submit).set('value', $(btn_submit).get('title'));
				}
			},
			
			onRequest: function() { 
				$(btn_submit).disabled = 1;
				$(btn_submit).set('value', 'Processing...');
			},
			
			onFailure: function() { 
				alert("Error connecting to server. Please refresh this page and try again.");					
				$(btn_submit).disabled = 0;
				$(btn_submit).set('value', $(btn_submit).get('title'));
			}	
			
		}).send(data);
	}	
	
	function requestForgotPassword(email)
	{
		var url = "process.asp";

		var data = "process=forgot_password";
		data = data + "&email=" + email;
		data = data + "&sid=" + Math.random();		
		
		var btn_submit = $('btn_submit_password');
		
		var req = new Request( {method: 'get', url: '' + url, 

			onSuccess: function(txt) {
				alert(txt);				
				$(btn_submit).disabled = 0;
				$(btn_submit).set('value', $(btn_submit).get('title'));
				document.passwordform.reset();
			},
			
			onRequest: function() { 
				$(btn_submit).disabled = 1;
				$(btn_submit).set('value', 'Processing...');
			},
			
			onFailure: function() { 
				alert("Error connecting to server. Please refresh this page and try again.");					
				$(btn_submit).disabled = 0;
				$(btn_submit).set('value', $(btn_submit).get('title'));
			}	
			
		}).send(data);
	}	
  
	//================================================================================================
	// FORM FUNCTIONS
	//================================================================================================
	function submitEnquiry()
	{
		var form = document.contactform;
		
		var c_fullname = form.fullname.value;
		var c_email = form.email.value;
		var c_address = form.address.value;
		var c_suburb = form.suburb.value;
		var c_state = form.state.value;
		var c_postcode = form.postcode.value;
		var c_phone = form.phone.value;
		var c_comment = form.comment.value;
		
		var valid = true;
		
		if ((c_fullname == "") || (c_fullname == "Name")) 
		{
			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_address == "") || (c_address == "Street address")) 
		{
			valid = false;
			alert("Please make sure you have entered your street address.");		
		} 
		else if ((c_suburb == "") || (c_suburb == "Suburb")) 
		{
			valid = false;
			alert("Please make sure you have entered your suburb.");		
		} 
		else if ((c_state == "") || (c_state == "State")) 
		{
			valid = false;
			alert("Please make sure you have entered your state.");		
		} 
		else if ((c_postcode == "") || (c_postcode == "Postcode")) 
		{
			valid = false;
			alert("Please make sure you have entered your postcode.");		
		} 
		else if ((c_phone == "") || (c_phone == "Phone")) 
		{
			valid = false;
			alert("Please make sure you have entered your phone number.");		
		} 
		else if ((c_comment == "") || (c_comment == "Comments or enquiries")) 
		{
			valid = false;
			alert("Please make sure you have entered comments or enquiries.");		
		} 
		
		if (valid == true) 
		{			
			sendEnquiry(c_fullname, c_email, c_address, c_suburb, c_state, c_postcode, c_phone, c_comment);
		}		
	}  
  
	function submitRegister()
	{
		var form = document.registerform;

		var c_email = form.email.value;
		var c_pwd = form.pwd.value;
		var c_confirm_pwd = form.confirm_pwd.value;
		var c_company = form.company.value;
		var c_contact = form.contact.value;
		var c_address = form.address.value;
		var c_suburb = form.suburb.value;
		var c_state = form.state.value;
		var c_postcode = form.postcode.value;
		var c_phone = form.phone.value;
		var c_hr = form.hr.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.");
		}
		else if (c_pwd == "")
		{
			valid = false;
			alert("Please make sure you have entered your password.");
		}
		else if (c_pwd != c_confirm_pwd)
		{
			valid = false;
			alert("Confirm password does not match the password");
		}
		else if (c_company == "")
		{
			valid = false;
			alert("Please make sure you have entered your company name.");
		}
		else if (c_contact == "")
		{
			valid = false;
			alert("Please make sure you have entered the contact person name.");
		}
		else if (c_address == "")
		{
			valid = false;
			alert("Please make sure you have entered your street address.");
		}
		else if (c_suburb == "")
		{
			valid = false;
			alert("Please make sure you have entered your suburb.");
		}
		else if (c_state == "0")
		{
			valid = false;
			alert("Please make sure you have selected your state.");
		}
		else if (c_postcode == "")
		{
			valid = false;
			alert("Please make sure you have entered your postcode.");
		}
		else if (c_phone == "")
		{
			valid = false;
			alert("Please make sure you have entered your phone.");
		}
		else if (c_hr == "")
		{
			valid = false;
			alert("Please make sure you have answered the security question.");
		}
		
		if (valid == true)
		{
			sendSignup(c_email, c_pwd, c_company, c_contact, c_address, c_suburb, c_state, c_postcode, c_phone, c_hr);
		}
	}  
  
	function submitProfile()
	{
		var form = document.profileform;

		var c_email = form.email.value;
		var c_pwd = form.pwd.value;
		var c_confirm_pwd = form.confirm_pwd.value;
		var c_company = form.company.value;
		var c_contact = form.contact.value;
		var c_address = form.address.value;
		var c_suburb = form.suburb.value;
		var c_state = form.state.value;
		var c_postcode = form.postcode.value;
		var c_phone = form.phone.value;

		var valid = true;

		if (c_pwd == "")
		{
			valid = false;
			alert("Please make sure you have entered your password.");
		}
		else if (c_pwd != c_confirm_pwd)
		{
			valid = false;
			alert("Confirm password does not match the password");
		}
		else if (c_company == "")
		{
			valid = false;
			alert("Please make sure you have entered your company name.");
		}
		else if (c_contact == "")
		{
			valid = false;
			alert("Please make sure you have entered the contact person name.");
		}
		else if (c_address == "")
		{
			valid = false;
			alert("Please make sure you have entered your street address.");
		}
		else if (c_suburb == "")
		{
			valid = false;
			alert("Please make sure you have entered your suburb.");
		}
		else if (c_state == "0")
		{
			valid = false;
			alert("Please make sure you have selected your state.");
		}
		else if (c_postcode == "")
		{
			valid = false;
			alert("Please make sure you have entered your postcode.");
		}
		else if (c_phone == "")
		{
			valid = false;
			alert("Please make sure you have entered your phone.");
		}
		
		if (valid == true)
		{
			sendUpdateProfile(c_email, c_pwd, c_company, c_contact, c_address, c_suburb, c_state, c_postcode, c_phone);
		}
	}  
	
	function submitTradeLogin()
	{
		var form = document.loginform;
		
		var c_email = form.email.value;
		var c_pwd = form.pwd.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.");		
		}
		else if ((c_pwd == "")) 
		{
			valid = false;
			alert("Please make sure you have entered your password.");		
		} 
		
		if (valid == true) 
		{			
      requestLogin(c_email, c_pwd);
		}		
	}
  
	function submitForgotPassword()
	{
		var form = document.passwordform;
		
		var c_email = form.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) 
		{			
      requestForgotPassword(c_email);
		}		
	}  
  
	function submitOrder()
	{
		var form = document.orderform;
		var grandTotal = parseInt(form['order_grandtotal'].value);

		var valid = true;
		
		if (grandTotal <= 200)
		{
			alert("Minimum total order is $200.");
			valid = false;
		} 
				
		if (valid)
		{
			form.submit();
		}
	}  
  
	function updateTotal(productID)
	{
		var form = document.orderform;

		var c_qty = form['qty_' + productID];
		var c_price = form['price_' + productID];
		var c_priceper = form['priceper_' + productID];
		var c_total = $('total_' + productID).get('html');	
		
		var intQty, intQtyPer, floatPrice, floatNewTotal;
		
		if (!IsNumeric(c_qty.value))
		{
			c_qty.value = "0";
			$('total_' + productID).set('html', '0.00');
		}
		else
		{
			intQty = parseInt(c_qty.value);
      intQtyPer = parseInt(c_priceper.value);
			floatPrice = parseFloat(c_price.value);
			
			floatNewTotal = floatPrice * intQty * intQtyPer;

			c_qty.value = intQty;
			$('total_' + productID).set('html', floatNewTotal.toFixed(2));
		}		

		//subtotal
		var floatSubTotal = calculateSubTotal();
		//$('subtotal').set('html', floatSubTotal.toFixed(2));
		//form['order_subtotal'].value = floatSubTotal.toFixed(2);
		
		calculateGrandTotal(floatSubTotal.toFixed(2), 0, 0);		
	}	  
  
	function calculateGrandTotal(subtotal, discount, delivery)
	{		
		var form = document.orderform;		
		var floatGrandTotal = (subtotal - discount) + delivery;
		
		$('grandtotal').set('html', floatGrandTotal.toFixed(2));
		form['order_grandtotal'].value = floatGrandTotal.toFixed(2);					
	}  
  
	function calculateSubTotal()
	{
		var subTotal = 0;	
		var arrTotal = $$('.totalbox').get('html');
				
		for (i=0; i < arrTotal.length; i++)
		{
			subTotal = subTotal + parseFloat(arrTotal[i]);
		}		
		
		return subTotal;
	}  
	
	//================================================================================================
	// LAYOUT FUNCTIONS 
	//================================================================================================			
	function resetMenuPositions()
	{
		var w = window.getWidth() / 2 - 490;
		$('randomharvestContainer').setStyle('left', (w + 65) + 'px');

		// $('container_wheretobuy').setStyle('left', (w + 150) + 'px');				
		// $('container_distributors').setStyle('left', (w + 285) + 'px');				
		// $('container_tradelogin').setStyle('left', (w + 400) + 'px');				
		// $('container_contactus').setStyle('left', (w + 480) + 'px');				

		$('millicentgroveContainer').setStyle('left', (w + 185) + 'px');
		$('container_wheretobuy').setStyle('left', (w + 265) + 'px');				
		$('container_distributors').setStyle('left', (w + 400) + 'px');				
		//$('container_tradelogin').setStyle('left', (w + 515) + 'px');				
		$('container_contactus').setStyle('left', (w + 595) + 'px');				
		//$('container_latest_news').setStyle('left', (w + 775) + 'px');				
	}
	
	function showLatestNews(show)
	{
		var top = (show ? '0px' : '-170px');
		
		if (flagLatestNews)
		{
			flagLatestNews	= false;
			new Fx.Morph('container_latest_news').start( {'top' : top } ).chain(function() {
				flagLatestNews = true;
			}); 
		}
	}
	
	function showProduct(id)
	{
		new Fx.Scroll('scrollable_product_details').toElement('product_' + id);		
	}	
	
	function showDistributor(id)
	{
		new Fx.Scroll('scrollable_distributors').toElement('distributor_' + id);		
	}		
	
	function showWhereToBuy()
	{
		if (!openWhereToBuy)
		{
			hideDistributors();
			hideTradeLogin();
			hideContactUs();
			
			$('container_wheretobuy').setStyle('display', 'block');	
		}
		openWhereToBuy = true;
	}	
	
	function hideWhereToBuy()
	{
		if (openWhereToBuy)
		{
			$('container_wheretobuy').setStyle('display', 'none');	
		}
		openWhereToBuy = false;
	}	

	function toggleWhereToBuy()
	{
		if (openWhereToBuy)
		{
			hideWhereToBuy();
		}
		else
		{
			showWhereToBuy();
		}
	}
	
	function showDistributors()
	{
		if (!openDistributors)
		{
			hideWhereToBuy();
			hideTradeLogin();
			hideContactUs();
			
			$('container_distributors').setStyle('display', 'block');	
		}
		openDistributors = true;
	}	
	
	function hideDistributors()
	{
		if (openDistributors)
		{
			$('container_distributors').setStyle('display', 'none');	
		}
		openDistributors = false;
	}	

	function toggleDistributors()
	{
		if (openDistributors)
		{
			hideDistributors();
		}
		else
		{
			showDistributors();
		}
	}	
	
	function showTradeLogin()
	{
		if (!openTradeLogin)
		{
			hideWhereToBuy();
			hideDistributors();
			hideContactUs();
			
			$('container_tradelogin').setStyle('display', 'block');	
		}
		openTradeLogin = true;
	}	
	
	function hideTradeLogin()
	{
		if (openTradeLogin)
		{
			$('container_tradelogin').setStyle('display', 'none');	
		}
		openTradeLogin = false;
	}	

	function toggleTradeLogin()
	{
		if (openTradeLogin)
		{
			hideTradeLogin();
		}
		else
		{
			showTradeLogin();
		}
	}	
	
	function showContactUs()
	{
		if (!openContactUs)
		{
			hideWhereToBuy();
			hideTradeLogin();
			hideDistributors();
			
			$('container_contactus').setStyle('display', 'block');	
		}
		openContactUs = true;
	}	
	
	function hideContactUs()
	{
		if (openContactUs)
		{
			$('container_contactus').setStyle('display', 'none');	
		}
		openContactUs = false;
	}	

	function toggleContactUs()
	{
		if (openContactUs)
		{
			hideContactUs();
		}
		else
		{
			showContactUs();
		}
	}	

	function setupCufons()
	{
		Cufon.replace('.josschrift', { fontFamily: 'Josschrift' });
	}	  
	
	//================================================================================================
	// EVENTS FUNCTIONS
	//================================================================================================		
	function setupActions()
	{
		if ($chk($('container_latest_news')))
		{
			$("container_latest_news").addEvents({
				
				'mouseover' : function(e) {
					showLatestNews(true);
				},
			
				'mouseout' : function(e) {
					showLatestNews(false);
				}
				
			});	
		}
	}	
	
	function setupScrollbars()
	{
		if ($chk($('product_area_scroller')))
		{
			makeScrollbar( $('scrollable_product_thumbs'), $('product_scroller'), $('scroller_handle'), true );
		}				
	}	
	
	function $E(tag,el){return $(el||document).getElement(tag)}
	
	kina={
		doc:{x:0,y:0},
		fix:
			function()
			{				
				if(kina.bg.complete&&(db.offsetWidth!=kina.doc.x||db.offsetHeight!=kina.doc.y||kina.fix.src!=kina.bg.src))
				{
					var bg=kina.bg.getSize();
					kina.doc={x:db.offsetWidth,y:db.offsetHeight};
					kina.fix.src==kina.bg.src||$extend(kina.fix,{p:bg.x/bg.y,src:kina.bg.src});
					kina.bg.setStyles({width:(bg.y=kina.doc.x>(bg.x=Math.round(kina.doc.y*kina.fix.p)))?kina.doc.x:bg.x,height:bg.y?Math.round(kina.doc.x/kina.fix.p):kina.doc.y})			
				}								
			}
	}	
	
	//================================================================================================
	// START THIS WHEN PAGE DOM READY
	//================================================================================================		
	window.addEvents({
	
		'domready' : function(e) {
			setupScrollbars();
			setupCufons();
			//setupActions();
			//showLatestNews(false);
			
			resetMenuPositions();
			
			if ($chk($('bg')))
			{
				$extend
				(
					kina,{bg:$E('img',$E('#bg',db=$(document.body))),timer:setInterval(kina.fix,100),menu:$('menu')}
				);			
			}
		},
		
		'resize' : function() {
			resetMenuPositions();
		}
		
	});
	

//-->
