﻿function getXmlHttpObj()
{  
    var xmlHttp = null;
    try
    {    // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();  
    }
    catch (e)
    {    // Internet Explorer
        try
        {      
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {      
            try
            {        
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      
            }
            catch (e)
            {               
                return null;        
            }      
        }    
    }
    return xmlHttp;  
}


function SetTableRowOver(oSource,isOver)
{
    if(isOver)
    {
        oSource.style.backgroundColor = "#CFE4EC";
    }
    else
    {
        oSource.style.backgroundColor = "White";
    }
}

// adds a value to a hidden field
// format: value;value;value...
// warning: sValue can't contain ';'
function AddToHiddenField(sFieldId, sValue)
{
    var oField = document.getElementById(sFieldId);
    if(oField)
    {
        var sCurValue = oField.value;
        if(sCurValue == "")
        {
            oField.value = sValue;
        }
        else
        {
            // check if value not exists
            if(sCurValue.indexOf(sValue) == -1)
            {
                oField.value = oField.value + ";" +  sValue;
            }
        }
        
    }
} 

// removes a value from a hidden field
// format: value;value;value...
// warning: sValue can't contain ';'
function removeFromHiddenField(sFieldId, sValue)
{
    var oField = document.getElementById(sFieldId);
    if(oField)
    {
        var sCurValue = oField.value;
        if(sCurValue != "")
        {
            // check if value exists
            if(sCurValue.indexOf(sValue) > -1)
            {
                var sNewHiddenValue = "";
                var sCurValueArr = sCurValue.split(";");
                for(i=0 ; i < sCurValueArr.length ; i++)
                {
                    if(sCurValueArr[i] != sValue)
                    {
                        if(sNewHiddenValue == "")
                        {
                            sNewHiddenValue = sCurValueArr[i];
                        }
                        else
                        {
                            sNewHiddenValue = sNewHiddenValue + ";" + sCurValueArr[i];
                        }
                    }
                }
                // set the new value
                oField.value = sNewHiddenValue;
            }
        }
    }
} 

function closeDate(oCalendar)
{
    oCalendar.hide();
}

function submitOnTextBoxEnter(sBtnId,e)
{
    if(event != null)
    {
        e = event;
    }
    if(e != null)
    {
        if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13))
        {
        
            var oBtn = document.getElementById(sBtnId);
            if(oBtn)
            {
                oBtn.click();
                return false;
            }
            return true;
        }
        else 
            return true;
    }
}

function LoadFileActionsPage(sPage,sAction, sParams)
{
    myWindow=window.open("FileActions.aspx?Page="+sPage+"&Action="+sAction+"&Params="+sParams,"","width=600,height=500,resizable=yes,scrollbars=yes");
    myWindow.focus();
}

var tOnlinePopupMenu = null;
// online popup menu
function OpenOnlinePopupMenu()
{
    clearTimeout(tOnlinePopupMenu);
    document.getElementById('idOnlinePopupMenu').style.display = '';
}

function CloseOnlinePopupMenu()
{
    tOnlinePopupMenu = setTimeout("document.getElementById('idOnlinePopupMenu').style.display = 'none';",100);
}

var tProductsPopupMenu = null;
// products popup menu
function OpenProductsPopupMenu()
{
    clearTimeout(tProductsPopupMenu);
    document.getElementById('idProductsPopupMenu').style.display = '';
}

function CloseProductsPopupMenu()
{
    tProductsPopupMenu = setTimeout("document.getElementById('idProductsPopupMenu').style.display = 'none';",100);
}

var tOrderPopupMenu = null;
// products popup menu
function OpenOrderPopupMenu()
{
    clearTimeout(tOrderPopupMenu);
    document.getElementById('idOrderPopupMenu').style.display = '';
}

function CloseOrderPopupMenu()
{
    tOrderPopupMenu = setTimeout("document.getElementById('idOrderPopupMenu').style.display = 'none';",100);
}



function LoadPage(sPage)
{
    window.location.href = sPage;
}

function LoadHtmlForPrint(sHtml)
{
    myWindow=window.open("","","width=800,height=600,resizable=yes,scrollbars=yes");
    myWindow.document.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
    myWindow.document.write("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
    myWindow.document.write("<head>");
    myWindow.document.write("<title>Print</title>");
    myWindow.document.write("</head>");
    myWindow.document.write("<body onLoad=\"this.print();\">");
    myWindow.document.write("<div style='direction:rtl;'>");
    myWindow.document.write("<div style='direction:rtl;'>");
    myWindow.document.write(sHtml);
    myWindow.document.write("</div>");
    myWindow.document.write("</body>");
    myWindow.document.write("</html>");
    myWindow.document.close();
    myWindow.focus();
}

function CleanUpAllFields(sParentFieldId)
{
    var oParentElement = document.getElementById(sParentFieldId);
    if(oParentElement != null)
    {
        for(var i=0; i<oParentElement.childNodes.length ; i++)
        {
            recursiveClean(oParentElement.childNodes[i]);
        }
    }
}

function recursiveClean(oNode)
{
    if(oNode.tagName != null)
    {
        if(oNode.tagName.toLowerCase() == "input" && oNode.type == "text")
        {
            oNode.value = "";
        }
        else if(oNode.tagName.toLowerCase() == "select")
        {
            oNode.selectedIndex = 0;
        }
    }
    for(var i=0; i<oNode.childNodes.length ; i++)
    {
        recursiveClean(oNode.childNodes[i]);
    }
}