//-------------------------------------------------------------------
//
// Codice per gestione degli Errori
//
//window.onerror = HandleError
//
//function HandleError(message, url, line) {
//  var str = "An error has occurred in this dialog." + "\n\n"
//  + "Error: " + line + "\n" + message;
//  alert(str);
//  //window.close();
//  return true;
//}





function winOpen(oUrl,oWinName,oWinLayout){
	window.open(oUrl,oWinName,oWinLayout);
	return false;
}

function SetLayDownBar(idLay){
	if( !document.getElementById )
		return true;

	objPH=document.getElementById('ph'+idLay);
	objTesto=document.getElementById(idLay);


	objPH.innerHTML = objTesto.innerHTML;




	return true;
}

function GetMousePos(obj){

	if( !document.getElementById )
		return true;

	ml = obj.offsetLeft;
	mt = obj.offsetTop;

	//alert(ml+'\n'+mt)

	chiudiDownBarLayAll();

	//alert('ritorno funzione');

	layH = document.getElementById( obj.id +'Lay' ).style.height;

	//--------------------------------------------------------------------------------
	//
	//	Explorer calcola offsetLeft in senso relativo all'incapsulamento dei div
	//	Mozilla calcola offsetTop in senso assoluto cioè rispetto alla pagina
	//
	//--------------------------------------------------------------------------------

	if(navigator.appName.indexOf("Microsoft") != -1){
		if( document.getElementById("testata") )
			mt += 357;

		if( document.getElementById("menuSX") ){
			ml += document.getElementById("testo").offsetLeft;
		}

		diffBrowser = 0;

	}else
		diffBrowser = 5;

	//alert( layH.substring(0,layH.indexOf('px')) );

	mt -= parseInt( layH.substring(0,layH.indexOf('px')) ) + diffBrowser;


//	document.onmousemove = GetMousePos;
//
//	ml = (document.layers) ? e.pageX : event.clientX
//	mt = (document.layers) ? e.pageY : event.clientY


	document.getElementById( obj.id + 'Lay' ).style.visibility = 'visible';
	document.getElementById( obj.id + 'Lay' ).style.left = ml;
	document.getElementById( obj.id + 'Lay' ).style.top = mt;

	obj.style.backgroundColor = '#5283B2';

	return false;
}

function chiudiDownBarLay(obj){

	chiudiDownBarLayAll();

	strNomeElemDownBar = obj.id.substring(0, obj.id.indexOf('Lay'));

	document.getElementById( strNomeElemDownBar ).style.background = 'transparent';


}

function chiudiDownBarLayAll(){
	arrLay =
	[
		[
			document.getElementById('DownBarContactLay'), document.getElementById('DownBarContact')
		],
		[
			document.getElementById('DownBarDisclaimerLay'), document.getElementById('DownBarDisclaimer')
		],
		[
			document.getElementById('DownBarCreditsLay'), document.getElementById('DownBarCredits')
		]
	];

	for( i=0; i<arrLay.length; i++){
		arrLay[i][0].style.visibility = 'hidden';
		arrLay[i][1].style.background = 'transparent';
	}

	//alert('fine chiudiDownBarLayAll');
}



//-------------------------------------------------------------------
//
// Codice per gestione delle diversità tra i browser
//
function checkBrowser(caso){
	switch(caso){
		case 'photoGallery':
				if (navigator.userAgent.indexOf('Gecko')	>= 0){
					strAlert = 'Se usi come compressore WinZip '
						+ 'ed il file che stai scaricando viene salvato con estensione .zip\n'
						+ 'devi rinominarlo con estenzione .gz\n\n'
						+ 'In caso di problemi contatta il webmaster.';
					alert( strAlert );
				}
			break;
	}
}


//-------------------------------------------------------------------
//
// Codice per l'urlencode delle stringhe
//
function urlencode(strText) {
	// Autore: 			Charles Toepfer
	// Link articolo:	http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=3623&lngWId=2

	var isObj;

	var trimReg;

	if( typeof(strText) == "string" ) {

		if( strText != null ) {

			trimReg = /(^\s+)|(\s+$)/g;

			strText = strText.replace( trimReg, '');

			for(i=32;i<256;i++) {

				strText = strText.replace(String.fromCharCode(i),escape(String.fromCharCode(i)));
				//strText = strText.replace(strText.fromCharCode(i),escape(strText.fromCharCode(i)));

			}

		}

	}
	return strText;

}


//-------------------------------------------------------------------
//
// Codice per la stampa
//
function stampa(nomeDiv){

	if( nomeDiv == 'TestoL' && window.print())
		window.print();
	else{
		elementToPrint = document.getElementById(nomeDiv);
		winOpen('/4U/pop.php?action=print','winstampa','width=770,height=400,scrollbars=yes,resizable=yes');
	}


	return false;
}


//-------------------------------------------------------------------
//
// Codice per dare il focus alla finestra
//
function daiFocus(){
	this.focus();
}


//-------------------------------------------------------------------
//
// Codice per mostrare un blocco
//
function showBlock(id){
	document.getElementById(id).style.display='inline';
}


//-------------------------------------------------------------------
//
// Codice per nascondere un blocco
//
function hideBlock(id){
	document.getElementById(id).style.display='none';
}


//-------------------------------------------------------------------
//
// Codice per nascondere un blocco
//
function showHide(id){
	document.getElementById(id).style.display= (document.getElementById(id).style.display == 'none')? 'block' : 'none';

	if(document.getElementById('lbl'+id))
		document.getElementById('lbl'+id).innerText= (document.getElementById('lbl'+id).innerText == 'mostra')? 'nascondi' : 'mostra';

	if(document.getElementById('img'+id))
		document.getElementById('img'+id).src = (document.getElementById(id).style.display == 'none')? imgBaseDir+'/globali/1pxA.gif' : imgBaseDir+'/globali/bulletMenu_on.gif';


	return false;
}


//-------------------------------------------------------------------
//
// Codice per il rollover delle immagini
//
function rollon(imgName) {
	if (ok_img) document[imgName].src = eval(imgName + "_on.src");
}

function rolloff(imgName) {
	if (ok_img) document[imgName].src = eval(imgName + "_off.src");
}



//-------------------------------------------------------------------
//
// Funzione per effettuare un PostBack
//
function __DoPostBack( formName, sender, argument) {

   // Devo includere nella pagina i seguenti HiddenFilds
   // Nella stessa form che richiamo con il parametro "formName"
   // <input type="hidden" name="__Sender" value="">
   // <input type="hidden" name="__Argument" value="">

   //alert(sender);

   document.forms[formName].__Sender.value = sender;
   document.forms[formName].__Argument.value = argument;

   document.forms[formName].submit();

   return false;
}




function checkEmail(strEmail){
	var email_re = new RegExp("^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$");
	return email_re.test(strEmail);

}


