// CREDITS:
// Newsmemory by Tecnavia SA
// Copyright (c) 2001-2004 Tecnavia SA. All rights reserved.
// Permission given to use the scripts only for visualisation of pages processed by the NewsMemory Service.

var STATUS_DISABLE = 0x4000

var visZoom=1;
var pageOrigX=8;
var pageOrigY=35;
if (this.pageZoom) { // show the page a different size
	visZoom = pageZoom();
}
if (window.sXY) {            //set customized parameters (from page.htm) if exists
   var offset = sXY();
   pageOrigX = offset.px;     //set customized page offset (from page.htm)
   pageOrigY = offset.py;
}

var lastActive = -1;
var selArticle = -1;
var lastSelect = -1;
var divBy2 = 0;
var section="none";
var pagenum=1;
var parentP = parent;
var isIeb = util_isIeP();
var util_bw = util_bwcheck();
var isNs6 = util_bw.ns6;
var isNs4 = util_bw.ns4;
var nsver = util_bw.nsver;
var mzver = util_bw.mzver;
var uIsIe = util_bw.ie || util_bw.dom;
var uIsMac = util_bw.mac;
var css = "";
var totW = "";
var newWindow;
var linkFound;
var emailFound;
var TRIDFound;
var divUrlH = 0;
var isCTRLkey = 0;
var isALTkey = 0;
var isADV = 0;
var alreadyGrid = false;
var realXP = 0;
var realYP = 0;

// ...mouse pointer
var mPx = -1;
var mPy = -1;
   
var forceImgSingleColumn = false;

//if (!util_bw.ns4) isIeb = true;

/* utility func */
function util_clearBlanks(str) {
   return util_clearAllBlanks(str,0);
}
function util_clearAllBlanks(str,intern) {
   var db, sss;
   var i,j,k;
   var out = "";

   if (str != "") {
      sss = str.toString();
      db = sss.split(" ");
      
      for (i=0; (i<db.length) && (db[i] == ""); i++) { }
      for (j=db.length-1; (j>=0) && (db[j] == ""); j--) { }
   
      //alert(db.length + " - " + i + " - " + j);
      for (k=i; k<=j; k++) {
         //alert("'" + db[k] + "'");
         if (db[k] != "") {
            if (intern != 1 && out != "") out = out + " ";
            // if (out != "") out = out + " ";
            out = out + db[k];
         }
      }
   } else {
      out = str;
   }
   
   return(out);
}

function util_bwcheck(){
   this.ver=navigator.appVersion; this.agent=navigator.userAgent
   this.dom=document.getElementById?1:0;
   this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
   this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom)?1:0;
   this.ie4=(document.all && !this.dom)?1:0;
   this.ie=this.ie4||this.ie5||this.ie6;
   this.mac=this.agent.indexOf("Mac")>-1;
   this.opera5=this.agent.indexOf("Opera 5")>-1;
   this.safari=this.agent.toUpperCase().indexOf("SAFARI")>-1;
   this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0;
   this.ns4=(document.layers && !this.dom)?1:0;
   this.nsver = 100;
   if ((pos = this.agent.indexOf("Netscape/")) >= 0) this.nsver = parseFloat(this.agent.substring(pos+9,this.agent.length),10);
   this.mzver = 100;
   if ((pos = this.agent.indexOf("rv:")) >= 0) this.mzver = parseFloat(this.agent.substring(pos+3,this.agent.length),10);
   this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5 || this.safari || this.dom);
   return this
}

function util_isIeP() {
   return (navigator.appName.indexOf("Explorer") >= 0) ? true :false
}
function util_isIe() { return uIsIe; }
function util_isSafari() { return util_bw.safari; }


function util_getFrameW(f) {
   if (!util_isIe() || util_isSafari()) {
      return(f.innerWidth);
   } else {
      return(f.document.body.clientWidth);
   }
}

function util_getFrameH(f) {
   if (!util_isIe() || util_isSafari()) {
      return(f.innerHeight);
   } else {
      return(f.document.body.clientHeight);
   }
}

function path_normalize(path) {
   var toret;
   var times = 0;
   toret = path;
   pos = toret.indexOf("/..");
   while (pos > 0 && times < 10) {
      times++;
      var bstr = toret.substring(0,pos);
      var bpos = bstr.lastIndexOf("/");
      if (bpos > 0) {
         var news = bstr.substring(0,bpos) + toret.substring((pos+3),toret.length);
         toret = news;
         pos = toret.indexOf("/..");
      } else {
         pos = 0;
      }
   }
   return toret;
}

/********************************/
/* Functions for temporary grid */
/********************************/
function temp_sXY(a,b,c,d,e,f,g,h,i,j) {
   this.ox=a;this.oy=b;
   this.px=c;this.py=d;this.pw=e;this.ph=f;
   this.cx=g;this.cy=h;this.cw=i;this.ch=j;
return this};


/* Get correct frames */
var mainW=parent.contents;
var mainB=parent.button;
var mainA=parent.article;
var curPage="parent.page";

if (parent.contents == null) { // dual frame
   if (parent.parent.contents != null) {
      
      parentP = parent.parent;
      mainW=parent.parent.contents;
      mainB=parent.parent.button;
      mainA=parent.parent.article;
      curPage="parent.page."+window.name;
   } else {
      if (parent.opener != null) {
         if (parent.opener.parent.contents != null ) {
      	
            parentP = parent.opener.parent;
            mainW=parent.opener.parent.contents;
            mainB=parent.opener.parent.button;
            mainA=parent.opener.parent.article;
            curPage="parent.opener.parent.page."+window.name;
         }//added for double page pop up
      
         else if (parent.opener.parent.parent.contents != null ) {   
            parentP = parent.opener.parent.parent;
            mainW=parent.opener.parent.parent.contents;
            mainB=parent.opener.parent.parent.button;
            mainA=parent.opener.parent.parent.article;
            curPage="parent.opener.parent.parent.page."+window.name;
         }
      }
   }
}
//alert(mainW);
if (mainW) {
   css = "<link rel=\"stylesheet\" type=\"text/css\" href=\"" + mainW.stylecss + "/layout.css\"" + ">";
}
if (mainW && mainW.document && mainW.document.cmdForm) {
   /* get section and page number */
   var list = null;
   if (mainW.getFormObj) list = mainW.getFormObj("selCateg");
   else list = mainW.document.cmdForm.list;

   if (parent && parent.parent && parent.parent.data) {
   	var dFrame = parent.parent.data;
	   if (window.name == "p1") {
	      section = dFrame.p[parseInt(mainW.document.cmdForm.pIndex.value)].cat
	   } else if (window.name == "p2") {
	      if ( dFrame.p.length > (parseInt(mainW.document.cmdForm.pIndex.value) + 1 ) ) {
	      	section = dFrame.p[parseInt(mainW.document.cmdForm.pIndex.value)+1].cat;
	      } else {
	      	section = "";
	      }
		}
   } else {
      var seid = -1;
      if (list) seid = list.selectedIndex;
      if (seid >=0 ) section = list.options[seid].text;
   }
   pagenum = mainW.document.cmdForm.CurPage.value;
}

function init() {
   // background
   /*
   if (document.body) document.body.bgColor="#BDC9D5"; //C9CDDC
   // border
   var divp = document.getElementById("divp");
   if (divp) divp.style.border="solid #636363 2px";
   */
   
   //tell to button page that the page is finish to load

   //alert( parentP.button.nmlStatus );
   //if( parentP.button.nmlStatus ) return;

   if (parentP && parentP.button && parentP.button.endLoadPage) {
      parentP.button.endLoadPage();
   }
   
      //modification for page jumps
   if(mainW.getPJumpName){
      var artid=0;
      if(mainW.pjumpName != ""){
         
         for(i=0;i<a.length;i++){
            if(a[i].js && a[i].js == mainW.pjumpName)
               artid =i;
         }         
      
         //parent.page.sA(artlink);
         //alert("ARTee"+parent.page.sA);
         parent.page.sA(artid);
         mainW.setPJumpName("");
      }
   }
   
   return true;
}

function setBgGif() {
   if (parent && parent.article) {
      parent.article.document.body.background = "../pics/back.gif";
   } else {
      if (parent && parent.parent && parent.parent.frames) {
         parent.parent.frames["article"].document.body.background = "../pics/back.gif";
      }
   }
}
function sV(xpos) {
   // double mode view set frame RD 21/06/2002
   if (parent.ChangeFrames && parent.ChangeFrames != "undefined") {
      if (mainW.getViewFramePosition) {
      } else {
   	   parent.ChangeFrames("430,*,0");
   	}
      var evt = window.event;
      if (evt && !mainW.openView) {
      	mainW.openView = true;
         var toscro = event.clientX;
         if (window.name == "p2") {
         	toscro += 360;
         }
         if (toscro < 360) toscro = 0;
      	setTimeout("parent.scroll("+toscro+",0);",100);
      }
   }
}

function sh(onoff,which) { // showAreaRB
   if (onoff) {
      if (lastActive >= 0 && lastActive!=which) {
         if (selArticle==lastActive) {
            if (lastSelect >= 0 && lastSelect !=selArticle) {
               showAreaRDoB(0,lastSelect);
            }
            lastSelect = selArticle;
            showAreaRDoB(2,selArticle);
         } else {
            showAreaRDoB(0,lastActive);
         }
      }
      if (onoff == 2 && selArticle>=0 && selArticle != which) {
         showAreaRDoB(0,selArticle);
      }
      lastActive = which;
      showAreaRDoB(onoff,lastActive);
   }   
   //turn off other frame highlight ( yellow selection )
   if (window.name == "page" && !onoff) {
      parent.page.offHighLight();
   }    

   if (window.name == "p1") {
      if (!onoff && parent.p1) { parent.p1.offHighLight(); }
   	if (parent.p2 && parent.p2.offHighLight) {
   		parent.p2.offHighLight();
   	}
   } else {
      if (!onoff && parent.p2) { parent.p2.offHighLight(); }
   	if (parent.p1 && parent.p1.offHighLight) {
   		parent.p1.offHighLight();
   	}
   }
     
   if(f.length >0)
      if (window.showTitle) showTitle(which);
      
}

function offHighLight() {
	showAreaRDoB(0,lastActive);
	if (document.all && document.all.showtitle) {
	   document.all.showtitle.style.visibility = "hidden";
   } else if (document.getElementById("showtitle")) {
      document.getElementById("showtitle").style.visibility = "hidden";
   }
   
}

function offHighLightSelect() {
	showAreaRDoB(0,lastSelect);
	lastSelect = -1;
}

function showAreaRDoB(onoff,which) {
   var toWrite="";
   if (onoff) {
      if (onoff>=2) {
         if (onoff>=10) { todo (10+(onoff-10)%17);
         } else {  todo = 2; }
      } else { todo = 1; }
   } else { todo = 0; }

   for (var i=0;which>=0 && i<a[which].boxlen;i++) {
      var layerIma = eval("document."+"L"+i+"_"+which);
      if (layerIma) {
         switch (todo) {
            case 0 : { layerIma.src = "../pics/none.gif"; break; }
            case 1 : { if (isIeb || nsver >= 7.1 || mzver >= 1.4 ) {layerIma.src = "../pics/none.gif"}
                       else { layerIma.src = "../pics/blue.gif";}; break; }
            case 2 : { if (isIeb || nsver >= 7.1 || mzver >= 1.4) {layerIma.src = "../pics/none.gif"}
                       else { layerIma.src = "../pics/redtrans.gif";}; break; }
            default : { layerIma.src = "../pics/Bck"+todo+".gif"; break; }
         }
      }
      var divIma = null;
      if (isIeb || nsver >= 7.1 || mzver >= 1.4) {
         if (document.all) divIma = eval("document.all.X"+i+"_"+which);
         else divIma = document.getElementById("X"+i+"_"+which);
      }
      if (divIma) {
         var toset = "";
         switch (todo) {
            case 0 : { toset = "url(../pics/none.gif)"; break; }
            case 1 : { toset = "url(../pics/yellowp.gif)"; break; }
            case 2 : { toset = "url(../pics/orangepd.gif)"; break; }
            default : { break; }
         }
         if (divIma.style.background != toset) divIma.style.background = toset;
      }
   }
}
var oldBody = "";
var oldBody2 = "";

function restoreBody() {
   if (parent.page.oldBody != "" && parent.page.oldBody2 != "") {
      parent.page.document.body.innerHTML = parent.page.oldBody;
      parent.page2.document.body.innerHTML = parent.page.oldBody2;
      parent.page.oldBody = "";
      parent.page.oldBody2 = "";
   } else {
      //parent.page.document.body.innerHTML = parent.page2.oldBody;
      //parent.page2.document.body.innerHTML = parent.page2.oldBody2;
      //parent.page2.oldBody = "";
      //parent.page2.oldBody2 = "";
      parent.page.document.body.innerHTML = parent.page.oldBody;
      parent.page.oldBody = "";
      parent.page.oldBody2 = "";
      
   }
}

function checkAltNotUsed() {
   // ...show the low.jpg and titles of the page
   var toWrite = "";
   var toWrite2 = "";
   var evt = window.event;
   var j,il,index,max;
   var lSize=0;
   var lSize2=0;
   
   if (evt && evt.altKey) {
      toWrite += "<table><tr><td>";
      toWrite += "<img _height='128' onClick='restoreBody();' src='" + parent.page.document.images[0].src.replace("graph.jpg","low.jpg") + "' align='left'>";
      toWrite += "</td></tr><tr><td>";
      
      for(j=0;j<parent.page.a.length;j++) {
         max = 0;
         index = 0;
         artlink = 0;
         for (var il=0;il<parent.page.a[j].e.length;il++) {
            var link = parent.page.a[j].e[il].link;
            if (link >= 0) {
               var par = parent.page.p[link];
               for (var is=0;par && is< par.S.length;is++) {
                  if (parent.page.f != null) {
                     
                     if (par.S[is].fontId<parent.page.f.length) {
	                     //family = f[par.S[is].fontId].family;
	                     lSize = parent.page.f[par.S[is].fontId].size;
	                  } else {
	                     //family = "";
	                     lSize = 0;
	                  }      

                     if (max < lSize) {
                        max = lSize;
                        index = is;
                        artlink = link;
                     }
                     
                  } else {
                     index = 0;
                     artlink = 0;
                  }
               }
            }
         }
         par = parent.page.p[artlink];
         if (par.S[index].textV.toUpperCase().indexOf("IMAGE_") < 0 && par.S[index].textV.length > 2) {
            toWrite += "<li>" + par.S[index].textV + "</li><br>";
         }
      }
      toWrite += "</td></tr></table>";
      /*
      if (parent.page2.document.body) {
         toWrite2 += "<table><tr><td>";
         toWrite2 += "<img _height='128' onClick='restoreBody();' src='" + parent.page2.document.images[0].src.replace("graph.jpg","low.jpg") + "' align='left'>";
         toWrite2 += "</td></tr><tr><td>";

         for(j=0;j<parent.page2.a.length;j++) {
            max = 0;
            index = 0;
            artlink = 0;
            for (var il=0;il<parent.page2.a[j].e.length;il++) {
               var link = parent.page2.a[j].e[il].link;
               if (link >= 0) {
                  var par = parent.page2.p[link];
                  for (var is=0;par && is< par.S.length;is++) {
                     if (parent.page2.f != null) {

                        if (par.S[is].fontId<parent.page2.f.length) {
	                        //family = f[par.S[is].fontId].family;
	                        lSize2 = parent.page2.f[par.S[is].fontId].size;
	                     } else {
	                        //family = "";
	                        lSize2 = 0;
	                     }      
                        
                        if (max < lSize2) {
                           max = lSize2;
                           index = is;
                           artlink = link;
                        }
                     } else {
                        index = 0;
                        artlink = 0;
                     }
                  }
               }
            }
            par = parent.page2.p[artlink];
            if (par.S[index].textV.toUpperCase().indexOf("IMAGE_") < 0 && par.S[index].textV.length > 2) {
               toWrite2 += "<li>" + par.S[index].textV + "</li><br>";
            }
         }
         toWrite2 += "</td></tr></table>";
         oldBody2 = parent.page2.document.body.innerHTML;
         parent.page2.document.body.innerHTML = toWrite2;
      }
      */
      oldBody = parent.page.document.body.innerHTML;
      parent.page.document.body.innerHTML = toWrite;
      return true;
   }
}

function sAOld(which) { //setArticle
   return toWrite;
}

function checkFoto(which) {
   var toRet = true;
   return toRet;
}
var curArt;
var curMode=0;
var lastCurMode=0;
var grpMode = false;
var lastGrpNum = -1;
var sameClickedArticle = false;
var setpopUp;
var vMode = 0;
//var dblPagePop = 0;
var pageJumps="";

function sA(which,evt) { //setArticle

  //var evt = window.event;
  //alert(evt + "\nIE:" + isIeb +"\nMac" + uIsMac);
  
  if (evt) {
     if (isIeb) {      
        //mPx = evt.offsetX-10;
        //mPy = evt.offsetY-50;
        mPx = evt.clientX-10;
        mPy = evt.clientY-50;
        //alert("test:" + evt.clientX);
     } else {
        mPx = evt.pageX-10;
        mPy = evt.pageY-50;
     }   
  } else {
     mPx = -1;
     mPy = -1;
  } 
  
  //alert("clicked:" + mPx + "\n" + mPy);
  //alert("c:" + evt.clientX);
  
	sameClickedArticle = false;
	if (f.length && which == curArt) { // se riclicco sullo stesso articolo selezionato in rosso
		sameClickedArticle = true;
	} else {
		lastCurMode = 0;
		curMode = 0;
	   if (window.sAEx) { //usato per decidere come mostrare l'articolo ( testo o grafica)
	      window.sAEx(which,pagenum,section);
	   } else {
	      // based on density reverse mode.
	      if (which != -2) {
   	      if (a[which] && a[which].den!="undefined") {
   	        if (a[which].den < 2 ||
   	           (a[which].den > 100 && a[which].stdd <= 0)) {
   	           if (curMode == 2 ) {
   	           } else {
   	               curMode = (curMode + 1 ) % 2;
   	           } 
   		         //curMode = (curMode + 1 ) % 2;
   		         //Grid
   		         //curMode = (curMode + 1 ) % 3;
   	         }
   	      }
   	   } // ...which = -2   
	   }
	}
	
	// ... if shift pressed force to graphic
  if (evt && evt.shiftKey) {
    curMode = 1;
  }

  isCTRLkey = 0;
  if (evt && evt.ctrlKey) {
    isCTRLkey = 1;
  }
  
  isALTkey = 0;
  if (evt && evt.altKey) {
    isALTkey = 1;
  }

  curArt = which;
  
  // page jump
  
  
  
  
  if (a[which] && a[which].js && a[which].js.length> 0) {
	  if (a[which].jf.length> 0) {
	     var jlabelFrom= parent.contents.pjumpFrom.replace("$$S$",a[which].js);
	     jlabelFrom= jlabelFrom.replace("$$P$",a[which].jf);
        pageJumps+="<A href='javascript:parent.contents.setPJumpName(\""+a[which].js+"\");javascript:parent.contents.gotoPage(\"A\",\""+a[which].jf+"\");'>"+jlabelFrom + "</A><br>";
     }
  	  
	  if (a[which] && a[which].jt && a[which].jt.length> 0) {
	  	//alert("JUMPTO");
	     var jlabelTo= parent.contents.pjumpTo.replace("$$S$",a[which].js);
	     jlabelTo= jlabelTo.replace("$$P$",a[which].jt);
        pageJumps+="<A href='javascript:parent.contents.setPJumpName(\""+a[which].js+"\");javascript:parent.contents.gotoPage(\"A\",\""+a[which].jt+"\");'>"+jlabelTo + "</A><br>";
  	  }
  }

  /* POPUP */
  if ( parent.parent && parent.parent.contents && parent.parent.contents.activePopUp) setpopUp = parent.parent.contents.activePopUp;
  else if (parent.contents && parent.contents.activePopUp) setpopUp = parent.contents.activePopUp;

  modEdit=0;
  //alert("FRAME: "+parent.button);
  //alert("BUTTON: "+parent.button.buttonForm.modedit);
 // alert(parent.button.buttonForm.modedit.checked);

  if(mainB.buttonForm)//  if(parent.button.buttonForm)
  if(mainB.buttonForm.modedit)//   if(parent.button.buttonForm.modedit)
  if(mainB.buttonForm.modedit.checked==true)//     if(parent.button.buttonForm.modedit.checked==true)
         modEdit=1;

  if(modEdit==1)
     callModifyPhp(which);
  else{
  
      if (setpopUp == 1) window.openPopUp("-1");
      //else if(a[which].js && parent.contents.pageJumpsType==1) window.sAgFindCont("-1");
      else if(a[which] && a[which].js && mainW.pageJumpsType==1) window.sAgFindCont("-1");
   	else if(a[which] && a[which].jt && a[which].jt.length> 0) window.printfEx(window.sAg("-1"),css); //do not put to page jumps at the top
      else window.printfEx(pageJumps + window.sAg("-1"),css);
   
  }
  
	/*
	if(mainW.dblPagePop) dblPagePop = mainW.dblPagePop;
   if (setpopUp == 1){
   	 window.openPopUp("-1");
   }else if(mainW.visualMode==1 && (dblPagePop==1)){//if pop up only in double mode and we're in double mode
   	window.openPopUp("-1");
   }else {
   	window.printfEx(window.sAg("-1"),css);
   }
   */

  return false;
}


function callModifyPhp(which){
   
     var page="editpagexml.php";
     var urlToLoad=page+"?pSetup="+parent.contents.pSetup+"&artid="+which;
   
     if (mainW) {
      arg = fp_location;
      //var pos = arg.indexOf("0@");
      //if (pos >= 0) arg = mainW.baseUrl + arg.substring(pos+2,arg.length);
      var pos = arg.indexOf("@");
      if (pos >= 0) {
      	var pageType = arg.charAt(pos-1);
      	if(pageType == 0){
      	   urlToLoad="../load/"+urlToLoad+"&file="+fp_location;
	         arg = mainW.baseUrl + arg.substring(pos+1,arg.length);
	      }else if (pageType == 1){ //is demo
	         urlToLoad="../load/"+urlToLoad+"&file="+fp_location;
	      	arg = mainW.demoBaseUrl + arg.substring(pos+1,arg.length);
	      }else{  //2@ so it arch
	         if (pageType >= 2 && (pageType-2) < mainW.archBaseUrls.length) {
	            if(mainW.archBaseDomains[pageType-2] != ""){
		      	   //make the argument the entire path to the archive server
		            argArray = arg.split("/");
		      	   issueDate = argArray[argArray.length-3];
		      	   arg = "http://"+ mainW.archBaseDomains[pageType-2] + mainW.archBaseUrls[pageType-2] + "/" + argArray[argArray.length-4] + "/" + issueDate.substring(0,4) + "/" + issueDate.substr(4,2) + "/" + argArray[argArray.length-3]+ "/" +argArray[argArray.length-2]+ "/"; 
   		         urlToLoad="http://"+ mainW.archBaseDomains[pageType-2]+"/eeBrowser/frame/arch_version/libphp/"+urlToLoad;
     		         urlToLoad+="&file="+mainW.archBaseDirs[pageType-2]+"@"+fp_location.substring(2);
   		      }else{
		      	   arg = mainW.archBaseUrls[pageType-2] + arg.substring(pos+1,arg.length);
		      	   urlToLoad="../load/"+urlToLoad+"&file="+fp_location;
		      	}
		      } else {
	      		arg = mainW.archBaseUrl + arg.substring(pos+1,arg.length);
	      		urlToLoad="../load/"+urlToLoad+"&file="+fp_location;
	      	}
	      }  
      }
   }
   
   //alert(urlToLoad);
   parent.contents.util_loadPage(parent.article,urlToLoad);
   
   
}

function sAg(which) { //setArticle ret html

   var toret="";
   var pageLocation = "";
   var displayAdFirstClick=0;
   
   var pjump=0;
   
   if (parent.contents)
   	if(parent.contents.displayAdFirstClick)
   	   displayAdFirstClick=parent.contents.displayAdFirstClick;
  
   if (which == "-1") which = curArt;

   if (which != -2) {
      sh(2,which);
      selArticle = which;
   }   

   var grpNum = -1;
	 grpNum = findGroupNum(g,which);

   if (sameClickedArticle) {  //ho selezionato un articolo gia selezionato
      grpNum = -1;
		  lastCurMode = curMode;
		  
		  //curMode = ( curMode + 1 ) % 2; //toggle mode
		  //Grid
		  //curMode = ( curMode + 1 ) % 3; //toggle mode
		  if ( curMode == 2 ) {
		  	  //alert("GRID");
		  	  curMode = 2;  
//		  }else if ( curMode == 3 ) {
//		     curMode = 3;  
		  } else {
 		     curMode = ( curMode + 1 ) % 2; //toggle mode
		  } 
	 }
	 
	 //alert("sagafterSAMEART:" + curMode);
   isADV = 0;
   
   if (which != -2) {
      // ...force set flag to 1
      if ((a[which].cat & 0x7F) == 4) {
         isADV = 1;
      }   
   }
   
   // ...force to text if CTRL key is pressed   
   if (isCTRLkey) { curMode = 0; }
   //if (isALTkey) { curMode = 0; }
   
   // turn off all the layer for articles in group
   if (window.g && lastGrpNum>= 0) {
     	for(var i=0;i<g[lastGrpNum].a.length;i++) {
     	   showAreaRDoB(0,g[lastGrpNum].a[i]);
     	}
     	lastGrpNum = -1;
   }

   if (mainW) {
      arg = fp_location;
      //var pos = arg.indexOf("0@");
      //if (pos >= 0) arg = mainW.baseUrl + arg.substring(pos+2,arg.length);
      var pos = arg.indexOf("@");
      if (pos >= 0) {
      	var pageType = arg.charAt(pos-1);
      	if(pageType == 0){
	         arg = mainW.baseUrl + arg.substring(pos+1,arg.length);
	      }else if (pageType == 1){ //is demo
	      	arg = mainW.demoBaseUrl + arg.substring(pos+1,arg.length);
	      }else{  //2@ so it arch
	         if (pageType >= 2 && (pageType-2) < mainW.archBaseUrls.length) {
		      	arg = mainW.archBaseUrls[pageType-2] + arg.substring(pos+1,arg.length);
		      	if(mainW.archBaseDomains[pageType-2] != ""){
		      	   //make the argument the entire path to the archive server
		            argArray = arg.split("/");
		      	   issueDate = argArray[argArray.length-3];
		      	   arg = "http://"+ mainW.archBaseDomains[pageType-2] + mainW.archBaseUrls[pageType-2] + "/" + argArray[argArray.length-4] + "/" + issueDate.substring(0,4) + "/" + issueDate.substr(4,2) + "/" + argArray[argArray.length-3]+ "/" +argArray[argArray.length-2]+ "/";
		      	   
   		      }else{
   		         
						//arg = mainW.archBaseUrls[pageType-2] + arg.substring(pos+1,arg.length);
						//commented 20080116
   		      }
		      } else {
	      		arg = mainW.archBaseUrl + arg.substring(pos+1,arg.length);
	      	}
	      }  
      }
   }

   //alert("sag2:" + curMode);
   if (curMode == 0 && which != -2) {  //text mode
      if (isADV && !isCTRLkey /*!isALTkey*/) {
         if(displayAdFirstClick==0)
            toret = window.getGraphicADV(which,0,0,pagenum,section,arg); 
         else
            toret=window.getGraphicADV2(which,0,0,pagenum,section,arg);  
      } else {   
         if (window.sAgTextEx) {
            toret=window.sAgTextEx(which,pagenum,section,arg);
         } else {
            if(a[which].js && a[which].jt && mainW.pageJumpsType==1){              
               toret=window.sAgTextArt(which,pagenum,section,0,arg);
            }else{
               toret=window.sAgText(which,pagenum,section,arg);
         }
         }
         pjump=1;
      }   
      if (mainB && mainB.updateParam) {
         mainB.updateParam(curPage,which,1,getThePage(""),fp_location);
      }
   } else if (curMode == 1 && which != -2){ // ...graph mode
      if (grpNum>=0) {
         toret=window.getGraphicMulti(g[grpNum].a,0,40,which,arg);
         lastGrpNum = grpNum;
      } else {
         if (isADV) {
            if(displayAdFirstClick==0)
               toret=window.getGraphicADV2(which,0,0,pagenum,section,arg);
            else
               toret = window.getGraphicADV(which,0,0,pagenum,section,arg);   
         } else {   
            toret=window.getGraphic(which,0,0,pagenum,section,arg);
         }   
      }
      if (mainB && mainB.updateParam) {
         mainB.updateParam(curPage,which,0,getThePage(""),fp_location);
      }
   } else if (curMode == 2){ // ...grid mode
      //Grid
      toret = window.getGrid(which,0,0,pagenum,section,arg);
      if (mainB && mainB.updateParam) {
         mainB.updateParam(curPage,which,3,getThePage(""),fp_location);
      }

   }   

   if(a[which] && a[which].js && parent.dataSearch.a && pjump==1 && parent.contents.pageJumpsType==1){
      
      var contartid=0;
      var pgtype="to";
      var labeljump=a[which].js;
      var pjumpsnum="";
      if(a[which].jt){
         pjumpsnum=a[which].jt;
      }else{
         pjumpsnum=a[which].jf;
         pgtype="from";
      }
      
      var dFrame = parent.data;
      var pgname="";
      var newarg="";
      
      //search page
      for(i=0;i<dFrame.p.length;i++){         
        pg=dFrame.p[i];
        if(pg.page == pjumpsnum){
            pgname=pg.name;
            break;
        }                  
      }

      //search article
      var newpagearray=parent.dataSearch.a;
      for(i=0;i<newpagearray.length;i++){
         if(newpagearray[i].js && newpagearray[i].js==labeljump){
            contartid=i;
            break;
         }
      }
      
      
      argArray = arg.split("/");
      for(i=0;i<argArray.length-2;i++)
         newarg+=argArray[i]+"/";
      
      newarg+=pgname.toLowerCase()+"/";
   
      //alert("CONTARTID: "+contartid);
      //alert(parent.dataSearch.sAgText);      
      //alert("PAGENUM2:"+pjumpsnum+" SECTION: "+section+"ARG2: "+newarg);
      
      var conttext="";
      
      //alert(conttext);
      
      if(pgtype=="to"){
         conttext=parent.dataSearch.sAgText(contartid,pjumpsnum,section,newarg);
         //toret=toret+removeTitle(conttext);
         toret=toret+conttext;
      }else{
         conttext=parent.dataSearch.sAgTextArt(contartid,pjumpsnum,section,0,newarg);
         //toret=conttext+removeTitle(toret);
         toret=conttext+toret;
      }
   }

   return toret;
}

function sAgFindCont(which){
   
   var pjumpsnum="";
   if (which == "-1") which = curArt;

   if (which != -2) {
      sh(2,which);
      selArticle = which;
   }   
   
   if(a[which].jt)
         pjumpsnum=a[which].jt;
   else
         pjumpsnum=a[which].jf;
         
   var labeljump=a[which].js;
   //alert(pjumpsnum);
   
   var dFrame = parent.data;
   //alert(dFrame);
   var pg;
   var pgname ="";
   var filetopass="";
   var newarg="";
   
   for(i=0;i<dFrame.p.length;i++){         
     pg=dFrame.p[i];
     if(pg.page == pjumpsnum){
         pgname=pg.name;
         break;
     }                  
   }
     
   fpArray = fp_location.split("/");
   for(i=0;i<fpArray.length-2;i++)
      filetopass+=fpArray[i]+"/";
   
   filetopass+=pgname.toLowerCase()+"/";

   urlToLoad="../php-script/fullpageContinuation.php?pSetup="+parent.contents.pSetup+"&file="+filetopass;
      
   parent.contents.util_loadPage(parent.dataSearch,urlToLoad);
   
}

function removeTitle(toret){
   
   var first=0;
   var last=0;
   
   while(toret.indexOf("maintitle") > -1){
      
      first=toret.indexOf("<font face='Arial' size='8' class='maintitle'>");
      last=toret.indexOf("</font>",first);
      
      toret=toret.substr(0,first)+toret.substring(last+7);

   }
   
   return toret;
   
}

function getThePage(which) {
   var toret="";
   if (typeof isFromSearch != "undefined") {
      toret += o[which];
   } else {
      toret += document.location;
   }
   return toret;
}

function isInGroup(grp,art,mode) {
	var grpLen=grp.length;
	var i;
	var toret= false;
	for(i=0;i<grpLen && !toret;i++) {
		if (grp[i]==art) toret = true;
	}
	return toret;
}

function findGroupNum(grp,art) {
	var i,j;
	var grpLen=grp.length;
	var toret=-1;
	for(i=0;(i<grpLen) && (toret < 0);i++) {
		artLen = grp[i].a.length;
		for(j=0;(j<artLen) && (toret < 0);j++) {
			if (grp[i].a[j]==art) toret = i;
		}
	}
	return toret;
}

function getGraphicMulti(group,x,y,which,xmlpath)  {
   var toWrite = "";
   var toLoad = window.location;
   var xoff = 9999;
   var yoff = 9999;
   for (var el=0;el<rep.length;el++) {
   	if (isInGroup(group,rep[el].a)) {
         xoff = Math.min(xoff,rep[el].c);
         yoff = Math.min(yoff,rep[el].d);
      }
   }
   var zoom = 3.10854;
   if (window.sP) {
      zoom = (Pw/Pwm)*dpi/72;
   }
   var border = 5;
   
   //var imagif = path_normalize(window.location + "/../page/");
   if (xmlpath == "") {
      var imagif = path_normalize(window.location + "/../page/");
   } else {
      var imagif = path_normalize(xmlpath + "/../page/");
   }

   for (var el=0;el<rep.length;el++) {
   	if (isInGroup(group,rep[el].a)) {
        	showAreaRDoB(2,rep[el].a);
         var valCrop = "pag_"+rep[el].a+"_"+rep[el].b;
         var wid = Math.round((rep[el].e-rep[el].c+2) * zoom);
         var hei = Math.round((rep[el].f-rep[el].d+1) * zoom);
         var left =Math.round((rep[el].c - xoff) * zoom) + border + x ;
         var top = Math.round((rep[el].d - yoff) * zoom) + border + y ;
         if (isIeb) {
	         toWrite +="<DIV style='position:absolute ; overflow:hidden;";
	         toWrite +=" left:"+left+"px; top:"+top+"px;";
	         toWrite +=" width:"+wid+"px; height:"+hei+"px";
	         toWrite +="'> <IMG src='"+imagif+valCrop+".jpg' width='"+wid+"' height='"+hei+"'></DIV>\n";
	         toWrite +="<DIV style='position:absolute ; overflow:hidden;";
	         toWrite +=" left:"+left+"px; top:"+top+"px;";
	         toWrite +=" width:"+wid+"px; height:"+hei+"px";
	         toWrite +="'> <IMG src='"+imagif+valCrop+".gif' width='"+wid+"' height='"+hei+"'></DIV>\n";
         } else {
            toWrite +="<LAYER ";
            toWrite +=" left='"+left+"' top='"+top+"' ";
            toWrite +=" width='"+wid+"' height='"+hei+"' visibility='show'";
            toWrite +="'> <IMG src='"+imagif+valCrop+".jpg' width='"+wid+"' height='"+hei+"'></LAYER>\n";
            toWrite +="<LAYER ";
            toWrite +=" left='"+left+"' top='"+top+"' ";
            toWrite +=" width='"+wid+"' height='"+hei+"' visibility='show'";
            toWrite +="'> <IMG src='"+imagif+valCrop+".gif' width='"+wid+"' height='"+hei+"'></LAYER>\n";
         }
      }
   }
   return toWrite;
}

function openPopUp(which) {
   var URL = path_normalize(mainW.location + "/../../page/popDef.htm");
   var sWidth=(screen.availWidth-570);
   var popXSize = 395;
   if ( isNs6 || isNs4 ) {
   	
      // newWindow = window.open(URL,"Show","height=" + (screen.availHeight-190) + ",width=" + sWidth + ",alwaysRaised,screenX="+ (screen.availWidth-sWidth-10) + ",screenY=135,resizable");
      newWindow = window.open(URL,"Show","height=" + (screen.availHeight-190) + ",width=" + popXSize + ",alwaysRaised,screenX="+ (screen.availWidth-popXSize-10) + ",screenY=135,resizable");
   } else {
   	
      // newWindow = window.open(URL,"Show","height=" + (screen.availHeight-190) + ",width=" + sWidth + ",alwaysRaised,left="+ (screen.availWidth-sWidth-10) + ",top=135,resizable");
      newWindow = window.open(URL,"Show","height=" + (screen.availHeight-190) + ",width=" + popXSize + ",alwaysRaised,left="+ (screen.availWidth-popXSize-10) + ",top=135,resizable");
   }
   newWindow.focus();
}

function printf(toWrite) {
	printfEx(toWrite,"");
}


function myscroll(xValue, yValue, operation){
   
   var artFrameW = null;
   var artFrameH = null;

 	 //alert("MYSCROLL" + "\n" + "X " + xValue + " Y " + yValue + " " + operation);   
 	 
   if (curMode == 2 ) {
   	xBottom = Math.floor(xValue/256) - 1;
   	yBottom = Math.floor(yValue/256) - 1;
   	if(xBottom<0) xBottom=0;
   	if(yBottom<0) yBottom=0;
   	artFrame = mainA;
   	
   	if (mainA.window.innerWidth) { //NN
   	  artFrameH = mainA.window.innerWidth;
   	  artFrameW = mainA.window.innerHeight;
      // artFrameW = mainA.document.width;
      // artFrameH = mainA.document.height;
    } else {
   	  artFrameW = parent.document.getElementById("article").width;
   	  artFrameH = parent.document.getElementById("article").height;
   }
   	
   	//alert(artFrame + "\n" + artFrameW + "\n" + artFrameH);
   	
   	xTop = Math.ceil((xValue + artFrameW)/256);
   	yTop = Math.ceil((yValue + artFrameH)/256);
   	
   	xarrayLen = fileNameJpg[0].length;
   	yarrayLen = fileNameJpg.length;
   	
   	if(xTop > xarrayLen) xTop = xarrayLen;
   	if(yTop > yarrayLen) yTop = yarrayLen;
   	
   	//DOUBLE ARRAYS ARE [y][x] pairs
   	//change images from xBottom to XTop and YBottom to YTop
   	//alert(xBottom + "\n" + xTop + "\n" + yBottom + "\n" + yTop);
   	
   	for(x=xBottom; x<xTop; x++){
   		for(y=yBottom; y<yTop; y++){
   			if(!fileShown[y][x]){
   				imgNameJ = 'jpg_'+x+'_'+y;
   				imgNameG = 'gif_'+x+'_'+y;
   				if(fileNameJpg[y][x]){	
   				   try {
   					mainA.document.images[imgNameJ].src = fileNameJpg[y][x] + ".jpg";
   					mainA.document.images[imgNameG].src = fileNameGif[y][x] + ".gif";
   					} catch( e ) { /* do nothing */ }
   				}
   				fileShown[y][x] = true;
   			}
   		}
   	}
   	
   	TopThird = Math.ceil(artFrameH /3);
   	firstHalf = Math.ceil(artFrameW/3);
   	if (operation==1) { 
   	   mainA.scroll(xValue-firstHalf, yValue-TopThird); 
   	   if ( !util_isSafari() && !!util_isIe() ) {
   	      mainA.doScroll();
   	   }   
   	}	
   
    realXP = xValue;
    realYP = yValue;
	}
}

/*
function calculateGridPos(offsetXv,offsetYv,operation) {

   var tmpX;
   var tmpY;
   
   if (curMode == 2 ) {
      if (operation==1) {
         tmpX = Math.floor(realXP + offsetXv);
         if ( tmpX<0 ) { tmpX=0; }
         
         tmpY = Math.floor(realYP + offsetYv);
         if ( tmpY<0 ) { tmpY=0; }
      } else {
         tmpX = offsetXv;
         tmpY = offsetYv;
      }   
      myscroll(tmpX,tmpY,operation);
   
      realXP = tmpX;
      realYP = tmpY;
   }
   
}
*/
   
function printfEx(toWrite,css) {
   
   //reset pageJumps
   pageJumps = "";
   var func = "";
   var bodyFunc = "";
   
   if (curMode == 1 && !isNs4 ) {
      func += "<s" + "cript language=\"javascript\" src=\"" + path_normalize(mainW.location.href.substring(0,mainW.location.href.indexOf('?')) + "/../../dual/scroll.js") + "\"></s" + "cript>\n";
      //func += "<s" + "cript language=\"javascript\" src=\"" + path_normalize(mainW.location + "/../../load/browse.js") + "\"></s" + "cript>\n";
      bodyFunc += " style=\"cursor:move;\" onMouseOut='return outPan(event);' onMouseMove='return panGraphics(event);' onMouseDown='return startPan(event);' onMouseUp='return endPan(event);'";
      alreadyGrid = false;
   } else if ( curMode == 2 && !alreadyGrid) {
      func += "<s" + "cript language=\"javascript\" src=\"" + path_normalize(mainW.location.href.substring(0,mainW.location.href.indexOf('?')) + "/../../dual/scroll.js") + "\"></s" + "cript>\n";
      func += "<s" + "cript language=\"javascript\" >";
      func += "var isMoz=false; \n";
      func += "if (document.captureEvents) { document.captureEvents(Event.SCROLL); \n";
      if (!util_isSafari()) {
         func += "isMoz=true; \n";
      }   
      func += "document.onscroll = doScroll; } \n";
      
      func += "</s" + "cript>";
      //func += "<s" + "cript language=\"javascript\" src=\"" + path_normalize(mainW.location + "/../../load/browse.js") + "\"></s" + "cript>\n";
      bodyFunc += " style=\"cursor:move;\" onMouseOut='return outPan(event);' onMouseMove='return panGraphics(event);' onMouseDown='return startPan(event);' onMouseUp='return endPan(event);' onscroll='if (!isMoz) return doScroll(event);'";
      //bodyFunc += " style=\"cursor:move;\" onMouseOut='return outPan(event);' onMouseMove='return panGraphics(event);' onMouseDown='return startPan(event);' onMouseUp='return endPan(event);' onscroll='return doScroll(event);'";
      bodyFunc += " onLoad='parent.page.myscroll(" + realXP + "," + realYP + ",1);'";  
   } else {
      if ( curMode != 2 ) { alreadyGrid = false; }
      if (curMode == 0 && isADV && !isCTRLkey) {
         func += "<s" + "cript language=\"javascript\" src=\"" + path_normalize(mainW.location + "/../../libjs/showadv.js") + "\"></s" + "cript>\n";
      }   
   }   
   
   /* get article frame */
   artFrame = parent.article;
   if (!artFrame) artFrame = parent.parent.article;
   
   if (!alreadyGrid) {
      if (artFrame && toWrite != "") {
      		if (!isIeb) {
      		   artFrame.document.write("<html><head>" + css + func + "</head><body" + bodyFunc + ">\n<div id='content'>\n" + toWrite +"\n</div></body></html>");
      		} else {
      		   artFrame.document.write("<html><head>" + css + func + "</head><body" + bodyFunc + ">\n<div id='content'>\n" + toWrite +"\n</div></body></html>");
      		}
      		//call FILL PAGE JUMP
      		//alert("FILL PAGE JUMP");
      		
      		//JILL LOOK AT THIS COMMENT
      		
      		if(mainW.pageJumpsType==2)loadXMLHTTPRequest();
   		artFrame.document.close();
      }
      if (curMode == 2 ) { alreadyGrid = true; }
      
   } else if (curMode == 2 ) {
      //alert("qui "+ artFrame + "\n" + realXP + "\n" + realYP);
      //artFrame.scroll(realXP,realYP);
      myscroll(realXP,realYP,1);
   }      
}

var rep=new Array();
function makeR(a,b,c,d,e,f) {
   this.a=a;
   this.b=b;
   this.c=c;
   this.d=d;
   this.e=e;
   this.f=f;
   return this;
}

var errX=-4;
var errY=-5;
var ns4=(document.layers && !this.dom)?1:0;
var titleLayer = true;
var firstT = true;
function cL(name, inleft, intop, imgWidth, imgHeight, visible, el ,ar) {
   var toW="";
   var cname = "L"+el+"_"+ar;
   var indRep = rep.length;
      rep[indRep] = new makeR(ar,el,pageOrigX + (inleft-pageOrigX),pageOrigY+(intop-pageOrigY),pageOrigX+(inleft+imgWidth-pageOrigX),pageOrigY + (intop+imgHeight-pageOrigY));
   // var content='<A HREF="#'+ar+'" onClick="return sA('+ar+');" ONMOUSEOVER="sh(1,'+ar+');" ONMOUSEOUT="sh(0,'+ar+');">\n';
   
   imgWidth = Math.round(visZoom*imgWidth);
   imgHeight = Math.round(visZoom*imgHeight);
   if (divBy2) {
      imgWidth = imgWidth / divBy2;
      imgHeight = imgHeight / divBy2;
      inleft = inleft / divBy2;
      intop = intop / divBy2;
   }

  if (firstT) {
   /*
      // ...statistic functions
 	   if (window.stclk_init) {toW += window.stclk_init();}
  	   if (window.stclk_incjs) {toW += window.stclk_incjs();}
      if (window.stclk_exec) {toW += window.stclk_exec();}
   */   
      firstT = false;
   }

   if (titleLayer) {
      titleLayer = false;
      toW += '<div id="overDiv" name="overDiv" style="position:absolute; visibility:hidden; border: solid #000000 1px; z-index:1000;"></div>\n';
   }   

   var content = '<IMG name="'+cname+'" id="'+cname+'" src="../pics/none.gif" border="0" width="'+imgWidth+'" height="'+imgHeight+'">';

	if (ns4) {
      toW += '<layer name="' + name + '" left=' + Math.round(visZoom*(inleft+errX)) + ' top=' + Math.round(visZoom*(intop+errY)) + ' width=' + imgWidth + ' height=' + imgHeight +  ' visibility=' + (visible ? '"show"' : '"hide"') +  '>\n';
		toW += content;
		toW += '</layer>';
	} else {
		toW += '<DIV id="' + name + '" style="position:absolute; overflow:hidden; left:' + Math.round(visZoom*(inleft+errX)) + 'px; top:' + Math.round(visZoom*(intop+errY)) + 'px; width:' + imgWidth + 'px; height:' + imgHeight + 'px; visibility:' + (visible ? 'visible' : 'hidden') + '">\n';
		toW += content;
		toW += '</DIV>';
	}

   /*
   if (titleLayer) {
      titleLayer = false;
   	// if (isNs6 || isNs4) {
   	if (isNs4) {
   		toW += '<layer name="showtitle" left=15 top=0 width=' + (Pwm-16) + ' height=50 visibility=show>\n';
         toW += '<IMG name="titleimage" id="titleimage" src="../pics/none.gif" border="0" width="1" height="1">';
   		toW += '</layer>';
   	} else {
   		toW += '<DIV id="showtitle" name="showtitle" style="position:absolute; overflow:visible; left:15px; top:0px; width:' + (Pwm-16) + 'px; height:50px; visibility: visible>\n';
         toW += '<IMG name="titleimage" id="titleimage" src="../pics/none.gif" border="0" width="1" height="1">';
         toW += '</DIV>';
   	}
   }
   */
   
	document.writeln(toW);
}



function mMap() {
   var toW="";
   var imgPage;
   var imgW = 0;
   var imgH = 0;
   
   for (var i=0;i<rep.length;i++) {
      if (divBy2) {
         toW += '<AREA SHAPE="rect" COORDS="' + (rep[i].c/divBy2) + ','+ (rep[i].d/divBy2) + ','+ (rep[i].e/divBy2) + ','+ (rep[i].f/divBy2) + '"';
      } else {
         toW += '<AREA SHAPE="rect" COORDS="' + (visZoom*rep[i].c+errX) + ','+ (visZoom*rep[i].d+errY) + ','+ (visZoom*rep[i].e) + ','+ (visZoom*rep[i].f) + '"';
      }
      if (window.ver != null) {
         toW += " HREF='#' onClick='sV("+rep[i].c+");sA("+rep[i].a+",event);return (false);' onMouseOver='sh(1,"+rep[i].a+");return(false);' onMouseOut='sh(0,"+rep[i].a+"); return nd();/*return(false);*/'>\n";
         //toW += " HREF='#' ondblclick='switchMode2(3,"+rep[i].a+"); sV("+rep[i].c+");sA("+rep[i].a+",event);return (false);' onClick='sV("+rep[i].c+");sA("+rep[i].a+",event);return (false);' onMouseOver='sh(1,"+rep[i].a+");return(false);' onMouseOut='sh(0,"+rep[i].a+"); return nd();/*return(false);*/'>\n";
      } else {
         toW += ' HREF="#'+rep[i].a+'" onClick="sV('+rep[i].c+');return sAOld('+rep[i].a+');" ONMOUSEOVER="sh(1,'+rep[i].a+');" ONMOUSEOUT="sh(0,'+rep[i].a+'); return nd();" onfocus="this.blur();return (false);">\n';
         //toW += ' HREF="#'+rep[i].a+'" ondblclick="switchMode2(3,'+rep[i].a+');sV('+rep[i].c+');return sAOld('+rep[i].a+');" onClick="sV('+rep[i].c+');return sAOld('+rep[i].a+');" ONMOUSEOVER="sh(1,'+rep[i].a+');" ONMOUSEOUT="sh(0,'+rep[i].a+'); return nd();" onfocus="this.blur();return (false);">\n';
      }
   }
   
   imgPage = document.getElementById("page");
   if (imgPage) {
      imgW = imgPage.width;
      imgH = imgPage.height;
      //<AREA SHAPE="rect" COORDS="0,0,352,650" HREF='#' onClick='sA(-2,event);'>
      toW += '<AREA SHAPE="rect" COORDS="0,0,' + (imgW) + ',' + (imgH) +'" HREF="#" onClick="sA(-2,event);">';
   }   
	 document.writeln(toW);
}

function sANo() { // non edited page
   //alert("sANo");
   if (window.sANoEx) {
      sANoEx(pagenum,section);
   }
  var evt = window.event;
  //alert(evt + "\nIE:" + isIeb +"\nMac" + uIsMac);
  
  if (evt) {
     if (isIeb) {      
        //mPx = evt.offsetX-10;
        //mPy = evt.offsetY-50;
        mPx = evt.clientX-10;
        mPy = evt.clientY-50;
        //alert("test:" + evt.clientX);
     } else {
        mPx = evt.pageX-10;
        mPy = evt.pageY-50;
     }   
  } else {
     mPx = -1;
     mPy = -1;
  } 
   
   css="";
   arg="";
   if (mainW) {
      css = "<link rel=\"stylesheet\" type=\"text/css\" href=\"" + mainW.stylecss + "/layout.css\"" + ">";
      arg = fp_location;
      //var pos = arg.indexOf("0@");
      //if (pos >= 0) arg = mainW.baseUrl + arg.substring(pos+2,arg.length);
      var pos = arg.indexOf("@");
      if (pos >= 0) {
      	var pageType = arg.charAt(pos-1);
      	if(pageType == 0){
	         arg = mainW.baseUrl + arg.substring(pos+1,arg.length);
	      }else if (pageType == 1){ //is demo
	      	arg = mainW.demoBaseUrl + arg.substring(pos+1,arg.length);
	      }else{  //2@ so it arch
	         if (pageType >= 2 && (pageType-2) < mainW.archBaseUrls.length) {
		      	if(mainW.archBaseDomains[pageType-2] != ""){
		      	   //make the argument the entire path to the archive server
		      	   argArray = arg.split("/");
		      	   issueDate = argArray[argArray.length-3];
		      	   arg = "http://"+ mainW.archBaseDomains[pageType-2] + mainW.archBaseUrls[pageType-2] + "/" + argArray[argArray.length-4] + "/" + issueDate.substring(0,4) + "/" + issueDate.substr(4,2) + "/" + argArray[argArray.length-3]+ "/" +argArray[argArray.length-2]+ "/";
		      	   
   		      }else{
   		         arg = mainW.archBaseUrls[pageType-2] + arg.substring(pos+1,arg.length);
   		      }
		      } else {
	      		arg = mainW.archBaseUrl + arg.substring(pos+1,arg.length);
	      	}
	      }  
      }
   }
   
   //Grid
   //alert("saNo");
   toret = window.getGrid(-1,0,0,pagenum,section,arg);
   //alert(toret);
   if (mainB && mainB.updateParam) {
      mainB.updateParam(curPage,-1,3,getThePage(""),fp_location);
   }
   curMode = 2;
   window.printfEx(toret,css);
   
}

var bannerShowed = false;

// ...get the URL and email
function sAgTextURLeMail(which,pageNum,pageSection,imagePath) {
   var toret = "";
   var toWrite = "";
   var family;
   var lSize;
   var isTitle;
   var textToShow;
   var cntLinks = 0;
   
   // ...init variable
   divUrlH = 0;
   if (which >=0 && which < a.length) {
      for (var il=0;il<a[which].e.length;il++) {
         var link = a[which].e[il].link;
	       if (link >= 0) {
            var par = p[link];
	          isLink = false;
	          for (var is=0;par && is< par.S.length;is++) {
              if (par.S[is].fontId<f.length) {
                 family = f[par.S[is].fontId].family;
                 lSize = f[par.S[is].fontId].size;
              } else {
                 family = "";
                 lSize = 0;
              }               

              var textV = par.S[is].textV;              
              textV = removeExtraChar(textV,isTitle);
              textToShow = textV;
//alert(textToShow);
              linkFound = "";
   						textToShow = substLink(textToShow,"http://","");

              if (linkFound != "") {    						
		   				   toret += linkFound;
		   				   cntLinks++;
		   				}   
		   				linkFound = "";
		   				textToShow = substLink(textToShow,"www.","http://");
              if (linkFound != "") { 
                 if (toret != "" ) toret +="<br>";   						
		   				   toret += linkFound;
		   				   cntLinks++;
		   				}   

		   				emailFound = "";
				   		if(window.substMailCustom) textToShow = substMailCustom(textToShow);
				   		else textToShow = substMail(textToShow);
				   		if (emailFound != "") {
				   		   if (toret != "" ) toret +="<br>";   						
				   		   toret += emailFound;
				   		   cntLinks++;
				   	  }  

				   	  TRIDFound = "";
				   	  if (window.findLinks ) textToShow = findLinks(textToShow,pageNum,family,lSize);
				   	  if (TRIDFound != "") {
				   	      toret += TRIDFound;
				   	      cntLinks++;
				   	  } 
            }  
         } // ...link>0   
      }   
   }
   if (toret != "") {
     divUrlH = 20 * cntLinks;      
     if (isNs4) {
        toWrite +="<LAYER ";
        toWrite +=" left='0' top='0' ";
        toWrite +=" width='500' height='" + divUrlH + "' visibility='show'>";
        toWrite +=toret;
        toWrite +="</LAYER>\n";
     } else {
        toWrite +="<DIV style='position:absolute ; overflow:hidden;";
        toWrite +=" left:0px; top:0px;";
        toWrite +=" width:500px; height:" + divUrlH + "px'>";
        toWrite +=toret;
        toWrite +="</DIV>\n";
     }

   }   
   return toWrite;
}   


function sAgText(which,pageNum,pageSection,imagePath) {
   toret = ""
   var grp=-1;
   bannerShowed= false;
   if (window.g) grp = findGroupNum(g,which);
   // add banners in pages requested
   if (pageNum.length > 1 && pageNum.charAt(0) == '0' && pageNum.charAt(1) != "") pageNum = pageNum.substring(1,3);
   if (pageNum.length > 1 && pageNum.charAt(0) == '0' && pageNum.charAt(1) != "") pageNum = pageNum.substring(1,2);
   var pNum = parseInt(pageNum);
   grpMode = false;
   if (grp<0) {
      toret += sAgTextArt(which,pageNum,pageSection,0,imagePath);
   } else {
      grpMode = true;
      for (var i=0;i<g[grp].a.length;i++) {
         var backgr =1;
         if (which==g[grp].a[i]) {
            backgr = 2;
            toret  += "<DIV id='highlightC'>";
         }
         toret += sAgTextArt(g[grp].a[i],pageNum,pageSection,backgr,imagePath);
         if (which==g[grp].a[i]) {
            toret  += "</DIV>";
         }
      }
      if (isIeb) {
	      toret += "<scr"+"ipt>"
	      toret += "document.all.highlightC.scrollIntoView();"
	      toret += "</"+"script>"
	   }
   }
   
   toret += addPageJumpInfo(which);
   if(mainW.adLoc == 0) toret = addDisplayAd(which) + toret;
   if(mainW.adLoc == 2) toret = toret + addDisplayAd(which);
   toret += addCredit(which);
   return toret;
}



function sAgTextArt(which,pageNum,pageSection,init,imagePath) {
   var prevfont;
   var toRepImages = "";
   var toWrite="";
   var prevPar = -1;
   var totalWrittenText = 0;
   var wrapMode = "";
   var lCMode = 2;
   var multi;
   var wasMulti;
   fontsz = "medium";
   if (parent.contents) {
   	if(parent.contents.FontSize)
   		fontsz=parent.contents.FontSize; 
   }
   if (parent.parent.contents) {
   	if(parent.parent.contents.FontSize)
   		fontsz=parent.parent.contents.FontSize; 
   }
   
   if(fontsz == "medium"){
      class_maintitle="maintitle";
      class_subtitle="subtitle";
      class_abody="abody";
      class_aautor="aautor";   	   	
   }
   else {
      class_maintitle="maintitle_"+fontsz;
      class_subtitle="subtitle_"+fontsz;
      class_abody="abody_"+fontsz;
      class_aautor="aautor_"+fontsz;   	      	
   }

   toWrite += "<scr"+"ipt> function gPage(type,show) {"
   toWrite += " var lpag = parent.contents;";
   toWrite += " if (!lpag) {";
   toWrite += "    if (parent.opener.parent.contents) {"
   toWrite += "       lpag=parent.opener.parent.contents; } else {";
   toWrite += "    lpag=parent.opener.parent.parent.contents; } }";
   toWrite += "if (lpag) lpag.gotoPage(type,show);";
   toWrite += "}";
   toWrite += "</scr"+"ipt>";
 
   var tWidth = getGraphicW(which,0,50);

   if (window.checkAlt && checkAlt() ) {
      /* Do nothing */
   } else {
      if (mainW && mainW.getColumnMode) {
         lCMode = mainW.getColumnMode();
      }   
      
      multi = guessMultiColumn(which);
      wasMulti = multi.isMulti;
      
      if (lCMode == 1 || grpMode) {
         multi.isMulti = false;
         wasMulti = false;
      }      
      
      toWrite += "<DIV id=\"topscroll\"></DIV>";
      var tableWidth = "90%";
      if (multi.isMulti) tableWidth = "100%";
      
      
      //PEZZO AGGIUNTO
      
      if ((a[which].cat & 0x7F) == 2) { //table mode
         multi.isMulti = false;
         tableWidth = "100%";
         wrapMode = "nowrap";
      }

      if (tWidth > 0 && tWidth < 400 ) {  //Force Single column mode if width < 400 px
          multi.isMulti = false;
          wasMulti = false;
          tableWidth = "90%";
      }   

      if (forceImgSingleColumn) {  // more than 2 images force in Single column mode
          multi.isMulti = false;
          wasMulti = false;
          tableWidth = "90%";
      }
      
      if (init>=2) {
	      toWrite  += "<TABLE border='0' cellpadding='0' cellspacing='0' width=\"" + tableWidth + "\" bgcolor='lightblue'>";
	   } else {
	      toWrite  += "<TABLE border='0' cellpadding='3' cellspacing='0' width=\"" + tableWidth + "\">";
	   }

      //FINE PEZZO AGGIUNTO

      var textStarted = false;
      var oldSize, newSize;
      
      var newSize = 3;
      var oldSize = 3;
      var first = false;
      var italic, vold, CR, isCity, isTitle;
      var oldFamily="", prevShort, bold, italic, prevBigLetter, sameText;
      var lenToCompare=8;
      var textToShow = "";
      
      prevShort = false;
      prevBigLetter = false;
      sameText = false;
      toDel = "";
      
      var toShowFoto = true;
      var family;
      var prevFamily;
      var lSize;
      var isTable = false;
      var opentext = false;
      var titleOpen = false;
      var isLink;
      var isFirma;
      var isLegenda = false;
      var upTitleWritten = false;
      var titleSize;
      var textT;
      var maxSize = 10;
      var forcedSt = 0;
      var insertedNL = 0;
      var prevNewLine = 0;
      var prevBkN = 0;
      var psCr = -1;
      //toWrite += "<p align='justify'><font style='font-family: Verdana; font-size:12px'>\n";
      //--tolto ALEtoWrite += "<p align='justify'>";
      var prevBr = 0;
      var isBigLetter = 0;
      var prevText = "";
      var cnt1E = 0;
      var double1E=String.fromCharCode(0X1e) + String.fromCharCode(0X1e);
      var isSameText = 0;
      var thereisimage=0;
      var openfont=0;
      
      var isStep=0;

      // set to 1 to get the font attributes, set to 2 to get also the \n and 1xE position
      var toDebug = 0;     
      
      if (which >=0 && which < a.length) {
   
 	      /* Calculate the maxsize of the article */
	      for (var il=0;il<a[which].e.length;il++) {
	         link = a[which].e[il].link;
	         if (link >= 0) {
	            par = p[link];
	            for (var is=0;par && is< par.S.length;is++) {

	               //family = f[par.S[is].fontId].family;
	               textT = par.S[is].textV;
	               
                  if (par.S[is].fontId<f.length) {
	                  family = f[par.S[is].fontId].family;
	                  lSize = f[par.S[is].fontId].size;
	               } else {
	                  family = "";
	                  lSize = 0;
	               }      

	               if ( textT.indexOf("Image ") < 0 && textT.indexOf("Image_") < 0 && textT.length>2) {
	                  if (rule_Title(family,lSize,par.S[is].textV.length,il)) {
	                     titleSize = lSize;
	                     if (titleSize > maxSize ) maxSize = titleSize;
	                  }
	               }
	            }
	         }
	      }

   
         // Draw the text   
         for (var il=0;il<a[which].e.length;il++) {
   
            var link = a[which].e[il].link;
            if (link >= 0) {
               var par = p[link];
               isLink = false;
               for (var is=0;par && is< par.S.length;is++) {
                  var isBr = 0;
                  isLink = isLegenda = isFirma = sameText = CR = isTitle = bold = italic = 0; //init
                  forcedSt = 0;
                  insertedNL = 0;
                  psCr = -1;
                  isBigLetter = 0;
                  isSameText = 0;
                  
                  
                  if (par.S[is].fontId<f.length) {
                     family = f[par.S[is].fontId].family;
                     lSize = f[par.S[is].fontId].size;
                  } else {
                     family = "";
                     lSize = 0;
                  }      

                  // Get the title
	               if (rule_Title(family,lSize,par.S[is].textV.length,il)) {
	                  isTitle = 1;
	               }

                  if ( window.rule_FirmaCustom) {
                     isFirma = rule_FirmaCustom(family,lSize,par.S[is].textV.length,il);
                  }
                     
                  if ( window.custom_checkSameText ) {
                     isSameText = custom_checkSameText(family,lSize,oldFamily,oldSize);
                  }   

                  var fLink = true;
                  
                  if ((a[which].cat & 0x7F) == 2) { //table mode
                     isTable = true;
                  }
                  
                  if ((a[which].cat & 0x7F) == 3) { //Legenda mode
                     isLegenda = true;
                  }
                  
                  if ((a[which].cat & 0x7F) == 4) { //Advertisement mode
                  }
                  
                  if ((a[which].cat & 0x7F) == 5) { //Single column mode
                  }
                  
                  if (tWidth < 270) {  //Force Single column mode if width < 270 px
                  }
                    
                  var fLink = true;
                  
                  var sCr = String.fromCharCode(0X1e);
                  var textV = par.S[is].textV;
                  
                  textToShow = textV;         
                  
                  if ( toDebug) {
                     //alert(textToShow + " " + textToShow.indexOf(sCr));
                  }   
                  
                  /*OLD
                  if ( textToShow.indexOf(sCr) == 0 ) {
                     if (!prevBigLetter && !prevNewLine) {
                        textToShow = textToShow.replace(sCr,"<br _1einit>");
                     } else {
                        textToShow = textToShow.replace(sCr,"");
                     }      
                  } 
                  */
                  /*
                  //THIS IS FROM VERSION 
                  if (textV.indexOf(double1E) >= 0) {
                     textToShow = replaceAll(textToShow,double1E,"<br>");
                  }   
                  */
                  
                  // Check if big letter
                  var tmpText = removeExtraChar(textV,isTitle);
                  tmpText = util_clearBlanks(tmpText);
                  if ( tmpText.length==1 && lSize > 13 ) { isBigLetter = 1; }
                  
                  
                  /* TENTATIVO PER UNIRE DUE BOX CON STESSO FONT
                  if((il+1)<a[which].e.length){
                     var nextlink = a[which].e[il+1].link;
                     var nextpar = p[nextlink];
                     var nexttext= nextpar.S[0].textV;
                     if(nexttext.substr(0,1) == "0x1E"){
                        for(z=1;z<par.S.length;z++){                           
                           if(isBigLetter)
                              textToShow+=par.S[z].textV;
                           else
                              textToShow+=" "+par.S[z].textV;
                        }
                     }
                     //alert("nextpar.S[0].fontId"+nextpar.S[0].fontId);
                     //if(nextpar.S[0].fontId == par.S[is].fontId){
                        //textToShow+= nextpar.S[0].textV;
                        //il++;
                     //}
                  }
                  */


                  //TESTP
                  //alert("PrevShort: " + prevShort + "\nSame text: " + sameText + "\nOld family: " + oldFamily +  "\nOldsize: " + oldSize + "\nFamily: " + family  + "\nSize: " + lSize + "\nprevBigLetter: " + prevBigLetter +"\n\n-" + par.S[is].textV + "-\nChar code (0)" + par.S[is].textV.charCodeAt(0) + "\nIs title: " + rule_Title(family,lSize,par.S[is].textV.length) +"\n" + il +"\nlength: " + par.S[is].textV.length);                   
                  if ( toDebug) {
                     alert("Old family: " + oldFamily +  "\nOldsize: " + oldSize + "\nFamily: " + family  + "\nSize: " + lSize + "\nprevBigLetter: " + prevBigLetter +"\n\n-" + par.S[is].textV+ "\nlen:" + par.S[is].textV.length + "\n" + prevNewLine + "\n" + il);
                  }   
                  
                  if (!isTable) { //not table
	                   if ( isLegenda ) {
                        if(window.findLegendaCustom){
                           textToShow = findLegendaCustom(textToShow);
                        } else {
                           textToShow = findLegenda(textToShow);
                        }
                     } else {
                         textToShow = removeExtraChar(textToShow,isTitle);
                     }   
                  
                  } else {
                     textToShow = AdjustTable(textToShow,lSize);
                  }  // ...not table
                          
                  
                  if (toDebug==2) {
                     alert("nn:" + textV.indexOf("\n"));
                  }   

                                   // 1st rule : if \n insert newline
                  if (textV.indexOf("\n") >= 0) {
                     textToShow = replaceAll(textToShow,"\n","<br>&nbsp;");
                  }
                  
                  
                  //FROM BAK US 2.  US2 has this higher(it is commented )
                  if (textV.indexOf(double1E) >= 0) {
                     textToShow = replaceAll(textToShow,double1E,"<br>");
                  }   

						
						
						
                  // check URL and e-mail before putting <br> New position
						//textToShow = substLink(textToShow,"http://","");  
						//textToShow = substLink(textToShow,"www.","http://");
						if(window.substMailCustom) textToShow = substMailCustom(textToShow);
						else textToShow = substMail(textToShow);
						
						textToShow = linkwoPrefix(textToShow);
						
						
                  //alert("DOPO 1 rule " +textToShow);
                  
                  if (toDebug==2) {
                     alert("1e:" + textV.lastIndexOf(sCr));
                  }  
                  
                  //number of chars to compare to understand if the fonts belong to the same family
                  if(oldFamily.length<lenToCompare || family.length<lenToCompare)
                     lenToCompare =3;
                  
                  // 2nd rule : if BigLetter and font size > 1.5 times the oldSize and the first char of the box is 1E
                  if ( prevBigLetter && ( family != oldFamily || lSize != oldSize ) &&
                     //( oldSize > ( lSize + parseInt(lSize/2,10) ) ) ) {
                     ( lSize > ( oldSize + parseInt(oldSize/2,10) ) ) ) {
                     psCr = textV.indexOf(sCr);
                     if ( psCr==0 && !insertedNL) {
                        if (toDebug==2) textToShow = "<br _2r_begin>" + textToShow;
                        else textToShow = "<br>" + textToShow;
                        insertedNL = 1;
                     }      
                  }      
                  
                  // 2nd rule : if BigLetter and font size > 1.5 times the oldSize and the last char of the previous box is 1E
                  if ( prevBigLetter && ( family != oldFamily || lSize != oldSize ) &&
                     ( oldSize > ( lSize + parseInt(lSize/2,10) ) ) ) {
                     //psCr = textV.lastIndexOf(sCr);
                     psCr = prevText.lastIndexOf(sCr);
                     if ( psCr>0 && (psCr==prevText.length-1) && !insertedNL) {
                        if (toDebug==2) textToShow = "<br _2r_end>" + textToShow;
                        else textToShow = "<br>" + textToShow;
                        insertedNL = 1;
                     }      
                  }      
                  
                  
                  // 3th rule : if not Bigletter 
                  if ( !prevBigLetter && ( family.substr(0,lenToCompare) != oldFamily.substr(0,lenToCompare) || lSize != oldSize ) ) { 
                     psCr = textV.indexOf(sCr);
                     if ( psCr==0 && !insertedNL && /*!prevBkN && */!isSameText) {
                        if (toDebug==2) textToShow = "<br _3r_begin>" + textToShow;
                        else textToShow = "<br>" + textToShow;
                        insertedNL = 1;
                     }
                  }   
                  
                  // 3th rule : if not Bigletter
                  if ( !prevBigLetter && ( family.substr(0,lenToCompare) != oldFamily.substr(0,lenToCompare) || lSize != oldSize ) ) { 
                     //psCr = textV.lastIndexOf(sCr);
                     psCr = prevText.lastIndexOf(sCr);
                     if ( psCr>0 && (psCr==prevText.length-1) && !insertedNL) {
                        if (toDebug==2) textToShow = "<br _3r_end>" + textToShow;
                        else textToShow = "<br>" + textToShow;
                        insertedNL = 1;
                        cnt1E = 0;
                     } else {
                        /*
                        if ( cnt1E == 0 ) { 
                           textToShow = "<br>" + textToShow;
                           insertedNL = 1;
                        } 
                        */  
                     }                             
                  }   

                  if (!insertedNL && !prevBigLetter ) {

                     textToShow = " " + textToShow;
                  }
                  
                  if (isBigLetter) {
                     //textToShow = "<br _bl>" + textToShow;
                  }   
                  
                  // ... check bold and italic style        
                  if (lSize>=16) bold = 1;          
                  if ( family.toLowerCase().indexOf("oblique") >= 0) italic = 1;
                  if ( family.toLowerCase().indexOf("italic") >= 0) italic = 1;
                  if ( family.toLowerCase().indexOf("kursiv") >= 0) italic = 1;
                  if ( family.toLowerCase().indexOf("bold") >= 0 ) bold = 1;
                  if ( family.toLowerCase().indexOf("black") >= 0 ) bold = 1;
                  if ( family.toLowerCase().indexOf("demi") >= 0 ) bold = 1;
                  if ( family.toLowerCase().indexOf("heavy") >= 0 ) bold = 1;
                  if ( family.toLowerCase().indexOf("halbfett") >= 0 ) bold = 1;
                  if ( family.toLowerCase().indexOf("kraeftig") >= 0 ) bold = 1;
                  if ( family.toLowerCase().indexOf("bdital") >= 0 ) {
                     bold = 1;
                     italic = 1;
                  }
                  
                  if (window.checkFontAtt) {
                    var isAtt = window.checkFontAtt(family,lSize);
                    if (isAtt.isBold !=-1 ) { bold = isAtt.isBold; }
                    if (isAtt.isItalic !=-1 ) { italic = isAtt.isItalic; }
                  } 

                  if (lSize>=16) bold = 1;          
                  
               	if (family.indexOf("Euro-") == 0) {
							if (isIeb) {
								textToShow = replaceAll(textToShow,"B","&#8364;");
   						} else {
                        textToShow = replaceAll(textToShow,"B","<b>euro&nbsp;</b>");
   						}
	                  prevShort = true;
						}
						
						
						if ( window.customFixSpecialChars ) {
						   textToShow = customFixSpecialChars(family,lSize,textToShow);
						}   

                  var text = "";
                  var numIma = -1;
                  text += textV;
                  var imgPos;

                  if ( ((imgPos = textV.indexOf("Image ")) >= 0 )  || ((imgPos = textV.indexOf("Image_")) >= 0 ) ) {
                     var index, textI;
                     var Iwidth=350;
                     var Iheight=0;
                     textI = textV.substring(imgPos+6,textV.length);
                     index = textI.indexOf("_");
                     if (index >= 0) {
                        var index2=textI.substring(index+1,textI.length).indexOf("_");
                        Iwidth=parseInt(textI.substring(index+1,textI.length));
                        if (index2>0) {
                          Iheight=parseInt(textI.substring(index+1+index2+1,textI.length));
                        }
                        textI=textI.substring(0,index);
                        if (Iwidth > 350) {
                          Iheight = Iheight*350/Iwidth;
                          Iwidth=350;
                        }
                     }
                     numIma = parseInt(textI);
                  }

                  if (!isNaN(numIma) && numIma >= 0 ) {
                     
                    //PEZZO AGGIUNTO
                    
                    if (opentext) {//never set after declaration (where it == false) consider removing block
               		   toWrite += "</font>\n";
               		   toWrite += "</P>\n";
                  		toWrite += "</td></tr>\n";
                    		toWrite += "<tr><td colspan='4'>";

								//alert("PAGE JUMPS " + pageJumps);
								//if page jumps == "" nothing will be added
								
                        if (!bannerShowed && mainW.adLoc == 1) {
                 		      toWrite += addDisplayAd(which);
                 		   }
                 		   toWrite += "<hr>";
                 	   }
                 	   
                 	   //FINE PEZZO AGGIUNTO
                 	   
                     /*
                     if (isTable) {
                        toWrite += "<font style='font-family: Courier; font-size:12px'>\n";
                     } else {
                        toWrite += "<font _class='"+class_abody+"' >\n";
                     }
                     */
                     
                     var Swidth="";
                     var Sheight="";
                     if (Iwidth>0) Swidth="width='" + Iwidth + "' ";
                     if (Iheight>0) Sheight="height='" + Iheight + "' ";
                     if (toShowFoto && imagePath) {
                        var ima = path_normalize( imagePath + "/../img/Image_" + numIma + ".jpg");
                        toWrite += "<BR><img " + Swidth+Sheight + "src='" + ima+"'><BR>";
                     }
                     
                     thereisimage=1;
                     
                  } else {

                     if (!isLegenda && !isLink) {
                        if (fLink && window.findLinks) { textToShow = findLinks(textToShow,pageNum,family,lSize); }
                     }
                     
                     if (isLink && window.findLinks) { textToShow = findLinks(textToShow,pageNum,family,lSize); }
                     
                     if (isTitle) {

                        if ( (lSize < maxSize-1)  ) { // sotto e sopra titolo
                           toWrite += "<span class='"+class_subtitle+"'>";
                           if (italic) toWrite += "<I>";
                           if (bold) toWrite += "<b>";
                           toWrite += textToShow;
                           if (bold) toWrite += "</b>";
                           if (italic) toWrite += "</I>";
                           toWrite += "</span>";
                           upTitleWritten = true;
                           if ( isStep ==1 ) { isStep = 2; }
                        } else {
                           // up title already write so add a line
                           if (upTitleWritten) {
                              //toWrite += "<hr noshade style='border-style: groove;'></td></tr><tr><td colspan='4'>";
                           }
                            toWrite += "<span class='"+class_maintitle+"'>";
                           if (italic) toWrite += "<I>";
                           if (bold) toWrite += "<b>";
                           toWrite += textToShow;
                           if (bold) toWrite += "</b>";
                           if (italic) toWrite += "</I>";
                           toWrite += "</span>";
                           isStep = 1;
                        }
                        
                     } else {  // not Title
                        
                        if (isStep == 2) { toWrite += "<br>";  isStep = 3;}
                        
                        //if (isFirma) { toWrite += "<br _firma>"; }
                                               
                        //-----------------PEZZO AGGIUNTO
                        
                       if (!opentext) { //solo la prima volta entra qui
	               		if (multi.isMulti) {
	               		   toWrite += "<tr><td width='45%' valign='top'>\n";
                        } else {
	               		   toWrite += "<tr><td  " + wrapMode + " width='80%' valign='top'>\n";
                        }
	                     toWrite +="<P align='justify'>";
	                     
	                     opentext=true;
	                     }
	                  
	                  //----------------------FINE PEZZO AGGIUNTO
                     
                        if ( !prevBigLetter ) {     
                           if (isTable) {
                              toWrite += "<span style='font-family: Courier; font-size:.8em'>\n";
                           } else {
                              toWrite += "<span class='"+class_abody+"'>\n";
                           }
                        }   
                     
                        //-----------------------SECONDO PEZZO AGGIUNTO

                     //alert("TOTWRITTEN: "+totalWrittenText + textToShow.length);
                     //alert("TEXTOSHOW LENGTH: "+textToShow.length);
                     //alert("TEXTOSHOW: "+textToShow);
                     //alert("MULTI COUNT: "+multi.countChar / 2);

                     if (multi.isMulti && ( totalWrittenText + textToShow.length ) > (multi.countChar / 2) ) {
                        multi.isMulti = false; //stop to create column
   	                  if (CR == 1) {
   	                     toWrite += "<BR>";
   	                     CR = 0;
                        }
                        textToShow1 = divideText(textToShow,totalWrittenText,multi.countChar/2,0,bold,italic);
   	                  //if (!isTable && prevFamily != "ZapfDingbats") textToShow1 = replaceAll(textToShow1,"\n","");
                        toWrite += textToShow1;
                        textToShow = divideText(textToShow,totalWrittenText,multi.countChar/2,1,0,0);
               		   if(thereisimage==0)
               		      textToShow="<BR _div>" + textToShow;
               		   if(!prevBigLetter) toWrite += "</span>\n";
               		   if (multi.countChar > 2500) {
                  		   if (isIeb) {
                     		   toWrite += "<br><br><A HREF=\"#\" onClick=\"javascript:document.all.topscroll.scrollIntoView();return false;\" style='color:#0000FF; text-decoration: none'><span style='font-family: Verdana; font-size:.8em;'>Top</span></A>\n";
                           } else {
                  		      toWrite += "<br><br><A HREF=\"#\" onClick=\"javascript:parent.contents.scrollTop();return false;\" style='color:#0000FF; text-decoration: none'><span style='font-family: Verdana; font-size:.8em;'>Top</span></A>\n";
                           }
                        }
               		   toWrite += "</P>\n";
                  		toWrite += "</td><td width='6%'></td>\n";
                  		toWrite += "<td align='justify' width='45%' valign='top'>\n";
	                     toWrite +="<P align='justify'>";
                        if (isTable) {
                           toWrite += "<span style='font-family: Courier; font-size:.8em'>\n";
                        } else {
                           toWrite += "<span class='"+class_abody+"'>\n";
                        }
                     }
                     //alert(textToShow);
                     if(textToShow.indexOf("<br>")!=-1)
                        totalWrittenText += (textToShow.length - 4);
                     else
                        totalWrittenText += textToShow.length;
                        
                        // --------------------FINE SECONDO PEZZO AGGIUNTO
                        

                        if (italic) toWrite += "<I>";
                        if (bold) toWrite += "<b>";
                        toWrite += textToShow;
                        if (bold) toWrite += "</b>";
                        if (italic) toWrite += "</I>";
                        
                        if ( !isBigLetter ) { toWrite += "</span>"; }
                        
                        if (isFirma) { toWrite += "<br>"; }
                        
                     }  // isTitle   
                     
                     
                  } // ...numIma

                  if (toDebug==2) {
                     alert("insertedNL:" + insertedNL + "\nbold:" + bold + "\nitalic:" + italic + "\n" + toWrite);
                  }   

                  // Read Number of 1E
                  while ( (psCr = textV.indexOf(sCr,psCr+1)) >= 0) {
                     cnt1E = cnt1E + 1;
                  }
                  
                  // 
                  prevBigLetter = isBigLetter;

                  if ( textV.indexOf("Image ") < 0 && textV.indexOf("Image_") < 0) {
                    oldFamily = family;
                    oldSize = lSize;
                  }

                  prevText = par.S[is].textV;
                  prevPar = il;
                  prevfont = par.S[is].fontId;                     
                  prevNewLine = insertedNL;
                  
                  // If box has a \n at the end set a variable
                  prevBkN = 0;
                  if ( textV.lastIndexOf("\n") == (textV.length-1) ) {
                     prevBkN = 1;
                  }   

               }  // ...is
            } // ...link
         }  //  
      }
   }   
   //tolto -- toWrite = toWrite + "</p>";
   
   //pezzo aggiunto
      if (opentext) {
		   toWrite += "</span><!--tag may have been open-->\n";
		   toWrite += "</P>\n";
   		toWrite += "</td><td width='2%' valign='top'>\n";
   		toWrite += "</td></tr>\n";
     		toWrite += "<tr height='10'><td>&nbsp;</td></tr>\n";
   	}
   //fine pezzo aggiunto	
   	
   toWrite += "</TABLE>\n\n";
   return toWrite;
}


function sAgTextArtOld(which,pageNum,pageSection,init,imagePath) {
   var prevfont;
   var toRepImages = "";
   var toWrite="";
   var prevPar = -1;
   var totalWrittenText = 0;
   var wrapMode = "";
   var lCMode = 2;
   var multi;
   var wasMulti;
  
   toWrite += "<scr"+"ipt> function gPage(type,show) {"
   toWrite += " var lpag = parent.contents;";
   toWrite += " if (!lpag) {";
   toWrite += "    if (parent.opener.parent.contents) {"
   toWrite += "       lpag=parent.opener.parent.contents; } else {";
   toWrite += "    lpag=parent.opener.parent.parent.contents; } }";
   toWrite += "if (lpag) lpag.gotoPage(type,show);";
   toWrite += "}";
   toWrite += "</scr"+"ipt>";
 
   var tWidth = getGraphicW(which,0,50);

   if (window.checkAlt && checkAlt() ) {
      /* Do nothing */
   } else {
      if (mainW && mainW.getColumnMode) {
         lCMode = mainW.getColumnMode();
      }   
      
      multi = guessMultiColumn(which);
      wasMulti = multi.isMulti;
      
      if (lCMode == 1 || grpMode) {
         multi.isMulti = false;
         wasMulti = false;
      }      
      
/*
      toWrite += "<DIV id=\"topscroll\"></DIV>";
      var tableWidth = "90%";
      if (multi.isMulti) tableWidth = "100%";

	   if (which >=0 && which < a.length) {
         if ((a[which].cat & 0x7F) == 2) { //table mode
            multi.isMulti = false;
            tableWidth = "100%";
            wrapMode = "nowrap";
         }
      }
*/
      toWrite += "<DIV id=\"topscroll\"></DIV>";
      var tableWidth = "90%";
      if (multi.isMulti) tableWidth = "100%";

      if ((a[which].cat & 0x7F) == 2) { //table mode
         multi.isMulti = false;
         tableWidth = "100%";
         wrapMode = "nowrap";
      }

      if (tWidth > 0 && tWidth < 400 ) {  //Force Single column mode if width < 400 px
          multi.isMulti = false;
          wasMulti = false;
          tableWidth = "90%";
      }   

      if (forceImgSingleColumn) {  // more than 2 images force in Single column mode
          multi.isMulti = false;
          wasMulti = false;
          tableWidth = "90%";
      }
      if (init>=2) {
	      toWrite  += "<TABLE border='0' cellpadding='0' cellspacing='0' width=\"" + tableWidth + "\" bgcolor='lightblue'>";
	   } else {
	      toWrite  += "<TABLE border='0' cellpadding='3' cellspacing='0' width=\"" + tableWidth + "\">";
	   }

	   var textStarted = false;
	   var oldSize, newSize;

	   var newSize = 3;
	   var oldSize = 3;
	   var first = false;
	   var italic, vold, CR, isCity, isTitle;
	   var oldFamily, prevShort, bold, italic, prevBigLetter, sameText;
	   var textToShow = "";
	   prevShort = false;
	   prevBigLetter = false;
	   sameText = false;
	   toDel = "";
	   var toShowFoto = true;
	   var family;
	   var prevFamily;
	   var lSize;
	   var isTable = false;
	   var opentext = false;
	   var titleOpen = false;
	   var isLink;
	   var isFirma;
	   var isLegenda = false;
     var upTitleWritten = false;
  	 var titleSize;
	   var textT;
	   var maxSize = 10;
	   var forcedSt = 0;

	   toWrite += "<font style='font-family: Verdana; font-size:.8em'>\n";
	   var prevBr = 0;
	   if (which >=0 && which < a.length) {
	      /* Calculate the maxsize of the article */
	      for (var il=0;il<a[which].e.length;il++) {
	         link = a[which].e[il].link;
	         if (link >= 0) {
	            par = p[link];
	            for (var is=0;par && is< par.S.length;is++) {

	               //family = f[par.S[is].fontId].family;
	               textT = par.S[is].textV;
	               
                  if (par.S[is].fontId<f.length) {
	                  family = f[par.S[is].fontId].family;
	                  lSize = f[par.S[is].fontId].size;
	               } else {
	                  family = "";
	                  lSize = 0;
	               }      

	               if ( textT.indexOf("Image ") < 0 && textT.indexOf("Image_") < 0 && textT.length>2) {
	                  if (rule_Title(family,lSize,par.S[is].textV.length,il)) {
	                     titleSize = lSize;
	                     if (titleSize > maxSize ) maxSize = titleSize;
	                  }
	               }
	            }
	         }
	      }

	      for (var il=0;il<a[which].e.length;il++) {
	
	         var link = a[which].e[il].link;
	         if (link >= 0) {
	            var par = p[link];
	            isLink = false;
	            for (var is=0;par && is< par.S.length;is++) {
	               var isBr = 0;
	               isLink = isLegenda = isFirma = sameText = CR = isTitle = bold = italic = 0; //init
	               forcedSt = 0;

	               //family = f[par.S[is].fontId].family;
	               //lSize = f[par.S[is].fontId].size;

                  if (par.S[is].fontId<f.length) {
	                  family = f[par.S[is].fontId].family;
	                  lSize = f[par.S[is].fontId].size;
	               } else {
	                  family = "";
	                  lSize = 0;
	               }      

	               if (rule_Title(family,lSize,par.S[is].textV.length,il)) {
	                  isTitle = 1;
	               }
	               //TESTP
                 //alert("PrevShort: " + prevShort + "\nSame text: " + sameText + "\nOld family: " + oldFamily +  "\nOldsize: " + oldSize + "\nFamily: " + family  + "\nSize: " + lSize + "\nprevBigLetter: " + prevBigLetter +"\n\n-" + par.S[is].textV + "-\nChar code (0)" + par.S[is].textV.charCodeAt(0) + "\nIs title: " + rule_Title(family,lSize,par.S[is].textV.length) +"\n" + il +"\nlength: " + par.S[is].textV.length);                   
                  
                  if ((a[which].cat & 0x7F) == 2) { //table mode
                     isTable = true;
                     multi.isMulti = false;
                     wasMulti = false;
                  }
	               if ((a[which].cat & 0x7F) == 3) { //Legenda mode
                     isLegenda = true;
                     multi.isMulti = false;
                     wasMulti = false;
                  }
                  if ((a[which].cat & 0x7F) == 4) { //Advertisement mode
                     multi.isMulti = false;
                     wasMulti = false;
                  }
                  if ((a[which].cat & 0x7F) == 5) { //Single column mode
                     multi.isMulti = false;
                     wasMulti = false;
                  }
                  if (tWidth < 270) {  //Force Single column mode if width < 270 px
                     multi.isMulti = false;
                     wasMulti = false;
                  }
                  var fLink = false;
                  /*
                  if (family == "BureauRomanThree-Bold" && lSize==10 ) fLink = true;
                  if (family == "Helvetica-Bold" && lSize==9 && par.S[is].textV.length<25 ) fLink = true;
                  if (family == "Helvetica-Condensed-Bold" && lSize==10 && par.S[is].textV.length<20 ) fLink = true;
                  if (family == "Helvetica-Condensed-Bold" && lSize==9 && par.S[is].textV.length<20 ) fLink = true;
                  if (family == "Helvetica-Condensed-Bold" && lSize==7 && par.S[is].textV.length<45 ) fLink = true;
                  // new font link
                  if (family == "FranklinGothic-Heavy" && lSize>=8 && lSize<=10 ) fLink = true;
                  if (family == "ImperialBT-Bold" && lSize==9 ) fLink = true;
                  */

                  fLink = true;
                  
	               /* Try to Guess if same text*/
	               var sCr = String.fromCharCode(0X1e);
	               var textV = par.S[is].textV;

                  sameText = true;
               	if (prevPar != il) { // <p> differente dal precedente
               	   if (isTable) textV = "<br _caso1>" + textV;
		               if (family != oldFamily || lSize != oldSize) { //change of font
		                  if (!prevBigLetter) { // if article starts with BIG letter
		                     if (window.custom_checkSameText && custom_checkSameText(family,lSize,oldFamily,oldSize) ){ 
                            sameText = true;
                            textV = "&nbsp;" + textV;
                            forcedSt = 1;
  	                     } else {   
                            sameText = false;		                        
                         }   
                         prevShort = false;
	                     }   
	                  } else {
	                     if ( textV.charCodeAt(0) == 8226) {  // if starts with
	                     } else {
		               	   textV = "&nbsp;" + textV;
		               	}
	                     sameText = true;
	                  }
               	} else {
               	   sameText = true;
		               if (family != oldFamily || lSize != oldSize) { //change of font
	               		if (textV.indexOf(sCr) > 1) {
	               		   if (!prevBigLetter) { // if article starts with BIG letter
   		                     if (window.custom_checkSameText && custom_checkSameText(family,lSize,oldFamily,oldSize) ){ 
                              sameText = true;
                              textV = "&nbsp;" + textV;
   		                     } else {   
   		                        sameText = false;   		                        
                           }   
			                  }
			                  //sameText = true;
			               } else {
		                     if (window.custom_checkSameText && custom_checkSameText(family,lSize,oldFamily,oldSize) ){ 
                            sameText = true;
                            textV = "&nbsp;" + textV;
		                     } else {   
                            sameText = false;
                         }   
			               }
		               } else { //stesso font
		               	textV = "&nbsp;" + textV;
	                     sameText = true;
		               }
		            }

                if (isTitle && prevPar != il && !forcedSt) sameText = false;
                
	              /* Adjust door (firma) */
	              var posDoor = textV.indexOf("door");

               	if (posDoor >= 0 && posDoor < 3) { //door is found at the start of subparagraph
               	   if (textV.indexOf(sCr) < posDoor) { //replace CR before Door
               	      textV = textV.replace(sCr,"");
                   }
                   if (textV.indexOf(sCr) > 0) {
            	        textV = textV.replace(sCr,""); //replace CR after Door
                   } else if (textV.length < 30) {
                      textV = "<BR _door>" + textV +"<BR _door1>";
                   }
                }

	              /* check font attributes */
                if (lSize >=16 ) bold = 1;

	              if ( family.toLowerCase().indexOf("oblique") >= 0) italic = 1;
	              if ( family.toLowerCase().indexOf("italic") >= 0) italic = 1;
	              if ( family.toLowerCase().indexOf("bold") >= 0 ) bold = 1;
	              if ( family.toLowerCase().indexOf("black") >= 0 ) bold = 1;
	              if ( family.toLowerCase().indexOf("demi") >= 0 ) bold = 1;
	              if ( family.toLowerCase().indexOf("heavy") >= 0 ) bold = 1;
	              if ( family.toLowerCase().indexOf("bdital") >= 0 ) {
                   bold = 1;
			             italic = 1;
	              }

	              if (window.checkFontAtt) {
	                 var isAtt = window.checkFontAtt(family,lSize);
	                 if (isAtt.isBold !=-1 ) { bold = isAtt.isBold; }
	                 if (isAtt.isItalic !=-1 ) { italic = isAtt.isItalic; }
	              } 
	               
	               /*
                  if (family == "MillerHeadline-Bold" && lSize == 15 && il>2) {
                     textV = "<BR _mhb>" + textV + "<BR _mhb>";
                  }
                  */
                  
                 /* Take care of special char inserted in text ( space, CR ...) */
	               if (!isTable) { //not table
	                  
	               // Check if CR is needed
	               if ( (!first && !prevShort && !sameText) ) CR = 1;
	               if ( textV.charCodeAt(0) == 8226 ) CR = 1;
		             if ( isLegenda ) {
		                if(window.findLegendaCustom){
		                	textV = findLegendaCustom(textV);
		                }else{
		                	textV = findLegenda(textV);
		                }
		             } else {
     	                textV = removeExtraChar(textV,isTitle);
		             }   
		             
		            } else {
		               textV = AdjustTable(textV,lSize);
						}

						/* Subst change of paragraph with CR */
						if (!prevShort) {
						   if (opentext) {
               		   if (isTable) {
               		      textToShow = textV
               		   } else {
               		      textToShow = insertLine(textV);
                        }
                     } else {
                        textToShow = textV;
                     }
               	} else {
               	   if (textV.indexOf("\n") == 0) {
               	      var count = 0;
               	      //textV = textV.replace("\n ","< _brnnn>");
		                  //textV = textV.replace("\n ","&nbsp;&nbsp;");
		                  textV = textV.replace("\n ","");
               	      while (textV.charAt(count) == " ") {
                  	      count++;
                        }
                        textToShow = textV.substring(count,textV.length);
                     } else {
                        textToShow = textV;
                     }
               	}

	               /* Store if short text */
	               if (textV.length <= 2) {
	                  prevShort = true;
	               } else {
	               	prevShort = false;
	               }

               	/* Fix special char */
               	if (family == "PiFontAFT") textToShow = textToShow.replace(/0/g,"<BR>&#9632; ");
               	if (family == "ZapfDingbats") textToShow = "&#9632;";
               	if (family == "MathematicalPi-Six") textToShow = "&#8658;";
               	if (family == "ClarionFractionsPlain") textToShow = "<BR>&#9679;";
               	if (family == "SwissCondFraPlain" && lSize==17) textToShow = "<BR>&#9679;<BR>";
               	if (family == "SwissFraPlain" && lSize==9) textToShow = "<BR>&#9679;";
               	if (family == "EuropeanPi-Three" && lSize==8) textToShow = "<BR>&rArr;";
               	if (family == "EuropeanPi-Three" && lSize==20) textToShow = "&rArr;";

               	if (family == "CXPiFont1General") {
							textToShow = textToShow.replace("<BR>","");
							var i = 0;
							while (i < textToShow.length && textToShow.charAt(i) == " ") {
								i++;
							}
							if (isIeb) {
   							switch (textToShow.charAt(i)) {
   								case "R": textToShow = textToShow.replace("R","&#9679;"); break;
   							}
   						} else {
   							switch (textToShow.charAt(i)) {
   								case "R": textToShow = textToShow.replace("R","<b>-</b>"); break;
   							}
   						}
	                  prevShort = true;
						}

               	if (family.indexOf("Euro-") == 0) {
							if (isIeb) {
								textToShow = replaceAll(textToShow,"B","&#8364;");
   						} else {
                        textToShow = replaceAll(textToShow,"B","<b>euro&nbsp;</b>");
   						}
	                  prevShort = true;
						}
						if ( window.customFixSpecialChars ) {
						   textToShow = customFixSpecialChars(family,lSize,textToShow);
						}   

	               if ( textToShow.indexOf("Image ") < 0 && textToShow.indexOf("Image_") < 0) {
	                  //Store prev info only if text is not image to avoid unwanted <BR>
	                  oldFamily = family;
	                  oldSize = lSize;
	               }

						//textToShow = substLink(textToShow,"http://","");
						//textToShow = substLink(textToShow,"www.","http://");
						if(window.substMailCustom) textToShow = substMailCustom(textToShow);
						else textToShow = substMail(textToShow);

						textToShow = linkwoPrefix(textToShow);
						
	               var text = "";
	               var numIma = -1;
	               text += textV;
	               var imgPos;
	               if ( ((imgPos = textV.indexOf("Image ")) >= 0 )  || ((imgPos = textV.indexOf("Image_")) >= 0 ) ) {
	                  var index, textI;
	                  var Iwidth=350;
	                  var Iheight=0;
                     textI = textV.substring(imgPos+6,textV.length);
	                  index = textI.indexOf("_");
	                  if (index >= 0) {
	                     var index2=textI.substring(index+1,textI.length).indexOf("_");
	                     Iwidth=parseInt(textI.substring(index+1,textI.length));
	                     if (index2>0) {
	                        Iheight=parseInt(textI.substring(index+1+index2+1,textI.length));
	                     }
	                     textI=textI.substring(0,index);
	                     if (Iwidth > 350) {
	                        Iheight = Iheight*350/Iwidth;
	                        Iwidth=350;
	                     }
	                  }
	                  numIma = parseInt(textI);
	               }

	               if (!isNaN(numIma) && numIma >= 0 ) {
                     if (titleOpen) {
                        toWrite += "</td></tr>\n";
                        titleOpen = false;
                     }
                  	if (opentext) {
               		   toWrite += "</font>\n";
               		   toWrite += "</P>\n";
                  		toWrite += "</td></tr>\n";
                    		toWrite += "<tr><td colspan='4'>";
                    		if (!bannerShowed && mainW.adLoc == 1) {
                    		   toWrite += addDisplayAd(which);
                    		}



                    		toWrite += "<hr>";
                        if (isTable) {
                           toWrite += "<font style='font-family: Courier; font-size:12px'>\n";
                        } else {
                           toWrite += "<font class='abody' _style='font-family: Arial; font-size:.8em'>\n";
                        }
                  	}
	                  var Swidth="";
	                  var Sheight="";
	                  if (Iwidth>0) Swidth="width='" + Iwidth + "' ";
	                  if (Iheight>0) Sheight="height='" + Iheight + "' ";
	                  if (toShowFoto && imagePath) {
	                     var ima = path_normalize( imagePath + "/../img/Image_" + numIma + ".jpg");
	                     toWrite += "<BR><img " + Swidth+Sheight + "src='" + ima+"'><BR>";
	                  }
	               } else if (isTitle) {
	                  if (multi.isMulti == false && wasMulti == true) multi.isMulti = true;
	                  if (opentext) {
	                     toWrite += "</font>\n";
	                     toWrite +="</P>";
	               		toWrite += "</td>";

	               		if (!multi.isMulti) toWrite += "<td width='20%'>&nbsp;</td>";
	               		if (!isLegenda) {
	               		   toWrite += "</tr>\n";
	   	            	   toWrite += "<tr height='10'><td _bgcolor='#F9F8F8'>&nbsp;</td></tr>\n";
	   	            	}   
	                     opentext= false;
	                  }

                     if (!isLegenda && !isLink) {
                        //if (fLink && window.findLinks) textToShow = " " + findLinks(textToShow,pageNum) + " ";
                        if (fLink && window.findLinks) textToShow = findLinks(textToShow,pageNum,family,lSize);
                     }
                     
                     if (isLink && window.findLinks) textToShow = findLinks(textToShow,pageNum,family,lSize);
                     
                     if (CR == 1 && !isLegenda) {
                        toWrite += "</td></tr>\n";
                        titleOpen = false;
                     }
	                  if (!titleOpen) {
	                     toWrite += "<tr><td colspan='4'>";
	                     titleOpen = true;
                     }
                     if ( (lSize < maxSize-1)  ) { // sotto e sopra titolo
	                     //toWrite += "<font class='subtitle' _style='font-family: Arial; font-size:14px'>";
	                     toWrite += "<font face='Arial' size='6' class='subtitle'>";
	                     if (italic) toWrite += "<I>";
	                     if (bold) toWrite += "<b>";
	                     toWrite += textToShow;
	                     if (bold) toWrite += "</b>";
	                     if (italic) toWrite += "</I>";
	                     toWrite += "</font>";
	                     upTitleWritten = true;
	                  } else {
	                     // up title already write so add a line
	                     if (upTitleWritten) {
	                        //toWrite += "<hr noshade style='border-style: groove;'></td></tr><tr><td colspan='4'>";
	                     }
	                     //toWrite += "<font style='font-family: Arial; font-size:68px; font-weight:bold'><font class='maintitles'>";
	                      toWrite += "<b><font face='Arial' size='8' class='maintitle'>";
	                     if (italic) toWrite += "<I>";
	                     if (bold) toWrite += "<b>";
	                     toWrite += textToShow;
	                     if (bold) toWrite += "</b>";
	                     if (italic) toWrite += "</I>";
	                     toWrite += "</font></b>";
	                  }
	               } else {
                     if (titleOpen) {
                        toWrite += "</td></tr>\n";
                        titleOpen = false;
                     }
	                  if (!opentext) {
	               		if (multi.isMulti) {
	               		   toWrite += "<tr><td width='45%' valign='top'>\n";
                        } else {
	               		   toWrite += "<tr><td  " + wrapMode + " width='80%' valign='top'>\n";
                        }
	                     toWrite +="<P align='justify'>";
                        if (isTable) {
                           toWrite += "<font style='font-family: Courier; font-size:12px'>\n";
                        } else {
                           toWrite += "<font class='abody' _style='font-family: Arial; font-size:.8em'>\n";
                        }
                        opentext=true;
	                  }

                     if (!isLegenda && !isLink) {
                        if (fLink && window.findLinks) textToShow = " " + findLinks(textToShow,pageNum,family,lSize) + " ";
                     }
                     if (isLink && window.findLinks) textToShow = findLinks(textToShow,pageNum,family,lSize);

                     if (multi.isMulti && ( totalWrittenText + textToShow.length ) > (multi.countChar / 2) ) {
                        multi.isMulti = false; //stop to create column
   	                  if (CR == 1) {
   	                     toWrite += "<BR _CR>";
   	                     CR = 0;
                        }
                        textToShow1 = divideText(textToShow,totalWrittenText,multi.countChar/2,0,bold,italic);
   	                  if (!isTable && prevFamily != "ZapfDingbats") textToShow1 = replaceAll(textToShow1,"\n","");
                        toWrite += textToShow1;
                        textToShow = "<BR _div>" + divideText(textToShow,totalWrittenText,multi.countChar/2,1,0,0);
               		   toWrite += "</font>\n";
               		   if (multi.countChar > 2500) {
                  		   if (isIeb) {
                     		   toWrite += "<br><br><A HREF=\"#\" onClick=\"javascript:document.all.topscroll.scrollIntoView();return false;\" style='color:#0000FF; text-decoration: none'><font style='font-family: Verdana; font-size:12px'>Top</font></A>\n";
                           } else {
                  		      toWrite += "<br><br><A HREF=\"#\" onClick=\"javascript:parent.contents.scrollTop();return false;\" style='color:#0000FF; text-decoration: none'><font style='font-family: Verdana; font-size:12px'>Top</font></A>\n";
                           }
                        }
               		   toWrite += "</P>\n";
                  		toWrite += "</td><td width='6%'></td>\n";
                  		toWrite += "<td align='justify' width='45%' valign='top'>\n";
	                     toWrite +="<P align='justify'>";
                        if (isTable) {
                           toWrite += "<font style='font-family: Courier; font-size:12px'>\n";
                        } else {
                           toWrite += "<font class='abody' _style='font-family: Arial; font-size:.8em'>\n";
                        }
                     }
                     totalWrittenText += textToShow.length;
                     if ( family == "FranklinGothic-Roman" && lSize==9 ) toWrite += "<BR _got>";
                     if ( prevFamily == "PiFontAFT" ) {
                     } else {
                        if (CR == 1 && !isLegenda) toWrite += "<BR _CR1>";
                     }
	                  if (bold) toWrite += "<B>";
	                  if (italic) toWrite += "<I>";
	                  if (!isTable && prevFamily != "ZapfDingbats") {
                        textToShow = replaceAll(textToShow,"\n","");
                     }
	                  toWrite += textToShow;
	                  if (italic) toWrite += "</I>";
	                  if (bold) toWrite += "</B>";
	               }

	               count = 0;
         	      while (textToShow.charAt(count) == " ") count++;
                  textToShow = textToShow.substring(count,textToShow.length);

	               /*********** set all variable used in the next loop *******************/
	               prevBigLetter = false;
	               if ( ( textToShow.length <= 2 && lSize > 16 ) || (textV.indexOf("«") == 0 && textV.length < 4)) { //Big letter or start with «
	                  prevBigLetter = true;
	               }
	               prevShort = false;
	               if (textV.length <= 2 || (textV.charAt(textV.length-1) == ":") || family == "CoopSonderzeichen" || family == "ZapfDingbats") {
	                  prevShort = true;
	               }
	               prevfont = par.S[is].fontId;
	               prevFamily = family;
	               prevText = textV;
	               prevPar = il;
	               first = false;
	            }
	         }
	      }
	   }

   	if (opentext) {
		   toWrite += "</font>\n";
		   toWrite += "</P>\n";
   		toWrite += "</td><td width='2%' valign='top'>\n";
   		toWrite += "</td></tr>\n";
     		toWrite += "<tr height='10'><td>&nbsp;</td></tr>\n";
   	}
	   toWrite += "</TABLE>\n\n";
	   /*
      if (mainW) {
      	//add statistics on click passing it article id as well
      	toWrite += mainW.stclk(2, which,section,pagenum);
         
         if(mainW.displayAd && mainW.displayAd==1){
            toWrite += mainW.makeBanner(mainW);
         }
   	   toWrite += mainW.getRights(mainW);
   	}
      toWrite += "\n\n";
      */
   }
   if(window.findLinksAfter) toWrite = findLinksAfter(toWrite);
   return toWrite;
}


function addCredit(which) {
   var toWrite = "";

   if (mainW) {
   	//add statistics on click passing it article id as well
   	if(window.typeThree && window.typeThree==1){
   		
   	}else{
   		toWrite += mainW.stclk(2, which,section,pagenum,"");
		}
      
  		if (!bannerShowed) {
         if(mainW.displayAd && mainW.displayAd==1){
            toWrite += mainW.makeBanner(mainW);
         } else if(mainW.displayAd && mainW.displayAd==2){
      		toWrite += mainW.makeBannerEx(mainW);
      	} else if(mainW.displayAd && mainW.displayAd==3){
      		toWrite += mainW.makeBannerCustom(mainW);
      	}
         bannerShowed = true;
      }
	   toWrite += mainW.getRights(mainW);
	}
   toWrite += "\n\n";

   return toWrite;   
}   

function addDisplayAd(which) {
   var toWrite = "";

   if (mainW) {
   	//add statistics on click passing it article id as well
   	//toWrite += mainW.stclk(2, which,section,pagenum);
      
  		if (!bannerShowed) {
         if(mainW.displayAd && mainW.displayAd==1){
            toWrite += mainW.makeBanner(mainW);
         } else if(mainW.displayAd && mainW.displayAd==2){
      		toWrite += mainW.makeBannerEx(mainW);
      	} else if(mainW.displayAd && mainW.displayAd==3){
      		toWrite += mainW.makeBannerCustom(mainW);
      	}
         bannerShowed = true;
      }
	}
   toWrite += "\n\n";

   return toWrite;   
}   


var articleIn = new Array();


function getGraphicW(which,x,y) {
   getGraphicWEx(which,x,y,1,"",0);
}   

function getGraphicWEx(which,x,y,zoomFactor,xmlpath,findArts) {
   var tLeft = 1000;
   var tRight = 0;
   // customized offset parameters to be read.
   var custXoff = 8;
   var custYoff = -13;
   var Xoffset = 3 ;
   var Yoffset = 3 ;
   var xOffc = 1;
   var yOffc = 1;
   var wOffc = 2;
   var hOffc = 2;
   
   if (which>=0 && which <= a.length || xmlpath != "" ) {
      var xoff = 9999;
      var yoff = 9999;
      var xend = 0;
      var yend = 0;

      for (var el=0;el<rep.length;el++) {
         if (rep[el].a==which) {
            xoff = Math.min(xoff,rep[el].c);
            yoff = Math.min(yoff,rep[el].d);
            xend = Math.max(xend,rep[el].e);
            yend = Math.max(yend,rep[el].f);
         }
      }
      var border = 5;
      
      if(findArts == 1) { //se non provengo da sagtexart
      //if (xmlpath == "") {
         var isArtIn;
         articleIn.length = 0;
         for (var i=0;i<a.length;i++) {
            isArtIn = true;
            for (var el=0;el<rep.length && isArtIn;el++) {
               if (rep[el].a==i) {
                  if (rep[el].c >= xoff && rep[el].e <= xend && rep[el].d >= yoff && rep[el].f <= yend) {  //
                  } else {
                     isArtIn = false;
                  }
               }
            }
            if (isArtIn) articleIn[articleIn.length] = i;
         }
      //}
      }
      
      if ( (window.ver && (window.ver() > 1)) ) {
         if (window.getPageOffset) {  //set customized page offset from corsera_crop.js (if exists)
            var offset = getPageOffset();
            custXoff = offset.xOff;
            custYoff = offset.yOff;
         }
         if (window.setOffParam) {    //set the customized crop offset from corsera_crop.js (if exists)
            var offset = setOffParam();
            xOffc = offset.x ;
            yOffc = offset.y ;
            wOffc = offset.w ;
            hOffc = offset.h ;
         }
         if (window.sXY) {            //set customized parameters (from page.htm) if exists
            var offset = sXY();
            custXoff = offset.px;     //set customized page offset (from page.htm)
            custYoff = offset.py;
            Xoffset = offset.ox ;     //set the Xoffset and Yoffset parameters (from page.htm)
            Xoffset = offset.oy ;
            xOffc = offset.cx ;       //set the customized crop offset (from page.htm)
            yOffc = offset.cy ;
            wOffc = offset.cw ;
            hOffc = offset.ch ;
         }

         var totXoff = custXoff + xOffc + Xoffset ;
         var totYoff = custYoff + yOffc + Yoffset ;
         var zoomX = 3.10854;
         var zoomY = 3.10854;

         if (window.sP) {
            var dimHrX = Math.floor(Pw * dpi / 72) ;
            var dimHrY = Math.floor(Ph * dpi / 72) ;
            zoomX =  dimHrX / Pwm ;
            zoomY =  dimHrY / Phm ;
         }

         zoomX = zoomX * zoomFactor;
         zoomY = zoomY * zoomFactor;

         xoff = Math.floor((xoff - totXoff) * zoomX);
         yoff = Math.floor((yoff - totYoff) * zoomY);

	      for (var el=0;el<rep.length;el++) {
	         var isIn = false;
	         if (rep[el].a==which || isInArticleList(rep[el].a)) {
	            var wid = Math.floor((rep[el].e - rep[el].c + wOffc) * zoomX) ;
	            var hei = Math.floor((rep[el].f - rep[el].d + hOffc) * zoomY) ;
	            var left = (Math.floor((rep[el].c - totXoff) * zoomX) - xoff) + border + x ;
	            var top  = (Math.floor((rep[el].d - totYoff) * zoomY) - yoff) + border + y ;
               var fullW = parseInt(left,10) + parseInt(wid,10);
               if (tRight <= fullW) tRight = fullW;
	            if (tLeft >= left) tLeft = left;
	         }
	      }
      }
   }
   fWidth = parseInt(tRight,10) - parseInt(tLeft,10);
   return fWidth;
}

function getGraphicH(which,x,y) {
   getGraphicHEx(which,x,y,1,"");
}

function getGraphicHEx(which,x,y,zoomFactor,xmlpath) {
   var tTop = 1000;
   var tBottom = 0;
   var fHeight;
   // customized offset parameters to be read.
   var custXoff = 8;
   var custYoff = -13;
   var Xoffset = 3 ;
   var Yoffset = 3 ;
   var xOffc = 1;
   var yOffc = 1;
   var wOffc = 2;
   var hOffc = 2;

    if (which>=0 && which <= a.length || xmlpath != "") {
      var xoff = 9999;
      var yoff = 9999;
      var xend = 0;
      var yend = 0;

      for (var el=0;el<rep.length;el++) {
         if (rep[el].a==which) {
            xoff = Math.min(xoff,rep[el].c);
            yoff = Math.min(yoff,rep[el].d);
            xend = Math.max(xend,rep[el].e);
            yend = Math.max(yend,rep[el].f);
         }
      }
      var border = 5;

      var isArtIn;
      articleIn.length = 0;
      for (var i=0;i<a.length;i++) {
         isArtIn = true;
         for (var el=0;el<rep.length && isArtIn;el++) {
            if (rep[el].a==i) {
               if (rep[el].c >= xoff && rep[el].e <= xend && rep[el].d >= yoff && rep[el].f <= yend) {  //
               } else {
                  isArtIn = false;
               }
            }
         }
         if (isArtIn) articleIn[articleIn.length] = i;
      }
      
      if (window.ver && (ver() > 1)) {
         if (window.getPageOffset) {  //set customized page offset from corsera_crop.js (if exists)
            var offset = getPageOffset();
            custXoff = offset.xOff;
            custYoff = offset.yOff;
         }
         if (window.setOffParam) {    //set the customized crop offset from corsera_crop.js (if exists)
            var offset = setOffParam();
            xOffc = offset.x ;
            yOffc = offset.y ;
            wOffc = offset.w ;
            hOffc = offset.h ;
         }
         if (window.sXY) {            //set customized parameters (from page.htm) if exists
            var offset = sXY();
            custXoff = offset.px;     //set customized page offset (from page.htm)
            custYoff = offset.py;
            Xoffset = offset.ox ;     //set the Xoffset and Yoffset parameters (from page.htm)
            Xoffset = offset.oy ;
            xOffc = offset.cx ;       //set the customized crop offset (from page.htm)
            yOffc = offset.cy ;
            wOffc = offset.cw ;
            hOffc = offset.ch ;
         }

         var totXoff = custXoff + xOffc + Xoffset ;
         var totYoff = custYoff + yOffc + Yoffset ;
         var zoomX = 3.10854;
         var zoomY = 3.10854;

         if (window.sP) {
            var dimHrX = Math.floor(Pw * dpi / 72) ;
            var dimHrY = Math.floor(Ph * dpi / 72) ;
            zoomX =  dimHrX / Pwm ;
            zoomY =  dimHrY / Phm ;
         }

         zoomX = zoomX * zoomFactor;
         zoomY = zoomY * zoomFactor;
         
         xoff = Math.floor((xoff - totXoff) * zoomX);
         yoff = Math.floor((yoff - totYoff) * zoomY);

	      for (var el=0;el<rep.length;el++) {
	         var isIn = false;
	         if (rep[el].a==which || isInArticleList(rep[el].a)) {
	            var wid = Math.floor((rep[el].e - rep[el].c + wOffc) * zoomX) ;
	            var hei = Math.floor((rep[el].f - rep[el].d + hOffc) * zoomY) ;
	            var left = (Math.floor((rep[el].c - totXoff) * zoomX) - xoff) + border + x ;
	            var top  = (Math.floor((rep[el].d - totYoff) * zoomY) - yoff) + border + y ;
              var fullH = parseInt(top,10) + parseInt(hei,10);
              if (tBottom <= fullH) tBottom = fullH;
	            if (tTop >= top) tTop = top;
	         }
	      }
      }
   }
   fHeight = parseInt(tBottom,10) - parseInt(tTop,10);
   return fHeight;
}

function isInArticleList(art) {
   var toret = false;
   for(var i=0;i<articleIn.length && !toret;i++) {
      if (articleIn[i] == art ) toret = true;
   }
   return toret;
}

function guessMultiColumn(which) {
   var startOfText = false;
   var toret = new multiInfo();
   var lSize=0;
   var family = "";
   
   if (f.length > 0 && which >=0 && which < a.length) {
      for (var il=0;il<a[which].e.length;il++) {
         var link = a[which].e[il].link;
         if (link >= 0) {
            var par = p[link];
            for (var is=0;par && is< par.S.length;is++) {
               
               //family = f[par.S[is].fontId].family;
               //lSize = f[par.S[is].fontId].size;
               
               if (par.S[is].fontId<f.length) {
                  family = f[par.S[is].fontId].family;
                  lSize = f[par.S[is].fontId].size;
               } else {
                  family = "";
                  lSize = 0;
               }                     
               
               if (!rule_Title(family,lSize,par.S[is].textV.length,il) && par.S[is].textV.indexOf("Image_") < 0) {
                  toret.countChar += removeExtraChar(par.S[is].textV).length;
                  startOfText = true;
               } else if (par.S[is].textV.indexOf("Image_") >= 0) {
                  toret.images++;
               } else if (startOfText) {
                  //toret.isMulti = false;
               }
            }
         }
      }
   }
   if (toret.countChar < 400) toret.isMulti = false;
   return toret;
}

function multiInfo() {
   this.isMulti = true;
   this.images = 0;
   this.countChar = 0;
   return this;
}

function divideText(text,writtenText,halfChar,mode,bold,italic) {
   toret = "";
   
   //alert("TEXT:"+text);
   /*
   alert("br"+text.indexOf("<br "));
   alert("brend: "+text.indexOf(">",text.indexOf("<br ")));
   */
   //var br_start = text.indexOf("<br>");
  // var br_end = br_start +4;
   
  // firsttag = text.substr(br_start, (br_end-br_start)+1);
  // text = text.substr(br_end+1);
   //----writtenText = writtenText - firsttag.length;
   
   //alert("FIRSTTAG: "+firsttag);
   //alert("TEXT: "+text);
   
   
   var startPos = halfChar - writtenText;
   while(text.charAt(startPos) != " " && startPos < text.length) {
      startPos++;
   }

   if ( (pos = text.indexOf("<A")) >= 0 ) {
      var APos = 0;
      ATagOpen = text.indexOf("<A",APos);
      while ( ATagOpen >= 0 && ATagOpen <= startPos ) {
         ATagClose = text.indexOf("</A>",ATagOpen);
         if (ATagClose > startPos) {
            startPos = ATagOpen;
         }
         ATagOpen = text.indexOf("<A",ATagOpen + 1);
      }
   }

   // code used to avoid cut of text in the middle of font tag ( <font>...</font> )
   if ( (pos = text.indexOf("<font")) >= 0 ) {
      var fontPos = 0;
      FontTagOpen = text.indexOf("<font",fontPos);
      while ( FontTagOpen >= 0 && FontTagOpen <= startPos ) {
         FontTagClose = text.indexOf("</font>",FontTagOpen);
         if (FontTagClose > startPos) {
            startPos = FontTagOpen;
         }
         FontTagOpen = text.indexOf("<font",FontTagOpen + 1);
      }
   }

   if (bold) toret += "<B>";
   if (italic) toret += "<I>";

   if (mode == 0) {
      toret += text.substring(0,startPos);
   } else {
      toret += text.substring(startPos,text.length);
   }

   if (bold) toret += "</B>";
   if (italic) toret += "</I>";

   //if(mode == 0)
    //  toret=firsttag+toret;
   //alert("TORET:"+toret);
   
   return toret;
}


	var fileNameJpg = new Array;
   var fileNameGif = new Array;
   var fileShown = new Array;
   
function getGrid(which,x,y,pageNum,pageSection,xmlpath) {
   //alert("GETGRID");
   mainW.setArticleFrame(4);
   //alert("AFTER MAINW set art" + which + " X " + x + " Y " + y + " PAGE " + pageNum + "pageSection " + pageSection + " XML " + xmlpath);
   
   var toWrite = "";
   var dimY = 0;
   var dimX = 0;
   var divp;
   var gridDim = 256;
   var tmpVMod = 0;
   var tmpVBox = 0;
   var tmpHMod = 0;
   var tmpHBox = 0;
   var totHBoxes = 0;
   var totVBoxes = 0;
   var totBoxes = 0;
   var divLeft = 0;
   var divTop = 0;
   var divWid = 0;
   var divHei = 0;
   var valCrop = "";

   var xoff = 9999;
   var yoff = 9999;
   var xend = 0;
   var yend = 0;
   var custXoff = 8;
   var custYoff = -13;
   var Xoffset = 3 ;
   var Yoffset = 3 ;
   var xOffc = 1;
   var yOffc = 1;
   var wOffc = 2;
   var hOffc = 2;
   var border = 5;
   
//   alert("XMLPATH: "+xmlpath);

      if (xmlpath == "") {
         var imagif = path_normalize(window.location + "/..");
      } else {
         var imagif = path_normalize(xmlpath + "/..");
      }
      
      lpos = imagif.lastIndexOf("/");
      if (lpos>0) {
         imagif = imagif.substring(0,lpos) + "/fork/nav/"+imagif.substring(lpos+1,imagif.length);
      }
      // imagif += ".nav/";
      imagif += "/";

      var offset_sXY = "";
      
      if (window.ver && (ver > 1)) {
      } else {
         /* Define the page offsets */
         offset_sXY = new temp_sXY(0,0,0,0,0,0,0,0,0,0);
      }
   
      if (window.getPageOffset) {  //set customized page offset from corsera_crop.js (if exists)
         var offset = getPageOffset();
         custXoff = offset.xOff;
         custYoff = offset.yOff;
      }
      
      if (window.setOffParam) {    //set the customized crop offset from corsera_crop.js (if exists)
         var offset = setOffParam();
         xOffc = offset.x ;
         yOffc = offset.y ;
         wOffc = offset.w ;
         hOffc = offset.h ;
      }
      
      
      if (window.sXY || offset_sXY) { //set customized parameters (from page.htm) if exists
         var offset;

         if (window.sXY) offset = sXY();
         if (offset_sXY) offset = offset_sXY;
         
         custXoff = offset.px;     //set customized page offset (from page.htm)
         custYoff = offset.py;
         Xoffset = offset.ox ;     //set the Xoffset and Yoffset parameters (from page.htm)
         Xoffset = offset.oy ;
         xOffc = offset.cx ;       //set the customized crop offset (from page.htm)
         yOffc = offset.cy ;
         wOffc = offset.cw ;
         hOffc = offset.ch ;
      }

      var totXoff = custXoff + xOffc + Xoffset ;
      var totYoff = custYoff + yOffc + Yoffset ;
      var zoomX = 3.10854;
      var zoomY = 3.10854;

      if (window.sP) {
         
         var dimHrX = Math.floor(Pw * dpi / 72) ;
         var dimHrY = Math.floor(Ph * dpi / 72) ;
         zoomX =  dimHrX / Pwm ;
         zoomY =  dimHrY / Phm ;
         
         xoff = Math.floor((xoff - totXoff) * zoomX);
         yoff = Math.floor((yoff - totYoff) * zoomY);

         realXP = Math.floor((mPx / Pwm) * dimHrX);
         realYP = Math.floor((mPy / Phm) * dimHrY);
         
         if (!alreadyGrid) {                           
	         //alert("NOT ALREADY GRID");
         // ...Get HORIZ Num Boxes
         tmpHMod=0
         tmpHBox = parseInt(dimHrX / gridDim,10);
         tmpHMod = dimHrX % gridDim;
         totHBoxes = tmpHBox;
         if (tmpHMod > 0) { totHBoxes = totHBoxes + 1; }
      
         // ...Get VERT Num Boxes
         tmpVMod=0
         tmpVBox = parseInt(dimHrY / gridDim,10);
         tmpVMod = dimHrY % gridDim;
         totVBoxes = tmpVBox;
         if (tmpVMod > 0) { totVBoxes = totVBoxes + 1; }

         //alert("getGrid:" + dimHrY + " " + dimHrX + "\n" + totHBoxes + "\n" + totVBoxes + "\n" + imagif);         
         //alert("X:" + mPx + "\nY:" + mPy + "\nPwm:" + Pwm + "\nPhm" + Phm + "\nreal:" + realXP + "\n" + realYP);
			
         for (var cntY=0;cntY<totVBoxes;cntY++) {
            
            divHei = gridDim;
            divLeft = 0;
            if (cntY+1==totVBoxes) { divHei = tmpVMod; }
            fileNameJpg[cntY] = new Array();
            fileNameGif[cntY] = new Array();
            fileShown[cntY] = new Array();
            for (var cntX=0;cntX<totHBoxes;cntX++) {
               
               divWid = gridDim;   
               if (cntX+1==totHBoxes) { divWid = tmpHMod; }
               
               valCrop = "graph" + cntX + "_" +  cntY;

               /*
               var wid = Math.floor(divWid * zoomX);
 	            var hei = Math.floor(divHei * zoomY);

 	            var left = (Math.floor(divLeft * zoomX) ) + border + x;
	              var top  = (Math.floor(divTop * zoomY) ) + border + y;
	              */

               var wid = divWid;
	              var hei = divHei;

	              var left = divLeft + border + x;
	              var top  = divTop  + border + y;
               
               toWrite +="<DIV style='position:absolute ; overflow:hidden;";
               toWrite +=" left:"+left+"px; top:"+top+"px;";
               toWrite +=" width:"+wid+"px; height:"+hei+"px";
               //toWrite +="'> <IMG src='"+imagif+valCrop+".jpg' width='"+wid+"' height='"+hei+"'></DIV>\n";
	               toWrite +="'> <IMG  ondblclick=\"parent.page.returnToSingle(); return false;\" name='jpg_"+ cntX + "_" + cntY + "'  src='../pics/none.gif' width='"+wid+"' height='"+hei+"'></DIV>\n";
      			
      			    fileNameJpg[cntY][cntX] = imagif+valCrop;
               valCrop = "text" + cntX + "_" + cntY;
               
               toWrite +="<DIV style='position:absolute ; overflow:hidden;";
               toWrite +=" left:"+left+"px; top:"+top+"px;";
               toWrite +=" width:"+wid+"px; height:"+hei+"px";
               //toWrite +="'> <IMG src='"+imagif+valCrop+".gif' width='"+wid+"' height='"+hei+"'></DIV>\n";
	               toWrite +="'> <IMG ondblclick=\"parent.page.returnToSingle(); return false;\" name='gif_"+ cntX + "_" + cntY + "' src='../pics/none.gif' width='"+wid+"' height='"+hei+"'></DIV>\n";
               
               fileNameGif[cntY][cntX] = imagif+valCrop;
               fileShown[cntY][cntX] = false;
               
               divLeft += divWid;
            }  // ...cntX
            
            divTop += divHei;
         }  // ...cntY
         }
         
      }  // ...sP
   
  //alert("result:" + toWrite);
   /*
   for (var cntY=0;cntY<totVBoxes;cntY++) {
   	for (var cntX=0;cntX<totHBoxes;cntX++) {
   		toAlert += fileNameGif[cntY][cntX] + ".GIF ";
   		toAlert += fileNameJpg[cntY][cntX] + ".JPG ";
   		toAlert += fileShown[cntY][cntX] + "SHOWN ";
   	}
   	toAlert += " NEW ROW \n";
   }
   alert(toAlert);
   */
   return toWrite;
}   
function returnToSingle(){
	//alert("returnToSingleCalled");	
	//alert("DO SOMETHINGx");
	mainW.setArticleFrame(1);
	
}

function getGraphic(which,x,y,pageNum,pageSection,xmlpath)  {
   var toWrite = "";
   // customized offset parameters to be read.
   var custXoff = 8;
   var custYoff = -13;
   var Xoffset = 3 ;
   var Yoffset = 3 ;
   var xOffc = 1;
   var yOffc = 1;
   var wOffc = 2;
   var hOffc = 2;
   var toLoad = window.location;

   if (which>=0 && (which <= a.length || xmlpath != "")) {
      var xoff = 9999;
      var yoff = 9999;
      var xend = 0;
      var yend = 0;

      for (var el=0;el<rep.length;el++) {
         if (rep[el].a==which) {
            xoff = Math.min(xoff,rep[el].c);
            yoff = Math.min(yoff,rep[el].d);
            xend = Math.max(xend,rep[el].e);
            yend = Math.max(yend,rep[el].f);
         }
      }
      var border = 5;
      if (xmlpath == "") {
         var imagif = path_normalize(window.location + "/../page/");
      } else {
         var imagif = path_normalize(xmlpath + "/../page/");
      }
      
      //if (xmlpath == "") {
         var isArtIn;
         articleIn.length = 0;
         for (var i=0;i<a.length;i++) {
            isArtIn = true;
            for (var el=0;el<rep.length && isArtIn;el++) {
               if (rep[el].a==i) {
                  if (rep[el].c >= xoff && rep[el].e <= xend && rep[el].d >= yoff && rep[el].f <= yend) {  //
                  } else {
                     isArtIn = false;
                  }
               }
            }
            if (isArtIn) articleIn[articleIn.length] = i;
         }
     // }

      if (window.ver && (ver() > 1)) {
         if (window.getPageOffset) {  //set customized page offset from corsera_crop.js (if exists)
            var offset = getPageOffset();
            custXoff = offset.xOff;
            custYoff = offset.yOff;
         }
         if (window.setOffParam) {    //set the customized crop offset from corsera_crop.js (if exists)
            var offset = setOffParam();
            xOffc = offset.x ;
            yOffc = offset.y ;
            wOffc = offset.w ;
            hOffc = offset.h ;
         }
         if (window.sXY) {            //set customized parameters (from page.htm) if exists
            var offset = sXY();
            custXoff = offset.px;     //set customized page offset (from page.htm)
            custYoff = offset.py;
            Xoffset = offset.ox ;     //set the Xoffset and Yoffset parameters (from page.htm)
            Xoffset = offset.oy ;
            xOffc = offset.cx ;       //set the customized crop offset (from page.htm)
            yOffc = offset.cy ;
            wOffc = offset.cw ;
            hOffc = offset.ch ;
         }

         var totXoff = custXoff + xOffc + Xoffset ;
         var totYoff = custYoff + yOffc + Yoffset ;
         var zoomX = 3.10854;
         var zoomY = 3.10854;

         if (window.sP) {
            var dimHrX = Math.floor(Pw * dpi / 72) ;
            var dimHrY = Math.floor(Ph * dpi / 72) ;
            zoomX =  dimHrX / Pwm ;
            zoomY =  dimHrY / Phm ;
         }

         xoff = Math.floor((xoff - totXoff) * zoomX);
         yoff = Math.floor((yoff - totYoff) * zoomY);

	      for (var el=0;el<rep.length;el++) {
	         var isIn = false;
	         if (rep[el].a==which || (isInArticleList(rep[el].a) && !grpMode) ) {
	         //if (rep[el].a==which || isInArticleList(rep[el].a)  ) {
	            var valCrop = "pag_"+ rep[el].a +"_"+rep[el].b;

	            var wid = Math.floor((rep[el].e - rep[el].c + wOffc) * zoomX) ;
	            var hei = Math.floor((rep[el].f - rep[el].d + hOffc) * zoomY) ;
	            var left = (Math.floor((rep[el].c - totXoff) * zoomX) - xoff) + border + x ;
	            var top  = (Math.floor((rep[el].d - totYoff) * zoomY) - yoff) + border + y ;
	            if (isNs4) {
	               toWrite +="<LAYER ";
	               toWrite +=" left='"+left+"' top='"+top+"' ";
	               toWrite +=" width='"+wid+"' height='"+hei+"' visibility='show'";
	               toWrite +="'> <IMG src='"+imagif+valCrop+".jpg' width='"+wid+"' height='"+hei+"'></LAYER>\n";

	               toWrite +="<LAYER ";
	               toWrite +=" left='"+left+"' top='"+top+"' ";
	               toWrite +=" width='"+wid+"' height='"+hei+"' visibility='show'";
	               toWrite +="'> <IMG src='"+imagif+valCrop+".gif' width='"+wid+"' height='"+hei+"'></LAYER>\n";
	            } else {
	               toWrite +="<DIV style='position:absolute ; overflow:hidden;";
	               toWrite +=" left:"+left+"px; top:"+top+"px;";
	               toWrite +=" width:"+wid+"px; height:"+hei+"px";
	               toWrite +="'> <IMG src='"+imagif+valCrop+".jpg' width='"+wid+"' height='"+hei+"'></DIV>\n";

	               toWrite +="<DIV style='position:absolute ; overflow:hidden;";
	               toWrite +=" left:"+left+"px; top:"+top+"px;";
	               toWrite +=" width:"+wid+"px; height:"+hei+"px";
	               toWrite +="'> <IMG src='"+imagif+valCrop+".gif' width='"+wid+"' height='"+hei+"'></DIV>\n";
	            }
	         }
	      }
      }
   }
   return toWrite;
}


function getGraphicADV(which,x,y,pageNum,pageSection,xmlpath,opt_Search)  {
   
   var opt_fromSearch=0;
   
   if(typeof(opt_Search)!="undefined"){
      opt_fromSearch=opt_Search;
   }
   
   var toWrite = "";
   var ULinks = "";
   // customized offset parameters to be read.
   var custXoff = 8;
   var custYoff = -13;
   var Xoffset = 3 ;
   var Yoffset = 3 ;
   var xOffc = 1;
   var yOffc = 1;
   var wOffc = 2;
   var hOffc = 2;
   var toLoad = window.location;
   var artFrame;
   var aFW;
   var aFH;
   var isH;
   var isW;
   var zoomFactor;
   var foundZoom;
   var factW;
   var factH;
   
   // ...read frame dimension
   artFrame = parent.article;
   if (!artFrame) artFrame = parent.parent.article;
   if (artFrame) {
      aFW = util_getFrameW(artFrame);
      aFH = util_getFrameH(artFrame);
      
      // ...5 is the offset
      aFW = parseInt(aFW,10) - 5;
      aFH = parseInt(aFH,10) - 5;
   }   
   
   // ...read full image dimension
   zoomFactor = 1;
   foundZoom = 0;
   
   isW = getGraphicWEx(which,x,y,zoomFactor,xmlpath,1);
   isH = getGraphicHEx(which,x,y,zoomFactor,xmlpath);

   //alert("0:" + which + " " +  isH + " " + isW + " " + aFH + " " + aFW);   
   // ...calculate the right zoomFactor;
   while (!foundZoom) {
      // ...get factW and factH
      factW = (aFW - 1) / isW;   // NB Added -1 to avoid infinite loop
      factH = (aFH - 1) / isH;   // NB Added -1 to avoid infinite loop

      // ...width to big
      if (isW>aFW && isH<=aFH) { zoomFactor = factW; }      
      
      // ...height to big
      if (isW<=aFW && isH>aFH) { zoomFactor = factH; }            
      
      // ...both too big
      if (isW>aFW && isH>aFH) { 
         // ...take the smallest one
         zoomFactor = factH <= factW ? factH : factW;
      }            
      
      // ...both too small
      if (isW<aFW && isH<aFH) { 
         // ...take the smallest one
         //--old zoomFactor = factH <= factW ? factH : factW;
         zoomFactor = 1;
      }            
         
      isW = getGraphicWEx(which,x,y,zoomFactor,xmlpath,1);
      isH = getGraphicHEx(which,x,y,zoomFactor,xmlpath);
      if (isW<=aFW && isH<=aFH) { foundZoom = 1; }
   }   

   ULinks = "";
   //alert("sAgTextURLeMail("+which+","+pagenum+","+section+","+xmlpath+")");
   if (window.sAgTextURLeMail) {
      if(opt_fromSearch){ULinks = window.sAgTextURLeMail(0,pagenum,pageSection,xmlpath);}
      else{ULinks = window.sAgTextURLeMail(which,pagenum,pageSection,xmlpath);}
   }   

   if (window.sAgTextTRID) {
      if(opt_fromSearch){ULinks += window.sAgTextTRID(0,pagenum,pageSection,xmlpath);}
      else{ULinks += window.sAgTextTRID(which,pagenum,pageSection,xmlpath);}
   }   
   
   //if (window
   
   if (ULinks != "") toWrite += ULinks;
   
   //alert("1:" + toWrite + " " +  isW + " " + isH + " " + aFW + " " + aFH + "\n" + xmlpath);
   
   if (which>=0 && (which <= a.length || xmlpath != "")) {
      var xoff = 9999;
      var yoff = 9999;
      var xend = 0;
      var yend = 0;

      for (var el=0;el<rep.length;el++) {
         if (rep[el].a==which) {
            xoff = Math.min(xoff,rep[el].c);
            yoff = Math.min(yoff,rep[el].d);
            xend = Math.max(xend,rep[el].e);
            yend = Math.max(yend,rep[el].f);
         }
      }
      var border = 5;
      if (xmlpath == "") {
         var imagif = path_normalize(window.location + "/../page/");
      } else {
         var imagif = path_normalize(xmlpath + "/../page/");
      }
      
      if (xmlpath == "") {
         var isArtIn;
         articleIn.length = 0;
         for (var i=0;i<a.length;i++) {
            isArtIn = true;
            for (var el=0;el<rep.length && isArtIn;el++) {
               if (rep[el].a==i) {
                  if (rep[el].c >= xoff && rep[el].e <= xend && rep[el].d >= yoff && rep[el].f <= yend) {  //
                  } else {
                     isArtIn = false;
                  }
               }
            }
            if (isArtIn) articleIn[articleIn.length] = i;
         }
      }

      if (window.ver && (ver() > 1)) {
         if (window.getPageOffset) {  //set customized page offset from corsera_crop.js (if exists)
            var offset = getPageOffset();
            custXoff = offset.xOff;
            custYoff = offset.yOff;
         }
         if (window.setOffParam) {    //set the customized crop offset from corsera_crop.js (if exists)
            var offset = setOffParam();
            xOffc = offset.x ;
            yOffc = offset.y ;
            wOffc = offset.w ;
            hOffc = offset.h ;
         }
         if (window.sXY) {            //set customized parameters (from page.htm) if exists
            var offset = sXY();
            custXoff = offset.px;     //set customized page offset (from page.htm)
            custYoff = offset.py;
            Xoffset = offset.ox ;     //set the Xoffset and Yoffset parameters (from page.htm)
            Xoffset = offset.oy ;
            xOffc = offset.cx ;       //set the customized crop offset (from page.htm)
            yOffc = offset.cy ;
            wOffc = offset.cw ;
            hOffc = offset.ch ;
         }

         var totXoff = custXoff + xOffc + Xoffset ;
         var totYoff = custYoff + yOffc + Yoffset ;
         var zoomX = 3.10854;
         var zoomY = 3.10854;

         if (window.sP) {
            var dimHrX = Math.floor(Pw * dpi / 72) ;
            var dimHrY = Math.floor(Ph * dpi / 72) ;
            zoomX =  (dimHrX / Pwm);
            zoomY =  (dimHrY / Phm);
         }

         // ...apply the zoom factor
         zoomX = zoomX * zoomFactor;
         zoomY = zoomY * zoomFactor;
         
         xoff = Math.floor((xoff - totXoff) * zoomX);
         yoff = Math.floor((yoff - totYoff) * zoomY);

	      for (var el=0;el<rep.length;el++) {
	         var isIn = false;
	         if (rep[el].a==which || (isInArticleList(rep[el].a) && !grpMode) ) {
	         //if (rep[el].a==which || isInArticleList(rep[el].a)  ) {
	            var valCrop = "pag_"+ rep[el].a +"_"+rep[el].b;

	            var wid = Math.floor((rep[el].e - rep[el].c + wOffc) * zoomX) ;
	            var hei = Math.floor((rep[el].f - rep[el].d + hOffc) * zoomY) ;
	            var left = (Math.floor((rep[el].c - totXoff) * zoomX) - xoff) + border + x ;
	            var top  = (Math.floor((rep[el].d - totYoff) * zoomY) - yoff) + border + y ;
	            if (isNs4) {
	               top = top + divUrlH;
	               toWrite +="<LAYER ";
	               toWrite +=" left='"+left+"' top='"+top+"' ";
	               toWrite +=" width='"+wid+"' height='"+hei+"' visibility='show'";
	               toWrite +="'> <IMG src='"+imagif+valCrop+".jpg' width='"+wid+"' height='"+hei+"'></LAYER>\n";

	               toWrite +="<LAYER ";
	               toWrite +=" left='"+left+"' top='"+top+"' ";
	               toWrite +=" width='"+wid+"' height='"+hei+"' visibility='show'";
	               toWrite +="'> <IMG src='"+imagif+valCrop+".gif' width='"+wid+"' height='"+hei+"'></LAYER>\n";
	            } else {
	               top = top + divUrlH;
	               toWrite +="<DIV style='position:absolute ; overflow:hidden; cursor:move;";
	               toWrite +=" left:"+left+"px; top:"+top+"px;";
	               toWrite +=" width:"+wid+"px; height:"+hei+"px";
	               toWrite +="'> <IMG src='"+imagif+valCrop+".jpg' width='"+wid+"' height='"+hei+"'></DIV>\n";

	               toWrite +="<DIV style='position:absolute ; overflow:hidden; cursor:move;";
	               toWrite +=" left:"+left+"px; top:"+top+"px;";
	               toWrite +=" width:"+wid+"px; height:"+hei+"px";
	               toWrite +="' onClick=\"sa_showfulladv(" + which +"," + x + "," + y + ",'" + pageNum + "','" + pageSection + "','" + xmlpath  + "','" + curPage +"'); return false;\"><IMG alt='click to enlange' title='click to enlarge' src='"+imagif+valCrop+".gif' width='"+wid+"' height='"+hei+"'></DIV>\n";
	            }
	         }
	      }

      }
   }
   
   //alert("getGraphicsADV: " + toWrite);
   return toWrite;
}

function getGraphicADV2(which,x,y,pageNum,pageSection,xmlpath)  {
   var toWrite = "";
   // customized offset parameters to be read.
   var custXoff = 8;
   var custYoff = -13;
   var Xoffset = 3 ;
   var Yoffset = 3 ;
   var xOffc = 1;
   var yOffc = 1;
   var wOffc = 2;
   var hOffc = 2;
   var toLoad = window.location;
   
   ULinks = "";
   //alert("sAgTextURLeMail("+which+","+pagenum+","+section+","+xmlpath+")");
   if (window.sAgTextURLeMail) {
      ULinks = window.sAgTextURLeMail(which,pagenum,section,xmlpath);
   }   

   if (window.sAgTextTRID) {
      ULinks += window.sAgTextTRID(which,pagenum,section,xmlpath);
   }   
   
   //if (window
   
   if (ULinks != "") toWrite += ULinks;

   if (which>=0 && (which <= a.length || xmlpath != "")) {
      var xoff = 9999;
      var yoff = 9999;
      var xend = 0;
      var yend = 0;

      for (var el=0;el<rep.length;el++) {
         if (rep[el].a==which) {
            xoff = Math.min(xoff,rep[el].c);
            yoff = Math.min(yoff,rep[el].d);
            xend = Math.max(xend,rep[el].e);
            yend = Math.max(yend,rep[el].f);
         }
      }
      var border = 5;
      if (xmlpath == "") {
         var imagif = path_normalize(window.location + "/../page/");
      } else {
         var imagif = path_normalize(xmlpath + "/../page/");
      }
      
      if (xmlpath == "") {
         var isArtIn;
         articleIn.length = 0;
         for (var i=0;i<a.length;i++) {
            isArtIn = true;
            for (var el=0;el<rep.length && isArtIn;el++) {
               if (rep[el].a==i) {
                  if (rep[el].c >= xoff && rep[el].e <= xend && rep[el].d >= yoff && rep[el].f <= yend) {  //
                  } else {
                     isArtIn = false;
                  }
               }
            }
            if (isArtIn) articleIn[articleIn.length] = i;
         }
      }

      if (window.ver && (ver() > 1)) {
         if (window.getPageOffset) {  //set customized page offset from corsera_crop.js (if exists)
            var offset = getPageOffset();
            custXoff = offset.xOff;
            custYoff = offset.yOff;
         }
         if (window.setOffParam) {    //set the customized crop offset from corsera_crop.js (if exists)
            var offset = setOffParam();
            xOffc = offset.x ;
            yOffc = offset.y ;
            wOffc = offset.w ;
            hOffc = offset.h ;
         }
         if (window.sXY) {            //set customized parameters (from page.htm) if exists
            var offset = sXY();
            custXoff = offset.px;     //set customized page offset (from page.htm)
            custYoff = offset.py;
            Xoffset = offset.ox ;     //set the Xoffset and Yoffset parameters (from page.htm)
            Xoffset = offset.oy ;
            xOffc = offset.cx ;       //set the customized crop offset (from page.htm)
            yOffc = offset.cy ;
            wOffc = offset.cw ;
            hOffc = offset.ch ;
         }

         var totXoff = custXoff + xOffc + Xoffset ;
         var totYoff = custYoff + yOffc + Yoffset ;
         var zoomX = 3.10854;
         var zoomY = 3.10854;

         if (window.sP) {
            var dimHrX = Math.floor(Pw * dpi / 72) ;
            var dimHrY = Math.floor(Ph * dpi / 72) ;
            zoomX =  dimHrX / Pwm ;
            zoomY =  dimHrY / Phm ;
         }

         xoff = Math.floor((xoff - totXoff) * zoomX);
         yoff = Math.floor((yoff - totYoff) * zoomY);

	      for (var el=0;el<rep.length;el++) {
	         var isIn = false;
	         if (rep[el].a==which || (isInArticleList(rep[el].a) && !grpMode) ) {
	         //if (rep[el].a==which || isInArticleList(rep[el].a)  ) {
	            var valCrop = "pag_"+ rep[el].a +"_"+rep[el].b;

	            var wid = Math.floor((rep[el].e - rep[el].c + wOffc) * zoomX) ;
	            var hei = Math.floor((rep[el].f - rep[el].d + hOffc) * zoomY) ;
	            var left = (Math.floor((rep[el].c - totXoff) * zoomX) - xoff) + border + x ;
	            var top  = (Math.floor((rep[el].d - totYoff) * zoomY) - yoff) + border + y ;

	            if (isNs4) {
	               top = top + divUrlH;
	               toWrite +="<LAYER ";
	               toWrite +=" left='"+left+"' top='"+top+"' ";
	               toWrite +=" width='"+wid+"' height='"+hei+"' visibility='show'";
	               toWrite +="'> <IMG src='"+imagif+valCrop+".jpg' width='"+wid+"' height='"+hei+"'></LAYER>\n";

	               toWrite +="<LAYER ";
	               toWrite +=" left='"+left+"' top='"+top+"' ";
	               toWrite +=" width='"+wid+"' height='"+hei+"' visibility='show'";
	               toWrite +="'> <IMG src='"+imagif+valCrop+".gif' width='"+wid+"' height='"+hei+"'></LAYER>\n";
	            } else {
	               top = top + divUrlH;
	               toWrite +="<DIV style='position:absolute ; overflow:hidden;";
	               toWrite +=" left:"+left+"px; top:"+top+"px;";
	               toWrite +=" width:"+wid+"px; height:"+hei+"px";
	               toWrite +="'> <IMG src='"+imagif+valCrop+".jpg' width='"+wid+"' height='"+hei+"'></DIV>\n";

	               toWrite +="<DIV style='position:absolute ; overflow:hidden;";
	               toWrite +=" left:"+left+"px; top:"+top+"px;";
	               toWrite +=" width:"+wid+"px; height:"+hei+"px";
	               toWrite +="'> <IMG src='"+imagif+valCrop+".gif' width='"+wid+"' height='"+hei+"'></DIV>\n";
	            }
	         }
	      }
      }
   }
   return toWrite;
}


function rule_Title(font,size,len,il) {
   var toret = false;
   if (window.rule_TitleCustom) {
      toret = window.rule_TitleCustom(font,size,len,il);
   } else {   
      if (size >= 16 && len >= 3) toret = true;
   }   
   return toret;
}

var crCount = 0;

function removeExtraChar(textV,isTitle) {
   var symbCr = String.fromCharCode(0X1e);
   var symbHyp = "-" + String.fromCharCode(0X1e);
   var symbSp =  String.fromCharCode(0X1d);
   var symbShy =  String.fromCharCode(0Xad); // 173
   var symbHy =  String.fromCharCode(0X2d); //hyphen
   var symbAb =  String.fromCharCode(0X1c);
   var toAdd;

	
	var pos = 0;
   while( (pos = textV.indexOf(symbHy, pos+1)) >= 0 ){
      //if you find a hypen followed by a carriage return or 2 places over
      if((textV.charCodeAt(pos+1)) == 0X1e || (textV.charCodeAt(pos+2)) == 0X1e){
         //replace ONLY this hyphen with softhypen
         temp1 = textV.substring(0, pos);
         temp2 = textV.substring(pos);
         //replace only replaces first occurance?
         temp2 = temp2.replace(symbHy, "­");  //softhypen
         textV = temp1 + temp2;
      }
   }
   
   crCount=0;
   pos = 0;
   while ( (pos = textV.indexOf(symbCr,pos+1)) >= 0) {
		crCount++;
   }
   
   /* hyphen newline is a shy acrobat 6*/
   while ( (pos = textV.indexOf(symbHyp)) >= 0) {
		textV = textV.replace(symbHyp,symbShy)
   }
   while ( (pos = textV.indexOf(symbCr)) >= 0) {
		textV = textV.replace(symbCr,"")
   }

   pos = textV.indexOf(symbSp);
   while ( pos >= 0 ) {
      deltaPos = 0;
      toAdd = " ";
      if (pos == 0) toAdd = "";
      if (textV.indexOf("²",pos) == pos+2) {
         toAdd = "&shy;";
         deltaPos = 1;
         if (textV.indexOf(" ",pos) == pos+3) deltaPos = 2;
      }
      textV = textV.substring(0,pos) + toAdd + textV.substring(pos+2+deltaPos,textV.length);
      pos = textV.indexOf(symbSp);
   }

   pos = textV.indexOf("²");
   while ( pos > 0 ) {
      befPos = 0;
      aftPos = 0;
      if (textV.charAt(pos-1) == " ") befPos = 1;
      if ( (pos+1) < textV.length && textV.charAt(pos+1) == " ") aftPos = 1;
      textV = textV.substring(0,pos-befPos) + textV.substring(pos+1+aftPos,textV.length);
      pos = textV.indexOf("²");
   }

   return textV;
}

function AdjustTable(textV,size) {
   var symbCr = String.fromCharCode(0X1e);
   var symbSp =  String.fromCharCode(0X1d);
   var symbShy =  String.fromCharCode(0Xad); // 173
   var symbAb =  String.fromCharCode(0X1c);

   var pos=-1;
   // introduce cr for
   while ((pos=textV.indexOf(symbSp))>=0) {
      var len = textV.length;
      if (pos>=0 && pos+1<=len) {
         var numSpace = textV.charCodeAt(pos+1);
         numSpace = numSpace - 48;
         if (numSpace >= 10) numSpace = numSpace - 17 + 10;
         if (pos>0) {
            textV = textV.substring(0,pos)+makeSpaces(numSpace,size)+textV.substring(pos+2,len+1);
         }else{
            textV = makeSpaces(numSpace)+textV.substring(pos+2,len+1);
         }
      } else {
         textV = textV.replace(symbSp,"&nbsp;");
      }
   }

   while ((pos=textV.indexOf(symbCr))>=0) {
      textV = textV.replace(symbCr,"<BR _pppp>");
   }

   while ((pos=textV.indexOf(symbAb))>=0) {
      var len = textV.length;
      if (pos>=0 && pos+3<=len) {
         var numSpace = (textV.charCodeAt(pos+1)-48)*74 + textV.charCodeAt(pos+2);
         if (pos>0) {
            textV = textV.substring(0,pos)+makeSpaces(numSpace,size)+textV.substring(pos+3,len+1);
         }else{
            textV = makeSpaces(numSpace)+textV.substring(pos+2,len+1);
         }
      } else {
         textV = textV.replace(symbAb,"&nbsp;");
      }
   }

   while (textV.indexOf(symbShy)>=0) {
      textV = textV.replace(symbShy,"&shy;");
   }
   return textV;
}

function isAlpha(c) {
	var toret = false;
	if ( (c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || ( c == '/' )  || ( c == ' ' )) toret = true;
	return toret;
}

function isAlphaL(c) {
	var toret = false;
	if ( (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || ( c == '/' ) ) toret = true;
	return toret;
}

function isAlphaUpper(c) {
	var toret = false;
	if (c >= "A" && c <= "Z") toret = true;
	return toret;
}

function followUpper(pos,str) {
	var i = pos+1;
	var toret = false;
	while (!toret && i < str.length && !isAlpha(str.charAt(i)) ) {
		i++;
	}
	if ( isAlphaUpper(str.charAt(i)) ) toret = true;
	return toret;
}

function replaceAll(string,toSearch,toReplace) {
	var toret = string;
	var pos = 0;
	var posS;
	while ((posS = toret.indexOf(toSearch,pos))>=0) {
		toret = toret.replace(toSearch,toReplace);
		pos = posS + toReplace.length;
	}
	return toret;
}

function insertLine(text) {
   var lastPos, toret;
   var posS, pos;
   var substLen;
   pos = 0;
   toret = "";
   lastPos = 0;
	while ((posS = text.indexOf("\n",pos)) >= 0) {
	   if (posS < 5 || (posS - lastPos) > 220) {
		   text = text.replace("\n","<BR>&nbsp;&nbsp;");
		   substLen = 8;
      } else {
		   text = text.replace("\n","<BR>&nbsp;&nbsp;");
		   substLen = 0;
      }
		lastPos = posS;
		pos = posS + substLen;
	}
   return text;
}

function substMail(textV) {
   var startMail, endMail, atPos;
	var isEnd = false;
   var isNLst = -1;
   var isNLend = -1;
   var tmpText = "";
   
   var symbShy =  String.fromCharCode(0Xad); // 173
   
   tmpText = util_clearBlanks(textV);
   if (tmpText.indexOf("\n") == 0) {
      isNLst = 1;
   }

   if (tmpText.lastIndexOf("\n") == tmpText.length-1) {
      isNLend = 1;
   }
      
   // remove all \n
   textV = replaceAll(textV,"\n","");      
   
   if ( ( atPos = textV.toLowerCase().indexOf("@")) >= 0 && atPos < textV.length-1) {
   	if (atPos>=1 && textV.charAt(atPos-1) == "$") { // special symbols $@symb.jpg$
  			var posend=textV.indexOf("$",atPos);
 			textV = textV.substring(0,atPos-1) + "<IMG src=\""+laydir+"/images/symbols/"+ textV.substring(atPos+1,posend) +"\">";
 			//hard coded for demonstration
 			//textV = textV.substring(0,atPos-1) + "<IMG src=\"/eeLayout/omahaworldherald/symbols/"+ textV.substring(atPos+1,posend) +"\">";
  		} else {
  		if (textV.charAt(atPos-1) == " ") textV = textV.substring(0,atPos-1) + textV.substring(atPos,textV.length);

   	endMail = textV.indexOf(" ",atPos);
		while (endMail >= 0 && !isEnd) {
			if ( (textV.charAt(endMail-1) == "." || textV.charAt(endMail-1) == "-" ||
			      textV.charAt(endMail-1) == "_" || textV.charAt(endMail-1) == "@" ) 
			      && textV.substr(endMail-5,4)!=".com" ) {  //last condition to fix email addresses that end with a period like jkurtz@tecnavia.com. Something
				textV = textV.substring(0,endMail) + textV.substring(endMail+1,textV.length);
      		endMail = textV.indexOf(" ",endMail);
			} else {
				isEnd = true;
			}
		}

		//check last char of extracted mail address
		if (endMail < 0) {
			endMail = textV.length;
	   }
	     
	   // START ALE MODIFICATION 09/26/2006
	   var isTag=0;
	   var counter=0;
	   var origendMail=endMail;
		while ( !isAlpha(textV.charAt(endMail-1)) || (isTag==1 && counter<10)) { //elimino i tag
		
			if(textV.charAt(endMail-1) == ">" || textV.charAt(endMail-1) == ";")
	         isTag=1;
	      if(textV.charAt(endMail-1) == "<" || textV.charAt(endMail-1) == "&")
	         isTag=0;

		   endMail--;
		   counter++; 
		}
		
		if(isTag==1)
		   endMail=origendMail-1;
           // END ALE MODIFICATION

		startMail = atPos;
  		while( atPos >= 0 && textV.charAt(atPos) != " " && textV.charAt(atPos) != ">") {
  			startMail = atPos;
  			atPos--;
  		}

  		var toW = "";
		if (endMail >= 0) {
			toW = textV.substring(startMail,endMail);
			emailFound = "<A class=\"email\" HREF=\"mailto:" + toW + "\" target=\"_blanks\">" + toW + "</A>";
			if (toW.indexOf("Ticin@") < 0 && toW.charAt(0) != "@") {
				textV = textV.substring(0,startMail) + "<A class=\"email\" HREF=\"mailto:" + replaceAll(toW,symbShy,"") + "\" target=\"_blanks\">" + toW + "</A>" + textV.substring(endMail,textV.length);
			}
		} else {
	    toW = textV.substring(startMail,textV.length);
		  emailFound = "<A class=\"email\" HREF=\"mailto:" + toW + "\" target=\"_blanks\">" + toW + "</A>";
			if (toW.indexOf("Ticin@") < 0 && toW.charAt(0) != "@") {
  				textV = textV.substring(0,startMail) + "<A class=\"email\" HREF=\"mailto:" + replaceAll(toW,symbShy,"") + "\" target=\"_blanks\">" + toW + "</A>";
}
  			}
		}
  	}

  	if (isNLst == 1 ) { textV = "\n" + textV; }
  	if (isNLend == 1 ) { textV = textV + "\n"; }
  	
	return textV;
}

//Creating URL links from a block of text without Prefix of www. or http
function linkwoPrefix(textToShow) {
   var text = textToShow;
   var newText = new Array();
   var linkFound = '';
   var startLink = 0;
   var endLink = 0;
   
   // Max 40 loop for article
   for (var i = 0; i < 40; i++) {
      linkFound = '';
      startLink = 0;
      endLink = 0;
      
      startLink = text.search(/\.(com|edu|org|net|tv|ch|it|biz|gov|mil|nl|de|at|info|ca|fr|uk|ac|au|ky|be|bm|bz|cn|coop|es|eg|hk|in|int|jobs|jp|museum|mx|name|nato|nom|pro|ru|sg|store|tr|tw|travel|web|dk)/i);
      
      // No more links
      if (startLink == -1) {
         newText.push(text);
         break;
      }
      
      // Find start Link
      for (var j = startLink; j >= 0; j--) {
         if (text.charAt(j).search(/[a-z0-9\.\-_\/:@]/i) == -1) {
            startLink = j + 1;
            break;
         }
         
         startLink = 0;
      }
      
      newText.push(text.substring(0, startLink));
      text = text.substring(startLink);
      
      // Find end link
      endLink = text.search(/\.?(\ |,|'|\.$|\)|<|&)/i);
      
      if (endLink == -1) {
         endLink = text.length;
      }
      
      linkFound = text.substring(0, endLink);
      
      if (linkFound.search('@') == -1) {
         linkFound = linkFound.replace(/\n/g, "");
         if (linkFound.search('http://') != -1) {
            linkFound = '<a target="_blank" href="' + linkFound + '">' + linkFound + '</a>';
         } else {
            linkFound = '<a target="_blank" href="http://' + linkFound + '">' + linkFound + '</a>';
         }
      
         newText.push(linkFound);
      } else {
         newText.push(text.substring(0, endLink));
      }
      
      text = text.substring(endLink);
   }
   
   // Build text
   text = '';
   for (var i = 0; i < newText.length; i++) {
      text += newText[i];
   }
   
   return text;
}

function substLink(textV,tofind,prefix) {    //check www link and email link
   var startWWW, endWWW;
   var isEnd = false;
   endWWW = 0;
   
   var symbShy =  String.fromCharCode(0Xad); // 173
   //alert("TEXTV: "+textV);
   
   while ( endWWW >= 0 && ( startWWW = textV.toLowerCase().indexOf(tofind,endWWW)) >= 0) {
   	endWWW = textV.indexOf(" ",startWWW);
		while (endWWW >= 0 && !isEnd) {
			if ((textV.charAt(endWWW-1) == "." && textV.charAt(endWWW-2) != ")")  || textV.charAt(endWWW-1) == "/"
				|| textV.charAt(endWWW-1) == "-" || textV.charAt(endWWW-1) == "_" || textV.charAt(endWWW-1) == "~" ) {
				//toglie gli spazi in mezzo alla url
				textV = textV.substring(0,endWWW) + textV.substring(endWWW+1,textV.length);
      		endWWW = textV.indexOf(" ",endWWW);
			} else {
				isEnd = true;
			}
		}
		
      
		//check last char of extracted URL
		if (endWWW < 0) {
			endWWW = textV.length;
	   }
	   

	   var isTag=0;
	   // START ALE/JILL MODIFICATION
	   var counter=0;
	   var origendWWW=endWWW;
	   while ( !isAlpha(textV.charAt(endWWW-1)) || (isTag==1 && counter<10)) { //elimino i tag
	      //alert("CHAR: "+textV.charAt(endWWW-1)+" ISTAG: "+isTag);
	      if(textV.charAt(endWWW-1) == ">" || textV.charAt(endWWW-1) == ";")
	         isTag=1;
	      if(textV.charAt(endWWW-1) == "<" || textV.charAt(endWWW-1) == "&")
	         isTag=0;

		   endWWW--;
		   counter ++;
		}
		if(isTag==1)
		   endWWW=origendWWW-1;
           // END ALE MODIFICATION

		/*} else {
			while ( !isAlpha(textV.charAt(endWWW-1)) ) {
				endWWW--;
			}
		}*/
		
      /* check if prefix is already present so do not change anything */
      if ( prefix != "" ) {
         if (textV.substr(startWWW - prefix.length, prefix.length) == prefix ) return textV;
      }

		if (endWWW >= 0) {
		  linkFound = "<A class=\"email\" HREF=\"" + prefix + "" + textV.substring(startWWW,endWWW) + "\" target=\"_blanks\">" + textV.substring(startWWW,endWWW) + "</A>"; 
			textV = textV.substring(0,startWWW) + "<A class=\"email\" HREF=\"" + prefix + "" + replaceAll(textV.substring(startWWW,endWWW),symbShy,"") + "\" target=\"_blanks\">" + textV.substring(startWWW,endWWW) + "</A>" + textV.substring(endWWW,textV.length);
			var added = "<A class=\"email\" HREF=\"http://" + textV.substring(startWWW,endWWW) + "\" target=\"_blanks\">";
			endWWW = endWWW + added.length;
			isEnd = false;
		} else {
		  linkFound = "<A class=\"email\" HREF=\"" + prefix + "" + textV.substring(startWWW,textV.length) + "\" target=\"_blanks\">" + textV.substring(startWWW,textV.length) + "</A>";
			textV = textV.substring(0,startWWW) + "<A class=\"email\" HREF=\"" + prefix + "" + replaceAll(textV.substring(startWWW,textV.length),symbShy,"") + "\" target=\"_blanks\">" + textV.substring(startWWW,textV.length) + "</A>";
			endWWW = -1;
		}
  	}
  	
  	return textV;
}


//function added to make text/graphic button work
function switchMode(mode,which) {
   if (f.length) {
      curMode=mode;
      sameClickedArticle = false;
      // DEVI SCEGLIERE secondo la variabile ActivePopUp cosa deve fare
      var toexe = "";
      if (setpopUp == 1) toexe = "openPopUp("+which+")";
      else toexe="printfEx(sAg("+which+"),css)";
      
      setTimeout(toexe,10);
   }
   return false;
}

function switchMode2(mode,which) {
   if (f.length) {
      switch(mode) {
         case 1: curMode = 1;break; // text inverted value (real value is 0)
         case 2: curMode = 0;break; // grafic inverted value (real value is 1)
         case 3: curMode = 2;break; //grid
         default:   curMode=mode;
      }
      sameClickedArticle = true;
      var toexe = "printfEx(sAg("+which+"),css)";
      setTimeout(toexe,10);
   }
   return false;
}





/*=================================LEGENDA FUNCTION ===================================*/

function removeExtraCharLegenda(textV,isTitle) {
   var symbCr = String.fromCharCode(0X1e);
   var symbSp =  String.fromCharCode(0X1d);
   var symbShy =  String.fromCharCode(0Xad); // 173
   var symbHy =  String.fromCharCode(0X2d); //hyphen
   var symbAb =  String.fromCharCode(0X1c);
   var toAdd;

	
	var pos = 0;
   while( (pos = textV.indexOf(symbHy, pos+1)) >= 0 ){
      //if you find a hypen followed by a carriage return or 2 places over
      if((textV.charCodeAt(pos+1)) == 0X1e || (textV.charCodeAt(pos+2)) == 0X1e){
         //replace ONLY this hyphen with softhypen
         temp1 = textV.substring(0, pos);
         temp2 = textV.substring(pos);
         //replace only replaces first occurance?
         temp2 = temp2.replace(symbHy, "­");  //softhypen
         textV = temp1 + temp2;
      }
   }
   
   crCount=0;
   pos = 0;
   while ( (pos = textV.indexOf(symbCr,pos+1)) >= 0) {
		crCount++;
   }
   while ( (pos = textV.indexOf(symbCr)) >= 0) {
		textV = textV.replace(symbCr,"\n")
   }

   pos = textV.indexOf(symbSp);
   while ( pos >= 0 ) {
      deltaPos = 0;
      toAdd = " ";
      if (pos == 0) toAdd = "";
      if (textV.indexOf("²",pos) == pos+2) {
         toAdd = "&shy;";
         deltaPos = 1;
         if (textV.indexOf(" ",pos) == pos+3) deltaPos = 2;
      }
      textV = textV.substring(0,pos) + toAdd + textV.substring(pos+2+deltaPos,textV.length);
      pos = textV.indexOf(symbSp);
   }

   pos = textV.indexOf("²");
   while ( pos > 0 ) {
      befPos = 0;
      aftPos = 0;
      if (textV.charAt(pos-1) == " ") befPos = 1;
      if ( (pos+1) < textV.length && textV.charAt(pos+1) == " ") aftPos = 1;
      textV = textV.substring(0,pos-befPos) + textV.substring(pos+1+aftPos,textV.length);
      pos = textV.indexOf("²");
   }

   return textV;
}

function findLegenda(toWrite,family,size) {
   
   var toRet = "";
   var i;
//   if ( family == "Utopia-Bold" && size == 9 ) {
      toRet = buildLegenda(toWrite);
//   } else {
//      toRet = toWrite;
//   }     
   return toRet;
}   


function buildLegenda(toWrite) {
   
   var strlen;
   var str;
   var i;
   var digit;
   var numSegue = -1;
   var val = "";
   var newWrite = "" ;
   var firstT = true;
   var dots = "";
   var aCapo = false;
   var firstV = false;
   var prova =false;
   
   var symbCr = String.fromCharCode(0X1e);
   var crCount;
   var pos;
   
   toWrite = removeExtraCharLegenda(toWrite,null);   
      
   // NBS 20070108
   // indexOf returns -1 in case it is not found, 0 is a possible "found" value
   // So changed "found > 0" to "found >= 0"
   var found = -2;
   found = toWrite.toLowerCase().indexOf("&#8217;");
   if(found >= 0){
      toWrite = toWrite.replace("&#8217;", "'");
   }
   found = toWrite.toLowerCase().indexOf("&#8220;");
   if(found >= 0){
      toWrite = toWrite.replace("&#8220;", "");
   }
   found = toWrite.toLowerCase().indexOf("&#8222;");
   if(found >= 0){
      toWrite = toWrite.replace("&#8222;", "");
   }
   found = toWrite.toLowerCase().indexOf("&#8211;");
   if(found >= 0){
      toWrite = toWrite.replace("&#8211;", "-");
   }
   // NBE
   
   str = toWrite;
   found = 0;
   if (str.indexOf("Image_") >= 0 ) found = -1;
      
   //strlen = toWrite.length;
   strlen = str.length;
   
   if (found>=0) {
      for (i=0;i<strlen;i++) {
        
         //alert(str.charAt(i)); 
         
         digit = str.charCodeAt(i);
         if (digit >= 48 && digit <= 57) {
            val += str.charAt(i);
           
         } else {
           
            //if (val != "" && val !="0" && i<strlen-4) {
            if (val != "" && val !="0" && val !="60" && val !="80" && str.charAt(i+1) != "p" && parseInt(val,10)<150) {   
               numSegue = parseInt(val,10);
               if (numSegue) {
                     
                     newWrite += dots;
                     //newWrite += "<BR><BR _legenda1><A style=\"text-decoration:none; color=blue;\" href='javascript:parent.contents.gotoPage(\"A\",";
                     newWrite += "<A style=\"text-decoration:none; color=blue;\" href='javascript:parent.contents.gotoPage(\"A\",";
                     newWrite += numSegue + ");' align='right'><font face=\"Verdana\" ><B>"+ numSegue +"</B></font></A>";
                     
                     newWrite += str.charAt(i);
               } else {
                  if ( val != "" ) newWrite += val;
                  //newWrite += str.charAt(i);
                  val = "";
               }     
               
            } else {
               if ( val != "" ) newWrite += val;
               newWrite += str.charAt(i);
               val="";
            }       
            val = "";
         }   
      }  
       
      //alert( newWrite);
      // if last is page number 
      //if (val != "" && val !="0" && i<strlen-4) {
      //if (val != "" && val !="0" && str.charAt(i) != " " ) {   
      if (val != "" && val !="0" && parseInt(val,10)<150) {      
         numSegue = parseInt(val,10);
         if (numSegue) {
            newWrite += dots;
            //newWrite += "<BR><BR _legenda2><A style=\"text-decoration:none; color=blue;\" href='javascript:parent.contents.gotoPage(\"A\",";
            newWrite += "<A style=\"text-decoration:none; color=blue;\" href='javascript:parent.contents.gotoPage(\"A\",";
            newWrite += numSegue + ");' align='right'><font face=\"Verdana\"><B> "+ numSegue +"</B></font></A><BR _legenda2>";
         }   
      } else {
         if ( val != "" ) newWrite += val;
      }     
   } else {
      newWrite = toWrite;
   }      
   return newWrite;
}
   

/*=================================END LEGENDA FUNCTION ===================================*/


/*===============ADDED FOR PROPER DISPLAY OF ARTICLES 2 COLUMNS and GRAPHIC MODE===============================*/

function sAEx(which,pageNum,pageSection) {
   var invert=false;
   var isImage = false;
   var mode = 1; // ...text

   forceImgSingleColumn = false;
   
   if (pageNum.length > 1 && pageNum.charAt(0) == '0' && pageNum.charAt(1) != "") pageNum = pageNum.substring(1,3);
   if (pageNum.length > 1 && pageNum.charAt(0) == '0' && pageNum.charAt(1) != "") pageNum = pageNum.substring(1,2);

   // if there is no text in the file
   var howmuchtext=0;
   var howmanyimages=0;
   if (which >=0 && which < a.length) {
      for (var il=0;il<a[which].e.length;il++) {
         var link = a[which].e[il].link;
         if (link >= 0) {
            var par = p[link];
            for (var is=0;par && is< par.S.length;is++) {
               var isBr = 0;
               if ( par.S[is].textV.indexOf("Image ") >= 0 || par.S[is].textV.indexOf("Image_") >= 0) {
                  howmanyimages++;
               } else {
                  if (par.S[is].textV != "") howmuchtext++;
               }
            }
         }
      }
   }

   // alert(a[which].den + " " + a[which].stdd + " " + howmuchtext);
   /*  
   if (a[which] && a[which].den!="undefined") {
      if ( ( a[which].den <= 4.5 && a[which].stdd <= 4.5 ) || (a[which].den <= 22 && howmuchtext > 40 ) ) invert = true;
   }
   */

   //graphic mode
   invert = true;
   if (which != -2) {
      if ((a[which].cat & 0x7F) == 0) invert = false;  //article
      if ((a[which].cat & 0x7F) == 3) invert = false;  //legenda
      if ((a[which].cat & 0x7F) == 4) invert = false;  //advertisements to SHOW THE URL FIRST
   }   
   
   if (!howmuchtext) invert= true;
   
   if (howmanyimages>=15) invert= true;
   
   if (howmanyimages>=2) forceImgSingleColumn = true;
   
   if (isImage) invert= true;
   
   
   var buttonFrame = mainB;
   if (parent && parent.parent && parent.parent.button) buttonFrame = parent.parent.button;
   if (buttonFrame.getMode) {
      mode = buttonFrame.getMode();
      if (mode == 1) invert = false;
      if (mode == 2) invert = true;
      if (mode == 3) invert = true;
   }
   
   if (mode ==3 ) {
      curMode = 2;
   } else {   
      if (invert) curMode = (curMode + 1 ) % 2;
   }   
   //if (invert) curMode = (curMode + 1 ) % 2;
   //Grid
   //if (invert) curMode = (curMode + 1 ) % 3;
}


function makeSpaces(numSpec,fontsize) {
   var toretStr = "";
   if (fontsize <=0) fontsize = 1;
   var space = numSpec;
   for (var i=0;i<space;i++) {
      toretStr += "&nbsp;";
   }
   if (space<=0) {
      toretStr += "<font color='red'>#</font>";
   }
   return toretStr;
}



/=================PAGE JUMP THINGS==============/
//ONLY FOR "TO" jumps
var filetopass = "";
var linkinfo = "";
function addPageJumpInfo(which){
	toret = ""; 
	linkinfo = "";
	pageJumps = "";
	
  if (a[which] && a[which].js && a[which].js.length> 0) {
	  if (a[which].jf.length> 0) {
	     var jlabelFrom= parent.contents.pjumpFrom.replace("$$S$",a[which].js);
	     jlabelFrom= jlabelFrom.replace("$$P$",a[which].jf);
        pageJumps+="<A href='javascript:parent.contents.setPJumpName(\""+a[which].js+"\");javascript:parent.contents.gotoPage(\"A\",\""+a[which].jf+"\");'>"+jlabelFrom + "</A><br>";
     }
  	  
	  if (a[which] && a[which].jt && a[which].jt.length> 0) {
	  	//alert("JUMPTO");
	     var jlabelTo= parent.contents.pjumpTo.replace("$$S$",a[which].js);
	     jlabelTo= jlabelTo.replace("$$P$",a[which].jt);
        pageJumps+="<A href='javascript:parent.contents.setPJumpName(\""+a[which].js+"\");javascript:parent.contents.gotoPage(\"A\",\""+a[which].jt+"\");'>"+jlabelTo + "</A><br>";
  	  }
  }
	
	if (a[which] && a[which].jt && a[which].jt.length> 0) {	
		toret += "<hr>\n";
		toret += pageJumps;
		
	}
	
	//alert("pageJumpsType" +mainW.pageJumpsType);
	if(((a[which] && a[which].jt && a[which].jt.length> 0) || (a[which] && a[which].jf && a[which].jf.length> 0)) && mainW.pageJumpsType == 2){

		//do some other stuff.
		toret += "<div name='continuation' id='continuation'>\n";
		toret += "Page Jump Loading";
		toret += "\n</div>\n";
		
		
		//set filetopass
		var pjumpsnum="";
		if (which == "-1") which = curArt;
		
		if (which != -2) {
		   sh(2,which);
		   selArticle = which;
		}   
		
		if(a[which].jt){
		      pjumpsnum=a[which].jt;
		      linkinfo += "TO_"+a[which].jt+"_";
		      linkinfo += a[which].js;     
		}
		else{
		      pjumpsnum=a[which].jf;
		      //linkinfo += "FROM_"+ a[which].jf+"_";
		      //linkinfo += a[which].js;     
		}
		      
		
		
		var labeljump=a[which].js;
		//alert(pjumpsnum);
		
		var dFrame = parent.data;
		//alert(dFrame);
		var pg;
		var pgname;
		var newarg="";
		
		for(i=0;i<dFrame.p.length;i++){         
		  pg=dFrame.p[i];
		  if(pg.page == pjumpsnum){
		      pgname=pg.name;
		      break;
		  }                  
		}
		  
		fpArray = fp_location.split("/");
		for(i=0;i<fpArray.length-2;i++)
		   filetopass+=fpArray[i]+"/";
		
		filetopass+=pgname.toLowerCase()+"/";
	}
	return toret;
}

function httpChange( ) {
	toWrite = "";
   if( http.readyState == 4 ) {
      if( http.status == 200 ) {
         
         //ll.innerHTML =  http.responseText ;
         if (artFrame.document.getElementById || artFrame.document.all) {
    		  //for debugging
    		  //toWrite = "<textarea>"+http.responseText+"</textarea>";
    		  var el = artFrame.document? artFrame.document.getElementById('continuation'): artFrame.document.all['continuation'];
      	  if (el && typeof el.innerHTML != "undefined") el.innerHTML = toWrite + http.responseText;//http.responseText;
   		}
      } else {
         alert("Problem retrieving data");
      }
   }
}
   
   
function loadXMLHTTPRequest() {

//GET READY TO CALL VIA HTTP
	http = false;   
   if(window.XMLHttpRequest) {
      try {
		   http = new XMLHttpRequest();
      } catch(e) {
			http = false;
      }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
      try {
         http = new ActiveXObject("Msxml2.XMLHTTP");
      } catch(e) {
         try {
            http = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
            http = false;
        	}
		}
    }
    
    if( http ) {
      http.onreadystatechange = httpChange;
 //alert(filetopass);
      URL = "../php-script/xmlArt_continuation.php?pSetup="+mainW.pSetup+"&file="+filetopass;
      URL += "&paper="+mainW.paper+"&filetype=nitf&TAUID="+mainW.cookie_get('TAUID');
      URL += "&date="+""+"&lnkInfo="+linkinfo;
   //   alert(URL);
      http.open("POST", URL, true);
 
                 //file=0@/nn/20070508/p050508.pdf.0/
      http.send(null);
    }
    filetopass = "";
}
