function setAutoSaveOn() {
	if  (typeof(document.getElementById('auto_save'))!='undefined') {		
		document.getElementById('auto_save').innerHTML='Auto saving...';
		document.getElementById('auto_save').style.display='block';
	}
}

function setAutoSaveOff() {
	if  (typeof(document.getElementById('auto_save'))!='undefined') {	
		document.getElementById('auto_save').innerHTML='';
		document.getElementById('auto_save').style.display='none';
	}
}

function autoSaveForm(sSource,obj_id,obj_type_id) {
	
	frm=document.getElementById(sSource);
	for(iIndex=0;iIndex<frm.length;iIndex++) {

		sField=frm[iIndex].name;			
		// check if this field is a candidate for the auto save procedure.
		aField=sField.split("$");			
		bAutoSaveField=false;
		if (aField.length == 3) {
			sFieldType=aField[1];
			// text fields are allowed
			if (sFieldType=="text") {
				bAutoSaveField=true;
			}
		}
					
		if (bAutoSaveField) {
			// get value to save
			sValue=frm[iIndex].value;
			
			// check for editor field (which we need to approach differently):		
			if (typeof(aConnectEditorIdToFormId.mapping[sField])!='undefined') {					
				// editor found for this form field.					
				sEditorId=aConnectEditorIdToFormId.mapping[sField];
				if (sEditorMode=="tinymce") {
					var editor_reference;
					editor_reference=tinyMCE.getInstanceById(sEditorId);
					// reset value to the contents of the editor instance
					sValue=editor_reference.getHTML();	
				} else {
					alert('could not auto save, didn\'t recognize wysiwyg editor');
					sValue="";
				}
			}				
			
			if (sValue!="") {
				sValue=escape(sValue);
				sField=escape(sField);
				sUrl="main.php?obj_id="+obj_id + '&obj_type_id='+obj_type_id+'&action=save_field&form_field_name='+sField + '&value='+sValue;
				
				// save field
				synchronousSimplePost(sUrl,function (xmlhttp) {});
				setTimeout("setAutoSaveOff();", 2000);
			}
			
		}
	}	
}
