﻿function InputTextboxClearDefaultText(obj, defaultText, errorMessageClientID)
{
    if (obj.value.replace("'","") == defaultText)
    {
        obj.value = '';
    }
    else if (obj.value == '')
    {
        obj.value = defaultText;
    }
    
    if (document.getElementById(errorMessageClientID) != null)
	{
	   document.getElementById(errorMessageClientID).innerText = "";
	}
}

function ToggleInputTextboxButton(obj, buttonId, minChars)
{
    var button = document.getElementById(buttonId);
    
    button.disabled = (obj.value.length < minChars);
}

function ConfirmAction(message)
{
    var confirmed = confirm(message);
    return confirmed;
}

function DisplayProgress(elementToHideId, elementToDisplayId)
{
   var e1 = document.getElementById(elementToHideId);
   var e2 = document.getElementById(elementToDisplayId);
        
    if (e1 != null && e2 != null)
    {
        e1.style.display = "none";
        e2.style.display = "inline";
    }
    else if (e1 == null && e2 != null)
    {
        e2.style.display = "inline";
    }
}

function ConfirmActionAndDisplayProgress(message, elementToHideId, elementToDisplayId)
{
    if(message != null && message != "")
    {
        var confirmed = confirm(message);
        if (confirmed)
        {
            DisplayProgress(elementToHideId,elementToDisplayId);
        }
       return confirmed;
   }
   else
   {
     DisplayProgress(elementToHideId,elementToDisplayId);
     return true;  
   }
}

function ToggleDescriptionFullDisplay(id,clientid,expanddesc,collapsedesc,dotspanlabel) 
{ 
	if (document.getElementById(id).style.display == "none")
	{
		document.getElementById(id).style.display = 'inline';
		
		 if (document.getElementById(clientid) != null)
		    {
		       document.getElementById(dotspanlabel).style.display = 'none';
		       document.getElementById(clientid).innerHTML  = collapsedesc;
		       
		    }
	}
	 else 
	 {
		document.getElementById(id).style.display = 'none';	
		
		 if (document.getElementById(clientid) != null)
		    {
		       document.getElementById(clientid).innerHTML  =  expanddesc;
		       document.getElementById(dotspanlabel).style.display = 'inline';
		    }
	 }	
}

function SetFocus(id)
{
  if ( document.getElementById(id) != null)
   {
      window.location.href = "#"+id;
      document.getElementById(id).style.backgroundColor ="#CCCCCC";
      document.getElementById(id).focus();

   }
}

function StoreCategorySelected(hiddenlabel, categorySelected)
{
    if (document.getElementById(hiddenlabel) != null && categorySelected != null)
    {
      document.getElementById(hiddenlabel).value = categorySelected ;
    }
}

function ToggleDashboardCustomizeProgressIndicators(eventType, saveButtonId, cancelButtonId)
{
    var saveProgressDivId = "SaveProgress";
    var cancelProgressDivId = "CancelProgress";
    
    if (document.getElementById(saveProgressDivId) != null 
        && document.getElementById(cancelProgressDivId) != null
        && document.getElementById(saveButtonId) != null
        && document.getElementById(cancelButtonId) != null)
    {
        if (eventType == "Save")
        {
            document.getElementById(saveProgressDivId).style.display = "inline";
            document.getElementById(cancelProgressDivId).style.display = "none";
        }
        else
        {
            document.getElementById(saveProgressDivId).style.display = "none";
            document.getElementById(cancelProgressDivId).style.display = "inline";
        }
        
        document.getElementById(saveButtonId).style.display = "none";
        document.getElementById(cancelButtonId).style.display = "none";
    }
    
    return true;
}

function DisableElements(DatesDropDownList, ConnectionsRadioButtonList, DisplayConnectionsBox, DontDisplayConnectionsBox, AddButton, RemoveButton)
{
    if (document.getElementById(DatesDropDownList) != null 
        && document.getElementById(ConnectionsRadioButtonList) != null
        && document.getElementById(DisplayConnectionsBox) != null
        && document.getElementById(DontDisplayConnectionsBox) != null
        && document.getElementById(AddButton) != null
        && document.getElementById(RemoveButton) != null )
        {
            document.getElementById(DatesDropDownList).disabled = true;
            document.getElementById(ConnectionsRadioButtonList).disabled = true; 
            document.getElementById(DisplayConnectionsBox).disabled = true; 
            document.getElementById(DontDisplayConnectionsBox).disabled = true; 
            document.getElementById(AddButton).src = "../Images/btn_arrowL.gif";
            document.getElementById(AddButton).onclick="";
            document.getElementById(RemoveButton).src = "../Images/btn_arrowR.gif";
            document.getElementById(RemoveButton).onclick="";
        }
}

function LoadUrl(url)
{
    if (url)
    {
        window.location.href = url;
    }
}

function ResetSearchWhenFocusLost(textBoxId, buttonId)
{
    if (navigator.userAgent.indexOf("MSIE") >= 0)
    {
        var textBox = document.getElementById(textBoxId);
        var button = document.getElementById(buttonId);
        
        if (textBox && button)
        {
            if (document.activeElement != textBox && document.activeElement != button)
            {
                textBox.value = "";
                button.disabled = true;
            }
        }
    }
}

function ToggleMsSearchAttribution(searchScopeDropdownId, searchTextBoxId, searchLogoId, searchButtonId, 
    searchAllConnect, searchThisConnection)
{
    var searchScopeDropdown = document.getElementById(searchScopeDropdownId);
    var searchButton = document.getElementById(searchButtonId);
    
    if (searchButton)
    {
        if (searchScopeDropdown)
        {
            var searchTextBox = document.getElementById(searchTextBoxId);
            var searchLogo = document.getElementById(searchLogoId);
            
            if (searchTextBox && searchLogo)
            {
                if (searchScopeDropdown.options[searchScopeDropdown.selectedIndex].value == "AllConnect")
                {
                    searchLogo.style.display = "inline-block";
                    searchTextBox.style.width = "130px";
                    searchButton.title = searchAllConnect;
                }
                else
                {
                    searchLogo.style.display = "none";
                    searchTextBox.style.width = "177px";
                    searchButton.title = searchThisConnection;
                }
            }
        }
        else
        {
            searchButton.title = searchAllConnect;
        }
    }
}

//
// Initializes the details section on the feedback details page.
//

function initializeDetails() {

    var detailsBtn = $get('detailsImage');
    detailsBtn.collapsedImage = "../images/communitydiscussionicons/collapsed_30.gif";
    detailsBtn.expandedImage = "../images/communitydiscussionicons/expanded_30.gif";
    detailsBtn.src = detailsBtn.collapsedImage;
    detailsBtn.expanded = false;
    
}

//
// Toggles the details section on the feedback details page.
//

function toggleFeedbackDetails() {

    var detailsBtn = $get('detailsImage');
    var detailsContent = $get('feedbackDetails');
    var detailsLink = $get('detailsLink');
    
    if (detailsBtn.expanded) {
    
        detailsContent.style.display = 'none';
        detailsBtn.expanded = false;
        detailsBtn.src = detailsBtn.collapsedImage;
        detailsLink.style.visibility = 'visible';
               
    } else {
    
        detailsContent.style.display = 'block';
        detailsLink.style.visibility = 'hidden';
        detailsBtn.expanded = true;
        detailsBtn.src = detailsBtn.expandedImage;
        
    }
    
}

//
// Strips unwanted elements from survey content.
//

function stripUnwantedElementsFromFeedbackContent() {

    var text = $get('surveyContent').innerHTML;
    text = text.replace(/<\/?(?:span|font|strong)[^>]*>/ig, '');
    text = text.replace(/(<div[^>]*>)(<br(?:\s?\/)?>)+<\/div>/ig, '$1</div>');
    $get('surveyContent').innerHTML = text;

}

//
// Toggles workaround tab view.
//

function toggleWorkaroundTabView(tsid, cbid, show) {

    var tabStrip = $find(tsid);
    var wa_tab = tabStrip.get_tabs().getTab(1);
    wa_tab.select();
    
    if (show) {
        eval(cbid+'_ToggleInputControlsOn()');
    } else {
        eval(cbid+'_ToggleInputControlsOff()');
    } 

    return false;

}  		
