




/*// BROWSER UPDATE ////////////////////////////////////////////////////////////////////////////////////*/
$(document).ready(function(){	/* Lo script viene eseguito solo quando la pagina è stata caricata completamente */

	if($.browser.msie && $.browser.version<'7.0')	/* Se è internet explorer v.6 o inferiore */
		$('#browser_update','html body')
			.fadeIn('slow')						/* fai comparire la barra */

	$('#browser_update_close','html body #browser_update').click(function(){	/* Se l'utente clicca sul tasto di chiusura */
		$('#browser_update','html body')							/* La barra */
			.fadeOut('slow')										/* e ritorna invisibile */
	})

	/* E' più pratico far aprire la pagina di download in un'altra finestra,
	   ma dato che l'attributo target non è più considerato valido dal w3c
	   è meglio impostarlo via javascript */
	$('.browser_download','html body #browser_update').attr('target','_blank')
})






/*// APRI POPUP ////////////////////////////////////////////////////////////////////////////////////*/
var pagina=null;
function apriPopup(url,w,h){
	x=screen.width/2-w/2;
	y=screen.height/2-h/2;
	if (pagina != null)
		pagina.close();
	pagina=window.open(url,"","fullscreen=no,status=no,toolbar=no,scrollbars=yes,width="+w+",height="+h+",top="+y+",left="+x);
}






/*//////////////////////////////////////////////////////////////////////////////////////*/
function ShowHide(passa_el){
	if(document.getElementById){
	var el = document.getElementById(passa_el);
		if(el.style.display != "block"){
				el.style.display = "block";
		}else{
			el.style.display = "none";
		}
	}
}





/*// CONTROLLO EMAIL ////////////////////////////////////////////////////////////////////////////////////*/
var whitespace = " \t\n\r";
function isEmail (s)
{
	if (isEmpty(s)) 
	   if (isEmail.arguments.length == 1) return defaultEmptyOK;
	   else return (isEmail.arguments[1] == true);
	if (isWhitespace(s)) return false;
	var i = 1;
	var sLength = s.length;
	while ((i < sLength) && (s.charAt(i) != "@")){ 
		i++
	}
	if ((i >= sLength) || (s.charAt(i) != "@")) return false;
	else i += 2;
	while ((i < sLength) && (s.charAt(i) != ".")){ 
		i++
	}
	if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
	else return true;
}
function isEmpty(s){
	return ((s == null) || (s.length == 0))
}
function isWhitespace (s){
	var i;
	if (isEmpty(s)) return true;
	for (i = 0; i < s.length; i++){   
		var c = s.charAt(i);
		if (whitespace.indexOf(c) == -1) return false;
	}
	return true;
}





/*// ANTI-SPAM ////////////////////////////////////////////////////////////////////////////////////*/
function DisplayMail(Server, Login, Display){
if ((Display.length == 0) || (Display.indexOf('@')+1)) {
document.write("<a href=" + "'mai" + "lto:" + Login + "@" + Server + "'>" + Login + "@" + Server + "</a>"); }
else {
document.write("<a href=" + "'mai" + "lto:" + Login + "@" + Server + "'>" + Display + "</a>"); }
}




/*// CAMPI FORM ////////////////////////////////////////////////////////////////////////////////////*/
	$(document).ready(function(){
		
		// REPLACE SELECT
		$("select").change(function () {
			var str_select_option = "";
			$(this).find("option:selected").each(function () {
				str_select_option += $(this).text() + " ";
			});
			$(this).prev("span.select_replace").text(str_select_option);
		})
		.change();
		$("select").keyup(function () {
			var str_select_option = "";
			$(this).find("option:selected").each(function () {
				str_select_option += $(this).text() + " ";
			});
			$(this).prev("span.select_replace").text(str_select_option);
		});
		$("select").focus(function () {
			$(this).prev("span.select_replace").addClass("selected");
		});
		$("select").blur(function () {
			$(this).prev("span.select_replace").removeClass("selected");
		});
		
		// REPLACE INPUT FILE
		$("input[type='file']").change(function () {
			var str_inputfile = $(this).val();
			var tmp = str_inputfile.split("\\");
			$(this).prev("span.inputfile_replace").text(tmp[tmp.length-1]);
		})
		.change();
		
		// FOCUS INPUT CERCA
		var tmp_value_input_cerca;
		$("#campo_cerca").focus(function(){tmp_value_input_cerca = $(this).val();$(this).val("");});
		$("#campo_cerca").blur(function(){if ($(this).val()==""){$(this).val(tmp_value_input_cerca);}});
		// FOCUS INPUT USERNAME
		var tmp_value_input_username;
		$("#campo_login_username").focus(function(){tmp_value_input_username = $(this).val();$(this).val("");});
		$("#campo_login_username").blur(function(){if ($(this).val()==""){$(this).val(tmp_value_input_username);}});
		// FOCUS INPUT PASSWORD
		var tmp_value_input_password;
		$("#campo_login_password").focus(function(){tmp_value_input_password = $(this).val();$(this).val("");});
		$("#campo_login_password").blur(function(){if ($(this).val()==""){$(this).val(tmp_value_input_password);}});
		// FOCUS INPUT USERNAME
		var tmp_value_input_login_username;
		$("#login_username_anteprima").focus(function(){tmp_value_input_login_username = $(this).val();$(this).val("");});
		$("#login_username_anteprima").blur(function(){if ($(this).val()==""){$(this).val(tmp_value_input_login_username);}});
		// FOCUS INPUT PASSWORD
		var tmp_value_input_login_password;
		$("#login_password_anteprima").focus(function(){tmp_value_input_login_password = $(this).val();$(this).val("");});
		$("#login_password_anteprima").blur(function(){if ($(this).val()==""){$(this).val(tmp_value_input_login_password);}});
		// FOCUS INPUT FILTRO
		var tmp_value_input_filtro;
		$("#filtro_ricette_txt").focus(function(){tmp_value_input_filtro = $(this).val();$(this).val("");});
		$("#filtro_ricette_txt").blur(function(){if ($(this).val()==""){$(this).val(tmp_value_input_filtro);}});
		
	});
	
	
	
	

/*// ANIMAZIONE BOX ANTEPRIMA ////////////////////////////////////////////////////////////////////////////////////*/
	$(document).ready(function(){

		//content_anteprima_top
		$("#content_anteprima_top .box_anteprima").hover(function(){
				$(this).find("#box_anteprima_prodotti").stop(true,true).animate({
					bottom: '0'
				  }, 1 );
				var sposta = $(this).outerHeight()-40;
				  $(this).stop(true,false).animate({
					marginBottom: "-"+sposta+"px"
				  }, 500 );
			},function(){
				$(this).find("#box_anteprima_prodotti").stop(true,false).animate({
					bottom: '30'
				  }, 800 );
				  $(this).stop(true,false).animate({
					marginBottom: "0px"
				  }, 500 );
			}
		);
		
		//content_anteprima_bottom
		$("#content_anteprima_bottom .box_anteprima").hover(function(){
				var sposta = $(this).outerHeight()-40;
				  $(this).stop(true,false).animate({
					marginTop: "-"+sposta+"px"
				  }, 500 );
			},function(){
				  $(this).stop(true,false).animate({
					marginTop: "0px"
				  }, 500 );
			}
		);

	});
	
	
/*// ANIMAZIONE BOX EVIDENZIA HOME ////////////////////////////////////////////////////////////////////////////////////*/
	function anim_box_home(){
		$('#box_evidenzia').fadeOut(1500,function() {
		  $(this).fadeIn(1500);
		});
	};
	$(document).ready(function(){
					
		var div_evidenzia = $(document.createElement('div')).attr("id","box_evidenzia").css({
			position:"absolute",
			top:"-10px",
			left:"232px",
			width:"242px",
			height:"319px",
			background:"#C30A1D"
		});	
		$("#content_anteprima_middle .box_anteprima.box2di4").before(div_evidenzia);		   
		var tempoanim = setInterval("anim_box_home()",3000);					   
	});
	
	
	
	
	
	

/*// PLAY PAUSE VIDEO BG ////////////////////////////////////////////////////////////////////////////////////*/
function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
    return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }
}
function stopVideo() {
	var flashMovie=getFlashMovieObject("bg_flash");
	flashMovie.SetVariable("/:disabilita_video", "true");
	flashMovie.GotoFrame(3);
	document.getElementById("")
	$("#video_controllo_pause").hide();
	$("#video_controllo_play").show();
	setCookieVideo("true");
}
function playVideo() {
	var flashMovie=getFlashMovieObject("bg_flash");
	flashMovie.SetVariable("/:disabilita_video", "false");
	flashMovie.GotoFrame(3);
	$("#video_controllo_pause").show();
	$("#video_controllo_play").hide();
	setCookieVideo("false");
}

function setCookieVideo(disattivato){
	if(disattivato != ''){
		var dataOggi = new Date()
		var dataExpires = new Date()
		var durataGiorniCookieVideo=30;
		dataExpires.setTime(dataOggi.getTime() + 24 * durataGiorniCookieVideo * 3600000);
		document.cookie = 'Despar_Video'+'='+escape(disattivato)+''+'; path=/'+'; expires='+dataExpires.toGMTString();
	}
}


/*// COOKIE CAMBIO LINGUA NAVIGAZIONE ///////////////////////////////////////////////////////////////////////*/
function cambiaLingua(lingua){
	setCookieLingua(lingua)
	document.location=base_url+lingua+"/index.php";
}

function setCookieLingua(lingua){
	if(lingua != ''){
		var dataOggi = new Date()
		var dataExpires = new Date()
		var durataGiorniCookieLingua=30;
		dataExpires.setTime(dataOggi.getTime() + 24 * durataGiorniCookieLingua * 3600000);
		document.cookie = 'Despar_Lingua'+'='+escape(lingua)+''+'; path=/'+'; expires='+dataExpires.toGMTString();
	}
}


/*// LOGIN MY DESPAR ////////////////////////////////////////////////////////////////////////////////////*/


function send_bottom_login(){
	if(document.getElementById('campo_login_username').value!=='' && document.getElementById('campo_login_username').value!=='Username' && document.getElementById('campo_login_password').value!=='' && document.getElementById('campo_login_password').value!=='Password')
	{
		var psw_md5="";
		psw_md5=MD5(document.getElementById('campo_login_password').value);
		//document.getElementById('campo_login_password').value=psw_md5;
		document.getElementById('form_bottom_login').submit();
	}
}
