
///Toggles the display of a div element from "block" to "none" and vice versa
//PARAM "divId" = the unique id of the div element to toggle
//PARAM "linkRef" = a reference to the link that called this function
//PARAM "hiddenHTML" = the link's innerHTML when the div is hidden
//PARAM "visibleHTML" = the link's innerHTML when the div is visible
function ToggleDivDisplay(divId, linkRef, hiddenHTML, visibleHTML)
{
    var divRef = document.getElementById(divId);
    
    var currentDisplay = divRef.style.display;
    
    if (currentDisplay == "block")//display is visible (block) so make it hidden (none)
    {
        divRef.style.display = "none";
        
        //change the link text
        linkRef.innerHTML = hiddenHTML;
        
    }
    else//display is none so make it visible
    {
        divRef.style.display = "block";
        
        //change the link text
        linkRef.innerHTML = visibleHTML;
    }
}//end of ToggleDivDisplay



///Toggles the display of a div element from "block" to "none" and vice versa, and also another div to the oposite of that
//PARAM "divId" = the unique id of the div element to toggle
//PARAM "divId2" = the unique id of the other div element to toggle
//PARAM "linkRef" = a reference to the link that called this function
//PARAM "div1LinkHTML" = the link's innerHTML when the div1 is hidden
//PARAM "div2LinkHTML" = the link's innerHTML when the div2 is visible
function swapDivDisplay(divId1, divId2, linkRef, div1LinkHTML, div2LinkHTML)
{
    var divRef = document.getElementById(divId1);
    
    var currentDisplay = divRef.style.display;
    
    if (currentDisplay == "block")//display is visible (block) so make it hidden (none)
    {
        divRef.style.display = "none";
        
        ToggleDivDisplay(divId2, linkRef, "", div2LinkHTML);
    }
    else//display is none so make it visible
    {
        document.getElementById(divId2).style.display = "none";
        
        ToggleDivDisplay(divId1, linkRef, "", div1LinkHTML);
    }
}//end of swapDivDisplay


///Toggles between two div tags switching their CSS display properties from none and block, to block and none
///PARAM "divId1" = the unique id of the div element to toggle to display:block
///PARAM "divId2" = the unique id of the div element to toggle to display:none
function switchDivDisplay(divId1, divId2)
{
    document.getElementById(divId1).style.display = "block";
    document.getElementById(divId1).style.visibility = "visible";
    document.getElementById(divId2).style.display = "none";
    document.getElementById(divId2).style.visibility = "hidden";
}


///Toggles the display of a div element from "block" to "none" and vice versa, and also another div to the oposite of that
//PARAM "divId" = the unique id of the div element to toggle
//PARAM "divId2" = the unique id of the other div element to toggle
//PARAM "buttonRef" = a reference to the button that called this function
//PARAM "buttonValue1" = the value to set to the buttons value attribute when div 1 is selected
//PARAM "buttonValue2" = the value to set to the buttons value attribute when div 2 is selected
function swapDivButtonDisplay(divId1, divId2, buttonRef, buttonValue1, buttonValue2)
{
    var divRef1 = document.getElementById(divId1);
    var divRef2 = document.getElementById(divId2);
    var currentDisplay = divRef1.style.display;
    
    if (currentDisplay == "block")
    {
        divRef1.style.display = "none";
        divRef2.style.display = "block";
        buttonRef.value = buttonValue2;
    }
    else
    {
        divRef1.style.display = "block";
        divRef2.style.display = "none";
        buttonRef.value = buttonValue1;
    }
    
}//end of swapDivButtonDisplay



function MakeDivInvisible(divId)
{
	document.getElementById(divId).style.visibility = "hidden";
}//end of MakeDivInvisibe


function MakeDivVisible(divId)
{
	document.getElementById(divId).style.visibility = "visible";
	
}//end of MakeDivVisibe



///will hold a reference to the current content management element beind edited
var currentContentManagementEditElement;


///Show the Upload Image window so that a user can upload an image
//PARAM "objectType" = the type of object we are uploading for
//PARAM "objectId" = the unique ID of the object we are uploading for
//PARAM "maxImageWidth" = the maximum width that the image will be resized down to
//PARAM "maxImageHeight" = the maximum height that the image will be resized down to
//PARAM "maxFileSize" = the maximum file size in kb that the image will be compressed down to
function ShowUploadImageWindow(objectType, objectId, maxImageWidth, maxImageHeight, maxFileSize)
{
	var editElement = document.selection.createRange().parentElement();

    if (!editElement.isContentEditable){
        //its not editable
        alert("You cannot insert an image unless you place your cursor within the textbox for the content");
        return;
    }
	var url = "/includes/UploadImage.aspx?foreignType=" + objectType + "&foreignId=" + objectId + "&maxImageWidth=" + maxImageWidth + "&maxImageHeight=" + maxImageHeight + "&maxFileSize=" + maxFileSize + "&action=use";
	currentContentManagementEditElement = document.selection.createRange();
    window.open(url, "", "resizable=yes,scrollbars=yes,width=470,height=200");
}//end of ShowUploadImageWindow



function pasteImageHTMLIntoLastContentPlace(html)
{
    currentContentManagementEditElement.pasteHTML(html);
}//end of pasteImageHTMLIntoLastContentPlace



///Shows one div and hides the other divs. This also assumes that there are "tabs" which you can click to represent the divs. The class
///of the tabs will be changed for the one that is shown and the ones that are hidden to "ActiveTab" and "InactiveTab" respectively
//PARAM "divIdToShow" = the unique id of the div element to show
//PARAM "divsIdToHide" = and array of strings containing the unique ids of the div elements to hide
//PARAM "activeTabID" = the unique ID of the tab div that is now the active tab, corresponding to the active div to show
//PARAM "inactiveTabIDs" = a string array containing the unique ids of the tabs to make inactive
function ShowDivAndHideMultipleDivs(divIdToShow, divIdsToHide, activeTabID, inactiveTabIDs)
{
    for(i = 0; i < inactiveTabIDs.length; i++)
    {
        document.getElementById(inactiveTabIDs[i]).className = "InactiveTab";
    }
    
    
    for(i = 0; i < divIdsToHide.length; i++)
    {
        document.getElementById(divIdsToHide[i]).style.display = "none";
    }
    
    var activeTab = document.getElementById(activeTabID);
    activeTab.className = "ActiveTab";
    
    document.getElementById(divIdToShow).style.display = "Block";

}//end of ShowDivAndHideMultipleDivs




function DivToShowAndHideGrey(divIdToHide, divIdToShow, InactiveTabColor, ActiveTabColor, Tabs)
{
    for(i=5; i < arguments.length; i++)
    {
        //document.getElementById(arguments[i]).style.backgroundColor= InactiveTabColor;
        document.getElementById(arguments[i]).className= "InactiveGreyTab";
    }
    
    var myTab = document.getElementById(Tabs);
    document.getElementById(divIdToHide).style.display ="none";
    document.getElementById(divIdToShow).style.display="Block";
    myTab.className="ActiveGreyTab";
    
    
}//end of DivToShowAndHideGrey


function SwapPrimaryHeaderTab(headerId, isLeft, divToShow, divToHide)
{
	if (isLeft)
		document.getElementById(headerId).className = "PrimaryHeaderLeftActive";
	else
		document.getElementById(headerId).className = "PrimaryHeaderRightActive";
		
	document.getElementById(divToShow).style.display = "block";
	document.getElementById(divToHide).style.display = "none"
}//end of SwapPrimaryHeaderTab



///This is to quote the selected text in an editable element. But usually used just when editing blogs
function QuoteSelectedEditableText()
{
	//this will first check if the element is editable
	var textRange = document.selection.createRange();
    var editElement = textRange.parentElement();

    if (!editElement.isContentEditable){
        //its not editable
        return;
    }
    
   
    textRange.pasteHTML("<table class='QuoteText'><tr><td class='QuoteTextLeft'>&nbsp;</td><td class='QuoteTextMain'>" + textRange.text + "</td><td class='QuoteTextRight'>&nbsp;</td></tr></table>");


}//end of QuoteSelectedEditableText






/* ####  POPUP CONTROL FUNCTIONS  #### */

function ToggleUiLockOn(check)                              { var ui = $get("Main"); var op = 100; if(check) op = 20; ui.style.filter = "alpha(style = 0, opacity:" + op + ")"; ui.style.MozOpacity = op / 100; ui.style.opacity = op / 100; }
function showLoginPopup()                                   { var popupTitle = "Please Login"; if (arguments.length > 0) popupTitle = arguments[0]; showCpPopup("/includes/popups/login.aspx", popupTitle, 600, 230); }
function showMemberSignupPopup()                            { var signupURL = "/Includes/Popups/MemberSignup.aspx"; if (arguments.length > 0) signupURL += "?display=" + arguments[0]; showCpPopup(signupURL, "New Clubplanet member signup", 750, 600); }
function showMemberActivationCodePopup()                    { showCpPopup("/Includes/Popups/MemberActivation.aspx", "Activate You Membership", 500, 200); }
function showForgotPasswordPopup()                          { showCpPopup("/Includes/Popups/ForgotPassword.aspx", "Forgot your password?", 500, 200); }
function showGuestlistPopup(eventId)                        { showCpPopup("/Includes/Popups/guestlistsignup.aspx?eventId=" + eventId, "Sign up for this guestlist", 400, 250); }
function showEventRSVPPopup(eventId)                        { showCpPopup("/Includes/Popups/guestlistsignup.aspx?eventId=" + eventId, "Add Event to My Calendar", 350, 250); }
function showMeetupSetupPopup(foreignType, foreignKeyId, popupHeaderText)    { showCpPopup("/Includes/Popups/MeetupSetup.aspx" + "?foreignType=" + foreignType + "&foreignKeyId=" + foreignKeyId, popupHeaderText, 500, 375); }
function showSendToAFriendPopup(url, objectText)            { showCpPopup("/Includes/Popups/SendToFriend.aspx?url=" + url + "&objectText=" + objectText, "Send to a Friend", 500, 250); }
function showZipUploadStatusPopup(progressIdInt)            { showCpPopup("/Includes/Popups/ZipProgressStatus.aspx?progressId=" + progressIdInt, "Uploading Zip File... please wait", 400, 200); }
function showPopUpMessagePopup(message)                     { window.open("/Includes/Popups/ShowPopupMessage.aspx?message=" + message, "myWin", "menubar=0,resizable=0,width=800,height=450"); }
function showPrivateMessagePopup(messageId)                 { showCpPopup("/Includes/Popups/ShowPrivateMessage.aspx?messageId=" + messageId, "Message", 600, 400); }


/* ####  MENU CONTROL FUNCTIONS  #### */

var lastMenuShown;
var hideMenuTimeout;

function menuLinkOver(menuItemLink) { window.clearTimeout(hideMenuTimeout); if (lastMenuShown) { lastMenuShown.style.display = 'none' }; lastMenuShown = menuItemLink.parentNode.getElementsByTagName('ul')[0]; lastMenuShown.style.display = 'block'; }
function menuLinkOut(menuItemLink) { hideMenuTimeout = setTimeout("hideLastMenuItem()", 250); }
function hideLastMenuItem() { if (lastMenuShown) lastMenuShown.style.display = 'none'; }


