/*
	CET Virtual Library™

	Centre for Educational Technology,
	Ramat-Aviv, Israel.
	http://lib.cet.ac.il/

	ITEM.JS
*/

function up_to_caption (el)
{
	var p = el.parentElement
	if ( p.tagName == 'H4' || p.tagName == 'BODY' )
		return p;
	
	return up_to_caption(p)
}

function document_onclick() {
	
	show_chapter_list(0, 'hidden')
	
	if ( window.event.srcElement.name == "paragraph" )
	{
		on_chapter(window.event.srcElement)
	}
	
	
}

function getElementTop(el) 
{
  var nTop = 0;
  while (el)
  {
    nTop += el.offsetTop;
    el = el.offsetParent;
  }
  return nTop;
}


/**
* chapter list processing
*/
function on_chapter (el)
{
	var p = up_to_caption(el)

	createChapterList (p)
	
//	var offset = p.offsetTop + el.offsetHeight + rowItemView.offsetTop + HeaderTable.offsetTop
	var offset = el.offsetHeight + getElementTop(p);
	
	show_chapter_list (offset, 'visible')
	
	
}

function show_chapter_list(offset, isshow)
{	
	if ( offset > 0 )
		chaptersList.style.posTop = offset
	
	//if ( isshow == 'visible' )
	//	setTimeout("chaptersList.style.visibility = '" + isshow + "'", 150)
	//else
		chaptersList.style.visibility = isshow	
}

function on_chapter_out(el)
{
	el.style.textDecoration = ''
}

function on_chapter_over(el)
{
	el.style.textDecoration = 'underline'
}

function goto_chapter(el)
{
	
	var index = new Number(el.name)
	
	var el = document.all(index)	
		
	show_chapter_list (index, 'hidden')
	
	el.scrollIntoView(true)
}

function createChapterList (el)
{
	var hlist = document.getElementsByTagName ("H4")	
	var htmlstrr = ""
	
	for ( i = 0; i < hlist.length; i++ )
	{		
		if( hlist[i].sourceIndex == el.sourceIndex)
			htmlstrr += "<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr class='cslChapterListItemH'><td width='16px'><img src='http://lib.cet.ac.il/images/combo/pop_arrow.gif' width='16' height='15'></td><td>" + hlist[i].innerText + "</td></tr></table>"
		else
			htmlstrr += "<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr class='cslChapterListItem'><td width='16px'></td><td onmouseout='on_chapter_out(this)' onmouseover='on_chapter_over(this)' onclick='goto_chapter(this)' name='" + hlist[i].sourceIndex + "'>" + hlist[i].innerText + "</td></tr></table>"
	}
	
	chaptersList1.innerHTML = htmlstrr
}

function on_biblio(id, el)
{
	var div1 = document.all(id)
	var div2 = document.all(id + "back")
	
	var v = 'visible'
	if ( div1.style.visibility == 'visible' )
		v = 'hidden'
	
	div1.style.posTop = rowItemView.offsetTop + el.offsetHeight
	div2.style.posTop = rowItemView.offsetTop + el.offsetHeight
	div1.style.posLeft = el.offsetWidth
	div2.style.posLeft = el.offsetWidth
	
	div1.style.visibility = v
	div2.style.visibility = v
}

function on_biblio_click (el)
{
	var div1 = document.all(el.id)
	var div2 = document.all(el.id + "back")
	
	div1.style.visibility = 'hidden'
	div2.style.visibility = 'hidden'
}

function on_search_again2() {
  var Q;
  //var id = get_first_subject();

  try {
    Q = document.selection.createRange().text;
    if (Q.length == 0) {
      //document.location= ("../pages/sub.asp?item=" + id);				
    }
    else {
      SEARCH_FORM.str1.value = Q;
    }
    if (SEARCH_FORM.str1.value.length > 0)
      SEARCH_FORM.submit();
  } catch (e) {
    return;
  }
}

function clearBrokenLinks()
{
  // call onload
  var oBody = document.getElementById("itembody");
  if (oBody)
  {
    var oLinks = oBody.all.tags("A");
    for (var i = oLinks.length-1; i >= 0; i--)
    {
      if (oLinks[i].getAttribute(PROJECT_ID) != "1")
      {
        if (oLinks[i].className == "clsItemLexicon")
          oLinks[i].href = "javascript:void(0);"; 
        else if (oLinks[i].name == "itemlink")
          oLinks[i].outerHTML = oLinks[i].innerHTML;
      }
    }
  }

  // for sound item abstract
  oBody = document.getElementById("itemabstract")
  if (oBody)
  {
    oLinks = oBody.all.tags("A");
    for (var i = oLinks.length-1; i >= 0; i--)
    {
      if (oLinks[i].getAttribute(PROJECT_ID) != "1")
      {
        if (oLinks[i].className == "clsItemLexicon")
          oLinks[i].href = "javascript:void(0);"; 
        else if (oLinks[i].name == "itemlink")
          oLinks[i].outerHTML = oLinks[i].innerHTML;
      }
    }
  }
}


function InsertHtml(sDivID, sHTML)
//       ~~~~~~~~~~
{
  var oDiv = document.getElementById(sDivID);
  oDiv.outerHTML = sHTML;    
}
//-------------------------------------------------

function InsertFlash(sDivID, sParams, sSrc, sFlashVars)
//       ~~~~~~~~~~~
{
  var oDictionary = new ActiveXObject("Scripting.Dictionary");
  oDictionary.add ("sWidth", "100%");
  oDictionary.add ("sHeight", "100%");
  oDictionary.add ("sBgColor", "");
  oDictionary.add ("sAlign", "");
  oDictionary.add ("sID", "");
  oDictionary.add ("sWmode", "");  
  oDictionary.add ("sSalign", "");  
  oDictionary.add ("sFlashVars", ""); 

  arrParams = sParams.split('&');  
    
  for (var i=0; i<arrParams.length; i++)
  {     
    var nDelimPos =  arrParams[i].indexOf("=");
    oDictionary.Item(arrParams[i].substr(0, nDelimPos)) = arrParams[i].substr(nDelimPos + 1);                
  }  
  
  if(sFlashVars != undefined)
    oDictionary.Item('sFlashVars') = sFlashVars;
  
  var oDiv = document.getElementById(sDivID);
  var sFlash = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"' + 
                ' WIDTH=' + oDictionary.Item('sWidth') + ' HEIGHT=' + oDictionary.Item('sHeight') + ' id=' + oDictionary.Item('sID') + ' ALIGN=' + oDictionary.Item('sAlign') + ' VIEWASTEXT>' + 
                ' <PARAM NAME="movie" VALUE=' + sSrc + '>' + 
                ' <PARAM NAME="quality" VALUE="high">' + 
                ' <PARAM NAME="FlashVars" VALUE=' + oDictionary.Item("sFlashVars") + '>' +
                ' <PARAM NAME="bgcolor" VALUE=' + oDictionary.Item('sBgColor') + '>' + 
                ' <PARAM NAME="menu" VALUE="false">' + 
                ' <PARAM NAME="wmode" VALUE=' + oDictionary.Item('sWmode') + '>' + 
                ' <PARAM NAME="salign" VALUE=' + oDictionary.Item('sSalign') + '>' + 
                ' <EMBED src=' + sSrc + ' quality="high" bgcolor=' + oDictionary.Item('sBgColor') + ' WIDTH=' + oDictionary.Item('sWidth') + ' HEIGHT=' + oDictionary.Item('sHeight') + 
                ' NAME=' + oDictionary.Item('sID') + ' ALIGN=' + oDictionary.Item('sAlign') + ' salign=' + oDictionary.Item('sSalign') + ' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>' + 
                ' </OBJECT>';
  InsertHtml (sDivID, sFlash);    
}
//-------------------------------------------------


