function inizializza(){
	if (document.all) { // creo le variabili per la sintassi di IE
		documento="document.all";
		parA="[\"";
		parB="\"]";
		stile=".style.";
	}else if (document.layers){ //NN4
		documento="document.layers";
		parA="[\"";
		parB="\"]";
		stile=".";
	}else if (document.getElementById) { // Opera e NN6
		documento="document.getElementById";
		parA="(\"";
		parB="\")";
		stile=".style.";
	}
} 


function setstile(mioelement,miostile,miovalore) {
     eval(documento+parA+mioelement+parB+stile+miostile+"='"+miovalore+"';");
}

function getstile(mioelement,miostile) {
     eval ( documento+parA+mioelement+parB+stile+miostile);
}

function fed(ilform,mioelement,miovalore,tipo){
	if (tipo == 'disabled'){
		ilform.elements[mioelement].disabled=miovalore;
	} else if (tipo == 'value'){
		ilform.elements[mioelement].value=miovalore;
	} else if (tipo == 'selectedIndex'){
		ilform.elements[mioelement].selectedIndex=miovalore;
	}
}


function setformvalue(mioelement,miovalore) {
	ilform.elements[mioelement].value=miovalore;
}

function SetSelectedValue(mioelement,miovalore) {
	theSelect = document.forms['dmd_form'].elements[mioelement];
	for (prop in theSelect.options) {
		if (theSelect.options[prop].value == miovalore)
			theSelect.selectedIndex = prop;
	}
}


function setparentdisabled(tabella,miovalore){
	element = 'ana__parent_txt';		document.forms['dmd_form'].elements[element].disabled=miovalore;
	element = 'ana__partitaiva';		document.forms['dmd_form'].elements[element].disabled=miovalore;
	element = tabella+'__citta';				document.forms['dmd_form'].elements[element].disabled=miovalore;
	element = tabella+'__op_address';		document.forms['dmd_form'].elements[element].disabled=miovalore;
	element = tabella+'__address';			document.forms['dmd_form'].elements[element].disabled=miovalore;
	element = tabella+'__cap';					document.forms['dmd_form'].elements[element].disabled=miovalore;
	element = tabella+'__provincia_sigla';	document.forms['dmd_form'].elements[element].disabled=miovalore;
	element = tabella+'__regione';			document.forms['dmd_form'].elements[element].disabled=miovalore;
	element = tabella+'__nazione';			document.forms['dmd_form'].elements[element].disabled=miovalore;
	element = 'ana__tel_lavoro';								document.forms['dmd_form'].elements[element].disabled=0;
	//if(document.forms['dmd_form'].elements[element].value=='###') document.forms['dmd_form'].elements[element].value='';
	element = 'ana__op_unitaoperativa';			document.forms['dmd_form'].elements[element].disabled=0;
	//if(document.forms['dmd_form'].elements[element].value=='###') document.forms['dmd_form'].elements[element].value='';
	setstile('lavoroForm','display','block');
}



function setnewparent(id){
	setparentdisabled('ind_parent',0);
	setformvalue('ana__parent','');
	setformvalue('ana__parent_txt','');
	setformvalue('ana__partitaiva','');
	setformvalue('lavoro__id',id);
	setformvalue('ana__ind_parent',id);
	setformvalue('lavoro__address','');
	setformvalue('lavoro__citta','');
	setformvalue('lavoro__provincia_sigla','');
	setformvalue('lavoro__cap','');	
	setformvalue('lavoro__nazione','ITALIA');
	
	document.forms['dmd_form'].elements['ind_parent__op_address'].selectedIndex=1;
	document.forms['dmd_form'].elements['ind_parent__regione'].selectedIndex=0;
}

function absCountWords (this_field, max_parole, max_parole_img, allegatoFile,allegato) {
var maxWord = max_parole;
if (allegatoFile.value.length > 0){maxWord = max_parole_img;}
if (allegato){maxWord = max_parole_img;}


var char_count = this_field.value.length;
var fullStr = this_field.value + " ";
var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
var splitString = left_trimmedStr.split(" ");
var word_count = splitString.length -1;
if (word_count == 0) {
alert ('non hai inserito il testo');
return false;
}
if (word_count > maxWord) {
alert ('il testo inserito risulta di ' + word_count +' parole e il limite è di '+ maxWord);
return false;
}else{
return true;
}

}

function CountWords (this_field, show_word_count, show_char_count) {
if (show_word_count == null) {
show_word_count = true;
}
if (show_char_count == null) {
show_char_count = false;
}
alert(this_field);
alert(this_field.value);

var char_count = this_field.value.length;
var fullStr = this_field.value + " ";
var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
var splitString = cleanedStr.split(" ");
var word_count = splitString.length -1;
alert (word_count);

if (fullStr.length <2) {
word_count = 0;
}
if (word_count == 1) {
wordOrWords = " word";
}
else {
wordOrWords = " words";
}
if (char_count == 1) {
charOrChars = " character";
} else {
charOrChars = " characters";
}
if (show_word_count & show_char_count) {
alert ("Word Count:\n" + "    " + word_count + wordOrWords + "\n" + "    " + char_count + charOrChars);
}
else {
if (show_word_count) {
return  word_count;
}
else {
if (show_char_count) {
alert ("Character Count:  " + char_count + charOrChars);
      }
   }
}
return word_count;
}


inizializza(); //lancio la funzione che inizializza le variabili
