function ajaxPage(url, containerid, do_not_jump){
	/* fetches url, inserts response into container element,
	then runs commands. */
$(containerid).update('<img src="/images/loading.gif" />')	
//	if(auto_suggest_instance!=null){
		var mces = $$('.autosuggest');
		for (var i = 0; i<mces.length; i++){
			mces[i].remove();
		}
	//}
	if(do_not_jump!=true){
		Effect.ScrollTo(containerid, {offset:-60, duration:0.25});
	}
	new Ajax.Updater(containerid,url, {
	  evalScripts: true,
	  method:'post',
	  parameters:'ajax_target_id=' + containerid + "&item_mode_id=" + window_item_mode_id + "&item_mode_type=" + window_item_mode_type,
	  onComplete : function(transport){
	  	afterComp(containerid, do_not_jump);
	  }
	  	  
	});
}

function ajaxPost(url, postString, containerid, do_not_jump){
	/* posts url, inserts response into container element,
	then runs command */
	if(do_not_jump!=true){
		Effect.ScrollTo(containerid, {offset:-60, duration:0.25});
	}
	new Ajax.Updater(containerid, url, {
		method:'post',
		parameters:postString + "&item_mode_id=" + window_item_mode_id + "&item_mode_type=" + window_item_mode_type,	  
		evalScripts: true,
		onComplete: function(transport){
		  	afterComp(containerid, do_not_jump)
	  	}
	});
}

function afterComp(containerid, do_not_jump){
	textAreasInit();
	if(do_not_jump!=true){
		Effect.ScrollTo(containerid, {offset:-60, duration:0.25});
	}
}

var win
function ajaxPopup(url, window_id, w, h, postval){
	if(w==undefined||w>500){
 		w=500;
 	}
 	 if(h==undefined||h>400){
 		h=400;
 	}
 	if(window_id!=undefined){
 		window_id = 'popup_' + window_id;
 	}else{
		var randomnumber=Math.floor(Math.random()*11);
 		window_id = 'popup_' + randomnumber;
 	}
 	if($(window_id)){
 		win = Windows.getWindow(window_id);
 	}else{
		win = new Window(window_id, {className: "snpop", width:w, height:h, destroyOnClose:true, zIndex: 100, resizable: true, title: "", showEffect:Effect.BlindDown, hideEffect: Effect.SwitchOff, draggable:true, wiredDrag: true})
 	}
	win.setAjaxContent(url, {evalScripts: true,
	  method:'post',
	  parameters: postval + "&item_mode_id=" + window_item_mode_id + "&item_mode_type=" + window_item_mode_type
	},true,false); 
}
 
function closeAjaxPopup(window_id) {
	if(window_id==undefined){
		Windows.closeAll();
	}else{
		window_id = 'popup_' + window_id;
		Windows.close(window_id);
	}
	return true;
}


 function slideDiv(id){
 	element = $(id);
 	Effect.toggle(element.id, 'slide', {duration:1, toggle:true});
 }
 
 function ajaxSubmit(form, do_not_jump){
 	form=$(form);
 	try{
 		tinyMCE.triggerSave(true,true);
 	}catch(e){
 		
 	}
 	var submit_page = form.action + "&item_mode_id=" + window_item_mode_id + "&item_mode_type=" + window_item_mode_type;
 	var div = form.target;
 	//set fake hash that will not be saved - this way if the user edits the same object it will allow them to proceed
 	hashListener.setFakeHash(document.location.hash+'&submit=true');
 	//if form is being submitted through aframe, send to iframe @ this point as the rest is not needed
 	if(submit_page.indexOf('/aframe')!=-1){
 		form.action = submit_page + '?aframe_target=' + form.target;
 		form.target = 'iframe_submitter';
 		//add hidden item_mode and type to form
 		var additional_html = "<input type='hidden' name='item_mode_id' value='" + window_item_mode_id + "' /><input type='hidden' name='item_mode_type' value='" + window_item_mode_type + "' />";
		form.insert(additional_html);
 		form.onsubmit = '';
 		return true;
 	}
 	
 	
 	var postString = form.serialize();
 	postString += "&item_mode_id=" + window_item_mode_id + "&item_mode_type=" + window_item_mode_type;
 	var method = form.method;
 	
 	try{$('frmsub').addClassName('hidden')}catch(e){}
 	$(div).update('<img src="/images/loading.gif" />');
 	if(method.toLowerCase()=='post'){
 		//submit using post
 		ajaxPost(submit_page, postString, div, do_not_jump);
 	}else{
 		//submit using get
 		ajaxPage(submit_page + '?' + postString, div, do_not_jump)
 	}
 	
 	//return false to override actual submit of form.
 	return false;
 }

