var tempX=0;var tempY=0;var distX=0;var distY=0;var premuto;var time;var elem;var IE=document.all?true:false
function getTarget(e){var targ;if(!e)var e=window.event;if(e.target)targ=e.target;else if(e.srcElement)targ=e.srcElement;if(targ.nodeType==3){targ=targ.parentNode;}
return targ;}
function myAlert(type,text){var classe='a1';if(type==2)classe='a2';if(type==3)classe='a3';if(type==4)classe='a4';var divA=document.createElement("DIV");divA.id="divAlert";divA.className='alert '+classe;var textA=document.createElement("DIV");textA.innerHTML=text;divA.appendChild(textA);var buttA=document.createElement("BUTTON");buttA.value='OK';divA.appendChild(buttaA);var divMaskA=document.createElement("DIV");divMaskA.id="divMaskAlert";divMaskA.className='mask_alert';document.body.appendChild(divMaskA);document.body.appendChild(divA);}
function closeAlert(){document.body.removeChild(document.getElementById('divAlert'));document.body.removeChild(document.getElementById('divMaskAlert'));}
function loading(type,obj){if(type){var divMX=document.createElement("DIV");divMX.id="divLoading";divMX.className="maskLoading";divMX.style.display="block";var loading=document.createElement("IMG");loading.id='imgLoading';loading.className='loading';loading.src="images/loading.gif";var testo=document.createElement("DIV");testo.id='txtLoading';testo.className='loading';testo.innerHTML='loading';if(obj){obj.appendChild(divMX);obj.appendChild(loading);obj.appendChild(testo);}
else{document.getElementById('divMain').appendChild(divMX);document.getElementById('divMain').appendChild(loading);document.getElementById('divMain').appendChild(testo);}}else{document.getElementById('divMain').removeChild(document.getElementById("divLoading"));document.getElementById('divMain').removeChild(document.getElementById("imgLoading"));document.getElementById('divMain').removeChild(document.getElementById("txtLoading"));}}
function getMouseXY(e){if(IE){tempX=window.event.clientX+document.body.scrollLeft
tempY=window.event.clientY+document.body.scrollTop}else{tempX=e.pageX
tempY=e.pageY}
if(tempX<0){tempX=0}
if(tempY<0){tempY=0}
return true}
function move(){if(premuto){premuto.style.left=(tempX-distX)+"px";premuto.style.top=(tempY-distY)+"px";distX=tempX-premuto.offsetLeft;distY=tempY-premuto.offsetTop;}}
function setPremuto(id){elem=document.createElement("DIV");elem.id="divCanvas";elem.className="canvas";document.getElementById(id).style.zIndex=28;elem.style.zIndex=(parseInt(document.getElementById(id).style.zIndex)-1);document.body.appendChild(elem);premuto=document.getElementById(id);distX=tempX-premuto.offsetLeft;distY=tempY-premuto.offsetTop;time=setInterval(move,10);}
function stopMove(){if(time)clearInterval(time);if(document.getElementById("divCanvas"))document.body.removeChild(elem);premuto=null;}
function uploadFile(filename,idPost){document.getElementById("imgObject").src=filename;}
function xDate(data,type){var conv="";if(type==2){var dates=data.split('/');conv=dates[2]+""+dates[1]+""+dates[0];}else{var dates=data.split('-');conv=dates[2]+"/"+dates[1]+"/"+dates[0];}
return conv;}
function trim(str,chars){return ltrim(rtrim(str,chars),chars);}
function ltrim(str,chars){chars=chars||"\\s";return str.replace(new RegExp("^["+chars+"]+","g"),"");}
function rtrim(str,chars){chars=chars||"\\s";return str.replace(new RegExp("["+chars+"]+$","g"),"");}
//ritorna tutti i valori di campi di input sotto forma di url
 function getForm(id){
	var ritorno = "";
	var input = document.getElementById(id).getElementsByTagName('INPUT');
	for(var i=0;i<input.length;i++){
		if(!checkDataField(input[i]))return false;
		if(input[i].name!='')ritorno+='&'+input[i].name+'='+escape(input[i].value);
		else ritorno+='&'+input[i].id+'='+escape(input[i].value);
	}
	input = document.getElementById(id).getElementsByTagName('SELECT');
	for(var i=0;i<input.length;i++){
		if(!checkDataField(input[i]))return false;
		if(input[i].name!='')ritorno+='&'+input[i].name+'='+escape(input[i].value);
		else ritorno+='&'+input[i].id+'='+escape(input[i].value);
	}
	input = document.getElementById(id).getElementsByTagName('TEXTAREA');
	for(var i=0;i<input.length;i++){
		if(!checkDataField(input[i]))return false;
		if(input[i].name!='')ritorno+='&'+input[i].name+'='+escape(input[i].value);
		else ritorno+='&'+input[i].id+'='+escape(input[i].value);
	}
	return ritorno;
 }
 
 function checkDataField(input){
	if(input.getAttribute('_trg'))
		if(input.value==""){
			alert('Attenzione. Alcuni campi obbligatori sono stati lasciati vuoti.');
			return false;
		}	
	return true;
 }
