﻿function logTableFocusOn(multiSelectInstance) { $("#" + multiSelectInstance).attr("mouse_on_list", "1"); }
function logTableFocusOut(multiSelectInstance) { $("#" + multiSelectInstance).attr("mouse_on_list", "0"); }
function setFocusOnMultiSelectText(multiSelectInstance) { $("#Txt" + multiSelectInstance)[0].focus(); }
function closeMultiSelectPnl(multiSelectInstance) 
{ 
    if ($("#" + multiSelectInstance).attr("mouse_on_list") == 0) { $("#PnlList" + multiSelectInstance).hide(); } 
}
function setSelectedText(targetTextControlId, targetValueControlId) 
{ 
    $("#" + targetTextControlId).val("");
    $("#" + targetValueControlId).val("");
    return this.each(function()
    { 
        var me   = jQuery(this);
        $("#" + targetTextControlId).val($("#" + targetTextControlId).val() + me.attr("text") + ";");
        $("#" + targetValueControlId).val($("#" + targetValueControlId).val() + me.val() + ";");
    });
};

function OpenMultiSelectPnl(multiSelectInstance) 
{
  /*  var offset = $("#Txt" + multiSelectInstance).offset();
    $("#PnlList" + multiSelectInstance).css({ "left": offset.left + "px" });
    $("#PnlList" + multiSelectInstance).css({ "top": (offset.top + 20) + "px" });*/
    $("#PnlList" + multiSelectInstance).show();
    setFocusOnMultiSelectText(multiSelectInstance);
}
function PostPageForPostBack(multiSelectInstance, postUrl)
{
    var txtVal = $("#Txt" + multiSelectInstance).val();    
   if(txtVal != "")
   { 
       postUrl = postUrl + "&SR="+$("#Txt" + multiSelectInstance).val();      
       $.post(postUrl, {}, function(response) 
        {
         
            $("#LstItems" + multiSelectInstance).html(response);
            if($("#LstItems" + multiSelectInstance + " > ol").length > 0 ) 
            { 
                $("#LstItems" + multiSelectInstance + " > ol").attr("id", "LstItems" + multiSelectInstance);
                $("#LstItems" + multiSelectInstance + " > ol").attr("style", "text-align: left; margin: 0px; padding:0px;" );
            }
            $("#LstItems" + multiSelectInstance + " li").addClass("NoIconListStyle");          
        });        
    }
    else
    {
     closeMultiSelectPnl(multiSelectInstance);
    }
}
function InitializeMultiSelectInstance(multiSelectInstance,postUrl)
{
    $("#PnlList" + multiSelectInstance).hide();    
    $("#PnlList" + multiSelectInstance).mouseover(function() { logTableFocusOn(multiSelectInstance); });
    $("#PnlList" + multiSelectInstance).mouseout(function() { logTableFocusOut(multiSelectInstance); });
    $("#Txt" + multiSelectInstance).blur(function(event) { closeMultiSelectPnl(multiSelectInstance); });
    $("#PnlList" + multiSelectInstance).click(function(event) { setFocusOnMultiSelectText(multiSelectInstance); });
    $("#PnlList" + multiSelectInstance).mouseout(function(event) { setFocusOnMultiSelectText(multiSelectInstance); });
    $("#Txt" + multiSelectInstance).keypress(function(event) { OpenMultiSelectPnl(multiSelectInstance); });
    $("#Txt" + multiSelectInstance).keyup(function(event) { PostPageForPostBack(multiSelectInstance, postUrl); });
}
function instantiateMultiSelect(containerID,postUrl)
{  
    var strHTMLContent = "<div>";     
    strHTMLContent += "<input autocomplete=\"off\" type=\"text\" id=\"Txt" + containerID + "\"/></div>";
   // strHTMLContent += "<input type=\"hidden\" id=\"HdnValue" + containerID + "\" /></div>";
    strHTMLContent += "<div id=\"PnlList" + containerID + "\" class=\"PlnClass\">";
    strHTMLContent += "<div id=\"LstCountries2Slot\"><ol id=\"LstItems" + containerID + "\"  style=\"margin:0px; padding:0px;text-align: left; \" ><li>Loading...</li></ol></div></div>";
   
    $("#" + containerID).append(strHTMLContent);
    InitializeMultiSelectInstance(containerID,postUrl);
}
function showhide(imgID,prefixText,hydvaltxt,ContentID)
{  
   var txtID ="Txt"+ContentID;  
   var imgSRC = $('#'+imgID).attr("src") ;
   var imgALT =  $('#'+imgID).attr("alt");
   var txtVal =  $('#'+txtID).val(); 
   
  
     
   if(imgSRC == "/images/Check_Search.gif")
    {
       $('#'+imgID).attr("src", "/images/Uncheck_Search.gif");      
       txtVal = new String(txtVal);imgALT = new String(imgALT);
       txtVal =  txtVal.replace(imgALT+";","");
       $('#'+txtID).val(txtVal);  
    }   
   else
   {       
       $('#'+imgID).attr("src", "/images/Check_Search.gif");  
        prefixText = new String(prefixText);          
        
        if(prefixText == txtVal)
        { $('#'+txtID).val("");   }
        
       $('#'+txtID).val($('#'+txtID).val() + imgALT + ";");
       $("#"+hydvaltxt).val($("#"+hydvaltxt).val() + imgALT + ";");           
   }}
function PostPageForPostBackMultipleDropdown(multiSelectInstance, postUrl) {   
    var strHTMLContent = "";
    var txtVal = $("#Txt" + multiSelectInstance).val();
    if (txtVal != "") {
        postUrl = postUrl + "&SR=" + $("#Txt" + multiSelectInstance).val();
        $.post(postUrl, {}, function(response) {

            $("#LstItems" + multiSelectInstance).html(response);
            if ($("#LstItems" + multiSelectInstance + " > ol").length > 0) {
                $("#LstItems" + multiSelectInstance + " > ol").attr("id", "LstItems" + multiSelectInstance);
                $("#LstItems" + multiSelectInstance + " > ol").attr("style", "text-align: left; margin: 0px; padding:0px;");
            }
            $("#LstItems" + multiSelectInstance + " li").addClass("NoIconListStyle");
            strHTMLContent += response;
            $("#" + multiSelectInstance).append(strHTMLContent);
            closeMultiSelectPnl(multiSelectInstance);

        });
    }
    else {
        closeMultiSelectPnl(multiSelectInstance);
    }
}
function showhide_Click(imgID, prefixText, hydvaltxt, txtid) {
    var txtID = document.getElementById(txtid);
    var imgSRC = $('#' + imgID).attr("src");
    var imgALT = $('#' + imgID).attr("alt");
    var txtVal = txtID.value;

    if (imgSRC == "/images/Check_Search.gif") {
        $('#' + imgID).attr("src", "/images/Uncheck_Search.gif");
        txtVal = new String(txtVal); imgALT = new String(imgALT);
        txtVal = txtVal.replace(imgALT + ";", "");
        txtID.value = txtVal;
    }
    else {
        $('#' + imgID).attr("src", "/images/Check_Search.gif");
        prefixText = new String(prefixText);

        if (prefixText == txtVal)
        {txtID.value = "";}

        txtID.value = txtID.value + imgALT + ";"        
        $("#" + hydvaltxt).val($("#" + hydvaltxt).val() + imgALT + ";");
    }
}
function GetCompanyListForHomePage(Instance,PageURL ,txtvalue, postUrl) {
    var txtVal = $("#" + txtvalue).val();
    postUrl = postUrl + "&StrSearch=" + txtVal + "&PURL=" + PageURL;
    $.post(postUrl, {}, function(response) {
        $("#" + Instance).html("");
        $("#" + Instance).append(response);       
    });
}
