﻿
function initPlugg(displayFromStart) {
    if (!displayFromStart)
        $('#wrapper-plugg').hide();
    else
        $('#wrapper-plugg').show();        
    //$('#menu ul:first').show();
    $('#search-plugg-header a').click(
    function() {
        var obj = $('#wrapper-plugg');
        if (!(obj.is(':visible'))) {
            $('#wrapper-plugg').slideDown('normal');
            document.getElementById("btn_expand").src = "/images/btn_collapse.gif";
        }
        else {
            $('#wrapper-plugg').slideUp('normal');
            document.getElementById("btn_expand").src = "/images/btn_expand.gif";
        }
    /*        
    var checkElement = $(this).next();
    if ((checkElement.is('#wrapper-plugg')) && (checkElement.is(':visible'))) {
    return false;
    }
    if ((checkElement.is('#wrapper-plugg')) && (!checkElement.is(':visible'))) {
    $('#wrapper-plugg').slideUp('normal');
    checkElement.slideDown('normal');
    return false;
    }
    */
    });
}

var loc = document.location + "";
if (loc.indexOf("products_pluggtatning.asp") < 0) {
    $(document).ready(function() { initPlugg(false); });
} else {
    $(document).ready(function() { initPlugg(true); });
}

function checkValues() {
    var duct = document.getElementById("duct");
    if (isNaN(duct.value))
        duct.value = "";
        
    var cable = document.getElementById("cable");
    if (isNaN(cable.value))
        cable.value = "";

    if (cable.value.length == 0 && duct.value.length == 0) {
        alert("Du måste välja diameter!")
        return false;
    }
    else {
        return true;
    }
}


function initHiddenResult() {
    $('.odd-expand').hide();
    //$('#menu ul:first').show();
/*    
    $('#search-plugg-header a').click(
    function() {
        var obj = $('#wrapper-plugg');
        if (!(obj.is(':visible'))) {
            $('#wrapper-plugg').slideDown('normal');
            document.getElementById("btn_expand").src = "/images/btn_collapse.gif";
        }
        else {
            $('#wrapper-plugg').slideUp('normal');
            document.getElementById("btn_expand").src = "/images/btn_expand.gif";
        }
    }
);
*/
}
$(document).ready(function() { initHiddenResult(); });

function displayResult(obj, img, th_left, td_right) {
    var obj = $('#' + obj);
    var thleft = document.getElementById(th_left);
    var tdright = document.getElementById(td_right);
    if (!(obj.is(':visible'))) {
        obj.slideDown('normal');
        document.getElementById(img).src = "/images/arrow_search_minus.gif";
//        if (tr.className.indexOf("odd") != -1)
//            tr.className = "odd TR-selected";
//        else
//            tr.className = "TR-selected";        
    }else{
        obj.slideUp('normal');
        document.getElementById(img).src = "/images/arrow_search_plus.gif";
//        if (tr.className.indexOf("odd") != -1)
//            tr.className = "odd";
//        else
//            tr.className = "";
    }

    //thleft.className = "th_selected";
    //alert(tdright);
}


function addProduct(id) {
    var add_product = document.getElementById("add_product");
    add_product.value = id;
    var theForm = document.getElementById("pluggsearchform");
    theForm.submit(); 
}
