function getE(id) {
	return document.getElementById(id);
}

function doAjaxRequest(url, t, div_id, ordernum, area_preselected_str) {
	var oXmlDom = zXmlDom.createDocument();
	oXmlDom.onreadystatechange = function () {
		if (oXmlDom.readyState == 4) {
			if (oXmlDom.parseError.errorCode == 0) {
				var oRoot = oXmlDom.documentElement;
				
				if (t=='aree_competenza') {
					getE(div_id).innerHTML = '<br/>Selezionare una o pi&ugrave; aree di competenza:<br/>';
					var sArea = oRoot.getElementsByTagName("area");
					var id_area, descr_area;
					
					if (sArea.length>0) {
						for (var i = 0; i < sArea.length; i++) {
							var oCurrentChild = sArea[i].firstChild;
							
							do {
								switch (oCurrentChild.tagName) {
									case "id":
										id_area = parseInt(oCurrentChild.text);
										break;
									case "descr":
										descr_area = oCurrentChild.text;
										break;
								}
							} while (oCurrentChild = oCurrentChild.nextSibling);
							
							var checked_str = '';
							if (area_preselected_str.indexOf('-'+id_area+'-')>-1)	checked_str = " checked";
							getE(div_id).innerHTML += '<br/><input type="Checkbox" name="profilo_'+ordernum+'_area_id_'+id_area+'" id="profilo_'+ordernum+'_area_id_'+id_area+'" value="1" class="noborder"'+checked_str+'>'+descr_area;
						}
						getE(div_id).style.minHeight = 'auto';
						getE(div_id).style.display = '';
					}
					else
						getE(div_id).style.display = 'none';
				}
			}
			else
				alert("Le informazioni richieste non sono state trovate.");
		}
	};
	
	//window.location= url;
	oXmlDom.load(url);
}

// visualizza i DIV dinamici del modulo di inserimento dati esperienze professionali (passo 1.1 di 4)
function step_1_display_areas(ordernum, area_preselected_str) {
	doAjaxRequest('reserved.php?a=ajaxareecompetenza&id='+getE('profilo_professionale_'+ordernum).value, 'aree_competenza', 'profilo_'+ordernum+'__aree', ordernum, area_preselected_str);
	
	if (parseInt(getE('profilo_professionale_'+ordernum).value)>0)
		getE('profilo_'+ordernum+'__tipologia').style.display = '';
	else
		getE('profilo_'+ordernum+'__tipologia').style.display = 'none';
}

mw=null;
function openWindowDimBars(FileName,w,h,barre) {
	myWindow=window.open(FileName,'','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars='+barre+',resizable=0,top=10,left=10,width='+w+',height='+h);
	return myWindow;
}

function isObject(a) {
	return (a && typeof a == 'object') || isFunction(a);
}
function isFunction(a) {
	return typeof a == 'function';
}

var testresults;
function checkemail(email_addr) {
	var filter=/^[\'+\\./0-9A-Z^_\`a-z{|}~\-]+@[a-zA-Z0-9_\-]+(\.[a-zA-Z0-9_\-]+){1,3}$/i;
	if (filter.test(email_addr)) {
		testresults = true;
	}
	else {
		testresults = false;
	}
	
	return(testresults);
}

// visualizza il modulo di inserimento di un'altra laurea (fase 2 di 4)
function step2_add_degree(i) {
	if (isObject(getE("laurea_"+(i+1)+"_div")))		getE("laurea_"+(i+1)+"_div").style.display = '';
	if (isObject(getE("laurea_"+i+"_span")))		getE("laurea_"+i+"_span").style.display = 'none';
}

// visualizza il modulo di inserimento di un'altra specializzazione (fase 2 di 4)
function step2_add_specialization(i) {
	if (isObject(getE("specializzazione_"+(i+1)+"_div")))	getE("specializzazione_"+(i+1)+"_div").style.display = '';
	if (isObject(getE("specializzazione_"+i+"_span")))		getE("specializzazione_"+i+"_span").style.display = 'none';
}

// abilita i dettagli sulle lingue straniere parlate (fase 3 di 4)
function step3_show_lang(i) {
	if (getE('lingua_'+i).checked) {
		getE('lingua_'+i+'_livello_p').disabled = false;
		getE('lingua_'+i+'_livello_s').disabled = false;
		
		if (isObject(getE('lingua_'+i+'_altro'))) {
			getE('lingua_'+i+'_altro').disabled = false;
			getE('lingua_'+i+'_altro').focus();
		}
	}
	else {
		getE('lingua_'+i+'_livello_p').disabled = true;
		getE('lingua_'+i+'_livello_s').disabled = true;
		
		if (isObject(getE('lingua_'+i+'_altro')))
			getE('lingua_'+i+'_altro').disabled = true;
	}
}

// esegue controlli sulle singole cifre del codice fiscale
function codice_fiscale_check_char(id_part, ordernum) {
	var is_error = false;
	var filter=/^[a-z]{1}$/i
	if (ordernum==7 || ordernum==8 || ordernum==10 || ordernum==11 || ordernum==13 || ordernum==14 || ordernum==15)
		var filter=/^[0-9]{1}$/i
	
	if (filter.test(getE(id_part+ordernum.toString()).value)) {
		if (isObject(getE(id_part+(ordernum+1).toString()))) {
			getE(id_part+(ordernum+1).toString()).value = '';
			getE(id_part+(ordernum+1).toString()).focus();
		}
	}
	else
		getE(id_part+ordernum.toString()).value = '';
	
	return;
}

function is_valid_username(str, min_chars, max_chars) {
	var filter=/^[a-zA-Z0-9]{1,}[\.|\_|-]?[a-zA-Z0-9]{1,}$/i
	if (filter.test(str) && str.length>=min_chars) {
		if (max_chars>=min_chars) {
			if (str.length<=max_chars)
				return true;
			else
				return false;
		}
		else
			return true;
	}
	else
		return false;
}

function confirmLink(theLink, confirmMsg) {
	if (typeof(window.opera)!='undefined') {
		return true;
	}
	
	var is_confirmed = confirm(confirmMsg);
	return is_confirmed;
}

function regions_check_all() {
	var fields = document.getElementsByTagName("input");
	for (i=0; i<fields.length; i++) {
		if (fields[i].id=='prov_lavoro' && fields[i].type.toLowerCase()=='checkbox')
			fields[i].checked = getE('prov_lavoro_all').checked;
	}
}