function RefreshImage(valImageId) {
	var objImage = document.images[valImageId];
	if (objImage == undefined) {
		return;
	}
	var now = new Date();
	objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
}

function no_spam(user,dominio)
{         
	document.location.href = "mailto:" + user + "@" + dominio;     
}

function openIMG(url,nome,w,h) {
	var features = 'width='+w+',height='+h+',top=10,left=10,toolbar=no,resizable=no,menubar=no,location=no,status=no,scrollbars=no';
	window.open(url, nome, features);
}


function doppioInvio(lingua)
{
	if(verificaLoginConsoleForm(lingua)){
		getUrl("http://www.redhostpepper.com/tt22/index.php");
		document.LoginConsoleForm.submit();

	}
}

function captureEnter(e) {
	e = e || window.event;
	if (e.keyCode == 13)  // Codice dell'invio
		return true; 
	else
		return false;
}


function refresh() 
{ 
    window.location.reload(); 
} 


function apriPopUpload(indirizzo)
{
	var popUp = open(indirizzo,'popUp','resizable=no,scrollbars=no,status=yes,width=400,height=300');
	popUp.moveTo(300,120);	
}


function controllaApici(elemento){
	var outstr="";
		for (x=0;x<elemento.value.length;x++){
			if (elemento.value.charAt(x) == "'") outstr += "&#39;";
			else outstr +=elemento.value.charAt(x);
			}
	elemento.value = outstr;
}

function controllaVirgolette(elemento){
	var outstr="";
		for (x=0;x<elemento.value.length;x++){
			if (elemento.value.charAt(x) == "\"") outstr += "&#34;";
			else outstr +=elemento.value.charAt(x);
			}
	elemento.value = outstr;
}

function roundToPrecision(inputNum, desiredPrecision){
	var precisionGuide = Math.pow(10, desiredPrecision);
	return( Math.round(inputNum * precisionGuide) / precisionGuide );
}

function controllaSpecialChars(valore, campoITA)
{
	var p = valore;
	
	var numeri = "1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
	var x = 0;
	var count = 0;
	   
	   if (p.length != 0){
		 for( x=0;x<p.length;x++){
			var chr = p.charAt(x);
			var pos = numeri.indexOf(chr);
			if (pos>=0) count++;
		 }
		 if (count<p.length){
			alert("Attenzione: il campo "+ campoITA +" puo' contenere solo cifre o numeri (non sono ammesse nemmeno le lettere accentate)!");
			return false;
		 } else {
			return true;
		 }
	   }
	   return true;
}

function controllaNumero(valore, campoITA)
{
	var p = valore;
	
	var numeri = "1234567890 ";
	var x = 0;
	var count = 0;
	   
	   if (p.length != 0){
		 for( x=0;x<p.length;x++){
			var chr = p.charAt(x);
			var pos = numeri.indexOf(chr);
			if (pos>=0) count++;
		 }
		 if (count<p.length){
			alert("Attenzione: il campo "+ campoITA +" puo' contenere solo numeri!");
			return false;
		 } else {
			return true;
		 }
	   }
	   return true;
}

function verificaUtenteSito()	{

	var em = document.form_contatti.email.value
	var tel = document.form_contatti.tel.value
	var nom = document.form_contatti.nome.value
	var cap = document.form_contatti.captchacode.value
	
	controllaApici(document.form_contatti.nome)
	controllaApici(document.form_contatti.email)
	controllaApici(document.form_contatti.tel)
	controllaApici(document.form_contatti.msg)
	
	controllaVirgolette(document.form_contatti.nome)
	controllaVirgolette(document.form_contatti.email)
	controllaVirgolette(document.form_contatti.tel)
	controllaVirgolette(document.form_contatti.msg)
	
		
	if ((em!="")&&(em.indexOf("@") == -1)) {
		alert("E-mail non valida!");
		return false;
	}
	
	if (tel!="") {
		if (!controllaNumero(tel, "Telefono"))
			return false;
	}
	
	if (em=="") {
		alert("Attenzione: devi inserire la tua email!");
		return false;
	}
	
	if (nom=="") {
		alert("Attenzione: devi inserire il tuo nome e cognome o Ragione Sociale!");
		return false;
	}
	
	if (cap=="") {
		alert("Attenzione: devi inserire il codice di controllo!");
		return false;
	}
	
	
	return true;	
}

