// constants
var noValue = '-99'

// globals
var curOption = new Array();
var isLoaded = new Array();

		function emptyList( listName ){
  		var lst = document.forms['stForm'][listName];
  		lst.options.length = 0;
  		lst.onchange = null;
  		isLoaded[listName] = false;
  		curOption[listName] = noValue;
		}

    function jSelPaese() {
      jsrsExecute("../../classi/forms.php", jFillRegs, "getRegs", "IT");
    }

    function jSelRegione() {
			if (navigator.appVersion.indexOf('Macintosh')<0) {
				path="../../classi/forms.php";
			} else {
				path="../classi/forms.php";
			}
      jsrsExecute(path, jFillProvs, "getProvs", document.stForm.fR.options[document.stForm.fR.selectedIndex].value);
    }
	
		function selectOption( listName, optionVal ){
  		// set list selection to option based on value
  		var lst = document.forms['stForm'][listName];
  		for( var i = 0; i< lst.options.length; i++ ){
    		if( lst.options[i].value == optionVal ){
      		lst.selectedIndex = i;
      		curOption[listName] = optionVal;
      		return;
    		}
  		}
		}

		function jFillRegs (a) {
			if (a.length>1) {
				listName = 'fR';
				emptyList('fR');
			  var lst = document.forms['stForm']['fR'];
  			lst.disabled = true;
  			lst.options[0] = new Option('', noValue);
			  var aOptionPairs = a.split('|');
			  for( var i = 0; i < aOptionPairs.length; i++ ){
			    if (aOptionPairs[i].indexOf(',') != -1) {
			      var aOptions = aOptionPairs[i].split(',');
			      lst.options[i + 1] = new Option(aOptions[1], aOptions[0]);
			    }  
			  }
		  	selectOption( listName, noValue );
  			isLoaded[listName] = true;
  			lst.disabled = false;
				document.stForm.fR.onchange = jSelRegione;
			} else {
				emptyList('fR');
  			document.forms['stForm']['fR'].disabled = true;
				emptyList('fPr');
  			document.forms['stForm']['fPr'].disabled = true;
			}
		}

		function jFillProvs (a) {
			if (a.length>1) {
				listName = 'fPr';
				emptyList('fPr');
			  var lst = document.forms['stForm']['fPr'];
  			lst.disabled = true;
  			lst.options[0] = new Option('', noValue);
			  var aOptionPairs = a.split('|');
			  for( var i = 0; i < aOptionPairs.length; i++ ){
			    if (aOptionPairs[i].indexOf(',') != -1) {
			      var aOptions = aOptionPairs[i].split(',');
			      lst.options[i + 1] = new Option(aOptions[1], aOptions[0]);
			    }  
			  }
		  	selectOption( listName, noValue );
  			isLoaded[listName] = true;
  			lst.disabled = false;
			} else {
  			document.forms['stForm']['fPr'].disabled = true;
				alert('ecchite!!!');
			}

		}