
function popup(url, windowsname, x, y, left, top) 
{
	var hWnd=window.open(url, windowsname, "toolbar=no,width="+x+",height="+y+",left="+left+",top="+top+",directories=no,status=no,statusbar=no,resizable=1,menubar=no,scrollbars=yes,location=no");
	
	if(!hWnd.opener)
		hWnd.opener=self;
	if(hWnd.focus!=null)
		hWnd.focus();
}

function validate()
{
	//alert(document.form.consenso[0].checked);
	//if(document.form.consenso[0].checked==true)
	//{
		if(document.form.nome.value.length==0)
		{
			alert("Please, fill the name field.");
			return false;
		}
		
		if(document.form.mail.value.length==0)
		{
			alert("Please, fill the e-mail field.");
			return false;
		}
		
		var regex=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
		if(!regex.test(document.form.mail.value))
		{
			window.alert("Warning, the e-mail field has an incorrect value.");
			return false;
		}
	/*}
	else
	{
		alert("Attenzione, il consenso al trattamento dei dati personali è obbligatorio per la richiesta di informazioni");
		return false;
	}*/
	
	//return true;
	mandaMail(document.form.nome.value, document.form.info.value, document.form.mail.value);
}

function mandaMail(name, info, mail)
{
	$.ajax({
		type: "POST",
		url: "contenutoMailSend.php",
		data: "name="+escape(name)+'&info='+escape(info)+'&mail='+escape(mail),
		success: function(msg){
			//alert(msg);
			if(msg.indexOf("OK")>-1)
			{
				alert('Message succesfully sent.');
			}
			else
			{
				alert('An error has occurred, please try later.');
			}
		}
	});	
}

function searchArt()
{
	el = document.getElementById('txtsearch');
	//alert("["+el.value+"]");
	//alert("["+jQuery.trim(el.value)+"]");
	
	//if(jQuery.trim(el.value)!="")
		$('#form').submit();
}

function openFormComment()
{
	//alert(openForm);
	if(openForm)
	{
		$("#newcomment").click(function(event){$('img.newcomment').attr('src', 'img/addcomment_over.gif');});
		openForm = 0;
		
		$('#form_comment').show('slow', function() {});
	}
	else
	{
		$("#newcomment").click(function(event){$('img.newcomment').attr('src', 'img/closecomment_over.gif');});
		openForm = 1;
		
		$('#form_comment').hide('slow', function() {});
	}
}

function sendComment()
{
	var g_key = $('#google_adsense_key').val();
	var cgi_allc = $('#cgi_allc').val();
	var cgi_bind = $('#cgi_bind').val();
	var idart = $('#idart').val();
	//alert(g_key+" / "+cgi_allc+" / "+cgi_bind+" / "+idart);
	
	if(jQuery.trim(cgi_allc)=="" || jQuery.trim(cgi_bind)=="")
		alert("Please fill Name and Comment fields.");
	else
	{
		$("#commentsendimage").click(function(event){$("img.commentsendimage").attr("src","img/comment_loading.gif");});
		
		if(clicked==0)
		{
			clicked = 1;
			$.ajax({
				type: "POST",
				url: "doComments.php",
				data: 'idart='+idart+'&cgi_allc='+Base64.encode(cgi_allc)+'&cgi_bind='+Base64.encode(cgi_bind)+'&google_adsense_key='+(g_key),
				success: function(msg){
					//alert(msg);
					if(msg.indexOf("OK")>-1)
					{
						window.location.reload(true);
						//window.location.href = top.location.href+'#comments';
					}
					else
					{
						//alert(msg);
						alert('An error has occurred, please try later.');
					}
				}
			});
		}
	}	
}

$(document).ready(function()
{
	$("#mnart img").hover(function(){this.src = this.src.replace("_normal","_over");}, function(){this.src = this.src.replace("_over","_normal");});
	$("#mnfaq img").hover(function(){this.src = this.src.replace("_normal","_over");}, function(){this.src = this.src.replace("_over","_normal");});
	$("#mnmail img").hover(function(){this.src = this.src.replace("_normal","_over");}, function(){this.src = this.src.replace("_over","_normal");});
	$("#mnlinks img").hover(function(){this.src = this.src.replace("_normal","_over");}, function(){this.src = this.src.replace("_over","_normal");});
	$("#search").hover(function(){this.src = this.src.replace("_normal","_over");}, function(){this.src = this.src.replace("_over","_normal");});
	
	$("#newcomment img").hover(function(){this.src = this.src.replace("_normal","_over");}, function(){this.src = this.src.replace("_over","_normal");});
	$("#rss img").hover(function(){this.src = this.src.replace("_normal","_over");}, function(){this.src = this.src.replace("_over","_normal");});
});

Shadowbox.init();
var openForm = 1;
var clicked = 0;


