// Prove
function GiveMeEditor(id, settings)
{

	WYSIWYG.setSettings(id, settings);
	WYSIWYG_Core.includeCSS(WYSIWYG.config[id].CSSFile);
	WYSIWYG._generate(id, settings);
	//WYSIWYG.attach(id, settings);
}

function filter_select(selectname, label_to_parse)
{
	selectObj=document.getElementById(selectname);

	for(var i=0; i < selectObj.length; i++)
		if ( selectObj[i].text.search(label_to_parse) == -1 )
			selectObj.remove(i);
}

// nuove fx JS 2007 ----------------------
var debug = false;

// Ajax functions ------------------------


function AjaxXMLHR() {
	var XHR = null;
	var browserUtente = navigator.userAgent.toUpperCase();

	if(typeof(XMLHttpRequest) === "function" || typeof(XMLHttpRequest) === "object")
	{
		XHR = new XMLHttpRequest();
		if (XHR.overrideMimeType)
			XHR.overrideMimeType('text/xml');
	}
	else if(window.ActiveXObject && browserUtente.indexOf("MSIE 4") < 0)
		if(browserUtente.indexOf("MSIE 5") < 0)
			XHR = new ActiveXObject("Msxml2.XMLHTTP");
		else
			XHR = new ActiveXObject("Microsoft.XMLHTTP");
	return XHR;
}

function AjaxGet(url,layer) {
	var ajax = AjaxXMLHR();
	var r = Math.floor(Math.random()*10000)
	
	// se specifica output in un layer visualizzo loading
	if (document.getElementById(layer))
		document.getElementById(layer).innerHTML='<div class="normal_center mrg_t5"><img class="ajax_loading" src="images/layout/ajax_loading.gif"><span class="ajax_loading">&nbsp;loading data...</span></div>';
	
	if(ajax) {
		// se non e' null chiamo ready state, se e' null e' inutile perche'
		// significa che tanto non mi interessa l'output e potrebbe dare
		// errore se la chiamo sull'unload di una pagina
		if (layer)
			ajax.onreadystatechange = function() {AjaxState(ajax,layer);};
		ajax.open("get", url+"&r="+r, true);
		ajax.send(null);
	} else
		alert('Ajax not initialized');
}

function AjaxState(ajax,layer) 
{
	if (ajax.readyState == 4)
	{ 
		if (ajax.status == 200)
		{
			if (document.getElementById(layer))
				document.getElementById(layer).innerHTML = ajax.responseText;
			else
				if (layer){
					if (layer == 'alert')
						alert(ajax.responseText);
					else (layer == 'fx')
						return ajax.responseText;
				}
		} else {
			if (document.getElementById(layer))
				document.getElementById(layer).innerHTML = "ajax error:\n "+ajax.statusText;
			else
				if (layer)
					if (layer == 'alert')
						alert("ajax error:\n "+ajax.statusText);
		}
	}
}





//document.getElementById(layer).innerHTML = "ajax error:\n"+ajax.statusText;


// main Timer Function
// -----------------------------------------------------------

var usr_inchat_list = '0,0'
var usr_sessionid_list = '0,0'
var usr_new_msg = 0

function AjaxGetXML(url) {

	var ajax = AjaxXMLHR();
	var r = Math.floor(Math.random()*10000);
	
	// se specifica output in un layer visualizzo loading
	//if (layer)
	//	document.getElementById(layer).innerHTML='<div class="normal_center mrg_t5"><img class="ajax_loading" src="images/layout/ajax-loader.gif"><span class="ajax_loading">&nbsp;loading data...</span></div>';
	//else
	//	return ajax.responseText;
	
	if (ajax) {
		ajax.onreadystatechange = function() {AjaxStateXML(ajax);};
		ajax.open("get", url+"&r="+r, true);
		ajax.send(null);
	} else
		alert('Ajax not initialized');
}
function AjaxStateXML(ajax) 
{
	if (ajax.readyState == 4)
	{
		if (ajax.status == 200)
		{ 
			var xmldoc			=	ajax.responseXML;
			usr_inchat_list		=	xmldoc.getElementsByTagName('usr_inchat_list').item(0).firstChild.nodeValue;
			usr_sessionid_list	=	xmldoc.getElementsByTagName('usr_sessionid_list').item(0).firstChild.nodeValue;
			usr_new_msg			=	xmldoc.getElementsByTagName('usr_new_msg').item(0).firstChild.nodeValue;
		}
		else
		{
			if (debug)
				alert('AjaxStateXML: ajax error:\n '+ajax.statusText);
		}
	}
}

var z=0;

function timer() {
	var usr_sessionid_array = usr_sessionid_list.split(',');
	
	if (usr_inchat_list){
		for (var i=0;i<usr_sessionid_array.length;i++){
			if (usr_inchat_list.match(usr_sessionid_array[i])){
				if (document.getElementById(usr_sessionid_array[i]+'_IsInChat'))
					document.getElementById(usr_sessionid_array[i]+'_IsInChat').className='';
			} else {
				if (document.getElementById(usr_sessionid_array[i]+'_IsInChat'))
					document.getElementById(usr_sessionid_array[i]+'_IsInChat').className='hidden';
			}	
		}
	}

	if (usr_new_msg>0 && document.getElementById('usr_new_msg').style){
		document.getElementById('usr_new_msg').className = "popup_show";
		if (navigator.userAgent.toUpperCase().indexOf('MSIE 5') != -1 || navigator.userAgent.toUpperCase().indexOf('MSIE 6') != -1 ){
			document.getElementById('usr_new_msg').style.position = "absolute";
			document.getElementById('usr_new_msg').style.top = 244+"px";
			document.getElementById('usr_new_msg').style.left = 143+"px";
		}
	}
/*
	if (screen.width && document.getElementById('content'))
	{
		if (screen.width > 800)
			document.getElementById('column1024').className='column1024';
		if (screen.width > 1024)
			document.getElementById('column1280').className='column1280';
		document.getElementById('footer').className='footer';
	}
*/
	if (debug){
		z=z+1;
		document.getElementById('debug').innerHTML=z+'<br>'+usr_inchat_list+'<br>'+usr_sessionid_list+'<br>'+usr_new_msg
		}
	AjaxGetXML('ajax_data.asp?i=0');
}

// main Timer Function END
// -----------------------------------------------------------


// function used to prevent  extra request in some situation
// ---------------------------------------------------------

var older_request = 'no request';
var user_activity

function AjaxGetAI (url,layer,newer_request) {
	newer_request = new Date(newer_request);
	
	if (older_request == 'no request')
		older_request = newer_request;

	//document.getElementById('ajax').innerHTML = older_request +'<br>'+ newer_request + (Math.ceil(newer_request.getTime() - older_request.getTime()));

	if (Math.ceil(newer_request.getTime() - older_request.getTime()) > 800) {
		AjaxGet (url,layer);
		older_request = 'no request';
	} else {
		clearTimeout(user_activity);
		older_request = newer_request;
		user_activity = setTimeout("AjaxGetAI('"+url+"','"+layer+"', new Date())",800);
	}
}


// Ajax functions  END -------------------

// ------------ END 2007 -----------------



var width;				//width of screen
var height;				//height of screen

var active_layer;		//used to save menu active layer... is only a fast workaround... need to rewrite

// gestione location
function Go(str,finestra)
{
	if (finestra)
		finestra.location.href = (str);
	else
		location.href = (str);
}

// funzioni per accendere spegnere le celle
function CellOnOff ( cell, textcolor, bgcolor )
{
//cell.style.cssText += 'font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt; font-weight: bold; color: #336699; background-color: #E7E7E7; line-height: 20pt ;';
cell.style.color = textcolor;
cell.style.backgroundColor = bgcolor;
}

function WhatRes()
{
//calcolo la larghezza del browser
width = document.body.clientWidth;
//width = document.body.offsetWidth;
if (width == 0)
	width = 800;
}

//gestione layer

function LayOn (Lay)
{
if (!Lay.style)	{

active_layer=Lay;

if(document.getElementById)
		Lay=document.getElementById(Lay);
	else if (document.all)
		Lay=document.all[Lay];
}
Lay.style.display = 'block';
}

function LayOff (Lay)
{
if (!Lay.style)	{
	if(document.getElementById)
		Lay=document.getElementById(Lay);
	else if (document.all)
		Lay=document.all[Lay];
}
Lay.style.display = 'none';
}



function LayerRepositioning()
{
WhatRes();

if (width >= 1024)
	normalspace=(width-760-20)/2-80;
else
	normalspace=(width-760-20)/2+8;

if (document.getElementById)	{
// riposizionamento dei layer dei menu'
	Lay=document.getElementById('menu_informati');
	Lay.style.left=normalspace+6;
	Lay=document.getElementById('menu_parla');
	Lay.style.left=normalspace+156;
	Lay=document.getElementById('menu_gadget');
	Lay.style.left=normalspace+455;
	Lay=document.getElementById('menu_altro');
	Lay.style.left=normalspace+554;

//riposizionamento dei layer del layout
	Lay=document.getElementById('corpo');
	Lay.style.left=normalspace;
	Lay=document.getElementById('ronzino');
	Lay.style.left=normalspace+5;
	Lay=document.getElementById('xmas');
	Lay.style.left=normalspace+387;
	
	if (width >= 1024)	{
		Lay=document.getElementById('usersonline');
		Lay.style.left=normalspace+762;
		Lay.style.top=5;
		Lay.style.visibility = 'visible';
	}
	else	{
		Lay=document.getElementById('usersonline');
		Lay.style.left=normalspace+592;
		Lay.style.top=34;
	}
}

else if (document.all)	{
// riposizionamento dei layer dei menu'
	Lay=document.all['menu_informati'];
	Lay.style.left=normalspace+6;
	Lay=document.all['menu_parla'];
	Lay.style.left=normalspace+156;
	Lay=document.all['menu_gadget'];
	Lay.style.left=normalspace+455;
	Lay=document.all['menu_altro'];
	Lay.style.left=normalspace+554;

//riposizionamento dei layer del layout
	Lay=document.all['corpo'];
	Lay.style.left=normalspace;
	Lay=document.all['ronzino'];
	Lay.style.left=normalspace+5;

//riposizionamento layer usersonline
	if (width >= 1024)	{
		Lay=document.all['usersonline'];
		Lay.style.left=normalspace+762;
		Lay.style.top=5;
		Lay.style.visibility = 'visible';
	}
	else	{
		Lay=document.all['usersonline'];
		Lay.style.left=normalspace+592;
		Lay.style.top=34;
	}
}
}
	
function LayerRepositioningHome()	//riposizione i layer presenti solo nella home
{
WhatRes();
normalspace=(width-760-20)/2;

	if (document.getElementById)
		Lay=document.getElementById('popup');
	else if (document.all)
		Lay=document.all['popup'];
	Lay.style.left=35;
}

function resize_iframe(iframe_name,obj)
{
	if (document.all)	{ // se è explorer o opera ! modificare per opera
		if (obj.document.body.scrollHeight)
			iframe_length=obj.document.body.scrollHeight;
		else if	(obj.document.documentElement.offsetHeight)
			iframe_length=obj.document.documentElement.offsetHeight;
	}
	else			 // mozilla
		if (obj.document.body.scrollHeight)	
			iframe_length=obj.document.body.scrollHeight+2;
		
	for (i=1; i<window.frames.length; i++ )
		if (window.frames[i])
		{
			if (window.frames[i].name == iframe_name)
			{
				if (document.getElementById)
				{
					document.getElementById(window.frames[i].name).style.height = iframe_length;
					break;
				}
		
				if (document.all)
				{
					document.all[window.frames[i].name].style.height = iframe_length;
					break;
				}
			}
		}
}

function ShowImage (ImageTarget , ImageToShow)
{
ImageTarget.src=ImageToShow;
}

// funzioni per il PopUp di finestre

// funzione per il PopUp della finestra commenti
var commenti;

function PopUpCommenti(commentoId , oggettoId, tipoId, sourceId)
{
var windows_def = 'width=430,height=500,toolbar=no,location.href=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no'

if ( ! commenti )
{
	commenti = window.open('/asvp/commenti.asp?cId='+commentoId+'&oId='+oggettoId+'&tId='+tipoId+'&sId='+sourceId, 'commenti', windows_def );
	commenti.focus();
}
else
	if (commenti.closed)	
		commenti = window.open('/asvp/commenti.asp?cId='+commentoId+'&oId='+oggettoId+'&tId='+tipoId+'&sId='+sourceId, 'commenti', windows_def);
	else
	{
		commenti.location.href='/asvp/commenti.asp?cId='+commentoId+'&oId='+oggettoId+'&tId='+tipoId+'&sId='+sourceId;
		commenti.focus();
	}
}

// funzione per il PopUp della finestra smile
var smile;

function OpenSmile()
{
var windows_def = 'width=470,height=520,toolbar=no,location.href=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no';

if ( ! smile )
{
	smile = window.open("/asvp/smile.asp","smile", windows_def);
	smile.focus();
}
else
	if (smile.closed)	
		smile = window.open("/asvp/smile.asp","smile", windows_def);
	else
		smile.focus();
}

// funzione per il PopUp della chat
var chat

function OpenChat()
{
if ( ! chat )
{
	chat = window.open("chat.asp","chat", "width=420,height=500,toolbar=no,location.href=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no");
	chat.focus();
}
else
	if (chat.closed)
		chat = window.open("chat.asp","chat", "width=415,height=500,toolbar=no,location.href=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no");
	else
		chat.focus();
}

var partecipanti;

function OpenPartecipanti(eventoId)
{
var windows_def = 'width=420,height=512,toolbar=no,location.href=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no';

if ( ! partecipanti )
{
	partecipanti = window.open("/asvp/eventi_partecipanti.asp?eId="+eventoId,"partecipanti", windows_def);
	partecipanti.focus();
}
else
	if (partecipanti.closed)	
		partecipanti = window.open("/asvp/eventi_partecipanti.asp?eId="+eventoId,"partecipanti", windows_def);
	else
	{
		partecipanti = window.open("/asvp/eventi_partecipanti.asp?eId="+eventoId,"partecipanti", windows_def);
		partecipanti.focus();
	}
}

var explorer;

function OpenExplorer()
{
var windows_def = 'width=700,height=520,toolbar=no,location.href=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no';

if ( ! explorer )
{
	explorer = window.open("/asvp/admin_explorer.asp?path=/public/images","explorer", windows_def);
	explorer.focus();
}
else
	if (explorer.closed)	
		explorer = window.open("/asvp/admin_explorer.asp?path=/public/images","explorer", windows_def);
	else
		explorer.focus();
}

var viewer

function OpenViewer(sourceId, tipoId)
{
var windows_def = 'width=780,height=530,toolbar=no,location.href=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no';

if ( ! viewer )
{
	viewer = window.open("/asvp/viewer.asp?sId="+sourceId+"&tId="+tipoId,"viewer", windows_def);
	viewer.focus();
}
else
	if (viewer.closed)	
		viewer = window.open("/asvp/viewer.asp?sId="+sourceId+"&tId="+tipoId,"viewer", windows_def);
	else
	{
		viewer = window.open("/asvp/viewer.asp?sId="+sourceId+"&tId="+tipoId,"viewer", windows_def);
		viewer.focus();
	}
}

function CheckSMS()
{
// prendi dinamicamente 2 variabili, controlla ronzsms_check per maggiori dettagli.
// l'include scrive questo:
// response.write ("last_read="&UltimoRonziSms&";"&VbCrLf)
// response.write ("last_received="&rs("msgId")&";"&VbCrLf)

	if ( last_read != last_received) // no new SMS
		alert('Ehi giovane hai un nuovo ronzisms nella tua casella postale !');
}


function CheckAtLeastOne(a,b){
	if (a.value=='' &&  b.value==''){
		alert('Inserire un valore nel campo \"'+a.label+'\" o nel campo \"'+b.label+'\"');
		a.focus();
		return (false);
	}
return (true);
}


var valoreiniziale

function high(which2)
{
if (which2.style.MozOpacity)
	valoreiniziale=which2.style.MozOpacity;
else if (which2.filters)
	valoreiniziale=which2.filters.alpha.opacity;

	theobject=which2
	highlighting=setInterval("highlightit(theobject)",50)
}
function low(which2)
{
	clearInterval(highlighting)
		if (which2.style.MozOpacity)
			which2.style.MozOpacity=valoreiniziale;
		else if (which2.filters)
			which2.filters.alpha.opacity=valoreiniziale;
}
function highlightit(cur2)
{
	if (cur2.style.MozOpacity<1)
		cur2.style.MozOpacity=parseFloat(cur2.style.MozOpacity)+0.1
	else if (cur2.filters&&cur2.filters.alpha.opacity<100)
		cur2.filters.alpha.opacity+=10
	else if (window.highlighting)
		clearInterval(highlighting)
}

/*Number check script-
By JavaScript Kit (www.javascriptkit.com)
Over 200 free scripts here!
*/

function IsNumeric(Num){
//var x=document.checknum.pnum.value
var anum=/(^\d+$)|(^\d+\.\d+$)/
if (anum.test(Num))
testresult=true
else{
testresult=false
}
return (testresult)
}

function IsNumber(NumOrString)
{
if (NumOrString == 0 || NumOrString == 1 || NumOrString == 2 || NumOrString == 3 || NumOrString == 4 || NumOrString == 5 || NumOrString == 6 || NumOrString == 7 || NumOrString == 8 || NumOrString == 9) 
	return(true);
else
	return(false);
}

var Lastcalled = new Date();

function CharsNumber(input, maxchrs)
{
var LastChar;
if (new Date() - Lastcalled < 100)
{
	Lastcalled = new Date();
	return
}
Lastcalled = new Date();

	if (input.value.length > maxchrs)
	{
		alert('Questo campo può contenere al massimo massimo '+maxchrs+' caratteri !');
		input.value=String(input.value).substring(0,maxchrs);
	}

	//alert( String(input.value).substring(maxchrs,maxchrs-1) );
	LastChar=String(input.value).substring(maxchrs,maxchrs-1);

	if ( LastChar=='{' || IsNumber(LastChar) )
		if (String(input.value).substring(maxchrs,maxchrs-3).search('{') != -1)	//se negli ultimi 3 caratteri del campo di input trovi { non va bene
		{
			// porcehria... sono le 3 di notte... e js sembra un idiota 
			if (String(input.value).substring(maxchrs,maxchrs-1) == '{')
				input.value=String(input.value).substring(0,maxchrs-1);
			
			if (String(input.value).substring(maxchrs-1,maxchrs-2) == '{')
				input.value=String(input.value).substring(0,maxchrs-2);
			
			if (String(input.value).substring(maxchrs-2,maxchrs-3) == '{')
				input.value=String(input.value).substring(0,maxchrs-3);
		}

	window.defaultStatus=input.value.length;
	//window.defaultStatus=getMilliseconds(new Date() - Lastcalled) 

}

function CheckEmail(email) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email.value)){
		return (true);
	}
	alert('L\'indirizzo email inserito non è valido !');
	email.focus();
	return (false);
}


//			CutPoint = input.value.match('{');
//			for (i=0;  i<CutPoint.length; i++)
//			{
//			palle=palle+CutPoint[i];
//			window.defaultStatus=palle;//input.value=String( input.value ).substring( 0,String(input.value).substring(maxchrs,maxchrs-3).search('{') );
//			}

