//JavaScript Document

var o_towar_preview_ajax = createXmlHttpRequestObject();

var o_towar_preview_div = null;

var o_towar_preview_cache = new Object();

var towar_preview_send_id = -1;

function towar_preview( towar_id ){

    if ( towar_preview_send_id == towar_id ){
        alert('Proszę czekać!');
        return;
    }
    

    if( o_towar_preview_ajax ){
        try{
          showTlo();
          
          showLoading();
          
          towar_preview_send_id = towar_id;
          
            towar_preview_send_id
          if ( typeof(o_towar_preview_cache[towar_id]) == 'undefined' ){
              server_connect( o_towar_preview_ajax, MAIN_URL + '/action_towar/mode_show/ajax_1/ID_' + towar_id, towar_preview_response );
          }else{
              towar_preview_show( o_towar_preview_cache[towar_id] );
          }
        }catch(e){
            window.location = MAIN_URL + '?action=towar&mode=show&ID=' + towar_id;
        }
    }else{
        //w przciwnym razie zmieniamy adres przegladarki
        window.location = MAIN_URL + '?action=towar&mode=show&ID=' + towar_id ;
    }
}

function towar_preview_response( o_txt ){
    
    if ( !o_towar_preview_div ){
        o_towar_preview_div = document.getElementById('towar_preview_div');
        
        if ( !o_towar_preview_div ){
            //utworz
            towar_preview_crete_div();
        }
    }

    o_towar_preview_cache[towar_preview_send_id] = o_txt;

    towar_preview_send_id = -1;
    
    towar_preview_show(o_txt);
}


function towar_preview_show( html ){
    hideLoading();
    
    o_towar_preview_div.style.width = 600;
    o_towar_preview_div.style.visibility = 'visible';
    
    o_towar_preview_div.innerHTML = html;
    
    o_towar_preview_div.onclick = function(){}
    
    center_both_obj(o_towar_preview_div);
    
    add_event('click', o_tlo_div, hideTowarPreview, true);
}


function hideTowarPreview(){
    remove_event('click', o_tlo_div);
    
    hideTlo();

    o_towar_preview_div.style.visibility = 'hidden';
    o_towar_preview_div.style.display = 'none';
    o_towar_preview_div.style.top = 0;
    o_towar_preview_div.style.left = 0;
    
}

function towar_preview_crete_div(){

    o_towar_preview_div = document.createElement('div');

    o_towar_preview_div.className = 'preview';
    o_towar_preview_div.style.zIndex = 510;
    o_towar_preview_div.style.position = "absolute";
    o_towar_preview_div.style.display  = "none";
    o_towar_preview_div.style.visibility = "hidden";

    o_towar_preview_div.style.backgroundColor = '#ffffff';
    o_towar_preview_div.style.border = 'solid 1px #A6A6A6';

    o_towar_preview_div.style.width = 600;

    document.body.appendChild( o_towar_preview_div );

}

