var intStr = "0123456789 -/";

function checkCheck(){

	var checkCounter = 0;
	for (i = 0;  i < 4;  i++){
		t = document.getElementsByName("op["+i+"]");
		if (t[0].checked){
			checkCounter = checkCounter + 1;
		}
	}

	if (checkCounter == 0){
		return false;
	}
	return true;
}

function changeURL(url){
	window.opener.location = url;
	window.close();
}

function checkAll(){
	var name = document.getElementById("name").value;
	var num = document.getElementById("num").value;
//	var speed = document.getElementById("speed").value;

	if(num == "" || (num> 30 || num < 10) || !isInt(num)){
		alert("Numero dev'essere compreso tra 10 e 30\n---------------------------------------\nNumber must be set between 2 and 30");
		document.getElementById("num").value	 = "20";
		return false;
	}

	if(!checkCheck()){
		alert("Selezionare almeno una operazione\n---------------------------------------\nSelect at least one operation");
		return false;
	}

//	if(speed == "" || (speed > 30 || speed < 2) || !isInt(speed)){
//		alert("La velocità dev'essere compresa tra 2 e 30\n---------------------------------------\nSpeed must be set between 2 and 30");
//		document.getElementById("speed").value	 = "2";
//		return false;
//	}

	if(trim(name)==""){
		alert("Inserisci un nome valido!\n---------------------------------------\nInsert a valid name!");
		document.getElementById("name").value = "Player 1";
		return false;
	}

	document.getElementById("name").value = trim(name);
 window.open('http://www.lyra.net/fabio/giochi/sendTo.php', 'Popup','width=770,height=570,left=150,top=150,scrollbars=no,resizable=no');
document.getElementById('f1').target='Popup';
return true;

}

function isInt(myS){
	for (var i = 0; i < myS.length; i++) {
   		if (intStr.indexOf(myS.charAt(i)) < 0) {
         	return false;
        }
    }
	return true;
}


function trim(stringa){

	while (stringa.substring(0,1) == ' '){
		stringa = stringa.substring(1, stringa.length);
	}

	while (stringa.substring(stringa.length-1, stringa.length) == ' '){
		stringa = stringa.substring(0,stringa.length-1);
	}

	return stringa;
}