	// Javascript includes

// seite drucken **************************************************************
function drucken()
{
print();
}


// ebenen ansprechen & referenzieren ******************************************
function identify(ebene) 
{
if (document.layers) {
    return document.layers[ebene];
    }
if (document.all) {
    return document.all[ebene];
    }
if (document.getElementById) {
   return document.getElementById(ebene);
   }
}


// fenster dimensionen - unbenutzt ***********************************************
function position_layer(ebene,xleft,xtop){
	var breite= window.innerWidth || window.document.body.offsetWidth;
	var hoehe= window.innerHeight || window.document.body.offsetHeight;
	identify(ebene).style["left"] = breite/2-xleft;
	identify(ebene).style["top"] = xtop;
}

// bsp - unbenutzt ***********************************************
var objClient = new Object()
// BrowserBreite###############################
if (window.document.body) {
objClient.InnerBrowserBreite = window.document.body.offsetWidth;
} else if (window.innerWidth) {
objClient.InnerBrowserBreite = window.innerWidth;
} else {
objClient.InnerBrowserBreite = "unknown";
}
// BrowserHoehe##############################
if (window.document.body) {
objClient.InnerBrowserHoehe = window.document.body.offsetHeight;
} else if (window.innerHeight) {
objClient.InnerBrowserHoehe = window.innerHeight;
} else {
objClient.InnerBrowserHoehe = "unknown";
}
// AvailBildschirmBreite##########################
if (screen) {
objClient.AvailXScreen = screen.availWidth;
} else {
objClient.AvailXScreen = "unknown";
}
// AvailBildschirmHoehe ########################
if (screen) {
objClient.AvailYScreen = screen.availHeight;
} else {
objClient.AvailYScreen = "unknown";
}


// formular senden *******************************************************
function send_form(val_1){
	theForm = document.yes; 
  	theForm.energie_form.value = val_1; 
	theForm.submit();
	}
	
function chg_loc(page)
	{
	document.location=page; 
	}
	
function get_stromrechner(val_1,val_2,val_3,val_4){
	theForm = document.schnell_check; 
  	theForm.status.value = val_4; 
	theForm.submit();
	}

function show_hide(ebene){
	if(identify(ebene).style.display == "block"){
		identify(ebene).style.display = "none";
		}
	else{ identify(ebene).style.display = "block"; }
	}
	
function show_hide_antw(ebene,anz){
	for(i=1; i<= anz; i++)
	{ 
		if(identify(ebene) != identify('antw_'+i)){ identify('antw_'+i).style.display = "none"; }
		else {
	if(identify(ebene).style.display == "block"){
		identify(ebene).style.display = "none";
		}
	else{ identify(ebene).style.display = "block"; }
		}
	}
	}
	
function show_hide_err(ebene,anz){
	for(i=0; i<= anz; i++)
	{ 
		if(identify(ebene) != identify('err_text_'+i)){ identify('err_text_'+i).style.display = "none"; }
		else {
	if(identify(ebene).style.display == "block"){
		//identify(ebene).style.display = "none";
		}
	else{ identify(ebene).style.display = "block"; }
		}
	}
	}
	
	
function show_tt(ebene){
	if(identify(ebene).style.display == "block"){
		identify(ebene).style.display = "none";
		}
	else{ identify(ebene).style.display = "block"; 
		}
	}
	
function senden(id,n,tf){
	if(id==0){berechnen(id,n,tf);return true;}
	if(id==1){weiter(id,n,tf);}
	}

/* tarifwechsel ************************************************************************/
function change(id,n,tf){
	theForm = identify(tf);
	theForm.status.value = id; 
	theForm.n.value = n; 		
	theForm.submit();
	//berechnen(id,n,tf);
	}

/* formular schnell-check pruefen  ****************************************************/
function berechnen(id,n,tf){
	theForm = identify(tf);
	var error = false;
	var errorText = '';
	var messg1 ="Bitte geben Sie für Ihre PLZ 5 Zahlen ein!";
	var messg2 ="Bitte geben Sie für Ihren Jahresverbrauch nur Zahlen von 500 - 100.000 ein!";

//leistung Check
	if (trim(theForm.leistung.value) == "" || isNaN(theForm.leistung.value) == true || trim(theForm.leistung.value) < 500 || trim(theForm.leistung.value) > 100000 )
		{
		errorText = messg2;
		error = true;
		theForm.leistung.focus();
  		}
//plz Check
	if (trim(theForm.plz.value) == "" || isNaN(theForm.plz.value) == true || (theForm.plz.value).length < 5)
		{
		errorText = messg1;
		error = true;
		theForm.plz.focus();
  		}
// ausgabe / submit
	if (error) { 

		identify('err_text').innerHTML = errorText;
		}
	else{
		theForm.status.value = id; 
		theForm.n.value = n; 
		theForm.submit();
		}
}

/* formular schnell-check pruefen  -   unbenutzt****************************************************/
function berechnen_2(id,n,tf){
	theForm = identify(tf); 
	theForm.status.value = id; 
	theForm.n.value = n; 	
	theForm.submit();
	//berechnen(id,n,tf);
	}

/* formular bestellen absenden ****************************************************/
function store_order(id,n,tf){
	theForm = identify(tf); 
	theForm.status.value = id; 
	theForm.n.value = n; 	
	theForm.submit();
	}


	
	
	
/* Formular-Check -----------------------------------------------------------*/
function trim(text)
	{
	text = text+" ";
	var first = text.length;
	var last  = 0;

	for(i=0; i<text.length; i++)
		{
		if(text.charAt(i)!=" ")
			{
			first = i;
			break;
			}
		}
	for(i=text.length; i>0; i--)
		{
		if(text.charAt(i-1)!=" ")
			{
			last = i;
			break;
			}
		}
	if(first>last) return("");
	return(text.substring(first,last));
	}
	
function isEmail(string)
{
  var atloc,dotloc,i,ch;
 
  if(string.length<6) return false;
  atloc = string.indexOf('@');
  dotloc = string.lastIndexOf('.');
  if(atloc==-1 || dotloc==-1 || atloc>dotloc || dotloc==(string.length-1) || (string.length-4)>dotloc || (string.length-2)==dotloc) return false;
  if(string.indexOf('@',atloc+1)!=-1) return false;
  for(i=0; i<string.length; i++)
  {
    ch = string.charAt(i);
    if(!((i<dotloc && ch>='0' && ch<='9') || (ch>='A' && ch<='Z') || (ch>='a' && ch<='z') || (i<=dotloc && (ch=='.' || ch=='@' || ch=='-' || ch=='_' || ch=='+'))))
      return false;
  }
  return true;
}
  
function send_msg(id,tf){
	theForm = identify(tf);
	var error = false;
	var errorText = '';
	
	var messg1 ="Bitte geben Sie Ihren Namen ein!";
	var messg2 ="Bitte geben Sie Ihre E-Mail-Adresse korrekt ein!";
	
	//EMail Check
  if (!isEmail(theForm.contact_email.value))
  	{
		errorText = messg2;
	    error = true;
		theForm.contact_email.focus();
	}
	//name Check
	if (trim(theForm.contact_name.value) == "")
  	{
   		errorText = messg1;
		error = true;
	    theForm.contact_name.focus();
  	} 
    
// ****************************************
// ausgabe / submit
	if (error) { 
		//alert(errorText); 
		identify('err_text').innerHTML = errorText;
		}
	else{
		theForm.status.value = id; 
		theForm.submit();
		}
}


	
function weiter(id,n,tf){
	theForm = identify(tf);
	var error = false;
	var errorText = '';
	
	var messg0 ="Bitte wählen Sie Ihre Anrede aus!";
	var messg1 ="Bitte geben Sie Ihren Vornamen ein!";
	var messg2 ="Bitte geben Sie Ihren Namen ein!";
	var messg3 ="Bitte geben Sie Ihre Strasse ein!";
	var messg4 ="Bitte geben Sie Ihre Hausnummer ein!";
	var messg5 ="Bitte geben Sie für Ihre PLZ 5 Zahlen ein!";
	
	var messg6 ="Bitte geben Sie Ihren Ort ein!";
	var messg7 ="Bitte geben Sie Ihre E-Mail-Adresse korrekt ein!";
	var messg8 ="Bitte geben Sie für Ihre Vorwahl mindestens 3 Zahlen ein!";
	var messg9 ="Bitte geben Sie für Ihre Telefonnummer mindestens 3 Zahlen ein!";
	var messg10 ="Bitte geben Sie für Ihren Geburtstag nur Zahlen von 1 - 31 ein!";
	
	var messg11 ="Bitte geben Sie für Ihren Geburtsmonat nur Zahlen von 1 - 12 ein!";
	var messg12 ="Bitte geben Sie für Ihr Geburtsjahr 4 Zahlen ein!";
	var messg13 ="Bitte geben Sie für Ihr Neueinzug Datum (Tag) nur Zahlen von 1 - 31 ein!";
	var messg13a ="Bitte geben Sie für Ihr Neueinzug Datum (Monat) nur Zahlen von 1 - 12 ein!";
	var messg13b ="Bitte geben Sie für Ihr Neueinzug Datum (Jahr) nur 4 Zahlen ein! 2008 oder später.";
	
	var messg13f ="Bitte geben Sie Ihren bisherigen Versorger ein!";
	var messg13g ="Bitte geben Sie Ihre bisherige Kundennummer ein!";
	var messg13h ="Bitte geben Sie Ihre bisherige Zählernummer ein!";
	
	var messg14 ="Bitte geben Sie den Namen Ihrer Bank ein!";
	var messg15 ="Bitte geben Sie Ihre Kontonummer ein!";
	var messg16 ="Bitte geben Sie Ihre BLZ ein (8-stellig)!";
	var messg17 ="Bitte geben Sie den Namen des Kontoinhabers ein!";
	var messg18 ="Bitte AGB "; var messg18a =" bestätigen / ankreuzen!";
    
    var messg19 ="Bitte geben Sie Ihren Ort ein!";
    


//AGB Check	------------------------------------------------------------
if((theForm.agb6)){
    if((theForm.agb6.checked) == false){ 
    errorText = messg18+'6'+messg18a;
    err_fld = 18;
    error = true;
    theForm.agb6.focus();
} }
    
if((theForm.agb5)){
    if((theForm.agb5.checked) == false){ 
    errorText = messg18+'5'+messg18a;
    err_fld = 18;
    error = true;
    theForm.agb5.focus();
} }

if((theForm.agb4)){
	if((theForm.agb4.checked) == false){ 
	errorText = messg18+'4'+messg18a;
	err_fld = 18;
    error = true;
    theForm.agb4.focus();
	} }
if((theForm.agb3)){
	if((theForm.agb3.checked) == false){ 
	errorText = messg18+'3'+messg18a;
	err_fld = 18;
    error = true;
    theForm.agb3.focus();
	} }
if((theForm.agb2)){	
if((theForm.agb2.checked) == false){ 
	errorText = messg18+'2'+messg18a;
	err_fld = 18;
    error = true;
    theForm.agb2.focus();
	} }
if((theForm.agb1)){
if((theForm.agb1.checked) == false){ 
	errorText = messg18+'1'+messg18a;
	err_fld = 18;
    error = true;
    theForm.agb1.focus();
	} }


//kto-inhaber Check
if (trim(theForm.kin.value) == "")
  {
    errorText = messg17;
	err_fld = 17;
    error = true;
    theForm.kin.focus();
  } 
  
//blz Check
  if (trim(theForm.blz.value) == "" || isNaN(theForm.blz.value) == true || (theForm.blz.value).length < 8)
  {
    errorText = messg16;
	err_fld = 16;
    error = true;
    theForm.blz.focus();
  } 

//kto Check
  if (trim(theForm.kto.value) == "" || isNaN(theForm.kto.value) == true)
  {
    errorText = messg15;
	err_fld = 16;
    error = true;
    theForm.kto.focus();
  } 

//bank Check
  if (trim(theForm.bnk.value) == "")
  {
    errorText = messg14;
	err_fld = 15;
    error = true;
    theForm.bnk.focus();
  } 
		

//RE_Adresse Check
if((theForm.are.checked) == true){ 
	//Ort Check
  	if (trim(theForm.or.value) == "")
  	{
    errorText = "Rechnungsadresse: "+messg6;
	err_fld = 14;
    error = true;
    theForm.or.focus();
  	}
  
	//pl Check
	if (trim(theForm.pl.value) == "" || isNaN(theForm.pl.value) == true || (theForm.pl.value).length < 5)
	{
	errorText = "Rechnungsadresse: "+messg5;
	err_fld = 14;
	error = true;
	theForm.pl.focus();
	}

//nr Check
  if (trim(theForm.nu.value) == "")
  {
    errorText = "Rechnungsadresse: "+messg4;
	err_fld = 14;
    error = true;
    theForm.nu.focus();
  } 
    
//strasse Check
  if (trim(theForm.st.value) == "")
  {
    errorText = "Rechnungsadresse: "+messg3;
	err_fld = 14;
    error = true;
    theForm.st.focus();
  } 

//name Check
if (trim(theForm.na.value) == "")
  {
    errorText = "Rechnungsadresse: "+messg2;
	err_fld = 14;
    error = true;
    theForm.na.focus();
  } 

//vorname Check
  if (trim(theForm.vo.value) == "")
  {
    errorText = "Rechnungsadresse: "+messg1;
	err_fld = 14;
    error = true;
    theForm.vo.focus();
  }
  
    //Anrede Check
  if (theForm.an.options[0].selected==true)
  {
    errorText = "Rechnungsadresse: "+messg0;
	err_fld = 14;
    error = true;
    theForm.an.focus();
  }   

}	
		

//ne Check

	if((theForm.we.checked) == true){ 
		var std = theForm.std3.value+theForm.std2.value+theForm.std1.value;
		
		if(std < theForm.heute.value){ 
		errorText = 'Neueinzug Datum liegt in der Vergangenheit!';
		err_fld = 13;
		error = true;
		theForm.std1.focus(); 
		}		
		if(trim(theForm.std3.value) == "" || isNaN(theForm.std3.value) == true || trim(theForm.std3.value) < 2008)
		{
		errorText = messg13b;
		err_fld = 13;
		error = true;
		theForm.std3.focus();
  		}	
		
		if(trim(theForm.std2.value) == "" || isNaN(theForm.std2.value) == true || trim(theForm.std2.value) > 12)
		{
		errorText = messg13a;
		err_fld = 13;
		error = true;
		theForm.std2.focus();
  		}	
		
		if(trim(theForm.std1.value) == "" || isNaN(theForm.std1.value) == true || trim(theForm.std1.value) > 31)
		{
		errorText = messg13;
		err_fld = 13;
		error = true;
		theForm.std1.focus();
  		}	
		
	}
	else {
		//Bisheriger VS Check
		if (trim(theForm.stz.value) == "" || isNaN(theForm.stz.value) )
  		{
		errorText = messg13h;
		err_fld = 13;
		error = true;
		theForm.stz.focus();
  		}
		if (trim(theForm.stn.value) == "" || isNaN(theForm.stn.value))
  		{
		errorText = messg13g;
		err_fld = 13;
		error = true;
		theForm.stn.focus();
  		}
		if (trim(theForm.stb.value) == "")
  		{
		errorText = messg13f;
		err_fld = 13;
		error = true;
		theForm.stb.focus();
  		}
	}
	
	
        //go-inhaber Check
if (trim(theForm.go.value) == "")
  {
    errorText = messg19;
    err_fld = 19;
    error = true;
    theForm.go.focus();
  } 
    
	
//gd3 Check
	if (trim(theForm.gd3.value) == "" || isNaN(theForm.gd3.value) == true || (theForm.gd3.value).length < 4 || trim(theForm.gd3.value) > 2000 || trim(theForm.gd3.value) < 1900)
		{
		errorText = messg12;
		err_fld = 12;
		error = true;
		theForm.gd3.focus();
  		}

//gd2 Check
	if (trim(theForm.gd2.value) == "" || isNaN(theForm.gd2.value) == true || trim(theForm.gd2.value) > 12 || trim(theForm.gd2.value) < 1)
		{
		errorText = messg11;
		err_fld = 11;
		error = true;
		theForm.gd2.focus();
  		}

//gd1 Check
	if (trim(theForm.gd1.value) == "" || isNaN(theForm.gd1.value) == true || trim(theForm.gd1.value) > 31 || trim(theForm.gd1.value) < 1)
		{
		errorText = messg10;
		err_fld = 10;
		error = true;
		theForm.gd1.focus();
  		}

//telefon Check
  if (trim(theForm.te2.value) == "" || isNaN(theForm.te2.value) == true || theForm.te2.value.length < 4)
  {
    errorText = messg9;
	err_fld = 9;
    error = true;
    theForm.te2.focus();
  }
    
//vorwahl Check
  if (trim(theForm.te1.value) == "" || isNaN(theForm.te1.value) == true || theForm.te1.value.length < 3)
  {
    errorText = messg8;
	err_fld = 8;
    error = true;
    theForm.te1.focus();
  }
  
//EMail Check
  if (!isEmail(theForm.em.value))
  {
    errorText = messg7;
	err_fld = 7;
    error = true;
    theForm.em.focus();
  }
  
//Ort Check
  if (trim(theForm.aor.value) == "")
  {
    errorText = messg6;
	err_fld = 6;
    error = true;
    theForm.aor.focus();
  }
  
//apl Check
if (trim(theForm.apl.value) == "" || isNaN(theForm.apl.value) == true || (theForm.apl.value).length < 5)
	{
	errorText = messg5;
	err_fld = 5;
	error = true;
	theForm.apl.focus();
	}

//nr Check
  if (trim(theForm.anu.value) == "")
  {
    errorText = messg4;
	err_fld = 4;
    error = true;
    theForm.anu.focus();
  } 
    
//strasse Check
  if (trim(theForm.ast.value) == "")
  {
    errorText = messg3;
	err_fld = 3;
    error = true;
    theForm.ast.focus();
  } 

//name Check
if (trim(theForm.ana.value) == "")
  {
    errorText = messg2;
	err_fld = 2;
    error = true;
    theForm.ana.focus();
  } 

//vorname Check
  if (trim(theForm.avo.value) == "")
  {
    errorText = messg1;
	err_fld = 1;
    error = true;
	//theForm.avo.style['background-color'] = '#ffcc99';
    theForm.avo.focus();
  }   
  
  //Anrede Check
  if (theForm.aan.options[0].selected==true)
  {
    errorText = messg0;
	err_fld = 0;
    error = true;
    theForm.aan.focus();
  }   

    
// ****************************************
// ausgabe / submit
	if (error) { 
		//alert(errorText); 
		show_hide_err('err_text_'+err_fld,19)
		identify('err_text_'+err_fld).innerHTML = errorText;
		}
	else{
		theForm.status.value = id; 
		theForm.n.value = n; 		
		theForm.submit();
		}
}



function clear_NE(tf){
	theForm = identify(tf);
	if ((theForm.we.checked) == true){
		theForm.stb.value = '';
		theForm.stn.value = '';
		theForm.stz.value = '';
  		}	
	if ((theForm.we.checked) == false){
		theForm.std1.value = '';
		theForm.std2.value = '';
		theForm.std3.value = '';
  		}		
	}




		
// unbenutzt / löschen **************************************************************
// **********************************************************************************
function loadandclose(lacfile)
{
	parent.opener.document.location=lacfile;
	parent.close();
}


//  used!!! Öffnen eines Fensters mit Scroll-Leiste //
function winpop(site,stitle) 
	{
    if(document.layers || document.getElementById )
    	{
        newwin = window.open(site,stitle,"width=1020,height=700,screeny=50,screenx=50,status,scrollbars,resizable=YES");
        newwin.focus();
        }
	else
    	{
        newwin = window.open(site,stitle,"width=1020,height=700,top=50,left=50,status,scrollbars,resizable=YES");
		newwin.focus();
        newwin.close();
        if(newwin.closed != true)
        	{
            newwin.close();
            }
            newwin = window.open(site,stitle,"width=1020,height=700,top=50,left=50,status,scrollbars,resizable=YES");
        }
	}

function winpop_x(site,stitle){
	newwin = window.open(site,stitle,"width=1020,height=700,screeny=50,screenx=50,status,scrollbars,resizable=YES");
    newwin.focus();
}
	





