﻿var MAX_ALLOWED_HEIGHT = 280;
var SINGLE_ITEM_HEIGHT = 54;


function OnClientEvent(sender, eventArgs) {
    if (eventArgs._domEvent.keyCode == 13) {

        alert('Per effettuare una ricerca selezionare \ncol mouse una voce nella tendina inferiore');
        //        var rearchstr = 'http://b2b.amos.it/cart/elenco_avanzato_cd.asp?page=1&categoria=&sottocategoria=&from=libera&lang=&target=&tipo_ricerca=input&come=contiene&dove=&operatore=AND&ricercaalto=yes&search=Cerca&StringaDaCercare='
        //        rearchstr = rearchstr+ sender._callbacktext.replace(' ', '+');
        //        parent.centro.location.href = rearchstr;

    }
}

function clientItemSelected(sender, eventArgs) {
    var item = eventArgs.get_item();
    //var form = top.document.forms["srcform"]
    var values_array = item.get_value().split("|");

    var type = values_array[0];
    var valuedata = values_array[1];

    if (type == 'ANA') {
        var rearchstr = '/cart/elenco_analitico_fs.asp?ID='
        rearchstr = rearchstr + valuedata;
        parent.centro.location.href = rearchstr;
    }
    else if (type == 'COD') {
        var rearchstr = '/cart/elenco_avanzato_cd.asp?page=1&categoria=&sottocategoria=&from=libera&lang=&target=&tipo_ricerca=input&come=contiene&dove=&operatore=AND&ricercaalto=yes&search=Cerca&StringaDaCercare='


        rearchstr = rearchstr + valuedata;
        parent.centro.location.href = rearchstr;

        //top.location = rearchstr;
    }
    //sender.set_text(unescape(sender._callbacktext));
    //sender.set_text(values_array[2]);
}

function closeFrame(sender, eventArgs) {
    if (top.document.getElementById("srcframe") != null) {
        //top.document.getElementById("srcframe").style.height = 22;
        top.document.getElementById("srcframe").setAttribute('rows', 27 + ',*', 0);
    }
}

function openFrame(height) {
    if (top.document.getElementById("srcframe") != null) {

        top.document.getElementById("srcframe").setAttribute('rows', height + ',*', 0);
        //top.document.getElementById("srcframe").style.height = height;
    }
}

function OnClientItemsRequestedHandler(sender, eventArgs) {
    //set the max allowed height of the combo   
    //this is the single item's height

    openFrame(MAX_ALLOWED_HEIGHT + 50)


    var calculatedHeight = sender.get_items().get_count() * SINGLE_ITEM_HEIGHT;

    var dropDownDiv = sender.get_dropDownElement();

    if (calculatedHeight > MAX_ALLOWED_HEIGHT) {
        setTimeout(
            function () {
                dropDownDiv.firstChild.style.height = MAX_ALLOWED_HEIGHT + "px";
            }, 20
        );

        setTimeout(
            function () {
                dropDownDiv.firstChild.style.height = MAX_ALLOWED_HEIGHT + "px";
            }, 1000
        );
    }
    else {
        setTimeout(
            function () {
                dropDownDiv.firstChild.style.height = calculatedHeight + "px";
            }, 20
        );
        setTimeout(
            function () {
                dropDownDiv.firstChild.style.height = calculatedHeight + "px";
            }, 1000
        );

    }
}


function itemRequesting(sender, eventArgs) {
    var text = eventArgs.get_text();
    if (text.length < 3) {
        closeFrame();
        eventArgs.set_cancel(true);
        return;
    }


    var context = eventArgs.get_context();
    context["Filter"] = sender.get_text();

}

