function reg_showTab(vsNumTab)
{
	vnNumTab = 4;
	voTab = document.getElementById("reg_tab0"+vsNumTab);
	voCont = document.getElementById("reg_cont0"+vsNumTab);
	
	//controllo per il passaggio al tab 3
	if (vsNumTab==3)
	{
		if (document.getElementById("pro_serialnumber").value!="" || document.getElementById("pro_randomnumber").value!="")
		{
			if (!window.confirm("ATTENZIONE: la registrazione del prodotto che stai inserendo non e' completa.\nPer terminarla, clicca su ANNULLA per chiudere questa finestra, e poi sul pulsante 'AGGIUNGI IL PRODOTTO IN ELENCO' in fondo alla pagina.\nCliccando su OK il prodotto NON verra' registrato."))
				voTab = false;
		}
	}
	
	if (voTab && voCont)
	{
		//ciclo per nascondere i tab
		for (i=1;i<=vnNumTab;i++)
		{
			if (i!=vsNumTab)
			{
				voTabHidden = document.getElementById("reg_tab0"+i);
				voContHidden = document.getElementById("reg_cont0"+i);
				if (voTabHidden && voContHidden)
				{
					voTabHidden.className="reg_tab0"+i;
					voContHidden.className="reg_div_hidden";
				}
			}	
		}
		//mostro quello che mi serve
		voTab.className = "reg_tab0"+vsNumTab+"_show";
		voCont.className = "reg_div_visible";
	}
}

function preloader()
{
	var arguments = preloader.arguments;
	for (var i = 0; i < arguments.length; i++) 
	{
		voImage = new Image(); 
		voImage.src = arguments[i];
	}
}

var vaOpenDiv = new Array();
vaOpenDiv['reg_div_agg_prod']=true;
var vbDivAnimating = true;
setTimeout("vbDivAnimating = false",2000);//al caricamento della pagina, attende 2 secondi per rendere attivo il pulsante
function reg_toggleDiv(vsDiv,vbForceClose)
{
	if (!vbDivAnimating)
	{
		voDiv = document.getElementById(vsDiv);
		vbDivAnimating = true;
		if (!vbForceClose && (!vaOpenDiv[vsDiv] || (vaOpenDiv[vsDiv]==false)))
		{
			Effect.SlideDown(vsDiv);
			vaOpenDiv[vsDiv]=true;
		}	
		else
		{
			Effect.SlideUp(vsDiv);
			vaOpenDiv[vsDiv]=false;
		}
		setTimeout("vbDivAnimating = false",2000);	
	}	
}

function reg_hideDiv(vsDiv)
{
	voDiv = document.getElementById(vsDiv);
	voDiv.style.display = "none";
	vaOpenDiv[vsDiv]=false;
}

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize()
{
	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) 
	{	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} 
	else if (document.documentElement.scrollHeight > document.documentElement.offsetHeight){ // all but Explorer Mac
		xScroll = document.documentElement.scrollWidth;
		yScroll = document.documentElement.scrollHeight;
	}
	else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} 
	else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function showWaiting()
{
	vaPageSize = getPageSize();
	document.getElementById("statediv").style.visibility="visible";
	document.getElementById("statediv").style.display="block";
	document.getElementById("statediv").style.height=vaPageSize[1]+"px";
}

function hideWaiting()
{
	document.getElementById("statediv").style.visibility="hidden";
	document.getElementById("statediv").style.display="none";
}

function svuotaCodice()
{
	voField = document.getElementById("conf_codice");
	voField.value = "";
	voField.focus();
}

function ricaricaCaptcha()
{
	var newImg = new Image();
	voDate = new Date();
	newImg.src="/community/reg/captcha-image.php?test="+voDate.getTime();
	document.getElementById("captcha_image").src=newImg.src;
	svuotaCodice();
}

function loadComuneNas()
{
	var voField = document.getElementById("aux_prov_nas");
	if (voField.value!="")
	{
		var voComuni = document.getElementById("reg_field_20");
		var divWait = document.getElementById(voField.id+"_waitDiv");
		var imgTest = document.getElementById(voField.id+"_waitImg");
		if (divWait && !imgTest)//evito che compaia due volte
		{
			var imgWait = document.createElement("img");
			var imgName = voField.id+"_waitImg";
			imgWait.setAttribute('id',imgName);
			imgWait.setAttribute('src',"images/ajax-loader.gif");
			divWait.appendChild(imgWait);
		}		
		var oXMLHttpRequest = new XMLHttpRequest;
		var url = "/community/reg/act_engine.php?action=ajax&type=comuneNas&value="+voField.value;
				
		oXMLHttpRequest.open("GET", url, false);
		oXMLHttpRequest.onreadystatechange = function() 
		{ 
			if (this.readyState == XMLHttpRequest.DONE) 
			{
				listaComuni = eval(oXMLHttpRequest.responseText);
				if (listaComuni)
				{
					voComuni.options.length=0;
					for (n=0;n<listaComuni.length;n++)
					{
						voComuni.options.add(new Option(listaComuni[n].CTLOCAL,listaComuni[n].CTCODFISC),0);
					}
					voComuni.options.add(new Option("",""),0);
					voComuni.options[0].selected=true;
				}	
			} 
		} 
		oXMLHttpRequest.send(null); 	
		
		if (divWait)
		{
			divWait.removeChild(imgWait);
		}
	}	
}
