/*
Buzdeo Scripts (c) xeinet media Inc 2007

*/


//MemberVideo Ajax calls

//Vars used to persist current media settings
var currentMediaId;
var currentTab;
var currentPage;

function ReturnToTab()   {SetTabInfo(currentTab,currentMediaId,currentPage);}

//Standard Error Out message box
function OnCallError(error,userContext,methodName)
{
                if(error !== null){
                 //    txtresult.innerHTML = "Cannot Details on this video, try refreshing this page";
                    alert(error.get_message());
                    }
 }

//Pause Video
function Pause()
{
  var txtresult =  document.getElementById('ctl00_ContentPlaceHolder1_lbInfo');
  PageMethods.PauseVideo(currentMediaId,OnPauseComplete,OnCallError,txtresult);
  
  

}

function OnPauseComplete(result,txtresult,methodName){
	 txtresult.innerHTML = result;
	 document.getElementById('ctl00_ContentPlaceHolder1_lbTabInfo').innerHTML = GetTabInfo(0,currentMediaId);
}

/////////////////////////////////////////////END PAUSE VIDEO///////////////////////////////////////////////


/////////////////////////////////////////////////BEGIN TOGGLE PUBLIC///////////////////////////////////////

//Toggle Public Video
function TogglePublic()
{
  var txtresult =  document.getElementById('ctl00_ContentPlaceHolder1_lbInfo');
  PageMethods.MakePublic(currentMediaId,OnPublicComplete,OnCallError,txtresult);
}

function OnPublicComplete(result,txtresult,methodName){
	 txtresult.innerHTML = result;
	 document.getElementById('ctl00_ContentPlaceHolder1_lbTabInfo').innerHTML = GetTabInfo(0,currentMediaId);
}
/////////////////////////////////////////////END TOGGLE PUBLIC///////////////////////////////////////////////


function Delete()
{
   window.location = "./DeleteVideo.aspx?i=" + currentMediaId;

}


function VideoEcard()
{
   window.location = "./MemberVideoECard.aspx?i=" + currentMediaId;

}



/////////////////////////////////////////////////BEGIN DYNAMIC TAB FOR INFO AREA////////////////////////////

//Create Dynamic Tab for video Info Area
function GetTabInfo(tab,mediaId)
{
    var html = "";
    
    

    switch(tab)
    {
    
    case 0: //This videoTab
    
   html = "<table cellpadding=0 cellspacing=0 style='width: 100%; height: 19px'><tr>" + 
            "<td class=nounderlinehl align='center' style='color:#696969; width: 100px'>This video</td>" + 
            "<td class=nounderlinehl align='center' style='background-image: url(i/TabBackSilver.gif); border-right : gainsboro 1px solid; border-left: gainsboro 1px solid;width: 100px'>" + 
            "<A href='Javascript:SetTabInfo(3," + mediaId + ",1);' />Comments</A></td>" + 
            "<td class=nounderlinehl align='center' style='width: 100px;background-image: url(i/TabBackSilver.gif);'>" + 
            "<A href='Javascript:SetTabInfo(2," + mediaId + ",1);' />View History</A></td></tr></table>";
 
        break;
    
   
     
     case 2:
     
     
      html = "<table cellpadding=0 cellspacing=0 style='width: 100%; height: 19px'><tr>" + 
             "<td class=nounderlinehl align='center' style='background-image: url(i/TabBackSilver.gif); width: 100px'>" + 
             "<A href='Javascript:SetTabInfo(0," + mediaId + ",1);' />This video</A></td>" + 
             "<td class=nounderlinehl align='center' style='background-image: url(i/TabBackSilver.gif); border-right : gainsboro 1px solid; border-left: gainsboro 1px solid;width: 100px'>" + 
             "<A href='Javascript:SetTabInfo(3," + mediaId + ",1);' />Comments</A></td>" + 
             "<td class=nounderlinehl align='center' style='color:#696969; width: 100px;'>View History</td></tr></table>";
        break;
   
    case 3:
    
         html = "<table cellpadding=0 cellspacing=0 style='width: 100%; height: 19px'><tr>" + 
                "<td class=nounderlinehl align='center' style='background-image: url(i/TabBackSilver.gif); width: 100px'>" + 
                "<A href='Javascript:SetTabInfo(0," + mediaId + ",1);' />This video</A></td>" + 
                "<td class=nounderlinehl align='center' style='color:#696969; border-right : gainsboro 1px solid; border-left: gainsboro 1px solid;width: 100px'>" + 
                " Comments</td>" + 
                "<td class=nounderlinehl align='center' style='width: 100px;background-image: url(i/TabBackSilver.gif);'>" + 
                "<A href='Javascript:SetTabInfo(2," + mediaId + ",1);' />View History</A></td></tr></table>";
        break;
   
   
    }

return html;


}


//Create Dynamic Tab for video Info Area
function GetTabInfoPublic(tab,mediaId)
{
    var html = "";
    
    

    switch(tab)
    {
    
    case 0: //This videoTab
    
   html = "<table cellpadding=0 cellspacing=0 style='width: 100%; height: 19px'><tr>" + 
            "<td class=nounderlinehl align='center' style='color:#696969; width: 50%'>This video</td>" + 
            "<td class=nounderlinehl align='center' style='background-image: url(i/TabBackSilver.gif); border-right : gainsboro 1px solid; border-left: gainsboro 1px solid;width: 50%'>" + 
            "<A href='Javascript:SetTabInfo(3," + mediaId + ",1);' />Comments</A></td>" + 
            "</tr></table>";
 
        break;
    
   
     
     case 2:
     
     
      html = "<table cellpadding=0 cellspacing=0 style='width: 100%; height: 19px'><tr>" + 
             "<td class=nounderlinehl align='center' style='background-image: url(i/TabBackSilver.gif); width: 50%'>" + 
             "<A href='Javascript:SetTabInfo(0," + mediaId + ",1);' />This video</A></td>" + 
             "<td class=nounderlinehl align='center' style='background-image: url(i/TabBackSilver.gif); border-right : gainsboro 1px solid; border-left: gainsboro 1px solid;width: 50%'>" + 
             "</tr></table>";
        break;
   
    case 3:
    
         html = "<table cellpadding=0 cellspacing=0 style='width: 100%; height: 19px'><tr>" + 
                "<td class=nounderlinehl align='center' style='background-image: url(i/TabBackSilver.gif); width: 50%'>" + 
                "<A href='Javascript:SetTabInfo(0," + mediaId + ",1);' />This video</A></td>" + 
                "<td class=nounderlinehl align='center' style='color:#696969; border-right : gainsboro 1px solid; border-left: gainsboro 1px solid;width: 50%'>" + 
                " Comments</td>" + 
                "</tr></table>";
        break;
   
   
    }

return html;


}

////////////////////////////////////////////END DYNAMIC TAB FOR INFO AREA////////////////////////////////


////////////////////////////////////////////BEGIN GET MEMBER NETWORK/////////////////////////////////////


//Get the network share list and display in drop down
function ShareNetwork()
{
 var txtresult =  document.getElementById(txtInfo);
 PageMethods.GetShareNetwork(mid,OnShareNetworkComplete,OnCallError,txtresult);

}



//We will receive a comma separated 2d array, split up and add to drop down
function OnShareNetworkComplete(result,txtresult,methodName)
{
    
    //Split up the returned list and create drop down list
    var array = result.split("#");
    var dlHtml = "<select id=dlNetwork style='width: 150px;' >";
    for (var i = 0 ; i < array.length;i++)
     {  var itm = array[i].split("|");
        dlHtml = dlHtml + "<option value='" + itm[0] + "' >" + itm[1] + "</option>";
     }  
     
     dlHtml = dlHtml + "</select>";

		  var sBody = "<BR><BR><table style='width: 100%; font-size: 8pt;border-top: gainsboro 1px solid;border-bottom: gainsboro 1px solid; color: #393938; height: 193px;'>" +
                   "<tr><td align=right>" +
                   "<a style='font-size:6pt; text-decoration:none; font-weight:bold; color: #003399; font-family: Arial;' href='javascript:ReturnToTab();'>" +
                   "CLOSE X</A></td></tr><tr><td valign=top>" +
                   "Select a network group to share this video with:<br />" +
                   "</td>" +
                   "</tr><tr><td>" + dlHtml +  "&nbsp;<A target=_blank HREF=memberNetwork.aspx >Add New</A><br />" +
                   "Add a short message with the shared video:<BR/>" +
                   "<textarea id='txtMessage'  width=260 cols='47' rows='2' style='width:260;height:70px;font-family:helvetica;font-size:8pt;  border-right: gainsboro 1px solid; " + 
                   " border-top: gainsboro 1px solid; border-left: gainsboro 1px solid; border-bottom: gainsboro 1px solid' ></textarea>" + 
                   "</td>" +
                   "</tr><tr><td style='height: 20px' valign='top'>" + 
                   "</td></tr><tr><td style='height: 20px' valign='top'>" + 
                    "<a style='font-size:8pt; text-decoration:none; font-weight:bold; color: #003399; font-family: Arial;' href='javascript:SendNetworkLink();'>" +
                   "send</A> | " +
                   "<a style='font-size:8pt; text-decoration:none; font-weight:bold; color: #003399; font-family: Arial;' href='javascript:ReturnToTab();'>" +
                   "cancel</A></td></tr></table>";
                
        //add format html 
        txtresult.innerHTML = sBody;
  
		
  }

//Function calls for saving Title Etc
function SendNetworkLink()
{
  var txtresult =  document.getElementById(txtInfo);
  //Values of edited text
  var NetworkId =   document.getElementById('dlNetwork').options[document.getElementById('dlNetwork').selectedIndex].value;  //Need to work out how to get
  var txtMessage  = document.getElementById('txtMessage').value;
       
  PageMethods.SendNetworkLink(currentMediaId,NetworkId,txtMessage,OnNewtworkLinkComplete,OnCallError,txtresult);
    
}

function OnNewtworkLinkComplete(result,txtresult,methodName){
		 ReturnToTab(); 
		 alert(result); 
		 // txtresult.innerHTML = result;
  }  



////////////////////////////////////////////END MEMBER NETWORK//////////////////////////////////////////





////////////////////////////////////////////BEGIN OBJECT LINK CODE///////////////////////////////////////


function GetObjectEmbed()
{
  var txtresult =  document.getElementById(txtInfo);
  PageMethods.GetEmbedCode(currentMediaId,OnEmbedCodeComplete,OnCallError,txtresult);
    
}

function OnEmbedCodeComplete(result,txtresult,methodName)
{
		  var html = "<BR><BR><table style='width: 100%; font-size: 8pt;border-top: gainsboro 1px solid;border-bottom: gainsboro 1px solid; color: #393938; height: 193px;'>" +
                   "<tr><td align=right>" +
                   "<a style='font-size:6pt; text-decoration:none; font-weight:bold; color: #003399; font-family: Arial;' href='javascript:ReturnToTab();'>" +
                   "CLOSE X</A></td></tr><tr><td valign=top>" +
                   "Copy the code below to embed the video player directly into a webpage or blog. <A HREF='TutorialLinking.aspx' target='_blank' >(Learn)</A><br />" +
                   "</td>" +
                   "</tr><tr><td>embed video: <A href=javascript:ClipBoard('txtEmbed'); > <IMG border=0 align=absmiddle src=i/copy_text.gif /></A> <br />" +
                   "<textarea id='txtEmbed' TITLE='Right click and copy'  width=260 cols='47' rows='2' onClick=javascript:selectText('txtEmbed');   style='width:260;height:70px;font-family:helvetica;font-size:8pt;  border-right: gainsboro 1px solid; " + 
                   " border-top: gainsboro 1px solid; border-left: gainsboro 1px solid; border-bottom: gainsboro 1px solid' ></textarea>" + 
                   "</td>" +
                   "</tr><tr><td style='height: 20px' valign='top'>" + 
                   "</td></tr></table>";
                   
        //add format html 
        txtresult.innerHTML = html;
        
        //add result / object code to text area
        document.getElementById('txtEmbed').value = result;
		
  }
  
/////////////////////////////////////////////END OBJECT LINK CODE////////////////////////////////////////////





////////////////////////////////////////////BEGIN SEND EMAIL FUNCTIONS ///////////////////////////////////////

//Email Video Link Screen
function ShowEmailVideo()
{

    var pz = document.getElementById(txtInfo);
        var html = "<BR><BR><table style='width: 100%; font-size: 8pt;border-top: gainsboro 1px solid;border-bottom: gainsboro 1px solid; color: #393938; height: 193px;'>" +
                   "<tr><td align=right>" +
                   "<a style='font-size:6pt; text-decoration:none; font-weight:bold; color: #003399; font-family: Arial;' href='javascript:ReturnToTab();'>" +
                   "CLOSE X</A></td></tr><tr><td valign=top>" +
                   "email this video to: (seperate with commas)<br />" +
                   "<input id='txtEmail' maxlength=100 width=200 style='width:250;border-right: gainsboro 1px solid; border-top: gainsboro 1px solid; " +
                   " border-left: gainsboro 1px solid; border-bottom: gainsboro 1px solid; height: 20px' type='text' />" +
                   "</td>" +
                   "</tr><tr><td>enter a personalized message:<br />" +
                   "<textarea id='txtmessage' width=250 cols='45' rows='2' style='width:250;height:70px;font-family:helvetica;font-size:9pt;  border-right: gainsboro 1px solid; " + 
                   " border-top: gainsboro 1px solid; border-left: gainsboro 1px solid; border-bottom: gainsboro 1px solid' ></textarea>" + 
                   "</td>" +
                   "</tr><tr><td style='height: 20px' valign='top'>" + 
                    "<a style='font-size:8pt; text-decoration:none; font-weight:bold; color: #003399; font-family: Arial;' href='javascript:SendEmailLink();'>" +
                   "send</A> | " +
                   "<a style='font-size:8pt; text-decoration:none; font-weight:bold; color: #003399; font-family: Arial;' href='javascript:ReturnToTab();'>" +
                   "cancel</A></td></tr></table>";
        
        pz.innerHTML = html;


}

//Function calls for saving Title Etc
function SendEmailLink()
{
  var txtresult =  document.getElementById(txtInfo);
  //Values of edited text
  var txtEmail =   document.getElementById('txtEmail').value;
  var txtMessage  = document.getElementById('txtmessage').value;
       
  PageMethods.SendEmailLink(currentMediaId,txtEmail,txtMessage,OnEmailLinkComplete,OnCallError,txtresult);
    
}

function OnEmailLinkComplete(result,txtresult,methodName){
		 ReturnToTab(); 
		 alert(result); 
		 // txtresult.innerHTML = result;
  }  
/////////////////////////////////END SEND EMAIL FUNCTIONS///////////////////////////////////////


////////////////////////////////BEGIN SHOW LINK TEXT///////////////////////////////////////////
//call ajax function to retrieve the link url
function GetLinkUrl()
{ var txtresult =  document.getElementById(txtInfo);
  PageMethods.GetURLLink(currentMediaId,OnLinkCodeComplete,OnCallError,txtresult);
}
//when ajax calls back show input text box and insert link url
function OnLinkCodeComplete(result,txtresult,methodName)
{
		  var html = "<BR><BR><table style='width: 100%; font-size: 8pt;border-top: gainsboro 1px solid;border-bottom: gainsboro 1px solid; color: #393938; height: 193px;'>" +
                   "<tr><td align=right>" +
                   "<a style='font-size:6pt; text-decoration:none; font-weight:bold; color: #003399; font-family: Arial;' href='javascript:ReturnToTab();'>" +
                   "CLOSE X</A></td></tr><tr><td valign=bottom>" +
                   "<BR>Copy the url code  below to link directly to this video.</td>" +
                   "</tr><tr><td valign=middle>link: " +
                   "<input id='txtLink' TITLE='Right click and copy' onClick=javascript:selectText('txtLink'); maxlength=1000 width=225 style='font-size:8pt;width:225;border-right: gainsboro 1px solid; border-top: gainsboro 1px solid; " +
                   " border-left: gainsboro 1px solid; border-bottom: gainsboro 1px solid; height: 15px' type='text' />" +
                   "<A href=javascript:ClipBoard('txtLink'); ><IMG border=0 align=absmiddle src=i/copy_text.gif /></A>" +
                   "</td>" +
                   "</tr><tr><td style='height: 20px' valign='top'>" + 
                   "</td></tr></table>";
                   
        //add format html 
        txtresult.innerHTML = html;
        
        //add result / object code to text area
        document.getElementById('txtLink').value = result;
	
}
//////////////////////////////////END SHOW LINK TEXT////////////////////////////////////////////////////////



//////////////////////////////////BEGIN EDIT SCREEN FOR TITLE & DESC///////////////////////////////////////

//Show edit area located in lblInfo
function ShowEditScreen()
{
    //get existing details if any
    var eTitle = document.getElementById('eTitle').innerHTML;
    var eDesc = document.getElementById('eDesc').innerHTML;
 
    var pz = document.getElementById('ctl00_ContentPlaceHolder1_lbInfo');
        var html = "<BR><BR><table style='width: 100%; font-size: 8pt;border-top: gainsboro 1px solid;border-bottom: gainsboro 1px solid; color: #393938; height: 193px;'>" +
                   "<tr><td align=right>" +
                   "<a style='font-size:6pt; text-decoration:none; font-weight:bold; color: #003399; font-family: Arial;' href='javascript:ReturnToTab();'>" +
                   "CLOSE X</A></td></tr><tr><td valign=top>" +
                   "Title for this Video: (100 characters max)<br />" +
                   "<input id='txtTitle' maxlength=100 width=200 style='width:250;border-right: gainsboro 1px solid; border-top: gainsboro 1px solid; " +
                   " border-left: gainsboro 1px solid; border-bottom: gainsboro 1px solid; height: 20px' type='text' />" +
                   "</td>" +
                   "</tr><tr><td>Description:(1000 characters max)<br />" +
                   "<textarea id='txtDesc' width=250 cols='45' rows='2' style='width:250;height:70px;font-family:helvetica;font-size:9pt;  border-right: gainsboro 1px solid; " + 
                   " border-top: gainsboro 1px solid; border-left: gainsboro 1px solid; border-bottom: gainsboro 1px solid' ></textarea>" + 
                   "</td>" +
                   "</tr><tr><td style='height: 20px' valign='top'>" + 
                    "<a style='font-size:8pt; text-decoration:none; font-weight:bold; color: #003399; font-family: Arial;' href='javascript:SaveDetails();'>" +
                   "save</A> | " +
                   "<a style='font-size:8pt; text-decoration:none; font-weight:bold; color: #003399; font-family: Arial;' href='javascript:ReturnToTab();'>" +
                   "cancel</A></td></tr></table>";
        
        pz.innerHTML = html;
        
        document.getElementById('txtTitle').value = eTitle;
        document.getElementById('txtDesc').value  = eDesc;
          
}
 

 //Function calls for saving Title Etc
function SaveDetails()
{
  var txtresult =  document.getElementById(txtInfo);
  //Values of edited text
  var txtTitle =   document.getElementById('txtTitle').value;
  var txtDesc  = document.getElementById('txtDesc').value;
       
  PageMethods.SaveVideoDetails(currentMediaId,txtTitle,txtDesc,OnSaveDetailsComplete,OnCallError,txtresult);
}
  
function OnSaveDetailsComplete(result,txtresult,methodName) {  ReturnToTab();   }  

/////////////////////////////////////////////END EDIT SCREEN FOR TITLE AND DESC///////////////////////////////


/////////////////////////////////////////////BEGIN ADD COMMENT TO VIDEO////////////////////////////////////////////

//Email Video Link Screen
function ShowAddComment()
{

    var pz = document.getElementById(txtInfo);
        var html = "<BR><BR><table style='width: 100%; font-size: 8pt;border-top: gainsboro 1px solid;border-bottom: gainsboro 1px solid; color: #393938; height: 193px;'>" +
                   "<tr><td align=right>" +
                   "<a style='font-size:6pt; text-decoration:none; font-weight:bold; color: #003399; font-family: Arial;' href='javascript:ReturnToTab();'>" +
                   "CLOSE X</A></td></tr><tr><td valign=top>" +
                   "your Name:<br />" +
                   "<input id='txtName' maxlength=100 width=200 style='width:150;border-right: gainsboro 1px solid; border-top: gainsboro 1px solid; " +
                   " border-left: gainsboro 1px solid; border-bottom: gainsboro 1px solid; height: 20px' type='text' />" +
                   "</td>" +
                   "</tr><tr><td>Add Comment:<br />" +
                   "<textarea id='txtComment' width=250 cols='45' rows='2' style='width:250;height:70px;font-family:helvetica;font-size:9pt;  border-right: gainsboro 1px solid; " + 
                   " border-top: gainsboro 1px solid; border-left: gainsboro 1px solid; border-bottom: gainsboro 1px solid' ></textarea>" + 
                   "</td>" +
                   "</tr><tr><td style='height: 20px' valign='top'>" + 
                    "<a style='font-size:8pt; text-decoration:none; font-weight:bold; color: #003399; font-family: Arial;' href='javascript:AddComment();'>" +
                   "Save</A> | " +
                   "<a style='font-size:8pt; text-decoration:none; font-weight:bold; color: #003399; font-family: Arial;' href='javascript:ReturnToTab();'>" +
                   "cancel</A></td></tr></table>";
        
        pz.innerHTML = html;

}



//Function calls for saving Title Etc
function AddComment()
{
  var txtresult =  document.getElementById(txtInfo);
  //Values of edited text
   var txtAuthor =   document.getElementById('txtName').value;
   var txtComment =   document.getElementById('txtComment').value;
         
  PageMethods.AddComment(currentMediaId,txtAuthor,txtComment,OnCommentAddedComplete,OnCallError,txtresult);
    
}

function OnCommentAddedComplete(result,txtresult,methodName){
		 ReturnToTab(); 
		// alert(result); 
		 // txtresult.innerHTML = result;
  }  

////////////////////////////////////////////END ADD COMMENT TO VIDEO//////////////////////////////////////////


///////////////////////////////////////////////BEGIN DELETE COMMENT//////////////////////////////////////////



function DeleteComment(id)
{
 var txtresult =  document.getElementById(txtInfo);
PageMethods.DeleteComment(id,OnCommentDeleteComplete,OnCallError,txtresult);

}

function OnCommentDeleteComplete(result,txtresult,methodName)
{
ReturnToTab(); 

}

/////////////////////////////////////////////////END DELETE COMMENT/////////////////////////////////////////







//////////////////////////////////////////////BEGIN TEXT SELECTION FUNCTIONS///////////////////////////////////////
//Selects text in an text area, call on the onclick etc
function selectText(id)
{  var text =  document.getElementById(id);
    text.focus();
    text.select();
}
//Copy to clipboard function IE only
function ClipBoard(id) 
{   var text =  document.getElementById(id);
    Copied =  text.createTextRange();
    Copied.execCommand("Copy");
}
/////////////////////////////////////////////END TEXT SELECTIONS FUNCTIONS//////////////////////////////////



/////////////////////////////////////////////BEGIN PAGEBAR FUNCTIONS////////////////////////////////////////


//execute hidden buttons click event, 
//pagerId refers to the pager on the screen, 
//pagePos refers to the new page position
function pageItem(pagerId, pagePos,mediaId,sort)
{

    if (pagerId == 2 || pagerId == 3)
    {
    SetTabInfo(pagerId,mediaId,pagePos);
    }
    else  //main video list
    {

    var btn = document.getElementById('ctl00_ContentPlaceHolder1_btnAjax'); //Hidden button to execute
    var hd = document.getElementById('ctl00_ContentPlaceHolder1_hfData'); //Hidden field to hold postback data
    //Set the value of the hidden fields used to hold the data

   // alert(hd.Value);
     
    hd.value = pagerId + "," + pagePos + "," + sort;

        //click button to fire postback
        if (btn) btn.click();
    }

}


//////////////////////////////////////////////////////////////////////////////////////////////////////////



//////////////////////////////////////BEGIN SORT DROP DOWN LIST//////////////////////////////////////////


var timeout	= 500;
var closetimer	= 0;
var ddmenuitem	= 0;

// open hidden layer
function mopen(id)
{	
	// cancel close timer
	mcancelclosetime();

	// close old layer
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';

	// get new layer and show it
	ddmenuitem = document.getElementById(id);
	ddmenuitem.style.visibility = 'visible';

}
// close showed layer
function mclose()
{
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}

// go close timer
function mclosetime()
{
	closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

// close layer when click-out
document.onclick = mclose; 





////////////////////////////////////////////////////////////////////////////////////////////////////////


