toggleElementById = function(id) {
	$(id).disabled = !$(id).disabled;
}

function submitForm(index, stepBackFieldName, backButtonName) {
	//alert('  index: ' + index + ' formName: ' + formName + ' fieldName: ' + fieldName);
	// alert('elem value: ' + document.getElementById(fieldName).value + '
	// index: ' + index);
	document.getElementById(stepBackFieldName).value = index;
	// alert('elem value: ' + document.getElementById(fieldName).value + '
	// index: ' + index);
	clickButton(backButtonName);
}

function setRedirectUrl(popupName, fieldId){
	//alert(popupName + ' ::: ' + fieldId + ' ::: ' + window.location.href);
	var redirectUrl =  document.getElementById(fieldId).value;
	
	var indexOfShowOk = redirectUrl.lastIndexOf("showOkmyPage");
	
	if(redirectUrl == '' || indexOfShowOk > 0) 
		redirectUrl = window.location.href;
	var index = redirectUrl.lastIndexOf("?");
	if (index >0) redirectUrl = redirectUrl.substr(0, index);
	redirectUrl = redirectUrl + '?popup=' + popupName;
	$(fieldId).value = redirectUrl;
}

function clickButton(idButton){
	var button = document.getElementById(idButton);
	button.click();
}

document.observe("dom:loaded", function() {

	var mmMemberFlagSelect = $('formEntity.mmMemberFlag');
	var employerSelectorSelect = $('formEntity.idEmployerSector');
	var jobSelect = $('formEntity.idJob');
	var jobTypeSelect = $('formEntity.idJobType');

	if (jobTypeSelect) {
		var options = jobTypeSelect.options;
		var selectedValue = jobTypeSelect.selectedIndex;
		var value = options[selectedValue].value;
		if (value == '') {
			employerSelectorSelect.disabled = true;
			jobSelect.disabled = true;
			employerSelectorSelect.selectedIndex = 0;
			jobSelect.selectedIndex = 0;
		} else {
			employerSelectorSelect.disabled = false;
			jobSelect.disabled = false;
		}
	}
	/*
	if (mmMemberFlagSelect) {
		var options = mmMemberFlagSelect.options;
		var selectedValue = mmMemberFlagSelect.selectedIndex;
		var flag = options[selectedValue].value;
		if (flag == 'N') {
			$('formEntity.mmCardNumber').disabled = true;
		} else {
			$('formEntity.mmCardNumber').disabled = false;
		}
	}
	*/

});



function deleteFavourite(ob, url){
	if (ob == '0' && url == null) {

	}else{
		new Ajax.Request(url, {
			method: 'get',
			parameters: "id=" + ob,
			asynchronous: false,
			onSuccess: function(obj){
			}
		})
	};
};

function deleteAttachment(ob, url){
	if (ob == '0' && url == null) {

	}else{
		new Ajax.Request(url, {
			method: 'get',
			parameters: "id=" + ob,
			asynchronous: false,
			onSuccess: function(obj){
			}
		})
		
	};
};
function deleteRichiesteSalvate(ob, url,requestFormType){
	if (ob == '0' && url == null) {

	}else{
		new Ajax.Request(url, {
			method: 'get',
			//parameters: "id=" + ob,
			parameters: {id: ob, requestFormType: requestFormType},
			asynchronous: false,
			onSuccess: function(obj){
			}
		})
		
	};
};
function deletePreventiviSalvati(ob,url){
	if (ob == '0' && url == null) {

	}else{
		new Ajax.Request(url, {
			method: 'get',
			parameters: "id=" + ob,
			asynchronous: false,
			onSuccess: function(obj){
			}
		})
		
	};
};

function addFavourite(url){
	var pageURL = document.location.href;	
		new Ajax.Request(url, {
			method: 'get',
			parameters: {pageURL:pageURL},
			asynchronous: false,
			onSuccess: function(obj){
			}
		});
	
};

myLoadSelect = function(a, b, c, urlA, urlB){
	var valSelected = a.options[a.selectedIndex].value;
	var bObject = $(b);
	var cObject = $(c);
	var myVarB = bObject.options[0];
	var myVarC = cObject.options[0];

	
	var firstOptionB = '<option class="first" value="' + myVarB.value + '">' + myVarB.innerHTML + '</option>';
	var firstOptionC = '<option class="first" value="' + myVarC.value + '">' + myVarC.innerHTML + '</option>';
	if (a.selectedIndex == '0') {
		$(b).disabled = true;
		$(c).disabled = true;
		$(b).selectedIndex = "0";
		$(c).selectedIndex = "0";
	}else{
		new Ajax.Request(urlA, {
			method: 'post',
			parameters: "id=" + valSelected,
			onSuccess: function(obj){
				var o = obj.responseText;
				$(b).innerHTML = '';
				Element.insert($(b),{
					bottom : firstOptionB + o
				});
				$(b).disabled = false;
				$(b).selectedIndex = "0";
			}
		});
		new Ajax.Request(urlB, {
			method: 'post',
			parameters: "id=" + valSelected,
			onSuccess: function(obj){
				var o = obj.responseText;
				$(c).innerHTML = '';
				Element.insert($(c),{
					bottom : firstOptionC + o
				});
				$(c).disabled = false;
				$(c).selectedIndex = "0";
			}
		});
	}
}
