function CalcFinalPrice(type)
{
	var gp = parseInt($('#price').val());
	if( typeof(document.travelling_booking.insurance) != "undefined")
	{
		for (var i=0; i < document.travelling_booking.insurance.length; i++)
			if (document.travelling_booking.insurance[i].checked)
				var insurance = document.travelling_booking.insurance[i].value;
		insurance = parseInt(insurance.substring(insurance.indexOf(':')+1,insurance.indexOf('p.P.')));
	}
	insurance = (isNaN(insurance)) ? 0 : insurance;
	if( typeof(document.travelling_booking.rentalcar) != "undefined")
	{
		for (var i=0; i < document.travelling_booking.rentalcar.length; i++)
			if (document.travelling_booking.rentalcar[i].checked)
				var rentalcar = document.travelling_booking.rentalcar[i].value;
		rentalcar = parseInt(rentalcar.substring(rentalcar.indexOf(',')+1));
	}
	rentalcar = (isNaN(rentalcar)) ? 0 : rentalcar;
	gp = gp + insurance+ rentalcar;
	$('#final_price').text(gp+' €');
	$('#gpreis').val(gp);
}
function SetObjectFilterLocation(fw)
{
	$('#home_form_overlay').css('display','block');
	$('#loading2').css('display','block');
	$('#fw').val(fw);
	xajax_SetLocation(fw);
	return true;
}
function str_replace(search, replace, subject) 
{
	return subject.split(search).join(replace);
}
function FilterCity()
{
	var sel = document.getElementById('OFI');
	var ofi_start = window.location.href.indexOf('&OFI=');
	var ofi = sel.options[sel.selectedIndex].value;
	if(ofi_start>0)
		url = window.location.href.substring(0, ofi_start) + "&OFI="+ ofi;
	else
		url = window.location.href + "&OFI="+ ofi;
	window.location.href = url.replace(/&?POS=\d+/, "");
	
}
function CheckAvailability(param,id){
	//$('#loading').css('display','block');
	$('#availability').css('display','none');
	$('#travelling_dates_overlay').height($('#travelling_dates').height());
	$('#travelling_dates_overlay').width($('#travelling_dates').width());
	$('#travelling_dates_overlay').css('display','block');
	$('#loading3').css('display','block');
	xajax_CheckAvailability(param,id);
	return true;
}
function SetTravellingSearchFields()
{
	var sf = document.getElementById('sf').options[document.getElementById('sf').selectedIndex].value;
	if(sf == '1')
	{
		$('#travelling_search_hotel').css('display', 'none');
		$('#travelling_search_hotel input').attr('disabled', 'disabled');
		$('#travelling_search_flight').css('display', 'block');
		$('#travelling_search_flight input').attr('disabled', '');
	}
	else if(sf == '3')
	{
		$('#travelling_search_hotel').css('display', 'block');
		$('#travelling_search_hotel input').attr('disabled', '');
		$('#travelling_search_flight').css('display', 'none');
		$('#travelling_search_flight input').attr('disabled', 'disabled');
	}
	else
	{
		$('#travelling_search_hotel').css('display', 'block');
		$('#travelling_search_hotel input').attr('disabled', '');
		$('#travelling_search_flight').css('display', 'block');
		$('#travelling_search_flight input').attr('disabled', '');
	}
}
function CalcTripDays(){
	xajax_CalcTripDays($('#stime').val(),$('#etime').val());
	return true;
}
function SetTripFilterCategories(val){
	var val = $(val).val();
	xajax_SetTripFilterCategories(val);
	return true;
}
function SetTripFilterTimes(){
	xajax_SetTripFilterTimes($('#start').val(),$('#end').val());
	return true;
}
function CalcTripPrice(stamp){
	xajax_CalcTripPrice($('#adult_'+stamp).val(),$('#child_'+stamp).val(),$('#day_'+stamp).val(), stamp);
	return true;
}
function SubmitTripRequest(stamp){
	$('#stamp').val(stamp);
	document.trips_details.submit();
	return true;
}

function selectVisumCountry(){
	var sel = document.getElementById('visum_country');
	var test = sel.options[sel.selectedIndex].value;
	window.location.href = '/visum/' + test + '/';
}

function ShowRateStar(text,value,stars){
	img_src0 = "/images/content/mstar1.png";
	img_src1 = "/images/content/mstar2.png";

	if (value>0)
		for(i = 1; i <= stars; i++)
		{
			try {
				document.getElementById("vote"+text+"_"+i).src = (value>=i) ? img_src0 : img_src1;
		    } catch (failed){ }
		}
			
	else
		for(i = 1; i <= stars; i++)
		{
			try {
				document.getElementById("vote"+text+"_"+i).src = (votes[text]>=i) ? img_src0 : img_src1;
		    } catch (failed){ }
		}
 	return false;
}

function openpopup(file, winwidth, winheight){
	wdh = window.open(file, 'popup', 'width=' + winwidth + ',height=' + winheight + ',scrollbars');
 	wdh.focus();	
}

function swapBox( id, htbase ){
	var box_image = document.getElementById('swapbox_image_' + id);
	var plus = htbase + 'images/content/plus.jpg';
	var minus = htbase + 'images/content/minus.jpg';
	box_image.src = (box_image.src == plus) ? minus : plus;
	box_image.alt = (box_image.alt == 'plus') ? 'minus' : 'plus';
	$('#swapbox_' + id).slideToggle(800, null);
	//box.style.display = (box.style.display == 'none') ? 'block' : 'none';
	return true;
}
am = true;

function correctPNG(){
	for(var i=0; i<document.images.length; i++){
  		var img = document.images[i]
  		var imgName = img.src.toUpperCase()
		var is_opera  = (navigator.userAgent.toLowerCase().indexOf("opera") != -1);
  		if (imgName.substring(imgName.length-3, imgName.length) == "PNG"  && !is_opera){
    		var imgID = (img.id) ? "id='" + img.id + "' " : ""
    		var imgClass = (img.className) ? "class='" + img.className + "' " : ""
    		var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
    		var imgStyle = "display:inline-block;" + img.style.cssText
    		if (img.align == "left") imgStyle = "float:left;" + imgStyle
    		if (img.align == "right") imgStyle = "float:right;" + imgStyle
    		if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle      
    		var strNewHTML = "<span " + imgID + imgClass + imgTitle
    			+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
     			+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
    			+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
    		img.outerHTML = strNewHTML
    		i = i-1
     	}
   }
}

allchecked = false;
function SelectAll (){
    if (allchecked){
        var items = document.getElementsByTagName("input")
        for(i = 0; i < items.length; i++){
			if (items[i].id.substring (0, 6) == "check_"){
				items[i].checked = false;
          	}
        }
        allchecked = false;
    }
    else{
    	var items = document.getElementsByTagName("input")
        for(i = 0; i < items.length; i++){
            if (items[i].id.substring (0, 6) == "check_"){
				items[i].checked = true;
            }
        }
        allchecked = true;
    }
}

function SelectAllRights ( sub ){
	if (allcheckedRights){
        var items = document.getElementsByTagName("input")
        for(i = 0; i < items.length; i++){
			if (items[i].id.substring (0, 6) == sub){
				items[i].checked = false;
          	}
        }
        allcheckedRights = false;
    }
    else{
        var items = document.getElementsByTagName("input")
        for(i = 0; i < items.length; i++){
            if (items[i].id.substring (0, 6) == sub){
				items[i].checked = true;
            }
        }
        allcheckedRights = true;
    }
}

function changeFlag(country,country_img,path){
	select_value = document.getElementById(country).options[document.getElementById(country).selectedIndex].title
 	document.getElementById(country_img).src = (select_value) ? path + select_value : path + 'af.gif';
}

function ShowItem(banner, counter, active, max){
	for(i=1;i<=max;i++)
	{
		b = banner + '_' + i;
		c = counter + '_' + i;
		if(active ==  i)
		{
			document.getElementById(b).style.display =  'block';
			document.getElementById(c).style.backgroundImage = 'url(/images/design/'+i+'_on.png)'
		}
		else
		{
			document.getElementById(b).style.display =  'none';
			document.getElementById(c).style.backgroundImage = 'url(/images/design/'+i+'_out.png)'
		}
	}
}
var active = null;
function SwapMenu(span, max){
  for(i=1;i<=max;i++)
  	try {
		if(i==span){
			if(document.getElementById('m_' + span).style.display == 'none')
				document.getElementById('m_' + span).style.display =  'inline';
			}else
	      		document.getElementById('m_' + i).style.display = 'none';
    } catch (failed){ }
}

function SwapBoxes1(span, max){
  for(i=1;i<=max;i++)
  		try {
	  		if(i==span){
				if(document.getElementById('page1_' + span).style.display == 'none')
			  		document.getElementById('page1_' + span).style.display =  'inline';
			} else
	      		document.getElementById('page1_' + i).style.display = 'none';
    	} 
    	catch (failed){ }
}
function SwapBoxes2(span, max){
	for(i=1;i<=max;i++)
  		try {
	  		if(i==span){
				if(document.getElementById('page2_' + span).style.display == 'none')
			  	document.getElementById('page2_' + span).style.display =  'inline';
			}else
	      		document.getElementById('page2_' + i).style.display = 'none';
    	} 
    	catch (failed){ }
}

function UnswapMenu(max){
  for(i=1;i<max;i++)
  	try {
		document.getElementById('m_' + i).style.display = 'none';
	} catch (failed){ 
    }
}
function switchTextbox(){
  	txt = document.getElementById('value_simple');
  	txtarea = document.getElementById('value_multiple');
	multiple = document.getElementById('multiple');
	td_value_simple = document.getElementById('div_value_simple');
	td_value_multiple = document.getElementById('div_value_multiple');
  	if(multiple.checked){
  		txtarea.disabled = false;
	  	txtarea.style.display = 'block';
	  	txtarea.value = txt.value;
	  	td_value_multiple.style.display = 'block';
	  	txt.disabled = true;
	  	txt.style.display = 'none';
	  	td_value_simple.style.display = 'none';
  	}
  	if(!multiple.checked){
	  	txt.disabled = false;
	  	txt.style.display = 'block';
	  	txt.value = txtarea.value;
	  	td_value_simple.style.display = 'block';
	  	txtarea.disabled = true;
	  	txtarea.style.display = 'none';
	  	td_value_multiple.style.display = 'none';
  	}
}

function switchBoardOptions(){
	category = document.getElementById('category_id').value;
	board_options = document.getElementById('board_options');
  	if(category == '0')
  		board_options.style.display = 'none';
  	else
  		board_options.style.display = 'block';
}

function FileSelect( elem ){
	select = document.getElementById( elem + '_change' ).value;
	external = document.getElementById( elem + '_external' );
	upload = document.getElementById( elem );
  	external.style.display = (select == 'external') ? 'block' : 'none';
  	upload.style.display = (select == 'external') ? 'none' : 'block';
}

function swap( span ){
	var obj = document.getElementById(span);
	if(obj){
		var displayType = ( obj.style.display == 'none' ) ? 'block' : 'none';
		obj.style.display = displayType;
	}
}

var maxWidth = 400; 
function scaleImage(im) { 
  if (typeof im.naturalWidth == 'undefined') {
	im.naturalWidth = im.width;
	if (im.naturalWidth > maxWidth) { 
  		im.width = maxWidth; 
	} 
    	im.style.maxWidth = im.naturalWidth + 'px'; 
    	im.className = 'resized'; 
    	im.title = 'Full Screen';  
    	im.style.borderWidth = '0px'; 

  }
  if (im.naturalWidth > maxWidth) { 
	if (im.naturalWidth > maxWidth) { 
  		im.width = maxWidth; 
	} 
    im.style.maxWidth = im.naturalWidth + 'px'; 
    im.className = 'resized'; 
    im.title = 'Full Screen'; 
    im.style.borderWidth = '0px'; 
    // im.onclick = unscaleImage; 
  } 
} 

function unscaleImage() { 
  if (this.width == maxWidth) { 
    this.width = this.naturalWidth; 
    this.style.borderWidth = '0px'; 
    this.title = 'Small Size'; 
  } else { 
    this.width = maxWidth; 
    this.style.borderWidth = '2px'; 
    this.title = 'Full Size'; 
  } 
} 
