// ------------------------------------------------------------ popUpWindow

var popUpWin = 0;

function popUpWindow(URLStr, left, top, width, height)
{
	if(popUpWin)
		if(!popUpWin.closed) popUpWin.close();
	popUpWin = open(URLStr, 'popUpWin', 'toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function popUpEmailWindow(URLStr, left, top, width, height)
{
	if(popUpWin)
		if(!popUpWin.closed) popUpWin.close();
	popUpWin = open(URLStr, 'popUpEmailWin', 'toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function popUpRedirectWindow(URLStr, left, top, width, height)
{
	popUpWin = open(URLStr, '_blank', 'toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

// ------------------------------------------------------------ popUpWindowEmpty

var popUpWinEmpty = 0;

function popUpWindowEmpty(URLStr, left, top, width, height)
{
	if(popUpWinEmpty)
	{
		if(!popUpWinEmpty.closed) popUpWinEmpty.close();
	}
	
	popUpWinEmpty = open(URLStr, 'popUpWinEmpty', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

// ------------------------------------------------------------ changeText

function changeText(pre, num, str) 
{
	var theID = document.getElementById(pre + num);
	
	//if (s == '')
	//	s = " ";
		
	theID.childNodes[0].data = str;
}

// ------------------------------------------------------------ clearButton

function clearButton(str)
{
	//document.all.view.innerText = '';
	document.getElementById(str).innerText = '';
	//var um = document.getElementById("view");
	//um.childNodes[0].removeChild[0];
}

// ------------------------------------------------------------ checkForm

var wert = "";

function checkForm()
{
	var countErrors = 0;
	var errorMessage = 'Bitte füllen Sie alle mit einem Stern ( * ) gekennzeichneten Felder aus: ';
	var status = true;
	
	Felder = new Array("firma", "strasse", "hausnummer", "plz", "ort", "kontakt", "telefonvorwahl", "telefon");
  
  	for (var i = 0; i < Felder.length; i++)
  	{
  		/*
  		// working - but very uncool!
  		var txfield = ""; 
  		if (Felder[i] == "firma")
  			txfield = document.address.firma;
  		else if (Felder[i] == "strasse")
  			txfield = document.address.strasse;
  		else if (Felder[i] == "hausnummer")
  			txfield = document.address.hausnummer;
  		*/
  		
  		var txfield = document.getElementById(Felder[i]).value;
  		//alert(Felder[i] + ': ' + txfield);
  		
		if ((txfield == '') || (txfield.length < 1))
		{
			document.getElementById(Felder[i]+'Post').childNodes[0].data = '*';
			errorMessage += ' - ' + Felder[i];
			//document.address.firma.focus();
			countErrors++;
			status = false;
		}
		else
		{
			document.getElementById(Felder[i]+'Post').childNodes[0].data = '';
		}
  		
  	}
  
  	/*
	var tfield = document.address.firma;
	if ((tfield.value == "") || (tfield.value.length < 3))
	{
		document.getElementById('firmaPost').childNodes[0].data = '*';
		document.address.firma.focus();
		countErrors++;
		status = false;
	}
	else
	{
		document.getElementById('firmaPost').childNodes[0].data = '';
	}
	
	
	tfield = document.address.strasse;
	if ((tfield.value == "") || (tfield.value.length < 3))
	{
		document.getElementById('strassePost').childNodes[0].data = '*';
		//document.address.strasse.focus();
		countErrors++;
		status = false;
	}
	else
	{
		document.getElementById('strassePost').childNodes[0].data = '';
	}
	
	tfield = document.address.hausnummer;
	if ((tfield.value == "") || (tfield.value.length < 1))
	{
		document.getElementById('hausnummerPost').childNodes[0].data = '*';
		//document.address.hausnummer.focus();
		countErrors++;
		status = false;
	}
	else
	{
		document.getElementById('hausnummerPost').childNodes[0].data = '';
	}
	
	tfield = document.address.plz;
	if ((tfield.value == "") || (tfield.value.length < 3))
	{
		document.getElementById('plzPost').childNodes[0].data = '*';
		//document.address.plz.focus();
		countErrors++;
		status = false;
	}
	else
	{
		document.getElementById('plzPost').childNodes[0].data = '';
	}

	tfield = document.address.ort;
	if ((tfield.value == "") || (tfield.value.length < 3))
	{
		document.getElementById('ortPost').childNodes[0].data = '*';
		//document.address.ort.focus();
		countErrors++;
		status = false;
	}
	else
	{
		document.getElementById('ortPost').childNodes[0].data = '';
	}

	tfield = document.address.telefonvorwahl;
	if ((tfield.value == "") || (tfield.value.length < 3))
	{
		document.getElementById('telefonvorwahlPost').childNodes[0].data = '*';
		//document.address.telefonvorwahl.focus();
		countErrors++;
		status = false;
	}
	else
	{
		document.getElementById('telefonvorwahlPost').childNodes[0].data = '';
	}
	*/

	var chkZ = 1;
	for (i = 0; i < document.address.telefonvorwahl.value.length; ++i)
	{	
		if (document.address.telefonvorwahl.value.charAt(i) < "0" ||
			document.address.telefonvorwahl.value.charAt(i) > "9")
			chkZ = -1;
	}
	if (chkZ == -1)
	{
		errorMessage += ' Die Telefonvorwahl ist keine Zahl!';
		//document.address.telefonvorwahl.focus();
		countErrors++;
		status = false;
	}

	/*
	tfield = document.address.telefon;
	if ((tfield.value == "") || (tfield.value.length < 3))
	{
		document.getElementById('telefonPost').childNodes[0].data = '*';
		//document.address.telefon.focus();
		countErrors++;
		status = false;
	}
	else
	{
		document.getElementById('telefonPost').childNodes[0].data = '';
	}
	*/
	
	var mail1 = document.address.email1;
	if ((mail1.value == "") || (mail1.value.length < 3))
	{
		document.getElementById('email1Post').childNodes[0].data = '*';
		//document.address.email1.focus();
		countErrors++;
		status = false;
	}
	else
	{
		document.getElementById('email1Post').childNodes[0].data = '';
	}
	
	
	if (document.address.email1.value.indexOf("@") == -1) {
		errorMessage += ' Die erste E-Mail Adresse ist nicht gültig!';
		//document.address.email1.focus();
		countErrors++;
		status = false;
	}
	
	var mail2 = document.address.email2;
	if ((mail2.value == "") || (mail2.value.length < 3))
	{
		document.getElementById('email2Post').childNodes[0].data = '*';
		//document.address.email2.focus();
		countErrors++;
		status = false;
	}
	else
	{
		document.getElementById('email2Post').childNodes[0].data = '';
	}
	
	if (document.address.email2.value.indexOf("@") == -1) {
		errorMessage += ' Die zweite E-Mail Adresse ist nicht gültig!';
		//document.address.email2.focus();
		countErrors++;
		status = false;
	}	

	
	if (mail1.value != mail2.value)
		document.getElementById('error2').childNodes[0].data = ' Die angegebenen E-mail Adressen stimmen nicht überein!';
	else	
		document.getElementById('error2').childNodes[0].data = '';
	
	// ------------------------------------------------------------ 	
	// unset the message when no error !
	
	if (status == true)
		document.getElementById('error').childNodes[0].data = '';	
	else
		document.getElementById('error').childNodes[0].data = errorMessage;
		
	// ------------------------------------------------------------ 
	// this works without the branchSelect() function

	// var bfield = document.address.branche;
	var bfield = document.address.branche.selectedIndex;  
	// if ((bfield.value == ""))
	if ((bfield < 0))
	{
		document.getElementById('error3').childNodes[0].data = 'Bitte wählen Sie eine Branche aus!';
		//document.address. .value = "Bitte eintragen!";
		//document.address.search_branch.focus();
		status = false;
	}
	else
		document.getElementById('error3').childNodes[0].data = '';
		
	//bfield = document.address.anrede;
	//bfield = document.address.anrede.options[document.address.anrede.selectedIndex].value;
	bfield = document.address.anrede.selectedIndex;
	
	if (bfield == 0)
	{
		document.getElementById('anredePost').childNodes[0].data = '*';
		//document.address.search_branch.focus();
		status = false;
	}
	else
		document.getElementById('anredePost').childNodes[0].data = '';

	/*
	// this works with the branchSelect() function
	if (wert == "")
 	{
 		document.getElementById('error2').childNodes[0].data = 'Bitte waehlen Sie eine Branche aus!';
 		status = false;
	}
	else
		document.getElementById('error2').childNodes[0].data = '';
	*/

	return status;
}

// ------------------------------------------------------------ branchChanged
// <input type="select" .... onchange="branchChanged(this);" 

function branchChanged (select)
{
	wert = select.options[select.options.selectedIndex].value;
    
	if (wert == "")
	{
		select.form.reset();
		return false;
  	}
}

function checkFormAGB()
{
	var countErrors = 0;
	var errorMessage = 'Sie muessen die AGB akzeptieren!';
	var status = true;
  		
  	var txfield = document.getElementById('agb_accept').checked;
  		
	if ((txfield == false))
	{
		countErrors++;
		status = false;
	}
	
	if (status == true)
		document.getElementById('agb_error').childNodes[0].data = '';	
	else
		document.getElementById('agb_error').childNodes[0].data = errorMessage;

	return status;
}

function resize()
{
	 window.resizeTo(1024,768);
}
