if( window.addEventListener) {
   window.addEventListener( "load", init, false);
} else if( window.attachEvent) {
   window.attachEvent( "onload", init);
} else {
   window.onload = init;
}


function init() {
   addEventToFormFields();
}


function addEventToFormFields() {
   var contactForm = document.getElementById( "contactform");

   if( contactForm) {
      for( elementId = 0; elementId < contactForm.elements.length; elementId++) {
         var element = contactForm.elements[ elementId];

         if( "text" == element.type || "textarea" == element.type) {
            element.onfocus = function() {
               this.style.color = "#766A5A";

               if( "wronginput" == this.className ) {
                  this.className = "";
               }

               if( "name" == this.name && "Anrede/ Name" == this.value
                       || "company" == this.name && "Firma/ Position" == this.value
                       || "address" == this.name && "Adresse" == this.value
                       || "fone" == this.name && "Telefon" == this.value
                       || "email" == this.name && "eMail" == this.value
                       || "message" == this.name && "Ihre Nachricht " == this.value ) {
                  this.value = "";
               }
            }

            element.onblur = function() {
               if( "name" == this.name && this.value == "") {
                  this.value = "Anrede/ Name";
               } else if( "company" == this.name && "" == this.value) {
                  this.value = "Firma/ Position";
               } else if( "address" == this.name && "" == this.value) {
                  this.value = "Adresse";
               } else if( "fone" == this.name && "" == this.value) {
                  this.value = "Telefon";
               } else if( "email" == this.name && "" == this.value) {
                  this.value = "eMail";
               } else if( "message" == this.name && "" == this.value ) {
                  this.value = "Ihre Nachricht";
               }

               if( "optional" == this.className ) {
                  this.style.color = "#B3ACA4";
               }
            }
         }
      }
   }
}

