var IfSmallMenu=0;
var globalMenuHeight
var menuStat; //IF THE MENU IS COLLAPSED OR NOT
menuStat="opend";

if ((WBCMODE!="") || (NRMODE!="")){
          globalMenuHeight= 560;//530;//500;
        }else{
          globalMenuHeight=80;//50; // *small menu hight [30]
   }
 

 
//alert(NRMODE)
/*
  FUNCTION menuSize IS CALLED WHEN IN EDIT MODE AND CHANGES THE globalMenuHeight TO 100;
  SO ANY MENU HEIGHT CAHNGES MUST BE CHANGED IN THE changeState() ALSO!!!
*/


 

var IW= 0;
var IH= 0;
var PX= 0;
var PY= 0;
var ZIN= 0;
var us= null;
var IMGW= 0;
//modify top position
var IMGH= 2;
var LSAFETY= 100;
var TSAFETY;
if (screen.width > 805){
TSAFETY = 540;
} else {
TSAFETY = 140;
}

function branding() {
browserVer = parseInt(navigator.appVersion); 
if(browserVer<4) return;
 oldIW= IW;
 oldIH= IH;
 oldPX= PX;
 oldPY= PY;
 

  //if (navigator.appVersion.indexOf("Mac") == -1)
  {
    if ((document.body.clientHeight != oldIH)||(document.body.clientWidth != oldIW)||(document.body.scrollLeft != oldPX)||(document.body.scrollTop != oldPY))      {
      alldivs= document.getElementsByTagName("DIV");
      if (us == null){ 
       us = document.getElementById("Logo");
     
       
       /* for (i=0; i<alldivs.length; i++)
          {
          us= alldivs[i];
          if (us.id == "Logo"){
            us.style.left=0;  //  SAGIV
            break;
			}
          }*/
          
      }
      if (us != null){
        us.style.display= "none";

        IH= document.body.clientHeight;		
        IW= document.body.clientWidth;
        PX= document.body.scrollLeft;
        PY= document.body.scrollTop;
        ////us.style.bottom = 140;
      
        
        //*********************** change box height  *****************************//
		////us.style.bottom = document.body.clientHeight - globalMenuHeight; //500;//480
		
		
		
		//us.style.top = 140;
     	
// אחראי על המיקום הרוחבי

   /////////us.style.left=(PX-(IMGW+LSAFETY)+15);
   
//modify left position
		/*if (screen.width > 805){
		 us.style.left = (document.body.clientWidth - 780)/2 - 110;
		} else {
		 us.style.left = 0;
		}*/
		//alert(us.style.left)
		if(us.style.left < 0){			
		
		  us.style.left=0
		  // us.style.left = us.style.left;
		
		// us.style.left=0;
		 //  alert(1)
		}else{
			
			// us.style.left=0
		 //  us.style.left = 0;
		  // alert(2)
		}
       
//us.style.left = (150 - ims.width)/2;
        for (i=0; i<alldivs.length; i++){
          templay= alldivs(i);
          if (templay.style.zIndex > ZIN)
            us.style.zindex= (templay.style.zIndex + 1);
        }
        
        
          us.style.bottom = 140;  //fix the disapearing menu to the bottom
       
       
      // NRMODE=Unpublished
       //WBCMODE=PresentationUnpublished
     
       
        if ((WBCMODE!="") || ((NRMODE!="") && NRMODE!="Published")){

            if ((WBCMODE=="AuthoringReedit") || (WBCMODE=="AuthoringNew")) {
            
               if (dir=="rtl"){
				  us.style.bottom =  (document.body.clientHeight - document.body.scrollTop) - 130
				}else{
                   
                    if (menuStat=="opend"){
                      us.style.bottom = document.body.clientHeight - 130;
                     }else{
                       us.style.bottom = document.body.clientHeight - 30;
                     }
                }
            }else{
				if (dir=="rtl"){
				  us.style.bottom =  (document.body.clientHeight - document.body.scrollTop) -580//550;
				   if (menuStat=="opend"){
                       us.style.bottom = document.body.clientHeight - 580//550;
                     }else{
                       us.style.bottom = document.body.clientHeight - 30;
                     }
				}else{
				   if (menuStat=="opend"){
                       us.style.bottom = document.body.clientHeight - 580//550;
                     }else{
                       us.style.bottom = document.body.clientHeight - 30;
                     }
                  
                }
            }
            
        }else{
           //us.style.bottom = document.body.clientHeight - 130;
           
            if (dir=="rtl"){
               us.style.bottom =  (document.body.clientHeight - document.body.scrollTop) -130
             }else{
               us.style.bottom =  document.body.clientHeight - 130;
             }
        }
        
        
        
          for (i=0; i<alldivs.length; i++)
          {
          us= alldivs[i];
          if (us.id == "Logo"){
            us.style.left=0;  //  SAGIV
            break;
			}
          }
        
        
        us.style.display= "";
      }
  }
 }
 }

if ((document.all) || (document.layers))
{
 setInterval("branding()",10);
}



function changeBack(theTd,State){

   var theTdT;
   theTdT = document.getElementById(theTd);
  if (State==1) theTdT.style.backgroundColor="#D8EDFF";
  else theTdT.style.backgroundColor="";
}





//TO GET THE PARAMETER IF THE MENU SHOULD BE SMALL
function menuSize(State){
   IfSmallMenu=State;
   globalMenuHeight=100;
   branding()
}




//opens or colaps the floating menu
function changeState(){
   var theMenu;
   
  

   theMenu = document.getElementById("menuItem");
  if (theMenu.style.display=="inline") {
       
      if ((WBCMODE=="AuthoringReedit") || (WBCMODE=="AuthoringNew")  ) {
         globalMenuHeight=80; //50;//30
         document.getElementById("logo").style.bottom='530px';//'530px';//500
      }
      else {
         globalMenuHeight=30;
         document.getElementById("logo").style.bottom='580px';
        
      }
      branding();
      theMenu.style.display="none";
      document.all.theStatGif.src="/Masa/images/b_cloaps.gif";
      menuStat="closed";
      
    }
  else {
  
      theMenu.style.display="inline";
      menuStat="opend";
      
      if ((WBCMODE=="AuthoringReedit") || (WBCMODE=="AuthoringNew")  ) {
         globalMenuHeight=100;
         document.getElementById("logo").style.bottom='420px'//'420px';
      }
      else 
      {
      
        if ((WBCMODE!="") || ((NRMODE!="") && NRMODE!="Published")){
          globalMenuHeight=580;//530; //500;
          document.getElementById("logo").style.bottom ='35px';//'55px';//'85px';
        }else{
          globalMenuHeight=80;//50 //30
          document.getElementById("logo").style.bottom = document.body.clientHeight - 130;
          
        } 
        
      }
      
      branding();
      document.all.theStatGif.src="/Masa/images/b_open.gif";
    }
}

function DoFormSubmit( sourceForm, action, target, params, sourceDescription, index ) 
{
	var sourceElement; 
	if( index == null )
		index = "";
	var tmpForm = "<Form id='tmpForm' method='post' action='" + action + "' target='" + target + "'>"; 
	for( var i = 0; i < params.length; i++ ) 
	{ 
		try
		{ 
			sourceElement = document.getElementById(params[i] + index); 
			if(sourceElement.type == "checkbox")
			{
				if ( sourceElement.checked )
					tmpForm += "<Input type='hidden' value='on' name='" + params[i] + "' />";
				else
					tmpForm += "<Input type='hidden' value='off' name='" + params[i] + "' />";
			}
			else
			{
				// It works now only for text fields. If you need more, add checking of tagname here 
				tmpForm += "<Input type='hidden' value='" + sourceElement.value + "' name='" + params[i] + "' />";
			}
		} 
		catch( Ex ) {} 
	} 
	if( sourceDescription != undefined && sourceDescription != null )
		tmpForm += "<Input type='hidden' value='" + sourceDescription + "' name='sourceDescription' />"
	tmpForm += "</Form>";
	document.body.insertAdjacentHTML('beforeEnd', tmpForm); 
	document.forms[document.forms.length-1].submit(); 
}
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)
	}
}


