function helpdate(f, titolo, css)
{
		field=f;
		d=f.value;

	//preparo la stringa di parametri

		if (d!='') d='data='+d;
		if (titolo!='') titolo='titolo='+titolo;
		if (css!='') css='foglio='+css;

		param='?'
		if (d!='') param=param+d+'&';
		if (titolo!='') param=param+titolo+'&';
		if (css!='') param=param+css+'&';
		param = param.substring(0,param.length-1);
	//alert('calendar.asp'+param);
		open('calendar.asp'+param,'helpdate','width=320,height=180,left=0,top=0');
	}
 
function helpalbum(f, titolo)
{
		field=f;
		d=f.value;

	//preparo la stringa di parametri

		if (d!='') d='album='+d;
		if (titolo!='') titolo='titolo='+titolo;

		param='?'
		if (d!='') param=param+d+'&';
		if (titolo!='') param=param+titolo+'&';
		param = param.substring(0,param.length-1);
		open('albumlist.asp'+param,'Album','width=320,height=380,left=0,top=0,scrollbars=yes');
	}

function getLogo(f, album)
{
		field=f;
		d=f.value;

	//preparo la stringa di parametri

		if (d!='') d='logo='+d;
		if (album!='') titolo='album='+album;

		param='?'
		if (d!='') param=param+d+'&';
		if (titolo!='') param=param+titolo+'&';
		param = param.substring(0,param.length-1);
		open('logolist.asp'+param,'Logo','width=320,height=580,left=0,top=0,scrollbars=yes');
	}

function helpprovincia(f, titolo)
{
		field=f;
		d=f.value;

	//preparo la stringa di parametri

		if (d!='') d='album='+d;
		if (titolo!='') titolo='titolo='+titolo;

		param='?'
		if (d!='') param=param+d+'&';
		if (titolo!='') param=param+titolo+'&';
		param = param.substring(0,param.length-1);
		open('province.asp'+param,'Province','width=320,height=380,left=0,top=0,scrollbars=yes');
	}

function HelpServizio(f, titolo, css)
{
		field=f;
		d=f.value;

	//preparo la stringa di parametri

		if (d!='') d='valore='+d;
		if (titolo!='') titolo='script='+titolo;
		if (css!='') css='foglio='+css;

		param='?'
		if (d!='') param=param+d+'&';
		if (titolo!='') param=param+titolo+'&';
		if (css!='') param=param+css+'&';
		param = param.substring(0,param.length-1);
		open('helpservizio.asp'+param,'helpdate','width=320,height=180,left=0,top=0');
	}

function espandinews(idnews)
{
		d=idnews;

		if (d!='') d='news='+d;

		param='?'
		if (d!='') param=param+d;
		open('EspandiNews.asp'+param,'enews','width=600,height=380,left=0,top=0,scrollbars=yes');
	}

function kbpreview(f)
{

		field=f;
		/*d=f.value.replace(/\%0D\%0A/g,"Pluto");*/
		/*d=f.value.replace(/\n/g,"<br/>")*/
		d=escape(f.value) 
		if (d!='') d='testo='+d;
		param='?'
		if (d!='') param=param+d;

/*
win = window.open(", ", 'popup', 'toolbar = no, status = no, scrollbars=yes');
win.document.write("" + f.value + "");
*/

		open('kbpreview.asp'+param,'preview','width=700,height=480,left=0,top=0,scrollbars=yes');
/*win = window.open('kbpreview.asp', 'popup', 'toolbar = no, status = no, scrollbars=yes');
win.document.write("" + f.value + "");*/
	}


// ------------------------------ controllo data
function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function MyIsDate(dtStr){

	if (dtStr == '') return true
	
	var dtCh= "/";
	var minYear=1900;
	var maxYear=2100;

	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
		
	if (pos1==-1 || pos2==-1){
		alert("Scrivere la data nel formato: gg/mm/aa")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Il mese non è corretto: "+strMonth)
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Il giorno non è corretto: "+strDay)
		return false
	}
	if (strYear.length > 4){
		alert("L'anno non è corretto: "+strYear)
		return false
	}
//	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
//		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
//		return false
//	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("La data non è scritta correttamente")
		return false
	}
return true
}

// ------------------------------ controllo data
function MyDateCompare(dtStr){

	if (dtStr == '') return 0
	
	var dtCh= "/";
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYear)
	if (strYear.length == 2){
		year=year+2000
	}
//H'mmm - +D+(+M+Y*100)*100
return day+(month+year*100)*100
}


//-------------------------------- controllo e-mail
function iseMail(email)
{
    if(email.length <= 0)
	{
	  return true;
	}
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) return false;
    if(splitted[1] != null )
    {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) return false;
    }
    if(splitted[2] != null)
    {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null) 
      {
	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) return false;
      }// if
      return true;
    }
return false;
}
//-------------------------------- controllo e-mail

