﻿function SetInitialFocus() 
{
    var divSilverlight = document.getElementById('Xaml1');
    divSilverlight.focus();
}

//function OnLoaded(sender, args)
//{
    //window.Silverlight.ButtonAClicked = IFrameFlick;  //FRAME High-Light
    //window.Silverlight.ButtonBClicked = AddBookmark;  //Adding Bookmark
    //window.Silverlight.ButtonCClicked = FocusCurrentHeading;  //Focus the current heading
    //window.Silverlight.ButtonDClicked = DelBookmark;  //Deleting Bookmark
    //window.Silverlight.ButtonEClicked = AddShortnote; //Adding Shortnote
    //window.Silverlight.ButtonFClicked = RefreshThisBrowser; //Adding Shortnote
    //Silverlight.ButtonAClicked = IFrameFlick;  //FRAME High-Light
    //Silverlight.ButtonBClicked = AddBookmark;  //Adding Bookmark
    //Silverlight.ButtonCClicked = FocusCurrentHeading;  //Focus the current heading
    //Silverlight.ButtonDClicked = DelBookmark;  //Deleting Bookmark
    //Silverlight.ButtonEClicked = AddShortnote; //Adding Shortnote
    //Silverlight.ButtonFClicked = RefreshThisBrowser; //Adding Shortnote
     
//}

function RefreshThisBrowser()
{
    location.reload(true);
    SetInitialFocus();
}

function IFrameFlick(strPrevText, strNextText)
{
    var myFrame = document.getElementById("theiframe");
    var myPhrase = myFrame.contentWindow.document.getElementById(strNextText);
    var x = myPhrase.offsetLeft;
    var y = myPhrase.offsetTop;

    myFrame.contentWindow.scrollTo(x, y);
    if (strPrevText != '')
        myFrame.contentWindow.document.getElementById(strPrevText).style.backgroundColor = '#FFFFFF';
    if (strNextText != '')
        myPhrase.style.backgroundColor = '#FFFF00';

    SetInitialFocus();
}

//function IFrameFlick(sender, args)
//{
//    var myFrame  = document.getElementById("theiframe");    
//    var myPhrase = myFrame.contentWindow.document.getElementById(args.NextText);
//    var x = myPhrase.offsetLeft;
//    var y = myPhrase.offsetTop;
//  
//    myFrame.contentWindow.scrollTo(x,y); 
//    if (args.PrevText != '') 
//        myFrame.contentWindow.document.getElementById(args.PrevText).style.backgroundColor = '#FFFFFF';
//    if (args.NextText != '') 
//        myPhrase.style.backgroundColor = '#FFFF00';
// }

function AddShortnote(sntInfo)
{
    //sntInfo = ShortnoteFileName||USERID||BOOKID||ShortnoteText

    __doPostBack('TabContainer1$TabPanel3$TreeView3', 'ADDSNT||' + sntInfo);    //'ADDSNT||ShortnoteFileName||USERID||BOOKID||ShortnoteText'
    SetInitialFocus();
}



function FocusCurrentHeading(strPrevText)
{
    // In this case, args.PrevText equal to args.NextText which is smil#id
    __doPostBack('TabContainer1$TabPanel1$TreeView1', strPrevText);
    SetInitialFocus();
}

function TreeView_ChangeIt(strChangingControl) 
{
    // For sending the new chapter information to the silverlight control
    var control = document.getElementById("Xaml1");
    control.Content.SilverlightApp.strPosFromTree = document.getElementById(strChangingControl).innerHTML;
    SetInitialFocus();
}

function AddBookmark(strBookmarkId)
{
    __doPostBack('TabContainer1$TabPanel2$TreeView2', 'ADDBMK||' + strBookmarkId);
    SetInitialFocus();
}

function DelBookmark(strBookmarkId)
{
    __doPostBack('TabContainer1$TabPanel2$TreeView2', 'DELBMK||' + strBookmarkId);
    SetInitialFocus();
}

function AddShortNote(strShortNoteId) {
    __doPostBack('TabContainer1$TabPanel3$TreeView3', 'ADDSNT||' + strShortNoteId);
    SetInitialFocus();
}

function DelShortNote(strShortNoteId) {
    __doPostBack('TabContainer1$TabPanel3$TreeView3', 'DELSNT||' + strShortNoteId);
    SetInitialFocus();
}
//function CreateFile() 
//{  
    //__doPostBack('TabContainer1$TabPanel2','Book Content/speechgen0003.smil#tcp22/speechgen0004.smil#tcp50');
    //__doPostBack('TabContainer1$TabPanel1$TreeView1','sBook Content\\speechgen0012.smil#tcp829'); 
    //__doPostBack('TabContainer1$TabPanel1','selectcontent'); 
    //__doPostBack('TabContainer1$TabPanel2','addbookmark'); 
    
    //__doPostBack('TabContainer1$TabPanel1','Book Content/speechgen0003.smil#tcp22/speechgen0004.smil#tcp50');
//}          
         
         
//var theForm2 = document.forms['frmMain'];
//if (!theForm2) {
 //   theForm2 = document.frmMain;
//}

//function __doPostBack(eventTarget, eventArgument) 
//{
 //   if (!theForm2.onsubmit || (theForm2.onsubmit() != false)) {
      //  theForm2.__EVENTTARGET.value = eventTarget;
      //  theForm2.__EVENTARGUMENT.value = eventArgument;
    //    theForm2.submit();
  //  }
//}
         
 

//function SelectCurrentHeading(strName, strValue)
//{
//    //action||strName||strValue
//    //__doPostBack('TabContainer1$TabPanel1','select||' + strName + '||' + strValue);
//    
//    __doPostBack('TabContainer1$TabPanel1','select');
//}

////contains calls to silverlight.js, example below loads Page.xaml
//function createSilverlight()
//{
//	Silverlight.createObjectEx({
//		source: "Page.xaml",
//		parentElement: document.getElementById("SilverlightControlHost"),
//		id: "SilverlightControl",
//		properties: {
//			width: "100%",
//			height: "100%",
//			version: "1.1",
//            enableHtmlAccess: "true",        
//            ignoreBrowserVer: "true"
//		},
//		events:{
//            onError:null,               // OnError property value -- event-handler function name.
//            onLoad: OnLoaded},               // OnLoad property value -- event-handler function name.
//        initParams:"name=Audio,source=Test.mp3,background=50AAAAAA,volume=0.5,play=true",   // initParams property value -- user-settable string for information passing.
//        context:null});                 // Context value -- passed to Silverlight.js onLoad event handlers.
//        
//	// Give the keyboard focus to the Silverlight control by default
//    document.body.onload = function() 
//    {
//      var silverlightControl = document.getElementById('SilverlightControl');
//      if (silverlightControl)
//        silverlightControl.focus();    
//    }
//}

//var MPC = function() 
//{
//  this.isSafari = (navigator.userAgent.toString().toLowerCase().indexOf('safari')+1);
//  this._keyHandler = function(e) 
//  {
//   	var silverlightControl = document.getElementById('SilverlightControl');
//    if (silverlightControl)
//        silverlightControl.focus();    
//  }

//  this.init = function() 
//  {
//    document.onkeydown = this._keyHandler;
//    //window.onKeyDown = this._keyHandler; 
//  }
//}

//var mpc = new MPC();
//mpc.init();

////function InitPage() {
////  if (window.document.addEventListener) {
////    // W3
////    window.document.addEventListener('keydown', keyDown, true);
////  } else {
////    // IE
////    window.document.attachEvent('onkeydown', keyDown);
////  }
////  document.getElementById('SilverlightControl').focus();
////}

////function keyDown(e) {
//// document.getElementById('SilverlightControl').focus();
////}

////function focusSilverlight()
////{
////   document.getElementById("SilverlightControl").focus();
////   document.getElementById('SilverlightControl').focus();
////}
