// oggetto di verifica stato
var readyState = {
	INATTIVO:	0,
	INIZIALIZZATO:	1,
	RICHIESTA:	2,
	RISPOSTA:	3,
	COMPLETATO:	4
};

// array descrittivo dei codici restituiti dal server
// [la scelta dell' array è per evitare problemi con vecchi browsers]
var statusText = new Array();
statusText[100] = "Continue";
statusText[101] = "Switching Protocols";
statusText[200] = "OK";
statusText[201] = "Created";
statusText[202] = "Accepted";
statusText[203] = "Non-Authoritative Information";
statusText[204] = "No Content";
statusText[205] = "Reset Content";
statusText[206] = "Partial Content";
statusText[300] = "Multiple Choices";
statusText[301] = "Moved Permanently";
statusText[302] = "Found";
statusText[303] = "See Other";
statusText[304] = "Not Modified";
statusText[305] = "Use Proxy";
statusText[306] = "(unused, but reserved)";
statusText[307] = "Temporary Redirect";
statusText[400] = "Bad Request";
statusText[401] = "Unauthorized";
statusText[402] = "Payment Required";
statusText[403] = "Forbidden";
statusText[404] = "Not Found";
statusText[405] = "Method Not Allowed";
statusText[406] = "Not Acceptable";
statusText[407] = "Proxy Authentication Required";
statusText[408] = "Request Timeout";
statusText[409] = "Conflict";
statusText[410] = "Gone";
statusText[411] = "Length Required";
statusText[412] = "Precondition Failed";
statusText[413] = "Request Entity Too Large";
statusText[414] = "Request-URI Too Long";
statusText[415] = "Unsupported Media Type";
statusText[416] = "Requested Range Not Satisfiable";
statusText[417] = "Expectation Failed";
statusText[500] = "Internal Server Error";
statusText[501] = "Not Implemented";
statusText[502] = "Bad Gateway";
statusText[503] = "Service Unavailable";
statusText[504] = "Gateway Timeout";
statusText[505] = "HTTP Version Not Supported";
statusText[509] = "Bandwidth Limit Exceeded";

// funzione per prendere un elemento con id univoco
function prendiElementoDaId(id_elemento) {
	var elemento;
	if(document.getElementById)
		elemento = document.getElementById(id_elemento);
	else
		elemento = document.all[id_elemento];
	return elemento;
};

// funzione per assegnare un oggetto XMLHttpRequest
function assegnaXMLHttpRequest() {
	var
		XHR = null,
		browserUtente = navigator.userAgent.toUpperCase();
	if(typeof(XMLHttpRequest) === "function" || typeof(XMLHttpRequest) === "object")
		XHR = new XMLHttpRequest();
	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 loadswfTransparent(swf,w,h){
	document.write("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"");
    document.write("codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\"");
	document.write("width=\""+w+"\" height=\""+h+"\">");
    document.write("<param name='movie' value='"+swf+"' />\n");
    document.write("<param name='quality' value='high' />\n");
	document.write("<param name='wmode' value='transparent' />\n");
    document.write("<embed src=\""+swf+"\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\""+w+"\" height=\""+h+"\" wmode=\"transparent\"></embed>");
    document.write("</object>\n");
}
function loadswf(swf,w,h){
	document.write("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"");
    document.write("codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\"");
	document.write("width=\""+w+"\" height=\""+h+"\">");
    document.write("<param name='movie' value='"+swf+"' />\n");
    document.write("<param name='quality' value='high' />\n");
    document.write("<embed src=\""+swf+"\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\""+w+"\" height=\""+h+"\"></embed>");
    document.write("</object>\n");
}
function SelAll(fName, YesNo)
{
	var nb;

	nb = document.forms[fName].elements.length
	for (var i=0;i<nb;i++)
	{
		var e = document.forms[fName].elements[i];
		e.checked = YesNo
	}
}

function isnumeric_field(sText)
{

   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
                     
   return IsNumber;
   
}

function submit_on_enter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;
if (keycode == 13)
{
myfield.form.submit();
return false;
}
else
return true;
}

function start(winflash, x, y, bar)
{
window.open(winflash,'','scrollbars='+bar+',screenX=150,screenY=50,left=150,top=50,resizable=0,menubar=0,toolbar=0,status=0,width='+x+',height='+y);
}



function printon(){self.print();}

function popup(sPicURL) {
window.open("foto.htm?"+sPicURL, "", "resizable=0,HEIGHT=300,WIDTH=200");
}

function popupinvia(sPicURL) {
window.open("fotoinvia.asp?"+sPicURL, "", "resizable=0,HEIGHT=300,WIDTH=200");
}

function centra(page)
{
var w = screen.width; 
var h = screen.height; 
var x = Math.round(w / 2) - Math.round(700/2); 
var y = Math.round(h / 2) - Math.round(450/2); 
newwindow = window.open(page, null, 'scrollbars=1, left=' + x + ', screenX=' + x + ',top=' + y + 'screenY=' + y +',width=700,height=450'); 
window.opener=self
}

function vaisopra() {
window.top.scroll(0,0);
}


function ltrim(s) {return s.replace( /^\s*/, "" );}
function rtrim(s) {return s.replace( /\s*$/, "" );}
function trim (s) {return rtrim(ltrim(s));}

function verify()
{
ok = 0;

if (document.contact.nome.value == "")
    {
     errorString = "Il nome è obbligatorio";
     alert(errorString);
     document.contact.nome.focus();
     ok = 1;
    }

else if (document.contact.cognome.value == "")
    {
     errorString = "Il cognome è obbligatorio";
     alert(errorString);
     document.contact.cognome.focus();
     ok = 1;
    }

else if (document.contact.citta.value == "")
    {
     errorString = "La CITTA' è obbligatoria";
     alert(errorString);
     document.contact.citta.focus();
     ok = 1;
    }
	else if (document.contact.email.value == "")
    {
     errorString = "la mail è obbligatoria";
     alert(errorString);
     document.contact.email.focus();
     ok = 1;
    }

	
if (ok == 0)
   document.contact.submit();

}

function verify2(frm)
{

if (frm.name == 'registra')
{

ok = 0;

Ctrl = frm.email;
result = false;
space_tokens = Ctrl.value.split(" ");
if (space_tokens.length == 1) {
at_tokens = Ctrl.value.split("@");
if (at_tokens.length == 2) {
if (at_tokens[1].length != 0) {
   right_dot_tokens = at_tokens[1].split(".");
   if (right_dot_tokens.length >= 2) {
   if (right_dot_tokens[1].length != 0) {
   result=true;}}}}}

if (frm.nome.value == "")
    {
     errorString = "Il NOME è obbligatorio";
     alert(errorString);
     frm.nome.focus();
     ok = 1;
    }

else if (frm.cognome.value == "")
    {
     errorString = "Il COGNOME è obbligatorio";
     alert(errorString);
     frm.cognome.focus();
     ok = 1;
    }


else if (frm.citta.value == "")
    {
     errorString = "La CITTA' è obbligatoria";
     alert(errorString);
     frm.citta.focus();
     ok = 1;
    }

else if (frm.altezza.value == "")
    {
     errorString = "l'altezza è obbligatoria";
     alert(errorString);
     frm.altezza.focus();
     ok = 1;
    }

else if (!isnumeric_field(frm.altezza.value))
    {
     errorString = "L'altezza deve essere espressa in cifre";
     alert(errorString);
     frm.altezza.focus();
     ok = 1;
    }

else if (frm.peso.value == "")
    {
     errorString = "Il peso è obbligatorio";
     alert(errorString);
     frm.peso.focus();
     ok = 1;
    }

else if (!isnumeric_field(frm.peso.value))
    {
     errorString = "Il peso deve essere espresso in cifre";
     alert(errorString);
     frm.peso.focus();
     ok = 1;
    }

else if (!result){
           errorString = "Inserisci un'indirizzo E-MAIL valido";
           alert(errorString);
           Ctrl.focus();
           ok = 1;
           }


if (ok == 0)
   frm.submit();
else
     return false;

}

if (frm.name == 'utente')
{

ok = 0;

Ctrl = frm.email;
result = false;
space_tokens = Ctrl.value.split(" ");
if (space_tokens.length == 1) {
at_tokens = Ctrl.value.split("@");
if (at_tokens.length == 2) {
if (at_tokens[1].length != 0) {
   right_dot_tokens = at_tokens[1].split(".");
   if (right_dot_tokens.length >= 2) {
   if (right_dot_tokens[1].length != 0) {
   result=true;}}}}}

if (frm.nome.value == "")
    {
     errorString = "Il NOME è obbligatorio";
     alert(errorString);
     frm.nome.focus();
     ok = 1;
    }

else if (frm.cognome.value == "")
    {
     errorString = "Il COGNOME è obbligatorio";
     alert(errorString);
     frm.cognome.focus();
     ok = 1;
    }

else if (!result){
           errorString = "Inserisci un'indirizzo E-MAIL valido";
           alert(errorString);
           Ctrl.focus();
           ok = 1;
           }

else if (frm.provincia.value == "--")
    {
     errorString = "E' necessario selezionare la PROVINCIA";
     alert(errorString);
     frm.provincia.focus();
     ok = 1;
    }

else if (frm.comune.value == "")
    {
     errorString = "Il COMUNE è obbligatorio";
     alert(errorString);
     frm.comune.focus();
     ok = 1;
    }

else if (frm.indirizzo.value == "")
   {
     errorString = "L'INDIRIZZO è obbligatorio";
     alert(errorString);
     frm.indirizzo.focus();
     ok = 1;
    }

else if (frm.cap.value == "")
   {
     errorString = "Il CODICE di AVVIAMENTO POSTALE è obbligatorio";
     alert(errorString);
     frm.cap.focus();
     ok = 1;
    }

else if (frm.piva.value == "")
   {
     errorString = "Il CODICE FISCALE o la PARTITA IVA sono dati obbligatori";
     alert(errorString);
     frm.piva.focus();
     ok = 1;
    }

else if (!frm.privacy.checked)
   {
     errorString = "L'accettazione dell'informativa sulla privacy è necessaria per poter procedere con la registrazione";
     alert(errorString);
     frm.privacy.focus();
     ok = 1;
    }


if (ok == 0)
   return true;
else
   return false;

}


}
 
function verificaGiocaVinci()
{
if (nform.elements['nome'].value == "")
    {
     errorString = "Il nome è obbligatorio";
     alert(errorString);
     nform.elements['nome'].focus();
     return false;
    }

else if (nform.elements['cognome'].value == "")
    {
     errorString = "Il cognome è obbligatorio";
     alert(errorString);
     nform.elements['cognome'].focus();
     return false;
    }

else if (nform.elements['data_nascita'].value == "")
    {
     errorString = "La data di nascita è obbligatoria";
     alert(errorString);
     nform.elements['data_nascita'].focus();
     return false;
    }
else if (nform.elements['comune_nascita'].value == "")
    {
     errorString = "Il comune di nascita è obbligatorio";
     alert(errorString);
     nform.elements['comune_nascita'].focus();
     return false;
    }
else if (nform.elements['prov_nascita'].value == "--")
    {
     errorString = "La provincia di nascita è obbligatoria";
     alert(errorString);
     nform.elements['prov_nascita'].focus();
     return false;
    }
else if (nform.elements['comune_res'].value == "")
    {
     errorString = "Il comune di residenza è obbligatorio";
     alert(errorString);
     nform.elements['comune_res'].focus();
     return false;
    }
else if (nform.elements['prov_res'].value == "--")
    {
     errorString = "La provincia di residenza è obbligatoria";
     alert(errorString);
     nform.elements['prov_res'].focus();
     return false;
    }
else if (nform.elements['indirizzo_res'].value == "")
    {
     errorString = "L'indirizzo di residenza è obbligatorio";
     alert(errorString);
     nform.elements['indirizzo_res'].focus();
     return false;
    }
else if (nform.elements['cap'].value == "")
    {
     errorString = "Il cap è obbligatorio";
     alert(errorString);
     nform.elements['cap'].focus();
     return false;
    }
else if (nform.elements['cellulare'].value == "")
    {
     errorString = "Il cellulare è obbligatorio";
     alert(errorString);
     nform.elements['cellulare'].focus();
     return false;
    }
else if (nform.elements['email'].value == "")
    {
     errorString = "la mail è obbligatoria";
     alert(errorString);
     nform.elements['email'].focus();
     return false;
    }
		
	return true
} 

function verifica(frm)
{
	
if (frm.name == 'registra')
{
	ok = 0;

	Ctrl = frm.elements["email"];
	result = false;
	space_tokens = Ctrl.value.split(" ");
	if (space_tokens.length == 1) {
		at_tokens = Ctrl.value.split("@");
		if (at_tokens.length == 2) {
			if (at_tokens[1].length != 0) {
		   		right_dot_tokens = at_tokens[1].split(".");
				if (right_dot_tokens.length >= 2) {
	   				if (right_dot_tokens[1].length != 0) {
						result=true;
					}
				}
			}
		}
	}
	
if (frm.nickname.value == "")
    {
     errorString = "Il NICKNAME è obbligatorio";
     alert(errorString);
     frm.nickname.focus();
     ok = 1;
    }

else if (frm.nome.value == "")
    {
     errorString = "Il NOME è obbligatorio";
     alert(errorString);
     frm.nome.focus();
     ok = 1;
    }

else if (frm.cognome.value == "")
    {
     errorString = "Il COGNOME è obbligatorio";
     alert(errorString);
     frm.cognome.focus();
     ok = 1;
    }

else if (frm.giorno.value == "--"  || frm.mese.value == "--" || frm.anno.value == "----")
    {
     errorString = "La data di nascita NON è completa";
     alert(errorString);
     frm.giorno.focus();
     ok = 1;
    }

else if ((frm.sesso[0].checked == false) && (frm.sesso[1].checked == false))
    {
     errorString = "E' necessario indicare il SESSO";
     alert(errorString);
     ok = 1;
    }

else if (frm.citta.value == "")
    {
     errorString = "La CITTA' è obbligatoria";
     alert(errorString);
     frm.citta.focus();
     ok = 1;
    }

else if (frm.cap.value == "")
    {
     errorString = "Il Codice Avviamento Postale (CAP) è obbligatorio";
     alert(errorString);
     frm.cap.focus();
     ok = 1;
    }

else if (!isnumeric_field(frm.cap.value))
    {
     errorString = "Il CODICE DI AVVIAMENTO POSTALE (CAP) non è valido";
     alert(errorString);
     frm.cap.focus();
     ok = 1;
    }


else if (frm.provincia.value == "--")
    {
     errorString = "La PROVINCIA è obbligatoria";
     alert(errorString);
     frm.provincia.focus();
     ok = 1;
    }

else if (!result)
    {
     errorString = "Inserisci un'indirizzo E-MAIL valido";
     alert(errorString);
     Ctrl.focus();
     ok = 1;
    }

else if (frm.cellulare.value == "")
    {
     errorString = "Il numero di CELLULARE è obbligatorio";
     alert(errorString);
     frm.cellulare.focus();
     ok = 1;
    }

else if (frm.cellulare.value != "" && !isnumeric_field(frm.cellulare.value))
    {
     errorString = "Il numero di CELLULARE non è valido";
     alert(errorString);
     frm.cellulare.focus();
     ok = 1;
    }

else if (frm.regolamento.value == "NO")
    {
     	errorString = "L'accettazione del regolamento è necessaria per poter procedere con la registrazione";
     	alert(errorString);
     	ok = 1;
    }
else if (frm.tv[0].checked == false && frm.tv[1].checked == false && frm.tv[2].checked == false && frm.tv[3].checked == false)
    {
     	errorString = "E' necessario indicare dove vedi Music Box";
     	alert(errorString);
     	ok = 1;
    }

if (ok == 1)
   	return false;
	}
}

function verificaMod(frm)
{
	
if (frm.name == 'registra')
{
	ok = 0;

	Ctrl = frm.elements["email"];
	result = false;
	space_tokens = Ctrl.value.split(" ");
	if (space_tokens.length == 1) {
		at_tokens = Ctrl.value.split("@");
		if (at_tokens.length == 2) {
			if (at_tokens[1].length != 0) {
		   		right_dot_tokens = at_tokens[1].split(".");
				if (right_dot_tokens.length >= 2) {
	   				if (right_dot_tokens[1].length != 0) {
						result=true;
					}
				}
			}
		}
	}

if (frm.password.value == "")
    {
     errorString = "La PASSSWORD è obbligatoria";
     alert(errorString);
     frm.password.focus();
     ok = 1;
    }
	
else if (frm.giorno.value == "--"  || frm.mese.value == "--" || frm.anno.value == "----")
    {
     errorString = "La data di nascita NON è completa";
     alert(errorString);
     frm.giorno.focus();
     ok = 1;
    }

else if ((frm.elements["sesso"][0].checked == false) && (frm.elements["sesso"][1].checked == false))
    {
     errorString = "E' necessario indicare il SESSO";
     alert(errorString);
     ok = 1;
    }

else if (frm.citta.value == "")
    {
     errorString = "La CITTA' è obbligatoria";
     alert(errorString);
     frm.citta.focus();
     ok = 1;
    }

else if (frm.cap.value == "")
    {
     errorString = "Il Codice Avviamento Postale (CAP) è obbligatorio";
     alert(errorString);
     frm.cap.focus();
     ok = 1;
    }

else if (!isnumeric_field(frm.cap.value))
    {
     errorString = "Il CODICE DI AVVIAMENTO POSTALE (CAP) non è valido";
     alert(errorString);
     frm.cap.focus();
     ok = 1;
    }


else if (frm.provincia.value == "--")
    {
     errorString = "La PROVINCIA è obbligatoria";
     alert(errorString);
     frm.provincia.focus();
     ok = 1;
    }

else if (!result){
           errorString = "Inserisci un'indirizzo E-MAIL valido";
           alert(errorString);
           Ctrl.focus();
           ok = 1;
           }

else if (frm.cellulare.value != "" && !isnumeric_field(frm.cellulare.value))
    {
     errorString = "Il numero di CELLULARE non è valido";
     alert(errorString);
     frm.cellulare.focus();
     ok = 1;
    }
if (ok == 1)
   	return false;
	}
}
function startchat(winflash, x, y, bar)
{
window.open(winflash,'CHAT','scrollbars='+bar+',screenX=150,screenY=50,left=150,top=50,resizable=0,menubar=0,toolbar=0,status=0,width='+x+',height='+y);
}

function changeto(e,highlightcolor){
source=ie? event.srcElement : e.target
if (source.tagName=="TABLE")
return
while(source.tagName!=highlightbehavior && source.tagName!="HTML")
source=ns6? source.parentNode : source.parentElement
if (source.style.backgroundColor!=highlightcolor&&source.id!="ignore")
source.style.backgroundColor=highlightcolor
}

function openflash(winflash, x, y)
{
ind=winflash;
window.open(ind,'','scrollbars=1,screenX=150,screenY=50,left=150,top=50,resizable=0,menubar=0,toolbar=0,status=0,width='+x+',height='+y);
}
