﻿/**
 * toggle FAQ Items
 *
 * @param id 		the id of the FAQ item to hide or show
 * @param single	true to show only one item at a time, false the open as many as you want
 */
function toggleFaq(id, single, hash) {	
		
	if(single) {
		//show only one Q+A at a time
		toggleAll(false, hash);		
		showHideFaq(id, true, hash);
	}
	else {
		//open as many Q+A as you like		
		if(document.getElementById('irfaq_a_'+id+'_'+hash).style.display == 'none') {
			showHideFaq(id, true, hash);
		}
		else {
			showHideFaq(id, false, hash);
		}			
	}	
}

/**
 * shows or hides a FAQ item at a time depending on the given status
 *
 * @param id 		the id of the FAQ item to hide or show
 * @param status	true to show the item, false to hide it
 */
function showHideFaq(id, status, hash) {
	var faq_id = 'irfaq_a_'+id+'_'+hash; //answer
	var pm_id  = 'irfaq_pm_'+id+'_'+hash; // plus/minus icon
	
	if(status) {
		document.getElementById(faq_id).style.display = 'inline';
		document.getElementById(pm_id).src = tx_irfaq_pi1_iconMinus;
	}
	else {
		document.getElementById(faq_id).style.display = 'none';	
		document.getElementById(pm_id).src = tx_irfaq_pi1_iconPlus;
	}
}

/**
 * shows or hides all FAQ items with one click
 *
 * @param mode	true to show the items, false to hide them
 */
function toggleAll(mode, hash, count) {
	for(i = 0; i < count; i++) {
		showHideFaq(i+1, mode, hash);
	}	

			
}/* FORMULARÜBERPRÜFUNGEN */
    var need = new Array();
	need['vorbestellung'] = new Array(
		"Nachname",
		"Vorname",
		"Strasse",
		"PLZ",
		"Ort",
		"Telefon",
		"EMail",
		"Medikament1"
		);
	need['diabetes'] = new Array(
		"Nachname",
		"Vorname",
		"Strasse",
		"PLZ",
		"Ort",
		"Telefon",
		"EMail"
		);
	need['diabetes_risiko'] = new Array(
		"Nachname",
		"Vorname",
		"Strasse",
		"PLZ",
		"Ort",
		"Telefon",
		"EMail",
		"Gewicht",
		"Groesse",
		"Alter"
		);
	need['kontakt'] = new Array(
		"Nachname",
		"Vorname",
		"EMail",
		"Mitteilung"
		);
	need['kundenkarte'] = new Array(
		"Nachname",
		"Vorname",
		"Strasse",
		"PLZ",
		"Ort",
		"Telefon",
		"EMail",
		"Geburtsdatum",
		"Krankenkasse"
		);
	need['reiseimpfberatung'] = new Array(
		"Reiseziel",
		"Nachname",
		"Vorname",
		"Abreisedatum",
		"Rueckkehrdatum",
		"EMail",
		"Gewicht",
		"Alter"
		);
	need['satest'] = new Array(
		"alter",
		"geschlecht",
		"gewicht",
		"groesse",
		"schlaganfall",
		"herzrhytmus",
		"bluthochdruck",
		"diabetes",
		"raucher",
		"passivraucher",
		"blutfette",
		"aktiv"
		);

// -----------------------------------------------------------------------------------------------------
//       INTERNA - NICHT BEARBEITEN
// -----------------------------------------------------------------------------------------------------

// ------------------------------------------------------------
// Formularüberprüfung
String.prototype.trim = function() { return this.replace(/(^\s*)|(\s*$)/g, ""); }

function checkEMail(EMailValue)
{
    ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";

    for(i=0; i < EMailValue.length ;i++){
        if(ok.indexOf(EMailValue.charAt(i))<0) return (false);
    }

    if (document.images) {
        re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
        re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
        if (!EMailValue.match(re) && EMailValue.match(re_two)) return (-1);		
    }
}

function checkForm(formName,formTitle){
    var ac    = -1;
    var error = "";
    while(need[formTitle][++ac]){
        formField = need[formTitle][ac];
        formName.elements[formField].value = formName.elements[formField].value.trim();
        if (formField == "EMail") {
            if (! checkEMail(formName.elements[formField].value)) error += "\n - Bitte geben Sie eine korrekte E-Mail-Adresse ein.";
        } else {
            if (formName.elements[formField].value == '') error += "\n - " + formField;
        }
    }
    if(error){
        alert("Folgende Felder müssen ausgefüllt werden:\n"+error);
        return false;
    } else return true;
}

// ------------------------------------------------------------
