﻿
function ShowMediaModal(ActiveMediaType, ActiveMediaFile, ActiveMediaGallery, ActiveModalControl, ActiveModalHeader) 
{
/*    This is for addressing groups.
    Sys.Services.ProfileService.properties.DiscussionCenter = new Sys.Services.ProfileGroup();
    Sys.Services.ProfileService.properties.DiscussionCenter.Guid = recsGuid;
*/
    
    Sys.Services.ProfileService.properties.ActiveMediaType = ActiveMediaType;
    Sys.Services.ProfileService.properties.ActiveMediaFile = ActiveMediaFile;
    Sys.Services.ProfileService.properties.ActiveMediaGallery = ActiveMediaGallery;
    Sys.Services.ProfileService.properties.ActiveModalControl = ActiveModalControl;
    Sys.Services.ProfileService.properties.ActiveModalHeader = ActiveModalHeader;
    
    Sys.Services.ProfileService.save(null, OnSaveCompleted, OnProfileFailed, null);    
    
    var img = document.getElementById("ModalHeaderImg");
    switch (ActiveMediaType)
    {
        case "Audio": 
            img.src = FilePath+"Images/FP_MT_audio.gif";
        break;
        case "Video": 
            img.src = FilePath+"Images/FP_MT_video.gif";
        break;
        case "Photo": 
            img.src = FilePath+"Images/FP_MT_photos.gif";
        break;
        default:
        break;
    }
    
    
}

function CloseMediaModal() 
{

    Sys.Services.ProfileService.properties.ActiveMediaType = "";
    Sys.Services.ProfileService.properties.ActiveMediaFile = "";
    Sys.Services.ProfileService.properties.ActiveMediaGallery = "";
    Sys.Services.ProfileService.properties.ActiveModalControl = "~/UserControls/Stub.ascx";
    Sys.Services.ProfileService.properties.ActiveModalHeader = "";
    
    Sys.Services.ProfileService.save(null, OnSaveCloseCompleted, OnProfileFailed, null);       
    
}


function ShowMySiteMediaModal(ActiveMediaType, ActiveMediaFile, ActiveMediaGallery, ActiveModalControl, ActiveModalHeader) 
{

/*    This is for addressing groups.
    Sys.Services.ProfileService.properties.DiscussionCenter = new Sys.Services.ProfileGroup();
    Sys.Services.ProfileService.properties.DiscussionCenter.Guid = recsGuid;
*/
    
    Sys.Services.ProfileService.properties.ActiveMediaType = ActiveMediaType;
    Sys.Services.ProfileService.properties.ActiveMediaFile = ActiveMediaFile;
    //For MySites its the MySite GUID
    Sys.Services.ProfileService.properties.ActiveMediaGallery = ActiveMediaGallery;
    Sys.Services.ProfileService.properties.ActiveModalControl = ActiveModalControl;
    Sys.Services.ProfileService.properties.ActiveModalHeader = ActiveModalHeader;
    
    Sys.Services.ProfileService.save(null, OnSaveCompleted, OnProfileFailed, null);    

    var img = document.getElementById("ModalHeaderImg");
    switch (ActiveMediaType)
    {
    
        case "Audio": 
            img.src = FilePath+"Images/FP_MT_audio.gif";
        break;
        case "MySiteVideo": 
            img.src = FilePath+"Images/FP_MT_video.gif";
        break;
        case "MySitePhoto": 
            img.src = FilePath+"Images/FP_MT_photos.gif";
        break;
        default:
        break;
    }
    
    
}

function ShowProfileModal(leftSectionOrd, tabStripActiveItemOrd, profileSiteGuid) 
{



    Sys.Services.ProfileService.properties.ActiveModalControl = "~/UserControls/ProfileContainer.ascx";    
    Sys.Services.ProfileService.properties.ActiveProfileSection = leftSectionOrd;
    Sys.Services.ProfileService.properties.ActiveModalProfile = profileSiteGuid;
    
    Sys.Services.ProfileService.properties.ActiveProfileTab = tabStripActiveItemOrd;
    
    Sys.Services.ProfileService.save(null, OnSaveCompleted, OnProfileFailed, null);  
 
    var img = document.getElementById("ModalHeaderImg");
    img.src = FilePath+"Images/FP_MT_profile.gif";

   
    
}

//function ShowProfileModal(leftSectionOrd, tabStripActiveItemOrd) 
//{



//    Sys.Services.ProfileService.properties.ActiveModalControl = "~/UserControls/ProfileContainer.ascx";    
//    Sys.Services.ProfileService.properties.ActiveProfileSection = leftSectionOrd;
//    Sys.Services.ProfileService.properties.ActiveProfileTab = tabStripActiveItemOrd;
//    
//    Sys.Services.ProfileService.save(null, OnSaveCompleted, OnProfileFailed, null);  
// 
//    var img = document.getElementById("ModalHeaderImg");
//    img.src = FilePath+"Images/FP_MT_profile.gif";

//   
//    
//}

function OnSaveCompleted(numProperties, userContext, methodName)
{

    __doPostBack('ctl00_MediaContaner1_upnModalContent','');   
    var b = $find("ModalContainer");
    b.show();
}

function OnSaveCloseCompleted(numProperties, userContext, methodName)
{
    __doPostBack('ctl00_MediaContaner1_upnModalContent','');   
}

function OnProfileFailed(error_object, userContext, methodName){}


function Search()
{
    uurl = FilePath+'Search/Default.aspx?q='+ document.forms[0].q.value +'&output=xml_no_dtd&oe=UTF-8&ie=UTF-8&client=FreedomProject_frontend&site=FreedomProject';
    window.document.location.href=uurl;
}

function BlogSearch()
{
    uurl = FilePath+'Search/Default.aspx?q='+ document.forms[0].blog_q.value +'&output=xml_no_dtd&oe=UTF-8&ie=UTF-8&client=FreedomProject_Blog&site=FreedomProject';
    window.document.location.href=uurl;
}
function NewsSearch()
{
    uurl = FilePath+'Search/Default.aspx?q='+ document.forms[0].news_q.value +'&output=xml_no_dtd&oe=UTF-8&ie=UTF-8&client=FreedomProject_News=FreedomProject';
    window.document.location.href=uurl;
}
function NewsAdvSearch()
{
    uurl = FilePath+'Search/Default.aspx?q='+ document.forms[0].newsadv_q.value +'&output=xml_no_dtd&oe=UTF-8&ie=UTF-8&client=FreedomProject_News&site=FreedomProject';
    window.document.location.href=uurl;
}

        
var InFormName = '';
function CaptureKeyPress(e) 
{
    var keynum;
    if(window.event) 
    {
        keynum = e.keyCode;
    }
    else if(e.which) 
    {
        keynum = e.which;
    }

    if ((keynum == 13) && InFormName != '') 
    {
       switch (InFormName)
       {
        case 'Search':
            Search();
            break;
        case 'BlogSearch':
            BlogSearch();
            break;
        case 'NewsSearch':
            NewsSearch();
            break;
        case 'NewsAdvSearch':
            NewsAdvSearch();
            break;

        }
       return false;
    } 
    else
    {
        return true;
    }
}

function CaptureKeyPressAll(e) 
{
    var keynum;
    if(window.event) 
    {
        keynum = e.keyCode;
    }
    else if(e.which) 
    {
        keynum = e.which;
    }

    if ((keynum == 13) && InFormName != '') 
    {
       return false;
    }

}

function OverrideLinks(divID, target)
{
    var Area = document.getElementById(divID);
    var Links = Area.getElementsByTagName('a');
    for(i=0; i< Links.length; i++)
    {
        Links[i].target = target;     
    }

} 

function CopyToClipboard(objId)
{
    fnSelect(objId);
    if (document.selection) 
    {
       CopiedTxt = document.selection.createRange();
       CopiedTxt.execCommand("Copy");
    }
    else if (window.getSelection)
	{
       CopiedTxt = window.getSelection();
       //CopiedTxt.execCommand("Copy");
    }
}

function fnSelect(objId) 
{
	fnDeSelect();
	if (document.selection) {
	var range = document.body.createTextRange();
        range.moveToElementText(document.getElementById(objId));
	range.select();
	}
	else if (window.getSelection) {
	var range = document.createRange();
	range.selectNode(document.getElementById(objId));
	window.getSelection().addRange(range);
	}
}
		
function fnDeSelect() 
{
	if (document.selection) document.selection.empty(); 
	else if (window.getSelection)
            window.getSelection().removeAllRanges();
}

function MediaChangeRightSide(showDiv)
{
    // hide all
    document.getElementById('OtherFiles').style.display = 'none';    
    document.getElementById('DiscussIt').style.display = 'none';
    document.getElementById('ForwardToFriend').style.display = 'none';
    // show one
    document.getElementById(showDiv).style.display = 'block';

}

function MediaChangeDiv(showDiv)
{
    var obj =  document.getElementById(showDiv);
    //alert(obj.style.display);
    if (obj.style.display == 'none')
        obj.style.display = 'block';
    else
        obj.style.display = 'none';
}