/* 
(c)2002-2004 www.parallaxis.de  
  Funktionsbibliothek
*/


//	Funktion des Browser-Zurueck-Buttons 
function fBack()
{ 
history.back(1);
} 

//	Popup-Fenster DE oeffnen
function fPopup() 
{
window.open('0_popup.html', 'HotelChristophSchennaPopup', 
 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=360,height=470');
}
 
//	Popup-Fenster IT oeffnen
function fPopupit() {
 window.open('0_popup.html', 'HotelChristophSchennaPopup', 
 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=360,height=540');
}
 
function fOpenerLink(url) {
        opener.location = url;
        }

//	Formulartest deutsche Version---------------------------------------------
function chkForm()
		{
		  var valid
		  valid = true;
		  if(!chkName())  	//Namen generell ueberpruefen
		    {
		    valid = false;
		    return valid;
		    exit;
		    }
					//Abfrage ob Email, Fax oder Postversand
		  for (i=0;i<=2;i++)
		    {
		      if (document.Anfrage.MailerBestaetigungPer[i].checked==1)
			var Eingabe = document.Anfrage.MailerBestaetigungPer[i].value;
		    }
		  switch(Eingabe)
		    {
		      case "Email":
			if(!chkEmail())		//Email-Anfrage
			  {
			  valid = false;
			  return valid;
			  }
			break;
		      case "Fax":
			if(!chkFax())		//Fax-Anfrage
			  {
			  valid = false;
			  return valid;
			  }
			break;
		      case "Post":
			if(!chkAdresse())	//Post-Anfrage
			  {
			  valid = false;
			  return valid;
			  }
			break;
		    }
         // if (!document.Anfrage.MailerInfo_Weiterhin.checked)
				 //{
				 //document.Anfrage.MailerInfo_Weiterhin.checked;
			 //var infoweiter = "Bitte KEIN Informationsmaterial außer dem Angefragten!!!" 
           //document.Anfrage.MailerInfo_Weiterhin.value = infoweiter;
 			 //alert (document.Anfrage.MailerInfo_Weiterhin.value);	
 //}
		  return valid;
		}

	function chkName()
		{
		if(document.Anfrage.MailerName.value == "" ||  document.Anfrage.MailerName.value.substr(0, 1) == " ")
		  {
		    alert("Bitte geben Sie Vor- und Nachnamen ein und achten Sie darauf dass sich an erster Stelle kein Leerzeichen befindet!");
		    document.Anfrage.MailerName.focus();
		    return false;
		  }
		else
		  return true;
		}

	function chkAdresse()
		{
		if((document.Anfrage.MailerStrasse.value == "" || document.Anfrage.MailerStrasse.value.substr(0, 1) == " ") 
			|| (document.Anfrage.MailerPLZ.value == "" || document.Anfrage.MailerPLZ.value.substr(0, 1) == " ")
			|| (document.Anfrage.MailerOrt.value == "" || document.Anfrage.MailerOrt.value.substr(0, 1) == " ")
			|| (document.Anfrage.MailerLand.value == "" || document.Anfrage.MailerLand.value.substr(0, 1) == " "))
		  {
		  alert("Bitte geben Sie Ihre komplette Adresse an und achten Sie darauf dass sich an erster Stelle kein Leerzeichen befindet!");
		  document.Anfrage.MailerStrasse.focus();
		  return false;
		  }
		else
		  return true;
		}

	function chkEmail()
		{
		if (!CheckEmail (document.Anfrage.MailerEmail.value)) 
		 {
		  alert("Bitte überprüfen Sie Ihre E-mail Adresse! Oder ändern Sie die Form wie Sie Ihre Bestätigung erhalten möchten unter: Angebot bitte per:");
		  document.Anfrage.MailerEmail.focus();
		  return false;
		  exit;
		 }
		else
		  return true;
		}

	function chkFax()
		{
		
	/*	var ff = document.Anfrage.MailerTelefax.value.substr(0, 1);|||| ff == " "*/
	
		if(document.Anfrage.MailerTelefax.value == "" || document.Anfrage.MailerTelefax.value.substr(0, 1) == " ")
		 {
		 alert("Bitte geben Sie Ihre Faxnummer ein und achten Sie darauf dass sich an erster Stelle kein Leerzeichen befindet!");
		  document.Anfrage.MailerTelefax.focus();
		  return false;
		  exit;
		 }
	/*if(!PruefeZeichen(document.Anfrage.MailerTelefax, "0123456789 /-+()", "Bitte prüfen Sie die Telefonnummer"))
		 {
          return false;
		  exit;
		 }*/
	else
        
		  return true;
		}
		
		
		
/*----------------------------- TEST EINBAU EVENTUELL MACHEN auf zahlen überprüfen-------------------------------	*/	
		
		
		//--- Prüft, ob nur Zeichen eingegeben wurden,
  //--- die für eine Telefonnummer üblich sind
 /* function NurTelefon(Feld)
  {  PruefeZeichen(Feld, "0123456789 /-+()", "Bitte prüfen Sie die Telefonnummer") || Feld.value.substr(0, 1) == " "}
		*/
		
	 //--- Unterprogramm, welches die Zeichen prüft
    function PruefeZeichen(Feld, ZugelasseneZeichen, FehlerMeldung)
    {  // Erstellt von Ralf Pfeifer (www.arstechnica.de)
       for (var Pos = 0; Pos < Feld.value.length; Pos++)
       {
          if (ZugelasseneZeichen.indexOf(Feld.value.charAt(Pos)) == -1)
          { FehlerMeldung += "\n\nIhre Eingabe enthält das Zeichen '"
            FehlerMeldung += Feld.value.charAt(Pos)
            FehlerMeldung += "'. Sie dürfen nur diese Zeichen verwenden:\n"
            FehlerMeldung += ZugelasseneZeichen
            if (ZugelasseneZeichen.indexOf(" ") == -1 )
               { FehlerMeldung += "\nLeerzeichen sind nicht erlaubt" }
            else
               { FehlerMeldung += "\nund das Leerzeichen" }
            
			alert(FehlerMeldung)
			 Feld.focus();
		 return false;
         }
       }
 }

		
		
	/*----------------------------- TEST EINBAU ERST MACHEN auf zahlen überprüfen-------------------------------	*/
		
		


//	Formularabfrage italienische Version -----------------------------------------
function chkFormit()
		{
		  var valid
		  valid = true;
		  if(!chkNameit())  	//Namen generell ueberpruefen
		    {
		    valid = false;
		    return valid;
		    exit;
		    }
					//Abfrage ob Email, Fax oder Postversand
		  for (i=0;i<=2;i++)
		    {
		      if (document.Anfrage.MailerBestaetigungPer[i].checked==1)
			var Eingabe = document.Anfrage.MailerBestaetigungPer[i].value;
		    }
		  switch(Eingabe)
		    {
		      case "Email":
			if(!chkEmailit())		//Email-Anfrage
			  {
			  valid = false;
			  return valid;
			  }
			break;
		      case "Fax":
			if(!chkFaxit())		//Fax-Anfrage
			  {
			  valid = false;
			  return valid;
			  }
			break;
		      case "Post":
			if(!chkAdresseit())	//Post-Anfrage
			  {
			  valid = false;
			  return valid;
			  }
			break;
		    }
         // if (!document.Anfrage.MailerInfo_Weiterhin.checked)
				 //{
				 //document.Anfrage.MailerInfo_Weiterhin.checked;
			 //var infoweiter = "Bitte KEIN Informationsmaterial außer dem Angefragten!!!" 
           //document.Anfrage.MailerInfo_Weiterhin.value = infoweiter;
 			 //alert (document.Anfrage.MailerInfo_Weiterhin.value);	
 //}
		  return valid;
		}

	function chkNameit()
		{
			if(document.Anfrage.MailerName.value == "" || document.Anfrage.MailerName.value.substr(0, 1) == " ")
		  {
		    alert("Vi preghiamo di di inserire il Vs. nome e cognome! Stia attento che sul primo posto non ci sia una spaziatura.");
		    document.Anfrage.MailerName.focus();
		    return false;
		  }
		else
		  return true;
		}

	function chkAdresseit()
		{
			if((document.Anfrage.MailerStrasse.value == "" || document.Anfrage.MailerStrasse.value.substr(0, 1) == " ") 
			|| (document.Anfrage.MailerPLZ.value == "" || document.Anfrage.MailerPLZ.value.substr(0, 1) == " ")
			|| (document.Anfrage.MailerOrt.value == "" || document.Anfrage.MailerOrt.value.substr(0, 1) == " ")
			|| (document.Anfrage.MailerLand.value == "" || document.Anfrage.MailerLand.value.substr(0, 1) == " "))
		  {
		  alert("Vi preghiamo di compilare l'indirizzo completo! Stia attento che sul primo posto non ci sia una spaziatura.");
		  document.Anfrage.MailerStrasse.focus();
		  return false;
		  }
		else
		  return true;
		}

	function chkEmailit()
		{
		if (!CheckEmail (document.Anfrage.MailerEmail.value)) 
		 {
		  alert("Vi preghiamo di inserire il Vs. indirizzo Email o di scegliere un altro modo di conferma sul posto Offerta via: ");
		  document.Anfrage.MailerEmail.focus();
		  return false;
		  exit;
		 }
		else
		  return true;
		}

	function chkFaxit()
		{
		if(document.Anfrage.MailerTelefax.value == "" || document.Anfrage.MailerTelefax.value.substr(0, 1) == " ")
		 {
		  alert("Vi preghiamo di inserire il Vs. numero Fax! Stia attento che sul primo posto non ci sia una spaziatura.");
		  document.Anfrage.MailerTelefax.focus();
		  return false;
		  exit;
		 }
		else
		  return true;
		}


//	Formularabfrage englische Version ----------------------------------------------
function chkFormuk()
		{
		  var valid
		  valid = true;
		  if(!chkNameuk())  	//Namen generell ueberpruefen
		    {
		    valid = false;
		    return valid;
		    exit;
		    }
					//Abfrage ob Email, Fax oder Postversand
		  for (i=0;i<=2;i++)
		    {
		      if (document.Anfrage.MailerBestaetigungPer[i].checked==1)
			var Eingabe = document.Anfrage.MailerBestaetigungPer[i].value;
		    }
		  switch(Eingabe)
		    {
		      case "Email":
			if(!chkEmailuk())		//Email-Anfrage
			  {
			  valid = false;
			  return valid;
			  }
			break;
		      case "Fax":
			if(!chkFaxuk())		//Fax-Anfrage
			  {
			  valid = false;
			  return valid;
			  }
			break;
		      case "Post":
			if(!chkAdresseuk())	//Post-Anfrage
			  {
			  valid = false;
			  return valid;
			  }
			break;
		    }
         // if (!document.Anfrage.MailerInfo_Weiterhin.checked)
				 //{
				 //document.Anfrage.MailerInfo_Weiterhin.checked;
			 //var infoweiter = "Bitte KEIN Informationsmaterial außer dem Angefragten!!!" 
           //document.Anfrage.MailerInfo_Weiterhin.value = infoweiter;
 			 //alert (document.Anfrage.MailerInfo_Weiterhin.value);	
 //}
		  return valid;
		}

	function chkNameuk()
		{
		if(document.Anfrage.MailerName.value == "" || document.Anfrage.MailerName.value.substr(0, 1) == " ")
		  {
		    alert("Please enter your name! Pay attention that in the first place there is no blank space.");
		    document.Anfrage.MailerName.focus();
		    return false;
		  }
		else
		  return true;
		}

	function chkAdresseuk()
		{
	if((document.Anfrage.MailerStrasse.value == "" || document.Anfrage.MailerStrasse.value.substr(0, 1) == " ") 
			|| (document.Anfrage.MailerPLZ.value == "" || document.Anfrage.MailerPLZ.value.substr(0, 1) == " ")
			|| (document.Anfrage.MailerOrt.value == "" || document.Anfrage.MailerOrt.value.substr(0, 1) == " ")
			|| (document.Anfrage.MailerLand.value == "" || document.Anfrage.MailerLand.value.substr(0, 1) == " "))
		  {
		  alert("Please enter your full adress! Pay attention that in the first place there is no blank space.");
		  document.Anfrage.MailerStrasse.focus();
		  return false;
		  }
		else
		  return true;
		}

	function chkEmailuk()
		{
		if (!CheckEmail (document.Anfrage.MailerEmail.value)) 
		 {
		  alert("Please enter your email!or choose another way to receive a receipt in the field Offer by:");
		  document.Anfrage.MailerEmail.focus();
		  return false;
		  exit;
		 }
		else
		  return true;
		}

	function chkFaxuk()
		{
		if(document.Anfrage.MailerTelefax.value == "" || document.Anfrage.MailerTelefax.value.substr(0, 1) == " ")
		 {
		  alert("Please enter your fax number! Pay attention that in the first place there is no blank space.");
		  document.Anfrage.MailerTelefax.focus();
		  return false;
		  exit;
		 }
		else
		  return true;
		}



//	Zoom-Funktion mit Parametern
function fZoom(imageName,imageWidth,imageHeight,bildunterschrift) 
{ 
newWindow = window.open("","newWindow","width="+(imageWidth)+",height="+(imageHeight)+",scrollbars=no");
//newWindow=window.open("","newWindow","width="+(20+imageWidth)+",height="+(1+fensterheigth)+", scrollbars=no");
newWindow.document.open();
newWindow.document.write('<html><head><title>Christoph&#8217; s Hotel der Sinne - Schenna bei Meran - S&uuml;dtirol- Zoom</title>');
newWindow.document.write('</head>');
//newWindow.document.write('<body bgcolor="white" leftmargin="0" topmargin="10" marginheight="10" marginwidth="0" background="../images/streifen_hg.gif" onBlur="self.close()">');
newWindow.document.write('<body bgcolor="#F0E8A7" background="../pics/0_elements/hg.gif" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onBlur="self.close()">')
newWindow.document.write('<p align="center"><a href="javascript:self.close()"><img src=\"'+imageName+'\"  align="absmiddle" border=0></a>');
if (fZoom.arguments.length>3)
  {
  newWindow.document.write('<font face="Verdana, Arial, Helvetica, sans-serif" size="2" color="#281411"><br><br>'+ bildunterschrift+'</font></p></body></html>')
  }
newWindow.document.close(); 
newWindow.focus(); 
}

//	Zoom-Funktion mit Parametern  ITAL
function fZoomit(imageName,imageWidth,imageHeight,bildunterschrift) 
{ 
newWindow = window.open("","newWindow","width="+(imageWidth)+",height="+(imageHeight)+",scrollbars=no");
//newWindow=window.open("","newWindow","width="+(20+imageWidth)+",height="+(1+fensterheigth)+", scrollbars=no");
newWindow.document.open();
newWindow.document.write('<html><head><title>Christoph l&acute;albergo dei Sensi- Scena - Alto Adige- Zoom</title>');
newWindow.document.write('</head>');
//newWindow.document.write('<body bgcolor="white" leftmargin="0" topmargin="10" marginheight="10" marginwidth="0" background="../images/streifen_hg.gif" onBlur="self.close()">');
newWindow.document.write('<body bgcolor="#F0E8A7" background="../pics/0_elements/hg.gif" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onBlur="self.close()">')
newWindow.document.write('<p align="center"><a href="javascript:self.close()"><img src=\"'+imageName+'\"  align="absmiddle" border=0></a>');
if (fZoomit.arguments.length>3)
  {
 newWindow.document.write('<font face="Verdana, Arial, Helvetica, sans-serif" size="2" color="#281411"><br><br>'+ bildunterschrift+'</font></p></body></html>')
  }
newWindow.document.close(); 
newWindow.focus(); 
}

//	Zoom-Funktion mit Parametern  ENGL
function fZoomuk(imageName,imageWidth,imageHeight,bildunterschrift) 
{ 
newWindow = window.open("","newWindow","width="+(imageWidth)+",height="+(imageHeight)+",scrollbars=no");
//newWindow=window.open("","newWindow","width="+(20+imageWidth)+",height="+(1+fensterheigth)+", scrollbars=no");
newWindow.document.open();
newWindow.document.write('<html><head><title>Christoph&#8217; s Hotel der Sinne - Schenna - South Tyrol - Italy- Zoom</title>');
newWindow.document.write('</head>');
//newWindow.document.write('<body bgcolor="white" leftmargin="0" topmargin="10" marginheight="10" marginwidth="0" background="../images/streifen_hg.gif" onBlur="self.close()">');
newWindow.document.write('<body bgcolor="#F0E8A7" background="../pics/0_elements/hg.gif" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onBlur="self.close()">')
newWindow.document.write('<p align="center"><a href="javascript:self.close()"><img src=\"'+imageName+'\"  align="absmiddle" border=0></a>');
if (fZoomuk.arguments.length>3)
  {
 newWindow.document.write('<font face="Verdana, Arial, Helvetica, sans-serif" size="2" color="#281411"><br><br>'+ bildunterschrift+'</font></p></body></html>')
  }
newWindow.document.close(); 
newWindow.focus(); 
}


//	Macromedia Swapimage-Funktionen
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

 
function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_nbGroup(event, grpName) { //v3.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : args[i+1];
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    if ((nbArr = document[grpName]) != null)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = args[i+1];
      nbArr[nbArr.length] = img;
  } }
}


  var c2cframe = null;
  function openClickToCallFrame(userID, buttonID) {
    if(c2cframe != null) {
      if(!c2cframe.closed) {
        c2cframe.close();
      }
    }
/*
Wünschen Sie eine andere Sprache als im Call-Back-Office angegeben,
 kommentieren Sie einfach eine der nachfolgenden Zeilen ein:
 (de für Deutsch, en für Englisch, fr für Französisch)
*/
    c2cframe = open("http://hoteldirect.teleconf.de:80/callback/callbackinitiation.do" +
                    "?NEW=NEW" +
                    "&UserID=" + userID +
                    "&BUTTONID=" + buttonID
              //  +  "&Locale=de"
              //  +  "&Locale=en"
              //  +  "&Locale=fr"
                   , "ClickToCallFrame", "width=215,height=330,resizable=yes,left=50,top=50");
    return false;
  }

  //	Panorama-Funktion mit Parametern
function fPano_Zoom(imageName,imageWidth,imageHeight) 
{ 
newWindow = window.open("","newWindow","width="+(760)+",height="+(imageHeight+16)+",scrollbars=yes");
newWindow.document.open();
newWindow.document.write('<html><head><title>Hotel Caf&eacute; Christoph - Schenna bei Meran - S&uuml;dtirol - Italien</title>');
newWindow.document.write('<body bgcolor="#FFF4C3" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onBlur="self.close()">');
newWindow.document.write('<p align="center"><a href="javascript:self.close()"><img src=\"'+imageName+'\"  align="absmiddle" border=0></a>');
newWindow.document.write('</body></html>')
newWindow.document.close(); 
newWindow.focus(); 
}




function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_HideAllLayers() {
  for (i=0; i<36; i+=1) 
	if ((obj=MM_findObj('Layer'+i))!=null){ v='hide';
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function fpopup_karte(dateiname, fensterweite, fensterhoehe)
{
popupfenster = window.open(dateiname, "suedtirolkarte_popup", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width="+fensterweite+",height="+fensterhoehe);
popupfenster.focus();
}

function fpopup_anfrage(dateiname, fensterweite, fensterhoehe)
{
popupfenster = window.open(dateiname, "Anfrage_popup", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width="+fensterweite+",height="+fensterhoehe);
popupfenster.focus();
}	





//ERMAILABFRAGE


function CheckEmail (emailStr)
{

/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */

var checkTLD=1;

/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|ad|al|as|ao|aq|ar|aw|at|bs|bd|be|bj|by|ba|bv|io|bg|bi|kh|ca|ky|td|cn|cc|km|ck|hr|cy|dk|do|ec|sv|ee|fk|fj|fr|tf|gm|de|gi|gr|gd|gu|gn|gy|ht|hn|hu|in|ir|ie|it|jm|jo|ke|ki|kr|la|lb|lr|li|lu|mg|my|ml|mh|mr|mx|md|mn|ma|mm|nr|an|nt|nz|ne|nu|mp|om|pw|pg|pe|pn|pf|pr|re|ru|lc|sm|sn|sl|si|so|su|lk|pm|vc|sr|sz|ch|tj|tz|tg|to|tn|tm|tv|ua|uk|uy|uz|va|vn|vi|eh|yu|zm|af|dz|ad|ai|ag|am|au|az|bh|bb|bz|bm|bo|bw|br|bn|bf|bt|cm|cv|cf|cl|cx|co|cg|cr|cu|cs|dj|tp|eg|gq|et|fo|fi|fx|ga|ge|gh|gb|gl|gp|gt|gw|gf|hm|hk|is|id|iq|il|ci|jp|kz|kg|kp|kw|lv|ls|ly|lt|mo|mw|mv|mt|mq|mu|fm|mc|ms|mz|na|np|nl|nc|ni|ng|nf|no|pk|pa|py|ph|pl|pt|qa|ro|rw|ws|sa|sc|sg|sb|za|es|sh|st|sd|sj|se|sy|tw|th|tk|tt|tr|tc|ug|ae|us|um|vu|ve|vg|wf|ye|zr|zw|cz|sk|eu)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */

var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address. 
These characters include ( ) < > @ , ; : \ " . [ ] */

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a 
username or domainname.  It really states which chars aren't allowed.*/

var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */

var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */

var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */

var matchArray=emailStr.match(emailPat);

if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */

//alert("Ungültige Email-Adresse (pr&uuml;fen Sie @ and .'s)");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
//alert("Ungültige Zeichen im Usernamen.");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
//alert("Ungültige Zeichen im Domänennamen.");
return false;
   }
}

// See if "user" is valid 

if (user.match(userPat)==null) {

// user is not valid

//alert("Name ungültig.");
return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
//alert(" IP Address ungültig!");
return false;
   }
}
return true;
}

// Domain is symbolic name.  Check if it's valid.
 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
//alert("Ungültige Domäne.");
return false;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
//alert("Ungültige TLD oder Land .");
return false;
}

// Make sure there's a host name preceding the domain.

if (len<2) {
//alert("Kein Host angegeben!");
return false;
}

// If we've gotten this far, everything's valid!
return true;
}


