function filterEvents(view_all){
    
    var url = '/admin/events/filter_list/';
    
    if(view_all != 'view_all'){
        var ds = '-';
        var start_date  = Form.Element.getValue('EventStartDateYear')+ds+Form.Element.getValue('EventStartDateMonth')+ds+Form.Element.getValue('EventStartDateDay');
        var end_date    = Form.Element.getValue('EventEndDateYear')+ds+Form.Element.getValue('EventEndDateMonth')+ds+Form.Element.getValue('EventEndDateDay');
        
        var data = 'start_date='+start_date+'&end_date='+end_date;
        new Ajax.Updater('filter_list', url,{postBody:data});
    }else{
        new Ajax.Updater('filter_list', url);
    }
}

/*function gallery_delete_image(id){
    url = "/admin/delete_gallery_image/"+id+"/";//alert(url);
    new Ajax.Request(url, {method: 'post',onComplete: function(){}});
}*/

function page_header_delete_image(id){
    var cont = confirm("Are you sure that you to permanently delete this image?");
    if(cont){
        document.body.style.cursor = "wait";
        var url = "/admin/pages/delete_page_header_image/"+id+"/";
        var myAjax = new Ajax.Request(url, {
            method: 'post', 
            parameters: '',
            onSuccess: function(originalRequest){
                $('image-container-' + id.toString()).style.display='none';
                document.body.style.cursor = "default";
            },
            onFailure: function(){}
        });
    }
}

function gallery_category_delete_image(id){
    var cont = confirm("Are you sure that you to permanently delete this image?");
    if(cont){
        document.body.style.cursor = "wait";
        var url = "/admin/gallery_categories/delete_gallery_image/"+id+"/";
        var myAjax = new Ajax.Request(url, {
            method: 'post', 
            parameters: '',
            onSuccess: function(originalRequest){
                $('image-container-' + id.toString()).style.display='none';
                document.body.style.cursor = "default";
            },
            onFailure: function(){}
        });
    }
}
function gallery_delete_image(id){
    var cont = confirm("Are you sure that you to permanently delete this image?");
    if(cont){
        document.body.style.cursor = "wait";
        var url = "/admin/places/delete_gallery_image/"+id+"/";
        var myAjax = new Ajax.Request(url, {
            method: 'post', 
            parameters: '',
            onSuccess: function(originalRequest){
                $('image-container-' + id.toString()).style.display='none';
                document.body.style.cursor = "default";
            },
            onFailure: function(){}
        });
    }
}

function updateAttributes(place_id,controller){
    var url = "/admin/"+controller+"/update_attributes/"+place_id+"/";
    var myAjax = new Ajax.Request(url, {
        method: 'post', 
        parameters: Form.serialize($('place_attributes'))
    });
}

function updatePaymentOptions(place_id){
    var url = "/admin/accommodation/update_payment_attributes/"+place_id+"/";
    var myAjax = new Ajax.Request(url, {
        method: 'post', 
        parameters: Form.serialize($('payment_options')),
        onSuccess: function(originalRequest){
            $('tmp').innerHTML = originalRequest.responseText;
        },
        onFailure: function(){}
    });
}

function hideFlash() {
    if (document.getElementById('flash')) {
        new Effect.Fade('flash', {'duration': 5});
    }
}

function showPlaceDescriptionForm(){
    $('place-description-view-div').style.display = 'none';
    $('place-description-form-div').style.display = 'block';
}

function savePlaceTypeDescription(text, place_type, controller_name){
    var url = "/admin/"+controller_name+"/save_place_type_description/";
        var myAjax = new Ajax.Request(url, {
            method: 'post', 
            parameters: 'description='+text+'&place_type='+place_type,
            onSuccess: function(originalRequest){
                $('place_description_text').innerHTML = text;
                $('place-description-view-div').style.display = 'block';
                $('place-description-form-div').style.display = 'none';
            },
            onFailure: function(){}
        });
}

function loadImage(image_id){
    var url = "/galleries/load_image/"+image_id;
   // var test = new Ajax.Updater(url, 'active-image');
    var test = new Ajax.Request(url, {
            method: 'post', 
            onSuccess: function(transport){
                $('active-image').innerHTML = transport.responseText;
            },
            onFailure: function(){}
    });//alert("after");*/
    return false;
}

function checkDatesVisibility(){
    var val = $('event_type_id').options[$('event_type_id').selectedIndex].value;
    if(val==2 || val==1){
        $('start-date').style.display="block";
        $('end-date').style.display="block";
    }else{
        $('start-date').style.display="none";
        $('end-date').style.display="none";
    }
}

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);