// Courses lists connected to cities
var courses = new Array();

courses['empty'] = new Array(
'--- Courses ---'
);

courses['Madrid'] = new Array(
'Intensive Spanish',
'Intensive Spanish Plus',
'Super Intensive Spanish',
'Business Spanish Courses',
'One to One Spanish Lessons',
'Long Term Spanish',
'Part Time Spanish',
'B1 DELE Exam Preparation',
'B2 DELE Exam Preparation',
'C2 DELE Exam Preparation',
'Spanish for Teachers',
'One to One Spanish for Teachers',
'Spanish Conversation Classes',
'Spanish and Internship',
'Business Spanish and Internship',
'Just the Internship',
'Spanish Minigroup',
'Spanish Minigroup with 1hr Private Lessons',
'Spanish Minigroup with 2hr Private Lessons',
'Spanish Minigroup with 3hr Private Lessons',
'Jobs in Spain',
'Study in Spanish',
'Spanish with Flamenco Lessons',
'Christmas in Spain',
'Chamber of Commerce Exam Preparation'
);

courses['Barcelona'] = new Array(
'Intensive Spanish',
'Intensive Spanish Plus',
'Super Intensive Spanish',
'Business Spanish Courses',
'One to One Spanish Lessons',
'Long Term Spanish',
'Part Time Spanish',
'B1 DELE Exam Preparation',
'B2 DELE Exam Preparation',
'C2 DELE Exam Preparation',
'Spanish for Teachers',
'One to One Spanish for Teachers',
'Spanish Conversation Classes',
'Spanish and Internship',
'Business Spanish and Internship',
'Spanish Minigroup',
'Spanish Minigroup with 1hr Private Lessons',
'Spanish Minigroup with 2hr Private Lessons',
'Spanish Minigroup with 3hr Private Lessons',
'Jobs in Spain',
'Studying in Spanish',
'Christmas in Spain',
'Chamber of Commerce Exam Preparation'
);

courses['Valencia'] = new Array(
'Intensive Spanish',
'Intensive Spanish Plus',
'Super Intensive Spanish',
'Business Spanish Courses',
'One to One Spanish Lessons',
'Long Term Spanish',
'Part Time Spanish',
'B1 DELE Exam Preparation',
'B2 DELE Exam Preparation',
'C2 DELE Exam Preparation',
'Spanish for Teachers',
'One to One Spanish for Teachers',
'Spanish Conversation Classes',
'Spanish and Internship',
'Business Spanish and Internship',
'Just the Internship',
'Jobs in Spain',
'Christmas in Spain'
);

courses['Salamanca'] = new Array(
'Intensive Spanish',
'Intensive Spanish Plus',
'Super Intensive Spanish',
'Business Spanish Courses',
'One to One Spanish Lessons',
'Part Time Spanish',
'B1 DELE Exam Preparation',
'B2 DELE Exam Preparation',
'C2 DELE Exam Preparation',
'Spanish for Teachers',
'One to One Spanish for Teachers',
'Spanish Conversation Classes',
'Spanish and Internship',
'Business Spanish and Internship',
'Spanish Minigroup',
'Spanish Minigroup with 1hr Private Lessons',
'Spanish Minigroup with 2hr Private Lessons',
'Spanish Minigroup with 3hr Private Lessons',
'Just the Internship',
'Jobs in Spain',
'Studying in Spanish',
'Christmas in Spain',
'Chamber of Commerce Exam Preparation'
);

courses['Granada'] = new Array(
'Intensive Spanish',
'Intensive Spanish Plus',
'Super Intensive Spanish',
'One to One Spanish Lessons',
'Part Time Spanish',
'Tourism Spanish',
'B1 DELE Exam Preparation',
'B2 DELE Exam Preparation',
'C2 DELE Exam Preparation',
'Spanish and Internship',
'Studying in Spanish',
'Spanish with Flamenco Lessons',
'Christmas in Spain'
);

courses['Marbella'] = new Array(
'Intensive Spanish',
'Intensive Spanish Plus',
'Super Intensive Spanish',
'One to One Spanish Lessons',
'Spanish with Flamenco Lessons',
'Golf in Spanish',
'Tennis in Spanish',
'Spanish for Students Over 50'
);

courses['Seville'] = new Array(
'Intensive Spanish',
'Intensive Spanish Plus',
'Super Intensive Spanish',
'One to One Spanish Lessons',
'Spanish for Teachers',
'B1 DELE Exam Preparation',
'B2 DELE Exam Preparation',
'C2 DELE Exam Preparation',	
'Spanish and Internship',
'Christmas in Spain',
'Spanish with Flamenco Lessons'
);

// Centers lists connected to courses and city
var centers = new Array();

centers['empty'] = new Array();
centers['empty']['--- Courses ---'] = new Array('--- Study Center ---');

centers['Madrid'] = new Array();
centers['Madrid']['Intensive Spanish'] = new Array('Arguelles','Ventura Rodriguez');
centers['Madrid']['Intensive Spanish Plus'] = new Array('Arguelles');
centers['Madrid']['Super Intensive Spanish'] = new Array('Arguelles','Ventura Rodriguez');
centers['Madrid']['Business Spanish Courses'] = new Array('Arguelles','Ventura Rodriguez');
centers['Madrid']['One to One Spanish Lessons'] = new Array('Arguelles','Ventura Rodriguez');
centers['Madrid']['B1 DELE Exam Preparation'] = new Array('Arguelles','Ventura Rodriguez');
centers['Madrid']['B2 DELE Exam Preparation'] = new Array('Arguelles','Ventura Rodriguez');
centers['Madrid']['C2 DELE Exam Preparation'] = new Array('Arguelles','Ventura Rodriguez');
centers['Madrid']['Spanish for Teachers'] = new Array('Arguelles','Ventura Rodriguez');
centers['Madrid']['One to One Spanish for Teachers'] = new Array('Ventura Rodriguez');
centers['Madrid']['Long Term Spanish'] = new Array('Arguelles');
centers['Madrid']['Part Time Spanish'] = new Array('Arguelles');
centers['Madrid']['Spanish Conversation Classes'] = new Array('Ventura Rodriguez');
centers['Madrid']['Spanish and Internship'] = new Array('Arguelles','Ventura Rodriguez');
centers['Madrid']['Business Spanish and Internship'] = new Array('Arguelles','Ventura Rodriguez');
centers['Madrid']['Just the Internship'] = new Array('Arguelles');
centers['Madrid']['Spanish Minigroup'] = new Array('Ventura Rodriguez');
centers['Madrid']['Spanish Minigroup with 1hr Private Lessons'] = new Array('Ventura Rodriguez');
centers['Madrid']['Spanish Minigroup with 2hr Private Lessons'] = new Array('Ventura Rodriguez');
centers['Madrid']['Spanish Minigroup with 3hr Private Lessons'] = new Array('Ventura Rodriguez');
centers['Madrid']['Jobs in Spain'] = new Array('Ventura Rodriguez');
centers['Madrid']['Study in Spanish'] = new Array('Arguelles');
centers['Madrid']['Spanish with Flamenco Lessons'] = new Array('Arguelles');
centers['Madrid']['Christmas in Spain'] = new Array('Arguelles');
centers['Madrid']['Chamber of Commerce Exam Preparation'] = new Array('Ventura Rodriguez');

centers['Barcelona'] = new Array();
centers['Barcelona']['Intensive Spanish'] = new Array('Rocafort Spanish School','Spanish Institute');
centers['Barcelona']['Intensive Spanish Plus'] = new Array('Rocafort Spanish School');
centers['Barcelona']['Super Intensive Spanish'] = new Array('Rocafort Spanish School','Spanish Institute');
centers['Barcelona']['Business Spanish Courses'] = new Array('Rocafort Spanish School','Spanish Institute');
centers['Barcelona']['One to One Spanish Lessons'] = new Array('Rocafort Spanish School','Spanish Institute');
centers['Barcelona']['Long Term Spanish'] = new Array('Rocafort Spanish School');
centers['Barcelona']['Part Time Spanish'] = new Array('Rocafort Spanish School');
centers['Barcelona']['B1 DELE Exam Preparation'] = new Array('Rocafort Spanish School','Spanish Institute');
centers['Barcelona']['B2 DELE Exam Preparation'] = new Array('Rocafort Spanish School','Spanish Institute');
centers['Barcelona']['C2 DELE Exam Preparation'] = new Array('Rocafort Spanish School','Spanish Institute');
centers['Barcelona']['Spanish for Teachers'] = new Array('Rocafort Spanish School','Spanish Institute');
centers['Barcelona']['One to One Spanish for Teachers'] = new Array('Spanish Institute');
centers['Barcelona']['Spanish Conversation Classes'] = new Array('Spanish Institute');
centers['Barcelona']['Spanish and Internship'] = new Array('Rocafort Spanish School','Spanish Institute');
centers['Barcelona']['Business Spanish and Internship'] = new Array('Rocafort Spanish School','Spanish Institute');
centers['Barcelona']['Spanish Minigroup'] = new Array('Spanish Institute');
centers['Barcelona']['Spanish Minigroup with 1hr Private Lessons'] = new Array('Spanish Institute');
centers['Barcelona']['Spanish Minigroup with 2hr Private Lessons'] = new Array('Spanish Institute');
centers['Barcelona']['Spanish Minigroup with 3hr Private Lessons'] = new Array('Spanish Institute');
centers['Barcelona']['Jobs in Spain'] = new Array('Spanish Institute');
centers['Barcelona']['Studying in Spanish'] = new Array('Rocafort Spanish School');
centers['Barcelona']['Christmas in Spain'] = new Array('Rocafort Spanish School');
centers['Barcelona']['Chamber of Commerce Exam Preparation'] = new Array('Spanish Institute');

centers['Valencia'] = new Array();
centers['Valencia']['Intensive Spanish'] = new Array('Immersion School','Language Academy');
centers['Valencia']['Intensive Spanish Plus'] = new Array('Immersion School');
centers['Valencia']['Super Intensive Spanish'] = new Array('Immersion School','Language Academy');
centers['Valencia']['Business Spanish Courses'] = new Array('Immersion School');
centers['Valencia']['One to One Spanish Lessons'] = new Array('Immersion School','Language Academy');
centers['Valencia']['B1 DELE Exam Preparation'] = new Array('Immersion School','Language Academy');
centers['Valencia']['B2 DELE Exam Preparation'] = new Array('Immersion School','Language Academy');
centers['Valencia']['C2 DELE Exam Preparation'] = new Array('Immersion School','Language Academy');
centers['Valencia']['Spanish for Teachers'] = new Array('Immersion School');
centers['Valencia']['One to One Spanish for Teachers'] = new Array('Language Academy');
centers['Valencia']['Long Term Spanish'] = new Array('Immersion School');
centers['Valencia']['Part Time Spanish'] = new Array('Immersion School');
centers['Valencia']['Spanish Conversation Classes'] = new Array('Language Academy');
centers['Valencia']['Spanish and Internship'] = new Array('Immersion School','Language Academy');
centers['Valencia']['Business Spanish and Internship'] = new Array('Immersion School');
centers['Valencia']['Just the Internship'] = new Array('Immersion School');
centers['Valencia']['Jobs in Spain'] = new Array('Language Academy');
centers['Valencia']['Christmas in Spain'] = new Array('Immersion School');

centers['Salamanca'] = new Array();
centers['Salamanca']['Intensive Spanish'] = new Array('Salamanca School','Spanish Academy');
centers['Salamanca']['Intensive Spanish Plus'] = new Array('Salamanca School');
centers['Salamanca']['Super Intensive Spanish'] = new Array('Salamanca School','Spanish Academy');
centers['Salamanca']['Business Spanish Courses'] = new Array('Salamanca School','Spanish Academy');
centers['Salamanca']['One to One Spanish Lessons'] = new Array('Salamanca School','Spanish Academy');
centers['Salamanca']['B1 DELE Exam Preparation'] = new Array('Salamanca School','Spanish Academy');
centers['Salamanca']['B2 DELE Exam Preparation'] = new Array('Salamanca School','Spanish Academy');
centers['Salamanca']['C2 DELE Exam Preparation'] = new Array('Salamanca School','Spanish Academy');
centers['Salamanca']['Spanish for Teachers'] = new Array('Spanish Academy');
centers['Salamanca']['One to One Spanish for Teachers'] = new Array('Salamanca School','Spanish Academy');
centers['Salamanca']['Part Time Spanish'] = new Array('Salamanca School');
centers['Salamanca']['Spanish Conversation Classes'] = new Array('Spanish Academy');
centers['Salamanca']['Spanish and Internship'] = new Array('Salamanca School','Spanish Academy');
centers['Salamanca']['Business Spanish and Internship'] = new Array('Salamanca School','Spanish Academy');
centers['Salamanca']['Spanish Minigroup'] = new Array('Spanish Academy');
centers['Salamanca']['Spanish Minigroup with 1hr Private Lessons'] = new Array('Spanish Academy');
centers['Salamanca']['Spanish Minigroup with 2hr Private Lessons'] = new Array('Spanish Academy');
centers['Salamanca']['Spanish Minigroup with 3hr Private Lessons'] = new Array('Spanish Academy');
centers['Salamanca']['Just the Internship'] = new Array('Salamanca School');
centers['Salamanca']['Jobs in Spain'] = new Array('Spanish Academy');
centers['Salamanca']['Studying in Spanish'] = new Array('Salamanca School');
centers['Salamanca']['Christmas in Spain'] = new Array('Salamanca School');
centers['Salamanca']['Chamber of Commerce Exam Preparation'] = new Array('Spanish Academy');

centers['Granada'] = new Array();
centers['Granada']['Intensive Spanish'] = new Array('Granada Spanish School');
centers['Granada']['Intensive Spanish Plus'] = new Array('Granada Spanish School');
centers['Granada']['Super Intensive Spanish'] = new Array('Granada Spanish School');
centers['Granada']['One to One Spanish Lessons'] = new Array('Granada Spanish School');
centers['Granada']['Tourism Spanish'] = new Array('Granada Spanish School');
centers['Granada']['B1 DELE Exam Preparation'] = new Array('Granada Spanish School');
centers['Granada']['B2 DELE Exam Preparation'] = new Array('Granada Spanish School');
centers['Granada']['C2 DELE Exam Preparation'] = new Array('Granada Spanish School');
centers['Granada']['Part Time Spanish'] = new Array('Granada Spanish School');
centers['Granada']['Spanish and Internship'] = new Array('Granada Spanish School');
centers['Granada']['Studying in Spanish'] = new Array('Granada Spanish School');
centers['Granada']['Christmas in Spain'] = new Array('Granada Spanish School');
centers['Granada']['Spanish with Flamenco Lessons'] = new Array('Granada Spanish School');

centers['Marbella'] = new Array();
centers['Marbella']['Intensive Spanish'] = new Array('Marbella Spanish');
centers['Marbella']['Intensive Spanish Plus'] = new Array('Marbella Spanish');
centers['Marbella']['Super Intensive Spanish'] = new Array('Marbella Spanish');
centers['Marbella']['One to One Spanish Lessons'] = new Array('Marbella Spanish');
centers['Marbella']['Spanish with Flamenco Lessons'] = new Array('Marbella Spanish');
centers['Marbella']['Golf in Spanish'] = new Array('Marbella Spanish');
centers['Marbella']['Tennis in Spanish'] = new Array('Marbella Spanish');
centers['Marbella']['Spanish for Students Over 50'] = new Array('Marbella Spanish');

centers['Seville'] = new Array();
centers['Seville']['Intensive Spanish'] = new Array('Seville Spanish School');
centers['Seville']['Intensive Spanish Plus'] = new Array('Seville Spanish School');
centers['Seville']['Super Intensive Spanish'] = new Array('Seville Spanish School');
centers['Seville']['One to One Spanish Lessons'] = new Array('Seville Spanish School');
centers['Seville']['Spanish for Teachers'] = new Array('Seville Spanish School');
centers['Seville']['B1 DELE Exam Preparation'] = new Array('Seville Spanish School');
centers['Seville']['B2 DELE Exam Preparation'] = new Array('Seville Spanish School');
centers['Seville']['C2 DELE Exam Preparation'] = new Array('Seville Spanish School');
centers['Seville']['Spanish and Internship'] = new Array('Seville Spanish School');
centers['Seville']['Christmas in Spain'] = new Array('Seville Spanish School');
centers['Seville']['Spanish with Flamenco Lessons'] = new Array('Seville Spanish School');

/*##############################################
 * Travel packages
 #############################################*/

var cityTravel = new Array();
var duration = new Array();
var price = new Array();

cityTravel['empty']	= new Array('--- Itinerary ---');
duration['empty'] 	= new Array('--- Course Duration ---');
price['empty'] 		= new Array('--- Course Price ---');

cityTravel['p01'] 	= new Array('Valencia-Salamanca'); // TEXT - route
duration['p01'] 	= new Array('4'); // ONLY NUMBER - weeks
price['p01'] 		= new Array('645'); // ONLY NUMBER - price 

cityTravel['p02'] 	= new Array('Marbella-Valencia-Barcelona');
duration['p02'] 	= new Array('6');
price['p02'] 		= new Array('905');

cityTravel['p03'] 	= new Array('Madrid-Barcelona');
duration['p03'] 	= new Array('8');
price['p03'] 		= new Array('1265');

cityTravel['p04'] 	= new Array('Madrid-Barcelona-Valencia');
duration['p04'] 	= new Array('9');
price['p04'] 		= new Array('1315');



/* #############################################
 * WARNING!!! DO NOT TOUCH THE CODE BELOW
 * and be carefull editing  the code above
 ############################################### */

var lnk1=document.createElement('div');

function setLinks(){
var cnt = document.goForm.center.value
var cty = document.goForm.city.value

if (cnt == 'Arguelles') {
		lnk1.innerHTML = '<a href="/spanish-language-school-madrid/" target="_blank">Read more about Arguelles center</a>';
		$('.link').append(lnk1);
		$('form.prebooking').attr('action','/spanish-language-school-madrid/enrolment.html');
	}
	else 
		if (cnt == 'Ventura Rodriguez') {
			lnk1.innerHTML = '<a href="/spanish-language-centre-madrid/" target="_blank">Read more about Ventura Rodriguez</a>';
			$('.link').append(lnk1);
			$('form.prebooking').attr('action','/spanish-language-centre-madrid/enrolment.html');

		}
	else 
		if (cnt == 'Spanish Institute') {
			lnk1.innerHTML = '<a href="/spanish-institute-barcelona/" target="_blank">Read more about Spanish Institute</a>';
			$('.link').append(lnk1);
			$('form.prebooking').attr('action','/spanish-institute-barcelona/enrolment.html');			
		}
	else 
		if (cnt == 'Rocafort Spanish School') {
			lnk1.innerHTML = '<a href="/barcelona-spanish-school/" target="_blank">Read more about Rocafort Spanish School</a>';
			$('.link').append(lnk1);
			$('form.prebooking').attr('action','/barcelona-spanish-school/enrolment.html');			
		}
	else 
		if (cnt == 'Immersion School') {
			lnk1.innerHTML = '<a href="/spanish-immersion-school/" target="_blank">Read more about Immersion School</a>';
			$('.link').append(lnk1);
			$('form.prebooking').attr('action','/spanish-immersion-school/enrolment.html');			
		}		
	else
		if (cnt == 'Language Academy') {
			lnk1.innerHTML = '<a href="/spanish-language-academy/" target="_blank">Read more about Language Academy</a>';
			$('.link').append(lnk1);
			$('form.prebooking').attr('action','/spanish-language-academy/enrolment.html');			
		}
	else 
		if (cnt == 'Salamanca School') {
			lnk1.innerHTML = '<a href="/salamanca-language-school/" target="_blank">Read more about Salamanca School</a>';
			$('.link').append(lnk1);
			$('form.prebooking').attr('action','/salamanca-language-school/enrolment.html');			
		}
	else
		if (cnt == 'Spanish Academy') {
			lnk1.innerHTML = '<a href="/spanish-academy/" target="_blank">Read more about Spanish Academy</a>';
			$('.link').append(lnk1);
			$('form.prebooking').attr('action','/spanish-academy/enrolment.html');			
		}
	else 
		if (cnt == 'Granada Spanish School') {
			lnk1.innerHTML = '<a href="/granada-spanish-school/" target="_blank">Read more about Granada Spanish School</a>';
			$('.link').append(lnk1);
			$('form.prebooking').attr('action','/granada-spanish-school/enrolment.html');			
		}
	else 
		if (cnt == 'Marbella Spanish') {
			lnk1.innerHTML = '<a href="/marbella-spanish/" target="_blank">Read more about Marbella Spanish School</a>';
			$('.link').append(lnk1);
			$('form.prebooking').attr('action','/marbella-spanish/enrolment.html');			
		}
	else 
		if (cnt == 'Seville Spanish School') {
			lnk1.innerHTML = '<a href="/seville-spanish-school/" target="_blank">Read more about Seville Spanish School</a>';
			$('.link').append(lnk1);
			$('form.prebooking').attr('action','/seville-spanish-school/enrolment.html');			
		}
			
if (cty == 'empty'){
	$('.link').hide();
	} else {
	$('.link').show();			
	}

}

function setСourses() {
  citySel = document.getElementById('city');
  courseList = courses[citySel.value];
  changeSelect('course', courseList, courseList);
  setCenters();
}

function setCenters() {
  citySel = document.getElementById('city');
  courseSel = document.getElementById('course');
  centerList = centers[citySel.value][courseSel.value];
  changeSelect('center', centerList, centerList);
  setLinks();
}

/*
 * Travel functions
 */

function setCity(){
	a = document.getElementById('packages');
	
	weeksInsurance = document.getElementById('weeks_insurance'); // trick to fill the insurance week which is hidden
	
	b = cityTravel[a.value];
	d = duration[a.value];
	dTextNode = ' weeks';	
	p = price[a.value];
	pTextNode = ' euros'	
	
	changeSelect('citytravel', b, b);
	changeSelect('duration', d, d, dTextNode);
	changeSelect('price', p, p, pTextNode);
	travelAction();
		
	//weeksInsurance.value = d; // trick to fill the insurance week which is hidden // moved to config for detect if selected.
}


// TRAVEL ACTION PARA MINI FORM 
function travelAction(){
	var pkg = a.value
	
	if (pkg == 'p01') {
		$('form.travelPrebooking').attr('action', '/study-spanish-travel/low-cost/index.html');
	}
	else 
	
	if (pkg == 'p02') {
		$('form.travelPrebooking').attr('action', '/study-spanish-travel/beach-hopping/index.html');
	}
	else 
	
	if (pkg == 'p03') {
		$('form.travelPrebooking').attr('action', '/study-spanish-travel/city-slicker/index.html');
	}
	
	if (pkg == 'p04') {
		$('form.travelPrebooking').attr('action', '/study-spanish-travel/capital-tour/index.html');
	}

}

/*
 * Generic Functions for both versions
 */

// extraTextNode is extra variable to define extra text for the array option. For example value="4">4 weeks... etc.
function changeSelect(fieldID, newOptions, newValues, extraTextNode){

	if (extraTextNode == null) {
		extraTextNode = '';
	}
	
	selectField = document.getElementById(fieldID);
	selectField.options.length = 0;
	for (i = 0; i < newOptions.length; i++) {
		selectField.options[selectField.length] = new Option(newOptions[i] + extraTextNode, newValues[i]);
	}
}

// Multiple onload function
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

/*addLoadEvent(function() {
 setСourses();
});*/
