//the status the button had before hovering
var status_before = "";

function changeLinkBackground(id){
	status_before = document.getElementById(id).src;
	document.getElementById(id).src = document.getElementById(id).src.replace("off", "on");
}

function restoreLinkBackground(id){
	//check if the the button was on or off when last hovered over, f.gif=off, n.gif=on
	var on_off = status_before.substr(status_before.length-5);

	//dont chande to off, if it is the actual page
	if(on_off == 'f.gif' || on_off == 'f.jpg' || on_off == 'f.png'){
		document.getElementById(id).src = document.getElementById(id).src.replace("on", "off");
	}
}

function clearSearchField(){
	if(document.getElementById('search_input_field').value == "suche..." || document.getElementById('search_input_field').value == "cerca..." || document.getElementById('search_input_field').value == "search...")
		document.getElementById('search_input_field').value = "";
}



//show and hide privacy conditions in the request form
function setDisplay(id){
    try{
      var elem;
      elem = document.getElementById(id);
      if (elem != null){
        if (elem.style.display == "none"){
          elem.style.display = "block";
          return;
        }
        else{
          elem.style.display = "none";
          return;
        }
      }
    }
    catch(e){
    }
}






//FORM VALIDATION
//form validation
//languages:
//0: deutsch
//1: italiano
//2: english

//TEXTE
error_message = new Array(); //viene creato l'array
error_message[0]="Achtung, nicht alle Felder wurden korrekt ausgefuellt";
error_message[1]="Attenzione, non tutti i campi sono stati compilati in maniera corretta";
error_message[2]="Warning, not all fields were filled out correctly";

privacy_message = new Array(); //viene creato l'array
privacy_message[0]="Achtung, stimmen Sie bitte den Bedingungen zur Privacy zu.";
privacy_message[1]="Attenzione, per continuare e neccessario accettare le condizioni privacy";
privacy_message[2]="Warning, to continue please accept the privacy terms";




function validateFormOnSubmit(theForm, language) {
var reason = "";

  if(document.forms.formular.privacy.checked != true){
    alert(privacy_message[language]);
    return false;
  } 
	
   
  reason += validateEmpty(theForm.name_surname);
  reason += validateEmpty(theForm.adresse);
  reason += validateEmpty(theForm.plz);
  reason += validateEmpty(theForm.ort);
  reason += validateEmpty(theForm.land);    
  reason += validateEmail(theForm.e_mail);
  reason += validateEmpty(theForm.telephone);
      
  if (reason != ""){
    return false;
  }

  return true;
}

function validateEmpty(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.border = '1px solid red'; 
        error = "The required field has not been filled in.\n"
    } else {
        fld.style.border = '1px dotted silver';
    }
    return error;  
}


function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}

function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.border = '1px solid red';
        error = "You didn't enter an email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.border = '1px solid red';
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.border = '1px solid red';
        error = "The email address contains illegal characters.\n";
    } else {
        fld.style.border = '1px dotted silver';
    }
    return error;
}










