// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
function resizeText(multiplier) {
  if (document.body.style.fontSize == "") {
    document.body.style.fontSize = "1.0em";
  }
  document.body.style.fontSize = parseFloat(document.body.style.fontSize) + (multiplier * 0.2) + "em";
}

function generic_addEventListener(objet, evenement, fonction) {
  if (!objet.addEventListener && objet.attachEvent)
    objet.attachEvent('on' + evenement, fonction)
  else
    objet.addEventListener(evenement, fonction, false)
}

//Attache des evenements a certain elements des pop ups lors de la publication
function initialize(){
    //Chauffage
    element = $('heating_gaz_heating');
    if(element != null){
        generic_addEventListener(element, 'click', function (){
            my_div = $('div_heating_type')
            Effect.toggle(my_div,'blind');
        })
    }

    //Lands
    element = $('estate_appearance_genres_attributes_8_legend')
    if(element != null){
        generic_addEventListener(element, 'change', function (){
            my_div = $('div_constructible')
            if(element.value == 16){
                Effect.toggle(my_div,'blind');
            }else{
                my_div.hide()
            }
        })
    }
}

generic_addEventListener(window, 'load', initialize)

function interrogate(what) {
    var output = '';
    for (var i in what)
        output += i+ '\n';
    alert(output);
}

function show_mini_spinner() {
    $('mini_spinner').toggle();
}

function show_tooltip(e, id) {
	$(id).style.position = "fixed";
	$(id).style.left = (e.clientX + 5) + "px";
	$(id).style.top = (e.clientY + 5) + "px";
	$(id).style.display = "block";
	$(id).style.zIndex = 5000;
}

function hide_tooltip(e, id) {
	$(id).style.display = "none";
}

function switch_account(where){
    if(where == "new_account"){
        $$('.exist_account').each(function(elem){ elem.toggle();}); $$('.new_account').each(function(elem){ elem.toggle();});
        $('user_session_email').value = ''
        $('user_session_password').value = ''
    }else{
        $$('.exist_account').each(function(elem){ elem.toggle();}); $$('.new_account').each(function(elem){ elem.toggle();});
        $('user_email').value = ''
        $('user_password').value = ''
        $('user_password_confirmation').value = ''
        $('user_phone').value = ''
        $$('.selectAll').each(function(e){
            if(e.type == "checkbox"){
                e.checked = false;
            }
        });
        $$('.multi_select').each(function(e){ e.checked = false; });
        $$('.multiSelect').each(function(e){ e.value = '-'; });

        $('user_pro').checked = false;
        $('user_web').value = ''
        $('user_logo').value = ''
        $('logo_pro').hide();
    }

}


function hide_or_show_go_button(action, ad_id){
    if(action == 'show'){
        //$('btn_submit').src = "/images/layout/go_button_white.gif";
        //$('btn_submit').disabled = false;
        $('my_button_go').innerHTML = "<input type='image' id='btn_submit' src='/images/layout/go_button_white.gif'>"
        //$('choosen_data').innerHTML = ""
        //$('choosen_data').innerHTML = ""
    }else{
        //$('btn_submit').src = "/images/layout/go_button_white.gif";
        //$('btn_submit').disabled = true;
        $('my_button_go').innerHTML = "<a href='#' class='button_white' onclick=\"if($F('my_city') == ''){$('where').className='red'; $('where').scrollTo(); return false; }; new Ajax.Request('/cities/cities_list/"+ ad_id +"', {asynchronous:true, evalScripts:true, parameters:'my_city=' + $F('my_city') + '&country=' + $('ad_country').value + '&amp;authenticity_token=' + encodeURIComponent('2LLWL9cg1qxqPWZBqNuQ4lSvUK8xSLyfwljkc2VEr2I=')}); return false;\"></a>"
        $('choosen_data').innerHTML = ''
        $('city').value = ''
    }
}