var repswf="";
PEPS={};
PEPS.rollover={
	init:function(){this.preload();$(".ro").hover(function(){$(this).attr('src',PEPS.rollover.newimage($(this).attr('src')));},function(){$(this).attr('src',PEPS.rollover.oldimage($(this).attr('src')));});},
	preload:function(){$(window).bind('load',function(){$('.ro').each(function(key,elm){$('<img>').attr('src',PEPS.rollover.newimage($(this).attr('src')));});});},
	newimage:function(src){return src.substring(0,src.search(/(\.[a-z]+)$/))+'_o'+src.match(/(\.[a-z]+)$/)[0];},
	oldimage:function(src){return src.replace(/_o\./,'.');}
};
function init_main(pPos){
	
	PEPS.rollover.init();
	$("body").append("<div class='paninfo' id='tgt_info'><div style='position:fixed; width:530px; height:410px; left:50%; top:50%; margin-left:-265px; margin-top:-205px; z-index:78;'></div></div>");
	$("#tgt_info").fadeOut(0);
	
	$('.vc-menu a').fadeOut(0);
	
	$('.vc-menu').each(function(){
		$(this).mouseover(function(){
			$('a',this).fadeIn(0);
		})
		$(this).mouseout(function(){
			$('a',this).fadeOut(0);
		});
	})
}
function init(lev){
	if($.browser.msie && $.browser.version<7){location.href='update-your-browser.html';}
	
	repswf='<div style="position:absolute; left:200px;"><img onClick="openOfferte();" src="images/airplane.png" border="0"></div>';
	checkPage();
	
	PEPS.rollover.init();
	$("body").append("<div class='paninfo' id='tgt_info'><div style='position:fixed; width:530px; height:410px; left:50%; top:50%; margin-left:-265px; margin-top:-205px; z-index:78;'></div></div>");
	$("#tgt_info").fadeOut(0);
	

	if(lev==2){
		$('#airplane_sez').flash({src:'aereo.swf', width:'930', height:'150', allowscale:false, allowfullscreen:false,  wmode:"transparent", scale:"noscale"},{version:8});
	}
}
function checkPage(){
	var page=location.href.substring(location.href.lastIndexOf("/")+1,location.href.length);
	$("#menu li").each(function(){
		if($("a",$(this)).attr("href")==page){
			var src=$("a img",$(this)).attr("src");
			$("a img",$(this)).attr("src",src.substring(0,src.search(/(\.[a-z]+)$/))+'_o'+src.match(/(\.[a-z]+)$/)[0]).removeClass("ro");
			$(this).html($("a",$(this)).html());
			return false;
		}
	})
}
function pan_info(pVal){
	$.post('lib/pan_info.php',{id:pVal},function(data){
		$("#tgt_info div").html(data);
		$("#tgt_close").css("cursor","pointer");
		$("#tgt_close").click(function(){
			$("#tgt_info").fadeOut(function(){$("#tgt_info div").html("");});
			document.onmousewheel = null;  /* IE7, IE8 */
			if(document.addEventListener){ /* Chrome, Safari, Firefox */
				document.removeEventListener('DOMMouseScroll', stopWheel, false);
			}
		});
		initPan();
	});
}
function initPan(){
	$('#c_nome').focus(function(){if($(this).val()=='Nome Cognome'){$(this).val('');}}).blur(function(){if($(this).val()==''){$(this).val('Nome Cognome');}});
	$('#c_email').focus(function(){if($(this).val()=='E-mail'){$(this).val('');}}).blur(function(){if($(this).val()==''){$(this).val('E-mail');}});
	$('#c_messaggio').focus(function(){if($(this).val()=='scrivi qui la tua richiesta...'){$(this).val('');}}).blur(function(){if($(this).val()==''){$(this).val('scrivi qui la tua richiesta...');}});
	$('#invia').click(function(){
		$(".frm-cont").removeClass("login-error");
		var campi=new Array({c:'#c_nome',a:'Nome Cognome'},{c:'#c_email',a:'E-mail'},{c:'#c_messaggio',a:'scrivi qui la tua richiesta...'});
		var obj=new Object();
		var err=0;
		
		for(var i=0; i<campi.length; i++){
			if($.trim($(campi[i].c).val())==''||$.trim($(campi[i].c).val())==campi[i].a){
				$(campi[i].c).addClass("login-error");
				err++;
			}
			obj[campi[i].c.replace('#','')]=$(campi[i].c).val()
		}
		if(!$("#privacy").is(":checked")){
			alert("Devi accettare il trattamento dei dati personali!");
			return;
		}
		if(err==0){
			$.post('lib/php/sendmsg.php',obj,function(d){
				if(d==1){
					alert("Messaggio inviato correttamente");
					$(".frm-cont").removeClass("login-error");
					$(".frm-cont").val("");
				}else{
					alert("Si è verificato un errore!");
				}
			});
		}
	});
	$("#tgt_info").delay(300).fadeIn();
	document.onmousewheel = function(){ stopWheel(); } /* IE7, IE8 */
	if(document.addEventListener){ /* Chrome, Safari, Firefox */
		document.addEventListener('DOMMouseScroll', stopWheel, false);
	}

}

function stopWheel(e){
    if(!e){ e = window.event; } /* IE7, IE8, Chrome, Safari */
    if(e.preventDefault) { e.preventDefault(); } /* Chrome, Safari, Firefox */
    e.returnValue = false; /* IE7, IE8 */
}

function openOfferte(){
	$.post('lib/pan_offerte.php',{id:0},function(data){
		$("#tgt_info div").html(data);
		$("#tgt_close").css("cursor","pointer");
		$("#tgt_close").click(function(){
			$("#tgt_info").fadeOut(function(){$("#tgt_info div").html("");});
			document.onmousewheel = null;  /* IE7, IE8 */
			if(document.addEventListener){ /* Chrome, Safari, Firefox */
				document.removeEventListener('DOMMouseScroll', stopWheel, false);
			}
		});
		$("#tgt_info").delay(300).fadeIn();
		document.onmousewheel = function(){ stopWheel(); } /* IE7, IE8 */
		if(document.addEventListener){ /* Chrome, Safari, Firefox */
			document.addEventListener('DOMMouseScroll', stopWheel, false);
		}

	});
}
function openPrenota(){
	$.post('lib/pan_prenota.php',{id:0},function(data){
		$("#tgt_info div").html(data);
		$("#tgt_close").css("cursor","pointer");
		$("#tgt_close").click(function(){
			$("#tgt_info").fadeOut(function(){$("#tgt_info div").html("");});
			document.onmousewheel = null;  /* IE7, IE8 */
			if(document.addEventListener){ /* Chrome, Safari, Firefox */
				document.removeEventListener('DOMMouseScroll', stopWheel, false);
			}
		});
		$("#tgt_info").delay(300).fadeIn();
		document.onmousewheel = function(){ stopWheel(); } /* IE7, IE8 */
		if(document.addEventListener){ /* Chrome, Safari, Firefox */
			document.addEventListener('DOMMouseScroll', stopWheel, false);
		}

	});
}


function hoverlist(la){
	$('.btlista').each(function(){
		$(this).click(function(){
			if($(this).attr('id')=='lista'+la){
				location.href="lista.php?lista="+la;
			}else{
				$('#btlistacod_scroll').animate({left:0},0);
				$('#cod_list').removeClass("login-error");
				var o=$(this).offset();
				$('.btlistacod').offset({left:o.left,top:o.top}).fadeIn(1000);//+$(window).scrollTop()
				$('#id_list').val($(this).attr('id').replace('lista',''));
				$('#btlistacod_scroll').fadeIn();
			}
		});
	});
}

function ckcode(){
	$('#cod_list').removeClass("login-error");
	if($('#cod_list').val()!=""){
		$.post('lib/php/ckcode.php',{id_list:$('#id_list').val(),cod_list:$('#cod_list').val()},function(d){
			if(d>0){
				location.href="lista.php?lista="+d;
			}else{
				alert("Codice lista non valido!")
			}
		});
	}else{
		$('#cod_list').addClass("login-error");
	}
}
function recode(){
	$('#re_code').removeClass("login-error");
	if($('#re_code').val()!=""&&validateEmail($('#re_code').val())){
		$.post('lib/php/recode.php',{id_list:$('#id_list').val(),email:$('#re_code').val()},function(d){
			if(d==1){
				$('#btlistacod_scroll').animate({left:0},300,function(){
					alert("Richiesta inviata correttamente!");
				});
			}else{
				alert("Si è verificato un errore");
			}
		});
	}else{
		$('#re_code').addClass("login-error");
	}

}
function closecod(){
	$('#btlistacod_scroll').fadeOut(function(){
		$('.btlistacod').offset({left:0,top:0});
	});
}
function login(){
	$('.splogin').removeClass("login-error");
	if($('#l_user').val()!="" && $('#l_pwd').val()!=""){
		$.post('lib/php/login.php',{usr:$('#l_user').val(),pwd:$('#l_pwd').val()},function(d){
			if(d>0){
				//location.href="lista.php?lista="+d;
				location.href="liste-di-nozze.php";
			}else{
				$("#error_log").html("username o password errati");
			}
		});
	}else{
		if($('#l_user').val()=="")
			$('#l_user').addClass("login-error");
		if($('#l_pwd').val()=="")
			$('#l_pwd').addClass("login-error");
	}
}
function logout(){
	$.post('lib/php/login.php',{esci:1},function(data){
		location.href="liste-di-nozze.php";
	});
}

function sendQuota(){
	$('.spquota').removeClass('login-error');
	var err=0;
	var obj=new Object();
	$('.spquota').each(function(){
		obj[$(this).attr('id')]=$(this).val();
		if($(this).val()==""){
			err++;
			$(this).addClass('login-error');
		}
	});
	obj['telefono']=$('#telefono').val();
	obj['email']=$('#email').val();
	obj['idLista']=$('#idLista').val();
	
	if(err==0){
		$.post('lib/php/quota.php',obj,function(d){
			//alert("Quota ok");
			$('#tgt_quota').html(d);
			$('#tgt_bt_send').html("<div style='float:right; margin-top:12px; margin-right:-10px;'><a href='index.php'><strong>torna alla HOME</strong></a></div>");
			
		});
	}
}
function openrecode(d){
	var l=0;
	if(d=='sx')
		l='-=310';
	$('#btlistacod_scroll').animate({left:l},300,function(){
		//Animation complete.
	});
}


function validateEmail(pEmail){
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	return reg.test(pEmail);
}


