﻿
////////////// Begin dialog functions section ////////////////////////////////

//Global variables section.
var powerStripCloseButtonHandler = '';
var powerStripManageButtonHandler = '';
var SingleQuoteCode = /00X01/g;
var QuoteCode = /00X02/g;

function showGenericDialog(dialogName, contentUrl)
{
    var dialog = eo_GetObject(dialogName);
    if (null !== dialog)
    {
        if (null !== contentUrl) { dialog.setContentUrl(contentUrl); }
        dialog.show(true);
    }
    else
    { 
        window.alert("Unable to load the '" + dialogName + "' dialog.");
    }
    
    return false;
}

function showSimpleDialog(dialogName, title)
{
    var dialog = eo_GetObject(dialogName);
    var newTitle = title.toString().replace(SingleQuoteCode,"'");
    
    if (null !== dialog)
    {
        if( null != title ) { dialog.setCaption(newTitle.replace(QuoteCode,"\"")); }
        dialog.show(true);
    }
    else
    { 
        window.alert("Unable to load the '" + dialogName + "' dialog.");
    }
    
    return false;
}


//this function display a modal dialog width the provided parameters
// title: Header title for the dialog.
// contentUrl: Url of the page to show in the dialog.
// name: name of the nongeneric dialog if defined.
// height: heigh of the dialog. If is not provided take the defaul value.
// width: width of the dialog. If is not provided take the defaul value.
function showDialog( title, contentUrl, name, height, width  )
{ 
    var dialog; 
    if( name == '' || name == null ) {dialog = eo_GetObject('mainModalDialog');}
    else {dialog = eo_GetObject(name);}
    var newTitle = title.toString().replace(SingleQuoteCode,"'");
    
    if(null != dialog) 
    {                
        if( null != title ) { dialog.setCaption(newTitle.replace(QuoteCode,"\"")); }
        if( null != contentUrl ) { dialog.setContentUrl(contentUrl); }
        if( null != height && null != width ) { dialog.setSize(width,height); }
        dialog.show(true);    
    }
    else
    {
        alert('Error, loading the modal dialog');
    }
    return false;  
}



//This function show the communication dialog.
function ShowCommunications(title, contentUrl, height, width )
{
    if ('undefined' != typeof(gadgetTitles))
        contentUrl += "?gadgetData=" + gadgetTitles;
    return showDialog(title, contentUrl);
}

// this fucntion close the join this group for anonimous users and redirect to the assigned url.
function endJoinThisGroup(redirectUrl)
{
    window.$clearHandlers(this);
    closeDialog();
    parent.window.location = redirectUrl;
}

//this function display a modal Add Members dialog width the provided parameters
// contentUrl: Url of the Add Member page.
function showDialogAddMemberDialog(contentUrl)
{ 
    var dialog = eo_GetObject('addMemberDialog');
    
    if(null != dialog) 
    {
        if( null != contentUrl ) { dialog.setContentUrl(contentUrl); }
        dialog.show(true);    
    }
    else
    {
        alert('Error, loading the modal dialog');
    }
    return false;  
}

// Opens the specified in a new Tab.
function openInNewTab(navigationUrl, tabTitle, tabToolTip)
{
    // Replace the encoding with the real character
    var newTabTitleSingle = tabTitle.toString().replace(SingleQuoteCode,"'");    
    var newTabToolTipSingle = tabToolTip.toString().replace(SingleQuoteCode,"'");    
    var newNavigationUrlSingle = navigationUrl.toString().replace(SingleQuoteCode,"'");    
//    
//    var args = newNavigationUrlSingle + "|" + newTabTitleSingle + "|" + newTabToolTipSingle ;
//    eo_Callback('mainContentCallbackPanel', args.replace(QuoteCode,"\"")); 
    var dialog = eo_GetObject('loadingDialog');
    dialog.show(); 
    ToggleTab(newNavigationUrlSingle.replace(QuoteCode,"\""), newTabTitleSingle.replace(QuoteCode,"\""), newTabToolTipSingle.replace(QuoteCode,"\""));
}



function testUrlLink(url)
{
        window.open(url,'_blank');
}

//this function display a modeless dialog dialog width the provided parameters
// title: Header title for the dialog.
// contentUrl: Url of the page to show in the dialog.
function showModelessDialog(title, contentUrl)
{
    var dialog = eo_GetObject('mainModalDialog');
    var newContentUrl = contentUrl.toString().replace(SingleQuoteCode,"'");
    var newTitle = title.toString().replace(SingleQuoteCode,"'");
    
    if(null != dialog)
    {
        //if( null != title ) { dialog.setCaption(title); }
        if( null != title ) { dialog.setCaption(newTitle); }
        //if( null != contentUrl ) { dialog.setContentUrl(contentUrl); }
        if( null != contentUrl ) { dialog.setContentUrl(newContentUrl); }
        dialog.show(false);
    }
    else
    {
        alert('Error, loading the modal dialog');
    }
    return false;  
}

// This function close the Dialog
function closeDialog()
{
    window.$clearHandlers(this);
    var dialog = parent.eo_GetObject('mainModalDialog'); 
    if(null != dialog) { dialog.close(); }
    else { alert('Error, closing the modal dialog') } 
    return false;   
}

// This function close the specified eoDialog.
function closeGenericDialog(dialogName)
{
    window.$clearHandlers(this);
    var dialog = parent.eo_GetObject(dialogName);
    if(null != dialog) { dialog.close(); }
    else { alert('Error, closing the modal dialog') }
    return false;
}

var IsLoadedPowerStrip = false;

// this function writes the powerstrip content to the dialogbox.
function ShowPowerStrip(objectId, title, height, width, modalDialogId,closeImagePowerStrip, helpImagePowerStrip, helpOpenFunction)
{ 
        window.$clearHandlers(this);
        
       
        var dialog = eo_GetObject("powerStripModalDialog");
        IsLoadedPowerStrip = false;
        if(null != dialog)
        {
            var eoContainer = document.getElementById("dialogContainer");
            var powerStripContainer = document.getElementById(objectId);
            if( null != height ) { dialog.setHeight(height); }
            if( null != width ) { dialog.setWidth(width); }
            if( null != title )
            { 
                var headerTable = "<table width=\"340\" border=\"0\" onmouseover=\"this.style.cursor='move'\" cellpadding=\"0\" cellspacing=\"0\"><tr><td width=\'100%\'>" + title + "</td><td><img  id=\"pwdHelpPwrStrip\" style=\"display:none\" alt=\"Help ?\" onmouseover=\"this.style.cursor='help'\" onclick=\"" + helpOpenFunction + "\" src='" + helpImagePowerStrip + "' style=\"float:right\"/></td><td><img id=\"pwdClosepwrStrip\" style=\"display:none\" onmouseover=\"this.style.cursor='pointer'\" onclick=\"HidePowerStrip();\" src='" + closeImagePowerStrip + "' style=\"float:right\"/></td></tr></table>";
                dialog.setCaption(headerTable); 
            }  

            if ('' == eoContainer.innerHTML)
            {
                eoContainer.appendChild(powerStripContainer);          
            }
            
            dialog.show(false);
            dialog.move(200,200);  
            
            eoContainer.style.display = "block";
            
            if ('' != powerStripManageButtonHandler){
                setTimeout(powerStripManageButtonHandler,100);      
            }
        }      
    return false;  
}

//function hides the powerstrip
function HidePowerStrip()
{
    if (IsLoadedPowerStrip)
    {
        var dialog = eo_GetObject("powerStripModalDialog");
        var eoContainer = document.getElementById("dialogContainer");
        eoContainer.style.display = "none";
        setTimeout(powerStripCloseButtonHandler,0);
        
        dialog.close();
    }
    return false;
}

//function to resize the TextGadgetContent.
function ResizeTextContentGadget(lineNumber,textContainerId)
{
    var textContainer = document.getElementById(textContainerId);
    if (null != textContainer)
    {
        var fontSize = parseFloat(getStyle(textContainer, "font-size"));
        
        if ( -1 != navigator.userAgent.indexOf("Firefox") ){
            textContainer.style.height = (lineNumber * (fontSize + 4.25)) + 'px';
        }
        else if (-1 != navigator.appVersion.indexOf("MSIE")){
            textContainer.style.height = (lineNumber * (fontSize + 5)) + 'px';
        }
        else
        {
            textContainer.style.height = (lineNumber * (fontSize + 4.9)) + 'px';
        }    
    }
}

//this function returns a style attribute value.
//oELm: Element that contains the desired style.
//strCssRule: Desired style Attribute
function getStyle(oElm, strCssRule){
	var strValue = "";
	if(document.defaultView && document.defaultView.getComputedStyle){
		strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
	}
	else if(oElm.currentStyle){
		strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
			return p1.toUpperCase();
		});
		strValue = oElm.currentStyle[strCssRule];
	}
	return strValue;
}

//This function show a layer to protected that the user clickss on the powerstrip
function ShowPowerStripProtector(protectorDiv, postBackFunction, display)
{
    var powerStripProtectorLayer = document.getElementById(protectorDiv);
    if (null != powerStripProtectorLayer)
    {
        powerStripProtectorLayer.style.display = display;
        
        if (null != postBackFunction)
            setTimeout(postBackFunction, 400);
    }
    return false;
}


function showAnyDialog(modalDialog, title, contentUrl, height, width )
{ 

    var dialog = eo_GetObject(modalDialog);
    if(null != dialog) 
    {
        
        if( null != title ) { dialog.setCaption(title); }
        if( null != contentUrl ) { dialog.setContentUrl(contentUrl); }
        if( null != height && null != width ) { dialog.setSize(width,height); }
        dialog.show(true);    
    }
    else
    {
        alert('Error, loading the modal dialog');
    }
    return false;  
}

////////////// End dialog function section ////////////////////////////////


// Displays the Share Dialog
// contentTitle: The title of the content to share.
// contentUrl: The url of the content that will be shared.
function showShareDialog(contentTitle, contentUrl, siteId)
{
    var newContentTitle = escape(contentTitle.toString().replace(SingleQuoteCode,"'"));
    var newContentUrl = contentUrl.toString().replace(SingleQuoteCode,"'");    
    var shareDialogUrl = "/Pages/ShareDialog.aspx?Site=" + siteId + "&ContentTitle=" + newContentTitle + "&ContentUrl=" + newContentUrl;
    return showDialog("Share", shareDialogUrl.replace(QuoteCode,"\""));
}

// Displays the Share Dialog
// contentTitle: The title of the content to share.
// contentUrl: The url of the content that will be shared.
// contentPrameters: additional content store parameters that will be passed to ShareDialog.aspx directly
//
// Note! contentTitle and contentUrl must be passed encoded as they are decoded in ShareDialog.aspx with Server.UrlDecode()
function showShareDialogEx(contentTitle, contentUrl, siteId, contentPrameters)
{
    var shareDialogUrl = "/Pages/ShareDialog.aspx?Site=" + siteId + "&ContentTitle=" + contentTitle + "&ContentUrl=" + contentUrl + contentPrameters;
    return showDialog("Share", shareDialogUrl.replace(QuoteCode,"\""));
}

// Displays the Share Dialog
// siteDataListId: The database identifier of the data list for which the subscription will be created.
// alertTitle: The title of the alert to be created.
function showSubscribeDialog(siteDataListId, alertTitle)
{
    var newAlertTitle = alertTitle.toString().replace(SingleQuoteCode,"'");    
    var shareDialogUrl = "/Pages/SubscribeDialog.aspx?SiteDataListId=" + siteDataListId + "&AlertTitle=" + newAlertTitle;    
    return showDialog("Subscribe", shareDialogUrl);
}

function showLoginRegisterSubscribeDialog(siteDataListId, alertTitle)
{
    var newAlertTitle = alertTitle.toString().replace(SingleQuoteCode,"'");    
    var shareDialogUrl = "/Pages/SubscribeLoginRegisterDialog.aspx?SiteDataListId=" + siteDataListId + "&AlertTitle=" + newAlertTitle;    
    return showDialog("Subscribe", shareDialogUrl);
}

// Displays the Save Content Dialog
// contentId: The database identifier of user saved content will be created or edited.
// title: The title of the item to be created.
// url: The Url of the referenced item.
// description: Description of saved reference.
// keywords: Keywords for saved content.
function showSaveContentDialog(contentId, title, url, description, keywords) {
    var saveContentDialogUrl = "/Pages/Dialogs/SavedContentEdit.aspx?contentId=" + contentId + "&title=" + title + "&url=" + url + "&description=" + description + "&keywords=" + keywords;
    return showDialog("Save Content", saveContentDialogUrl);
}


// Displays an alert with the message "Content Saved Successfully." and calls modalDialogAfterCancel
// To be used in the ClientSideAfterUpdate of an EO::CallbackPanel with Add/Edit Modal Dialogs.
function modalDialogAfterUpdate(callback, output, extraData)
{
    window.$clearHandlers(this);
    closeDialog();
}

// This function updates the content of the parent window when a dialog is used
function UpdateParentWindow(buttonClientId)
{
    if (null != buttonClientId)
    {
        if (window.parent)
        {
            var updateButton  = document.getElementById(buttonClientId);
            if (null != updateButton)
            {
                updateButton.click();
            }
        }
    }
} 

// this function display a description in the descriptionContainer in the calendar full page view.
function DisplayDescription(innerHtml)
{
    var descriptionContainer = document.getElementById('descriptionContainer');
    
    if(null != descriptionContainer)
    {
        descriptionContainer.innerHTML = innerHtml;
    }
}

// This function clears the description container for a claendar event.
function ClearDescription()
{
    var descriptionContainer = document.getElementById('descriptionContainer');
    
    if(null != descriptionContainer)
    {
        descriptionContainer.innerHTML = "";
    }
}

// Function to update calendar events from the current calendar page.
function UpdateButtonClick(buttonClientId)
{
    if (null != buttonClientId)
    {
        var updateButton  = document.getElementById(buttonClientId);
        if (null != updateButton)
        {
            updateButton.click();
        }
    }
}

// This function set the values SiteCollection, ContentStoreListId, ContentStoreSiteId and ListItemId in a hiddenField that will be
// read for the edit button and delete button in the calendar.aspx to get these values.
function showEventInformation(innerHtml, hiddenFieldValues, hiddenFieldId, editButtonId, deleteButtonId, changeViewId, changeViewText, isEditor)
{
    DisplayDescription(innerHtml);
    
    showEditCalendarEventButtons(editButtonId, deleteButtonId, changeViewId, changeViewText, isEditor);
    
    var hiddenField = document.getElementById(hiddenFieldId);
    
    if(null != hiddenField)
    {
        hiddenField.value = hiddenFieldValues;
    }
}

// This function display the edit and delete buttons in the calendar full page view.
function showEditCalendarEventButtons(editButtonId, deleteButtonId,changeViewId, changeViewText, isEditor)
{
    if(null == isEditor)
    {
        isEditor = "0";
    }
    var editButton = document.getElementById(editButtonId);
    var deleteButton = document.getElementById(deleteButtonId);
    var changeViewButton = document.getElementById(changeViewId);
    
    if("1" == isEditor)
    {
        if(null != editButton)
        {
            editButton.style.display = "block";
        }
        
        if(null != deleteButton)
        {
            deleteButton.style.display = "block";
        }
        
        if (null != changeViewButton)
        {
            if (changeViewText != '')
            {
                changeViewButton.innerHTML = changeViewText;
                changeViewButton.style.display = "block";
            }else{
                changeViewButton.style.display = "none";
                changeViewButton.innerHTML = '';
            }
        }
    }
    else
    {
        if(null != editButton)
        {
            editButton.style.display = "none";
        }
        
        if(null != deleteButton)
        {
            deleteButton.style.display = "none";
        }
        
        if (null != changeViewButton)
        {
            changeViewButton.style.display = "none";
            changeViewButton.innerHTML = '';
        }
    }
}

//this function detects if enter key was pressed. 
//add this attribute to your textbox   onkeypress="return textBoxEnter(event,'tetboxId','buttonId');" 
function textBoxEnter(e, txtSendId, postButtonId, url, title) {
    var textbox =  document.getElementById(txtSendId)
    var button =  document.getElementById(postButtonId)
    var code='';
    if (window.event) {
        code = event.keyCode;
    }
    else 
    {
        code= e.which;
    }
    if (code==13)
    {
        if (textbox.value != "")
        {
            if (button)
                button.click();
            else
            {
                url = url + '&q=' + textbox.value;
                openInNewTab(url, title, "");
                return false;
            }
        }
        else
        {
            textbox.value = '';
            if (window.event) {
                e.cancelBubble = false;
            }
            else {
                e.stopPropagation();
            }                  
        }
    }
    return true;
}

//Show flog content
function ShowBlogContent()
{
    var container = document.getElementById('textBlogContent');
    
    if(null != container)
    {
        container.style.height = 'auto';
    }
}

function openSearchInNewTab(url, textboxId, groupsId, newsId, webId, documentId, title)
{
    if (null == url)
        return;
        
    var textBox = document.getElementById(textboxId);
    if (null == textBox)
        return;
        
    if ("" == textBox.value)
        return false;

    openInNewTab(url + "&q=" + textBox.value, title, title);
}


var timerID;

function ShowLayer(id)
{
  document.getElementById(id).style.display = "block"; 
}

function HideTimedLayer(id)
{  
    clearTimeout(timerID);
    document.getElementById(id).style.display = "none";
}

function timedLayer(id)
{
  ShowLayer(id);
  setTimeout("HideTimedLayer(\"" + id + "\")",5000); //5000= 5 seconds
}
