<!-- This opens the HTML comments that will hide the script from old browsers 
var xmlHttp;
var m_strTextBoxName = "";
var m_strListBoxName = "";
var m_strURL = "";
var m_strNextControlName = "";
var m_arrListBox = new Array();
var m_strCode = ""; //variable for each textbox with complete 

function popWin(strURL, strWindowName, intWidth, intHeight)		
{
    var strWindowSize = "width=" + intWidth + ",height=" + intHeight;		    
    var str1 = getControlName(strWindowName);
    
    str1 = "frmBlankTemplate_" + str1;
    window.open(strURL, str1, strWindowSize);
    return false;
}
function Form_Load()
{
    createXMLHttpRequest();
}
//function txtName_Enter()
//{
//    if (xmlHttp.readyState==4) 
//    {
//        window.location = 'frmBlankTemplates.aspx';
//    }    
//}
//function txtName_KeyDown(e)
//{
//    var keycode = getKeyCode(e);
//    
//    if(keycode == 13)
//    {    
//        var strTemplateName = document.getElementById("txtName").value;
//        strURL = "frmBlankTemplate.aspx?FuncName=Save&TemplateName=" + strTemplateName;        
//        xmlHttp.open("GET", strURL, true);
//        xmlHttp.onreadystatechange = txtName_Enter;
//        xmlHttp.send();
//        return false;
//    }
//        
//    return true;
//}
function txtQty_KeyDown(e)
{
    var keycode = getKeyCode(e);    
    return (keycode != 13); //enter
}
function txtSubCategory_Enter()
{
    if (xmlHttp.readyState==4) 
    {
        var strResponseText = xmlHttp.responseText;
        var arrResponse = strResponseText.split("\n");
        var txtControlName = m_strTextBoxName.substring(0, m_strTextBoxName.lastIndexOf("_")+1) + "lblSubCatDesc";
        var lblSubCatDesc = document.getElementById(txtControlName);
        lblSubCatDesc.innerText = arrResponse[0];
    }
}
function txtSubCategory_Response()
{
    if (xmlHttp.readyState==4) 
    {
        var oList = document.getElementById(m_strListBoxName);
        var strResponseText = xmlHttp.responseText;
        var arrResponse = strResponseText.split("\n");
        var arrItems = arrResponse[0].split(",");
        m_arrListBox = arrResponse[1].split(",");
        
        clearListBox( oList );
        
        for(var i=0;i<arrItems.length-1;i++)
        {
            var elm = document.createElement('option');
            elm.text = arrItems[i];
            
            if(elm.text != "")
            {
                try{ // standards compliant
                    oList.add( elm, null );
                }
                catch(ex){ //IE Only
                    oList.add( elm );            
                }
            }
        }
    }
}
function txtSubCategory_Focus(strTextBoxName, strNextControlName, strListBoxName, strURL)
{
    m_strTextBoxName = getControlName(strTextBoxName);
    m_strListBoxName = strListBoxName;
    m_strURL = strURL;
    m_strNextControlName = getControlName(strNextControlName);
}
function txtSubCategory_KeyDown(e)
{
    var oList = document.getElementById(m_strListBoxName);    
    var oTextBox = document.getElementById(m_strTextBoxName);
    var keycode = getKeyCode(e);
    
    if(keycode == 13) //enter
    {            
        if( oList.style.display == "block" && oList.length > 0)
        {
            var oNextControl = document.getElementById(m_strNextControlName);
            var strSelectedItem = oList.options[0].text;

            oTextBox.value = strSelectedItem;
            oList.style.display = "none";
            oNextControl.focus();
        }
        
        strURL = "frmLookup.aspx?FuncName=GetSubCategoryDescription&Code=" + strSelectedItem;
        xmlHttp.open("GET", strURL, true);
        xmlHttp.onreadystatechange = txtSubCategory_Enter;
        xmlHttp.send();                         
        
        return false;
    }
    
    return true;
}
function txtSubCategory_KeyUp(e)
{
    var oList = document.getElementById(m_strListBoxName);    
    var oTextBox = document.getElementById(m_strTextBoxName);

    var strCode = trim(oTextBox.value);
    var strURL;
    var keycode = getKeyCode(e);

    if(keycode == 40 && oList.style.display == "block") //down arrow
    {
        oList.focus();
        oList.selectedIndex = 0
        return
    }    

    if(strCode != "")
    {
        if(strCode != m_strCode)
        {
            m_strCode = strCode;
            setListBox(oTextBox, oList);
            strURL = m_strURL + strCode;
            xmlHttp.open("GET", strURL, true);
            xmlHttp.onreadystatechange = txtSubCategory_Response;
            xmlHttp.send();                
        }
    }
    else
    {   
        m_strCode = "";
        oList.style.display = "none";
        clearListBox(oList);        
    }
    
    return false;    
}
function setListBox(oTextBox, oList)
{
    oList.style.display = "block";
}
function lstSubCategory_KeyUp(e)
{
    var oTextBox = document.getElementById(m_strTextBoxName);
    var oList = document.getElementById(m_strListBoxName);    
    var keycode = getKeyCode(e);

    if(keycode == 13 && oList.style.display == "block") //enter    
    {
        if(oList.selectedIndex >= 0)
        {
            var oNextControl = document.getElementById(m_strNextControlName);
            var strSelectedItem = oList.options[oList.selectedIndex].text;            
            oTextBox.value = strSelectedItem;                        
            oList.style.display = "none";
            oNextControl.focus();
        }
    }
    else if((keycode == 38 || keycode == 40) && oList.style.display == "block") //up+down arrow
    {
        if(oList.selectedIndex >= 0)
        {
            var strSelectedItem = oList.options[oList.selectedIndex].text;            
            oTextBox.value = strSelectedItem;                        
            oList.focus();
        }    
    }
    else if(keycode == 27 && oList.style.display == "none") //escape
    {
        oList.style.display = "none";
        oTextBox.focus();        
    }
}
function lstSubCategory_KeyDown(e)
{
    var oTextBox = document.getElementById(m_strTextBoxName);
    var oList = document.getElementById(m_strListBoxName);
    var keycode = getKeyCode(e);
    
    if(keycode == 40 && oList.style.display == "block") //down arrow
    {
        if(oList.selectedIndex >= 0 && oList.selectedIndex+1 < oList.length)
        {
            var strSelectedItem = oList.options[oList.selectedIndex+1].text;            
            oTextBox.value = strSelectedItem;                        
            oList.focus();
        }    
    }    
    else if(keycode == 38 && oList.style.display == "block") //up arrow
    {
        if(oList.selectedIndex > 0)
        {
            var strSelectedItem = oList.options[oList.selectedIndex-1].text;            
            oTextBox.value = strSelectedItem;                        
            oList.focus();
        }    
    }    
}
function lstSubCategory_Change()
{
    var oTextBox = document.getElementById(m_strTextBoxName);
    var oList = document.getElementById(m_strListBoxName);            
    if(oList.selectedIndex >= 0)
    {
        var strSelectedItem = oList.options[oList.selectedIndex].text;            
        oTextBox.value = strSelectedItem;
        
        var strControlName = m_strTextBoxName.substring(0, m_strTextBoxName.lastIndexOf("_")+1) + "lblSubCatDesc";
        var lblSubCategory = document.getElementById(strControlName);
        lblSubCategory.innerText = m_arrListBox[oList.selectedIndex];
        
        oList.focus();
    }        
}
function lstSubCategory_DoubleClick()
{
    var oTextBox = document.getElementById(m_strTextBoxName);
    var oList = document.getElementById(m_strListBoxName);    
    var oNextControl = document.getElementById(m_strNextControlName);
    var strSelectedItem = oList.options[oList.selectedIndex].text;
    oTextBox.value = strSelectedItem;
    oList.style.display = "none";
    oNextControl.focus();
    
    var txtControlName = m_strTextBoxName.substring(0, m_strTextBoxName.lastIndexOf("_")+1) + "txtSubCategory";
    var txtSubCategory = document.getElementById(txtControlName);
    var strSubCategory = txtSubCategory.value;
    strURL = "frmLookup.aspx?FuncName=GetSubCategoryDescription&Code=" + strSubCategory;
    xmlHttp.open("GET", strURL, true);
    xmlHttp.onreadystatechange = txtSubCategory_Enter;
    xmlHttp.send();    
}

//--> This closes the comment section and the browser will read on normally 

