function checkUsr() {
	var url = document.getElementById('user').value;
	getPage('checkusr.php?url='+url+'&box=', 'usrcheked', '1');
}

function checkMail() {
	var mail = document.getElementById('email').value;
	getPage('checkusr.php?url='+mail+'&box=', 'mailcheked', '2');
}

function Modulo() {
//var nome = document.modulo.nome.value;
//var cognome = document.modulo.cognome.value;
var user = document.modulo.user.value;
var password = document.modulo.password.value;
var conferma = document.modulo.conferma.value;
//var indirizzo = document.modulo.indirizzo.value;
//var citta = document.modulo.citta.value;
//var provincia = document.modulo.provincia.value;
//var cap = document.modulo.cap.value;
var email = document.modulo.email.value;
var nascita = document.modulo.nascita.value;
var sex = document.modulo.sex.value;
var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
var usrcheck = document.modulo.usrch.value;
var mailcheck = document.modulo.mailch.value;

/*
if ((nome == "") || (nome == "undefined")) {
   alert("Il campo Nome è obbligatorio.");
   document.modulo.nome.focus();
   return false;
}

else if ((cognome == "") || (cognome == "undefined")) {
   alert("Il campo Cognome è obbligatorio.");
   document.modulo.cognome.focus();
   return false;
}

else if ((indirizzo == "") || (indirizzo == "undefined")) {
   alert("Il campo Indirizzo è obbligatorio.");
   document.modulo.indirizzo.focus();
   return false;
}

else if ((citta == "") || (citta == "undefined")) {
   alert("Il campo Nome è obbligatorio.");
   document.modulo.citta.focus();
   return false;
}

else if ((provincia == "") || (provincia == "undefined")) {
   alert("Il campo Provincia è obbligatorio.");
   document.modulo.provincia.focus();
   return false;
}

else if ((cap == "") || (cap == "undefined")) {
   alert("Il campo CAP è obbligatorio.");
   document.modulo.cap.focus();
   return false;
}
*/
if (document.modulo.termini.checked==false) {
   alert("Devi Accettare i Termini e le Condizioni");
   document.modulo.termini.focus();
   return false;
}

else if ((user == "") || (user == "undefined")) {
   alert("Il campo User è obbligatorio.");
   document.modulo.user.focus();
   return false;
}

else if (usrcheck != "1") {
   alert("L'UserName che hai inserito non è disponibile");
   document.modulo.user.focus();
   return false;
}
/*
else if ((citta == "") || (citta == "undefined")) {
   alert("Il campo Città è obbligatorio.");
   document.modulo.citta.focus();
   return false;
}
*/
else if ((password == "") || (password == "undefined")) {
   alert("Il campo Password è obbligatorio.");
   document.modulo.password.focus();
   return false;
}

else if ((nascita == "") || (nascita == "undefined")) {
   alert("Il campo Nascita è obbligatorio.");
   document.modulo.nascita.focus();
   return false;
}

else if (password != conferma) {
   alert("La password confermata è diversa da quella scelta, controllare.");
   document.modulo.conferma.value = "";
   document.modulo.conferma.focus();
   return false;
}

else if (document.modulo.nascita.value.substring(2,3) != "/" ||
   document.modulo.nascita.value.substring(5,6) != "/" ||
   isNaN(document.modulo.nascita.value.substring(0,2)) ||
   isNaN(document.modulo.nascita.value.substring(3,5)) ||
   isNaN(document.modulo.nascita.value.substring(6,10))) {
      alert("Inserire nascita in formato gg/mm/aaaa");
      document.modulo.nascita.value = "";
      document.modulo.nascita.focus();
      return false;
} else if (document.modulo.nascita.value.substring(0,2) > 31) {
   alert("Impossibile utilizzare un valore superiore a 31 per i giorni");
   document.modulo.nascita.select();
   return false;
} else if (document.modulo.nascita.value.substring(3,5) > 12) {
   alert("Impossibile utilizzare un valore superiore a 12 per i mesi");
   document.modulo.nascita.value = "";
   document.modulo.nascita.focus();
   return false;
} else if (document.modulo.nascita.value.substring(6,10) < 1900) {
   alert("Impossibile utilizzare un valore inferiore a 1900 per l'anno");
   document.modulo.nascita.value = "";
   document.modulo.nascita.focus();
   return false;
}
else if (!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
   alert("Inserire un indirizzo email corretto.");
   document.modulo.email.select();
   return false;
}

else if (mailcheck != 1) {
   alert("L'Email che hai inserito non è disponibile");
   document.modulo.email.focus();
   return false;
}

else {
  document.modulo.action = "iscriviti.php";
  document.modulo.submit();
}
}

function takePwd() {
	var mail= document.take.mail.value;
	var reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	if (!reg_exp.test(mail) || (mail == "") || (mail == "undefined")) {
   		alert("Inserire un indirizzo email corretto.");
	} else getPage('takepwd.php?mail='+mail+'&box=','takepwd','');
}

function mail(idvid,idus) {
	mails = document.video_share_form.mails.value;
	msg = document.video_share_form.mails.msg;
	var url  = 'inviavideo.php';
    var pars = 'mails='+mails+'&video='+idvid+'&user='+idus+'&msg='+msg;
    new Ajax.Request(url, {parameters:pars, onComplete:
        function(r) {
            var urlimg = r.responseText;
			document.getElementById('responseinvio').innerHTML = urlimg;
        }
    });
}

function mailfoto(idvid,idus) {
	mails = document.video_share_form.mails.value;
	msg = document.video_share_form.mails.msg;
	var url  = 'inviafoto.php';
    var pars = 'mails='+mails+'&foto='+idvid+'&user='+idus+'&msg='+msg;
    new Ajax.Request(url, {parameters:pars, onComplete:
        function(r) {
            var urlimg = r.responseText;
			document.getElementById('responseinvio').innerHTML = urlimg;
        }
    });
}

function changeFiledxList(id,tag,c,t) {
	if(id==0) {
		var url  = 'filecorrelati.php';
		var pars = 'tag='+tag+'&c='+c+'&t='+t;
		new Ajax.Request(url, {parameters:pars, onComplete:
			function(r) {
				document.getElementById('allvideo').innerHTML = r.responseText;
			}
		});
		document.getElementById('filecorr').style.backgroundColor='#FAD400';
		document.getElementById('filecanal').style.backgroundColor='#FAD400';
	} else {
		var url  = 'filecanale.php';
		var pars = 'c='+c;
		new Ajax.Request(url, {parameters:pars, onComplete:
			function(r) {
				document.getElementById('allvideo').innerHTML = r.responseText;
			}
		});
		document.getElementById('filecorr').style.backgroundColor='#FAD400';
		document.getElementById('filecanal').style.backgroundColor='#FAD400';
	}
}

function getFormUp(tipo) {
	document.getElementById('formvideo').style.display = 'none';
	document.getElementById('formimage').style.display = 'none';
	document.getElementById('formaudio').style.display = 'none';
	document.getElementById('formpps').style.display = 'none';
	document.getElementById('formtext').style.display = 'none';
	document.getElementById('formflash').style.display = 'none';
	
	document.getElementById('form'+tipo).style.display = '';
}

function rankstar(i) {
	for(var j=i;j >= 0;j--) {
		document.getElementById('rank'+j).src='img/star.gif';
	}
}

function origrank(i) {
	for(var j=0;j < i;j++) {
		document.getElementById('rank'+j).src='img/star.gif';
	}
	for(var j=i;j < 5;j++) {
		document.getElementById('rank'+j).src='img/star2.gif';
	}
}

function rankvideo(i,idvid) {
	getPage('rankfile.php?Box=', i, idvid);
	document.getElementById('rankbox').innerHTML = 'Grazie per aver Votato';
}

function upVideo() {
	if(document.upvideo.tipofile.options[document.upvideo.tipofile.selectedIndex].value=="image") {
		var titolo = document.upvideo.NomeImg.value;
		if ((titolo == "") || (titolo == "undefined")) {
		   alert("Il campo Titolo e' obbligatorio.");
		   document.upvideo.NomeImg.focus();
		   return false;
		}

		else {
		  document.upvideo.action = "upload_now.php?t=image";
		  document.upvideo.submit();
		}
	}	
	
	if(document.upvideo.tipofile.options[document.upvideo.tipofile.selectedIndex].value=="video") {
		var titolo = document.upvideo.NomeVideo.value;
		if ((titolo == "") || (titolo == "undefined")) {
		   alert("Il campo Titolo e' obbligatorio.");
		   document.upvideo.NomeVideo.focus();
		   return false;
		}

		else {
		  document.upvideo.action = "upload_now.php?t=video";
		  document.upvideo.submit();
		}
	}	
	
}


function Modulo2() {
var nascita = document.modulo.Nascita.value;

if ((nascita == "") || (nascita == "undefined")) {
   alert("Il campo Nascita è obbligatorio.");
   document.modulo.Nascita.focus();
   return false;
}

else if (document.modulo.Nascita.value.substring(2,3) != "/" ||
   document.modulo.Nascita.value.substring(5,6) != "/" ||
   isNaN(document.modulo.Nascita.value.substring(0,2)) ||
   isNaN(document.modulo.Nascita.value.substring(3,5)) ||
   isNaN(document.modulo.Nascita.value.substring(6,10))) {
      alert("Inserire nascita in formato gg/mm/aaaa");
      document.modulo.Nascita.value = "";
      document.modulo.Nascita.focus();
      return false;
} else if (document.modulo.Nascita.value.substring(0,2) > 31) {
   alert("Impossibile utilizzare un valore superiore a 31 per i giorni");
   document.modulo.Nascita.select();
   return false;
} else if (document.modulo.Nascita.value.substring(3,5) > 12) {
   alert("Impossibile utilizzare un valore superiore a 12 per i mesi");
   document.modulo.Nascita.value = "";
   document.modulo.Nascita.focus();
   return false;
} else if (document.modulo.Nascita.value.substring(6,10) < 1900) {
   alert("Impossibile utilizzare un valore inferiore a 1900 per l'anno");
   document.modulo.Nascita.value = "";
   document.modulo.Nascita.focus();
   return false;
}
else {
  document.modulo.action = "newuserprofilo.php";
  document.modulo.submit();
}

}