  
/* 
Module Javascript Skeleton

! Please remove all these comments before you upload your module.   Your users won't want to download all this stuff...

! This is beta-ish!  If you find bugs with it, please report them on the message board (linked in the top nav on iamalpha.com).
! If you have questions or things are clear, again, post something on the message board.

This skeleton should help you get started writing a module with an edit form and onload functions for view.   

You'll need to change the skeleton a little bit to use this skeleton:
1.  Add an onload attribute to the <body>, so it looks like this: <body (stuff) onload="formtester.init()">
2.  You need to create a reference to this file:
	2a. Save this file to your module's directory
	2b. Create a script tag: <script type="text/javascript" src="FILENAME.js"></script> in the <head> of your module.
3.  You also need to create a script tag for conf.js (just for now, we're working on fixing this), which you'll need to comment out before uploading your module: <script type="text/javascript" src="http://www.aimpages.com/.resource/jssdk/conf.js"></script>
	3a. conf.js should be loaded before this (the one you just created) file.

*/


/*

This section sets up your module's object and checks some stuff to see if it's running in AIM Pages or in standalone mode.
	- You may see some errors related to dojo packages and lop stuff.   They shouldn't keep you from developing your module (we hope).
	- If you're in standalone mode, you need to set the standalone property to true, and make sure you set it back to false before you upload your module.
	- You might want to use the debug property, or not.  It's up to you.
*/

if ( !formtester ) {
	var formtester={
		isinit:false,
		standalone:false,
		debug:false
	};
	
	if ( formtester.standalone && !formtester.isinit ) {
		var head=document.getElementsByTagName("head")[0];		
	    	djConfig={ baseScriptUri:"http://www.aimpages.com/.resource/jssdk/dojo-0.2.2", isDebug:true };
	    	lop_dojoBaseScriptUri="http://www.aimpages.com/.resource/jssdk/dojo-0.2.2";
	    	
	    	var ds=document.createElement("script");
	    		ds.setAttribute("type","text/javascript");
	    		ds.setAttribute("src","http://o.aolcdn.com/iamalpha/.resource/jssdk/dojo-0.2.2/dojo.js");
	    	var ls=ds.cloneNode(true);
	    		ls.setAttribute("src","http://www.aimpages.com/.resource/jssdk/lop.js");
	    	head.appendChild(ds);
	    	head.appendChild(ls);
	}
}

/* 
 formtester.init - The onload function that gets the module's DOM node and checks which action is being performed. 
 */

formtester.init=function(instance,action) {
	var module;
		
	module=dojo.byId(instance);
	
	if ( !instance ) {
		instance="form-tester";
		action="view";
		/* 
		You may want to run your edit function here, if it needs setting up.
		Otherwise, you'll want to create a link in your manifest outside of  edit or view that runs it for testing purposes.
		*/
		/* formtester.init('form-tester','edit'); */
	}
	
	switch(action) {
		case "edit":
			formtester.edit(instance,module);
			break;
	}
	formtester.isinit=true;
}

/*
formtester.edit - The function that gets called when your module's edit section is invoked.
*/

formtester.edit=function(instance,module) {
	var edit, form;
	
	edit=dojo.html.getElementsByClass("edit",module,"div")[0];
	
	lop_module_form_helper(instance,"edit");
	
	form=edit.getElementsByTagName("form")[0];
		
	dojo.event.connect(form,"onsubmit",function(evt) {
		lop_module_form_helper(instance,"save");
		//lop_mod_closeModEdit();
	});
	
}

/* formtester.n - This function REALLY does nothing */

formtester.n=function() {}

