var g_oldhrefs = new Array();
var g_cd_end = 0;

function _sbmap( type, lang )
{
	if (document.sf)
	{
		var x = ((screen.width  - 25) - 735) / 2;
		var y = ((screen.height - 34) - 640) / 2;
		var win = window.open( '/map/' + lang + '/' + type + '.html','s_map',
			'width='		+ 735 + ',' +
			'height='		+ 640 + ',' +
			'left='			+ x + ',' +
			'top='			+ y + ',' +
			'statusbar=0'   +     ',' +
			'resizable=0'	+	  ',' +
			'toolbar=0'		+     ',' +
			'scrollbars=1'	+     ',' +
			'location=0'	+     ',' +
			'dependant=1'	+     ',' +
			'menubar=0'
		);
		if (win && win.open && !win.closed)
		{
			win.opener = self;
			win.focus();
		}
	}
}
function _repinput( type )
{
	if (!document.sf)
	{
		alert( "Your browser doesn't support this feature." );
		return;
	}
	document.sf.rep.value = type;
	document.sf.submit();
}
function _repinputML( type, num )
{
	$(type+num+'title').innerHTML = '';
	fn = type+'t['+num+']';
	fn2 = type+'t'+num;

	if (typeof $(fn) != "undefined") temp = $(fn).value;
	else temp = '';
	
	field = '<input type="text" id="'+fn2+'" class="fromtotxt" value="'+temp+'" name="'+fn+'"/>';
	$(type+num+'container').innerHTML = field;
	var as = new bsn.AutoSuggest(fn2, options);
}
function _constate( p,state,c1,c2 )
{
	if (!p) return;
	c1 = c1 ? c1 : 'enabled';
	c2 = c2 ? c2 : 'disabled';
	p.className = state ? c1 : c2;
	p.disabled  = state ? 0 : 1;
}
function _tagstate( tag,name,state,c1,c2 )
{
	if (!tag || !name) return;
	c1 = c1 ? c1 : 'enabled';
	c2 = c2 ? c2 : 'disabled';
	var p = document.getElementsByTagName( tag )[ name ];
	if (p) p.className = state ? c1 : c2;
}
function _substate( state )
{
	_constate( document.sf.sub,state,'button','disabled' );
}
function _ancstate( name,state )
{
	if (!name) return;
	var a = document.getElementsByTagName('a')[ name ];
	if (a && state) {
		if (g_oldhrefs[ name ]) a.href = g_oldhrefs[ name ];
		g_oldhrefs[ name ] = '';
		a.className = '';
		if (a.style) a.style.cursor = document.all ? 'hand' : 'pointer';
	} else {
		g_oldhrefs[ name ] = a.href;
		a.href = "javascript://";
		a.className = 'disabled';
		if (a.style) a.style.cursor = 'default';
	}
}
function _getrb( obj )
{
	for (var i=0; i<obj.length; i++)
	{
		if (obj[ i ].checked) return obj[ i ].value;
	}
    return null;
}
function _setrb( obj,value )
{
	for (var i=0; i<what.length; i++)
	{
		if (obj[ i ].value == value) {
			obj[ i ].checked;
			return true;
		}
	}
	return false;
}
function unmix(saltynuts)
{
	document.write("<");
	document.write("inp");
	document.write("ut ");
	document.write("type=");
	document.write("\"hid");
	document.write("den\"");
	document.write(" nam");
	document.write("e=\"saltyn");
	document.write("uts\" va");
	document.write("lue=\"");
	document.write(saltynuts);
	document.write("\"");
	document.write(">");
}
function checkstudent(which)
{
	if (which == null) which = 'students';
	
	if ($('students') == null) return true;
	
	if ($('students').value > 0 && which == 'students')
	{
		$('studentscb').value = 'on';
		$('adults').value = 0;
		$('children').value = 0;
		$('infants').value = 0;
		
		for (i=1; i<=4; i++)
		{
			if (i <= $('students').value) $('st_age_'+i).show();
			else  $('st_age_'+i).hide();
		}
		new Effect.Appear('studentages');
		showiframe(390, 182, 270, 137);
	}
	if ($('students').value == 0 && which == 'students')
	{
		$('studentscb').value = 'off';
		$('adults').value = 1;
	}
	if ($('adults').value > 0 && which == 'adults')
	{
		$('studentscb').value = 'off';
		$('students').value = 0;
	}
	if ($('children').value > 0 && which == 'children')
	{
		$('studentscb').value = 'off';
		$('students').value = 0;
		$('adults').value = 1;
	}
	if ($('infants').value > 0 && which == 'infants')
	{
		$('studentscb').value = 'off';
		$('students').value = 0;
		$('adults').value = $('infants').value;
	}
	
	if ($('studentages').style.display != 'none' && $('students').value == 0)
	{
		new Effect.Fade('studentages');
		hideiframe();
	}
}
function changeRooms (what)
{
	if (what.id == 'lessRooms') $('roomsdd').value--;
	else $('roomsdd').value++;
	
	r = $('roomsdd').value

	if (r == 4) $('moreRooms').hide();
	if (r == 3) $('moreRooms').show();
	if (r == 1) $('lessRooms').hide();
	if (r == 2) $('lessRooms').show();

	if (what.id == 'moreRooms' && r == 3) showOverlay('roomwarning');
	showrooms();
}
function showrooms()
{
	for (i=1; i<=4; i++)
	{
		var room = $("room"+i);
		if (i <= $('roomsdd').value)
		{
			if (room.style.display == '') continue;
			new Effect.Appear(room, {duration: 0.5});
		}
		else
		{
			if (room.style.display == 'none') continue;
			new Effect.Squish(room, {duration: 0.5});
		}
	}
}
function checkrooms(whichroom)
{
	for (i=1; i<=4; i++)
	{
		if (whichroom != 0 && whichroom != i) continue;
	
		typeIndex = $('roomtype'+i).selectedIndex;
		types = $('roomtype'+i).options[typeIndex].value;
		
		if 		(types == 'si') ad = 1;
		else if (types == 'do') ad = 2;
		else if (types == 'tw') ad = 2;
		else if (types == 'tr') ad = 3;
		else if (types == 'qu') ad = 4;
		else if (types == 'su') ad = 2;
	
		while (1)
		{			
			if ($('adults'+i).length == 0) break;
			$('adults'+i).options[$('adults'+i).length - 1] = null;
		}
		
		for (j=1; j<=4; j++)
		{
			if (j > ad) break;
					
			//temp = (lang == 'de') ? ' Erwachsene' : ' Adults';
			//if(lang == 'de' && j == 1) temp = ' Erwachsener';
			//if(lang == 'de' && j > 1) temp = ' Erwachsene';
			//if(lang == 'en' && j == 1) temp = ' Adult';
			//if(lang == 'en' && j > 1) temp = ' Adults';
			if(j == 1) temp = ' ' + JSLanguage['flugsuche']['adultsSingle']; // added by ms
			if(j > 1)  temp = ' ' + JSLanguage['flugsuche']['adults']; // added by ms
			
			var entry = new Option(j+temp, j, false, true);			
			
			$('adults'+i).options[$('adults'+i).length] = entry;
		}
	}
}
function showchildage(which)
{
	childrenIndex = $('children'+which).selectedIndex;
	numchildren   = $('children'+which).options[childrenIndex].value;
	
	if (numchildren == 0) $('ca'+which+'div').hide();
	//else $('ca'+which+'div').show();
	else showOverlay('ca'+which+'div');

	for (i=0; i<2; i++)
	{
		e = $('ca'+which+'container'+(i+1));
		if ((i+1) <= numchildren) e.show();
		else e.hide();
	}
}
function checkform()
{
	window.setTimeout ("showrooms()", 50);
	window.setTimeout ("checkrooms(0)", 60);
}

function _checklegs()
{
	for (i=1; i<=4; i++)
	{
		if (i <= numlegs2) $('legcontainer'+i).show();
		else $('legcontainer'+i).hide();
	}
	
	// do not handle less than two flights
	if (numlegs2 == 2) $('lessflights').hide();
	else  $('lessflights').show();
	
	// do not handle more than four flights
	if (numlegs2 == 4) $('moreflights').hide();
	else  $('moreflights').show();
	
	// set the hidden field in the form to the correct leg value
	$('numlegs').value = numlegs2;
}
function _fillmldep (num)
{
	if (num < 4) $('dept'+(num+1)).value = $('arrt'+num).value;
}

function _changeproduct (id, product, searchurl)
{
	location.href = searchurl;
}
