Index: trunk/CHANGELOG
===================================================================
--- trunk/CHANGELOG	(revision 1104)
+++ trunk/CHANGELOG	(revision 1105)
@@ -12,6 +12,8 @@
 
 ------------------------------------- 2.8.0 -------------------------------------
 6-Aug-2009 Matthias Gallas
++	Added option to use a frontend_body.js in modules to include javascript from modules
+	in the body of the frontend (Thanks to Luisehahne)
 !	Updated Danish language Files (Thanks to Achrist)
 #	Fixed some display issues in argos_theme (Thanks to Argos)
 30-July-2009 Ruud Eisinga (Ruud)
Index: trunk/wb/framework/module.functions.php
===================================================================
--- trunk/wb/framework/module.functions.php	(revision 1104)
+++ trunk/wb/framework/module.functions.php	(revision 1105)
@@ -155,7 +155,7 @@
 		
 		if($css_file == 'frontend.css') {
 			// check if frontend.css needs to be included into the <body> section
-			if(!((!function_exists('register_frontend_modfiles') || !defined('MOD_FRONTEND_CSS_REGISTERED')) && 
+			if(!((!function_exists('register_frontend_modfiles') || !defined('MOD_FRONTEND_CSS_REGISTERED')) &&
 					file_exists(WB_PATH .'/modules/' .$mymod_dir .'/frontend.css'))) {
 				return false;
 			} 
@@ -178,11 +178,11 @@
 if (!function_exists('requires_module_js')) {
 	function requires_module_js($mymod_dir, $js_file) {
 		if(!in_array(strtolower($js_file), array('frontend.js', 'backend.js'))) {
-			echo '<strong>Note: </strong>Javascript file "' .htmlentities($js_file) .'" 
-			specified in module "' .htmlentities($mymod_dir) .'" not valid.'; 
+			echo '<strong>Note: </strong>Javascript file "' .htmlentities($js_file) .'"
+			specified in module "' .htmlentities($mymod_dir) .'" not valid.';
 			return false;
 		}
-		
+
 		if($js_file == 'frontend.js') {
 			// check if frontend.js is included to the <head> section
 			if(!defined('MOD_FRONTEND_JAVASCRIPT_REGISTERED')) {
@@ -192,9 +192,9 @@
 				to ensure that module frontend.js files are automatically loaded if required.</p>
 				<code style="color: #800000;">&lt;?php<br />if(function_exists(\'register_frontend_modfiles\')) { <br />
 				&nbsp;&nbsp;register_frontend_modfiles(\'js\');<br />?&gt;</code><br />
-				<p><strong>Tip:</strong> For WB 2.6.7 copy the code above to the index.php of your template. 
-				Then open the view.php of the "' .htmlentities($mymod_dir) .'" module and set the variable 
-				<code>$requires_frontend_js</code> to false. This may do the trick.</p><p>All WB versions below 2.6.7 needs 
+				<p><strong>Tip:</strong> For WB 2.6.7 copy the code above to the index.php of your template.
+				Then open the view.php of the "' .htmlentities($mymod_dir) .'" module and set the variable
+				<code>$requires_frontend_js</code> to false. This may do the trick.</p><p>All WB versions below 2.6.7 needs
 				to be upgraded to work with this module.</p>
 				';
 				return false;
@@ -214,5 +214,45 @@
 		return true;
 	}
 }
+// function to check if the optional module Javascript files are loaded into the <body> section
+if (!function_exists('requires_module_body_js')) {
+	function requires_module_body_js($mymod_dir, $js_file) {
+		if(!in_array(strtolower($js_file), array('frontend_body.js', 'backend_body.js'))) {
+			echo '<strong>Note: </strong>Javascript file "' .htmlentities($js_file) .'"
+			specified in module "' .htmlentities($mymod_dir) .'" not valid.';
+			return false;
+		}
 
+		if($js_file == 'frontend_body.js') {
+			// check if frontend_body.js is included to the <body> section
+			if(!defined('MOD_FRONTEND_BODY_JAVASCRIPT_REGISTERED')) {
+				echo '<p><strong>Note:</strong> The module: "' .htmlentities($mymod_dir) .'" requires WB 2.6.7 or higher</p>
+				<p>This module uses Javascript functions contained in frontend_body.js of the module.<br />
+				Add the code below before to the &lt;/body&gt; section in the index.php of your template
+				to ensure that module frontend_body.js files are automatically loaded if required.</p>
+				<code style="color: #800000;">&lt;?php<br />if(function_exists(\'register_frontend_modfiles_body\')) { <br />
+				&nbsp;&nbsp;register_frontend_modfiles_body(\'js\');<br />?&gt;</code><br />
+				<p><strong>Tip:</strong> For WB 2.6.7 copy the code above to the index.php of your template.
+				Then open the view.php of the "' .htmlentities($mymod_dir) .'" module and set the variable
+				<code>$requires_frontend_body_js</code> to false. This may do the trick.</p><p>All WB versions below 2.6.7 needs
+				to be upgraded to work with this module.</p>
+				';
+				return false;
+			}
+		} else {
+			// check if backend_body.js is included to the <body> section
+			global $admin;
+				if(!method_exists($admin, 'register_backend_modfiles_body') && file_exists(WB_PATH .'/modules/' .$mymod_dir .'/backend_body.js')) {
+				echo '<p><strong>Note:</strong> The module: "' .htmlentities($mymod_dir) .'" requires WB 2.6.7 or higher</p>
+				<p>This module uses Javascript functions contained in backend_body.js of the module.<br />
+				You need WB 2.6.7 or higher to ensure that module backend_body.js files are automatically loaded if required.</p>
+				<p>Sorry, you can not use this tool with your WB installation, please upgrade to the latest WB version available.</p><br />
+				';
+				return false;
+			}
+		}
+		return true;
+	}
+}
+
 ?>
\ No newline at end of file
Index: trunk/wb/framework/frontend.functions.php
===================================================================
--- trunk/wb/framework/frontend.functions.php	(revision 1104)
+++ trunk/wb/framework/frontend.functions.php	(revision 1105)
@@ -325,12 +325,58 @@
 	}
 }
 
+// Function to add optional module Javascript into the <body> section of the frontend
+if(!function_exists('register_frontend_modfiles_body')) {
+	function register_frontend_modfiles_body($file_id="js") {
+		// sanity check of parameter passed to the function
+		$file_id = strtolower($file_id);
+		if($file_id !== "css" && $file_id !== "javascript" && $file_id !== "js") {
+			return;
+		}
+
+		global $wb, $database;
+		// define default baselink and filename for optional module javascript files
+		$body_links = "";
+        $base_link = '<script src="'.WB_URL.'/modules/{MODULE_DIRECTORY}/frontend_body.js" type="text/javascript"></script>';
+        $base_file = "frontend_body.js";
+
+		// gather information for all models embedded on actual page
+		$page_id = $wb->page_id;
+		$query_modules = $database->query("SELECT module FROM " .TABLE_PREFIX ."sections
+				WHERE page_id=$page_id AND module<>'wysiwyg'");
+
+		while($row = $query_modules->fetchRow()) {
+			// check if page module directory contains a frontend_body.js file
+			if(file_exists(WB_PATH ."/modules/" .$row['module'] ."/$base_file")) {
+					// create link with frontend_body.js source for the current module
+				$tmp_link = str_replace("{MODULE_DIRECTORY}", $row['module'], $base_link);
+
+				// define constant indicating that the register_frontent_files was invoked
+					if(!defined('MOD_FRONTEND_BODY_JAVASCRIPT_REGISTERED')) define('MOD_FRONTEND_BODY_JAVASCRIPT_REGISTERED', true);
+
+				// ensure that frontend_body.js is only added once per module type
+				if(strpos($body_links, $tmp_link) === false) {
+					$body_links .= $tmp_link ."\n";
+				}
+			};
+		}
+
+		/* include the Javascript email protection function
+		if( $file_id != 'css' && file_exists(WB_PATH .'/modules/droplets/js/mdcr.js')) {
+			$body_links .= '<script type="text/javascript" src="'.WB_URL.'/modules/droplets/js/mdcr.js"></script>'."\n";
+		} elseif( $file_id != 'css' && file_exists(WB_PATH .'/modules/output_filter/js/mdcr.js')) {
+			$body_links .= '<script type="text/javascript" src="'.WB_URL.'/modules/output_filter/js/mdcr.js"></script>'."\n";
+		} */
+		echo $body_links;
+	}
+}
+
 // Function to add optional module Javascript or CSS stylesheets into the <head> section of the frontend
 if(!function_exists('register_frontend_modfiles')) {
 	function register_frontend_modfiles($file_id="css") {
 		// sanity check of parameter passed to the function
 		$file_id = strtolower($file_id);
-		if($file_id !== "css" && $file_id !== "javascript" && $file_id !== "js") { 
+		if($file_id !== "css" && $file_id !== "javascript" && $file_id !== "js") {
 			return;
 		}
 
@@ -338,11 +384,11 @@
 		// define default baselink and filename for optional module javascript and stylesheet files
 		$head_links = "";
 		if($file_id == "css") {
-			$base_link = '<link href="'.WB_URL.'/modules/{MODULE_DIRECTORY}/frontend.css"'; 
+			$base_link = '<link href="'.WB_URL.'/modules/{MODULE_DIRECTORY}/frontend.css"';
 			$base_link.= ' rel="stylesheet" type="text/css" media="screen" />';
 			$base_file = "frontend.css";
 		} else {
-			$base_link = '<script type="text/javascript" src="'.WB_URL.'/modules/{MODULE_DIRECTORY}/frontend.js"></script>';
+			$base_link = '<script src="'.WB_URL.'/modules/{MODULE_DIRECTORY}/frontend.js" type="text/javascript"></script>';
 			$base_file = "frontend.js";
 		}
 
