﻿ 
    // Syntax Regulaere Ausdrücke
    var szcheckmail = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})$/;
    
    var leftposition = "289px";
    
    

//formular= Bestellformular, oder Kontaktformular
function ValidateField(ctl, formular,topposition,message)
{
     var szDataValue = ctl.value;
    //testet vorab, ob ein regulärer Ausdruck zu Suchtreffern führt oder nicht. Gibt true zurück, wenn etwas gefunden wurde, und false, wennnichts gefunden wurde
    var Ergebnis = szcheckmail.test(szDataValue);
    if(!Ergebnis)
    {
        
         ShowErrorMsg(ctl, "<p><strong>" + message + "</strong></p>",topposition);
         document.getElementById(ctl.id).style.border = "solid 4px black";
        
    }
    else if(Ergebnis)
    {
        document.getElementById(ctl.id).style.border = "solid 2px #705E48";
    }
    
}

function semikolon(control,topposition,message)
{
        // var val
        if(control.value.indexOf(";") > -1){
            ShowErrorMsg(control, "<p><strong>" + message + "</strong></p>",topposition);
              document.getElementById(control.id).style.border = "solid 4px black";
            }
        else if(control.value.indexOf(";") < 0){  
              document.getElementById(control.id).style.border = "solid 2px #705E48";
              HideErrorMsg();
              }
        else{
            HideErrorMsg();
        }

}  
 

 
//Funktioniert im IE, nicht in FF. Aufruf mit onkeypress(). Die Methode wird nicht aufgerufen
function check(event, control)
{
   var jetzt;
   var val = control.value.replace(';', '');
   control.value = val;
      
   if(getkey(event) == 59 )  
    {   
        ShowErrorMsg(control, "<p><strong>Bitte keine Semikolons verwenden</strong></p>", "200px");
        return false;
    }
    else
        HideErrorMsg();
}

function getkey(e) {    
    if( typeof( e.keyCode ) == 'number'  ) {
      //DOM
        return e.keyCode;
    } else if( typeof( e.which ) == 'number' ) {
      //NS 4 compatible
        return e.which;
    } else if( typeof( e.charCode ) == 'number'  ) {
      //also NS 6+, Mozilla 0.9+
        return e.charCode;
    } else {
      //total failure, we have no way of obtaining the key code
      return null;
    }    
  }




function ShowErrorMsg(control, message, topposition)
{
   var errorbox = document.getElementById("_ERROR");

   window.document.getElementById("_ERRORMSG").innerHTML = message;
   
  
   errorbox.style.top = topposition;
   errorbox.style.left = leftposition;
   errorbox.style.border = "solid 2px #E8CCA4";
   errorbox.style.backgroundColor = "#F7F2D5";
   errorbox.style.textAlign = "left";
   errorbox.style.display = "block";
}

function HideErrorMsg()
{
    var errorbox = window.document.getElementById("_ERROR");
    errorbox.style.display = "none";
}

function CheckForms (message1, message2) 
{
    var checkEmail = document.getElementById("cds_email").value;
    var checkErgebnis = szcheckmail.test(checkEmail);
    for (i = 0; i < document.forms[0].elements.length-1; ++i)

    if(checkErgebnis == false)
    {
        
      ShowErrorMsg(null,"<p><strong>" + message2 + "</strong></p>","0px");
      return false; 
    }
    else if (document.forms[0].elements[i].value.indexOf(";") > -1 || checkErgebnis == false) 
    {
     
      ShowErrorMsg(null,"<p><strong>" + message1 +"</strong></p>","0px");
      document.forms[0].elements[i].focus();
      return false;
    }
 return true;
}
function semi()
{
    alert("hallo");
 }

