function enterSubmit(e)
{   
    if (!e) e = window.event;
    
    if (Page_IsValid && e.keyCode == 13)
    {
        Sys.WebForms.PageRequestManager.getInstance()._doPostBack('btnSearch', '');
    }
}

function triggerUpdateData(tbox,e,dataType)
{
    if (!e) e = window.event;
    var onblurHandler = null;
    
    if (e.keyCode == 13 || e.keyCode == 9)
    {
        if (dataType == "Price")
        {
            onblurHandler = tbox.onblur;
            tbox.onblur = null;
        }
        setTimeout("updateData('"+tbox.id+"','"+dataType+"',"+onblurHandler+")",250);
        return false;
    }
    return true;
}

function updateData(tboxID,dataType,onblurHandler)
{
    var tbox = document.getElementById(tboxID);
    var hfProdID = document.getElementById('hfID');
    var hfDesc = document.getElementById('hfDescription');
    var hfPrice = document.getElementById('hfPrice');
    var hfDataType = document.getElementById('hfDataType');
    var tableRowCellsColl = tbox.parentNode.parentNode.childNodes;
    var myRegxp = /^(?!0\d)\d+\.\d{2}$/;
    var priceNode;
      
    if (dataType == "Description" || dataType == "Price")
    {
        hfDataType.value = dataType;
        hfProdID.value = (tableRowCellsColl[0].nodeName != "TD") ? tableRowCellsColl[1].childNodes[1].innerHTML : tableRowCellsColl[0].firstChild.innerHTML;
        if (dataType == "Description")
        {
            hfDesc.value = tbox.value;
            priceNode = (tableRowCellsColl[0].nodeName != "TD") ? tableRowCellsColl[3].childNodes[1] : tableRowCellsColl[2].firstChild;
            hfPrice.value = priceNode.innerHTML;
        }
        else if (dataType == "Price")
        {
            priceNode = tbox;
            hfPrice.value = tbox.value;
            hfDesc.value = (tableRowCellsColl[0].nodeName != "TD") ? stripHtml(tableRowCellsColl[2].childNodes[1].innerHTML) : stripHtml(tableRowCellsColl[1].firstChild.innerHTML);
        }
        
        if (priceNode == tbox && !myRegxp.test(hfPrice.value))
        {
            alert("The price is invalid.");
            setTimeout("document.getElementById('"+tbox.id+"').focus()",250);
            if (tbox.onblur == null)
                tbox.onblur = onblurHandler;
        }
        else
        {    
            Sys.WebForms.PageRequestManager.getInstance()._doPostBack(tbox.parentNode.getElementsByTagName("input")[1].id.replace(/_/g,"$"), '');
        }
    }
}

function stripHtml(s) 
{
      return s.replace(/(<span style=".+?">)|(<\/span>)/ig, "");
}


//window.onscroll = function()
//{
//    var loadingDiv = document.getElementById('loading');
//    if (window.pageYOffset)
//        loadingDiv.style.top = window.pageYOffset + 290 + 'px';    
//    else if (document.documentElement.scrollTop)
//        loadingDiv.style.top = document.documentElement.scrollTop + 290 + 'px';		   			
//    else
//        loadingDiv.style.top = document.body.scrollTop + 290 + 'px'; 
//};
