/*-------------------- External Js Dependency Management ---------------------------*/
function w3gCheckMyJsDependency(){	
 if(typeof(w3gUtils)=='undefined')w3gIncludeJs("js/obj/w3gUtils.js");
 if(typeof(w3gMedia)=='undefined')w3gIncludeJs("js/obj/w3gMedia.js"); 
}
/*
var w3gDynIncludedJs= new Array();
w3gDynIncludedJs.push('js/w3g.js');
*/

function w3gIncludeJs(filename){ 
	if(w3gIsJsIncluded(filename)==true)return;
	//w3gDynIncludedJs.push(filename);	
 	var scriptElt = document.createElement('script');
 	scriptElt.type = 'text/javascript';
	scriptElt.src = filename;
 	document.getElementsByTagName('head')[0].appendChild(scriptElt); 

}
function w3gIsJsIncluded(filename)
{ 	
	if (window.document.getElementsByTagName) {
	   var inclusion = document.getElementsByTagName('head')[0].getElementsByTagName("script");
	   for (i = 0; i < inclusion.length; i++) {
	   	var obj = inclusion[i];
	   	if(obj && obj.src){
	   		if(obj.src.toString().indexOf(filename)>-1) return true;
	   }
	  }
	}
	return  false;
}

w3gCheckMyJsDependency();

/*-------------------- openPop ----------------------------------*/
function openPop(myIndirizzo, myTarget, popTitle, option ){ 
	
	if ((popTitle) && (popTitle!=null) && (popTitle.length>0))
		myIndirizzo += (myIndirizzo.indexOf("?")>=0 ? "&" : "?") + "popTitle="+popTitle;
		
	if (getW3gParameterCheck("idDevice=mobile"))
		myTarget =  "_top";
		
	if (option==null){		
		var viewport = window.screenDimensions();		
		// 2008.05.05@FC REMOVED, resolution 90%x80% only for media...
		//var defaultOption = 'width='+(screen.width*0.9)+',height='+(screen.height*0.8)+',status=yes,resizable=yes,scrollbars=yes,toolbar=no,menubar=no';
		var defaultOption = 'width=500,height=580,status=yes,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,top=20px,left=20px';
		if (/*myIndirizzo.indexOf("show?")>=0 && */myTarget!="_top") {					
			var myIdMedia = null;
			if(myIndirizzo.indexOf("show?")>=0){
				myIdMedia = myIndirizzo.substr(myIndirizzo.indexOf("show?")+(("show?").length));
			}else if(myIndirizzo.indexOf("popupMedia.do?id=")>=0){				
				myIdMedia = myIndirizzo.substr(myIndirizzo.indexOf("popupMedia.do?id=")+(("popupMedia.do?id=").length));
			}			
			if(myIdMedia!=null){
				var myMedia = new w3gMedia(myIdMedia);
				myMedia.load(function(){w3gOpenPop4MediaAjax(myMedia,myIndirizzo,myTarget)});				
				return;
			}else{
				//2008.04.28@FC open window with 90% user screen resolution 
				option = defaultOption;
			}
		} else{
			option = defaultOption;
		}
	}

	var popUpWindow = window.open(myIndirizzo, myTarget, option);
	if (popUpWindow!=null) popUpWindow.focus();
}  
function w3gOpenPop4MediaAjax(mediaObj,requestUrl,myTarget){
	if (myTarget==null) myTarget = "_blank"; //2007.07.24@IV fix openpop from pop, target must be setted otherwise 'access denied'
	var winOpt = "status=yes,resizable=yes,toolbar=no,menubar=no";			
	if(mediaObj.isImage()){		
		try {	
			var myImage = mediaObj.getImage();
			var iw = mediaObj.getImageWidth()
			if(iw==null || iw<=0)iw = myImage.width;
			var ih = mediaObj.getImageHeight()
			if(ih==null || ih<=0)ih = myImage.height;
			//if (iw>50||ih>50)	
				winOpt += ",width="+(iw+20)+",height="+(ih+25)+"";			
		}catch(err){winOpt += ",width=100,height=100";}
	}else{
		//2008.04.28@FC open window with 90% user screen resolution 
		var screen = window.screenDimensions();		
		winOpt += ",width="+(screen.width*0.9)+",height="+(screen.height*0.8);	
	}
	try { // forzo la chiusura della finestra precedentemente aperta per permettere l'apertura con dimensione corretta
		popUpWindow = window.open('portal/pageBlank.jsp',myTarget,winOpt);
		if (!popUpWindow.closed) popUpWindow.close();
	} catch (e) {/*DO NOTHING*/}
	popUpWindow = window.open( (requestUrl || mediaObj.getUrl()), myTarget, winOpt);	
	if (popUpWindow!=null) {
		popUpWindow.focus();
	}
}
var myTtFunction = new function(){};
/* ---------------- openPop4Media with autosizing for true image objects -----------------*/
var cntPict=0;
var idPict=new Array();

function openPop4Media(img, target){
	if (target==null) target = "_blank"; //2007.07.24@IV fix openpop from pop, target must be setted otherwise 'access denied'
	cntPict++;
	idPict[cntPict] = new Image();
	idPict[cntPict].src = img;
	idPict[cntPict].target = target;
	targetWin = window.open("portal/pageBlank.jsp", target, "width=100,height=100"); //2006.05.03@FV fix "openpop from pop"
	if (targetWin!=window) targetWin.close(); //close pre-opened target window 
	var interrupt = "viewPop4Media("+cntPict+")";  
	setTimeout( interrupt, 200 ); // set delay to allow data download
}
function viewPop4Media(id){
	var winOpt = "status=yes,resizable=yes,toolbar=no,menubar=no";
	try {
		if (idPict[id].width>50||idPict[id].height>50)	
		winOpt += ",width="+(idPict[id].width+20)+",height="+(idPict[id].height+25);
	} catch (e) {}
	var popUpWindow = window.open(idPict[id].src, idPict[id].target, winOpt);
	if (popUpWindow!=null) popUpWindow.focus();
}

/*-------------------- getW3gDocumentURL ---------------------------*/
function getW3gDocumentURL(){
	var urlLimit = document.URL.indexOf("?");
	var strUrl = document.URL.substring( 0, (urlLimit>0 ? urlLimit : document.URL.length));
	if (w3gItemAndSezione!=null) strUrl += "?"+w3gItemAndSezione;
	return strUrl;
} 
/*-------------------- getW3gDocumentURL ---------------------------*/
function getW3gParameterCheck( p ){
	try {
		var w3gp = w3gItemAndSezione.split("&");
		for (var i=0; i<w3gp.length; i++) {
			if (w3gp[i]==p) return true;
		}
	} catch (err) {};
	return false;
} 
/*-------------------- language ----------------------------------*/
var w3gItemAndSezione;
//2006.09.25@FV fix "location" value is not persistent on IE browser.
//2007.02.21@FV fix clear idLanguage parameter if present in qs
function language(idLanguage) {
	var strUrl = getW3gDocumentURL();
	var args = strUrl.split("&");
	var newUrl="";
	for (var i=0; i<args.length; i++) {
	 newUrl += (args[i].indexOf("idLanguage")>=0 ) ? "" : (i>0?"&":"")+args[i];
	}
	newUrl += (newUrl.indexOf("?")>0 ? "&":"?") + "idLanguage=" + idLanguage;
	window.open(newUrl,'_self','');
}
/*--------------------------- onloadFunctionAppender ----------------------*/
function onloadAddFunction( fnctn ) {
	if (window.addEventListener) 
		window.addEventListener( 'load', fnctn, false );
	else if (window.attachEvent)  
		window.attachEvent( 'onload', fnctn );
	else window.onLoad = fnctn;
}
/*-------------------- openerWindow ----------------------------------*/
function openerWindow( url ) {
var win;
try {
	if (opener!=null)
		win = opener.window.open( url, '_self','');
} catch (e) { 
	if (confirm("W3G lost synchronization. Please re-load main page"))
		window.close();
}
return win;
}

/*-------------------- formatData ----------------------------------*/
function formatData(campo){
   app = campo.value;
   lungh = app.length;
   // put the separator during the typing
   if(lungh == 3 || lungh == 6) campo.value = campo.value.substring(0,lungh-1) + "-";
   if(lungh == 11) campo.value = campo.value.substring(0,lungh-1) + " ";
   if(lungh == 14) campo.value = campo.value.substring(0,lungh-1) + ":";
} // formatData

/*------------------------- isDateTime ---------------------------------*/
function isDateTime(dateTime, messDescr, messFormat, messNumDays, messFebruary, messMonth, messYear, fullCondition) {
	var dateTimeStr = dateTime.value;
	var isOk = false;
	dateTime.value = (dateTimeStr.length>10) ? dateTimeStr.substring(0,10) : dateTimeStr; // isDate() need html object
	if (isDate(dateTime, messDescr, messFormat, messNumDays, messFebruary, messMonth, messYear, fullCondition) ) {
		dateTime.value = dateTimeStr;
		var timeStr  = (dateTimeStr.length>10) ? dateTimeStr.substring(11) : dateTimeStr;
		isOk = isTime( timeStr, messDescr, messFormat );
		if (!isOk) dateTime.focus();
	}
	return isOk;
}

/*------------------------- isTime ---------------------------------*/
function isTime(timeCrt, messDescr, messFormat ){
   var timePat = /^(\d{2})(\:)(\d{2})$/;
   var matchArray = timeCrt.match(timePat); // il formato è corretto?

   if(matchArray == null && timeCrt != "") {
	   alert(messDescr + " : " + messFormat);
      return false;
   }

   if(matchArray != null)  {    
	   hh = matchArray[1];
   	mm = matchArray[3];
   	if (!(hh.length==2 && hh>="00" && hh<"24" && mm.length==2 && mm>="00" && mm<"60" )) {
	   	alert(messDescr + " : " + messFormat);
      	return false;
      }
   }  

   return true;
}//isTime

/*------------------------- isDate ---------------------------------*/
function isDate(dateObj, messDescr, messFormat, messNumDays, messFebruary, messMonth, messYear, fullCondition) {
   dateCrt = dateObj.value;
   var datePat = /^(\d{2})(\-)(\d{2})(\-)(\d{4})$/;
   var matchArray = dateCrt.match(datePat); // il formato è corretto?
   if(matchArray == null && dateCrt != "") {
	   alert(messDescr + " : " + messFormat);
	   dateObj.focus();
      return false;
   }  
   if(matchArray != null)  {    
      day = matchArray[1];
      month = matchArray[3];
      year = matchArray[5];
    	// look the format
    	if (! checkDataValue("" + day, "" + month, "" + year, messDescr, messNumDays, messFebruary, messMonth, messYear, fullCondition) != "" ) {
		   dateObj.focus();
  			return false;
  		}
	}
   return true;
} // isDate



/*-------------------------- checkDataValue ------------------------*/
function checkDataValue(valGG, valMM, valYY, messDescr, messNumDays, messFebruary, messMonth, messYear, fullCondition){
   dataFormatted = "";
   if(valMM != "" && valGG != "" && valYY != "") {
      if (valGG > "31") { // more than 31 days
         alert (messDescr + " : "+ messNumDays );
         return dataFormatted;
      }
      if(valGG == "31") { // 31 days
         if(valMM == "04" || valMM == "06" || valMM == "09" || valMM == "11") {
            alert (messDescr + " : " + messNumDays );
            return dataFormatted;
         }
      }
      if(valMM == "02") { // feb with 28 days
         if (valGG > "29") {
            alert (messDescr + " : " + messNumDays );
            return dataFormatted;
         }
   	   // look if the number of days is 28 or 29 (leap year)
			var data = new Date(valYY, parseInt(valMM), 1);
         data = new Date(data - (24 * 60 * 60 * 1000));
         numDaysInMonth = data.getDate();
			if(parseInt(valGG) > parseInt("" + numDaysInMonth)) {
            alert (messDescr + " : " + messFebruary);
            return dataFormatted;
         }
      }
      // check the month
      if(valMM < "01" || valMM > "12") {
         alert (messDescr + " : " + messMonth);
         return dataFormatted;
      }
         
      if (fullCondition) {
        	// check the year only if fullCondition IS TRUE
      	if(valYY < "1900") {
         	alert (messDescr + " : " + messYear);
         	return dataFormatted;
      	}
      }
   }
   // returns the formatted data
   dataFormatted = valGG + "/" + valMM + "/" + valYY;
   return dataFormatted;
} // checkDataValue
  
/*-------------------------- adjustIFrameSize ------------------------*/
function adjustIFrameSize(iframeWindow) {
  if (iframeWindow.document.height) {
    var iframeElement = parent.document.getElementById(iframeWindow.name);
    iframeElement.style.height = iframeWindow.document.height + 'px';
    iframeElement.style.width = iframeWindow.document.width + 'px';
  }
  else if (document.all) {
    var iframeElement = parent.document.all[iframeWindow.name];
    if (iframeElement) {
	    if (iframeWindow.document.compatMode &&
	        iframeWindow.document.compatMode != 'BackCompat') 
	    {
	      iframeElement.style.height = iframeWindow.document.documentElement.scrollHeight + 'px';// + 5 + 'px';
	      iframeElement.style.width = iframeWindow.document.documentElement.scrollWidth + 'px';// + 5 + 'px';
	    }
	    else {
	      iframeElement.style.height = iframeWindow.document.body.scrollHeight + 'px';// + 5 + 'px';
	      iframeElement.style.width = iframeWindow.document.body.scrollWidth + 'px';// + 5 + 'px';
	    }
		 //move scrollbar to display window
		 parent.window.scrollTo(iframeWindow.screenLeft-iframeElement.style.pixelWidth,iframeWindow.screenTop-iframeElement.style.pixelHeight)
	}
  }
}

/*----------------------------- hideAdmin ----------------------------*/
function hideAdmin() {
	displayAdmin( window.name, "none", "none" );
}
  		  
/*----------------------------- showAdmin ----------------------------*/
function showAdmin( winName, noCover ) {
	displayAdmin( winName, "block", "none", noCover );
}

/*----------------------------- displayAdmin ----------------------------*/
function displayAdmin( winName, mode, modeInnerWin, noCover ) {

  if (winName == 'w3gAdminFrame') {

	   if (noCover==null || !noCover) {
		   // admin window blocks/releases browser page 
	  	   window.top.displayCover( 'Page', mode );
		   // admin window blocks/releases control panel
	  	   panel=window.open('','w3gPanel','height=1,width=1,status=no,toolbar=no,menubar=no,titlebar=no,scrollbar=no');
	  	   if (panel!=null)
		  	  try { panel.displayCover( 'Panel', mode ); } catch (e) { panel.close() }
	   }

	   window.parent.w3gAction.style.display=modeInnerWin;
	   window.parent.w3gList.style.display  =modeInnerWin;
	   window.parent.w3gAdmin.style.display =mode;

	   //reduce frame to 1x1 px, new content will resize window!  
	   hideFrame(window.parent.w3gActionFrame.window);
	   hideFrame(window.parent.w3gListFrame.window);
	   hideFrame(window.parent.w3gAdminFrame.window);
  }
  
  if (winName == 'w3gListFrame') {
	   window.parent.w3gAction.style.display=modeInnerWin;
	   window.parent.w3gList.style.display  =mode;
	   
	   hideFrame(window.parent.w3gActionFrame.window);
	   hideFrame(window.parent.w3gListFrame.window);
  }
  
  if (winName == 'w3gActionFrame') {
	   window.parent.w3gAction.style.display=mode;

  	   hideFrame(window.parent.w3gActionFrame.window);
  }	
  
  //2008.04.17@MV added w3gPanelFrame for added functionalities (for example w3gMap)
  if (winName == 'w3gPanelFrame') {
	   window.parent.w3gPanel.style.display=mode;

  	   hideFrame(window.parent.w3gPanelFrame.window);
  }	
}

/*---------------------------- hideFrame ------------------------------*/
function hideFrame (iframeWindow) {
  if (iframeWindow.document.height) {
    var iframeElement = parent.document.getElementById(iframeWindow.name);
    iframeElement.style.height = '1px';
    iframeElement.style.width = '1px';
  }
  else if (document.all) {
    var iframeElement = parent.document.all[iframeWindow.name];
    if (iframeWindow.document.compatMode &&
        iframeWindow.document.compatMode != 'BackCompat') 
    {
      iframeElement.style.height = '1px';
      iframeElement.style.width  = '1px';
    }
    else {
      iframeElement.style.height = '1px';
      iframeElement.style.width  = '1px';
    }
  }
}
/*2006.07.27@FV----------------------------- coverAdmin ----------------------------*/
coverStyleFilter="Alpha(Opacity=35, FinishOpacity=35, Style=2, StartX=50, StartY=50, FinishX=0, FinishY=0)"; 
function displayCover( name, status, msg ) {

	var cover = document.getElementById("w3g"+name+"Cover");
	var wait = document.getElementById("w3g"+name+"Wait");
	if (cover!=null) {
		if (status=='block') {
			try { // to extend cover to current window height&width.....
				cover.style.height= document.getElementById("w3gEndPage").offsetTop;
				cover.style.width= document.getElementById("w3gEndPage").offsetLeft;
			} catch (e) {}
			cover.style.filter = coverStyleFilter;
		}
		cover.style.display = status;
		//alert( "displayCover() w3g"+ name + "Cover = "+ status );
	}	
	if (wait!=null) {
		wait.style.display = status;
		//alert( "displayCover() w3g"+ name + "Wait = "+ status );
		if (msg!=null) wait.innerText = msg;
	}		
}
/*---------------------------- normalizeUTF8 ------------------------------*/
if (document.layers) { //in Netscape4 always filtered!
	window.captureEvents(Event.KEYPRESS);
	window.onkeypress = normalizeUTF8;
}
function normalizeUTF8( evt ) {
	wkc = (evt.which || evt.keyCode || evt.charCode);
	return (wkc<255)&&(wkc!=128);
}

/*2005.07.18@FV new--------------------------------- isEmail ------------------------------*/
function isEmail (s){
   if (s.length == 0) return (false);
   i = s.indexOf(" ");
   if (i > 0) return (false);
   indiceAt = s.indexOf("@");
   if (indiceAt <= 0) return (false);
   indiceUltimoPunto = s.lastIndexOf(".", s.length);
   if (indiceUltimoPunto <= 0) return (false);
   nomeDominio = s.substring((indiceAt+1), indiceUltimoPunto);
   if (!isDomainName(nomeDominio,1)) return (false);
   topLevelDomain = s.substring((indiceUltimoPunto+1), s.length);
   if (!isDomainName(topLevelDomain,2))  return (false);

   return (true);
}

/*2005.07.18@FV new------------------------------------- isDomainName ----------------------------*/
function isDomainName(checkStr, minLength){
  if (checkStr.length < minLength) return false;
  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-.";
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  return allValid;
}

/*2005.09.01@FV new------------------------------------- myInnerText ----------------------------*/
function myInnerText( xStr ) {
   var regExp = /<\/?[^>]+>/gi;
   xStr = xStr.replace(regExp,"");
   return xStr;
}

/*2006.07.18@FV new------------------------------------- set/get cookie ----------------------------*/
function getCookie( cookieName ) {
	var cookieJar = document.cookie.split( "; " );
	for( var x = 0; x < cookieJar.length; x++ ) {
		var oneCookie = cookieJar[x].split( "=" );
		if( oneCookie[0] == escape( cookieName ) ) { 
		return unescape( oneCookie[1] ); 
		}
	}
	return null;
}

function setCookie( cookieName, cookieValue, lifeTime, path, domain, isSecure ) {
	if( !cookieName ) { return false; }
	if( lifeTime == "delete" ) { lifeTime = -1; } //this is in the past. Expires immediately.
	/* document.cookie = newValue is equivalent to document.cookie = newValue + "; " + document.cookie; */
	document.cookie = escape( cookieName ) + "=" + escape( cookieValue ) +
		( lifeTime ? ";expires=" + ( new Date( ( new Date() ).getTime() + ( 1000 * lifeTime ) ) ).toGMTString() : "" ) +
		( path ? ";path=" + path : "") + ( domain ? ";domain=" + domain : "") + 
		( isSecure ? ";secure" : "");
	//check if the cookie has been set/deleted as required
	if( lifeTime < 0 ) { if( typeof( getCookie( cookieName ) ) == "string" ) { return false; } return true; }
	if( typeof( getCookie( cookieName ) ) == "string" ) { return true; } return false;
}

/*2006.07.18@FV new------------------------------------- hotkey check ----------------------------*/
function isJSHotKeyActive(){
	var fname=''+document.onkeypress;
	var hkfname='HotKey';
	if (fname==''||fname==null) return false;
	// recupera il nome della funzione dal corpo
	if(fname.substr(0,'function'.length).toLowerCase()=='function')
		fname=fname.substr('function'.length+1,fname.indexOf('(')-('function'.length+1));
	return fname==hkfname?true:false;
}

/*2007.04.23@FV new------------------------------------- tags visibility ----------------------------*/
function hideTags(elemID) {
	setTagsVisibility( elemID, "hidden" );
}
function showTags(elemID) {
	setTagsVisibility( elemID, "visible" );
}
function setTagsVisibility(elemID, status) {
	 if (window.document.all) {
	   for (i = 0; i < document.all.tags(elemID).length; i++) {
		obj = document.all.tags(elemID)[i];
		if (! obj || ! obj.offsetParent) {alert(i + ' skipped');continue;}
		obj.style.visibility = status;
	   }
	 }	
	 if (parent.frames["result_set"]!=null) {   
	   for (i = 0; i < result_set.document.all.tags(elemID).length; i++) {
		 obj = result_set.document.all.tags(elemID)[i];
		 if (! obj || ! obj.offsetParent) 
		 	continue;
		 obj.style.visibility = status;
	   }
	 }
}
/*2007.05.15@FV ----------------------------- WAI facility ------------------*/
/*
function adjustOpenPopAnchorTitle() {
try {
   if (waiOpenPopKeywords && waiOpenPopAlert && waiOpenPopAttachment) {
	 if (window.document.getElementsByTagName) {
	   var anchors = window.document.getElementsByTagName("A");
	   for (i = 0; i < anchors.length; i++) {
		var obj = anchors[i];
		if (! obj || ! obj.offsetParent) continue;
		if ((obj.href.indexOf("openPop(")>0) && 
			(obj.title.length==0 || waiOpenPopKeywords.indexOf(obj.title)<0)) { //not already set via cms
			var txt="";
			if (obj.href.indexOf("media/show")>0) //link to an attachment
				txt = waiOpenPopAttachment;
			else
				txt = waiOpenPopAlert;
			obj.title = (obj.title.length>0) ? obj.title+". "+txt : txt;
		}
	   }
	 }	
   }
}catch (e) {}
}
*/
/*2007.05.15@FV ----------------------------- WAI facility ------------------*/
function w3gFixBadAnchorsAttributes() {
	try {
		 if (window.document.getElementsByTagName) {
		   var anchors = window.document.getElementsByTagName("A");	   
		   for (i = 0; i < anchors.length; i++) {
		   	 var obj = anchors[i];
		   	 if (! obj || ! obj.offsetParent) continue;
		   	 w3gAdjustOpenPopAnchorTitle(obj);
		   	 w3gExternalAnchorURLWrapping(obj);	
		   	 w3gApplyContexRootToAnchorURL(obj);	
		   	 
		   	 /*2008.02.05@MV esegue altre funzioni dichiarate all'interno dell'array di funzioni
		   	 w3gAnchorFunctionArray dichiarato all'intero del media
		   	 */
		   	 if(typeof(w3gAnchorFunctionArray)!='undefined'){
		   	 	if(w3gAnchorFunctionArray!=null)
		   	 		for(j=0;j<w3gAnchorFunctionArray.length;j++)
      					w3gAnchorFunctionArray[j](obj);
      		}
             	 		 			
		   }	
	   	}
	}catch (e) {/*alert(e)*/
	}
}

function w3gAdjustOpenPopAnchorTitle(obj){
	if(w3gUtils.Undefined(obj))return;	
	try {	
	  var w3gSN = location.host;
	  var w3gCTX = "/" + window.w3gContex;
      if (waiOpenPopKeywords && waiOpenPopAlert && waiOpenPopAttachment) {	   
			//if (! obj || ! obj.offsetParent) continue;
			if ((obj.href.indexOf("openPop(")>=0) && 
				(obj.title.length==0 || waiOpenPopKeywords.indexOf(obj.title)<0)) { //not already set via cms
					var txt="";
					if (obj.href.indexOf("media/show")>=0) //link to an attachment
						txt = waiOpenPopAttachment;
					else
						txt = waiOpenPopAlert;
					obj.title = (obj.title.length>0) ? obj.title+". "+txt : txt;
			}
   	  }
  } catch(e) {/*alert(e)*/} 
}

function w3gExternalAnchorURLWrapping(obj) {
	if(w3gUtils.Undefined(obj))return;
	var original_href = obj.href;			  		  
  	try {		 
  		var w3gSN = location.host;
  		var w3gCTX = "/" + window.w3gContex;   
		var href_lower = obj.href.toLowerCase();
		if ((href_lower.indexOf("http://")>=0 || href_lower.indexOf("https://")>=0) && obj.href.indexOf(w3gSN)<0) {
		 /*2007.07.21@IV redraw external links for redirect*/
			var new_href = obj.href;
			if (href_lower.indexOf("javascript")>=0) {
		 		var my_href = new_href;
	  			new_href = my_href.substring(0,my_href.indexOf("'")+1);
	  			my_href = my_href.slice(my_href.indexOf("'")+1);
	  			new_href = new_href + escape(my_href.substring(0,my_href.indexOf("'"))) + my_href.slice(my_href.indexOf("'"));  		
		  	} else {
		  		new_href = escape(obj.href);  		
		  	}
		  	//obj.href = new_href.replace(new RegExp("http","i"),"externalUrl.jsp?url=http");
	  	} else {
		  	/*2007.07.21@IV redraw internal links for media*/
		    if (obj.href.indexOf("openPop")>=0 && obj.href.indexOf("media/show?")>=0)
	    		obj.href = obj.href.replace("media/show?","popupMedia.do?id=");  
				/*if (obj.href.indexOf("openPop('media/show?")>=0 
		   			|| obj.href.indexOf('openPop("media/show?')>=0 
		   			|| obj.href.indexOf("openPop('"+ w3gCTX +"/media/show?")>=0
		   			|| obj.href.indexOf('openPop("'+ w3gCTX +'/media/show?')>=0) {
		   				obj.href = obj.href.replace("media/show?","popupMedia.do?id=");*/			  
		}
   } catch(e) {obj.href=original_href;}
}

function w3gApplyContexRootToAnchorURL(obj) {
	if(w3gUtils.Undefined(obj))return;
	try {
	 	var w3gSN = location.host;
  	 	var w3gCTX = "/" + window.w3gContex; 	  		  
   	  	var original_href = w3gUtils.Undefined(obj.getAttribute('href'))?null:obj.getAttribute('href');	
	  	var openPopRegExp = new RegExp("(javascript(?: )?:(?: )?openPop(?: )?\\((?: )?')","i");
   	  	if(w3gUtils.Nullalize(original_href)!=null){
 	 		var new_href = w3gUtils.Trim(original_href);
     	 	var lnew_href=  new_href.toLowerCase();
     	 	if(lnew_href.indexOf('/')!=0
	     	 	&& lnew_href.indexOf('javascript:')<0
	     	 	&& lnew_href.indexOf('#')!=0
	     	 	&& lnew_href.indexOf('http:')!=0
	     	 	&& lnew_href.indexOf('https:')!=0	
	     	 	&& lnew_href.indexOf('mailto:')<0	 			
 	 		){
   	 	 		new_href = w3gCTX+'/'+ new_href;
	   	 	 	obj.setAttribute('href',new_href);		   	 	 	
	     	 }else if(
	     	 	new_href.match(openPopRegExp)&&
	     	 	(!new_href.match(new RegExp("'( )?http",'i')))&&
				(!new_href.match(new RegExp("'( )?/",'i')))
	     	 ){
	     	 	new_href = new_href.replace(openPopRegExp,'$1'+w3gCTX+'/')		     	 	
	     	 	obj.removeAttribute('href');
	   	 	 	obj.setAttribute('href',new_href);		   	 	 		     	 
	     	 }
     	}
	}catch(e){/*alert(e)*/} 
}


/*2008.02.05@MV Funzione per la generazione di Help balloons da associare alle chiamate al Wrapper */
var w3gWrapperCalled=0;
var w3gHelpBalloons=new Array();

function w3gAdjustWrapperUrl(obj) {
	  try {
	    var href = obj.href;
	    if (href.indexOf("W3GWrapper?W3GAction=help")>=0) {
		    //trova la prima occorrenza del carattere '
		    var indexOfWrapperUrl = href.indexOf("'");
		    var wrapperUrl = href.substring(indexOfWrapperUrl+1);
		    //trova la seconda occorrenza del carattere '
		    var indexOfLastChar = wrapperUrl.indexOf("'");
		    // estrae l'url della chiamata al wrapper
		    wrapperUrl = wrapperUrl.substring(0,indexOfLastChar);
		    // associa una id incrementale all'ancora (per poterci associare un evento)
		    obj.id='w3gHelpBalloon'+w3gWrapperCalled;
		      
		    //trova il titolo di default
		    var patternForTitleStart = "W3GAction=";
		    var patternForTitleEnd = "\&";
		     
		    var indexForTitleStart = wrapperUrl.indexOf(patternForTitleStart);
		    var indexForTitleEnd = wrapperUrl.indexOf(patternForTitleEnd);
		    var title = wrapperUrl.substring(indexForTitleStart+patternForTitleStart.length,indexForTitleEnd); 
		    // estrae l'url della chiamata al wrapper
		    wrapperUrl = wrapperUrl.substring(0,indexOfLastChar);

            if(typeof(w3gCostumizedHelpBalloon)=='function') {
                // deve essere definita la funzione w3gCostumizedHelpBalloon nella quale passare tutti
                // i parametri necessari alla generazione dell'help balloons (si veda esempio helpBalloons.js)
                w3gWrapperCalled++;
                w3gHelpBalloons[obj.id] = w3gCostumizedHelpBalloon(obj.id, title, wrapperUrl);
		    	obj.href="javascript: void(0);";  
		    	obj.title = title;
		    }
	   }	     
	 } catch(e) {/*alert(e)*/} 
}


onloadAddFunction(w3gFixBadAnchorsAttributes);



//-------------------------------------------------------------------------------------------
//------------------------------Prototype Extensions ----------------------------------------
//-------------------------------------------------------------------------------------------


/**
 2008.04.02@FC
 estensione di Element(prototype) che descrive un elementdo del DOM
 per rendere disponibili in esso metodi per nascondere le select sottostanti in IE <7.x
*/

if( typeof Prototype != 'undefined' ){ // Extend object ONLY if prototy.js is included
Object.extend(Element,{
	needOverlappingFix: (/Explorer/.test(navigator.appName)  && !/MSIE 7/.test(navigator.appVersion)) || /Opera/.test(navigator.appName) || /Safari/.test(navigator.appVersion)
});
Element.addMethods({
	overlappedChache:
		function(element,chace){
		element = $(element);
		if(!element._overlappedChache){
			element._overlappedChache = [];
		}
		if(chace)
			element._overlappedChache= chace;
		return element._overlappedChache;
	}
	,
	onTopPosition: function(obj){		
		var pos = Position.cumulativeOffset(obj)
		var y = parseInt(pos[1]);
		var x = parseInt(pos[0]);
		var dim = obj.getDimensions();
		var w = parseInt(dim.width);
		var h = parseInt(dim.height);		
		var x2 = x + w;
		var y2 = y + h;
		/*if(obj.id=='w3gDOMConsole')
			$LOG('x:'+x+' y:'+y+', w:'+w+' h:'+h);*/
		return {'x':x, 'y':y, 'x2':x2, 'y2':y2 , 'w':w, 'h':h};

	},
	/**
	* Determina se obj è figlio di element
	* @param {Element} obj
	* @param {Element} element << metodize in Element instance (es: nomeVar.isChild(obj); )
	*/
	isChild: function(element,obj)
	{		
		element = $(element);
		var i = 15;
		do{
			if(obj == element) return true;
			obj = obj.parentNode;
		}while(obj && i--);
		return false
	},
	/**
	* Determina se l'element è sopra obj
	* @param {Element} obj
	* @param {Element} element << metodize in Element instance (es: nomeVar.isOver(obj); )
	*/
	isOver: function(element,obj){ 
		element = $(element);
		obj = $(obj);
		if(element.isChild(obj)) return false;		
		var a = obj.onTopPosition();		
		var b = element.onTopPosition();		
		//2008.04.09@FC FIX isOver algorithm
		return  ( 
			( a.w!=0 && a.h!=0 && b.w!=0 && b.h!=0 )
			&&			 
		 	( Math.abs(a.x - b.x) <= a.w || Math.abs(a.x - b.x) <= b.w ) 
		 	&&
		 	( Math.abs(a.y2 - b.y2) <= a.h || Math.abs(a.y2 - b.y2) <= b.h )			 
			&& 			
			( Math.abs(a.y - b.y) <= a.h || Math.abs(a.y - b.y) <= b.h ) 
			&&
			( Math.abs(a.x2 - b.x2) <= a.w || Math.abs(a.x2 - b.x2) <= b.w ) 
			
		);
		
	},
	showLowerElements: function(element){
		element = $(element);		
		if (Element.needOverlappingFix){				
			var elements = element.overlappedChache();	
			//if(elements.length>0)$ERR(element.id +" "+elements);	
			for(var i = 0; i < elements.length; i++){			
				
				if(elements[i].style.visibility != 'visible' && elements[i].hiddenBy == element){
					elements[i].style.visibility = 'visible';
					elements[i].hiddenBy = null;
					if(elements[i].mask)
						elements[i].mask.hide();						
				}
				
			}
			element.overlappedChache([]);			
		}
		
		return element;		
	},
	hideLowerElements: function(element){ 
		element = $(element);		
		if (Element.needOverlappingFix){
			var elements = element.weirdAPIElements();	
			var elChache = element.overlappedChache();	
			var tt = 0;
			//Vanilla loop optimization
			for(var j = 0; len = elements.length, j < len; ++j)
			{
				var item = elements[j];
				if(item.style.display!='none' && item.style.visibility !='hidden'){
					item.style.visibility = 'hidden';
					item.hiddenBy = element;
					item.maskSelect();										
					elChache.push(item);					
				}
			}				
			element.overlappedChache(elChache);
			
		}				
		return element;
	},
	maskSelect:function(element){
		element = $(element);
		var _mask=element.mask;		
		if(!_mask){
			_mask = document.createElement('DIV');
			_mask.setAttribute('class', 'selectMask');
			_mask.setAttribute('align', 'left');
			_mask.className='selectMask';
			_mask.style.cursor= 'not-allowed';
			_mask.innerHTML = "&nbsp;&nbsp;---";				
			element.parentNode.appendChild(_mask);
			_mas = Position.absolutize(_mask);						
			element.mask = _mask;			
		}		
		Position.clone(element, _mask);	
		if(_mask.style.width)
			_mask.style.width=(parseInt(_mask.style.width)-2)+'px';
		if(_mask.style.height)
		_mask.style.height=(parseInt(_mask.style.height)-2)+'px';				
		_mask = element.mask;		
		_mask.show();
		element.mask=_mask;
		return element;
	},
	weirdAPIElements: function(element){ 
	    if (Element.needOverlappingFix){ // Se il browser è MSIE diverso dal 7.x o Opera o Safari		    
			element = $(element);	
			var elements = [];
			var e = document.getElementsByTagName('select');
			//Vanilla loop optimization
			for(var j = 0; len = e.length, j < len; ++j)
			{
				var current = e[j];				
				if(element.isOver(current))elements.push(current);
			}
			return elements;
		} else return [];
	},
	/**
		Metodo hide definito in prototype js
	*/
	originalHide: Element.Methods.hide
	,
	/**
		wrapping del metodo hide di un elemento del DOM
		che riprostina la visibilità delle eventuali select 
		nascoste da hideOverlappedSelect
	*/	
	overlappedReleaseHide: function(element){
		element = $(element)
		if (Element.needOverlappingFix){					
			element.showLowerElements();
			element.originalHide();
			element.hide = element.originalHide;			
		}
		return element;
	},
	/*
		IE < 7.x FIX nasconde le select che si sovrappongono ad un elemento del DOM
		e wrappa il metodo hide() dell'elemento per far si che venga anche 
		ripristinata la visibilità delle select nascoste.
	*/
	hideOverlappedSelect: function(element) {
		element = $(element)		
		if (Element.needOverlappingFix){
			element.hideLowerElements();	
			
		   	if( element.overlappedChache().length > 0 ){
		   		element.hide=element.overlappedReleaseHide;
		   		
		   	}
		   
	   	}	   
	   	return element;
  	},
  	/*
		IE < 7.x FIX nasconde le select che si sovrappongono ad un elemento del DOM
		e wrappa il metodo hide() dell'elemento per far si che venga anche 
		ripristinata la visibilità delle select nascoste.
	*/
	showOverlappedSelect: function(element) {
		element = $(element)
		if (Element.needOverlappingFix){			
		   	element.showLowerElements();
		   	element.hide = element.originalHide;		   
	   	}
	   	return element;
  }    
});
}//END IF Element present

//2008.04.28@FC get the current viewport on user browser.
window.viewportDimensions= function() {
    var intH = 0, intW = 0;
        
    if(self.innerHeight) {
       intH = window.innerHeight;
       intW = window.innerWidth;
    } 
    else if(document.documentElement && document.documentElement.clientHeight) {
            intH = document.documentElement.clientHeight;
            intW = document.documentElement.clientWidth;
    }
    else if(document.body) {
            intH = document.body.clientHeight;
            intW = document.body.clientWidth;
    }
    return {
        height: parseInt(intH, 10),
        width: parseInt(intW, 10)
    };
}
//2008.04.28@FC get user's screen resolution.
window.screenDimensions= function() {
    var intH = 0, intW = 0;
    if(window.screen) {
	    intH = window.screen.height;
		intW = window.screen.width;
	}
    return {
        height: parseInt(intH, 10),
        width: parseInt(intW, 10)
    };
}



