
//////////////////////////////////////////////////////////////
//            Trappable events declaration
//////////////////////////////////////////////////////////////

//document.onstop        			= LVMP_document_OnStop;
//document.onmouseup	   		= LVMP_document_OnMouseUp;
//document.onclick	   			= LVMP_document_OnMouseUp;
//document.ondblclick	   		 	= LVMP_document_OnDblClick;
//document.onkeydown      		= LVMP_document_OnKeyDown;
//window.onerror		    		= LVMP_document_error;
//  document.onreadystatechange		= LVMP_Document_Loading;
 
//document.onpropertychange 	= LVMP_document_OnActivate;

 window.onload		= LVMP_Document_Loading;

//////////////////////////////////////////////////////////////




var myPopUp;

var myOldTarget;
var Target;
var myOldStr;
var n;


function replaceContext(){

	if(window.parent==window){
			var doc_url = document.URL; 		
			var pageName = doc_url.substr(doc_url.lastIndexOf("/")+1);
			document.location.replace("../../../main.html?"+pageName);
	}
}




function LVMP_DOCUMENT_SHOWPDF()
{

	
			

			var mystring;						
			
			mystring = new String(window.parent.frames[2].document.location.href);						
			var myFPath =  mystring.split("/");					
			var myFileName  = myFPath[myFPath.length -1];
			

													
			var myFilePDF = "dati/f/pdf/" + myFileName.slice( 0, myFileName.length -3) +"pdf";
			


			

			if (typeof myPopUp  == 'object')
			{					
			  
                  		if (myPopUp.closed == false)
                 		 {			    
                      			myPopUp.close();
			   
                 		 }

			}										
			
			
             		var myPopUp = window.open(myFilePDF  ,'Versionpdf','fullscreen=0,scrollbars=1,resizable=1, toolbar=0,width=400, height=600');																	


}


function LVMP_SetPdfButton()
{
	if ( window.name == "document" )	
	{				
	    var oTables = window.parent.frames[1].document.getElementsByTagName("TABLE"); 			
		var myHref =  window.document.location.href
		
		try
		{
			if (myHref.search("main_content.html") > -1)
			{
				oTables[0].rows[0].cells[0].style.display = 'none' 
			}
			else
			{
				oTables[0].rows[0].cells[0].style.display = '' 
			}
		}
		catch(e)
		{
		}
		
		
	}
}

function LVMP_SetDocumentTitle(myTitle)
{	
	
	
	
	
	//var  myframeDocumentToolbar =  window.parent.frm_document_toolbar;
	
	
	
	

	if ( window.name == "document" )
	
	{
		if (myTitle == "")
		{
		
			myTitle = document.title;		
		
			if ( myTitle == "" )
			{
			myTitle = document.title;
			}
		}
		
 
	        var oTables = window.parent.frames[1].document.getElementsByTagName("TABLE");

 		

	
		try
		{
			if ( myTitle.length > 200 )
			{
				  oTables[0].rows[0].cells[2].innerHTML =  myTitle.slice(0,200) + "...  "
				//myframeDocumentToolbar.document_title.innerText =  myTitle.slice(0,200) + "...  "
				
			}
			else
			{
				 oTables[0].rows[0].cells[2].innerHTML = myTitle
				//myframeDocumentToolbar.document_title.innerText =  myTitle + "  "
			}
		}
		catch(e)
		{
		}
	}
}


function LVMP_Document_Loading()
{
	if (window.name.substr(0, 1)!='N'){
		replaceContext();
	}
	LVMP_SetPdfButton();
	LVMP_SetDocumentTitle("");
}




//////////////////////////////////////////////////////////////
//     Crea dinamicamente la T.O.C. dei documenti, 
//     basandosi sugli stili
//////////////////////////////////////////////////////////////
function LVMP_DOCUMENT_CREATE_TOC()
{         

	var mySourceDoc = window.parent.frames[2].document
	var myHref = mySourceDoc.location.href;																												
	myHref = myHref.replace("/s/","/pdf/")
	myHref = myHref.replace(".htm",".pdf")
	
   	if (typeof myWin == 'object')
    {						  
      	if (myWin.closed == false)
		{	                		
			myWin.close();
		}
    }															
    
    myWin = window.open(myHref ,'LVMP_TOC','fullscreen=0,scrollbars=1,resizable=1, menubar=0,toolbar=0, status=1, width=600, height=400');                    
   
   
	/*
	 myWin = window.open('createtoc.htm','LVMP_TOC','fullscreen=0,scrollbars=1,resizable=1, menubar=0,toolbar=0, status=1, width=600, height=400');                       	       	
     myWin.focus();   
   */
   	           
	 
}


function MyDocumentNote(myBM)
{
	
			var mystring;						
			
			mystring = new String(document.location.href);						
			var myFPath =  mystring.split("/");					
			var myFileName  = myFPath[myFPath.length -1];

													
			myFileNote = "../../f/n/n" + myFileName	+ "#FN"+ myBM;			
			//alert (myFileNote);

			if (typeof myPopUp  == 'object')
			{					
			  
                  if (myPopUp.closed == false)
                  {			    
                      myPopUp.close();
			   
                 }

			}										
			
			
             myPopUp = window.open(myFileNote,'Note','fullscreen=0,scrollbars=1,resizable=1, toolbar=0,width=350, height=150');																	
			             
						
                        
 }


function MyDocumentRSN(myRSN)
{
	
			var mystring;						
			
			mystring = new String(document.location.href);						
			var myFPath =  mystring.split("/");					
			
			if  ( "document" == document.parentWindow.name )
			{
				var myFileName  = myRSN + ".htm"
				document.location.href = myFileName  
			}
			else
			{
				var myFileName  = "../s/" +myRSN+ ".htm"
				 window.opener.location.href = myFileName
			}
			

			
   		  
			
                        
 }

function IfEnterstartfindInPageII(str)
{

     if ( navigator.appName == "Microsoft Internet Explorer"){

	if (window.event.keyCode == 13)  // checks whether the ENTER key 

   	{   	
	
		findInPage(str);
		return false;
	
   	}
     }

     if ( navigator.appName == "Netscape"){

	if (str.which == 13)  // checks whether the ENTER key 

   	{   	
	
		findInPage(str);
		return false;
	
   	}
     }
}


function findInPage(str) 
{	

	//myOldTarget = target	
			
	var win = window.parent.frames[2];		
		
	
	if ( str != "" )
	{	

		if ( n == 0 )
		{
			myOldStr = str;			
		}

		else		
		{
			
			if ( myOldStr != str )
			{
				n = 0;
				myOldStr = str;
				
			}
		}												
		
	}
	else
	{
		return;
	}

	if ( navigator.appName == "Microsoft Internet Explorer")
	{
		var txt, i, found;					
		txt = win.document.body.createTextRange();
		for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) 
		{
  		  txt.moveStart("character", 1);
		  txt.moveEnd("textedit");
		}
	
	
		if (found) 
		{
			txt.moveStart("character", -1);
			txt.findText(str);
			txt.select();
			txt.scrollIntoView();
			n++;
		}
		else 
		{
			if (n > 0)
			{
				n = 0;				
				findInPage(str);
			}
			else
			{	
				alert(str + ": Aucune occurrence trouvée");
			}
	
		}
	
	}
	else
	{
			
		
		if (!win.find(str))
		{
			while(win.find(str, false, true))
			n++;
		}
		else
		{
			n++;			
			if (n == 0) alert(str + ": Aucune occurrence trouvée");
		}
		
	}



}



function mySearch(mystring, mybtn)
{
	
	
	
	if ( mystring != "")
	{
		
		
		document.forms['search'].elements[1].value = "";

		if (mybtn == "tabmat")
		{
			document.forms['search'].action = 'searchtm.idq';			
			document.forms['search'].elements[1].value ='@DocTitle CONTAINS ' + document.forms['search'].elements[0].value
		}
		else
		{
			document.forms['search'].action = 'search.idq';
			document.forms['search'].elements[1].value = document.forms['search'].elements[0].value


		}
		document.forms['search'].submit();
	}
}

