

function displayViaLocation(next_advertise_step)
{
    document.getElementById('frmAdvertise').next_advertise_step.value = next_advertise_step;
    document.getElementById('frmAdvertise').new_via_location.value = 1;
    document.getElementById('frmAdvertise').submit();
}

function fillAddressFields(country,zip,city,city2,street,houseno,lat,lng,status)
{
    document.getElementById('space_location_zip_code').value = zip;
    document.getElementById('space_location_city'    ).value = city;
    document.getElementById('space_location_city2'   ).value = city2;
    document.getElementById('space_location_street'  ).value = street;
    document.getElementById('space_location_houseno' ).value = houseno;
    document.getElementById('space_location_lat'     ).value = lat;
    document.getElementById('space_location_lng'     ).value = lng;
    document.getElementById('space_location_status'  ).value = status;
    document.getElementById('space_location_country' ).value = country;
}

function onCommoditiesTypeChange(commodities_type,visible_commodities_type)
{
    if (commodities_type==visible_commodities_type){
        bVisible = true;
    } else {
        bVisible = false;
    }

    allDivs = document.getElementsByTagName("div");
    for (i = 0; i < allDivs.length; i++){
        el = allDivs[i];

		/*
        if (el.className=='locations_radius'){
		      if (commodities_type == "demand")
		      {
		        el.style.display = 'block';
		      }
		      else
		      {
		        el.style.display = 'none';
		      }
        }
        */
    }

    allInputs = document.getElementsByTagName("select");
    for (i = 0; i < allInputs.length; i++){
        el = allInputs[i];

        if (el.className=='locations_radius'){
            if (!bVisible){
                el.value = 0;
            }
        }
    }

}

function onBodyLoadMobile()
{
    if (document.getElementById('frmAdvertise')){
        if (document.getElementById('frmAdvertise').commodities_type){
            if (document.getElementById('frmAdvertise').commodities_type[0].checked){
                onCommoditiesTypeChange('supply','supply');
            } else {
                onCommoditiesTypeChange('demand','supply');
            }
        }
    }
}

function onBodyLoadSpace()
{
    if (document.getElementById('frmAdvertise')){
        if (document.getElementById('frmAdvertise').commodities_type){
            if (document.getElementById('frmAdvertise').commodities_type[0].checked){
                onCommoditiesTypeChange('supply','demand');
            } else {
                onCommoditiesTypeChange('demand','demand');
            }
        }
    }
}


function checkAll(checkbox_name,isChecked)
{
    checkboxes = document.getElementsByTagName('input');

    for (var i=0;i<checkboxes.length;i++){
        var e = checkboxes[i];
        if((e.checked!=isChecked)&&(e.type=="checkbox") && e.name.indexOf(checkbox_name)>=0){
            e.click();
        }
    }
}

function confirmDelete(commodities_id)
{
    if (confirm("Möchten Sie wirklich löschen?")){
        document.getElementById('action').value =
            'CommodityDelete';
        document.getElementById('commodities_id').value =
            commodities_id;

        document.getElementById('frmCommodities').submit();

    }
}

function confirmDeleteHint(url)
{
	if (confirm("Möchten Sie den Tipp wirklich löschen?")){
		window.location=url;
	}
}

function toggleCommoditiesActive(commodities_id, sender)
{
     document.getElementById('action').value =
            'CommoditySet'+(sender.className=='active' ? 'Inactive' : 'Active');
     document.getElementById('commodities_id').value =
            commodities_id;
     sender.className = (sender.className=='active' ? 'inactive' : 'active');

     // Timeout because of IE-problems:
     window.setTimeout("document.getElementById('frmCommodities').submit()", 10);
}

function toggleRecurrentActive(frequencies_recurrents_id)
{
    alert('todo');
}

function copyCommodity(commodities_id)
{
     document.getElementById('action').value =
            'CommodityCopy';
     document.getElementById('commodities_id').value =
            commodities_id;

     document.getElementById('frmCommodities').submit();
}

function editCommodity(commodities_id)
{
     document.getElementById('action').value =
            'CommodityEdit';
     document.getElementById('commodities_id').value =
            commodities_id;

     document.getElementById('frmCommodities').submit();
}

function displayRecurrents(commodities_id)
{
    alert('todo');
}




