/**
 * @author groening
 */

function writeHtmlEntities( str )
{
	retval = str;
	/* FIXME
	retval = str.replace( /ä/, "&auml;");
	retval = retval.replace( /ü/, "&uuml;" );
	retval = retval.replace( /ö/, "&ouml;" );
	retval = retval.replace( /Ä/, "&Auml;");
	retval = retval.replace( /Ü/, "&Uuml;" );
	retval = retval.replace( /Ö/, "&Ouml;" );
	retval = retval.replace( /ß/, "&szlig;" );
	*/
		
	return retval;
}


function setWindowTitle(box){
	title = 'Ferienhaus & Ferienwohnung {LANDNAME} buchen bei tui-ferienhaus.de';
	headlineOne = 'Suche Ferienhaus & Ferienwohnung{LANDNAME}';
	headlineTwo = 'Reiseziele{LANDNAME}';
	metadesc = 'Ferienaus & Ferienwohnung{LANDNAME} bequem online buchen bei tui-ferienhaus.de. Über 15.000 Ferienwohnungen & Ferienhäuser in 27 Ländern';
	
	if( document.getElementById('anlageart') && document.getElementById('anlageart').value == 'fh')
	{
		if (box.selectedIndex > 0) {
		
			landname = writeHtmlEntities(box[box.selectedIndex].text.replace(/\(.*\)/, ''));
			document.title = title.replace(/{LANDNAME}/, 'in ' + landname);
			if (document.getElementById('searchHeadlineOne')) {
				textlen = document.getElementById('searchHeadlineOne').firstChild.nodeValue.length;
				text = headlineOne.replace(/{LANDNAME}/, ' in ' + landname);
				document.getElementById('searchHeadlineOne').firstChild.replaceData(0, textlen, text);
			}
			if (document.getElementById('searchHeadlineTwo')) {
				textlen = document.getElementById('searchHeadlineTwo').firstChild.nodeValue.length;
				text = headlineTwo.replace(/{LANDNAME}/, ' in ' + landname);
				document.getElementById('searchHeadlineTwo').firstChild.replaceData(0, textlen, text);
			}
			var metas = document.getElementsByTagName('meta');
			var i = 0;
			for (i = 0; i < metas.length; i++) {
				if (metas[i].name == 'description') {
					metas[i].content = metadesc.replace(/{LANDNAME}/, ' in ' + landname);
					break;
				}
			}
			
		}
		else {
			document.title = title.replace(/{LANDNAME}/, '');
			if (document.getElementById('searchHeadlineOne')) {
				textlen = document.getElementById('searchHeadlineOne').firstChild.nodeValue.length;
				text = headlineOne.replace(/{LANDNAME}/, '');
				document.getElementById('searchHeadlineOne').firstChild.replaceData(0, textlen, text);
			}
			if (document.getElementById('searchHeadlineTwo')) {
				textlen = document.getElementById('searchHeadlineTwo').firstChild.nodeValue.length;
				text = headlineTwo.replace(/{LANDNAME}/, '');
				document.getElementById('searchHeadlineTwo').firstChild.replaceData(0, textlen, text);
			}
			var metas = document.getElementsByTagName('meta');
			var i = 0;
			for (i = 0; i < metas.length; i++) {
				if (metas[i].name == 'description') {
					metas[i].content = metadesc.replace(/{LANDNAME}/, '');
					break;
				}
			}
			/*
		 var countryobjects = document.getElementById( 'countryobjects' );
		 if( countryobjects )
		 {
		 do
		 {
		 knoten = countryobjects.firstChild;
		 if(knoten)
		 {
		 document.getElementById( 'countryobjects').removeChild(knoten);
		 }
		 }while( knoten );
		 }
		 */
		}
	}
}


function setWindowTitle2(box, formname){

	title = 'Ferienhaus und Ferienwohnung buchen bei tui-ferienhaus.de';
	headlineOne = 'Suche Ferienhaus & Ferienwohnung{LANDNAME}';
	headlineTwo = 'Reiseziele{LANDNAME}';
	metadesc = 'Ferienaus & Ferienwohnung{LANDNAME} bequem online buchen bei tui-ferienhaus.de. Über 15.000 Ferienwohnungen & Ferienhäuser in 27 Ländern';
	if (box.selectedIndex > 0) {
	
		landname = '';
		regionname = '';
		gebietname = '';
		ortname = '';
		
		
		if (box.name == 'searchdata[region_kz]') {
		
			landname = writeHtmlEntities(document.forms[formname].elements['searchdata[land_kz]'].options[document.forms[formname].elements['searchdata[land_kz]'].selectedIndex].text.replace(/\(.*\)/, ''));
			regionname = writeHtmlEntities(box[box.selectedIndex].text.replace(/\(.*\)/, ''));
			document.title = 'Ferienhaus ' + regionname + ' Ferienwohnung ' + landname + ' buchen bei tui-ferienhaus.de';
			
		}
		
		if (box.name == 'searchdata[area_kz]') {
		
			landname = writeHtmlEntities(document.forms[formname].elements['searchdata[land_kz]'].options[document.forms[formname].elements['searchdata[land_kz]'].selectedIndex].text.replace(/\(.*\)/, ''));
			regionname = writeHtmlEntities(document.forms[formname].elements['searchdata[region_kz]'].options[document.forms[formname].elements['searchdata[region_kz]'].selectedIndex].text.replace(/\(.*\)/, ''));
			gebietname = writeHtmlEntities(box[box.selectedIndex].text.replace(/\(.*\)/, ''));
			document.title = 'Ferienhaus ' + gebietname + ' Ferienwohnung ' + regionname + ' ' + landname + ' buchen bei tui-ferienhaus.de';
			
		}
		
		if (box.name == 'searchdata[ort_kz]') {
		
			landname = writeHtmlEntities(document.forms[formname].elements['searchdata[land_kz]'].options[document.forms[formname].elements['searchdata[land_kz]'].selectedIndex].text.replace(/\(.*\)/, ''));
			regionname = writeHtmlEntities(document.forms[formname].elements['searchdata[region_kz]'].options[document.forms[formname].elements['searchdata[region_kz]'].selectedIndex].text.replace(/\(.*\)/, ''));
			gebietname = writeHtmlEntities(document.forms[formname].elements['searchdata[area_kz]'].options[document.forms[formname].elements['searchdata[area_kz]'].selectedIndex].text.replace(/\(.*\)/, ''));
			ortname = writeHtmlEntities(box[box.selectedIndex].text.replace(/\(.*\)/, ''));
			document.title = 'Ferienhaus ' + ortname + ' Ferienwohnung ' + gebietname + ' ' + regionname + ' ' + landname + ' buchen bei tui-ferienhaus.de';
			
		}
		
		//landname = writeHtmlEntities(box[box.selectedIndex].text.replace( /\(.*\)/, ''));
		//document.title = title.replace( /{LANDNAME}/, 'in ' + landname);
		if (document.getElementById('searchHeadlineOne')) {
			textlen = document.getElementById('searchHeadlineOne').firstChild.nodeValue.length;
			text = headlineOne.replace(/{LANDNAME}/, ' in ' + landname);
			document.getElementById('searchHeadlineOne').firstChild.replaceData(0, textlen, text);
		}
		if (document.getElementById('searchHeadlineTwo')) {
			textlen = document.getElementById('searchHeadlineTwo').firstChild.nodeValue.length;
			text = headlineTwo.replace(/{LANDNAME}/, ' in ' + landname);
			document.getElementById('searchHeadlineTwo').firstChild.replaceData(0, textlen, text);
		}
		var metas = document.getElementsByTagName('meta');
		var i = 0;
		for (i = 0; i < metas.length; i++) {
			if (metas[i].name == 'description') {
				metas[i].content = metadesc.replace(/{LANDNAME}/, ' in ' + landname);
				break;
			}
		}
	}
	else {
		document.title = title.replace(/{LANDNAME}/, '');
		if (document.getElementById('searchHeadlineOne')) {
			textlen = document.getElementById('searchHeadlineOne').firstChild.nodeValue.length;
			text = headlineOne.replace(/{LANDNAME}/, '');
			document.getElementById('searchHeadlineOne').firstChild.replaceData(0, textlen, text);
		}
		if (document.getElementById('searchHeadlineTwo')) {
			textlen = document.getElementById('searchHeadlineTwo').firstChild.nodeValue.length;
			text = headlineTwo.replace(/{LANDNAME}/, '');
			document.getElementById('searchHeadlineTwo').firstChild.replaceData(0, textlen, text);
		}
		var metas = document.getElementsByTagName('meta');
		var i = 0;
		for (i = 0; i < metas.length; i++) {
			if (metas[i].name == 'description') {
				metas[i].content = metadesc.replace(/{LANDNAME}/, '');
				break;
			}
		}
		
		/*
		 var countryobjects = document.getElementById('countryobjects');
		 if (countryobjects) {
		 do {
		 knoten = countryobjects.firstChild;
		 if (knoten) {
		 document.getElementById('countryobjects').removeChild(knoten);
		 }
		 }
		 while (knoten);
		 }
		 */
	}
}
