 // str_normal.split(str_find)).join(str_replace)


function correctPhoneNo(strNo)
{
	if(strNo.charAt(0)=="0")
	{
		if(strNo.charAt(1)=="0")
		{
			return strNo;	
		}
		else
		{
			var result="+49-" + strNo.slice(1);
			return result;
		}
	}
	else return strNo;



}

function getAgency()
{
	var selection=document.Kontakt.Land.options[document.Kontakt.Land.options.selectedIndex].text;
//	alert('selection: ' + selection);
	
	if (selection==document.Kontakt.DefSelection.value) // if the user has seleted nothing, nothing must happen
	{
		return;
	}


	var arrayAgencies=buildArray("AddressAgencies");


//alert(arrayAgencies.join("~"));

	var resultArray = new Array();
	var j = 0;

	for (var i=0; i<arrayAgencies.length; i++)
// step through the array to find the element to which the selected country corresponds
	{
		var elementArray=arrayAgencies[i].split("|");  // every element holds a delimited string, which msut be splitted to an array
		if (elementArray[0]==selection)  // if the selected country is the same as the currently processed element, the element is written to a result array.
		{
			strTemp = arrayAgencies[i].split("~").join("@");  // JKo 04.08.02: replace the ~ chars by the @ chars
			resultArray[j] = strTemp;    // JKo 04.08.02: Write the temporary variable back.
		//	resultArray[j] = arrayAgencies[i];   // JKo 04.08.02: original line
			j++;
			
		}	
	}

	writeAgencyToNewWindow(document.Kontakt.TAgency.value, resultArray, document.Kontakt.LPhone.value, document.Kontakt.LFax.value);
}

  // function writes the address of the agency to a new browser-window, which is opened by the function
function writeAgencyToNewWindow(windowName,wArray, labelPhone, labelFax) 
{
	var hoehe=240 + (120 * (wArray.length - 1));  // if there is more than one agency the window must be higher.

	newWindow=window.open("","newWindow", "width=320,height=" + hoehe + ",menubar=yes,resizable=yes");
	newWindow.document.open();

	newWindow.document.writeln('<html><head><title>'+windowName+'</title>');
	checkBrowser(newWindow);
	newWindow.document.writeln('</head>');

	newWindow.document.writeln('<body bgcolor="#FFFFFF">');

	newWindow.document.writeln('<table border="0" cellpadding="0" cellspacing="0">');
	
	for (i=0; i<wArray.length; i++)
	{
		elementArray=wArray[i].split("|");  // country is written only once!
		if (i==0)
		{
			newWindow.document.writeln('<tr><td colspan="3" class="medium"><b>' + elementArray[0] + '</b><br>&nbsp;</td></tr>');
		}
		if (elementArray[2]!="")   // maybe there is no special string. The string is necessary e.g. if there are two agencies per country
		{
			newWindow.document.writeln('<tr><td colspan="3" class="medium">' + elementArray[2] + '<br>&nbsp;</td></tr>');
		}
		
		newWindow.document.writeln('<tr><td colspan="3" class="medium">' + elementArray[3] + '</td></tr>');
		newWindow.document.write('<tr><td width="10%" class="medium" valign="top">' + labelPhone + '</td><td>&nbsp;</td>');
		newWindow.document.writeln('<td class="medium">' + elementArray[4] + '</td></tr>');
		newWindow.document.write('<tr><td class="medium" valign="top">' + labelFax + '</td><td>&nbsp;</td>');
		newWindow.document.writeln('<td class="medium">' + elementArray[5] + '</td></tr>');
		newWindow.document.writeln('<td colspan="3" class="medium">' + elementArray[6] + '</td></tr>');
		if (elementArray[7]!="")  // maybe there is no email-address
		{
			newWindow.document.writeln('<tr><td colspan="3" class="medium"><a href="mailto:' + elementArray[7] + '">' + elementArray[7] + '</a></td></tr>');
		}
		if (elementArray[8]!="")  // maybe there is no internet-address
		{

			newWindow.document.writeln('<tr><td colspan="3" class="medium"><A HREF=javascript:void(window.resizeTo(640,480));void(window.location.href="' + elementArray[8] + '")>' + elementArray[8] + '<a/></td></tr>');
			
		}
		newWindow.document.writeln('<tr><td>&nbsp;</td></tr>');
	}

	newWindow.document.write('</table>');

	newWindow.document.writeln('</body></html>');
	newWindow.document.close();
	newWindow.focus();  
}


function buildArray(fieldName) {
// get the content of the field in a variable and explode it to an array
var temp="document.Kontakt." + fieldName + ".value";
var content=eval(temp);
return content.split("$");
}


function checkBrowser(nWindow)
{
var win=navigator.appVersion.indexOf("Win");

	if (win > -1)
	{
		nWindow.document.write("<LINK REL=\"stylesheet\" HREF=\"/WGAPublisher/wltde/css/TextFormat_Win_NN\" TYPE=\"text/css\">");
	}
	else
	{
 		nWindow.document.write("<LINK REL=\"stylesheet\" HREF=\"/WGAPublisher/wltde/css/TextFormat_Mac_NN\" TYPE=\"text/css\">");
	}
}


