if(typeof HTMLElement!="undefined" && !
HTMLElement.prototype.insertAdjacentElement){
	HTMLElement.prototype.insertAdjacentElement = function
(where,parsedNode)
	{
		switch (where){
		case 'beforeBegin':
			this.parentNode.insertBefore(parsedNode,this)
			break;
		case 'afterBegin':
			this.insertBefore(parsedNode,this.firstChild);
			break;
		case 'beforeEnd':
			this.appendChild(parsedNode);
			break;
		case 'afterEnd':
			if (this.nextSibling) 
this.parentNode.insertBefore(parsedNode,this.nextSibling);
			else this.parentNode.appendChild(parsedNode);
			break;
		}
	}

	HTMLElement.prototype.insertAdjacentHTML = function
(where,htmlStr)
	{
		var r = this.ownerDocument.createRange();
		r.setStartBefore(this);
		var parsedHTML = r.createContextualFragment(htmlStr);
		this.insertAdjacentElement(where,parsedHTML)
	}


	HTMLElement.prototype.insertAdjacentText = function
(where,txtStr)
	{
		var parsedText = document.createTextNode(txtStr)
		this.insertAdjacentElement(where,parsedText)
	}
}

// fix div problem in overflow 
// these functions are called by onLoad event in header body or in div with showTextRtb id

function setDivSize(divPt){
	
   // this code is written to solve the problem of using anchors in no overflow situation
  if(divPt.scrollHeight>divPt.clientHeight){
  divPt.visitflag=1;
  divPt.style.height=divPt.scrollHeight+16;
  
 }
 else if (divPt.anc==1&&divPt.visitflag==0){
  divPt.style.overflowX="scroll";
  divPt.style.scrollbarFaceColor="white";
  divPt.style.scrollbarBaseColor="white";
  divPt.style.scrollbarShadowColor="white";
  divPt.style.scrollbarDarkShadowColor="white";
    
  divPt.visitflag=2;
  
 }
 
}

function checkRtb(next,num,rtbs){
 nextRtbIndex=next;
 numOfRtb=num;
 allRtb=rtbs;
 
 if (nextRtbIndex<numOfRtb){
   setDivSize(allRtb[nextRtbIndex]);
   nextRtbIndex++;
   window.setTimeout('checkRtb(nextRtbIndex,numOfRtb,allRtb)',7);
 }
 //window.status="n:"+nextRtbIndex+" num:"+numOfRtb+" all:"+allRtb;
}

function invokeDivRtb(){
 allRtb=window.document.getElementsByName('showTextRtb');
 start=0;
 threadRtbCheck=this.setTimeout('checkRtb(start,allRtb.length,allRtb)',1);
 
}


// fixMsoClassTable - the function is in use to solve the problem of table overflow 
// when the user has copy a table from word to the editor.

function fixMsoClassTable(text){

  fixTableStr='<TABLE cellSpacing=0 cellPadding=0 width=\"100%\" border=1>';
  markMsoStart=text.indexOf("<TABLE class=Mso");
  while (markMsoStart!=-1){
  
  //alert("markMsoStart:"+markMsoStart);
  markMsoEnd=text.indexOf(">",markMsoStart+1);
  section1=text.substr(0,markMsoStart-1);
  section2=text.substr(markMsoEnd+1);
  text=section1+fixTableStr+section2;
  markMsoStart=text.indexOf("<TABLE class=Mso");
  }
  return(text);
}

function changeSpecialChar(text){

var rule_search=new Array(4);
var rule_change=new Array(4);
//alert("change:"+unescape(text));
//alert("change2:"+escape(text));

rule_search[0]="%u201C"; rule_change[0]="\"";
rule_search[1]="%u201D"; rule_change[1]="\"";
rule_search[2]="%u2026"; rule_change[2]="...";
rule_search[3]="%u2013"; rule_change[3]="-";

for (rule_index=0;rule_index<rule_search.length;rule_index++)
{
	//alert("search:"+unescape(rule_search[rule_index])+" replace="+rule_change[rule_index]);
	while ((indexChk=text.indexOf(unescape(rule_search[rule_index])))>-1)
	{
	  text=text.replace(unescape(rule_search[rule_index]),rule_change[rule_index]);
	  
	}
}
text=fixMsoClassTable(text);
return(text);
}
/*-----------------------------------------------------------------------------------------------------------------------
this function gets call when the user clicks the mouse with the left button
purpose: the function checks if the user clicked in order to open a hidden content segment
               if a hidden segment is found, the function reveals the segment
				  
 note: the event  trapper is set in the body tag
-----------------------------------------------------------------------------------------------------------------------*/

function showhide(e){
/*		alert (evt.srcElement.tagName);
	event = (evt) ? evt : event;

*/
if (!e) var e = window.event;
	if(e==null){
		return;
	}
	var actionObj =  (e.srcElement) ? (e.srcElement) :  e.target;
	//actionObj=event.srcElement;
	tmpobj=actionObj;
	while ((tmpobj.tagName!="BODY")&&(tmpobj.className !="RTBSegment")&&(tmpobj.className !="textSegmentHide")&&(tmpobj.className !="textSegmentShow")){
		     tmpobj=tmpobj.parentNode;
			 }
	
	if (tmpobj.className=="RTBSegment"){
		actionObj=tmpobj;
	}

	var closerObj=null;
	// if the user clicked on the bottom closer... 
	if (actionObj!=null&&actionObj.parentNode.className=="RTBSegmentCloser"){
		closerObj=actionObj.parentNode;
		actionObj=actionObj.parentNode.parentNode;
	}
	// if the user clicked on upper closer
    
	if (actionObj!=null&&actionObj.className=="RTBSegment"){

		  textObj=getTextObj(actionObj);
		  
	      /*
          uncomment these lines when you need to put other text as the first closer for the segment
		  //--------------------------------------------------------------------------------------------------------------

		  tmptext=getHTMLToObj(actionObj);
		  removeChildsToObj(actionObj,textObj);
		  //------------------------------------------------------------------------------------
		  // switch  between lastText and the current text
		  actionObj.insertAdjacentHTML("afterBegin",actionObj.lastText);
		  actionObj.lastText=tmptext;
		  // ------------------------------------------------------------------------------------

		  */

		 if (textObj.className=="textSegmentHide"){
			   
			  	textObj.className="textSegmentShow";
				actionObj.style.color="blue";
				textObj.style.color="black";
				sp=document.createElement( "SPAN" );
				sp.innerHTML="<U>[הסתר]</U>";
				sp.className="RTBSegmentCloser";
				textObj.insertAdjacentElement("AfterEnd",sp);
						
								
		 }
		 else {		        
			       	textObj.className="textSegmentHide";
					//actionObj.style.textDecoration="underline";
					actionObj.style.color="blue";
					if (closerObj!=null){
						closerObj.removeNode(true);
							
					}
					else { 
						if (textObj.nextSibling != null)
						{
				
						textObj.nextSibling.removeNode(true);
								}
						
					}
				}
	}
	
}

function getTextObj(p){
  var objFound=null;
 var DivCollection=p.getElementsByTagName("DIV");
   for (i=0;i<DivCollection.length&&objFound==null ;i++ ) {
	   if ((DivCollection[i].className=="textSegmentHide")||(DivCollection[i].className=="textSegmentShow")){
		   objFound=DivCollection[i];
	   }
   }
   return (objFound);
}

function goLink (url, type, width, height) {
	url = my_escape(url);
//	alert (url);
	switch (type)
	{
		
	case "new_win" :
		msgWindow=window.open(url)
		return (false);
	case "current" :
		return (true);
	case "small" :
		
		 if ( url.indexOf("en.jsp")!= -1 &&  url.indexOf("openu")!= -1 )
			 {
				url=url.replace("FocusPage", "ComponentPage&winsize=small");
				if ( url.indexOf("ComponentPage") == -1)
					{
					url=url.replace("en.jsp?", "en.jsp?enPage=ComponentPage&winsize=small&");
					}
			}

	
	    msgWindow=window.open(url,"_blank","width=" + width + ",height=" + height + ",resizable=yes,toolbar=no,scrollbars=yes,left=50,top=40");	
		return (false);
	default: return (true);
	
	}

}
var hexVals = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
              "A", "B", "C", "D", "E", "F");
var unsafeString = "\"<>\\^[]`\+\$\,";

function my_escape (val) {
	alert ("my_escape");
var len     = val.length;
var backlen = len;
var i       = 0;

var newStr  = "";
var frag    = "";
var encval  = "";
var original = val;
 for (i=0;i<len;i++)
        { char_code = (val.substring(i,i+1).charCodeAt(0));
              if (isUnsafe(val.substring(i,i+1)) == false)
                 { newStr = newStr + val.substring(i,i+1); }
           else
                 { newStr = newStr + convert(val.substring(i,i+1)); }
        }
		return (newStr);
}
function isUnsafe(compareChar)
// this function checks to see if a char is URL unsafe.
// Returns bool result. True = unsafe, False = safe
{
if (unsafeString.indexOf(compareChar) == -1 && compareChar.charCodeAt(0) > 32
    && compareChar.charCodeAt(0) < 123)
   { return false; } // found no unsafe chars, return false
else
   { return true; }
}


function decToHex(num, radix)
// part of the hex-ifying functionality
{
var hexString = "";
while (num >= radix)
      {
       temp = num % radix;
       num = Math.floor(num / radix);
       hexString += hexVals[temp];
      }
hexString += hexVals[num];
return reversal(hexString);
}

function reversal(s) // part of the hex-ifying functionality
{
var len = s.length;
var trans = "";
for (i=0; i<len; i++)
    { trans = trans + s.substring(len-i-1, len-i); }
s = trans;
return s;
}


function convert(val) // this converts a given char to url hex form
{ return  "%" + decToHex(val.charCodeAt(0), 16); }

function my_escape (val) {
var len     = val.length;
var backlen = len;
var i       = 0;

var newStr  = "";
var frag    = "";
var encval  = "";
var original = val;
 for (i=0;i<len;i++)
        { char_code = (val.substring(i,i+1).charCodeAt(0));
              if (isUnsafe(val.substring(i,i+1)) == false)
                 { newStr = newStr + val.substring(i,i+1); }
              else
                 { newStr = newStr + convert(val.substring(i,i+1)); }
        }
		return (newStr);
}
function goTarget(target){
	//alert("target:"+target);
	urlStr=document.location;
	document.location.href="#"+target;
}


 function toolTip_show(tip){

var e= window.event;
var prompter =  (e.srcElement) ? (e.srcElement) :  e.target;
var pos = getPosition(prompter);

//	note.style.display = (note.style &&  note.style.display=="block")  ? "none"  : "block";
//	positionNote(note, pos.x, pos.y);

//	  src = window.event.srcElement;
//	  offsetT=event.clientY;
//	  offsetX=event.clientX;
//	  el=document.getElementById('RTB_toolTip');

	var  el = document.createElement("DIV");

	  el.id=	"RTB_toolTip";					
	  el.innerText=tip;
	  el.style.visibility="visible";
	  el.style.left = pos.x - 32 +"px";
      el.style.top =  pos.y -15 +"px";

	  document.body.appendChild(el);
	  for (timePause=0;timePause<2500;timePause++){
		  // do nothing
	  }
  }
 function toolTip_hide(tip){
	  
	  el=document.getElementById('RTB_toolTip');
	document.body.removeChild(el);
	  
  }



  function isIEWindows()
{
	return( (navigator.appName=="Microsoft Internet Explorer") && 
		(navigator.appVersion.indexOf("Windows") != -1) );
}

// returns version of Internet Explorer


function ieVersion()
{
	var ieVer = 0;
	var start = navigator.appVersion.indexOf("MSIE "); 
	if (start != -1) { 
		ieVer = parseFloat(navigator.appVersion.substring(start+5)); 
	}
	return ieVer;
}


function isMPInstalled()
{
/*	try {
		var oMP = new ActiveXObject("MathPlayer.Factory.1");
		return true;
	}
	catch(e) {
		return false;
	}*/
	 var ua = navigator.userAgent;
	 if (ua.indexOf("MathPlayer")!=-1)
	 return true;
	 else return false;
}


	var MathAndActionElementsUpdated = false;
  function handleEquations(estudyURL){
	estudyURL=estudySiteAddress+"opus/bin/";
    var ua = navigator.userAgent;
//  if (ua.indexOf("MSIE")==-1 || ( isIEWindows() &&ieVersion() < 6.0 ) {

	var oSpans=document. getElementsByTagName("SPAN");


	for (i=0;i<oSpans.length ;i++ )
		{
		if (oSpans[i].id.indexOf("eqViewer") !=-1 && oSpans[i].id.indexOf("clicker") ==-1 )
		{ 
			// var eqMath=document.getElementById(oSpans[i].id+"_math");
			 //var eqAction=document.getElementById(oSpans[i].id+"_maction");
	//		  var eqMath=oMaths[i];
	//		 var eqAction=oMactions[i];
			var mpDiv=document.getElementById("mathplayerInstallMessage");

			if (isIEWindows() &&ieVersion() >= 6.0)
			{
				    if (isMPInstalled()) 
						{     
						     var start = navigator.appVersion.indexOf("MathPlayer");
							

							if (!MathAndActionElementsUpdated)  updateMathAndMactions();
				       if (start == -1) 
							  {  
						   document.body.appendChild(mpDiv);
						   if (mpDiv != null) {
								mpDiv.innerHTML = "מומלץ לעדכן את גרסת <a href='http://www.dessci.com/en/products/mathplayer/download.htm' target='blank'>mathplayer</a>";
								}

						    // need MP upgrade, have IE6
						    }
						// else do nothing  - user has IE6 and MathPLayer is installed
					    }
		  else 
						{        

							fDiv = document.createElement("DIV");
							fDiv.className="mathplayerMessage";
							fDiv.innerHTML = " נוסחה ";
//							eqMath.removeNode(true);
							removeChildrenRecursively(oSpans[i]);
							oSpans[i].appendChild(fDiv);
						   if (mpDiv != null) {
								mpDiv.style.display="inline";
								mpDiv.innerHTML = "בדף זה משולבות נוסחאות. כדי לצפות בהן יש להתקין   <a href='http://www.dessci.com/en/dl/MathPlayerSetup.asp' target='blank'>mathplayer</a>. <a href=\""+estudyURL+"en.jsp?enDispWho=Editor^l231336&enZone=Editor100287\" target=_blank>לפרטים נוספים</a>";
							}

				 // need MP, have IE6
					    }
			}
			else
				{ //either not IE or below IE6
		   var eq_span= oSpans[i];
			var mathml = eq_span.innerHTML.replace(/m:/g,"");
			mathml=mathml.replace(/<\?[^>]*>/g,"");
			var str = "";
			str += "<applet ";
			str += " id='" +eq_span.id+"'" ;
			if (eq_span.getAttribute("editEquationObj"))
			{
			str += " onbeforeeditfocus='" + eq_span.getAttribute("editEquationObj") +"' ";
			}
			
			str += " archive='/opus/static/webEQ/3.0/WebEQApplet.jar' code='webeq3.ViewerControl'";

			
			if (eq_span.getAttribute("w"))
			{
			str +="' width='" +eq_span.getAttribute("w");
			}
			if (eq_span.getAttribute("h"))
			{
			str +="' height='" +eq_span.getAttribute("h");
			}
			str +="' ";
			str += " align='middle' ";
			str += " MAYSCRIPT>\n";
			str += "<param name='scriptable' value='true'>";
			if (eq_span.getAttribute("pointSizeForView"))
			{
			str += "<param name='size' value='" +eq_span.getAttribute("pointSizeForView");
			}
			str +="'>\n";

			// the default 'valign' param value is 'baseline'.
			// do not confuse 'valign' param with the 'align=middle' attribute of the applet above
			// the param valigns the equation inside the given applet area
			if (eq_span.getAttribute("numLines") != null && eq_span.getAttribute("numLines") > 1) str += "<param name='valign' value='middle'>\n";

			str += "<param name='controls' value='true'>\n";
			str += "<param name='color' value='#ffffff'>\n";
			str += "<param name='padding' value='1'>\n";
			str += "<param name='overflow_markers' value='true'>\n";
			str += "<param name='eq' value='" +mathml +"'>\n";
			str += "</applet>";
			eq_span.innerHTML=str;
		   }
	  }
  }
}

     var start = navigator.appVersion.indexOf("MathPlayer");

function updateMathAndMactions(){
	var oMactions=document. getElementsByTagName("maction");
		var oMaths=document. getElementsByTagName("math");
//		alert ("max: "+Math.max(oMactions.length, oMaths.length));

	for (i=Math.max(oMactions.length, oMaths.length)-1;i>=0;i-- ) {


							 if (oMactions[i] !=null)
							 {
								 oMactions[i].removeNode(false);
							 }
						
							   	 if (oMaths[i] !=null)
							 {
								  oMaths[i].update();
							 }
		}
MathAndActionElementsUpdated=true;
	 }


function removeChildrenRecursively(node)
{
if (!node) return;
while (node.hasChildNodes()) {
removeChildrenRecursively(node.firstChild);
node.removeChild(node.firstChild);
}
}
function MathPlayerInstallCheck() {
	 var ua = navigator.userAgent;
	 if (ua.indexOf("MSIE")!=-1 &&  isIEWindows() &&ieVersion() >= 6.0 && ua.indexOf("MathPlayer")!=-1){
	document.write("	   <OBJECT    ID=MathPlayer");
		document.write("	  			      CLASSID=\"clsid:32F66A20-7614-11D4-BD11-00104BD3F987\"  >");
		document.write("	  			   </OBJECT>");
	document.write("	  				  <?IMPORT NAMESPACE=\"m\" IMPLEMENTATION=\"#MathPlayer\" ?>");}
}


function toggleNote(noteNum)
{
//alert('toggle_note');
//var e= window.event;
//var prompter =  (e.srcElement) ? (e.srcElement) :  e.target;
var prompter =  document.getElementById("noteClicker_" +noteNum);
var pos = getPosition(prompter);
/*
var cls = "";
if (prompter.id  && prompter.id.match("noteClicker_"))
	{
	var noteName = prompter.id.replace("noteClicker_", "");*/
	var note = document.getElementById("floatingNote_" +noteNum);
	if (note == null  ) return (true);
	note.style.display = (note.style &&  note.style.display=="block")  ? "none"  : "block";
	positionNote(note, pos.x, pos.y);

return(false);
}

function positionNote(note, posX, posY)
{
if (!note.id || !note.id.match("floatingNote_") ) return;
 var ua = navigator.userAgent;
 var shiftY =15;
//  if (ua.indexOf("MSIE")!=-1) shiftY = -100;
var shiftX = 5;
var lineHeight = 18;

var noteWidth = 270;  // in the css
var noteHeight =parseInt(note.offsetHeight) + lineHeight;
//alert ("noteHeight: "+noteHeight);
shiftY = shiftY - noteHeight;
shiftX = shiftX - noteWidth;
var note_x = Math.max(posX + shiftX, 10);
var note_y = Math.max(posY + shiftY, -1);
if (note_y < scrollTopDistance() ) note_y = posY+shiftY+ noteHeight;
//alert ("note_y: "+note_y);
document.body.appendChild(note);
note.style.left = note_x +"px";
note.style.top = note_y +"px";
/*note.style.left = posX-100 +"px";
note.style.top = posY +"px";*/

}

function getPosition(oElement)
{
// returns the coordinates of an HTML element, 
// even if the element's position was not explicitly set.
var tempY = 0; var tempX = 0;
var retval = new Object();
var tempObj = oElement;
while (tempObj.offsetParent)
	{
//	alert(tempObj.nodeName + " " +tempObj.offsetParent.nodeName +" " +tempObj.offsetLeft);
	tempX += tempObj.offsetLeft;
	tempY += tempObj.offsetTop;
	tempObj = tempObj.offsetParent;
	}
//alert ("tempY: "+tempY);
retval.x = parseInt(tempX);
retval.y = parseInt(tempY);
return(retval);
}

function scrollTopDistance()
{
/* returns an integer - 
  the vertical distance in pixels that the window is now scrolled,
  i.e. the distance from the visible top of the document to the real top of the document. 
 */
if (document.documentElement && document.documentElement.scrollTop) 
	//  IE in standards-compliant mode
	return(document.documentElement.scrollTop); 
 	// in non standards mode documentElement.scrollTop still exists but is equal to 0 in IE !!  so...
  else if (document.getElementsByTagName("BODY")[0].scrollTop)
		return(document.getElementsByTagName("BODY")[0].scrollTop);
     else return(0);
}
