﻿// Kontakt Form Validator

window.onload = function()
{
    
    borderColorOnAlert = "#FE0002";
    backgroundColorOnAlert = "#FFCCCB";
    defaultValue = " *";
    
    borderColor = "";
    backgroundColor = "";
    setOrClearDefaultValue();
    bottomNav();
}

function setOrClearDefaultValue()
{
    var alltags = document.getElementsByTagName("input");
    for (i=0; i<alltags.length; i++)
    {
        if (alltags[i].defaultValue == defaultValue)
        {
            borderColor = alltags[i].style.borderColor;
            backgroundColor = alltags[i].style.backgroundColor;
            
            alltags[i].onfocus = function()
            {
                clearDefaultValue(this);
            }
            alltags[i].onblur = function()
            {
                setDefaultValue(this);
            }
        }
    }
    
    alltags = document.getElementsByTagName("textarea");

    for (i=0; i<alltags.length; i++)
    {
        if (alltags[i].defaultValue == defaultValue)
        {
            alltags[i].onfocus = function()
            {
                clearDefaultValue(this);
            }
            alltags[i].onblur = function()
            {
                setDefaultValue(this);
            }
        }
    }
}


function clearDefaultValue(obj)
{
    if (obj.value == defaultValue)
        obj.value = '';
    
    obj.style.backgroundColor = backgroundColor;
    obj.style.borderColor = borderColor;
}


function setDefaultValue(obj)
{
    if (obj.value == '' || obj.value == defaultValue)
    {
        obj.value = defaultValue;
        obj.style.backgroundColor = backgroundColorOnAlert;
        obj.style.borderColor = borderColorOnAlert;
    }
}


function validateForm()
{
  flag = 0;
  for (i=1;i<=document.form1.elements.length - 1;i++)
  {
  
    if (document.form1.elements[i].value == defaultValue)
    {
        document.form1.elements[i].style.backgroundColor = backgroundColorOnAlert;
        document.form1.elements[i].style.borderColor = borderColorOnAlert;
        flag += 1;
    }
  }
  
  
  if (flag > 0)
     return false;
  else
  {
     document.forms.form1.submit();
     
  }
}

/*

function validateForm1()
{
    flag = 1;
  if (document.contactForm.vorname.value == " *")
  {
      document.contactForm.vorname.style.backgroundColor = "#FFCCCB";
      document.contactForm.vorname.style.borderColor = "#FE0002";
      flag = 0;
  }
  if (document.contactForm.nachname.value == " *")
  {
      document.contactForm.nachname.style.backgroundColor = "#FFCCCB";
      document.contactForm.nachname.style.borderColor = "#FE0002";
      flag = 0;
  }
  if (document.contactForm.mail.value == " *")
  {
      document.contactForm.mail.style.backgroundColor = "#FFCCCB";
      document.contactForm.mail.style.borderColor = "#FE0002";
      flag = 0;
  }
  if (document.contactForm.betreff.value == " *")
  {
      document.contactForm.betreff.style.backgroundColor = "#FFCCCB";
      document.contactForm.betreff.style.borderColor = "#FE0002";
      flag = 0;
  }
  if (document.contactForm.anfrage.value == " *")
  {
      document.contactForm.anfrage.style.backgroundColor = "#FFCCCB";
      document.contactForm.anfrage.style.borderColor = "#FE0002";
      flag = 0;
  }
  
  
  if (flag == 0)
     return false;
  else
      document.forms.contactForm.submit();

}


*/
