// 2008.12.05 bY Stefano.Deiuri@Elettra.Eu

var itemspace =15;

var th_bullet ="<th class='menuv'><img src='/images/menuv_bullet.gif' width='11' height='5' border='0' vspace='5'></th>";
var th_bullet_active ="<th class='menuv'><img src='/images/active_bullet.gif' width='11' height='5' border='0' vspace='5'></th>";
var th_corner ="<th class='menuv'><img src='/images/menuv_corner.gif' width='11' height='8' border='0'></th>";
var tr_spacer ="<tr><td>&nbsp;</td><th class='menuv'><img src='/images/spacer.gif' width='1' height='" +itemspace +"'></th></tr>"; 
var tr_spacer_dx ="<tr><th class='menuv'><img src='/images/spacer.gif' width='1' height='" +itemspace +"'></th><td>&nbsp;</td></tr>"; 

//-----------------------------------------------------------------------------
function local_info( _anchor_name ) {
 if (localonly == false) return;

 switch (_anchor_name) { 
 		case "RQ":
			 document.writeln( '<br><br><br><a href="/science/rq/"><img src="/science/rq/rq.gif" width="50" border="0"></a><br>IV Relazione Quadrimenstrale' );
			 break;
		case "6FP":
			 document.writeln( '<br><br><br><a href="/projects/fp6.html"><img src="/projects/images/fp6.gif" width="50" border="0"></a><br><strong>Sixth Framework Programme</strong>' );
			 break;
		case "6FP2":
			 document.writeln( '<td width="25%"><a href="/projects/fp6.html"><img src="/projects/images/fp6.gif" width="50" border="0" /></a><br /><strong>Sixth Framework<br />Programme</strong></td>' );
			 break;
 }

 return;
}

//-----------------------------------------------------------------------------
function open_video2_bl() {
 window.open( "/visitors/video/video2.html", "video", "width=500,height=500" );
}

//-----------------------------------------------------------------------------
function open_video_bl() {
 window.open( "/visitors/video/video.html", "video", "width=500,height=500" );
}

//-----------------------------------------------------------------------------
function uo_address() {
 w =window.open( "/experiments/users_handbook/address.html", "", "width=350,height=150" );
}

//-----------------------------------------------------------------------------
function mappa() {
 w =window.open( "/mappa.html", "", "width=450,height=450" );
}

//-----------------------------------------------------------------------------
function wst() {
 w =window.open( "/wst.html", "", "width=300,height=300" );
}

//-----------------------------------------------------------------------------
function number_list( _id, _email ) {
 url ="/phonebook/index.php?numlist=1&id=" +_id;
 if (_email) url +="&email=1";

 w =window.open( url, "numlist", "width=350,height=200,scrollbars=1,resizable=1" );
}

//-----------------------------------------------------------------------------
function contact_info( _id ) {
 url ="/phonebook/index.php?inwin=1&id=" +_id;

 w =window.open( url, "numlist", "width=400,height=160,scrollbars=1,resizable=1" );
}



//-----------------------------------------------------------------------------
function GetMenuLink( _obj, _path ) {
 if (_obj.wiki) return '/' +_obj.wiki +(_obj.wikipage ? '/index.php?n=' +_obj.wikipage : '');
 else if (_obj.wikipage) return _path +'?n=' +_obj.wikipage;
 else if (_obj.https) return 'https://' +_obj.https;
 else if (_obj.http) return 'http://' +_obj.http;
 else if (_obj.dir) return '/' +_obj.dir;
 else if (_obj.rdir) return _path +'/' +_obj.rdir;
 else if (_obj.page) return '/' +_obj.page +(_obj.page.indexOf('.') == -1 ? '.html' : '');
 else if (_obj.rpage) return _path +'/' +_obj.rpage +(_obj.rpage.indexOf('.') == -1 ? '.html' : '');
 else if (_obj.js) return 'javascript: ' +_obj.js +';';
 else if (_obj.mailto) return 'mailto: ' +_obj.mailto +'@elettra.trieste.it';
 return '#';
}


//-----------------------------------------------------------------------------
function WriteQuickLinks( _active ) {
 with (document) {
	writeln( "&nbsp;<br /><br /><table border='0' cellpadding='0' cellspacing='0' align='right'>" );
    writeln( "<tr><td align='right'><i>Quick Links</i></td><th class='menuv'>&nbsp;</th></tr>" +tr_spacer);

	for (i =0; i <QuickLinks.length; i ++) {
		q =QuickLinks[i];

		if (!q.hide) {
			active =(q.name == _active ? '_active' : '');
			tdclass ="menuSX" +(q.name == _active ? 'active' : '');
			target =(q.target ? " target='"+q.target+"'" : '');
		
			writeln( "<tr><td class='" +tdclass +"'><a href='" +GetMenuLink(q) +"'" +target +">" +q.text +"</a></td>" );
			writeln( (active ? th_bullet_active : th_bullet) +"</tr>" +tr_spacer );
		}
	}

	writeln( "</table>" );
 }
}


//-----------------------------------------------------------------------------
function WriteMenuSx( _active, _active_submenu ) {
 with (document) {
	writeln( "<table border='0' cellpadding='0' cellspacing='0'>" );
	writeln( "<tr><td width='139' align='right'><a href='/' target='_top'><img src='/images/logo_elettra-sm.gif' width='81' height='81' border='0' /></a><br /><br /></td><th class='menuv'>&nbsp;</th></tr>" );

	if (_active) {
		writeln( '<tr><td class="menuSX"><a href="/">back to homepage</a>&nbsp;</td>' );
		writeln( '<th class="menuv"><img src="/images/menuv_back.gif" width="11" height="9" border="0" vspace="5"></th></tr>' );
		writeln( tr_spacer );
	}
		
	for (i =0; i <MenuSx.length; i ++) {
		q =MenuSx[i];
		link =GetMenuLink(q,false);

		if (q.name == _active) {
			writeln( "<tr><td align='right'>" );
			if (q.submenu) {
				WriteSubMenuSx( q.text, link, q.submenu, _active_submenu );
				writeln( "<br /></td>" +th_bullet_active +"</tr>" );
			} else {
				writeln( "<tr><td class='menuSXactive'><a href='" +link +"'>" +q.text +"</a></td>" );
				writeln( th_bullet_active +"</tr>" +tr_spacer );
			}
		} else {
			writeln( "<tr><td class='menuSX'><a href='" +link +"'>" +q.text +"</a></td>" );
			writeln( th_bullet +"</tr>" +tr_spacer );
		}
	}

	writeln( "</table>" );
 }
}
//-----------------------------------------------------------------------------
function WriteSubMenuSx( _text, _link, _submenu, _active ) {
 with (document) {
	writeln( "<table cellpadding='0' cellspacing='0' border='0'>" );
	writeln( "<tr><td class='menuSX" +(_active ? '2' : 'active') +"'><a href='" +_link +"'>" +_text +"</a></td>" );
	writeln( th_corner +"</tr>" );

	for (j =0; j <_submenu.length; j ++ ) {
		q =_submenu[j];
		writeln( tr_spacer +"<tr><td class='menuSX" +(q.name == _active ? 'active' : '2') +"'><a href='" +GetMenuLink(q,_link) +"'>" +q.text +"</a></td>" +th_bullet_active +"</tr>" );
	}

	writeln( "</table>" );
 }
}
//-----------------------------------------------------------------------------
function write_menu_sx( _level1, _level2 ) {
 WriteMenuSx( _level1, _level2 );
}


//-----------------------------------------------------------------------------
function WriteMenuDx( _select ) {
 
 with (document) {
 	   writeln( '<table cellpadding="0" cellspacing="0" border="0">' );
	   if (_select == 256) writeln( "<tr><th class='menuv'>&nbsp;</th><td><a href='/FERMI/'><img src='/images/logo_fermi-sm.gif' border='0' /></a></td></tr>" );
 	   writeln( '<tr><th width="11" class="menuv">&nbsp;</th><td width="139">&nbsp;</td></tr>' );
	   
	   for (i =0; i < MenuDx.length; i++) {
			q =MenuDx[i];
 	   		writeln( "<tr>" +(q.name == _select ? th_bullet_active : th_bullet) + "<td class='menuDX" +(q.name == _select ? 'active' : '') +"'><a href='" +GetMenuLink(q) +"'>" +q.text +"</a></td></tr>" );
 	   		writeln( tr_spacer_dx );
	   }

	   if (language_available) {	   
	   	   lang =(language == "it") ? "en" : "it";
 	   	   writeln( '<tr>' );
 	   	   writeln( '	<th class="menuv">&nbsp;</th>' );
 	   	   writeln( '	<td class="menuDX"><br><a href="' +other_language_page +'"><img src="/images/menudx_' +lang +'.gif" width="72" height="26" border="0"></a><br><br></td>' );
 	   	   writeln( '	</tr>' );
	   }

 	   writeln( '</table>' );
 }
}
//-----------------------------------------------------------------------------
function write_menu_dx( _select ) {
 WriteMenuDx( _select );
}

//-----------------------------------------------------------------------------
function WriteMenuDown( _home, _select, _br2x ) {

 lu =(last_update_date.length > 5) ? last_update +last_update_date +"&nbsp;&nbsp;&nbsp;" : "";
 
 with (document) {
 	   if (!_br2x) writeln( "<br /><br />" );
 	   writeln( "<table border=0 cellpadding=0 cellspacing=0>" );
	   if (lu) writeln( '<tr><td colspan="6" align="right" class="update">' +lu +'</td></tr>' );
	   writeln( '<tr><td><img src="/images/menudown_corner_l.gif" width="16" height="13" alt="" border="0"></td>' );

       for (i=0; i<MenuDown.length; i++) {
			writeln( '	<td valign=bottom><img src="/images/menudown_bullet' +(MenuDown[i].name == _select ? "_active" : "") +'.gif" width="100" height="5"></td>' );
 	   }
	   writeln( '	<td><img src="/images/menudown_corner_r.gif" width="16" height="13" border="0"></td>' );
 	   writeln( "</tr><tr align='center' valign='top'><td></td>" );

       for (i=0; i<MenuDown.length; i++) {
			q =MenuDown[i];
			writeln( "<td class='menuDown" +(q.name == _select ? 'Active' : '') +"'><a href='" +GetMenuLink(q) +"'>" +q.text + "</a></td>" );
	   }
 	   writeln( "<td></td></tr></table>" );
	   
	   writeln( '<br /><br /><table border="0"><tr><td align="right" class="address"><strong>Sincrotrone Trieste S.C.p.A. di interesse nazionale</strong><br />Strada Statale 14 - km 163,5 in AREA Science Park<br />34149 Basovizza, Trieste ITALY<br>Tel. +39 040 37581 - Fax. +39 040 9380902<br /><i>Anagrafe Nazionale Ricerche Cod. 51779CRP<br />partita IVA 00697920320</i></td><td><a href="http://www.area.trieste.it" target="_blank"><img src="/images/logo_area.gif" width="101" height="43" border="0" align=middle></a></td></tr></table>' );
 }
}
//-----------------------------------------------------------------------------
function write_menu_down( _home, _select, _br2x ) {
 WriteMenuDown( _home, _select, _br2x );
}




//-----------------------------------------------------------------------------
function write_pre( _menusx1, _menusx2, _topbar, _alt, _lud, _language, _expand ) {

 printable_mode =( window.location.href.indexOf( "?printable" ) != -1 ) ? 1 : 0; 
 content_mode =( window.location.href.indexOf( "?content" ) != -1 ) ? 1 : 0; 

 if (ELETTRA_Emergency) document.writeln( ELETTRA_Emergency );

 if (printable_mode) {
  	 document.writeln( '<center><table border="0"><tr valign="middle"><td><img src="/images/logo_elettra-s.gif" width="50" height="51" alt="" border="0"></td><td><h1 class="h0"><i>ELETTRA Synchrotron Light Laboratory</i></h1></td></tr></table></center><hr noshade size="1">' );
 	 return;
 }
 
 if (content_mode) {
    document.writeln( '<center>' );
    return;
 }
 
 if (!_alt) _alt = "";
 if (_lud) last_update_date = _lud;

 t0 =window.location.href; 
 t =window.location.href.split( "/" );

 if (t.length > 6 && t[3] == "experiments" && t[4] == "beamlines") {
	if (t[6] == "" || t[6].indexOf("index") == 0) blpdf =t[5];
 }
 
 if (_language) {
 	 language =_language;
 	 language_available =1;
	 
	 if( language == "en" ) other_language_page ="it-" +(t[ t.length-1 ] ? t[ t.length-1 ] : "index.html");
	 else other_language_page =t[ t.length-1 ].substr( 3 );
 }

 now =new Date();
 l =window.location.href;
 page =l.substr( l.indexOf( "/", 8 )+1 );

 with( document ) {
	   html =(window.location.href.indexOf( ".ph" ) != -1 ) ? "" : "&html=1";
	   write( "<img src='/scripts/webstats-mainrec.php?ts=" +now.getTime() +html +"' width='1' height='1' border='0' />" );
 
 	   writeln( '<center><br>' );
	   
 	   if (_expand == 1) writeln( '<table border="0" cellpadding="0" cellspacing="0">' );
	   else writeln( '<table border="0" width="820" cellpadding="0" cellspacing="0">' );
	   
 	   writeln( "<tr><td width='150' align='right' valign='top'>" );
	   WriteMenuSx( _menusx1, _menusx2 );
	   WriteQuickLinks( _menusx1 );
 	   writeln( "</td>" );

	   if (_expand == 1) writeln( '	<td valign="top">' );
	   else writeln( '	<td width="520" valign="top">' );
	   
 	   writeln( '		<table border="0" width="100%" cellpadding="5" cellspacing="0">' );
 	   if (_topbar) {
	   	   if (_topbar.charAt(0) == '/') image =_topbar +".jpg";
		   else image ="images/" +_topbar +".jpg";
	   
	   	   writeln( '<tr><td colspan="3" align="center"><img src="' +image +'" width="480" height="90" alt="' + _alt + '" border="2" /></td></tr>' );
        }
 	   writeln( '<tr>\n<td rowspan="2" width="10">&nbsp;</td>\n<td><br />' );
 }
}


//-----------------------------------------------------------------------------
function write_pre_library() {

 cok = findinCookie( "ELETTRA", "library" );
 if( cok != "" ) {
 	 a = cok.split( "," );
	 write_pre( a[1], a[2] );
 } else write_pre( "organisation", "chart-sector-administrative" );
}


//-----------------------------------------------------------------------------
function write_post( _menuDx, _menuDown, _noback ) {
 
 if (printable_mode || content_mode) {
    document.writeln( '</center>' );
    return;
 }
 
 with (document) {

	if (blpdf) {
		writeln( "<br /><br /><img src='/icons/pdf.gif' width='16' height='16' border='0' /> <a href='../docs/" +blpdf +".pdf' target='_blank'>Download printable PDF document</a>" );
	}
 
	if (_noback != 1) writeln( '<br /><br /><img src="/images/back.gif" width="9" height="9" border="0" /> <a href="javascript: history.go(-1)" class="back">back to previous page</a>' );

	writeln( '</td>\n<td rowspan="2" width="10">&nbsp;</td>\n</tr>\n</table>\n</td>\n<td width="150" align="left" valign="top">' );

	WriteMenuDx( _menuDx );
 	
	writeln( '<img src="/images/spacer.gif" width="150" height="1" border="0">\n</td>\n</tr>\n<tr>\n<td colspan="3" align="center">' );

	WriteMenuDown( 0, _menuDown );
 	
	writeln( '</td></tr></table></center>' );
 }
}

//-----------------------------------------------------------------------------
function image_popup( _image_src, _width, _height, _dida ) {
 photo( _image_src, _width, _height, _dida );
 return false;
}

//-----------------------------------------------------------------------------
function photo( _image_src, _width, _height, _dida ) {

 if (screen.width < (_width+20)) winw = screen.width-100;
 else winw = _width+20;
 
 if (screen.height < (_height+50)) winh = screen.height-100;
 else {
 	  winh = _height+20;
	  if (_dida) winh = winh + 20;
 }

 winx = ",screenX=" + ((screen.width - winw) / 2);
 winy = ",screenY=" + ((screen.height - winh) / 2);

 if ((screen.width < (_width+20)) || (screen.height < (_height+20))) other = ",scrollbars=yes";
 else other = "";

 win =window.open( "", "Image", "width=" + winw + ",height=" + winh + winx + winy + other );
 
 with (win.document) {
 	   open();
	   write( '<head><title>Image</title></head><body bgcolor="#ffffff">' );
	   write( '<img src="' + _image_src + '" width="' + _width + '" heigth="' + _height + '" border="0" />' );
	   if (_dida) write( '<br><center><font face="Verdana,Arial,Times" size="2">' + _dida + '</font></center>' );
	   write( '</body>' );
	   close();
 }
}

//-----------------------------------------------------------------------------
function link_photo( _link, _image_src, _width, _height, _dida ) {
 href = 'href="javascript:photo(\'' + _image_src + '\',' + _width + ',' + _height + ',\'' + _dida + '\');"';
 with (document) {
 		if (_link.length > 1) write( '<a ' + href + ' class="photo">' + _link + '</a>' );
 		write( ' <a ' + href + '><img src="/icons/photo.gif" width="16" height="12" align="middle" border="0" /></a>' );
 }		
}

//-----------------------------------------------------------------------------
function lud( _lud ) {
 last_update_date = _lud;
}

//-----------------------------------------------------------------------------
function setCookie( _name, _value, _expire_day, _path ) {
 if (_expire_day != null) {
        today = new Date();
        expire = new Date();

        expire.setTime( today.getTime() + 1000*60*60*_expire_day );

        texp = "; expires=" + expire.toGMTString();

 } else texp = "";

 path ="; path=" +(_path != null ? _path : '/');
 if (_path == false) path ='';
 	
 document.cookie = _name +"=" +escape(_value) +texp +path;
}

//-----------------------------------------------------------------------------
function getCookie( _name ) {
 if (document.cookie.length > 0) {
       of = document.cookie.indexOf( _name + "=" );
       if (of == -1) return "";
       of += _name.length + 1;
       end = document.cookie.indexOf( ";", of );
       if (end == -1) end = document.cookie.length;

 } else return "";

 return unescape( document.cookie.substring( of, end ) );
}

//-----------------------------------------------------------------------------
function clearCookie( _name, _path ) {
 path ="; path=" +(_path != null ? _path : '/');
 if (_path == false) path ='';
 document.cookie = _name +"=" +path;
}

//-----------------------------------------------------------------------------
function findinCookie( _name, _value ) {
 cok =getCookie( _name );
 if (cok == "") return "";
 if (cok.indexOf( _value) == -1 ) return "";
 return cok; 
}

//-----------------------------------------------------------------------------
function showCookie( _name ) {
 alert( "cookie: " +_name +"=" +getCookie( _name ) );
}

