function vDiv(buttonCart,idDiv) 
{
	if (buttonCart != null) 
	{
		if (idDiv != null)
			obj=document.getElementById(idDiv);
		else
			obj=document.getElementById("divMessageBox");
	
		var asse_x = getX(buttonCart);
		var asse_y = getY(buttonCart);
		obj.style.left = (asse_x+buttonCart.offsetWidth+3) + "px";
		obj.style.top = (asse_y+4) + "px";
		obj.style.display = "block";
	}
}

function hDiv(idDiv)
{
	if (idDiv != null)
		obj=document.getElementById(idDiv);
	else
		obj=document.getElementById("divMessageBox");
	obj.style.display = "none";
}

function getY(oElement) 
{
	var iReturnValue = 0;
	while (oElement != null) 
	{
		iReturnValue += oElement.offsetTop;
		oElement = oElement.offsetParent;
	}
	return iReturnValue;
}

function getX(oElement) 
{
	var iReturnValue = 0;
	while (oElement != null) 
	{
		iReturnValue += oElement.offsetLeft;
		oElement = oElement.offsetParent;
	}
	return iReturnValue;
}


function verifyEmail(em) {
	var re = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	return re.test(em);
}

function frmComment_Submit() {
	frm = document.frmComment;
	ctrl = true
	if ((frm.cEmail.value == "") || !verifyEmail(frm.cEmail.value)) {
		alert("Attenzione, l'indirizzo e-mail inserito non e' corretto!");
		ctrl = false;
	}
	else if (frm.cText.value == "") {
		alert("Attenzione, inserire il commento!");
		ctrl = false;
	}
	else if (frm.code.value == "") {
		alert("Attenzione, inserire la sequenza di caratteri!");
		ctrl = false;
	}
	return ctrl;
}

function impostaVoto(classe, voto) {
	document.getElementById("stelle").className = "rating " + classe;
	document.frmComment.cVote.value = voto;
}


function inviaCommento()
		{
			if (frmComment_Submit()) {
				$.ajax
				({
					url: '/addComment.asp',
					type: 'POST',
					data: 'ajax=1&bisbn=' + $('#cbisbn').val() + '&cEmail=' + $('#cEmail').val() + '&cText=' + $('#cText').val().replace(/ /gi,"-:") + "&cVote=" + $('#cVote').val()+ "&sname=" + $('#sname').val()+ "&code=" + $('#code').val(),
					cache: false,
					success: function(data)
					{
						if (data.match(/ko:InvalidCode/))
						{
							alert("Attenzione: il codice controllo inserito non è corretto!");
						}
						else if (data.match(/ko:InvalidData/))
						{
							alert("Attenzione: indicare l'indirizzo email!");
						}
						else
							{
							$('#cmessaggio').html('<img src="/img/commento_registrato.jpg" border=0>');
						}
					},
					error: function(data)
					{
						alert('Load was performed nooooooo');
					}    
				});
			}
			$('#cText').val('');
			$('#cEmail').val('');
			$('#code').val('');
			
	}
	
	function addToWhish()
	{
		$.ajax
		({
			url: '/addWishList.asp',
			type: 'POST',
			data: 'ajax=1&bisbn=' + $('#bisbn').val(),
			cache: false,
			success: function(data)
			{
				$('#messaggio').html('<img src="/img/wishlist_aggiunto.jpg" border=0>');
			},
			error: function(data)
			{
				alert('Load was performed nooooooo');
			}    
		});
	}
