

/// Il mio codice Javascript qui

//GLOBAL

function validateDate(strValue) {
  var objRegExp = /^\d{2}(\-|\/|\.)\d{2}\1\d{4}$/
  var intDay;
  if(!objRegExp.test(strValue))
    return false; 
  else{
    var strSeparator = strValue.substring(2,3)
    var arrayDate = strValue.split(strSeparator);
    var arrayLookup = { '01' : 31,'03' : 31, '04' : 30,'05' : 31,'06' : 30,'07' : 31,
                        '08' : 31,'09' : 30,'10' : 31,'11' : 30,'12' : 31}
	if (arrayDate[0].substr(0,1)=='0') { intDay = parseInt(arrayDate[0].substr(1,1)) } else { intDay = parseInt(arrayDate[0]); }
    if(arrayLookup[arrayDate[1]] != null) {
      if(intDay <= arrayLookup[arrayDate[1]] && intDay != 0)
        return true;
    }
    var intMonth = parseInt(arrayDate[1]);
    if (intMonth == 2) { 
       var intYear = parseInt(arrayDate[2]);
       if( ((intYear % 4 == 0 && intDay <= 29) || (intYear % 4 != 0 && intDay <=28)) && intDay !=0)
          return true;
       }
  }
  return false;
}

function validateMail(oggetto) {
        var s = oggetto.value;
        s = s.replace(/^\s*|\s*$/, "");
        if (s == "undefined" || s.length < 8) {
             alert("La lunghezza dell\'indirizzo EMAIL deve essere di almeno 8 caratteri");
             oggetto.focus();
             return false;
            }
        re = /\s+/
        if (re.test(s)) {
             alert("Gli spazi non sono ammessi all'interno dell\'indirizzo email.");
             oggetto.focus();
             return false;
            }
        re = /^[\w-][\w-]*((\.[\w-]+)+)*@([\w-]+\.)*([\w-]{2,}\.)+([a-zA-Z]{2,4})$/
        if (!re.test(s)) {
             alert("Indirizzo EMAIL non corretto.");
             oggetto.focus();
             return false;
            }
        re = /\.(a[c-gil-oq-uwz]|b[a-bd-jm-or-tvwyz]|c[acdf-ik-orsuvx-z]|d[ejkmoz]|e[ceghr-u]|f[i-kmorx]|g[abd-ilmnp-uwy]|h[kmnrtu]|i[delm-oq-t]|j[emop]|k[eg-imnprwyz]|l[a-cikr-vy]|m[acdghk-z]|n[ace-giloprtuz]|om|p[ae-hk-nrtwy]|qa|r[eouw]|s[a-eg-ort-vyz]|t[cdf-hjkm-prtvwz]|u[agkmsyz]|v[aceginu]|w[fs]|y[etu]|z[admrw]|com|edu|net|org|mil|gov|biz|pro|aero|coop|info|name|museum|int)$/i
        if (!re.test(s)) {
             alert("Suffisso di dominio inesistente per l'email indicata.");
             oggetto.focus();
             return false;
            }
  return (true);
}



function checkLavagna(mForm)
{

	if (mForm.email.value != '') {
	if (!validateMail(mForm.email)) { return; }
	}

	if (mForm.msg.value == '') { alert('Il campo MESSAGGIO e\' vuoto.'); mForm.msg.focus(); return; }
	if (mForm.msg.value != '' && mForm.msg.value.length < 3) { alert('Il testo del messaggio non e\' valido.\nLunghezza minima: 3 caratteri'); mForm.msg.focus(); return; }
	if (mForm.msg.value != '' && mForm.msg.value.length > 4000) { alert('Il testo del messaggio non e\' valido.\nLunghezza massima: 8000 caratteri'); mForm.msg.focus(); return; }
		
	mForm.submit();

}

function checkFolclore(mForm)
{

	if (mForm.categ.value == '') { alert('Indicare la categoria'); mForm.categ.focus(); return; }

	if (mForm.msg.value == '') { alert('Il campo testo e\' vuoto.'); mForm.msg.focus(); return; }
	if (mForm.msg.value != '' && mForm.msg.value.length < 3) { alert('Il testo del messaggio non e\' valido.\nLunghezza minima: 3 caratteri'); mForm.msg.focus(); return; }
	if (mForm.msg.value != '' && mForm.msg.value.length > 4000) { alert('Il testo del messaggio non e\' valido.\nLunghezza massima: 8000 caratteri'); mForm.msg.focus(); return; }
		
	if (mForm.msgita.value == '') { alert('Il campo testo in italiano e\' vuoto.'); mForm.msgita.focus(); return; }
	if (mForm.msgita.value != '' && mForm.msgita.value.length < 3) { alert('Il testo del messaggio non e\' valido.\nLunghezza minima: 3 caratteri'); mForm.msgita.focus(); return; }
	if (mForm.msgita.value != '' && mForm.msgita.value.length > 4000) { alert('Il testo del messaggio non e\' valido.\nLunghezza massima: 8000 caratteri'); mForm.msgita.focus(); return; }
			
	mForm.submit();

}

function modLavagna(mForm)
{
	mForm.step.value = "";
	mForm.submit();
}

function modFolclore(mForm)
{
	mForm.step.value = "";
	mForm.submit();
}

function openChat()
{
	var finestra = window.open('/tools/float_chat.asp','Stio','height=410,width=710,location=no,toolbar=no,scrollbars=no,status=no,resizable=no');
}

function openChatHome()
{
	var finestra = window.open('/tools/float_chat.asp?x=no','Stio','height=410,width=710,location=no,toolbar=no,scrollbars=no,status=no,resizable=no');
}

function checkday(theForm)
{
	if (theForm.tchat.value == 'adesso') {
		theForm.ora.disabled = true;
		theForm.min.disabled = true;
	}
	else
	{
		theForm.ora.disabled = false;
		theForm.min.disabled = false;
	}
		
}

function checkInvite(theForm)
{
	if (theForm.fname.value == '') { alert('Inserisci il nome del tuo amico'); theForm.fname.focus(); return; }
	if (!validateMail(theForm.fmail)) { theForm.fmail.focus(); return; }
	if (theForm.mname.value == '') { alert('Inserisci il tuo nome'); theForm.mname.focus(); return; }	
	
	theForm.submit()
}


