var J = jQuery.noConflict();

function SelectImg(id,src) {
	document.getElementById(id).src = src;
}
function gestionePDF(act,id,codCategoria,codSottoCategoria,lang) 
{
	var randomnumber=Math.floor(Math.random(99999)*2345);
    var retParms = showModalDialog("uploadImg.php?act=" + act + "&id="+ id + "&codCategoria=" + codCategoria + "&codSottoCategoria=" + codSottoCategoria + "&lang=" + lang + "&r=" + randomnumber, document, "dialogWidth:500px;dialogHeight:300px; status: 0; help:0");
	var randomnumber2=Math.floor(Math.random()*Math.random()*23452);
	document.location = document.location +"&r=" + randomnumber2;
}
function ricercaSottocategorie(id)
{
	var randomnumber=Math.floor(Math.random(99999)*2344);
	cat = document.getElementById(id).value;
	document.location = document.location + "&codCategoria=" + cat + "&r=" + randomnumber;
}

function EliminaImmagine(id,id_img,id_delete_button) 
{
	J.ajax({
		type: "POST",
		url: "deleteImg.php",
		data: "id=" + id + "&fieldToDelete=" + id_img ,
		success: function(msg){
			var l = window.location;
			//window.location = window.location + "&code=<?php echo md5(rand(0,9999999999));?>";
			alert(msg);
			window.document.getElementById(id_img).src = "../images/prodotti/" + "image_null.png";
			window.document.getElementById(id_delete_button).style.visibility = 'hidden';
		},
		error: function(msg){
			alert(msg);
		}
	});
}
function send_formail(ajax_page,lang)
{
	var name = document.getElementById('name').value;
	var surname = document.getElementById('surname').value;
	var company = document.getElementById('company').value;
	var address = document.getElementById('address').value;
	var zip = document.getElementById('zip').value;
	var city = document.getElementById('city').value;
	var tel = document.getElementById('tel').value;
	var fax = document.getElementById('fax').value;
	var email = document.getElementById('email2').value;
	var message = document.getElementById('message').value;
	var x = 0;
	if (name == '') {
		J('#name').css("background-color", "#FFFFAA");
		x = 1;
	}else
	{
		J('#name').css("background-color", "#FFFFFF");
	}
	if (surname == '') {
		J('#surname').css("background-color", "#FFFFAA");
		//J('#surname').css("border", "1");
		x = 1;
	}else
	{
		J('#surname').css("background-color", "#FFFFFF");
	}
	if (tel == '') {
		J('#tel').css("background-color", "#FFFFAA");
		x = 1;
	}else
	{
		J('#tel').css("background-color", "#FFFFFF");
		var EnteredValue = J.trim(J("#tel").val()); 
		var TestValue = EnteredValue.replace(" ", ""); 
		if (isNaN(TestValue)) { 
			if (lang == 'it') {
				alert("Numero di telefono errato")
			}
			if (lang == 'en') {
				alert("Telephone Number Wrong")
			}
			if (lang == 'de'){
				alert("Telefon-Nummer falsch")
			} 
			J('#tel').css("background-color", "#FFFFAA");
			x = 1;
		}
	}
	if (J('#fax').text != '') {
		var EnteredValue = J.trim(J("#fax").val()); 
		var TestValue = EnteredValue.replace(" ", ""); 
		if (isNaN(TestValue)) { 
			if (lang == 'it') {
				alert("Numero di fax errato")
			}
			if (lang == 'en') {
				alert("Fax Number Wrong")
			}
			if (lang == 'de'){
				alert("Fax-Nummer falsch")
			} 
			J('#fax').css("background-color", "#FFFFAA");
			x = 1;
		}
	}
	if (message == '') {
		J('#message').css("background-color", "#FFFFAA");
		x = 1;
	}else
	{
		J('#message').css("background-color", "#FFFFFF");
	}
	if (email == '') {
		J('#email2').css("background-color", "#FFFFAA");
		x = 1;
	}else
	{
		J('#email2').css("background-color", "#FFFFFF");
	}
	if (x != 1) {
		J.ajax({
			type: "POST",
			url: ajax_page,
			data: "name=" + name + "&surname=" + surname + "&company=" + escape(company) + "&address=" + escape(address) + "&zip=" + zip + "&city=" + escape(city) + "&tel=" + tel + "&fax=" + fax + "&email=" + escape(email) + "&message=" + message+ "&lang=" + lang,
			success: function(msg){
				//alert(msg);
				J("#formreturnmessage").show();
				J("#messageDiv").html(msg);
				J("#messageDiv").height(300);
				J("#formmail").hide();
			},
			error: function(msg){
				alert(msg);
			}
		});
	}
	else
	{
		if (lang == 'it') {
			alert("Inserire i campi obbligatori")
		}
		if (lang == 'en') {
			alert("Please, insert required fields")
		}
		if (lang == 'de'){
			alert("Bitte erforderlich Felder einfügen")
		} 
	}
}
function indietroFormail()
{
	J("#formreturnmessage").hide();
	J("#messageDiv").html('');
	J("#formmail").show();
}
