
function einblenden(divID)
{
//alert(divID);
var obj = document.getElementById(divID);
obj.style.visibility="visible";
}
function ausblenden(divID)
{
//alert(divID);
var obj = document.getElementById(divID);
obj.style.visibility="hidden";
} 

function swapImage(imgName, swapImgName)
{
	document[imgName].src= swapImgName;
}

function fadeIn(id, millisec){
	document.getElementById(id).style.zIndex=2;
	opacity(id,0,100,millisec);
}
function fadeOut(id, millisec){
	opacity(id,100,0,millisec);	
	setTimeout("document.getElementById('" + id + "').style.zIndex=-2",millisec);
}

function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
	return true;
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	//object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function chkR( str, from, to ) {
	if ( str < from ) return false;
	if ( str > to ) return false;
	return true;
    }
    function isAlphaNum(s) {
        return chkR(s,"a","z") || chkR(s,"A","Z") || chkR(s,"0","9");
    }
    function isWord(s) {
        var i;
	if ( s.length == 0 ) {
	    return false;
	}
	for ( i=0; i<s.length; i++) {
	    var c = s.charAt(i);
	    if ( ! isAlphaNum(c) ) {
	        if ( i == 0 ) return false;
		if ( i == s.length - 1 ) return false;
	        if ( c != "-" ) 
	            return false;
	    }
	}
        return true;
    }

    function isWordOrDot(s) {
        var i;
	if ( s.length == 0 ) {
	    return false;
	}
	for ( i=0; i<s.length; i++) {
	    var c = s.charAt(i);
	    if ( ! isAlphaNum(c) ) {
	        if ( i == 0 ) return false;
		if ( i == s.length - 1 ) return false;
	        if ( (c != "-") && (c != ".") ) 
	            return false;
	    }
	}
        return true;
    }



    function check_mail(mail) {
      var idx = mail.indexOf( "@" );
      if ( idx == -1 || idx == 0 || idx == mail.length - 1) {
          return 0;
      } else {
          var user = mail.substring(0, idx);
          var host = mail.substring(idx + 1, mail.length);
          //
          // test mail
          //if ( ! isWordOrDot( user ) ) return false;
          //
          // test host
          var tok = host.split(".");
          for ( idx = 0; idx < tok.length; idx++ ) {
              if ( ! isWord( tok[ idx ] ) ) return false;
          }
          return true;
      }
    }

    function testsubmit () {
    //alert(document.gkform.usertext.value.length);
if (document.gkform.nameabs.value == "" || document.gkform.nameabs.value == "Name") 
         {
	    alert( "Bitte geben Sie Ihren Namen ein!" );
	    return false;
	} 
if (document.gkform.mailabs.value == "") 
         {
	    alert( "Bitte geben Sie Ihre Email-Adresse ein!" );
	    return false;
	} 
        if ( document.gkform.mailabs.value == "user@provider.suffix"
	|| ! check_mail( new String(document.gkform.mailabs.value) ) )
 {
	    alert("Die Email-Adresse des Absenders ist falsch eingegeben!" );
	    return false;
	} 
if (document.gkform.nameempf.value == "" || document.gkform.nameempf.value == "Name") 
         {
	    alert( "Bitte geben Sie den Namen des Empfängers ein!" );
	    return false;
	} 
if (document.gkform.mailempf.value == "") 
         {
	    alert( "Bitte geben Sie die Email-Adresse des Empfängers ein!" );
	    return false;
	} 
        if ( document.gkform.mailempf.value == "user@provider.suffix"
	|| ! check_mail( new String(document.gkform.mailempf.value) ) )
 {
	    alert("Die  Email-Adresse des Empfängers ist falsch eingegeben !" );
	    return false;
	} 

if (document.gkform.usertext.value == "") 
         {
	    alert( "Das Nachrichtenfeld darf nicht leer bleiben!" );
	    return false;
	} 
	var txt = document.gkform.usertext.value;
if (txt.length > 600) 
         {
	    alert( "Bitte verwenden Sie für die Nachricht maximal 300 Zeichen!" );
	    return false;
	}


	return true;

    }

 function textCounter() {
     if (document.gkform.usertext.value.length > 600) {
         document.gkform.usertext.value = document.gkform.usertext.value.substring(0, maxlimit);
     } else {
         document.gkform.textcounter.value = 600 - document.gkform.usertext.value.length;
     }
 }
