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,0,0\"");
   	document.write("width=\""+w+"\" height=\""+h+"\">");
    document.write("<param name='movie' value='"+swf+"' />\n");
    document.write("<param name='quality' value='high' /><param name='wmode' value='transparent' />\n");
    document.write("<embed src=\""+swf+"\" quality=\"high\" wmode=\"transparent\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\""+w+"\" height=\""+h+"\"></embed>");
    document.write("</object>\n");
}

function evidenzia(id, w, bg){
	var curleft = curtop = 0;
	if(id!=""){
		
		obj = document.getElementById(id);
		if (obj.offsetParent) {
			curleft = obj.offsetLeft;
			curtop = obj.offsetTop;
			while (obj = obj.offsetParent) {
				curleft += obj.offsetLeft;
				curtop += obj.offsetTop;
			}
			
			if(bg!="") document.getElementById('box_onmouse').style.background = '#' + bg;
			if(w!="") document.getElementById('box_onmouse').style.width = w + 'px';
			
			document.getElementById('box_onmouse').style.left = (curleft - 8) + 'px';
			document.getElementById('box_onmouse').style.top = (curtop - 2) + 'px';
			document.getElementById('box_onmouse').style.display = 'block';
		}
		
	}
	
	else{
		document.getElementById('box_onmouse').style.background = '#d2ddb7';
		document.getElementById('box_onmouse').style.width = '170px';
		document.getElementById('box_onmouse').style.left = 0;
		document.getElementById('box_onmouse').style.top = 0;
		document.getElementById('box_onmouse').style.display = 'none';
	}
}

function seleziona_voce(id, w, bg){
	var curleft = curtop = 0;
	
	obj = document.getElementById(id);
	if (obj.offsetParent) {
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
		
		if(bg!="") document.getElementById('box_onmouse_sel').style.background = '#' + bg;
		if(w!="") document.getElementById('box_onmouse_sel').style.width = w + 'px';
		
		document.getElementById('box_onmouse_sel').style.left = (curleft - 8) + 'px';
		document.getElementById('box_onmouse_sel').style.top = (curtop - 2) + 'px';
		document.getElementById('box_onmouse_sel').style.display = 'block';
	}
		
}

var indirizzoEmail;

function checkEmailAddress(field) {

     var goodEmail = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.biz)|(\..{2,2}))$)\b/gi);
     
     if (goodEmail){
        indirizzoEmail = true
     } 
     else {
        alert('Inserire un indirizzo email valido');
        field.focus();
        field.select();
        indirizzoEmail = false;
        }
  	return indirizzoEmail;
}

function submitSearch(){
	var thisForm = document.form_ricerca;
	
	if(thisForm.search_key.value==''){
		alert("inserire una chiave di ricerca");
		thisForm.search_key.focus();
		return;
	}
	
	thisForm.submit();
}

function controlloLogin(){
	thisform = document.form_login;
	
	if(thisform.email.value==''){
		alert("inserire un indirizzo email");
		thisform.email.focus();
		return;
	}
	
	if(!checkEmailAddress(thisform.email)){
		return;
	}
	
	if(thisform.password.value==''){
		alert("inserire la password");
		thisform.password.focus();
		return;
	}
	
	thisform.action = "_class/azioni.class.php";
	thisform.submit();
}

function controlloNewpass(){
	thisform = document.form_newpass;
	
	if(thisform.email.value==''){
		alert("inserire un indirizzo email");
		thisform.email.focus();
		return;
	}
	
	if(!checkEmailAddress(thisform.email)){
		return;
	}
	
	thisform.action = "_class/azioni.class.php";
	thisform.submit();
}

function loadRubricaCacciatore(idrubrica){
	thisform = document.form_cacciatore;
	
	if(idrubrica != ''){
		thisform.method = "GET";
		thisform.action = "ilcacciatore_list.php";
		thisform.submit();
	}
}

function loadRegione(){
	thisform = document.form_webregioni;
	
	if(thisform.id_regione.selectedIndex != 0){
		thisform.method = "GET";
		thisform.action = "regione.php";
		thisform.submit();
	}
}

function loadRegioneMap(id_regione){
	thisform = document.form_webregioni;
	
	thisform.id_regione.selectedIndex = id_regione;
	thisform.method = "GET";
	thisform.action = "regione.php";
	thisform.submit();

}

function loadRegioneProv(id_regione){
	var curleft = curtop = 0;
	
	for(var c=1; c<=20; c++){
		objHide = document.getElementById('regione_'+c);
		objHide.style.display = 'none';
	}
	
	objSel = document.getElementById('regione_'+id_regione);
	objImage = document.getElementById('italia');
	
	if (objImage.offsetParent) {
		curleft = objImage.offsetLeft;
		curtop = objImage.offsetTop;
		while (objImage = objImage.offsetParent) {
			curleft += objImage.offsetLeft;
			curtop += objImage.offsetTop;
		}
	}
	
	curleft = curleft + 300;
	curtop = curtop + 50;
	
	objSel.style.left = curleft + "px";
	objSel.style.top = curtop + "px";
	objSel.style.display = 'block';
	
}

function controlCharNumber(num, field){
	actualchar = field.value.length;
	if(actualchar > num){
		field.value = field.value.substring(0,(actualchar-1));
		alert("Hai superato il limite massimo di caratteri disponibili");
		return;
	}
}

function controlVotoSondaggio(thisform){
	
	var check = false;
	
	for(var i=0; i<10; i++){
		if(thisform.sondaggio_risp[i])
			if(thisform.sondaggio_risp[i].checked) check=true;
	}
	
	if(!check){
		alert("Selezionare una voce del sondaggio");
		return;
	}
	else {
		thisform.action = '_class/azioni.class.php';
		thisform.submit();
	}
}

function controlInvioQuest(){
	thisForm = document.form_questionario;
	nd = thisForm.nd.value;
	
	for(var i=0; i<nd; i++){
		var check = false;
		
		stringa = "rispo"+i;
		for( var h=0; h<thisForm.elements.length; h++){
			fieldname = thisForm.elements[h].name;
			if(fieldname.search(stringa) != "-1"){
				if(thisForm.elements[h].checked == true)
					check = true;
			}
		}
		
		if(!check){
			alert("Compilare tutte le domande");
			return;
		}
	}
	thisForm.action = '_class/azioni.class.php';
	thisForm.submit();
}

function openCredits(){
	var stile = "top=10, left=10, width=300, height=170, status=no, menubar=no, toolbar=no scrollbar=no";
	window.open("http://www.federcaccia.org/credits.php", "credits", stile);
}