// ################################ ROLLOVER VOCI ########################################

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// ################################ GESTIONE MENU ########################################

var menu = new Array('submenu1','submenu2','submenu3');
function showHide(obj){
for(i=0;i<3;i++){
  document.getElementById(menu[i]).style.display="none";
 }
  document.getElementById(obj).style.display="block";
}

function show(obj){
 document.getElementById(obj).style.display="block";
}

function hide(obj){
 document.getElementById(obj).style.display="none";
}

function showV2(obj, displayTipe){
 document.getElementById(obj).style.display = displayTipe;
}


// ################################### POPUP ##############################################

function popup(URL,NOME,WIDTH,HEIGHT,PROPRIETA) {
	
	//alert(PROPRIETA);
	if(PROPRIETA == ''){
		PROPRIETA = 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0';
	}
	win = window.open(URL,NOME,PROPRIETA + ',width=' + WIDTH + ',height=' + HEIGHT + '');
	
	//qui ridimensiono il popup...così se lo stesso popup è già aperto gli cambio le dimensioni...
	H = parseInt(HEIGHT) + 59; 
	W = parseInt(WIDTH) + 10;
	win.resizeTo(W,H);
	win.focus();
}

function popup2(URL,NOME,IMPOSTAZIONI) {
	window.open(URL,NOME,IMPOSTAZIONI);
}

// ########################## TEXT COUNTER PER CONTATTI ###################################

function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) { // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
		// otherwise, update 'characters left' counter
	} else { 
		countfield.value = maxlimit - field.value.length;
	}
}

// ########################## CONTROLLO PULSANTE INVIO FORM ###################################
function submitForm(EVENT, FORM){
	if(EVENT.keyCode == 13){
		document[FORM].submit();
	}
}


// ########################## POPUP SCHEDE STATICHE ###################################
function loadinparent(url, closeSelf){
     self.opener.location = url;
     self.opener.focus();
	 if(closeSelf) self.close();
     }

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}


function decision(MESSAGGIO, URL){
	if(confirm(MESSAGGIO)) location.href = URL;
}

// ho voglia di te

function scegliDestinatario(CHI){
	
	if(CHI == 'Riccardo Scamarcio'){
		showV2('R','inline');
		hide('L');
		hide('K');
		hide('N');
	} else if(CHI == 'Laura Chiatti'){
		hide('R');
		showV2('L','inline');
		hide('K');
		hide('N');
	} else if(CHI == 'Katy Saunders'){
		hide('R');
		hide('L');
		showV2('K','inline');	
		hide('N');
	} else {
		hide('R');
		hide('L');
		hide('K');
		showV2('N','inline');	
		
	}
	document.formDomanda.destinatario.value = CHI;
}

function showHide2(ID){
	if(document.getElementById(ID).style.display == 'inline' || document.getElementById(ID).style.display == 'block'){
		document.getElementById(ID).style.display = 'none';
	} else {
		document.getElementById(ID).style.display = 'block';
	}
}	

function showTextareaAltro(TEXTAREA, OPTION, ALTRO, ALTRO_VALORE){
	var check = document.getElementById(OPTION);
	var text = document.getElementById(TEXTAREA);
	var altro = document.getElementById(ALTRO);
	if(check.checked == true){
		text.style.display = 'block';
		altro.value = ALTRO_VALORE;
	} else {
		text.style.display = 'none';
		altro.value = 0;
	}
}

function checkTutti(FORM, STATO){
	var form = document.getElementById(FORM);
	for(i = 0 ; i < form.length ; i++){
		if(form[i].type == 'checkbox' && form[i].id != 'altro' && form[i].disabled == false){
	  		form[i].checked = STATO;
		}
	}
}

function controllaNazione(valoreProvincia) {
	// alert(valoreProvincia);
	if (valoreProvincia != 115 && valoreProvincia != 0) {


		 document.iscrizione.nazione.value = 106;
		 document.iscrizione.nazione.disabled = true;
		 
		 
	} else {
	   if (valoreProvincia == 115) {
		 
		 	for (var i=0, option; option = document.iscrizione.nazione.options[i]; i++) {
        	if (option.value == 106) {
			   	   option.disabled = true;
   			   document.iscrizione.nazione.value = 0;
        	}
			}


		 
		 } else {
		 
		 	for (var i=0, option; option = document.iscrizione.nazione.options[i]; i++) {
        	if (option.value == 106) {
			   	   option.disabled = false;
        	}
			}
		 
		 }
		 document.iscrizione.nazione.disabled = false;
	}
}

function ricercaAvanzata(){

    	if(document.getElementById('tipo_ricerca_dvd').checked == true){
    		action = 'ricerca-avanzata.php';
    	} else {
    		action = 'ricerca-avanzata-videogames.php';
    	}
    	
    	document.getElementById('form_ricerca_avanzata_side').action = action;
    	document.getElementById('form_ricerca_avanzata_side').submit();
	
	
	
	
}

function ricercaAvanzata2(EVENT,FORM) {

	if(EVENT.keyCode == 13){
		
		if(document.getElementById('tipo_ricerca_dvd').checked == true){
    		action = 'ricerca-avanzata.php';
    	} else {
    		action = 'ricerca-avanzata-videogames.php';
    	}
    	
    	document.getElementById('form_ricerca_avanzata_side').action = action;
    	document.getElementById('form_ricerca_avanzata_side').submit();
		
	}	

}


$(document).ready(function() {
	$("#menuh2 li").hover(function(){
		$(this).find("img").attr("src", $(this).find("img").attr("src").replace("-a.", "-b."));
	}, function(){
		$(this).find("img").attr("src", $(this).find("img").attr("src").replace("-b.", "-a."));
	});
	
	$("#menu2 li").hover(function(){
		$(this).find("img").attr("src", $(this).find("img").attr("src").replace("-a.", "-b."));
	}, function(){
		$(this).find("img").attr("src", $(this).find("img").attr("src").replace("-b.", "-a."));
	});
	
	
	$("#menu img.swap").hover(function(){
		$(this).attr("src", $(this).attr("src").replace("_a.", "_b."));
	}, function(){
		$(this).attr("src", $(this).attr("src").replace("_b.", "_a."));
	});
	
	
	$("#l2N").mousemove(function(){
		$("#submenu1").show();
	});
	$("#l2N").hover(function(){
	}, function(){
		$("#submenu1").hide();
	});
	$("#submenu1").hover(function(){
		$("#submenu1").show();
	}, function(){
		$("#submenu1").hide();
	});
	
	
	
	$("#l6N").mousemove(function(){
		$("#submenu4").show();
	});
	$("#l6N").hover(function(){
	}, function(){
		$("#submenu4").hide();
	});
	$("#submenu4").hover(function(){
		$("#submenu4").show();
	}, function(){
		$("#submenu4").hide();
	});
	
	
	
	$("#l3N").mousemove(function(){
		$("#submenu2").show();
	});
	$("#l3N").hover(function(){
	}, function(){
		$("#submenu2").hide();
	});
	$("#submenu2").hover(function(){
		$("#submenu2").show();
	}, function(){
		$("#submenu2").hide();
	});
	
	
	
	$("#l4N").mousemove(function(){
		$("#submenu3").show();
	});
	$("#l4N").hover(function(){
	}, function(){
		$("#submenu3").hide();
	});
	$("#submenu3").hover(function(){
		$("#submenu3").show();
	}, function(){
		$("#submenu3").hide();
	});
	
});

