//-----------------------------------------------------------------------------------------------
// Function:      doSearch
//
// Parameters:    searchText ==> string; text to pass to the search page.
//
// Description:   load's the site's search page, passing text to search for.
//
// Returns:       Nothing.
//
// Notes:         searchText must be a non-null, non-empty string.
//-----------------------------------------------------------------------------------------------
function doSearch(searchText)
{
    if(searchText && isString(searchText) && (searchText = trim(searchText)) != "")
        window.location.href = "/Search.aspx?q=" + encodeURIComponent(searchText);
}

//-----------------------------------------------------------------------------------------------
// Function:      hideControl
//
// Parameters:    controlID ==> string; the html element's ID.
//
// Description:   Via DHTML, hides the given html element.
//
// Returns:       Nothing.
//
// Notes:         controlID must be a non-null, non-empty string.  Also, The html element must
//                exist on the page the function is invoked from.
//-----------------------------------------------------------------------------------------------
function hideControl(controlID)
{
    var control;
    
    if(controlID  && isString(controlID) && (control = document.getElementById(controlID)))
        control.style.display = "none";
}

//-----------------------------------------------------------------------------------------------
// Function:      showControl
//
// Parameters:    controlID ==> string; the html element's ID.
//
// Description:   Via DHTML, shows the given html element.
//
// Returns:       Nothing.
//
// Notes:         controlID must be a non-null, non-empty string.  Also, The html element must
//                exist on the page the function is invoked from.
//-----------------------------------------------------------------------------------------------
function showControl(controlID)
{
    var control;
    
    if(controlID && isString(controlID) && (control = document.getElementById(controlID)))
        control.style.display = "inline";
}

//-----------------------------------------------------------------------------------------------
// Function:      trim
//
// Parameters:    str ==> string; the string to trim.
//
// Description:   Removes leading and trailing white-spaces from the given string.
//
// Returns:       the given string without leading and trailing white-spaces.
//
// Notes:         str must be a non-null string.  If not, the original object is returned
//                unchanged.
//-----------------------------------------------------------------------------------------------
function trim(str)
{
    if(isString(str))
    {
        // ^\s+ means leading white-spaces
        // \s+$ means trailing white-spaces
        str = str.replace(/^\s+/, "");
        str = str.replace(/\s+$/, "");
    }
    
    return str;
}

//-----------------------------------------------------------------------------------------------
// Function:      isString
//
// Parameters:    str ==> string; the object to test.
//
// Description:   Determines if the given object is a string.
//
// Returns:       true, if the given object is a string; false otherwise.
//
// Notes:         None.
//-----------------------------------------------------------------------------------------------
function isString(str)
{
    return typeof(str) == "string";
}


//-----------------------------------------------------------------------------------------------
// Function:      leavingSitePrompt
//
// Parameters:    url ==> string; url to launch.
//
// Description:   Launches the url in a new window, if the user agrees to the disclaimer
//
// Returns:       nothing
//
// Notes:         None.
//-----------------------------------------------------------------------------------------------
function leavingSitePrompt(url)
{
  var msg = "You have clicked on a link to another website. By following this link, you will be leaving the ViroPharma, Incorporated website.\r\n\r\n" + 
                    "ViroPharma, Incorporated cannot be responsible for the content of these sites.\r\n\r\nAre you sure you wish to proceed?";
  
   if(confirm(msg))
   window.open(url);
}

//-----------------------------------------------------------------------------------------------
// Function:      confirmMedicalLink
//
// Parameters:    url ==> string; url to launch.
//
// Description:   Links to medical info request form, if the user agrees to the disclaimer
//
// Returns:       nothing
//
// Notes:         None.
//-----------------------------------------------------------------------------------------------
function confirmMedicalLink()
{
  var msg = "Notice: The following information is intended for use only by health care professionals practicing in the United States. If you are a health care professional practicing your profession in the United States or one of its territories, please confirm by clicking OK.";
  
   if(!confirm(msg))
   {
    if(window.history.length > 0)
        window.history.back();
    else
        window.location.href = '/';
   }
}

/* pop up window */
function sh_windowpopup(file, name, w, h) {

    var xPos, yPos;
    var winProp;

    xPos = (screen.width / 2) - (w / 2);
    yPos = (screen.height / 2) - (h / 2);

    winProp = "width=" + w + ",height=" + h + ",left=" + xPos + ",top=" + yPos + ",resizable=1,scrollbars=1";

    win = window.open(file, name, winProp);
    win.focus();
}
