function askConfirm(url)
{
if (confirm("Sei sicuro?"))
window.location.replace(url);
}
function stringify(arr)
{
var str = new String();
for (var i = 0; i < arr.length; i++)
str += arr[i] + ",";
return str.substr(0, str.length - 1);
}
function deselectAll(id)
{
var sel = document.getElementById(id).options;
for (var i = 0; i < sel.length; i++)
sel[i].selected = false;
return true;
}
function isJSON(str)
{
try { JSON.parse(str); }
catch (e) { return false; }
return true;
}
function inserito(id)
{
var target_div = document.getElementById(id);
target_div.innerHTML = "
Inserimento effettuato
";
}
function clear_div_content(id)
{
var target_div = document.getElementById(id);
target_div.innerHTML = '';
}
function seleziona_cat(idc_sel)
{
var links = document.getElementsByName('cat_links');
for (var i = 0; i < links.length; i++)
if (links[i].id == idc_sel)
links[i].className = 'selez';
else
links[i].className = 'menu_sx_sotto';
}
function hideItem(id)
{
document.getElementById(id).style.visibility = "hidden";
document.getElementById(id).style.display = "none";
}
function showItem(id)
{
document.getElementById(id).style.visibility = "";
document.getElementById(id).style.display = "";
}
function getVal(target_id) { return document.getElementById(target_id).value; }
function setVal(target_id, val){ document.getElementById(target_id).value = val; }
function getById(id){ return document.getElementById(id); }
function enableButton(target) { document.getElementById(target).disabled = false; }
function disableButton(target) { document.getElementById(target).disabled = true; }
function precache(photoName)
{
var newphoto = new Image();
newphoto.src = photoName;
return newphoto;
}
function loadingGIF(target)
{
var contentHTML = "";
contentHTML += "
";
contentHTML += "";
contentHTML += " |
";
target.innerHTML = contentHTML;
}
function setOpacity(div, alpha)
{
var myDiv = document.getElementById(div);
myDiv.style.mozOpacity = alpha / 100;
myDiv.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + alpha + ")";
myDiv.style.opacity = alpha / 100;
}
function popup(urlname)
{
var stile = "top=0,left=0,fullscreen=yes,status=no,menubar=no";
stile += ",toolbar=no,scrollbar=yes,resize=yes";
window.open(urlname, "", stile);
}
function isArray()
{
if (typeof arguments[0] == 'object')
{
var criterion = arguments[0].constructor.toString().match(/array/i);
return (criterion != null);
}
return false;
}
function inArray(array, item)
{
if (isArray(array))
for (i = 0; i < array.length; i++)
if (array[i] == item) return true;
return false;
}
function decodeUrlVars(str){
//Aggiunto un replace per \n e \r dopo
//riscontro di un'anomalia. PHP restituisce la stringa delle variabili con un \n in testa!!
str = str.replace(/[\n\r]/g, '');
var stringa = new String(str);
var trimmed = str.replace(/^\s+|\s+$/g, '');
var vars = stringa.split("&");
var result = new Array();
for (i = 0; i < vars.length; i++)
{
var tmp = new String(vars[i]);
tmp = tmp.split("=");
//console.log(tmp);
result[tmp[0]] = tmp[1];
//console.log(result[tmp[0]]);
}
return result;
}
function removeById(id, target)
{
var elm = document.getElementById(id);
document.body.removeChild(elm);
try
{
document.getElementById(target).focus();
tinyMCE.get(target).focus();
}
catch (e1)
{
try { tinyMCE.get(target).focus(); }
catch (e2) {}
}
}
function lightpopup(message, target)
{
var marginTop = (ie) ? document.documentElement.scrollTop : window.pageYOffset;
var box = document.createElement("div");
box.id = "box_" + parseInt(Math.random() * 100);
box.style.position = "absolute";
box.style.top = "0px";
box.style.left = "0px";
box.style.width = "100%";
box.style.height = "100%";
/*box.style.backgroundColor = 'black';*/
if (target != null && target != undefined && target.length > 0)
box.target = target;
box.className = 'admin_preload_box';
var wall = document.createElement("div");
wall.id = "wall_" + parseInt(Math.random() * 100);
/*wall.style.position = "absolute";*/
wall.style.top = "0px";
wall.style.left = "0px";
wall.style.width = "100%";
wall.style.height = document.body.clientHeight + "px";
/*wall.style.backgroundColor = "black";*/
var pop = document.createElement("div");
pop.id = "popup_" + parseInt(Math.random() * 100);
pop.style.position = "absolute";
//pop.style.top = parseInt(marginTop + 10) + "px";
//pop.style.top = parseInt(marginTop + 10) + "px";
//pop.style.left = "50%";
pop.style.left = "47%";
pop.style.top = "30%"
pop.style.backgroundColor = "#FFF";
pop.style.borderColor = "#000";
pop.style.borderWidth = "2px";
pop.style.borderStyle = "solid";
pop.style.padding = "10px 10px 10px 10px";
var contentHTML = decodeURIComponent(message);
contentHTML += '';
pop.innerHTML = contentHTML;
box.appendChild(wall);
box.appendChild(pop);
document.body.appendChild(box);
setOpacity(wall.id, 70);
setOpacity(pop.id, 100);
}
function loginPopup(target)
{
var ie = (navigator.appName.indexOf("Internet Explorer") != -1) ? true : false;
var marginTop = (ie) ? document.documentElement.scrollTop : window.pageYOffset;
var box = document.createElement("div");
//box.id = "box_" + parseInt(Math.random() * 100);
box.id = "box_login_adv";
/*box.style.position = "absolute";*/
box.style.top = "0px";
box.style.left = "0px";
box.style.width = "100%";
box.style.height = "100%";
//box.style.background = "";
box.className = "admin_preload_box";
var wall = document.createElement("div");
wall.id = "wall_" + parseInt(Math.random() * 100);
wall.style.position = "absolute";
/*
wall.style.top = "0px";
wall.style.left = "0px";
*/
wall.style.top = "0px";
wall.style.left = "0px";
wall.style.width = "100%";
wall.style.height = document.body.clientHeight + "px";
//wall.style.backgroundColor = "white";
wall.className = "admin_preload_wall";
var pop = document.createElement("div");
pop.id = "popup_" + parseInt(Math.random() * 100);
pop.style.position = "absolute";
pop.className = 'admin_preload_popup';
/*
contentHTML = '';
*/
contentHTML = '';
pop.innerHTML = contentHTML;
box.appendChild(wall);
box.appendChild(pop);
document.body.appendChild(box);
setOpacity(wall.id, 70);
setOpacity(pop.id, 100);
}
function check(id, pattern)
{
var check = new String(document.getElementById(id).value);
if (!check.match(pattern))
{
document.getElementById(id).style.borderColor = "#FF0000";
document.getElementById(id).focus();
return false;
}
else
{
document.getElementById(id).style.borderColor = "gray";
return true;
}
}
function checkForm(nome_form, tipo_captcha)
{
var oForm = document.getElementById(nome_form);
var field;
for (var i = 0; i < oForm.elements.length; i++)
{
field = oForm.elements[i];
switch (field.type)
{
case "text" :
case "textarea" :
case "select-one" :
case "file" :
if (field.value.length <= 0 && field.id != "phone")
{
//alert(decodeURIComponent("Il campo __NOME_CAMPO__ non può essere vuoto " + field.id));
alert(decodeURIComponent("Il campo __NOME_CAMPO__ non può essere vuoto").replace("__NOME_CAMPO__", field.id.replace("_", " ")));
field.value = "";
field.style.backgroundColor = "#f0f0f0";
field.style.borderColor = "#ff0000";
field.focus();
return false;
}
else if ((field.id == "coperti" || field.name == "coperti" ||
field.id == "telefono" || field.name == "telefono" ||
field.id == "cellulare" || field.name == "cellulare" ||
field.id == "quantita" || field.name == "quantita") && isNaN(field.value))
{
alert(decodeURIComponent("Il campo può contenere solo numeri"));
field.style.backgroundColor = "#f0f0f0";
field.style.borderColor = "#ff0000";
field.value = "";
field.focus();
return false;
}
else if((field.id == "phone" || field.name == "phone") && field.value.length > 0 && isNaN(field.value))
{
alert(decodeURIComponent("Il campo può contenere solo numeri"));
field.style.backgroundColor = "#f0f0f0";
field.style.borderColor = "#ff0000";
field.focus();
return false;
}
else if ((field.id == "email" || field.name == "email") && (field.value.indexOf("@") <= 0 || field.value.indexOf("@") == field.value.length - 1))
{
alert(decodeURIComponent("È necessario inserire una e-mail valida"));
field.style.backgroundColor = "#f0f0f0";
field.style.borderColor = "#ff0000";
field.value = "";
field.focus();
return false;
}
else if ((field.id == "conferma_email" || field.name == "conferma_email") && (field.value != document.getElementById("email").value))
{
alert(decodeURIComponent("La conferma e-mail non corrisponde"));
field.style.backgroundColor = "#f0f0f0";
field.style.borderColor = "#ff0000";
//field.value = "";
field.focus();
return false;
}
else if ((field.id == 'giorno' || field.id == 'data' || field.name == 'giorno' || field.name == 'data'))
{
var temp = field.value.split("/");
if (temp[0].length != 2 || temp[1].length != 2 || temp[2].length != 4)
{
alert(decodeURIComponent("La data deve essere in formato GG/MM/AAAA"));
field.style.backgroundColor = "#f0f0f0";
field.style.borderColor = "#ff0000";
field.value = "";
field.focus();
return false;
}
else
{
field.style.backgroundColor = "";
field.style.borderColor = "";
}
}
else
{
field.style.backgroundColor = "";
field.style.borderColor = "";
}
break;
case "checkbox" :
if (field.checked == false)
{
text = field.id;
if(field.id == 'terms'){
text = 'Autorizza il trattamento dei dati personali.';
}
alert(decodeURIComponent("Il campo deve essere selezionato: " + text));
field.focus();
return false;
}
break;
case "radio" :
field = document.getElementsByName(field.name);
var checked = false;
for (var j = 0; j < field.length; j++)
if (field[j].checked)
{
checked = true;
break;
}
if (!checked)
{
alert(decodeURIComponent("Deve essere selezionata almeno un'opzione"));
field[0].focus();
return false;
}
break;
}
}
if(tipo_captcha=='google_captcha')
{
return true;
}else{
document.getElementById(nome_form).submit();
}
}
function checkFormContatti()
{
nome_form = 'form_contatti';
var oForm = document.getElementById(nome_form);
var field;
for (var i = 0; i < oForm.elements.length; i++)
{
field = oForm.elements[i];
switch (field.type)
{
case "text" :
case "textarea" :
case "select-one" :
case "file" :
if (field.value.length <= 0 && field.id != "phone")
{
alert(decodeURIComponent("Il campo non può essere vuoto"));
field.value = "";
field.style.backgroundColor = "#f0f0f0";
field.style.borderColor = "#ff0000";
field.focus();
return;
}
else if ((field.id == "coperti" || field.name == "coperti" ||
field.id == "telefono" || field.name == "telefono" ||
field.id == "cellulare" || field.name == "cellulare") &&
isNaN(field.value))
{
alert(decodeURIComponent("Il campo può contenere solo numeri"));
field.style.backgroundColor = "#f0f0f0";
field.style.borderColor = "#ff0000";
field.value = "";
field.focus();
return;
}
else if((field.id == "phone" || field.name == "phone") && field.value.length > 0 && isNaN(field.value))
{
alert(decodeURIComponent("Il campo può contenere solo numeri"));
field.style.backgroundColor = "#f0f0f0";
field.style.borderColor = "#ff0000";
field.focus();
return;
}
else if ((field.id == "email" || field.name == "email") && (field.value.indexOf("@") <= 0 || field.value.indexOf("@") == field.value.length - 1))
{
alert(decodeURIComponent("È necessario inserire una e-mail valida"));
field.style.backgroundColor = "#f0f0f0";
field.style.borderColor = "#ff0000";
field.value = "";
field.focus();
return;
}
else if ((field.id == 'giorno' || field.id == 'data' || field.name == 'giorno' || field.name == 'data'))
{
var temp = field.value.split("/");
if (temp[0].length != 2 || temp[1].length != 2 || temp[2].length != 4)
{
alert(decodeURIComponent("La data deve essere in formato GG/MM/AAAA"));
field.style.backgroundColor = "#f0f0f0";
field.style.borderColor = "#ff0000";
field.value = "";
field.focus();
return;
}
else
{
field.style.backgroundColor = "";
field.style.borderColor = "";
}
}
else
{
field.style.backgroundColor = "";
field.style.borderColor = "";
}
break;
case "checkbox" :
if (field.checked == false)
{
alert(decodeURIComponent("Il campo deve essere selezionato"));
field.focus();
return;
}
break;
case "radio" :
field = document.getElementsByName(field.name);
var checked = false;
for (var j = 0; j < field.length; j++)
if (field[j].checked)
{
checked = true;
break;
}
if (!checked)
{
alert(decodeURIComponent("Deve essere selezionata almeno un'opzione"));
field[0].focus();
return;
}
break;
}
}
document.getElementById(nome_form).submit();
}
var ie = navigator.appName.indexOf("Internet Explorer") != -1 ? 1 : 0;
try { LLI.callBack("otherfunctions_lib"); }
catch (e) {}