function init(){
	caricaTabs('p1',arrayProv);
	ShowHide("idTabPA",false);
	caricaTabs('idElencoAmmPA',arrayAmmPA);
	doResource();
	var dip = document.theForm.checkDipPA.checked;
	document.theForm.UserName.disabled = false;
	document.theForm.Licence.disabled = false;
	if (dip){
		document.theForm.checkDipPA.checked = false;
		document.theForm.accettoCheckbox.checked = false;
		document.theForm.Licence.value = "";	
	}
	
	objInput = document.getElementsByTagName('input');
	for (i = 0;i < objInput.length;i++){
		elem = objInput[i];
		if (elem.type == 'text' || elem.type == 'password')
			elem.value = "";
		if (elem.type == 'checkbox')
			if (elem.checked)
				elem.click();
		if (elem.type == 'radio')
			elem.checked = false;
		
		
	}
	
	document.theForm.data.value = "gg/mm/aaaa";
}

function pulisciCampi(){
	objInput = document.getElementsByTagName('input');
	for (i = 0;i < objInput.length;i++){
		elem = objInput[i];
		if (elem.type == 'text' || elem.type == 'password')
			elem.value = "";
		if (elem.type == 'checkbox')
			if (elem.checked)
				elem.click();
		if (elem.type == 'radio')
			elem.checked = false;
		
		
	}
	objSelect = document.getElementsByTagName('select');
	if (objSelect[0] != null)
		objSelect[0].options[0].selected = true;
}

function changeProv(){
      window.status = document.theForm.prov.value;
}


function caricaTabs(id,arrayTabs){
	var select = document.getElementById(id);
	if (select != null){
		for (i = 0; i < arrayTabs.length;i++){
			var option = document.createElement("option");
			 
			var valueSel = arrayTabs[i].split("|");
			option.value = valueSel[1];
			
			var text = document.createTextNode(valueSel[0]);
			option.appendChild(text);
			
			select.appendChild(option);
		}
	}
}

function ShowHide(tableid, inithidden)
{
	if (document.all) { //ie
		if (document.all(tableid).style.visibility == "hidden") {
			document.all(tableid).style.height = "";
			document.all(tableid).style.width = "100%";
			document.all(tableid).style.display = "block";
			document.all(tableid).style.visibility = "visible";
		} else if (document.all(tableid).style.visibility == "visible" ) {
			document.all(tableid).style.height = "0";
			document.all(tableid).style.display = "none";
			document.all(tableid).style.visibility = "hidden";
		} else if (inithidden)  {
			document.all(tableid).style.height = "";
			document.all(tableid).style.width = "100%";
			document.all(tableid).style.display = "block";
			document.all(tableid).style.visibility = "visible";
		} else  {
			document.all(tableid).style.height = "0";
			document.all(tableid).style.display = "none";
			document.all(tableid).style.visibility = "hidden";
		} 

	} else { //ns
		if (document.getElementById(tableid).style.visibility == "hidden") {
			document.getElementById(tableid).style.height = "";
			document.getElementById(tableid).style.width = "100%";
			document.getElementById(tableid).style.display = "block";
			document.getElementById(tableid).style.visibility = "visible";
		} else if (document.getElementById(tableid).style.visibility == "visible" ) {
			document.getElementById(tableid).style.height = "0";
			document.getElementById(tableid).style.display = "none";
			document.getElementById(tableid).style.visibility = "hidden";
		} else if (inithidden)  {
			document.getElementById(tableid).style.height = "";
			document.getElementById(tableid).style.width = "100%";
			document.getElementById(tableid).style.display = "block";
			document.getElementById(tableid).style.visibility = "visible";
		} else  {
			document.getElementById(tableid).style.height = "0";
			document.getElementById(tableid).style.display = "none";
			document.getElementById(tableid).style.visibility = "hidden";
		} 
	
	}
}

function isDipPA(obj){
	
	if (obj.checked){
		ShowHide("idTabPA",true);
	
		document.theForm.ElencoAmmPA.selectedIndex = 0;
		
		document.theForm.den_ufficio.value = "";
		document.theForm.den_ufficio.disabled = false;
		
		document.theForm.tel_ufficio.value = "";
		document.theForm.tel_ufficio.disabled = false;
		
		document.theForm.ind_ufficio.value = "";
		document.theForm.ind_ufficio.disabled = false;
		
		document.theForm.accettoCheckbox.disabled = false;
		
		document.theForm.email.value = "";
		
		document.theForm.UserName.value = "";
		document.theForm.UserName.title = "";
		document.theForm.UserName.disabled = false;
	
	}else{
		ShowHide("idTabPA",false);
		
		document.theForm.den_ufficio.value = "";
		document.theForm.den_ufficio.disabled = true;
		
		document.theForm.tel_ufficio.value = "";
		document.theForm.tel_ufficio.disabled = true;
		
		document.theForm.ind_ufficio.value = "";
		document.theForm.ind_ufficio.disabled = true;
		
		document.theForm.Licence.value = "";
		document.theForm.Licence.disabled = false;
		
		document.theForm.email.value = "";
		
		var objSpan = document.getElementById("idEmail");
		for( var j = 0; j < objSpan.childNodes.length; j++ ) {
		   objSpan.removeChild(objSpan.childNodes[j]);
		}
		
		if (document.theForm.accettoCheckbox.checked)
			document.theForm.accettoCheckbox.click();
		
		document.theForm.accettoCheckbox.disabled = true;
		
		document.theForm.UserName.value = "";
		document.theForm.UserName.title = "";
		document.theForm.UserName.disabled = false;
	}
}

function sendRequest(obj){
	if(document.theForm.checkDipPA.checked){
		document.theForm.email.value = document.theForm.email.value+"@"+document.theForm.ammApp.options[document.theForm.ammApp.selectedIndex].value;
	}
	
	if (confirm("Confermi il seguente indirizzo e-mail?\n\n"+document.theForm.email.value+"")){

		document.theForm.UserName.disabled = false;
		document.theForm.Licence.disabled = false;
	
		obj.form.submit(); 
	} else {
		document.theForm.email.focus();	
	}
}