function send_buy_function(product_id, product_name, price, units, article_id, article_text_id, in_stock) {
    if (window.parent.buy_product!=undefined){
        window.parent.buy_product(product_id, product_name, price, units, article_id, article_text_id, in_stock);
    } else {
        alert("Failed to register. Please, contact administrator.")
    }
}

var copynum=0;
function changeMain(div_name,get_go,get_param1,get_param2,get_param3,get_param4,get_param5) {
    var xwidth = $("#"+div_name).width();
    var xheight = $("#"+div_name).height();
    var offset = $("#"+div_name).offset();
    var xleft = offset.left;
    var xtop = offset.top;

    $("#"+div_name).attr('disabled','true');

    copynum++;
    if (copynum>9) copynum=1;
    
    var div_loading="#main_page_loader"+copynum;

    $(div_loading).css("position","absolute");
    $(div_loading).css("border","0px none");
    $(div_loading).css("display","block");
    $(div_loading).css("z-index","20000");

    $(div_loading).css("margin-top",$("#"+div_name).css("margin-top"));
    $(div_loading).css("margin-right",$("#"+div_name).css("margin-right"));
    $(div_loading).css("margin-bottom",$("#"+div_name).css("margin-bottom"));
    $(div_loading).css("margin-left",$("#"+div_name).css("margin-left"));
    
    $(div_loading).css("padding-top",$("#"+div_name).css("padding-top"));
    $(div_loading).css("padding-right",$("#"+div_name).css("padding-right"));
    $(div_loading).css("padding-bottom",$("#"+div_name).css("padding-bottom"));
    $(div_loading).css("padding-left",$("#"+div_name).css("padding-left"));
    
    $(div_loading).css("border-top",$("#"+div_name).css("border-top"));
    $(div_loading).css("border-right",$("#"+div_name).css("border-right"));
    $(div_loading).css("border-bottom",$("#"+div_name).css("border-bottom"));
    $(div_loading).css("border-left",$("#"+div_name).css("border-left"));

    $(div_loading).width(xwidth);
    $(div_loading).height(xheight);	
    $(div_loading).css("top",xtop);
    $(div_loading).css("left",xleft);

    $(div_loading).fadeTo("fast", 0.60);
    
    get_go = get_go || '';
    get_param1 = get_param1 || '';
    get_param2 = get_param2 || '';
    get_param3 = get_param3 || '';
    get_param4 = get_param4 || '';
    get_param5 = get_param5 || '';
    
    if (get_go!='') {
        var content_show = $(this).attr("title"); //retrieve title of link so we can compare with php file 
        
        $.ajax({
            method: "get",url: "actions.php",data: "ajax=true&go="+get_go+"&get_param1="+get_param1+"&get_param2="+get_param2+"&get_param3="+get_param3+"&get_param4="+get_param4+"&get_param5="+get_param5+"&lasturl="+lasturl,
            cache: false,
            beforeSend: function(){$(div_loading).show();}, //show loading just when link is clicked 
            complete: function(){ $(div_loading).hide();}, //stop showing loading when the process is complete 
            success: function(html){ //so, if data is retrieved, store it in html 
                $("#"+div_name).show(); //animation 
                
                $(div_loading).hide();
                $("#"+div_name).html(html); //show the html inside .content div 
                $("#"+div_name).removeAttr("disabled").focus();
                apply_simpletip();
            }
        });
    } else {
        $(div_loading).fadeOut("slow");
    }
}

function ajax(div_name, get_go, get_param1, get_param2, get_param3, get_param4, get_param5, async) {
    $("#"+div_name).attr('disabled','true');

    get_go = get_go || '';
    get_param1 = get_param1 || '';
    get_param2 = get_param2 || '';
    get_param3 = get_param3 || '';
    get_param4 = get_param4 || '';
    get_param5 = get_param5 || '';
    if (async == undefined)
    	async = true;
    	
    if (get_go!=''){
        var content_show = $(this).attr("title"); //retrieve title of link so we can compare with php file 
        
        $.ajax({
            method: "get",url: "actions.php",data: "ajax=true&go="+get_go+"&get_param1="+get_param1+"&get_param2="+get_param2+"&get_param3="+get_param3+"&get_param4="+get_param4+"&get_param5="+get_param5+"&lasturl="+lasturl,
            cache: false,
            async: async,
            beforeSend: function(){}, //show loading just when link is clicked 
            complete: function(){}, //stop showing loading when the process is complete 
            success: function(html){ //so, if data is retrieved, store it in html 
                $("#"+div_name).show(); //animation 
                $("#"+div_name).html(html); //show the html inside .content div 
                $("#"+div_name).removeAttr("disabled").focus();
                apply_simpletip();
            }
        });
    }
}	

function select_page(div_name,get_go,get,sort_dir,table_rnd,page) {
    changeMain(div_name, get_go, get, '', table_rnd, page);
}	

function select_sortmenu(table_rnd, cell_id, sort_dir, div_name, get_go, get_param1) {
    //making all TH - passive
    var tmp_th = document.getElementById('sortmenu_'+table_rnd).getElementsByTagName('th');
    
    for(var i = 0; i < tmp_th.length; i++) {
        //taking from all A arrows
        var tmp_but = document.getElementById('sortmenu_'+table_rnd).getElementsByTagName("th")[i].getElementsByTagName('a');
    
        
        if (tmp_th[i].className=='sort_active'){
            tmp_th[i].className='sort_passive';
        }
            
        if (tmp_th[i].className=='sort_passive'){
            for(var i2 = 0; i2 < tmp_but.length; i2++) {
                
                tmp_but[i2].style.backgroundImage='url(design/updown/updown_small.gif)';
                tmp_but[i2].title=sort_dir;

                if (sort_dir=="ASC"){
                        tmp_but[i2].onmouseover=function onmouseover(event) {this.style.backgroundImage='url(design/updown/updown_ASC_trans.gif)'};
                        tmp_but[i2].onmouseout=function onmouseout(event) {this.style.backgroundImage='url(design/updown/updown_small.gif)'};
                        tmp_but[i2].onmousedown=function onmousedown(event) {this.style.backgroundImage='url(design/updown/updown_ASC_solid.gif)'};
                } else {
                        tmp_but[i2].onmouseover=function onmouseover(event) {this.style.backgroundImage='url(design/updown/updown_DESC_trans.gif)'};
                        tmp_but[i2].onmouseout=function onmouseout(event) {this.style.backgroundImage='url(design/updown/updown_small.gif)'}; 
                        tmp_but[i2].onmousedown=function onmousedown(event) {this.style.backgroundImage='url(design/updown/updown_DESC_solid.gif)'}; 
                }
            }
        }
    }
    
    document.getElementById('sortmenu_'+table_rnd+'_'+cell_id+'').className='sort_active';
    
    //making button hoverable
    var sel_but = document.getElementById('sortmenu_'+table_rnd+'_'+cell_id+'_a');	

    if (sort_dir=="ASC") {
        sel_but.style.backgroundImage="url(design/updown/updown_ASC_solid.gif)"; 
        sel_but.onmouseover=function onmouseover(event) {this.style.backgroundImage='url(design/updown/updown_DESC_ASC_solid.gif)'};
        sel_but.onmouseout=function onmouseout(event) {this.style.backgroundImage='url(design/updown/updown_ASC_solid.gif)'};
        sel_but.onmousedown=function onmousedown(event) {this.style.backgroundImage='url(design/updown/updown_DESC_solid.gif)'};
    } else {
        sel_but.style.backgroundImage="url(design/updown/updown_DESC_solid.gif)";
        sel_but.onmouseover=function onmouseover(event) {this.style.backgroundImage='url(design/updown/updown_ASC_DESC_solid.gif)'};				
        sel_but.onmouseout=function onmouseout(event) {this.style.backgroundImage='url(design/updown/updown_DESC_solid.gif)'}; 
        sel_but.onmousedown=function onmousedown(event) {this.style.backgroundImage='url(design/updown/updown_ASC_solid.gif)'}; 
    }
    
    //making this active box title different from others....
    if (sort_dir=="ASC"){
        sort_dir_new='DESC';
        sel_but.title=sort_dir_new;
    } else {
        sort_dir_new='ASC';
        sel_but.title=sort_dir_new;
    }

    changeMain(div_name,get_go,get_param1,sort_dir,table_rnd);
}

function select_sortmenu_bms(table_rnd, cell_id, sort_dir, div_name, get_go, get_param1, get_param2) {
    var tmp_th = document.getElementById('sortmenu_'+table_rnd).getElementsByTagName('th');

    for (var i = 0; i < tmp_th.length; i++) {
        //taking from all A arrows
        var tmp_but = document.getElementById('sortmenu_'+table_rnd).getElementsByTagName("th")[i].getElementsByTagName('a');

        if (tmp_th[i].className=='sort_active'){
            tmp_th[i].className='sort_passive';
        }

        if (tmp_th[i].className=='sort_passive'){
            for(var i2 = 0; i2 < tmp_but.length; i2++) {
                
                tmp_but[i2].style.backgroundImage='url(design/updown/updown_small.gif)';
                tmp_but[i2].title=sort_dir;

                if (sort_dir=="ASC"){
                    tmp_but[i2].onmouseover=function onmouseover(event) {this.style.backgroundImage='url(design/updown/updown_ASC_trans.gif)'};
                    tmp_but[i2].onmouseout=function onmouseout(event) {this.style.backgroundImage='url(design/updown/updown_small.gif)'};
                    tmp_but[i2].onmousedown=function onmousedown(event) {this.style.backgroundImage='url(design/updown/updown_ASC_solid.gif)'};
                } else {
                    tmp_but[i2].onmouseover=function onmouseover(event) {this.style.backgroundImage='url(design/updown/updown_DESC_trans.gif)'};
                    tmp_but[i2].onmouseout=function onmouseout(event) {this.style.backgroundImage='url(design/updown/updown_small.gif)'}; 
                    tmp_but[i2].onmousedown=function onmousedown(event) {this.style.backgroundImage='url(design/updown/updown_DESC_solid.gif)'}; 
                }
            }
        }
    }
    
    document.getElementById('sortmenu_'+table_rnd+'['+cell_id+']').className='sort_active';
    
    var sel_but = document.getElementById('sortmenu_'+table_rnd+'['+cell_id+'_a]');	

    if (sort_dir=="ASC") {
        sel_but.style.backgroundImage="url(design/updown/updown_ASC_solid.gif)"; 
        sel_but.onmouseover=function onmouseover(event) {this.style.backgroundImage='url(design/updown/updown_DESC_ASC_solid.gif)'};
        sel_but.onmouseout=function onmouseout(event) {this.style.backgroundImage='url(design/updown/updown_ASC_solid.gif)'};
        sel_but.onmousedown=function onmousedown(event) {this.style.backgroundImage='url(design/updown/updown_DESC_solid.gif)'};
    } else {
        sel_but.style.backgroundImage="url(design/updown/updown_DESC_solid.gif)";
        sel_but.onmouseover=function onmouseover(event) {this.style.backgroundImage='url(design/updown/updown_ASC_DESC_solid.gif)'};				
        sel_but.onmouseout=function onmouseout(event) {this.style.backgroundImage='url(design/updown/updown_DESC_solid.gif)'}; 
        sel_but.onmousedown=function onmousedown(event) {this.style.backgroundImage='url(design/updown/updown_ASC_solid.gif)'}; 
    }
    
    //making this active box title different from others....
    if (sort_dir=="ASC") {
        sort_dir_new='DESC';
        sel_but.title=sort_dir_new;
    } else {
        sort_dir_new='ASC';
        sel_but.title=sort_dir_new;
    }

    changeMain(div_name, get_go, get_param1, get_param2, sort_dir, table_rnd);
}

/* TODO: Remove if this really isnt needed? */
/*
function transfer_from_fck_to_input(f) {
    // Loop through all the elements in the form
    for(var i = 0; i < f.elements.length; i++) {
        if (f.elements[i]!=undefined){
            var e = f.elements[i];
            
            if ((e.type=="hidden") && (e.style.display=="none") && (e.name==e.id)){
                //esli eto tot samij tipa
                
                if ($(f).find("input[id='"+e.name+"'][name='"+e.name+"']").val()!=undefined){
                    if ($(f).find("input[id='"+e.name+"___Config']").val()!=undefined){
                
                        if (FCKeditorAPI.GetInstance(e.name)!=undefined){
                            var content=FCKeditorAPI.GetInstance(e.name).GetHTML();
                            $(f).find("input[id='"+e.name+"'][name='"+e.name+"']").val(content)
                        } else {
                            alert("FCKEditor fails: "+e.name);
                        }
                    }
                }
            }
        }
    }
}
*/

function SetAjaxForm(this_form,response_div) {
    turn_on_reload_parent();	

    var options = { 
        target:        '#'+response_div,   // target element(s) to be updated with server response 
        beforeSubmit:  function(){
            $('#'+response_div).show();
            $('#'+response_div).removeClass('error_report');
            $('#'+response_div).addClass('loading_report');
            $('#'+response_div).html("&nbsp;");
            $('#'+response_div).height(50);
            
        },  // pre-submit callback 
        success:       function(){
            $('#'+response_div).removeClass('loading_report');
            $('#'+response_div).addClass('error_report');
            $('#'+response_div).height('auto');
            $('#'+response_div).show();
        }
    }; 				
    
    /*
    transfer_from_fck_to_input(this_form);				
    */
    $(this_form).ajaxSubmit(options);
    
    return false;
}

