function showDialog( dialogId, msg ) {
		
		
		dijit.byId(dialogId).attr("content",msg);
		
		dijit.byId(dialogId).show();
									
}	

function doPost(formId) {
	
  
	var kw = {
      
      form: formId,
      // The used data format:
      handleAs: "json",

      // Callback on successful call:
      load: function(response, ioArgs) {
					
					showDialog("dialogBox",response.items[0].messageSuccess);
					try {
					dojo.forEach( dijit.byId(formId).getDescendants(), 
							    function (entry) {
										   if (entry.name == dijit.byId( formId ).attr("value").key ) 
										       entry.attr("value",response.items[0][entry.name]);
								}
					);	
					} catch(e) {}
      },
      
		error: function(response, ioArgs){
				alert('erro');
		}
		
  }
	if (dijit.byId( formId ) != null) {
		if (dijit.byId( formId ).validate())
			dojo.io.iframe.send(kw);
	}	
	else
	   dojo.io.iframe.send(kw);
	
}



function loadXhr(formId, table, keyName, keyValue, fnc) {
	
				  if ( keyValue != '' ) {
				  		dojo.xhrGet({
						    			url: 'inc/loadData.php?table='+table+'&'+keyName+'='+keyValue,
						    			handleAs: "json",
										preventCache : true,
						    			load: function(response){
													
													responseArray = response.items[0];
							    					try {
													dojo.forEach( dijit.byId( formId ).getDescendants(), 
							    								  function (entry, i) {
								    									
								    									     if ( entry.type == 'text' || entry.type == 'hidden' || entry.type == 'password')
																		 		   try {
								    									     			entry.attr("value",response.items[0][entry.name]);							    									
							    									     	       }
							    									     	       catch (e) {
								    									     	   	 	entry.attr("displayedValue",response.items[0][entry.name]);   
							    									     	   	   }
																		 	 else if ( entry.type == 'radio' || entry.type == 'checkbox' ) {
																		 		  if (entry.value == response.items[0][entry.name] )
																		 		      entry.attr("checked",true);
																			 }
																			 else {
																				  
																				 if (entry.declaredClass == 'dijit.Editor') {
																					 entry.setValue(response.items[0][entry.id]);
																				 }		 
																			 }  	  
																	}
								    				);
								    		//alert(fnc);		
											//console.debug(fckeditor);
											if (fnc != null) fnc(response);			
											} catch (e) {}
						            	},
						    			error: function(data){
													console.debug(data);
													showDialog("Erro ao carregar o registro!");
											}
					    			});
			 		}	
	
}

function loadXhrObject(table, keyName, keyValue, fnc) {
	
				  if ( keyValue != '' ) {
				  		dojo.xhrGet({
						    			url: 'inc/loadData.php?table='+table+'&'+keyName+'='+keyValue,
						    			handleAs: "json",
										preventCache : true,
						    			load: function(response){
													//console.debug(response.items.length);
													
													fnc(response);		
											
						            	},
						    			error: function(data){
													console.debug(data);
													showDialog("Erro ao carregar o registro!");
											}
					    			});
					}		
	
}