﻿var totalWidth;
var totalHeight;
var closeLocationId;
var domainroot="http://geraldschroeder.com";
function Gsitesearch(curobj){
    curobj.q.value="site:"+domainroot+" "+curobj.qfront.value
}
function BodyLoad()
{
    if (document.all) 
    {
       document.body.style.fontSize = "75%";
    } 
//    var arr = document.getElementsByTagName('a');
//    for (var i = 0 ; i < arr.length ; i++)
//      {
//        if (arr[i].addEventListener){
//        arr[i].addEventListener("focus", closeLists2, false);
//        return true;
//      } else if (arr[i].attachEvent){
//        var r = arr[i].attachEvent("onfocus", closeLists2);
//        return r;
//      } else {
//        alert("Handler could not be attached");
//      }
//      }
//      var arr = document.getElementsByTagName('input');
//    for (var i = 0 ; i < arr.length ; i++)
//      {
//        if (arr[i].addEventListener){
//        arr[i].addEventListener("focus", closeLists2, false);
//        return true;
//      } else if (arr[i].attachEvent){
//        var r = arr[i].attachEvent("onfocus", closeLists2);
//        return r;
//      } else {
//        alert("Handler could not be attached");
//      }
//      }
}
function setSearchTerm()
{
   var anc = document.getElementById('ancSearch');
   var term = document.getElementById('txtSearch').value;
   var arr = term.split(" ");
   var href = arr[0];
   for (var i = 1; i<arr.length;i++)
   {
      var temp = arr[i];
      if (temp != '')
      {
        href += "+" + arr[i];
      }
   }
   anc.href = anc.href + href;
}
function dummy(){}
function enlarge(ele,hover)
{
   if (hover)
   {
      var arr = ele.parentNode.parentNode.getElementsByTagName('input');
      for (var i = 0 ; i < arr.length ; i++)
      {
        enlarge(arr[i],false);
      }
      var url = ele.src;
      var ext = url.slice(url.length - 4); 
      var file= url.slice(0,url.length - 4);
      url = file + "2" + ext;
      ele.src = url;
   }
   else
   {
      if (ele.src.indexOf('2') > -1)
      {
          var url = ele.src;
          var ext = url.slice(url.length - 4); 
          var file= url.slice(0,url.length - 5);
          url = file + ext;
          ele.src = url;
      }      
   }
}
function closeToc()
{
   $("#tocPopup").fadeOut("slow");
   hideCloak();
   $("#" + closeLocationId).focus(); 
}   
function focusElement(id)
{
   window.location = "#" + id; 
   try
   {
      document.getElementById(id).focus();
   }
   catch(errr)
   {
   }
}
function popupBook(ele,id)
{
   //ele.parentNode.style.border = "dotted 2px #24427E";
}
function lowerBook(ele,id)
{
   //ele.parentNode.style.border = "";
}
function changeOpacity(id,o,f,z)
{
   var ele = document.getElementById(id);
   if (o > 0) ele.style.display = "block";
   else ele.style.display = "none";
   ele.style.zIndex = z;
   if (ele.style.opacity)
   {
      ele.style.opacity = o;
   }
   else
   {
      ele.style.filter = "alpha(opacity=" + f + ")";   
   }
}
function expandDiv(id,imageId)
{
   var div = document.getElementById(id);
   var img = document.getElementById(imageId);
   if (img.src.indexOf('close') > -1)
   {
     div.style.height = "100px";
     div.style.overflow = "hidden";
     img.src="images/expand_tab_blue.gif";
     div.scrollTop = 0; 
   }
   else
   {
     div.style.height = "auto";
     img.src="images/close_tab_blue.gif";     
   }    
   focusElement(id);
}   
function showHideDiv(id)
{
   var div = document.getElementById(id);
   var display = "block";
   if (div.style.display == "block") display = "none";
   div.style.display = display;
}
function selectItem(ele)
{
   var bgColor = "#0E4453";
   var color = "#BBDAE2";   
   if (ele.getAttribute("selected") == "true")
   {
      var color = "#0E4453";
      var bgColor = "#D4E7EC";
      ele.setAttribute("selected","false");
   } 
   else ele.setAttribute("selected","true");
   ele.style.color = color;
   ele.parentNode.parentNode.style.backgroundColor = bgColor;
 }  
 function openToc(closeId)
 {
    showCloak(); 
    $("#tocPopup").fadeIn("slow");
    positionCenterElement('tocPopup');
    setCloseId(closeId);
    window.location = '#hdrToc';
 }  
 function positionCenterElement(id)
{
   var ele = $("#" + id);
   ele.css("top", ( $(window).height() - ele.height() ) / 2+$(window).scrollTop() + "px");
   ele.css("left", ( $(window).width() - ele.width() ) / 2+$(window).scrollLeft() + "px");
}
function getWindowHeight()
{
   return document.getElementById('divBody').scrollHeight + 85;
}
function showCloak()
{
   var ele = document.getElementById('cloak');
   ele.style.display = "block";
   ele.style.height = getWindowHeight() + "px";
}
function hideCloak()
{
   var ele = document.getElementById('cloak');
   ele.style.display = "none";
}
 function showPage(page)
 {
    var arr = document.getElementById('divPagingContent').getElementsByTagName('div');
    for (var i = 0;i< arr.length; i++)
    {
       arr[i].style.display = "none";
    }
    document.getElementById(page).style.display = "block";
    var anchorId = 'a' + page;
    var arr = document.getElementById('divPaging').getElementsByTagName('a');
    for (var i = 0;i< arr.length; i++)
    {
       arr[i].className = "";
    }
    try
    {
     document.getElementById(anchorId).className = "first";
    }
    catch(errr)
    {
    }     
    var anchorId2 = '2a' + page;
    var arr2 = document.getElementById('divPaging2').getElementsByTagName('a');
    for (var i = 0;i< arr.length; i++)
    {
       arr2[i].className = "";
    }
    try
    {
     document.getElementById(anchorId2).className = "first";
    }
    catch(errr)
    {
    }       
 }  
 function AdjustWindowHeight() 
 {
  getHeightWidth();
  document.getElementById('divOuterBody').style.height = totalHeight - 95 + "px"; 
  document.getElementById('divBody').style.height = totalHeight - 95 + "px"; 
}    
function getHeightWidth()
{
   if( typeof( window.innerWidth ) == 'number' ) 
   {
    //Non-IE
    totalWidth = window.innerWidth;
    totalHeight = window.innerHeight;
   } 
   else if ( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
   {
    //IE 6+ in 'standards compliant mode'
    totalWidth = document.documentElement.clientWidth;
    totalHeight = document.documentElement.clientHeight;
   } 
   else if ( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
   {
    //IE 4 compatible
    totalWidth = document.body.clientWidth;
    totalHeight = document.body.clientHeight;
   }
}
function setCloseId(id)
{
   closeLocationId = id;
}
function viewPopup(inner)
{
   showCloak();   
   document.getElementById('divViewerAbsolute').innerHTML = inner;
   //clickButton('cmdDummyOpenAnimation');
   $("#viewPopup").fadeIn("slow");
   positionCenterElement('viewPopup');
   window.location = '#hdrPopup';
}
function closeViewPopup()
{   
   hideCloak();
   $("#viewPopup").fadeOut("slow");  
   $("#" + closeLocationId).focus(); 
}
function closeViewPopup2()
{
   var popup = document.getElementById('viewPopup');
   var popupHdr = findElementParent('hdrPopup','h2',popup);  
   popupHdr.innerHTML = '';
   document.getElementById('divViewerAbsolute').innerHTML = '';
}
function clickButton(id) 
{
    try {
        var ele = findElement(id, 'input');
        ele.click();
    }
    catch (err) {
    }
}
function findElement(id,tag)
{
   var ele;
   var arr = document.getElementsByTagName(tag);
   for (var i = 0;i< arr.length; i++)
   {
      if (arr[i].id.indexOf(id) > -1)
      {
         ele = arr[i];
      }
   }
   return ele;
}
function findElementParent(id,tag,parent)
{
   var ele;
   var arr = parent.getElementsByTagName(tag);
   for (var i = 0;i< arr.length; i++)
   {
      if (arr[i].id.indexOf(id) > -1)
      {
         ele = arr[i];
      }
   }
   return ele;
}
function closeSearchList()
{
   var div = document.getElementById('divSearchOuter'); 
   var div2 = document.getElementById('divInnerSearch');
   div2.innerHTML = ''; 
   div.style.display = "none";
}
var xmlHttp;
function GetXmlHttpObject()
  {
  try 
  {
    xmlHttp=new XMLHttpRequest();
  }
  catch (e)
  {
    try
    {
      xmlHttp=new ActiveXObject('Msxml2.XMLHTTP');
    }
    catch (e)
    {
      xmlHttp=new ActiveXObject('Microsoft.XMLHTTP'); 
    }
  }
  return xmlHttp;
 }
 function disableEnterKey(e)
{
     var key;     
     if(window.event)
          key = window.event.keyCode; //IE
     else
          key = e.which; //firefox     

     return (key != 13);
}
function showWait()
{
   document.getElementById('divWait').style.display = "block";
}
function hideWait()
{
   document.getElementById('divWait').style.display = "none";
}
function bodyMouseDown(e)
{
   closeLists(e);
}
function openBookPartPopup(closeId,header,nodeName,fileName)
{
   showWait();
//   setCloseId(closeId);
//   var popup = document.getElementById('viewPopup');
//   var popupHdr = findElementParent('hdrPopup','h2',popup);
//   popupHdr.innerHTML = header;
//   if (header == 'Excerpts') {
//   document.getElementById('divFooter').style.display = 'block';
//   }
//   else 
//   {
//   document.getElementById('divFooter').style.display = 'none';
//   }
   var div = document.getElementById('mainPopupHeader').getElementsByTagName('h2')[0].innerHTML = header;
   var xmlHttp=GetXmlHttpObject() ;
   xmlHttp.onreadystatechange=bookPartOpened;
   xmlHttp.open('GET','Ajax.aspx?part=' + nodeName + '&file=' + fileName,true) ;
   xmlHttp.send(null);
}
function bookPartOpened()
{
   if (xmlHttp.readyState==4)
   {       
       var response = xmlHttp.responseText;       
       hideWait();
       document.getElementById('divAbsoluteWrapper').getElementsByTagName('div')[0].innerHTML = response;
       //viewPopup(response);       
   }      
}


