var resObject=null;
var IE=0;


resObject=erzXMLHttpRequestObject();

// *********************************************************************************************************************************
//
//
//
// *********************************************************************************************************************************



function erzXMLHttpRequestObject(){
  var resObject = null;
  try {
    resObject = new ActiveXObject("Microsoft.XMLHTTP");
	IE=1;
  }
  catch(Error){
    try {
      resObject = new ActiveXObject("MSXML2.XMLHTTP");
    }
    catch(Error){
      try {
      resObject = new XMLHttpRequest();
      }
      catch(Error){
        alert("Erzeugung des XMLHttpRequest-Objekts ist nicht möglich");
      }
    }
  }
  return resObject;
}

// *********************************************************************************************************************************
//
//
//
// *********************************************************************************************************************************


function sndReqPOST(_url,_query)
{
	_query += '&IE='+((navigator.userAgent.indexOf("icrosoft") >= 0)?1:0);
	/* 
	location.href="common/formulare.php?"+_query;
	return;
	*/
	
	resObject.open('POST',_url,true);
	resObject.onreadystatechange=handleResponse;
	resObject.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	resObject.send(_query);
}

// *********************************************************************************************************************************
//
//
//
// *********************************************************************************************************************************


function handleResponse(counterVar)
{
	if (typeof(counterVar) == undefined)
	{
		xcounterVar = 0;
	}
	else
	{
		xcounterVar = counterVar +1;
	}
	if (resObject.readyState == 4)
	{
		if (typeOfAction == 862)
		{
			res=resObject.responseText;

			if (res.indexOf('ERROR_100') >= 0)
			{
				resMSG="Eintrag nicht möglich, die von Ihnen angegebene Email-Adresse wurde bereits registriert...";
			}
			if (res.indexOf('ERROR_200') >= 0)
			{
				resMSG="Eintrag nicht möglich, Datenbankfehler, probieren Sie es bitte später nocheinmal...";
			}
			if (res.indexOf('ERROR_201') >= 0)
			{
				resMSG="Eintrag nicht möglich, Email konnte nicht überprüft werden, probieren Sie es bitte später nocheinmal...";
			}
			if (res.indexOf('ERROR_300') >= 0)
			{
				resMSG="Eintrag nicht möglich, Fehler beim Versenden der Email, probieren Sie es bitte später nocheinmal...";
			}
			if (res.indexOf('OK') >= 0)
			{
				resMSG="Danke sehr, die Bestätigungs-Email wurde an die von Ihnen angegebene Adresse gesandt...";
				document.ANMELDUNG.ANREDE.value='';
				document.ANMELDUNG.VORNAME.value='';
				document.ANMELDUNG.ZUNAME.value='';
				document.ANMELDUNG.EMIL.value='';
			}
			document.getElementById('FORM_AFM').className="DANKE_AMF";
			document.getElementById('FORM_AFM').innerHTML=resMSG;			
			return;
		}
	}
	else
	{
		if (xcounterVar < 1000)
		{
			window.setTimeout('handleResponse(xcounterVar)',100);
		}	
	}
}

// *********************************************************************************************************************************
//
//
//
// *********************************************************************************************************************************


function afmControl()
{
	error=0;
	afmMessage='';
	while (1 == 1)
	{
		if (document.ANMELDUNG.VORNAME.value=='')
		{
			afmMessage= "Bitte geben Sie Ihren Vornamen ein...";
			fc=document.ANMELDUNG.VORNAME;
			error=1;
			break;
		}
		if (document.ANMELDUNG.ZUNAME.value=='')
		{
			afmMessage= "Bitte geben Sie Ihren Zunamen ein...";
			fc=document.ANMELDUNG.ZUNAME;
			error=1;
			break;
		}
		if (document.ANMELDUNG.EMIL.value=='')
		{
			afmMessage= "Bitte geben Sie Ihre E-Mailadresse ein...";
			fc=document.ANMELDUNG.EMIL;
			error=1;
			break;
		}
		else
		{
			if (! emailcheck(document.ANMELDUNG.EMIL.value))
			{
				afmMessage= "Irgendwie sieht Ihre E-Mailadresse nicht nach E-Mailadresse aus...";
				fc=document.ANMELDUNG.EMIL;
				error=1;
				break;
			}
		}
		break;
	}	
	if (afmMessage != '')
	{
		alert(afmMessage);
		fc.focus();
	}
	return (error == 0);	
}


// *********************************************************************************************************************************
//
//
//
// *********************************************************************************************************************************

function emailcheck(s)
{																																							
 var a = false;
 var res = false;
 if(typeof(RegExp) == 'function')
 {
  var b = new RegExp('abc');
  if(b.test('abc') == true){a = true;}
  }

 if(a == true)
 {
  reg = new RegExp('^([a-zA-Z0-9\\-\\.\\_]+)'+
                   '(\\@)([a-zA-Z0-9\\-\\.]+)'+
                   '(\\.)([a-zA-Z]{2,4})$');
  res = (reg.test(s));
 }
 else
 {
  res = (s.search('@') >= 1 &&
         s.lastIndexOf('.') > s.search('@') &&
         s.lastIndexOf('.') >= s.length-5)
 }
 return(res);
}
function urlencode_string( estring )
{

	if (estring =='')
	{
		return '';
	}
	if (estring==null)
	{
		return '';
	}
	// alert(estring);

    hex = '0123456789ABCDEF';
    encString = '';
    e_char = '';
    e_len = estring.length;
    for( e_i = 0; e_i < e_len; e_i++ )
    {
        e_char = parseInt( estring.charCodeAt( e_i ) );
        encString += '%' + hex.charAt( (e_char >> 4) % 16 ) + hex.charAt( e_char % 16 );
    }
    return encString;

}


function getAnmeldung()
{
	if (! afmControl())
	{
		return;
	}
	mANREDE=urlencode_string(document.ANMELDUNG.ANREDE.value.substr(0,30));
	mVORNAME=urlencode_string(document.ANMELDUNG.VORNAME.value.substr(0,50));
	mZUNAME=urlencode_string(document.ANMELDUNG.ZUNAME.value.substr(0,50));
	mEMIL=urlencode_string(document.ANMELDUNG.EMIL.value.substr(0,100));
	typeOfAction=862;
	_de="common/formulare.php";
	_qu="mod=862&mANREDE="+mANREDE+"&mVORNAME="+mVORNAME+"&mZUNAME="+mZUNAME+"&mEMIL="+mEMIL;
	sndReqPOST(_de,_qu);
	return;

}


