// Anti Spam
function AntiSpam( name, domn, text ) {
if( ! text || text == "" ) text = name + "@" + domn;
document.write( "<a href=\"mailto:" + name + "@" + domn + "\">" +
text + "</a>" )
}

var welcome = "welcome";	// stores which content is actually loaded in the content div (especially for the language changing on the welcome sites)

function showHome(){
	// new Ajax.Updater({success:  'sideMenu' , failure: 'notice'},  './content/sideMenuNews.html' );
	new Ajax.Updater({success:  'content' , failure: 'notice'},  './content/home.html' );
	pageTracker._trackPageview('/content/home');
}
function showSMD(){
	//new Ajax.Updater({success:  'sideMenu' , failure: 'notice'},  './content/sideMenuNews.html' );
	new Ajax.Updater({success:  'content' , failure: 'notice'},  './content/smd.html' );
	pageTracker._trackPageview('/content/smd');
}
function showProgram(){
	$('sideMenu').style.paddingBottom= "0%";
	$('sideMenu').style.verticalAlign="middle";
	new Ajax.Updater({success:  'sideMenu' , failure: 'notice'},  './content/sideMenuProgram.html' );
	new Ajax.Updater({success:  'content' , failure: 'notice'},  './content/program.html' );
	pageTracker._trackPageview('/content/program');
}

function showWelcome(lang){
	$('sideMenu').style.paddingBottom="12%";
	switch (lang) {
	case "German":
		new Ajax.History.Updater({success:  'content' , failure: 'notice'},  './content/welcomeGerman.html' );
		new Ajax.History.Updater({success:  'sideMenu' , failure: 'notice'}, './content/sideMenuWelcomeGerman.html' , {asynchronous: false});
		// asynchron because the elements have to be loaded into the DOM before calling the function boldSideMenu(menu_name)
		pageTracker._trackPageview('/content/welcome_de');
		break;
	case "English":
		new Ajax.Updater({success:  'content' , failure: 'notice'},  './content/welcomeEnglish.html' );
		new Ajax.Updater({success:  'sideMenu' , failure: 'notice'},  './content/sideMenuWelcomeEnglish.html' , {asynchronous: false});
		pageTracker._trackPageview('/content/welcome_en');
		break;
	case "French":
		new Ajax.Updater({success:  'content' , failure: 'notice'},  './content/welcomeFrench.html' );
		new Ajax.Updater({success:  'sideMenu' , failure: 'notice'},  './content/sideMenuWelcomeFrench.html' , {asynchronous: false});
		pageTracker._trackPageview('/content/welcome_fr');
		break;
	case "Spanish":
		new Ajax.Updater({success:  'content' , failure: 'notice'},  './content/welcomeSpanish.html' );
		new Ajax.Updater({success:  'sideMenu' , failure: 'notice'},  './content/sideMenuWelcomeSpanish.html' , {asynchronous: false});
		pageTracker._trackPageview('/content/welcome_es');
		break;
	default:
		new Ajax.Updater({success:  'content' , failure: 'notice'},  './content/welcomeGerman.html' );
		new Ajax.Updater({success:  'sideMenu' , failure: 'notice'},  './content/sideMenuWelcomeGerman.html' , {asynchronous: false});
		pageTracker._trackPageview('/content/welcome_de');
		break;
	}
	welcome="welcome";
	boldSideMenu(welcome);
}

function boldSideMenu(menu_name) {
		var menu = "menu_" + menu_name;
		$(menu).style.fontWeight = "bold";
}

function showLearningGerman(lang){
	$('sideMenu').style.paddingBottom="12%";
	switch (lang) {
	case "German":
		new Ajax.Updater({success:  'content' , failure: 'notice'},  './content/learningGermanGerman.html' );
		new Ajax.Updater({success:  'sideMenu' , failure: 'notice'},  './content/sideMenuWelcomeGerman.html', {asynchronous: false});
		pageTracker._trackPageview('/content/learningGerman_de');
		break;
	case "English":
		new Ajax.Updater({success:  'content' , failure: 'notice'},  './content/learningGermanEnglish.html' );
		new Ajax.Updater({success:  'sideMenu' , failure: 'notice'},  './content/sideMenuWelcomeEnglish.html' , {asynchronous: false});
		pageTracker._trackPageview('/content/learningGerman_en');
		break;
	case "French":
		new Ajax.Updater({success:  'content' , failure: 'notice'},  './content/learningGermanFrench.html' );
		new Ajax.Updater({success:  'sideMenu' , failure: 'notice'},  './content/sideMenuWelcomeFrench.html' , {asynchronous: false});
		pageTracker._trackPageview('/content/learningGerman_fr');
		break;
	case "Spanish":
		new Ajax.Updater({success:  'content' , failure: 'notice' },  './content/learningGermanSpanish.html' );
		new Ajax.Updater({success:  'sideMenu' , failure: 'notice'},  './content/sideMenuWelcomeSpanish.html' , {asynchronous: false});
		pageTracker._trackPageview('/content/learningGerman_es');
		break;
	default:
		new Ajax.Updater({success:  'content' , failure: 'notice'},  './content/learningGermanGerman.html' );
		new Ajax.Updater({success:  'sideMenu' , failure: 'notice'},  './content/sideMenuWelcomeGerman.html' , {asynchronous: false});
		pageTracker._trackPageview('/content/learningGerman_de');
		break;
	}
	welcome="learningGerman";
	boldSideMenu(welcome);
}

function showHospitality(lang){
	$('sideMenu').style.paddingBottom="12%";
	switch (lang) {
	case "German":
		new Ajax.Updater({success:  'content' , failure: 'notice'},  './content/hospitalityGerman.html' );
		new Ajax.Updater({success:  'sideMenu' , failure: 'notice'},  './content/sideMenuWelcomeGerman.html' , {asynchronous: false});
		pageTracker._trackPageview('/content/hospitality_de');
		break;
	case "English":
		new Ajax.Updater({success:  'content' , failure: 'notice'},  './content/hospitalityEnglish.html' );
		new Ajax.Updater({success:  'sideMenu' , failure: 'notice'},  './content/sideMenuWelcomeEnglish.html' , {asynchronous: false});
		pageTracker._trackPageview('/content/hospitality_en');
		break;
	case "French":
		new Ajax.Updater({success:  'content' , failure: 'notice'},  './content/hospitalityFrench.html' );
		new Ajax.Updater({success:  'sideMenu' , failure: 'notice'},  './content/sideMenuWelcomeFrench.html' , {asynchronous: false});
		pageTracker._trackPageview('/content/hospitality_fr');
		break;
	case "Spanish":
		new Ajax.Updater({success:  'content' , failure: 'notice'},  './content/hospitalitySpanish.html' );
		new Ajax.Updater({success:  'sideMenu' , failure: 'notice'},  './content/sideMenuWelcomeSpanish.html' , {asynchronous: false});
		pageTracker._trackPageview('/content/hospitality_es');
		break;
	default:
		new Ajax.Updater({success:  'content' , failure: 'notice'},  './content/hospitalityGerman.html' );
		new Ajax.Updater({success:  'sideMenu' , failure: 'notice'},  './content/sideMenuWelcomeGerman.html' , {asynchronous: false});
		pageTracker._trackPageview('/content/hospitality_de');
		break;
	}
	welcome="hospitality";
	boldSideMenu(welcome);
}

function switchLanguage(lang){
	switch (welcome){
	case "welcome":
		showWelcome(lang)
		break;
	case "learningGerman":
		showLearningGerman(lang)
		break;
	case "hospitality":
		showHospitality(lang)
		break;
	default:
		showWelcome(lang)
		break;
	}
}

function showGallery(){
	$('sideMenu').style.paddingBottom="12%";
	new Ajax.Updater({success:  'sideMenu' , failure: 'notice'},  './content/sideMenuNews.html' );
	new Ajax.Updater({success:  'content' , failure: 'notice'},  './content/gallery.html' );
	pageTracker._trackPageview('/content/gallery');
}
function showLinks(){
	new Ajax.Updater({success:  'sideMenu' , failure: 'notice'},  './content/sideMenuNews.html' );
	new Ajax.Updater({success:  'content' , failure: 'notice'},  './content/links.html' );
	pageTracker._trackPageview('/content/links');
}
function showContact(){
	new Ajax.Updater({success:  'sideMenu' , failure: 'notice'},  './content/sideMenuNews.html' );
	new Ajax.Updater({success:  'content' , failure: 'notice'},  './content/contacts.html' );
	pageTracker._trackPageview('/content/contact');
}
function showImprint(){
	new Ajax.Updater({success:  'sideMenu' , failure: 'notice'},  './content/sideMenuNews.html' );
	new Ajax.Updater({success:  'content' , failure: 'notice'},  './content/imprint.html' );
	pageTracker._trackPageview('/content/imprint');
}

function initiateSite(){
	//History.Observer.start();
	/*History.Registry.set('page', function() {
    console.log(value);
});*/
	switch(History.get('page')){
		case "home":
			showHome();
			break;
		case "smd":
			showSMD();
			break;
		case "program":
			showProgram();
			break;
		case "welcome_de":
			showWelcome("German");
			break;
		case "welcome_en":
			showWelcome("English");
			break;
		case "welcome_fr":
			showWelcome("French");
			break;
		case "welcome_es":
			showWelcome("Spanish");
			break;
		case "learningGerman_de":
			showLearningGerman("German");
			break;
		case "learningGerman_en":
			showLearningGerman("English");
			break;
		case "learningGerman_fr":
			showLearningGerman("French");
			break;
		case "learningGerman_es":
			showLearningGerman("Spanish");
			break;
		case "hospitality_de":
			showHospitality("German");
			break;
		case "hospitality_en":
			showHospitality("English");
			break;
		case "hospitality_fr":
			showHospitality("French");
			break;
		case "hospitality_es":
			showHospitality("Spanish");
			break;
		case "gallery":
			showGallery();
			break;
		case "links":
			showLinks();
			break;
		case "contact":
			showContact();
			break;
		case "imprint":
			showImprint();
			break;
		default:
			showHome();
			break;
		}
}

/**
 * form utilities
 * @author pete goodman
 *
 */
var formUtil = {

	/**
	 * functions to clear a textbox of text
	 * @param id string the id of the text field in question
	 */
	autoFill : function (id){
		
		// retrieve the field, and access it's default text
		var field = document.getElementById(id);
		var defaulttext = field.value;

		// if default text is present when selected, hide it 
		field.onfocus = function() {
			if (this.value == defaulttext) {
				this.value = "";
			}
		}
		
		// if no text is entered on exit, replace default text
		field.onblur = function() {
			if (this.value == "") {
				this.value = defaulttext;
			}
		}
	},

		
	/**
	 * functions to select or deselect all checkboxes
	 * @param parentcheckbox string the id of the parent check box that toggles the rest
	 * @param childboxcontainer string the id of the html container for all child checkboxes
	 */
	toggleCheckboxes : function (parentcheckbox, childboxcontainer) {
		
		// detect when the parent checkbox value is changed
		var parentCheckbox = document.getElementById(parentcheckbox);
		parentCheckbox.onclick = function() { 
			switchfields(this.checked);
		}

		//get child checkboxes 
		var container = document.getElementById(childboxcontainer);
		var childCheckboxes = container.getElementsByTagName('input');

		 // traverse and check 
		function switchfields(checkOnOff) { 
			 for (var i=0; i < childCheckboxes.length; i++) {
			 	childCheckboxes[i].checked = checkOnOff; 
			 }
		}
	}
} 
