var linkUrl=document.location.href;
//last two replace to prevent cross site scripting
linkUrl=linkUrl.replace(/&/g,"%26").replace(/</g,"").replace(/>/g,"").replace(/%3e/gi,"").replace(/%3c/gi,"");

function addrollover(image_src,image_id){ 
     if(document.getElementById(image_id)){ 
          if(image_src.indexOf("_off")!=0){ 
               new_image_src = image_src.replace("_off","_on"); 
               document.getElementById(image_id).src=new_image_src; 
                
          }else{ 
               //if(s.indexOf("_off.gif") != 0){ 
               //new_image_src = image_src.replace("_off","_on"); 
               //document.getElementById(image_id).src=new_image_src; 
               //} 
          } 
               new_img_src = null; 
               image_src = null; 
               image_id = null; 
     } 
} 
 
function removerollover(image_src,image_id,old_status){
		if(old_status!="on"){
               new_img_src = image_src.replace("_on","_off"); 
               document.getElementById(image_id).src=new_img_src; 
               new_img_src = null; 
               image_src = null; 
               image_id = null;
		}
 
}

function popup(str) {

        searchWin = window.open(str,'popup','scrollbars=yes,resizable=yes,width=500,height=400,status=no,location=no,toolbar=no');

//        searchWin.refer = self;

}

function getStyleObject(objectId)
		{
			if (document.getElementById && document.getElementById(objectId)) {
				return document.getElementById(objectId).style;
			} else if (document.all && document.all(objectId)) {
				return document.all(objectId).style;
			} else {
				return false;
			}
		}
	function Toggle(thediv)
		{
			statebuffer = getStyleObject(thediv).display;
			getStyleObject('menu1').display = "none";
			getStyleObject('menu2').display = "none";
			getStyleObject('menu3').display = "none";
			getStyleObject('menu4').display = "none";
			getStyleObject('menu5').display = "none";
			if (!statebuffer || statebuffer == "none") {
				getStyleObject(thediv).display = "block";
			}
		}

var flashinstalled = 0;
var flashversion = 0;
MSDetect = "false";
if (navigator.plugins && navigator.plugins.length)
{
	x = navigator.plugins["Shockwave Flash"];
	if (x)
	{
		flashinstalled = 2;
		if (x.description)
		{
			y = x.description;
			flashversion = y.charAt(y.indexOf('.')-1);
		}
	}
	else
		flashinstalled = 1;
	if (navigator.plugins["Shockwave Flash 2.0"])
	{
		flashinstalled = 2;
		flashversion = 2;
	}
}
else if (navigator.mimeTypes && navigator.mimeTypes.length)
{
	x = navigator.mimeTypes['application/x-shockwave-flash'];
	if (x && x.enabledPlugin)
		flashinstalled = 2;
	else
		flashinstalled = 1;
}
else
	MSDetect = "true";


function flashImg(idFlash,idImg){
	//flash();
	if (flashinstalled==1){
		getStyleObject(idFlash).display = "none";
		getStyleObject(idImg).display = "block";
	}
}


function submitform(strMMTypology){
	document.mmsearchform.keywords.value = '';
	document.mmsearchform.startdate.value = '';
	document.mmsearchform.enddate.value = '';
	document.mmsearchform.areaKey.value =  '\/';
	document.mmsearchform.mmtypology.value = strMMTypology;
	document.mmsearchform.submit();
}



// JavaScript Document menu
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function genericPop(myUrl,myWinName,myWidth,myHeight,myPars) {
	var winl = (screen.width - myWidth) / 2;
	var wint = (screen.height - myHeight) / 2;
	parameters = myPars + '';
	if (parameters == '') parameters = ',toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no';
	gwin=window.open(myUrl,myWinName,'width='+myWidth+',height='+myHeight+',left='+winl+',top='+wint+parameters);
	gwin.focus();
}

function addPage() {
  if ((navigator.appName=="Microsoft Internet Explorer")&&
    (parseInt(navigator.appVersion)>=4)) {
    window.external.addFavorite
      (document.location.href, document.title);
  } else {
    var msg = "Attenzione il tuo browser non supporta lo script, aggiungi manualmente ai preferiti la seguente url " +
      document.location.href;
    if (navigator.appName=="Netscape") msg += " (CTRL-D)";
    alert(msg); 
  }
}


function MM_openBrWindow(theURL,winName,features) { //v2.0

  window.open(theURL,winName,features);

}
function feedBack(lang){
	var _url = "http://62.77.56.78/siteEval/vota.aspx?site=TI&lang=" + lang + "&page=" + linkUrl.replace(/\?/g,"%3F");
	try{
			new Windoo({
				modal: true,
				top: 50,
				left: (screen.width-400)/2,
				width: 400,
				height: 420,
				position: false,
				title: '',
				type: 'iframe',
				shadow: false,
				container: false,
				ghost: {resize: true, move: true},
				buttons: {minimize: 'disabled', maximize: 'disabled'},
				url: _url,
				destroyOnClose: true,
				theme: Windoo.Themes.aero
			}).show();
	}catch(e){ window.open(_url, "feedback", "top=200,left=200,width=400,height=500,status=no, menubar=no, toolbar=no, scrollbars=yes");}
}

function pageUpdate(lang){
	var _url = "http://smallapp.telecomitalia.it/always_on_F1/pageChangedNotifier.aspx?theurl=" + linkUrl.replace(/\?/g,"%3F") + "&lang=" + lang;
	try{
			new Windoo({
				modal: true,
				top: 50,
				left: (screen.width-400)/2,
				width: 300,
				height: 300,
				position: false,
				title: '',
				type: 'iframe',
				shadow: false,
				container: false,
				ghost: {resize: true, move: true},
				buttons: {minimize: 'disabled', maximize: 'disabled'},
				url: _url,
				destroyOnClose: true,
				theme: Windoo.Themes.aero
			}).show();
	}catch(e){ window.open(_url, "pageUpdate", "top=200,left=200,width=300,height=300,status=no, menubar=no, toolbar=no, scrollbars=yes");}
}

function podcasting(lang){
	var _url = "/TIPortale/investitori/podcasting_"+lang+".htm";
	try{
			new Windoo({
				modal: true,
				top: 30,
				left: (screen.width-600)/2,
				width: 600,
				height: 400,
				position: false,
				title: 'Podcasting',
				type: 'iframe',
				shadow: false,
				container: false,
				ghost: {resize: true, move: true},
				buttons: {minimize: 'disabled', maximize: 'disabled'},
				url: _url,
				destroyOnClose: true,
				theme: Windoo.Themes.aero
			}).show();
	}catch(e){ window.open(_url, "podcasting", "top=200,left=200,width=600,height=300,status=no, menubar=no, toolbar=no, scrollbars=yes");}
}

function sms(lang, title, eventDate){
	var _url = "http://smallapp.telecomitalia.it/always_on_F1/singleEventAlert.aspx?lang=" + lang + "&title=" + title + "&eventDate=" + eventDate;
	try{
			new Windoo({
				modal: false,
				top: 10,
				left: 100,
				width: 300,
				height: 400,
				position: 'center',
				title: '',
				type: 'iframe',
				shadow: false,
				container: false,
				ghost: {resize: true, move: false},
				buttons: {minimize: 'disabled', maximize: 'disabled'},
				url: _url,
				destroyOnClose: true,
				theme: Windoo.Themes.aero
			}).show();
	}catch(e){ window.open(_url, "feedback", "top=10,left=100,width=300,height=400,status=no, menubar=no, toolbar=no, scrollbars=yes");}
}

function smsReminder(lang, title, eventDate, top, left){
	var _url = "http://smallapp.telecomitalia.it/always_on_F1/singleEventAlert.aspx?lang=" + lang + "&title=" + title + "&eventDate=" + eventDate;
	try{
			new Windoo({
				modal: false,
				top: top,
				left: left,
				width: 300,
				height: 400,
				position: false,
				title: '',
				type: 'iframe',
				shadow: false,
				container: false,
				ghost: {resize: true, move: false},
				buttons: {minimize: 'disabled', maximize: 'disabled'},
				url: _url,
				destroyOnClose: true,
				theme: Windoo.Themes.aero
			}).show();
	}catch(e){ window.open(_url, "feedback", "top=top,left=left,width=300,height=400,status=no, menubar=no, toolbar=no, scrollbars=yes");}
}

function getPrint(print_area) {	
			
			//Creating new page
			var pp = window.open();
			//Adding HTML opening tag with <HEAD> … </HEAD> portion 
			pp.document.writeln('<HTML><HEAD><title>Print Preview</title>')
			pp.document.writeln('<LINK href="/TIPortale/css/TI_style.css" type="text/css" rel="stylesheet"><LINK href="/TIPortale/css/print.css"  type="text/css" rel="stylesheet"><base target="_self"></HEAD>')
			//Adding Body Tag
			pp.document.writeln('<body  bottomMargin="0" leftMargin="0" topMargin="0" rightMargin="0">');
			//Creating two buttons Print and Close within a table
			pp.document.writeln('<TABLE width="100%"><TR><TD><img src="/TIPortale/images/logo_telecom_new.gif" border="0" alt="Telecom Italia"></TD><TD align="right"><INPUT ID="PRINT" type="button" value="Print" onclick="window.print();"><INPUT ID="CLOSE" type="button" value="Close" onclick="window.close();"></TD></TR></TABLE>');
			//Writing print area of the calling page
			pp.document.writeln(document.getElementById(print_area).innerHTML);
			//Ending Tag of </form>, </body> and </HTML>
			pp.document.writeln('</body></HTML>');			
			pp.document.close();
		
}

function popupOpener(link){
	window.opener.parent.document.location.href=link;
	window.close();
}
function showMap(info,address,lang){if(lang && lang.toUpperCase()=='EN') lang = 'en'; else lang = 'it'; if(info && address){ var url = "/TIPortale/maps/map_" + lang + ".htm?info=" + info + "&address="+address; MM_openBrWindow(url,'map','scrollbars=no,width=820,height=510,status=no, menubar=no, toolbar=no');}}
function mapit(info,address){showMap(info,address,'it');} function mapen(info,address){showMap(info,address,'en');}