﻿// JScript File

var fileDisplayWindow;
var popupWindow;
var currentSectionID;

function OpenFileDisplay(filename)
{
    fileDisplayWindow = window.open('./popups/fileDisplay.aspx?filename=' + filename ,"fileDisplayWindow","width=800,height=600,scrollbars=yes");
    fileDisplayWindow.focus();

}

function RepositionElements()
{ 

    var button = document.getElementById('button_gototop');
    var iframe = document.getElementById('Ctrl_chapterlist1_divDocument');
    
    if (iframe != null && button != null)
    {
	    button.style.left = iframe.offsetWidth - 68;
     }
}



function RepositionPreviewElements()
{ 

    var button = document.getElementById('button_gototop');
    var iframe = document.getElementById('divDocument');
    
    if (iframe != null && button != null)
    {
	    button.style.left = iframe.offsetWidth - 68;
     }
}

function OpenPopup(url,width,height)
{
    popupWindow = window.open(url,'popup','width=' + width + ',height=' + height + ',toolbars=no');
    popupWindow.focus();
}

function FindTextInDoc()
{ 

    var obj = document.getElementById('txtFindInDoc');

    if (obj.value != "")
    {
        document.frames['Ctrl_chapterlist1_divDocument'].focus();
        document.frames['Ctrl_chapterlist1_divDocument'].FindText(obj.value);
    }
}

function FindTextInPreviewDoc()
{ 

    var obj = document.getElementById('txtFindInDoc');

    if (obj.value != "")
    {
        document.frames['divDocument'].focus();
        document.frames['divDocument'].FindText(obj.value);
    }
}

function HidePrintLayer()
{
    var printLayer = document.getElementById("divPrint");
    var mouseOverLayer = document.getElementById("divActiveMenu");
    if (printLayer)
    {
        printLayer.style.visibility = "hidden"; 
    }
}

function ShowPrintLayer()
{
    var printLayer = document.getElementById("divPrint");
    var mouseOverLayer = document.getElementById("divActiveMenu");
    
    if (printLayer)
    {
        printLayer.style.visibility = "visible"; 
    }
}


function SetCurrentSectionID(evt,sectionID)
{
    evt = (evt) ? evt : ((window.event) ? window.event : "")

   // alert("section id: " + sectionID);

if (document.getElementById('Ctrl_chapterlist1_currentSectionId') != null) 
{
    document.getElementById('Ctrl_chapterlist1_currentSectionId').value = sectionID; 
 }
 else
 {
    document.getElementById('currentSectionId').value = sectionID;
 }
    
    if (evt != null)
        evt.cancelBubble = true;
}

 function ReAnchorDocument()
 {
    if (document.getElementById('Ctrl_chapterlist1_currentSectionId').value != null && document.getElementById('Ctrl_chapterlist1_currentSectionId').value != "")
    {
        document.frames['Ctrl_chapterlist1_divDocument'].focus();
        document.frames['Ctrl_chapterlist1_divDocument'].GoToAnchor('s' + document.getElementById('Ctrl_chapterlist1_currentSectionId').value);
    }
 }

 function PP_ReAnchorDocument()
 {
    if (document.getElementById('currentSectionId').value != null && document.getElementById('currentSectionId').value != "")
    {
        document.frames['divDocument'].focus();
        document.frames['divDocument'].GoToAnchor('s' + document.getElementById('currentSectionId').value);
    }
 }
 
function PrintCurrentSection()
{
    if (document.getElementById('Ctrl_chapterlist1_hiddenSectionContent').value != null && document.getElementById('Ctrl_chapterlist1_hiddenSectionContent').value != "")
    { 
        
        
        Ctrl_chapterlist1_iframe_clipboard.document.body.innerHTML = document.getElementById('Ctrl_chapterlist1_hiddenSectionContent').value; 
        document.frames['Ctrl_chapterlist1_iframe_clipboard'].focus();
        document.frames['Ctrl_chapterlist1_iframe_clipboard'].print(false); 
         
        document.getElementById('Ctrl_chapterlist1_hiddenSectionContent').value = null;
    }
} 

function PP_PrintCurrentSection()
{
    if (document.getElementById('hiddenSectionContent').value != null && document.getElementById('hiddenSectionContent').value != "")
    { 
        
        
        iframe_clipboard.document.body.innerHTML = document.getElementById('hiddenSectionContent').value; 
        document.frames['iframe_clipboard'].focus();
        document.frames['iframe_clipboard'].print(false); 
         
        document.getElementById('hiddenSectionContent').value = null;
    }
} 

function AddEditQuerryString(querryString, querryValue)
{
    var link  = window.location.href

    //If no querystring present       
    if (link.indexOf('?') == -1 )	
        window.location.href += "?" + querryString +"=" + querryValue;
    else
    {
        // If the querystring is not found
        if(link.indexOf(querryString) == -1)
             window.location.href += "&" + querryString +"=" + querryValue;
        else
        {
            // querrystring is found
            var qsIndex = link.indexOf(querryString + "=")
            window.location.href =  link.replace(link.substring(qsIndex, link.length),  querryString +"=" + querryValue);
          }

    }   
}


