wwwroot = "../";

//var cookieName= "CPIshortCutList";

function saveShortCut(param){
	//il cookie shortCut è formattato: pageTitle:pageUrl|...
	//cookieName = cookieName;
	if (isCookieEnabled()){
		var pageNameArray=new Array("");
		var pageUrlArray=new Array("");
		shortCutHash = readArrayShortCut(param);
		
		var ind = location.search.indexOf("&");
		var titolo = location.search.substr(1, ind-1), url = location.search.substr(ind+1);
		var tempTitle = new Array(titolo), tempUrl = new Array(url);
		titolo=titolo.replace("<BR>"," ");
		
		if (shortCutHash==null){
			//non sono state ancora salvate scorciatoie
			var shortCutHash=new Array(2);		
			shortCutHash[0] = tempTitle;
			shortCutHash[1] = tempUrl;
		}
		else {
			//verifico la presenza di doppioni e sovrascrivo.
			for (var i=0; i<shortCutHash[0].length; i++)
			{
				if (shortCutHash[0][i] == titolo || shortCutHash[1][i] == url)
				{
					shortCutHash[0][i] = titolo;
					shortCutHash[1][i] = url;
					break;
				}
			}
			//aggiungo la pagina corrente
			if (i == shortCutHash[0].length) {
				shortCutHash[0] = tempTitle.concat(shortCutHash[0]);
				shortCutHash[1] = tempUrl.concat(shortCutHash[1]);
			}
		}			
		saveArrayShortCut(shortCutHash);
		document.write(sScorciatoiaSalvata);
	}
	else document.write(sCookieNonAbilitati);
}

function isCookieEnabled(){
	saveCookie("provaCookie","true");
	val = readCookie("provaCookie");
	return val=="true";
}

function resetLayout(){
	xRel = pageX(MM_findObj('inizio'));
	if(location.href.indexOf('menu.aspx')>=0) home = false;
	l = location.toString().toLowerCase();
	if( l.indexOf('boutenti.aspx')<0 && l.indexOf('utenti.aspx?')<0){
		if(home){
			MM_findObj('shortCuts').style.left = xRel;
		}
	}
}

function writeShort(param){
	linkStr= ""; 
	linkStr += (home)?"<a href='javascript:enableShortLayer();void(0);' onclick=''><img src='../img/short_"+lingua+".gif' alt='scorciatoie' width='225' height='12' border='0'></a>" : "<a href='javascript:scorciatoie(\""+param+"\")'><img src='../img/addshort_"+lingua+".gif' alt='' width='225' height='18' border='0'></a>";
	if(!home) return linkStr;
	linkStr += "<div id='shortCuts' style=\"visibility:hidden;position:absolute; top:0px;\">";
	linkStr += writeShortCutTable(162, param);
	linkStr += "</div>";
	return linkStr;
}

function writeShortAcc(param){
	linkStr= ""; 
	linkStr += "<a href='javascript:enableShortLayer();void(0);' onclick=''><img src='../img/short_"+lingua+".gif' alt='scorciatoie' width='95' height='14' border='0'></a>";
	linkStr += "<div id='shortCuts' style=\"visibility:hidden;position:absolute; top:40px;\">";
	linkStr += writeShortCutTable(96, param);
	linkStr += "</div>";
	return linkStr;	
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function scorciatoie(param) {
	cUrl = wwwroot+"pagine/scorciatoie.html?"+scriviVoce()+"&"+escape(document.location.href)+"&param="+param;
	
    open(cUrl,"","left="+ (screen.availWidth-300)/2 +",top="+ (screen.availHeight-100)/2 +",width=300,height=100,scrollbars=no");
}

function readArrayShortCut(param){
//restituisce un array bidimensionale: 0:pageName :: 1:pageURL
	var shortCutHash=new Array();
	var pageNameArray=new Array("");
	var pageUrlArray=new Array("");

	tempCookieVal=readCookie(param);
	
	if (tempCookieVal && tempCookieVal!="")
	{
		tempCookieArray=tempCookieVal.split(itemDelimiter);
		for (var i=0; i<tempCookieArray.length; i++)
		{
			tempStrArray=tempCookieArray[i].split(delimiter);
			pageNameArray[i]=tempStrArray[0];
			pageUrlArray[i]=tempStrArray[1];
			
		}
		shortCutHash[0]=pageNameArray;
		shortCutHash[1]=pageUrlArray;		
		return shortCutHash;
	}
	
	return null;
}

var home = ( (location.toString().toLowerCase().indexOf("home")>-1) || (location.toString().toLowerCase().indexOf("id=")==-1) );



function scriviVoce (menu) {
var paginaTitolo = document.title;
  if (home) return "Home";
  if (arguments.length==0) {
    if (paginaTitolo!="") return paginaTitolo;
    /*if (supporto!="") return supporto;*/
    /*menu = p;*/
  }
  /*if (supporto!="") return supporto;
  if (menu=="") return "";*/
  m = 0;
  for (k=0;k<menu.length;k++) {
    n = 0;
	for (j=0;j<m;j++) n+=linksPos[k][j];
    n += parseInt(menu.charAt(k));
    m = n;
  }
  return voci[k-1][m];
}

function creaLink (cLink) {
  if (cLink.indexOf("http://")!=-1) return cLink;
  if (cLink.indexOf(".gif")!=-1 || cLink.indexOf(".jpg")!=-1) return wwwroot + "img/" + cLink.replace(/ /g,"").replace(/'/g, "");
  return wwwroot +"pagine/pagina.aspx?ID="+ cLink +"&L="+ lingua;
}

function winOpen(arg,size) {
  open(arg,'',size);
}

function popUp(ref, width, height){
window.open(""+ref+"",null,
    "height="+height+",width="+width+",status=no,toolbar=no,menubar=no,location=no,scrollbars=yes");

}

function motoreRicAr(){
	var str = "";
	str +=	"<table cellpadding='0' cellspacing='0' border='0' bgcolor='#FFFFFF'><tr>"+
			"<td align=right class='header' width='40'>|&nbsp;&nbsp;"+sCerca+"&nbsp;&nbsp;</td>"+
			"<td align='right' width=100><input type='Text' id='cerca'></td>"+
			"<td align=right width=21><input id='cercaB' type='image' onmouseover=\"MM_swapImage('ms_Cerca','','"+creaLink("ms_"+ sCerca +"_.gif")+"','b_frecciaC','','"+creaLink("b_freccia_.gif")+"')\" onmouseout=\"MM_swapImgRestore()\" name='b_frecciaC' src='"+creaLink("b_freccia.gif")+"' alt='"+ sCerca +"' style='border-width:0px;height:15px;width:15px;'><script>inizCerca('cerca',0)</script></td>"+
			"</tr></table>"
	document.write(str);
}


function motoreRic(){
	var str = "";
	str +=	"<table cellpadding='0' cellspacing='0' border='0' bgcolor='#FFFFFF'><tr>"+
			"<td align=right class='header' width='40'>|&nbsp;&nbsp;"+sCerca+"&nbsp;&nbsp;</td>"+
			"<td align='right' width=100><input type='Text' id='cerca'></td>"+
			"<td align=right width=21><input id='cercaB' type='image' onmouseover=\"MM_swapImage('ms_Cerca','','"+creaLink("ms_"+ sCerca +"_.gif")+"','b_frecciaC','','"+creaLink("b_freccia_.gif")+"')\" onmouseout=\"MM_swapImgRestore()\" name='b_frecciaC' src='"+creaLink("b_freccia.gif")+"' alt='"+ sCerca +"' style='border-width:0px;height:15px;width:15px;'><script>inizCerca('cerca',2)</script></td>"+
			"</tr></table>"
	document.write(str);
}


function versioneStampabile(){
  var str = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"><html><head><title>"+ document.title +"</title>"+
  		"<link href='"+wwwroot+"style/css.css' rel='stylesheet' type='text/css'>"+
  		"<link href='"+wwwroot+"style/custom-styles.css' rel='stylesheet' type='text/css'>"+
  		"<style type='text/css'>BODY {margin:10;background-color:#FFFFFF}</style>"+
  		"</head><body>"+	
		MM_findObj("LayoutTemplate_paneldx").innerHTML +"<br>"+
		"</body></html>";

  win2 = open();
  win2.document.open();
  win2.document.write(str);
  win2.document.close();
}

function cercaOnC(elem, cat) {
  var valore = MM_findObj(elem).value;
  if (valore!="")
  {
	var cercaTipoGoogle = MM_findObj("cercaTipoGoogle");
	if (cercaTipoGoogle && cercaTipoGoogle.checked) location = "http://www.google.it/search?hl=it&q="+ valore;
	else location = "pagina.aspx?ID=ricerca001&L=IT"+"&CERCA="+ valore + (cat!=-1? "&CAT="+cat: "");
  }
}

function cercaOnF(elem, cat){
  document.forms[0].onsubmit= new Function("cercaOnC('"+elem+"',"+ cat +"); return false;");
}

function inizCerca(elemId, cat) {
  if (arguments.length==1) cat=-1;
  var elem = MM_findObj(elemId);
  elem.onfocus = new Function("cercaOnF('"+ elemId +"',"+ cat +")");
  elem.onblur = new Function ("document.forms[0].onsubmit=null");
  elem = MM_findObj(elemId+"B");
  elem.onclick = new Function("cercaOnC('"+ elemId +"',"+ cat +"); return false");
}

classe = "menu3";
var cookieExpiresDays = 365;
var itemDelimiter="-|-";
var delimiter="-!-";
var timerID=null;

if (typeof(lingua)=="undefined") {
  var lin = location.href.indexOf("%26L%3D");
  lingua = lin==-1? "IT": location.href.substr(lin+7,2);
  document.write("<script src='../script/"+ lingua +"parLingua.js'><\/script>");
}


if (home && !readCookie("cookieReserved"))
{
	//alert('msg');
	var shortCutHashPriv=new Array(2);		
	  shortCutHashPriv[0] = new Array("Area Riservata");
	  shortCutHashPriv[1] = new Array("pagina.aspx?ID=Home_Ar003&L=IT");

	var cookieStrPriv = "";
	for (var i=0; i<shortCutHashPriv[0].length; i++)
	{
		cookieStrPriv += escape(shortCutHashPriv[0][i]) + delimiter + escape(shortCutHashPriv[1][i]);
		if (i==(shortCutHashPriv[0].length-1)) break;
		cookieStrPriv += itemDelimiter;
	}
	saveCookie("cookieReserved" , cookieStrPriv , cookieExpiresDays);
}

if (home && !readCookie("cookiePublic"))
{
	var shortCutHashPubb=new Array(2);		
	  shortCutHashPubb[0] = new Array("Home Page");
	  shortCutHashPubb[1] = new Array("pagina.aspx?ID=Home&L=IT");

	var cookieStrPubb = "";
	for (var i=0; i<shortCutHashPubb[0].length; i++)
	{
		cookieStrPubb += escape(shortCutHashPubb[0][i]) + delimiter + escape(shortCutHashPubb[1][i]);
		if (i==(shortCutHashPubb[0].length-1)) break;
		cookieStrPubb += itemDelimiter;
	}
	saveCookie("cookiePublic" , cookieStrPubb , cookieExpiresDays);
}



function quitShortLayer(arg){
	if (arg) timerID=setTimeout('enableShortLayer()',300);
	else clearTimeout(timerID);
}

function writeShortCutTable(W, param){
	shortCutHash = readArrayShortCut(param);
	var maxShort=5;
	
	if (shortCutHash!=null)
	{
		var myLayer = "<table width=\""+W+"\" border=\"0\" cellspacing=\"1\" cellpadding=\"0\" bgColor=\"white\">";
		for (var i=0; i<shortCutHash[0].length; i++ ){
			loc=unescape(shortCutHash[1][i]);
			pgN=unescape(shortCutHash[0][i]).replace("<BR>"," ");
			myLayer += "\n<tr><td onmouseover=\"quitShortLayer(false);this.className='scorciatoieOn'\" onmouseout=\"quitShortLayer(true);this.className='scorciatoie'\" onclick=\"window.location='"+loc+"'\" class='scorciatoie' style=\"padding-left:4px;padding-right:4px;\"><a href=\""+loc+"\" style=\"line-height:12px;\">"+ pgN +"</a></td></tr>";
			if (i==maxShort-1) break;
		}
		myLayer +="\n</table>\n";
		return myLayer;
	}
	else return "";
}

var isShortCutsVisible = false;

function enableShortLayer(){	
  if(isShortCutsVisible) {
    MM_showHideLayers('shortCuts','','hide');
  }
  else {
    MM_showHideLayers('shortCuts','','show');
  }
  isShortCutsVisible= !isShortCutsVisible;
}


function saveArrayShortCut(shortCutHash){
	var cookieStr = "";
	for (var i=0; i<shortCutHash[0].length ; i++)
	{
		cookieStr += shortCutHash[0][i] + delimiter + shortCutHash[1][i];
		if (i==(shortCutHash[0].length-1)) break;
		cookieStr += itemDelimiter;
	}
	saveCookie("cookieReserved" , cookieStr , cookieExpiresDays);
	saveCookie("cookiePublic" , cookieStr , cookieExpiresDays);
}

function getUrlBox(param){
var obj = param.childNodes[0].childNodes[1].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].getAttribute('href');
	
	if(obj != null){
		var rel = obj;		
	}else{
		var rel = '#';
	}
	
return rel;
}

function getImgBox(param, status){
var obj = param.childNodes[0].childNodes[1].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[1].childNodes[0];
if (status != true)
{
	obj.src = "../img/arr.gif";
}
else{
	obj.src = "../img/arr_on.gif";
}
}

// Title: Tigra Calendar
// URL: http://www.softcomplex.com/products/tigra_calendar/
// Version: 3.2 (European date format)
// Date: 10/14/2002 (dd/mm/yyyy)
// Feedback: feedback@softcomplex.com (specify product title in the subject)
// Note: Permission given to use this script in ANY kind of applications if
//    header lines are left unchanged.
// Note: Script consists of two files: calendar?.js and calendar.html
// About us: Our company provides offshore IT consulting services.
//    Contact us at sales@softcomplex.com if you have any programming task you
//    want to be handled by professionals. Our typical hourly rate is $20.

// if two digit year input dates after this year considered 20 century.
var NUM_CENTYEAR = 30;
// is time input control required by default
var BUL_TIMECOMPONENT = false;
// are year scrolling buttons required by default
var BUL_YEARSCROLL = true;

var calendars = [];
var RE_NUM = /^\-?\d+$/;

function calendar1(obj_target) {

	// assing methods
	this.gen_date = cal_gen_date1;
	this.gen_time = cal_gen_time1;
	this.gen_tsmp = cal_gen_tsmp1;
	this.prs_date = cal_prs_date1;
	this.prs_time = cal_prs_time1;
	this.prs_tsmp = cal_prs_tsmp1;
	this.popup    = cal_popup1;

	// validate input parameters
	if (!obj_target)
		return cal_error("Error calling the calendar: no target control specified");
	if (obj_target.value == null)
		return cal_error("Error calling the calendar: parameter specified is not valid tardet control");
	this.target = obj_target;
	this.time_comp = BUL_TIMECOMPONENT;
	this.year_scroll = BUL_YEARSCROLL;
	
	// register in global collections
	this.id = calendars.length;
	calendars[this.id] = this;
}

function cal_popup1 (str_datetime) {
	this.dt_current = this.prs_tsmp(str_datetime ? str_datetime : this.target.value);
	if (!this.dt_current) return;

	var obj_calwindow = window.open(
		'calendar.html?datetime=' + this.dt_current.valueOf()+ '&id=' + this.id,
		'Calendar', 'width=200,height='+(this.time_comp ? 215 : 190)+
		',status=no,resizable=no,top=200,left=200,dependent=yes,alwaysRaised=yes'
	);
	obj_calwindow.opener = window;
	obj_calwindow.focus();
}

// timestamp generating function
function cal_gen_tsmp1 (dt_datetime) {
	return(this.gen_date(dt_datetime) /* + ' ' + this.gen_time(dt_datetime) */);
}

// date generating function
function cal_gen_date1 (dt_datetime) {
	return (
		(dt_datetime.getDate() < 10 ? '0' : '') + dt_datetime.getDate() + "/"
		+ (dt_datetime.getMonth() < 9 ? '0' : '') + (dt_datetime.getMonth() + 1) + "/"
		+ dt_datetime.getFullYear()
	);
}
// time generating function
function cal_gen_time1 (dt_datetime) {
	return (
		(dt_datetime.getHours() < 10 ? '0' : '') + dt_datetime.getHours() + ":"
		+ (dt_datetime.getMinutes() < 10 ? '0' : '') + (dt_datetime.getMinutes()) + ":"
		+ (dt_datetime.getSeconds() < 10 ? '0' : '') + (dt_datetime.getSeconds())
	);
}

// timestamp parsing function
function cal_prs_tsmp1 (str_datetime) {
	// if no parameter specified return current timestamp
	if (!str_datetime)
		return (new Date());

	// if positive integer treat as milliseconds from epoch
	if (RE_NUM.exec(str_datetime))
		return new Date(str_datetime);
		
	// else treat as date in string format
	var arr_datetime = str_datetime.split(' ');
	return this.prs_time(arr_datetime[1], this.prs_date(arr_datetime[0]));
}

// date parsing function
function cal_prs_date1 (str_date) {

	var arr_date = str_date.split('/');

	if (arr_date.length != 3) return cal_error ("Invalid date format: '" + str_date + "'.\nFormat accepted is dd/mm/yyyy.");
	if (!arr_date[0]) return cal_error ("Invalid date format: '" + str_date + "'.\nNo day of month value can be found.");
	if (!RE_NUM.exec(arr_date[0])) return cal_error ("Invalid day of month value: '" + arr_date[0] + "'.\nAllowed values are unsigned integers.");
	if (!arr_date[1]) return cal_error ("Invalid date format: '" + str_date + "'.\nNo month value can be found.");
	if (!RE_NUM.exec(arr_date[1])) return cal_error ("Invalid month value: '" + arr_date[1] + "'.\nAllowed values are unsigned integers.");
	if (!arr_date[2]) return cal_error ("Invalid date format: '" + str_date + "'.\nNo year value can be found.");
	if (!RE_NUM.exec(arr_date[2])) return cal_error ("Invalid year value: '" + arr_date[2] + "'.\nAllowed values are unsigned integers.");

	var dt_date = new Date();
	dt_date.setDate(1);

	if (arr_date[1] < 1 || arr_date[1] > 12) return cal_error ("Invalid month value: '" + arr_date[1] + "'.\nAllowed range is 01/12.");
	dt_date.setMonth(arr_date[1]-1);
	 
	if (arr_date[2] < 100) arr_date[2] = Number(arr_date[2]) + (arr_date[2] < NUM_CENTYEAR ? 2000 : 1900);
	dt_date.setFullYear(arr_date[2]);

	var dt_numdays = new Date(arr_date[2], arr_date[1], 0);
	dt_date.setDate(arr_date[0]);
	if (dt_date.getMonth() != (arr_date[1]-1)) return cal_error ("Invalid day of month value: '" + arr_date[0] + "'.\nAllowed range is 01-"+dt_numdays.getDate()+".");

	return (dt_date)
}

// time parsing function
function cal_prs_time1 (str_time, dt_date) {

	if (!dt_date) return null;
	var arr_time = String(str_time ? str_time : '').split('.');

	if (!arr_time[0]) dt_date.setHours(0);
	else if (RE_NUM.exec(arr_time[0])) 
		if (arr_time[0] < 24) dt_date.setHours(arr_time[0]);
		else return cal_error ("Invalid hours value: '" + arr_time[0] + "'.\nAllowed range is 00-23.");
	else return cal_error ("Invalid hours value: '" + arr_time[0] + "'.\nAllowed values are unsigned integers.");
	
	if (!arr_time[1]) dt_date.setMinutes(0);
	else if (RE_NUM.exec(arr_time[1]))
		if (arr_time[1] < 60) dt_date.setMinutes(arr_time[1]);
		else return cal_error ("Invalid minutes value: '" + arr_time[1] + "'.\nAllowed range is 00-59.");
	else return cal_error ("Invalid minutes value: '" + arr_time[1] + "'.\nAllowed values are unsigned integers.");

	if (!arr_time[2]) dt_date.setSeconds(0);
	else if (RE_NUM.exec(arr_time[2]))
		if (arr_time[2] < 60) dt_date.setSeconds(arr_time[2]);
		else return cal_error ("Invalid seconds value: '" + arr_time[2] + "'.\nAllowed range is 00-59.");
	else return cal_error ("Invalid seconds value: '" + arr_time[2] + "'.\nAllowed values are unsigned integers.");

	dt_date.setMilliseconds(0);
	return dt_date;
}

function cal_error (str_message) {
	alert (str_message);
	return null;
}

