
//===========
// PATCH LINK
//===========
window.onload = function OnLoad() { PatchLink(); Init(); }
function Init(){}
function PatchLink()
{
	for (var i=0; i<document.links.length; i++)
	{
		// Link verso documenti e/o pubblicazioni editati da backoffice e link speciali (immagine, fotogallery, stampa)
        if (document.links[i].className.search("target_open") >= 0)
        {
        	document.links[i].href = 'javascript:OpenLink("'+ document.links[i].href +'", '+ (document.links[i].className.search("target_self") >= 0) +')';
        	continue;
        }

		// Attributo target specificato in className per compatibilità XHTML
        if (document.links[i].className.search("target_blank") >= 0)
			document.links[i].target="_blank";
	}	
}


//===========
// OPEN POPUP
//===========
// Remapping per l'apertura di link di tipo target_open
function OpenLink(arg, bSelf)
{
	if (bSelf==null) bSelf = true;

	var name = "_blank";
	try	{ queryString = arg.split("?")[1] }	catch(e) { queryString = "_blank" }
		
	// Default features senza menu e barra di stato
	var features = "width=800, height=500, location=no, menubar=no, resizable=yes, scrollbars=yes, status=yes, titlebar=yes";

	// Specific features
	if (arg.search("OpenGallery.asp") >= 0)
	{
		// Galleria di immagini
		features = "width=800, height=700, location=no, menubar=no, resizable=yes, scrollbars=yes, status=yes, titlebar=yes";
	}
	else if (arg.search("OpenImage.asp") >= 0)
	{
		// Singola immagine
	}
	else if (arg.search("OpenObject.asp") >= 0)
	{
		// Singola pubblicazione 
		if (bSelf)
		{
			// Apertura nella finestra corrente
			document.location = arg;
			return;
		}
	}
	else if (arg.search("OpenDoc.asp") >= 0)
	{
		// Allegato
	}
	else
	{
		// Redirezione con arg inalterato, tipicamente utilizzata per la versione stampabile
		features = "width=800, height=600, location=yes, menubar=no, resizable=yes, scrollbars=yes, status=yes, titlebar=yes";		
	}

	// Le aperture in popup sono segnalate con parametro sulla query
	window.open(arg +"&popup=1", name, features).focus();
}


//==================
// CALENDAR FUNCTION
//==================

function DoCalendarRefresh(idCalendar, urlPattern)
{
	var month = document.getElementById(idCalendar +"_SELECT_Month").value;
	var year = document.getElementById(idCalendar +"_SELECT_Year").value;
	var url = urlPattern.replace("_event_", 2);
	var url = url.replace("_month_", month);
	var url = url.replace("_year_", year);
	window.document.location = url;	
}


//=======
// LOGIN
//=======
function DoLogin(formName)
{
	// LoginForm
	var form = document.getElementById(formName);

	// Check autologin
	if (form.Subject.value == form.InputUtente.value && form.InputPassword.value == ")auto(")
	{
		document.location = form.UrlSuccess.value;
		return;
	}

	// Utente
	var subject = Trim(form.InputUtente.value).toLowerCase();
	if ( subject == "" )
	{
		window.alert("Utente obbligatorio");
		FormLogin.InputUtente.focus();
		return false;
	}
	form.Subject.value = subject; 

	// Password
	var password = Trim(form.InputPassword.value).toLowerCase();
	
	// IpAddress
	var ip = Trim(form.IpAddress.value);
	
	// Ticket
	var ticket = Trim(form.Ticket.value);
	form.Ticket.value = ticket;
	
	// Digest
	var key = subject + password;
	key = SHA1EsaDigest(key, key.length);
	fullMsg = subject + ip + key + ticket;
	var digest = SHA1EsaDigest(fullMsg, fullMsg.length);
	form.Digest.value = digest;
	
	form.submit();
}

//================
// Gestione schede
//================
function ReferenzeMenuOver(idObject, list)
{
	for (var i=0; i<list.length; i++)
	{
		var target = document.getElementById("Logo_IMG_"+list[i]);
		if (target != null)
			target.className = target.className.replace(/-out/, "-over");
	}
}
function ReferenzeMenuOut()
{
	var list = document.getElementsByName("Logo_A");
	for (var i=0; i<list.length; i++)
	{
		var target = document.getElementById(list[i].id.replace(/_A_/, "_IMG_"));
		target.className = target.className.replace(/-over/, "-out");
		list[i].className = list[i].className.replace(/-selected/, "-normal");		
	}
}
function ReferenzeLogoOver(idMenu, idLogo)
{
	var target = document.getElementById("Menu_A_"+idMenu);
	if (target != null)
		target.className = target.className.replace(/-out/, "-over");
	target = document.getElementById("Logo_IMG_"+idLogo);
	target.className = target.className.replace(/-out/, "-over");
}
function ReferenzeLogoOut()
{
	var list = document.getElementsByName("Menu_A");
	for (var i=0; i<list.length; i++)
		list[i].className = list[i].className.replace(/-over/, "-out");		
	ReferenzeMenuOut();
}



//================
// Form Invio dati
//================
function ContattiCheck()
{
	var target;
	var inputObbligatori = ["Nome", "Cognome", "Azienda", "FunzioneAziendale", "Indirizzo", "Citta", "Telefono", "Mail"];
	for (var i=0; i<inputObbligatori.length; i++)
	{
		target = document.getElementById(inputObbligatori[i]);
		if (target != null && target.value == "")
		{
			window.alert("Campo obbligatorio");
			target.focus();
			return false;
		}
	}
	target = document.getElementById("PrivacyCheck");
	if (target != null && !target.checked)
	{
		window.alert("E' necessaria l'autorizzazione al trattamento dei dati per completare la procedura di contatto");
		target.focus();
		return false;
	}
	return true;
}



function SelectNazioniPopup(select)
{
	var idAttrValue = ParseInt(select.value, 0);
	var features = "width=550, height=500, location=no, menubar=no, resizable=yes, scrollbars=yes, status=yes, titlebar=yes";
	if (idAttrValue > 0)
		window.open("PopupReference.asp?IdAttrValue="+ idAttrValue, "SelectNazioniPopup", features).focus();
}

function pref()
{
	try
	{
		window.external.AddFavorite('http://www.alpinaindustriale.it','Alpina Industriale');
	}
	catch(e)
	{
		window.sidebar.addPanel('Alpina Industriale','http://www.alpinaindustriale.it','');
	}
}

function toLocaleStrDemo(){   

   var d, s;                      
   d = new Date();
   s = "";
   s += d.toLocaleDateString();       
   document.write(s)
}