/**
 * @package Module VM Universal Search PRO for Joomla! 1.5
 * @version $Id: mod_universal_search.js 599 2010-03-20 23:26:33Z you $
 * @author Arkadiy, Kirill
 * @copyright (C) 2010 - WebInteractions
 * @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
**/

var url = 'http://'+location.hostname;
jQuery.noConflict();
  
//при изменении категории меняем все остальное
function mod_categoryChange(load_product) {
    var qString = jQuery("#mod_vm_search_form").formSerialize();
    jQuery("#mod_mf_div").fadeTo("slow", 0.01);
    jQuery("#mod_ad_div").fadeTo("slow", 0.01);
    jQuery("#mod_typ_div").fadeTo("slow", 0.01);
    if(jQuery("div").is("#mod_mf_div")){
        jQuery.ajax({
            type: "POST",
            url: url+'/index2.php?option=com_vm_ext_search_pro&task=ajax_mod&no_html=1&task2=manufacturer',
            data: qString,
            dataType: 'HTML',
            success: function (data){
                jQuery("#mod_mf_div").html(data);
                customFadeTo("#mod_mf_div");
            }
        });
    }
    if(jQuery("div").is("#mod_ad_div")){
        jQuery.ajax({
            type: "POST",
            url: url+'/index2.php?option=com_vm_ext_search_pro&task=ajax_mod&no_html=1&task2=available_date',
            data: qString,
            dataType: 'HTML',
            success: function (data){
                jQuery("#mod_ad_div").html(data);
                customFadeTo("#mod_ad_div");
            }
        });
    }
    if(jQuery("div").is("#mod_typ_div")){
        jQuery.ajax({
            type: "POST",
            data: qString,
            url: url+'/index2.php?option=com_vm_ext_search_pro&task=ajax_mod&no_html=1&task2=typ',
            dataType: 'HTML',
            success: function (data){
                jQuery("#mod_typ_div").html(data);
                customFadeTo('#mod_typ_div');
                mod_typeChange(load_product);
            }
        });
    }
return;
}

function mod_mfChangeMulti(load_product) {
    var qString = jQuery("#mod_vm_search_form").formSerialize();
    jQuery("#mod_ad_div").fadeTo("slow", 0.01);
    jQuery("#mod_typ_div").fadeTo("slow", 0.01);
    if(jQuery("div").is("#mod_ad_div")){
        jQuery.ajax({
            type: "POST",
            url: url+'/index2.php?option=com_vm_ext_search_pro&task=ajax_mod&no_html=1&task2=available_date',
            data: qString,
            dataType: 'HTML',
            success: function (data){
                jQuery("#mod_ad_div").html(data);
                customFadeTo("#mod_ad_div");
            }
        });
    }
    if(jQuery("div").is("#mod_typ_div")){
        jQuery.ajax({
            type: "POST",
            data: qString,
            url: url+'/index2.php?option=com_vm_ext_search_pro&task=ajax_mod&no_html=1&task2=typ',
            dataType: 'HTML',
            success: function (data){
                jQuery("#mod_typ_div").html(data);
                customFadeTo("#mod_typ_div");
                mod_typeChange(load_product);
            }
        });
    }
    return;
}

function mod_availableDateChange(load_product) {
    var qString = jQuery("#mod_vm_search_form").formSerialize();
    jQuery("#mod_typ_div").fadeTo("slow", 0.01);
    if(jQuery("div").is("#mod_typ_div")){
        jQuery.ajax({
            type: "POST",
            data: qString,
            url: url+'/index2.php?option=com_vm_ext_search_pro&task=ajax_mod&no_html=1&task2=typ',
            dataType: 'HTML',
            success: function (data){
                jQuery("#mod_typ_div").html(data);
                customFadeTo("#mod_typ_div");
                mod_typeChange(load_product);
            }
        });
    }
    return;
}

function mod_typeChange(load_product){
    var qString = jQuery("#mod_vm_search_form").formSerialize();
    jQuery("#mod_harakt_div").fadeTo("slow", 0.01);
    jQuery.ajax({
        type: "POST",
        url: url+'/index2.php?option=com_vm_ext_search_pro&task=ajax_mod&no_html=1&task2=harakt',
        data: qString,
        dataType: 'HTML',
        success: function (data){
            jQuery("#mod_harakt_div").html(data);
            customFadeTo("#mod_harakt_div");
            if (load_product == true) mod_loadProduct();
        }
    });
    return;
}

function mod_loadProduct( limitstart ){
    var qString = jQuery("#mod_vm_search_form").formSerialize();
    jQuery("#main_search").fadeTo("slow", 0.01);
    jQuery.ajax({
        type: "POST",
        url: url+'/index2.php?option=com_vm_ext_search_pro&task=ajax_mod&task2=load_page&limitstart='+limitstart+'&no_html=1',
        data: qString,
        dataType: 'HTML',
        success: function (data){
            jQuery("#main_search").html(data);
            customFadeTo("#main_search");
        }
    });
    return;
}

function mod_uncheck( name, load_product ){
    for (var obj = document.getElementsByName ( name ), j = 0; j < obj.length; j++) obj [j].checked = false;
    if (name == 'catid[]') mod_categoryChange(load_product);
    else if (name == 'mf_id[]') mod_mfChangeMulti(load_product);
    else mod_typeChange(load_product);
}

function mod_product( link ){
    jQuery("#main_search").fadeTo("slow", 0.01);
    jQuery.ajax({
        type: "GET",
        url: url+'/'+link,
        success: function (data){
            jQuery("#main_search").html(data);
            customFadeTo("#main_search");
        }
    });
    return;
}
function mod_AddToCart( id ) {
    var qString = jQuery('#'+id ).formSerialize();
    jQuery.ajax({
        type: "POST",
        url: url+'/index.php',
        data: qString,
        dataType: 'HTML',
        success: function (data){
            jQuery('#'+id+'_div' ).html(data);
        }
    });
    return;
}

function mod_AscDesc() {
    var value = jQuery('#mod_orderby_input').val();
    if (value == 'ASC') {
        var data = '<img src="'+ url + '/components/com_vm_ext_search_pro/img/sort_desc.png" border="0" title="Z-A" alt="Z-A"/>\n\
                    <input id="mod_orderby_input" type="hidden" name="DescOrderBy" value="DESC" />';
    } else {
       var data = '<img src="'+ url + '/components/com_vm_ext_search_pro/img/sort_asc.png" border="0" title="A-Z" alt="A-Z"/>\n\
                    <input id="mod_orderby_input" type="hidden" name="DescOrderBy" value="ASC" />';
    }
    jQuery('#mod_orderby_a' ).html(data);
}
function mod_ShowHide(id) {
    jQuery('#id_parameter_'+id ).toggle();
    jQuery('#id_label_'+id ).toggleClass('show_param');
    if (jQuery('#id_input_'+id ).val() == 'none') {
        jQuery('#id_input_'+id ).attr('value', 'block');
    } else {
        jQuery('#id_input_'+id ).attr('value', 'none');
    }
}

function customFadeTo(id) {
    jQuery(id).fadeTo('slow', 1, function() {
          if (jQuery.browser.msie) jQuery(id).css('filter', '');
    });
}
jQuery.noConflict();
