
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapImagex(idimg){
	myimg=document.getElementById(idimg).src;
	
	nsla=myimg.lastIndexOf("/")+1;
	myimg1=myimg.substring(nsla,myimg.length);
	
	if(myimg1=="button_piu.gif")
		myimg2="img/button_meno.gif";
	else
		myimg2="img/button_piu.gif";
	
	MM_swapImage(idimg,'',myimg2,1);
}


function ColoraRighe(){
	var tabelle=document.getElementsByTagName("table");
	
	for(i=0;i<tabelle.length;i++){
		if(tabelle[i].className.indexOf("righealterne")>=0){
			trs=tabelle[i].tBodies[0].rows;
			for(j=1;j<trs.length;j+=2)
				trs[j].className="alterna";
		}
	}
}

function ShowMenu(menu){
	if(document.getElementById("menu_"+menu).style.display=="none"){
		document.getElementById("menu_"+menu).style.display="block";
	}
	else{
		document.getElementById("menu_"+menu).style.display="none";
	}
}

function toggle(id)

{

        if(document.getElementById(id).style.display=="none")

          document.getElementById(id).style.display="";

        else

          document.getElementById(id).style.display="none";

}

function xoopsGetElementById(id) {
if (document.getElementById(id)) {
	return document.getElementById(id);
	} else if (document.all[id]) {
		return document.all[id];
		} else if (document.layers && document.layers[id]) {
			return (document.layers[id]);
			} else {
				return false;
			}
}

function toggle_visibility(id, flag)  {

if (xoopsGetElementById(id)) {
	xoopsGetElementById(id).style.visibility = (flag) ? 'visible' : 'hidden';
	}
}

function showImgSelected(imgId, selectId, imgDir) {
imgDom     = xoopsGetElementById(imgId);
selectDom  = xoopsGetElementById(selectId);
imgDom.src = "http://www.altropc.it/"+ imgDir + "/" + selectDom.options[selectDom.selectedIndex].value;
}


function justReturn() {
	return;
}

function setVisible(id) {
	xoopsGetElementById(id).style.visibility = "visible";
}


function setHidden(id) {
	xoopsGetElementById(id).style.visibility = "hidden";
}

// Removes leading whitespaces
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}

function checkDatiOrdine(){
	if(trim(document.frmConfermaOrdine.ragionesociale.value)==""){
		alert("Non hai inserito la ragione sociale");
		document.frmConfermaOrdine.ragionesociale.focus();
		return false;
	}
	if(trim(document.frmConfermaOrdine.piva.value)==""){
		alert("Non hai inserito la partita iva");
		document.frmConfermaOrdine.piva.focus();
		return false;
	}
	if(trim(document.frmConfermaOrdine.indirizzo.value)==""){
		alert("Non hai inserito l'indirizzo");
		document.frmConfermaOrdine.indirizzo.focus();
		return false;
	}
	if(trim(document.frmConfermaOrdine.citta.value)==""){
		alert("Non hai inserito la citta");
		document.frmConfermaOrdine.citta.focus();
		return false;
	}
	if(trim(document.frmConfermaOrdine.cap.value)==""){
		alert("Non hai inserito il cap");
		document.frmConfermaOrdine.cap.focus();
		return false;
	}
	if(trim(document.frmConfermaOrdine.nazione.value)==""){
		alert("Non hai inserito la nazione");
		document.frmConfermaOrdine.nazione.focus();
		return false;
	}
	return true;
}

function CheckFormUser(){	
	if(trim(document.frmReguser.username.value)==""){
		alert("Non hai inserito l'username");
		document.frmReguser.username.focus();
		return false;
	}
	if(document.frmReguser.username.value.length < 4){
		alert("L'username inserita non č corretta, deve contenere almeno 4 caratteri");
		return false;
	}
	if(trim(document.frmReguser.email.value)==""){
		alert("Non hai inserito l'email");
		document.frmReguser.email.focus();
		return false;
	}
	if(trim(document.frmReguser.password.value) != "" && (document.frmReguser.password.value.length < 4)){
		alert("La password inserita non č corretta, deve contenere almeno 4 caratteri alfa numerici");
		document.frmReguser.password.focus();
		return false;
	}
	if(trim(document.frmReguser.password.value) != trim(document.frmReguser.password2.value)){
		document.frmReguser.password.focus();
		alert("Le password non coincidono");
		return false;
	}
	if(trim(document.frmReguser.nome.value)==""){
		alert("Non hai inserito il nome");
		document.frmReguser.nome.focus();
		return false;
	}
	if(trim(document.frmReguser.cognome.value)==""){
		alert("Non hai inserito il cognome");
		document.frmReguser.cognome.focus();
		return false;
	}
	if(trim(document.frmReguser.indirizzo.value)==""){
		alert("Non hai inserito l'indirizzo");
		document.frmReguser.indirizzo.focus();
		return false;
	}
	if(trim(document.frmReguser.citta.value)==""){
		alert("Non hai inserito la cittā");
		document.frmReguser.citta.focus();
		return false;
	}
	if(trim(document.frmReguser.provincia.value)==""){
		alert("Non hai inserito la provincia");
		document.frmReguser.provincia.focus();
		return false;
	}
	if(trim(document.frmReguser.cap.value)==""){
		alert("Non hai inserito il cap");
		document.frmReguser.cap.focus();
		return false;
	}
	if(trim(document.frmReguser.nazione.value)==""){
		alert("Non hai inserito la nazione");
		document.frmReguser.nazione.focus();
		return false;
	}
	
	return true;
}

function CheckFormNewsl(){	
	if(trim(document.frmNewsletter.email.value)==""){
		alert("Non hai inserito l'email");
		return false;
	}
	
	return true;
}

function CheckFormRic(){	
	if(trim(document.formric.all_fields.value)==""){
		alert("Non hai inserito la chiave di ricerca");
		return false;
	}
	
	var strTemp=trim(document.formric.all_fields.value);
	
	if(strTemp.length < 2){
		alert("Devi inserire almeno 2 lettere");
		return false;
	}
	return true;
}

function CheckFormRecupero(){	
	
	if(trim(document.frmRecupero.username.value)==""){
		alert("Non hai inserito l'username");
		return false;
	}
	
	if(trim(document.frmRecupero.email.value)==""){
		alert("Non hai inserito l'email");
		return false;
	}

	return true;
}

function CheckFormLogin(){	
	
	if(trim(document.frmLogin.user.value)==""){
		alert("Non hai inserito l'username");
		return false;
	}
	
	if(trim(document.frmLogin.pwd.value)==""){
		alert("Non hai inserito la password");
		return false;
	}

	return true;
}

function CheckContatti(){
	if(trim(document.frmContatti.denominazione.value)==""){
		alert("Non hai inserito la denominazione");
		document.frmContatti.denominazione.focus();
		return false;
	}
	if(trim(document.frmContatti.telefono.value)==""){
		alert("Non hai inserito il telefono");
		document.frmContatti.telefono.focus();
		return false;
	}
	if(trim(document.frmContatti.email.value)==""){
		alert("Non hai inserito l'indirizzo email");
		document.frmContatti.email.focus();
		return false;
	}
	if(trim(document.frmContatti.scode.value)==""){
		alert("Non hai inserito il codice che leggi nell'immagine");
		document.frmContatti.scode.focus();
		return false;
	}
	
	return true;
}

// setta la variabile MyText con la data odierna
function Oggi(MyText,Over)
{
	var now= new Date();
	
	var d=now.getDate();
	var giorno = (d < 10) ? '0' + d : d;

	var m=(now.getMonth()+1);
	var mese=(m < 10) ? '0' + m : m;
	
	var yy = now.getYear();
	var anno = (yy < 1000) ? yy + 1900 : yy;

	if(Over=='s')
		document.getElementById(MyText).value=giorno + "/" + mese + "/" + anno;
	else
		document.getElementById(MyText).value=document.getElementById(MyText).value + giorno + "/" + mese + "/" + anno;
}

function openWin (URL,larg,alt) {
	sinistra=(screen.width-larg)/2;
	alto=(screen.height-alt)/2;
    window.open(URL,"","width="+larg+",height="+alt+",left="+sinistra+",top="+alto+",toolbar=no, location=no,status=no,menubar=no,scrollbars=yes,resizable=no");
}

function ShowUpImg(){
	if(document.getElementById("upimg").style.display=="none"){
		document.getElementById("upimg").style.display="block";
	}
	else{
		document.getElementById("upimg").style.display="none";
	}
}

function AddImg2Form(filename){
	document.frmEventi.n_img.value=parseInt(document.frmEventi.n_img.value) + 1;
	var nimgT='img'+parseInt(document.frmEventi.n_img.value);
	var newinput = document.createElement('input');
	var newconttext=document.createElement('font');
	var newtext = document.createTextNode(filename + ' ');
	//var newremove=document.createElement('input');
	var newremove=document.createElement('a');
	var newbr = document.createElement('br');
	
	newinput.setAttribute('type','hidden');
	newinput.setAttribute('name',nimgT);
	newinput.setAttribute('id',nimgT);
	newconttext.setAttribute('id','text'+nimgT);
	//newremove.setAttribute('type','button');
	//newremove.setAttribute('value','Rimuovi');
	newremove.setAttribute('id','rem' + nimgT );
	newremove.onclick='RemoveAll(\'' + nimgT + '\')';
	newremove.setAttribute('href','javascript:RemoveAll(\'' + nimgT + '\');');
	//newremove.setAttribute('onclick',newremove.onclick);
	newremove.innerHTML="[RIMUOVI]"
	newinput.setAttribute('value',filename);
	
	document.getElementById('img_text').appendChild(newconttext);
	document.getElementById('text' + nimgT).appendChild(newtext); 
	document.getElementById('img_text').appendChild(newinput);
	document.getElementById('img_text').appendChild(newremove);
	
	document.getElementById('img_text').appendChild(newbr);
}

function RemoveAll(nimgT){
	document.getElementById('img_text').removeChild(document.getElementById(nimgT));
	document.getElementById('img_text').removeChild(document.getElementById('text'+nimgT));
	document.getElementById('img_text').removeChild(document.getElementById('rem'+nimgT));
}

function UploadComplete(){
	alert("L'upload dei file č avvenuto correttamente");
}

function PrezzoIva(){
	var noiva=document.frmProdotto.prezzovenditanoiva.value;
	if(noiva=="")
		noiva=0;
	
	var performat=Number(noiva);
	var euro=(noiva * 1.2);
	var valore=euro.toFixed(2);
	
	document.frmProdotto.prezzovenditanoiva.value=performat.toFixed(2);
	document.frmProdotto.prezzovenditaiva.value=valore;
}

function PrezzoNoIva(){
	var coniva=document.frmProdotto.prezzovenditaiva.value;
	if(coniva=="")
		coniva=0;
	
	var performat=Number(coniva);
	var euro=(coniva / 1.2);
	var valore=euro.toFixed(2);
	
	document.frmProdotto.prezzovenditaiva.value=performat.toFixed(2);
	document.frmProdotto.prezzovenditanoiva.value=valore;
}

// setta la variabile MyText con la data odierna
function Oggi2()
{	
	var now= new Date();

	var g=now.getDay();
	
	var d=now.getDate();
	var giorno = (d < 10) ? '0' + d : d;

	var m=(now.getMonth()+1);
	var mese = (m < 10) ? '0' + m : m;
	
	var yy = now.getYear();
	var anno4 = (yy < 1000) ? yy + 1900 : yy;
	
	var miadata=giorno + '/' + mese + '/' + anno4;
	
	return (miadata);
}