function contact_form(product_title,product_url){
	var product_url=window.location.href;
	$("body").append('<div id="contact_popup">\
    		<div class="ui-overlay">\
			<div class="ui-widget-overlay" style="z-index:100;"></div>\
			<div class="ui-widget-shadow ui-corner-all" style="width:490px;height:372px;position:absolute;left:500px;top:130px;z-index:101;"></div>\
		</div>\
		<div style="position:absolute;width:468px;height:350px;left:500px;top:130px;padding:10px;font-size:70%;font-style:Trebuchet MS ,sans-serif;z-index:102;" class="ui-widget ui-widget-content ui-corner-all">\
			<a href="#" onclick="javascript:$(\'#contact_popup\').remove()" style="float:right;font-size:12px;">X</a>\
			<div class="ui-dialog-content ui-widget-content" style="background:none;border:0">\
				<p><form action="url/of/your/php/script" method="post" id="contact_us">\
					<label for="name" style="font-size:12px;">Nome: </label><br><input type="text" name="name" id="name" style="font-size:12px;width:300px;" /><br /><br />\
					<label for="email" style="font-size:12px;">Email: </label><br><input type="text" name="email" style="font-size:12px;width:300px;"/><br /><br />\
					<label for="message" style="font-size:12px;">Messaggio: </label><br><textarea name="message" cols="68" rows="10" style="font-size:12px;">'+product_title+'</textarea><br /><br />\
					<input type="hidden" name="product_title" value="'+product_title+'" />\
					<input type="hidden" name="product_url" value="'+product_url+'" />\
					<input type="submit" value="Invia" onClick="javascript:sendMailAjax(product_title,product_url);return false;" style="font-size:12px;"/>\
				</form></p>\
			</div>\
		</div></div>');
}

function sendMailAjax(product_title,product_url)
{
	var name=$('input[name=name]');
	var email=$('input[name=email]');
	var message=$('textarea[name=message]');
	
	var whatreturn=true;
	
	// check if the name imput is not empty
	if($.trim(name.val())=="")
	{
		name.css('background','#ED0000');
		name.css('color','#FFF');
		whatreturn=false;
	}else
	{
		name.css('background','white');
		name.css('color','#000');
	}
	// check if email imput is not empty
	if($.trim(email.val())=="")
	{
		email.css('background','#ED0000');
		email.css('color','#FFF');
		whatreturn=false;	
	}
	// check if the email adress is OK
	else if(!isValidEmailAddress(email.val()))
	{
		email.css('background','#ED0000');
		email.css('color','#FFF');
		whatreturn=false;
	}
	// ok, you have the green light
	else
	{
		email.css('background','white');
		email.css('color','#000');
	}
	
	// check the message body
	if($.trim(message.val())==""){
		//alert("Please, enter the message!");
		message.css('background-color','#ED0000');
		message.css('color','#FFF');
		whatreturn=false;

	}


	if(!whatreturn)
		return false;
	
	$("input[type=submit]").attr("disabled", "disabled");
	// send the email
	$.post("/sendmail.php", 
			$("#contact_us").serialize(),
			function(data)
			{
				$('#contact_popup').remove();
			}
	);
	
	return false;
}
function isValidEmailAddress(emailAddress) {
    var pattern = new RegExp(/^(("[\w-+\s]+")|([\w-+]+(?:\.[\w-+]+)*)|("[\w-+\s]+")([\w-+]+(?:\.[\w-+]+)*))(@((?:[\w-+]+\.)*\w[\w-+]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][\d]\.|1[\d]{2}\.|[\d]{1,2}\.))((25[0-5]|2[0-4][\d]|1[\d]{2}|[\d]{1,2})\.){2}(25[0-5]|2[0-4][\d]|1[\d]{2}|[\d]{1,2})\]?$)/i);
    var ans=pattern.test(emailAddress);
    return ans;
}
function getParameterByName(name)
{
  name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
  var regexS = "[\\?&]" + name + "=([^&#]*)";
  var regex = new RegExp(regexS);
  var results = regex.exec(window.location.search);
  if(results == null)
    return "";
  else
    return decodeURIComponent(results[1].replace(/\+/g, " "));
}
