var winObj = new Array();
var winRef = new Array();
var winCount = 0;

// open or set focus to a window
function PopupOpen(sURL, sName, sID, sWidth, sHeight, sToolbar, sScrollbar)
{
    var i
    if (sToolbar != 'yes') sToolbar = 'no'
    // if(sScrollbar!='no') sScrollbar = 'no'
    var sProperties = 'scrollbars=' + sScrollbar + ',status=no,location=no,menubar=no,toolbar=' + sToolbar + ',resizable=no,width=' + sWidth + ',height=' + sHeight;
    var win = null;
    // search for an existing window of that name
    if (winCount > 0)
    {
        for (i = 0; i < winCount; i++)
        {
            if (winRef[i] == sName)
            {
                win = winObj[i];
                break;
            };
        };
    };
    if (sURL.search(/\?/) == -1)
        sURL += '?WindowMode=CONSOLE&Console=1'
    else
        sURL += '&WindowMode=CONSOLE&Console=1';

    // if found, show it or recreate it, otherwise add it to the list of popups and show it
    if (win)
    {
        if (!win.closed)
        {
            win.focus()
            win.location = sURL;
        }
        else
        {
            win = window.open(sURL, sName, sProperties);
            winObj[i] = win;
            win.focus()
        }
    }
    else
    {
        win = window.open(sURL, sName, sProperties);
        winObj[winCount] = win;
        winRef[winCount] = sName;
        winCount++;
        win.focus()
    };
    //return win;
};

// close the window sName, if any
function PopupClose(sName)
{
    var win = null;
    // search for an existing window of that name
    if (winCount > 0)
    {
        for (i = 0; i < winCount; i++)
        {
            if (winRef[i] == sName || sName == '')
            {
                win = winObj[i];
                win.close();
                if (sName != '')
                {  
                    break;
                }
            }
        }
    }
}

function newImage(arg)
{
    if (document.images)
    {
        rslt = new Image();
        rslt.src = arg;
        return rslt;
    }
}

function changeImages()
{
    if (document.images && (preloadFlag == true))
    {
        for (var i = 0; i < changeImages.arguments.length; i += 2)
        {
            document[changeImages.arguments[i]].src = changeImages.arguments[i + 1];
        }
    }
}

var preloadFlag = false;

function preloadImages()
{
    if (document.images)
    {
        //arrow_over = newImage("<% = g_sRedir %>media/images/arrow_hl.gif");
        preloadFlag = true;
    }
}

function menuItem(cell, blnShow)
{
    if (blnShow == true)
    {
        cell.bgColor = '#DFEAF1';
    }
    else
    {
        cell.bgColor = '#FFFFFF';
    }
}

// Place the focus to the first form field...
function placeFocus()
{
    if (document.forms.length > 0)
    {
        var field = document.forms[0];
        for (i = 0; i < field.length; i++)
        {
            if ((field.elements[i].type == "text") || (field.elements[i].type == "textarea") || (field.elements[i].type.toString().charAt(0) == "s"))
            {
                document.forms[0].elements[i].focus();
                break;
            }
        }
    }
}

function siteSearch()
{
    if (document.frmSiteSearch.frmCriteria.value.length > 0)
    {
        document.frmSiteSearch.submit();
    }
    else
    {
        alert("Please enter a criteria to search against.");
        placeFocus();
    }
}

function fileSearch()
{
    if (document.frmFileSearch.frmKeywords.value.length > 0)
    {
        document.frmFileSearch.submit();
        //document.location='test.asp'; 
    }
    else
    {
        alert("Please enter a criteria to search against.");
        placeFocus();
    }
}

function cellImg(idCell, imgName)
{
    document.getElementById(idCell).style.backgroundImage = "url(" + imgName + ")";

}

function DisplayComponentParamOptions()
{
    var objFld1 = eval("document.frmName.frmComponentID");
    var objFld2 = document.getElementById("tdComponentParam");

    //alert(objFld1);
    //alert(objFld2);

    objFld2.style.visibility = "hidden";
    objFld2.style.display = "none";
    //alert(objFld1.value == "Document Library");
    //if (objFld1.value == "Document Library")
    if (objFld1.value == "4")
    {
        objFld2.style.visibility = "visible";
        objFld2.style.display = "inline";
    }
    //alert(objFld2.style.visibility);
}

function validateEmail(emailAddress)
{

    if (emailAddress == null || emailAddress == "")
    {
        return false;
        
    }
    
    var regex = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    var re = new RegExp(regex);
    var m = re.exec(emailAddress);

    if (m != null)
    {
        return true;
    }
    
}



