/*Newsletter Test Scripts*/
function correctTest(lang) {
	var answers = new Array(10);
	
	if(lang=="en") {
		answers[0]="Bürge";
		answers[1]="Kurs";
		answers[2]="Anlagen";
		answers[3]="gehen zu Lasten";
		answers[4]="ausgewertet";
		answers[5]="eine Ware loben und sie zum Kauf empfehlen";
		answers[6]="Geltendmachung";
		answers[7]="verstehen sich";
		answers[8]="unterbreiten";
		answers[9]="auflösen";
	}
	else {		
		answers[0]="partner";
		answers[1]="training";
		answers[2]="achieved";
		answers[3]="sound";
		answers[4]="the way to go";
		answers[5]="make-or-break";
		answers[6]="increase";
		answers[7]="bookkeeping";
		answers[8]="sheet";
		answers[9]="comply";
	}
	
	var currentQuestion = 0;
	var correctQuestions = 0;
	$(".sbHolder").each(function() {
			if($(this).children(".sbSelector:first").text()==answers[currentQuestion]) {
				correctQuestions++;
				$(this).css('background', 'url(/files/images/select-gradient-green.png) repeat-x 0 0');
			}else {
				$(this).css('background', 'url(/files/images/select-gradient-red.png) repeat-x 0 0');
			}
			$(this).find('.answer').each(function() {
				if($(this).text()==answers[currentQuestion]) {
						$(this).css('background-color', '#d2f2ce');
					}else {
						$(this).css('background-color', '#d7aca6');
				}
			});	 
		currentQuestion++;
	});
	var correct = (correctQuestions/answers.length)*100;
	var correctDisplayText;
	if(lang=="de") {
		correctDisplayText="Sie haben "+correct+"% richtig gelöst.";
	}
	else if(lang=="fr") {
		correctDisplayText="Vous avez répondu correctement<br /> à "+correct+"% des questions.";
	}
	else {
		correctDisplayText=correct+"% of your answers are correct.";
	}
	
	$("#lösungsanzeige").css("display",""); 
	$("#lösungsanzeige").html(correctDisplayText);


}

function showTestSolution(){
    document.getElementById('testsolution').style.display = '';
}

function hideTestSolution(){
    document.getElementById('testsolution').style.display = 'none';
}

function showVideo(id){
    if(id!=0) {
    document.getElementById('embeddedvideo'+id).style.display = '';
	}
	else {
	document.getElementById('embeddedvideo').style.display = '';
	}
}

function hideVideo(id){
    if(id!=2) { 
    stopVideo(id);
	}
	if(id!=0) {
    document.getElementById('embeddedvideo'+id).style.display = 'none'; 
	}
	else {
	document.getElementById('embeddedvideo').style.display = 'none'; 
	}
}

function onYouTubePlayerReady(id) {
embeddedvideo = document.getElementById("myytplayer");
}

function stopVideo(id) {
  if(id!=0) {
  var myPlayer = document.getElementById('myytplayer'+id);
  myPlayer.stopVideo();
  }
  else {
  var myPlayer = document.getElementById('myytplayer');
  myPlayer.stopVideo();
  }
}




/* Kursplaner scripts */

/* show steps */
function showPage(id){
    hideAll();
    $('div[id*="page'+id+'"]').css('display', '');
    $("#_currentPage").val(id);
    goToPage=id-1;
    

}
function hidePage(id){
    $("#page"+id).css('display', 'none');
}

function hideAll(){
    $('div[id*="page"]').css('display', 'none');
}

function resetLanguageSelection() {
    $(".en").css('display', 'none');
    $(".de").css('display', 'none');
    $(".fr").css('display', 'none');
    $(".it").css('display', 'none');
    $(".sp").css('display', 'none');
}


function groupCourseAvailabilityCousePlanner(isAvailable) {
	if(isAvailable==1) {

	    document.getElementById('slimboxgroupinactive').style.display = 'none';
	    document.getElementById('slimboxgroup').style.display = '';
	}
	else {
	    document.getElementById('slimboxgroupinactive').style.display = '';
	    document.getElementById('slimboxgroup').style.display = 'none';
	}
	
}

function groupCourseAvailabilityContactForm(isAvailable) {
     if($('#pfo2').val()=="DE") {
	output  = '<option value="">--- bitte wählen ---</option>';
	output += '<option value="Einzelunterricht">Einzelunterricht</option>';
	output += '<option value="Intensivunterricht">Intensivkurs</option>';
	if(isAvailable==1) {
	   output += '<option value="Gruppenunterricht">Gruppenunterricht</option>';
	}
     }
     else if($('#pfo2').val()=="FR") {
	output  = '<option value="">--- veuillez choisir ---</option>';
	output += '<option value="Einzelunterricht">Cours individuels</option>';
	output += '<option value="Intensivunterricht">Cours intensifs</option>';
	if(isAvailable==1) {
	   output += '<option value="Gruppenunterricht">Cours collectifs</option>';
	}
     }
     else if($('#pfo2').val()=="EN") {
	output  = '<option value="">--- please select ---</option>';
	output += '<option value="Einzelunterricht">Individual courses</option>';
	output += '<option value="Intensivunterricht">Crash courses</option>';
	if(isAvailable==1) {
	   output += '<option value="Gruppenunterricht">Group courses</option>';
	}
     }
     
     
     $('#pfo4').html(output);
     
}


function checkIfGroupCourseExists(city, source) {
         
	if(source=="courseplanner") {
	    if(document.firstsecondthirdstep.courselanguage[6].checked==true) {
	   
	        $.get("/localinc/bx/php/groupcourseavailability.php", { city: city, lang: document.forms['firstsecondthirdstep'].courselanguage[6].value }, function(exists){

		    if(exists==1) {
			groupCourseAvailabilityCousePlanner(1);
			    
		    }
		    else {
			groupCourseAvailabilityCousePlanner(0);    
		    }
		});
	    }
	    else {
		groupCourseAvailabilityCousePlanner(1);
	    }
	}
	else if(source=="contactform") {
	    var lang = $('#pfo3').val();
	    if(lang!="Generalenglish" && lang!="Businessenglish" && lang!="Deutsch" && lang!="Franzoesisch" && lang!="Italienisch" && lang!="Spanisch") {
		 $.get("/localinc/bx/php/groupcourseavailability.php", { city: city, lang: lang }, function(exists){

		    if(exists==1) {
			groupCourseAvailabilityContactForm(1);
			    
		    }
		    else {
			groupCourseAvailabilityContactForm(0);    
		    }
		});
	    }
	    else {
		groupCourseAvailabilityContactForm(1);
	    }
	    
	    
	}
}

/* empfehlung or anfrage */
function checkKursplanerForm() {
    if (document.firstsecondthirdstep.unterrichtsform[1].checked == true || document.firstsecondthirdstep.unterrichtsform[2].checked == true) {
        document.firstsecondthirdstep.action = "../anfrage/";
    }
}

function showSingle(){
    hideSingleIntensiv();
    document.getElementById('einzelunterrichtwarnung').style.display = '';
}

function showIntensiv(){
    hideSingleIntensiv();
    document.getElementById('intensivunterrichtwarnung').style.display = '';
}
function hideSingleIntensiv(){
    document.getElementById('einzelunterrichtwarnung').style.display = 'none';
    document.getElementById('intensivunterrichtwarnung').style.display = 'none';
}

function showDiplomaLevel() {
	if (document.firstsecondthirdstep.courselanguage[0].checked ==true) lang='en';
	else if (document.firstsecondthirdstep.courselanguage[1].checked ==true) lang ='de';
	else if (document.firstsecondthirdstep.courselanguage[2].checked ==true) lang ='fr';
	else if (document.firstsecondthirdstep.courselanguage[3].checked ==true) lang ='it';
	else if (document.firstsecondthirdstep.courselanguage[4].checked ==true) lang ='sp';
	$("."+lang).css('display', 'block');
}
function showDiplomaLevelfromAngebot() {
	if (document.firstsecondthirdstep.courselanguage.value =='EN') lang='en';
	else if (document.firstsecondthirdstep.courselanguage.value =='DE') lang ='de';
	else if (document.firstsecondthirdstep.courselanguage.value =='FR') lang ='fr';
	else if (document.firstsecondthirdstep.courselanguage.value =='IT') lang ='it';
	else if (document.firstsecondthirdstep.courselanguage.value =='SP') lang ='sp';
	$("."+lang).css('display', 'block');
}
function submitSprachtest(f,helperMsg){
    if(document.onlinetest.FName.value.length == 0 || document.onlinetest.LName.value.length == 0 || !checkMail(document.onlinetest.EMail.value) && (!document.onlinetest.Title[0].checked || !document.onlinetest.Title[1].checked)){
        alert(helperMsg);
        return false;
    }
    else {
        f.target = 'Sprachtest';
        url  = 'http://www.i-e-learn.com/ch/inlingua-ch/index.asp?';
        url += 'loc='+document.onlinetest.loc.value+'&';
        url += 'lan='+document.onlinetest.lan.value+'&';
        url += 'rbTest='+document.onlinetest.rbTest.value+'&';
        url += 'language_id='+document.onlinetest.language_id.value+'&';
        url += 'as='+document.onlinetest.as.value+'&';
        url += 'course_type='+encodeURIComponent(document.onlinetest.course_type.value)+'&';
        
        w = document.onlinetest.Estimation.selectedIndex;
        estimation = document.onlinetest.Estimation.options[w].value;
        url += 'Estimation='+estimation+'&';
        
        if(document.onlinetest.Title[0].checked) {
            anrede = 'Frau';
        } else {
            anrede = 'Herr';
        }        
        url += 'Title='+anrede+'&';
        url += 'FName='+escape(document.onlinetest.FName.value)+'&';
        url += 'LName='+escape(document.onlinetest.LName.value)+'&';
        url += 'EMail='+encodeURIComponent(document.onlinetest.EMail.value)+'&';
        url += 'Adresse='+escape(document.onlinetest.Adresse.value)+'&';
        url += 'PLZ='+escape(document.onlinetest.PLZ.value)+'&';
        url += 'Tel='+escape(document.onlinetest.Tel.value)+'&';
        url += 'Company='+escape(document.onlinetest.Company.value)+'&';
        window.open(url,f.target,'menubar=0,scrollbars=1,width=650,height=680,resizeable=1');
        
        //f.submit();
        return false;
    }
}
function checkMail(email){
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(email)) {
		return true;
	}
	return false;
}
function getDiplomaOfLanguage() {        
    if ($('#pfo2').val()=='Englisch') {
        output  = '<option value="">--</option>';
        output += '<option value="Preliminary English Test">Preliminary English Test</option>';
        output += '<option value="BEC Preliminary Business English Certificate">BEC Preliminary Business English Certificate</option>';
        output += '<option value="First Certificate in English">First Certificate in English</option>';
        output += '<option value="BEC Vantage Business English Certificate">BEC Vantage Business English Certificate</option>';
        output += '<option value="Certificate in Advanced English">Certificate in Advanced English</option>';
        output += '<option value="BEC Higher Business English Certificate">BEC Higher Business English Certificate</option>';
        output += '<option value="ILEC International Legal English Certificate">ILEC International Legal English Certificate</option>';
        output += '<option value="ICFE International Certificate in Financial English">ICFE International Certificate in Financial English</option>';
        output += '<option value="Certificate of Proficiency in English">Certificate of Proficiency in English</option>';
       
    }
    else if ($('#pfo2').val()=='Deutsch') {
        output  = '<option value="">--</option>';
        output += '<option value="Zertifikat Deutsch">Zertifikat Deutsch</option>';
        output += '<option value="Goethe-Zertifikat B2">Goethe-Zertifikat B2</option>';
        output += '<option value="Goethe-Zertifikat C1 (ZMP)">Goethe-Zertifikat C1 (ZMP)</option>';
        output += '<option value="Zentrale Oberstufenprüfung">Zentrale Oberstufenprüfung</option>';
    }
    else if ($('#pfo2').val()=='Franzoesisch') {
        output  = '<option value="">--</option>';
        output += '<option value="DELF A2">DELF A2</option>';
        output += '<option value="CEFP1">CEFP1</option>';
        output += '<option value="DELF B1">DELF B1</option>';
        output += '<option value="CEFP2">CEFP2</option>';
        output += '<option value="DELF B2">DELF B2</option>';
        output += '<option value="CEFP2">Diplôme de langue</option>';
        output += '<option value="DALF C1">DALF C1</option>';
        output += '<option value="Diplôme supérieur">Diplôme supérieur</option>';
        output += '<option value="DALF C2">DALF C2</option>';

    }
    else if ($('#pfo2').val()=='Italienisch') {
        output  = '<option value="">--</option>';
        output += '<option value="CELI 2">CELI 2</option>';
        output += '<option value="CELI 3">CELI 3</option>';
        output += '<option value="CELI 4">CELI 4</option>';
        output += '<option value="CELI 5">CELI 5</option>';


    }
    else if ($('#pfo2').val()=='Spanisch') {
        output  = '<option value="">--</option>';
        output += '<option value="Diploma de Español B1">Diploma de Español B1</option>';
        output += '<option value="Diploma de Español B2">Diploma de Español B2</option>';
        output += '<option value="Diploma de Español C2">Diploma de Español C2</option>';
    }
    else {
        output  = '<option value="">--</option>';
    }
    /* Return String */
    $('#pfo4').html(output);
}
