function timeChange(season_index) {
    var date = new Date();
	var time = date.getHours() + "" + date.getMinutes();
	
	new Ajax.Request('seasons_times.xml',
      {
        method:'get',
        onSuccess: function(transport){
          var xml = parseXML(transport.responseText);
          var season = xml.getElementsByTagName('season')[season_index];
          
          var time_info = $A(season.getElementsByTagName('time')).findAll(function(item) {
            return parseInt(item.getAttribute('start')) < parseInt(time);  
          }).last();

          
          $$('#content h1')[0].innerHTML = getNodeValue(time_info,'title');
          $$('#content p')[0].innerHTML = getNodeValue(time_info,'info');
          $$('body')[0].className = 'time-' + time_info.getAttribute('start'); 
        },
        onFailure: function(){ alert('Something went wrong...') }
      })
	
}

function parseXML(text) {
    var xml = Try.these(
        function() { return new DOMParser().parseFromString(text, 'text/xml'); },
        function() { var xmldom = new ActiveXObject('Microsoft.XMLDOM'); xmldom.loadXML(text); return xmldom; }
    );
    return xml;
}

function getNodeValue(obj,tag) {
	return obj.getElementsByTagName(tag)[0].firstChild.nodeValue;
}

function switchPresetText(inviteID){
	if(document.getElementById === null || document.getElementById('invite_text') === null) { return false;}
	
	var inviteText = document.getElementById('invite_text');
	
	if (inviteID=="invite1") {
		inviteText.value = "We swould be absolutely delighted if you would kindly join us at our residence for a soir\xe9e of wine, cheese and conversation of the highest order. \n\n";
	} else if (inviteID=="invite2") {
		inviteText.value = "Come over and we'll give you some cheese. And if you're really lucky we'll give you some wine too.\n\n";
	} else if (inviteID=="invite3") {
		inviteText.value = "YOU'RE WANTED: Alive \nPlease drink responsibly! Arla foods. \n\nREWARD: Cheese \n\nCome to our upcoming soir\xe9e and we'll not only feed you with the finest cheeses known to humanity, we'll pontificate at length over a glass of wine. Or two. Or three. Why not four? Who knows? In fact, just come over and see what happens. \n\n";
	} else {
		inviteText.value = "We'd love it if you could join us for our get together. \n\n";
	}
}

function switchTab(tabID){
	if(document.getElementById ===null || document.getElementById('nutrition-info-white') ===null || document.getElementById('nutrition-info-blue') ===null || document.getElementById('nutrition-info') ===null){ return false;}
	
	var blueTable=document.getElementById('nutrition-info-blue');
	var whiteTable=document.getElementById('nutrition-info-white');
	var nutritionTab=document.getElementById('nutrition-info');
	
	if(tabID=="blue"){
		blueTable.style.display="block";
		whiteTable.style.display="none";
		nutritionTab.style.display="block";
	}else if(tabID=="white"){
		whiteTable.style.display="block";
		blueTable.style.display="none";		
		nutritionTab.style.display="block";
	}else{
		blueTable.style.display="none";
		whiteTable.style.display="none";
		nutritionTab.style.display="none";
	}
}

function compareEmails(valid, formObj){
	if(valid){
		if(formObj.email.value!=formObj.email_conf.value){
			alert("Your email confirmation does not match.");
			formObj.email_conf.focus();
			return false;
		}
	}
}

