/**
 * Java Script Funktionen
 *
 * Copyright 2004 by DACHCOM digital AG.
 * All rights reserved.
 *
 * Author: Walter Canal, wcanal@dachcomdigital.com
 * Version 1.0, 29.01.2004
 *
 * History:
 *  1.0 29.01.2004	wcanal	initial relase
 *  2.0 27.02.2009	snowak	erweiterung Kontaktform, email check, reset values
 *
 */

var contactform = new Array();

//Deutscher Teil
contactform["de"] = new Object();
contactform["de"]["requiredFields"] = "Bitte Felder mit * ausf%FCllen!";				//alert(contactform["de"]["requiredFields"]);
contactform["de"]["EMail"] 			= "Bitte eine korrekte E-Mail-Adresse eingeben!";	//alert(contactform["de"]["EMail"]);

contactform["de"]["anrede"] = "Anrede";
contactform["de"]["firma"] = "Firma *";
contactform["de"]["vorname"] = "Vorname *";
contactform["de"]["name"]= "Name *";
contactform["de"]["strasse"]= "Strasse *";
contactform["de"]["plz_ort"]= "PLZ/Ort *";
contactform["de"]["fax"]= "Fax";
contactform["de"]["telefon"]= "Telefon *";
contactform["de"]["e_mail"]= "E-Mail *";
contactform["de"]["land"]= "Land";

/* Anzeige 
var anzeige = '';
for (element in contactform) {
	anzeige += ' ' + element + '\n';
	for (key in contactform[element]) {
		anzeige += ' ' + key + ' = ' + contactform[element][key] + '\n';
	}
}
alert(anzeige);
*/
// File-Download
function openFile(id) {
	document.location.href = '/admin/include/downloadFile.php?action=d&id='+id;
}

function checkForm(kontaktformular) {
	
	var send = true;
	var mail = true;
	
	if (kontaktformular.firma.value == '' || kontaktformular.firma.value == 'Firma *') {
		document.getElementById("firma").className = 'error';
		send = false;
	} else {
		document.getElementById("firma").className = '';
	}
	
	if (kontaktformular.vorname.value == '' || kontaktformular.vorname.value == 'Vorname *') {
		document.getElementById("vorname").className = 'error';
		send = false;
	} else {
		document.getElementById("vorname").className = '';
	}
	
	if (kontaktformular.name.value == '' || kontaktformular.name.value == 'Name *') {
		document.getElementById("name").className = 'error';
		send = false;
	} else {
		document.getElementById("name").className = '';
	}
	
	if (kontaktformular.strasse.value == '' || kontaktformular.strasse.value == 'Strasse *') {
		document.getElementById("strasse").className = 'error';
		send = false;
	} else {
		document.getElementById("strasse").className = '';
	}
	
	if (kontaktformular.plz_ort.value == '' || kontaktformular.plz_ort.value == 'PLZ/Ort *') {
		document.getElementById("plz_ort").className = 'error';
		send = false;
	} else {
		document.getElementById("plz_ort").className = '';
	}
	
	if (kontaktformular.telefon.value == '' || kontaktformular.telefon.value == 'Telefon *') {
		document.getElementById("telefon").className = 'error';
		send = false;
	} else {
		document.getElementById("telefon").className = '';
	}
	
	if(kontaktformular.e_mail.value != '' && !eMail(kontaktformular.e_mail.value)){
        document.getElementById("e_mail").className = 'error';
		mail = false;
    } else {
		document.getElementById("e_mail").className = '';
	}
	
	if(send == false){
		alert(unescape(contactform["de"]["requiredFields"]));
		return false;
	} else if(mail == false){
		alert(contactform["de"]["EMail"]);
		return false;
	}

    return true;
}

function eMail(email){
    var a = false;
    var result = false;
    if(typeof(RegExp) == 'function'){
        var b = new RegExp('abc');
        if(b.test('abc') == true){a = true;}
    }    
    if(a == true){
        reg = new RegExp('^([a-zA-Z0-9\\-\\.\\_]+)'+
                         '(\\@)([a-zA-Z0-9\\-\\.]+)'+
                         '(\\.)([a-zA-Z]{2,4})$');
        result = (reg.test(email));
    }else{
        result = (email.search('@') >= 1 &&
                  email.lastIndexOf('.') > email.search('@') &&
                  email.lastIndexOf('.') >= email.length-5)
    }
    return(result);
}

function checkValue (element, def) {
	if (element.value=='') {
		element.value = def;
	}
}

function setValue (element, def) {
	if (element.value==def) {
		element.value = '';
	}
}


function resetValues () {
	
	document.getElementById("anrede").value  = contactform["de"]["anrede"];
	document.getElementById("firma").value   = contactform["de"]["firma"];
	document.getElementById("vorname").value = contactform["de"]["vorname"];
	document.getElementById("name").value    = contactform["de"]["name"];
	document.getElementById("strasse").value = contactform["de"]["strasse"];
	document.getElementById("plz_ort").value = contactform["de"]["plz_ort"];
	document.getElementById("fax").value     = contactform["de"]["fax"];
	document.getElementById("telefon").value = contactform["de"]["telefon"];
	document.getElementById("e_mail").value  = contactform["de"]["e_mail"];
	document.getElementById("land").value    = contactform["de"]["land"];
	document.getElementById("bemerkungen").value = "";
}
