/* 
--***********************************************************************************************
-- 	RVSales Common JS Utilities
--***********************************************************************************************
*/

function TrimString(p_sSringToTrim) 
{
	//return p_sSringToTrim.replace(/^\s+|\s+$/g,"");
	p_sSringToTrim = LTrimString(p_sSringToTrim);
	p_sSringToTrim = RTrimString(p_sSringToTrim);
	return p_sSringToTrim;
}

function LTrimString(p_sSringToTrim) 
{
	return p_sSringToTrim.replace(/^\s+/,"");
}

function RTrimString(p_sSringToTrim) 
{
	return p_sSringToTrim.replace(/\s+$/,"");
}

function GetQueryStringItem(p_sQueryStringKey) 
{
    var sQueryString = location.search;
    if (sQueryString.indexOf(p_sQueryStringKey) >= 0) 
    {
        var pPointer = sQueryString.indexOf(p_sQueryStringKey) + p_sQueryStringKey.length + 1;
        if (sQueryString.indexOf("&", pPointer) >= 0) 
        {
            return sQueryString.substring(pPointer, sQueryString.indexOf("&", pPointer));
        } 
        else 
        {
            return sQueryString.substring(pPointer, sQueryString.length);
        }
    } 
    else 
    {
        return null;
    }
}

function GetTextBoxValue(p_sTextBoxClientId)
{
    var sReturn = "";
    var tbTextBox = document.getElementById(p_sTextBoxClientId);
	if (tbTextBox != null)
	{
	    sReturn = tbTextBox.value;
	}
	return sReturn;
}

function GetDDLSelectionValue(p_sDDLClientId)
{
    var sReturn = "";
    var ddlDropDownList = document.getElementById(p_sDDLClientId);
	if ((ddlDropDownList != null) && (ddlDropDownList.selectedIndex > 0))
	{
	    sReturn = ddlDropDownList.options[ddlDropDownList.selectedIndex].value;
	}
	return sReturn;
}

//Global
var dOverlay = null;
var dMessageBox = null;

function PerformCloseOverlay()
{
    if (!dOverlay)
    {
        dOverlay = document.getElementById("dOverlay");
        dMessageBox = document.getElementById("dMessageBox");
    }

    for (var i = 0; i < arrSelects.length; i++)
    {
        arrSelects[i].style.visibility = "visible";
    }

    dOverlay.style.display = "none";
    dMessageBox.style.display = "none";
}

function PerformOpenOverlay(p_sMessageBoxHtml, p_sMessageBoxCSSClass)
{
    if (!dOverlay)
    {
        dOverlay = document.getElementById("dOverlay");
        dMessageBox = document.getElementById("dMessageBox");
    }
    
    arrSelects = document.getElementsByTagName("select");
    for (var i = 0; i < arrSelects.length; i++)
    {
        arrSelects[i].style.visibility = "hidden";
    }

    dOverlay.style.display = "block";
    dMessageBox.style.display = "block";

    if (p_sMessageBoxCSSClass)
    {
        dMessageBox.className = p_sMessageBoxCSSClass;
    }     

    if (dMessageBox.offsetLeft == 0)
    {
        var boxLeft = ((document.body.offsetWidth - dMessageBox.offsetWidth ) / 2);
        dMessageBox.style.left = boxLeft + "px";
    }

    if (dMessageBox.offsetTop == 0)
    {
        dMessageBox.style.top = "100px";
    }

    dMessageBox.innerHTML = p_sMessageBoxHtml;
}

function PerformDisplaySiteContentUpdatingDataContainerOveray(p_sUpdatingLabelInnerText)
{
    if (!dSiteContentDataContainer)
    {
        //alert("HI");
        //alert(zm_lUpdatingLabelID);
        var zm_lUpdatingLabel = document.getElementById(zm_lUpdatingLabelID);
        var dSiteContentDataContainer = document.getElementById("dSiteContentDataContainer");
        var dSiteContentUpdatingDataContainer = document.getElementById("dSiteContentUpdatingDataContainer");
    }
    
    //alert("HI2");
    if (!zm_lUpdatingLabel)
    {
        zm_lUpdatingLabel.innerText = p_sUpdatingLabelInnerText;
    }
    //alert("HI3");
    dSiteContentDataContainer.style.display = "none";
    dSiteContentUpdatingDataContainer.style.display = "block";
}

function PerformHideSiteContentUpdatingDataContainerOverlay()
{
//    alert("PerformHideSiteContentUpdatingDataContainerOverlay");
//    alert("zm_lUpdatingLabelID: "+  zm_lUpdatingLabelID);
//    alert("dSiteContentDataContainer: "+  document.getElementById("dSiteContentDataContainer"));
//    alert("dSiteContentUpdatingDataContainer: "+  document.getElementById("dSiteContentUpdatingDataContainer"));
    
    if (!dSiteContentDataContainer)
    {
        var zm_lUpdatingLabel = document.getElementById(zm_lUpdatingLabelID);
        var dSiteContentDataContainer = document.getElementById("dSiteContentDataContainer");
        var dSiteContentUpdatingDataContainer = document.getElementById("dSiteContentUpdatingDataContainer");
    }
    
    dSiteContentDataContainer.style.display = "block";
    dSiteContentUpdatingDataContainer.style.display = "none";
}

/* 
--***********************************************************************************************
-- 	Open New Window
--***********************************************************************************************
*/

function PerformOpenNewWindow(p_sUrl, p_sWindowSettings)
{
    var wWindow = window.open(p_sUrl, "NewWindow", p_sWindowSettings);
    wWindow.name = "NewWindow";
}

function PerformOpenNewWindow(p_sUrl, p_sWindowSettings, p_sNewWindowName)
{
    var wWindow = window.open(p_sUrl, p_sNewWindowName, p_sWindowSettings);
    wWindow.name = p_sNewWindowName;
}