
var debug = 0;
var action_remote_script = "/add_to_favorit.php";
var action_remote_script_del = "/del_to_favorit.php";

function add_favorit(site_part, catalog_id, product_id){
     $.post(action_remote_script, 
            {site_part:site_part, 
            catalog_id:catalog_id, 
            product_id:product_id}, 
            show_top_link_to_favorit);   
}

function del_favorit(site_part, catalog_id, product_id){
     $.post(action_remote_script_del, 
            {site_part:site_part, 
            catalog_id:catalog_id, 
            product_id:product_id}, 
            show_top_link_to_favorit);       
}

function show_top_link_to_favorit(data){
    if (data != "1") {
        $("#add_remove_favoite").attr("innerHTML","<a href=\"\" onclick=\"add_favorit('" + $("#site_part").attr("value") + "','" + $("#catalog_id").attr("value") + "','" + $("#product_id").attr("value") + "');return false;\" class=\"add\"><span>Обязательно куплю</span></a>");
    } else {
        $("#add_remove_favoite").attr("innerHTML","<a href=\"\"  onclick=\"del_favorit('" + $("#site_part").attr("value") + "','" + $("#catalog_id").attr("value") + "','" + $("#product_id").attr("value") + "');return false;\" class=\"remove\"><span>Удалить из списка покупок</span></a>");
    }
}

function send_city_shops(city){
    $.post("/load_shops.php", {city:city},showShpos);

}

function showShpos(data){
   if (data != "" || data != "0") {
       $("#stores").attr("innerHTML", data);
   }

}

function mapcityaddress(part, id){
   //$.post("",{part:part, id:id},xml_mapcityaddress);
   //showPopup('photoPopup2');
   
    var action = "/zal/load_scheme_xml.php";
    
    
    $('#bImg img').eq(0).remove();
    /// Добавляем новую
    var img = new Image();

    img.onload = function() {
        $('#bImg').append(this);
        $('#bImg img').eq(0).hide();
        $('#bImg img').eq(0).fadeIn(200);
    };
    /// Вывод фото
    img.src = "/img/loader.gif"; 
    
    
    $.post(action,{id:id,fkey:fkey},loadMapWay);   
}

function xml_mapcityaddress(xml){
}

function showPopupProduct(part, id){

     $.post("/load_prod_xml.php",{part:part, id:id},showPopupProductLoad);
}

function showPopupProductLoad(xml){

     var productcode = $("productcode", xml);
     var discount = $("discount", xml);
     var price = $("price", xml);
     var old_price = $("old_price", xml);
     var producer = $("producer", xml);
     var material = $("material", xml);
     var image = $("image", xml);
     
     var product_id = $("product_id", xml);
     var catalog_id = $("catalog_id", xml);
     var site_part = $("site_part", xml);
     
     $('#bImg img').eq(0).remove();
     var img = new Image();
     img.onload = function() {
         $('#bImg').append(this);
         $('#bImg img').eq(0).hide();
         $('#bImg img').eq(0).fadeIn(200);
     };
     img.src = image.text();
      
     $("#productcode").attr("innerHTML",productcode.text());
     $("#producer").attr("innerHTML",producer.text());
     $("#material").attr("innerHTML",material.text());
     $("#price").attr("innerHTML",price.text());
     $("#old_price").attr("innerHTML",old_price.text());
     
     
     if (discount.text() == "0") {
         $('#discount').attr("innerHTML", "") ;
         $('#discount').attr("class", "discount_no") ;
     } else {
         $('#discount').attr("innerHTML", "<strong> - " + discount.text() + "</strong>%");
         $('#discount').attr("class", "discount") ; 
     }
     
     if (old_price.text() == "0") {
         $("#old_price").attr("innerHTML","");
     } else {
         $("#old_price").attr("innerHTML","<em></em>" + old_price.text());
     }
     
     $("#remove").attr("href","/del_favorit.php?catalog_id="+catalog_id.text()+"&site_part="+site_part.text()+"&product_id="+product_id.text());
          
     showPopup('photoPopup');
}

function showPopupSheme(part, id){

    $.post("/load_sheme_shop.php", {part:part, id:id},showPopupShemeP);
}

function showPopupShemeP(xml){

       address = $("address", xml);
       phone = $("phone", xml);
       image = $("image", xml);
       $("#address").attr("innerHTML","<strong>"+address.text()+"</strong><br>Телефон: "+phone.text());
       /*
       $('#Bimgs img').eq(0).remove();
       var img = new Image();
       img.onload = function() {
           $('#Bimgs').append(this);
           $('#Bimgs img').eq(0).hide();
           $('#Bimgs img').eq(0).fadeIn(200);
       };
       img.src = image.text();
       img.width = "457";
       img.height = "439";
       */
       document.bimgs.src = image.text();
       showPopup('photoPopup1');
}

