diff --git a/t3lib/class.t3lib_div.php b/t3lib/class.t3lib_div.php
index 200bec44c5dc4281ce4edc3630ea40cbf75f8bf2..6e87e3f76553d96b329aa3411ff6f9ca1b3fd366 100755
--- a/t3lib/class.t3lib_div.php
+++ b/t3lib/class.t3lib_div.php
@@ -56,7 +56,7 @@
  *  466:     function fixed_lgd($string,$chars,$preStr='...')	
  *  488:     function fixed_lgd_pre($string,$chars)	
  *  502:     function breakTextForEmail($str,$implChar="\n",$charWidth=76)	
- *  522:     function breakLinesForEmail($str,$implChar="\n",$charWidth=76)	
+ *  522:     function breakLinesForEmail($str,$implChar="\n",$charWidth=76)
  *  558:     function cmpIP($baseIP, $list)	
  *  589:     function inList($in_list,$item)	
  *  602:     function rmFromList($element,$list)	
@@ -1513,22 +1513,34 @@ class t3lib_div {
 	
 	/**
 	 * Wraps JavaScript code XHTML ready with <script>-tags
+	 * Automatic re-identing of the JS code is done by using the first line as ident reference.
+	 * This is nice for identing JS code with PHP code on the same level.
 	 *
-	 * @param    string        JavaScript code
-	 * @return    string        The wrapped JS code, ready to put into a XHTML page
+	 * @param    string 	JavaScript code
+	 * @param	boolean 	Wrap script element in linebreaks? Default is TRUE.
+	 * @return    string 	The wrapped JS code, ready to put into a XHTML page
 	 * @author	Ingmar Schlecht <ingmars@web.de>
+	 * @author	René Fritz <r.fritz@colorcube.de>
 	 */
-	function wrapJS($JSCode) {
-		return '
-<script type="text/javascript">
-	/*<![CDATA[*/
-'.$JSCode.'
-	/*]]>*/
-</script>
-';
-	}
-
+	function wrapJS($string, $linebreak=TRUE) {
+		if(trim($string)) {
+				// <script wrapped in nl?
+			$cr = $linebreak? "\n" : '';
 
+				// remove nl from the beginning
+			$string = preg_replace ('/^\n+/', '', $string);
+				// re-ident to one tab using the first line as reference
+			if(preg_match('/^(\t+)/',$string,$match)) {
+				$string = str_replace($match[1],"\t", $string);
+			}
+			$string = $cr.'<script type="text/javascript">
+/*<![CDATA[*/
+'.$string.'
+/*]]>*/
+</script>'.$cr;
+		}
+		return trim($string);
+	}
 	/**
 	 * Parses XML input into a PHP array with associative keys
 	 * 
@@ -1783,7 +1795,7 @@ class t3lib_div {
 	function xmlGetHeaderAttribs($xmlData)	{
 		$xmlHeader = substr(trim($xmlData),0,200);
 		$reg=array();
-		if (eregi('^<\?xml([^>]*)\?>',$xmlHeader,$reg))	{
+		if (eregi('^<\?xml([^>]*)\?\>',$xmlHeader,$reg))	{
 			return t3lib_div::get_tag_attributes($reg[1]);
 		}
 	}
@@ -2950,4 +2962,4 @@ class t3lib_div {
 }
 
 
-?>
\ No newline at end of file
+?>
diff --git a/t3lib/class.t3lib_exec.php b/t3lib/class.t3lib_exec.php
index 21a7a50603b684a1662c1ea2e78adcd03d8050bd..af3a26bf7d4d35d3c8932a8c4dd9062d6bc346b5 100755
--- a/t3lib/class.t3lib_exec.php
+++ b/t3lib/class.t3lib_exec.php
@@ -29,7 +29,6 @@
  * @subpackage t3lib
  */
 
-#require_once(t3lib_extMgm::extPath('cc_debug').'class.tx_ccdebug.php');
 
 /**
  * returns exec command for a program
@@ -65,7 +64,7 @@ class t3lib_exec {
 	 *
 	 * @param 	string 	the command that should be executed. eg: "convert"
 	 * @param 	string 	executer for the command. eg: "perl"
-	 * @return 	boolean -1 if cmd is not found, or -2 if the handler is not found
+	 * @return 	boolean false if cmd is not found, or -1 if the handler is not found
 	 */
 	function checkCommand($cmd, $handler='')	{
 
@@ -76,7 +75,7 @@ class t3lib_exec {
 #debug($GLOBALS['t3lib_exec'], 't3lib_exec', __LINE__, __FILE__);
 
 		if ($handler && !t3lib_exec::checkCommand($handler)) {
-			return -2;
+			return -1;
 		}
 			// already checked and valid
 		if ($GLOBALS['t3lib_exec']['apps'][$cmd]['valid']) {
@@ -88,7 +87,7 @@ class t3lib_exec {
 		}
 		
 		reset($GLOBALS['t3lib_exec']['paths']);
-		while(list($path,$validPath)=each($GLOBALS['t3lib_exec']['paths'])) {
+		foreach($GLOBALS['t3lib_exec']['paths'] as $path => $validPath) {
 				// ignore invalid (false) paths
 			if ($validPath) {
 				if ($osType=='WIN') {
@@ -115,9 +114,9 @@ class t3lib_exec {
 			}
 		}
 
-			// try to get the executable with the command 'which'. It do the same like already done, but that on other paths??
+			// try to get the executable with the command 'which'. It do the same like already done, but maybe on other paths??
 		if ($osType=='UNIX') {
-			$cmd = exec ('which '.$val['cmd']);
+			$cmd = @exec ('which '.$val['cmd']);
 
 			if (@is_executable($cmd)) {
 				$GLOBALS['t3lib_exec']['apps'][$cmd]['app'] = $cmd;
@@ -127,7 +126,7 @@ class t3lib_exec {
 			}
 		}
 
-		return -1;
+		return false;
 	}
 	
 
@@ -138,7 +137,7 @@ class t3lib_exec {
 	 * @param 	string 	the command that should be executed. eg: "convert"
 	 * @param 	string 	handler (executor) for the command. eg: "perl"
 	 * @param 	string 	options for the handler, like '-w' for "perl"
-	 * @return 	mixed returns command string, or -1 if cmd is not found, or -2 if the handler is not found
+	 * @return 	mixed returns command string, or false if cmd is not found, or -1 if the handler is not found
 	 */
 	function getCommand($cmd, $handler='', $handlerOpt='')	{
 
@@ -149,14 +148,14 @@ class t3lib_exec {
 			$handler = t3lib_exec::getCommand($handler);
 
 			if (!$handler) {
-				return -2;
+				return -1;
 			}
 			$handler .= ' '.$handlerOpt.' ';
 		}
 
 			// command
 		if (!t3lib_exec::checkCommand($cmd)) {
-			return -1;
+			return false;
 		}
 		$cmd = $GLOBALS['t3lib_exec']['apps'][$cmd]['path'].$GLOBALS['t3lib_exec']['apps'][$cmd]['app'].' ';
 
diff --git a/t3lib/class.t3lib_extmgm.php b/t3lib/class.t3lib_extmgm.php
index 7f12bae0d1d90bb8618852db0779961acdb7d2cd..4f97c77de9cc6ca5bf5d01d14f8cc7c465ec5aa8 100644
--- a/t3lib/class.t3lib_extmgm.php
+++ b/t3lib/class.t3lib_extmgm.php
@@ -501,12 +501,31 @@ class t3lib_extMgm {
 				}
 
 				if( $info['available'] AND ($info['subtype']=='' XOR $info['serviceSubTypes'][$serviceSubType]) AND $info['priority']>=$priority ) {
+						// has a lower quality than the already found, therefore we skip this service
 					if($info['priority']==$priority AND $info['quality']<$quality) {
 						continue;
 					}
-					$serviceKey = $key;
-					$priority = $info['priority'];
-					$quality = $info['quality'];
+
+						// service depends on external programs - check if they exists
+					if(trim($info['exec'])) {
+						require_once(PATH_t3lib.'class.t3lib_exec.php');
+
+						$executables = t3lib_div::trimExplode(',', $info['exec'],1);
+						foreach($executables as $executable)	{
+							if(!t3lib_exec::checkCommand($executable)) {
+								t3lib_extMgm::deactivateService($serviceType, $key);
+								$info['available']=FALSE;
+								break;
+							}
+						}
+					}
+
+						// still available after exec check?
+					if($info['available']) {
+						$serviceKey = $key;
+						$priority = $info['priority'];
+						$quality = $info['quality'];
+					}
 				}
 			}
 		}
diff --git a/t3lib/class.t3lib_modsettings.php b/t3lib/class.t3lib_modsettings.php
index 37dc0f575457d878c825a537c548b631d00b5a53..4c6ed0827d437c9cc4489ccd09bbb5204987a796 100755
--- a/t3lib/class.t3lib_modsettings.php
+++ b/t3lib/class.t3lib_modsettings.php
@@ -172,7 +172,7 @@ class t3lib_modSettings {
 
 
 
-	function makeStoreControl($show='load,remove,save')	{
+	function getStoreControl($show='load,remove,save')	{
 			// Load/Save
 		$show = t3lib_div::trimexplode(',',$show,1);
 		$storeArray = $this->initStoreArray();
diff --git a/t3lib/class.t3lib_scbase.php b/t3lib/class.t3lib_scbase.php
index f77f528175d98d289711dd7a32e78854876f0c9a..b4b54682f79a965f669f6704ed76210dde92cbd7 100644
--- a/t3lib/class.t3lib_scbase.php
+++ b/t3lib/class.t3lib_scbase.php
@@ -41,12 +41,12 @@
  *  136: class t3lib_SCbase 
  *  252:     function init()	
  *  269:     function menuConfig()	
- *  289:     function mergeExternalItems($modName,$menuKey,$menuArr)	
+ *  289:     function mergeExternalItems($modName,$menuKey,$menuArr)
  *  308:     function handleExternalFunctionValue($MM_key='function')	
  *  325:     function getExternalItemConfig($modName,$menuKey,$value='')	
  *  339:     function checkExtObj()	
  *  353:     function checkSubExtObj()	
- *  362:     function extObjContent()	
+ *  362:     function extObjContent()
  *
  * TOTAL FUNCTIONS: 8
  * (This index is automatically created/updated by the extension "extdeveval")
@@ -55,7 +55,7 @@
 /**
  * EXAMPLE PROTOTYPE
  * 
- * As for examples there are lots of them if you search for classes which extends 't3lib_SCbase'. 
+ * As for examples there are lots of them if you search for classes which extends 't3lib_SCbase'.
  * However you can see a prototype example of how a module might use this class in an index.php file typically hosting a backend module.
  * NOTICE: This example only outlines the basic structure of how this class is used. You should consult the documentation and other real-world examples for some actual things to do when building modules.
  *  
@@ -347,7 +347,7 @@ class t3lib_SCbase {
 
 	/**
 	 * Calls the checkExtObj function in sub module if present.
-	 * 
+	 *
 	 * @return	void		
 	 */
 	function checkSubExtObj()	{
@@ -355,12 +355,25 @@ class t3lib_SCbase {
 	}
 
 	/**
-	 * Calls the main function inside the "Function menu module" if present
-	 * 
-	 * @return	void		
+	 * Calls the 'header' function inside the "Function menu module" if present.
+	 * A header function might be needed to add JavaScript or other stuff in the head. This can't be done in the main function because the head is already written.
+	 * example call in the header function:
+	 * $this->pObj->doc->JScode = $this->pObj->doc->wrapScriptTags(' ...
+	 *
+	 * @return	void
+	 */
+	function extObjHeader()	{
+		if (is_callable(array($this->extObj,'head')))	$this->extObj->head();
+	}
+
+	/**
+	 * Calls the 'main' function inside the "Function menu module" if present
+	 *
+	 * @return	void
 	 */
 	function extObjContent()	{
-		if (is_object($this->extObj))	$this->content.=$this->extObj->main();
+		$this->extObj->pObj = &$this;
+		if (is_callable(array($this->extObj, 'main')))	$this->content.=$this->extObj->main();
 	}
 }
-?>
\ No newline at end of file
+?>
diff --git a/t3lib/class.t3lib_svbase.php b/t3lib/class.t3lib_svbase.php
index fccef1d1b54e5cff35154b770b7940ad4387db44..08ba0d402d159513e74d2af6f905029a6e5a06cd 100755
--- a/t3lib/class.t3lib_svbase.php
+++ b/t3lib/class.t3lib_svbase.php
@@ -355,7 +355,7 @@ function available()	{
 	 * @param	string 	File name to write into. If empty a temp file will be created.
 	 * @return 	string 	File name or FALSE
 	 */
-	function writeFile (&$content, $absFile='')	{
+	function writeFile ($content, $absFile='')	{
 		$ret = TRUE;
 
 		if (!$absFile) {
diff --git a/t3lib/class.t3lib_tceforms.php b/t3lib/class.t3lib_tceforms.php
index b2ae2e028cff72ca2793473c52b6c0f496395224..fb1271edd133804445f67e93c30353f08d0d3e38 100755
--- a/t3lib/class.t3lib_tceforms.php
+++ b/t3lib/class.t3lib_tceforms.php
@@ -35,32 +35,32 @@
  *
  *
  *
- *  193: class t3lib_TCEforms	
+ *  193: class t3lib_TCEforms
  *  286:     function t3lib_TCEforms()	
  *  323:     function initDefaultBEmode()	
  *
  *              SECTION: Rendering the forms, fields etc
  *  366:     function getSoloField($table,$row,$theFieldToReturn)	
  *  405:     function getMainFields($table,$row,$depth=0)	
- *  532:     function getListedFields($table,$row,$list)	
+ *  532:     function getListedFields($table,$row,$list)
  *  574:     function getPaletteFields($table,$row,$palette,$header='',$itemList='',$collapsedHeader='')	
- *  650:     function getSingleField($table,$field,$row,$altName='',$palette=0,$extra='',$pal=0)	
- *  777:     function getSingleField_SW($table,$field,$row,&$PA)	
+ *  650:     function getSingleField($table,$field,$row,$altName='',$palette=0,$extra='',$pal=0)
+ *  777:     function getSingleField_SW($table,$field,$row,&$PA)
  *
  *              SECTION: Rendering of each TCEform field type
- *  848:     function getSingleField_typeInput($table,$field,$row,&$PA)	
- *  900:     function getSingleField_typeText($table,$field,$row,&$PA)	
- *  969:     function getSingleField_typeCheck($table,$field,$row,&$PA)	
- * 1028:     function getSingleField_typeRadio($table,$field,$row,&$PA)	
- * 1058:     function getSingleField_typeSelect($table,$field,$row,&$PA)	
- * 1217:     function getSingleField_typeGroup($table,$field,$row,&$PA)	
- * 1359:     function getSingleField_typeNone($table,$field,$row,&$PA)	
- * 1413:     function getSingleField_typeFlex($table,$field,$row,&$PA)	
- * 1514:     function getSingleField_typeFlex_langMenu($languages,$elName,$selectedLanguage,$multi=1)	
- * 1533:     function getSingleField_typeFlex_sheetMenu($sArr,$elName,$sheetKey)	
- * 1563:     function getSingleField_typeFlex_draw($dataStruct,$editData,$cmdData,$table,$field,$row,&$PA,$formPrefix='',$level=0,$tRows=array())	
- * 1712:     function getSingleField_typeUnknown($table,$field,$row,&$PA)	
- * 1727:     function getSingleField_typeUser($table,$field,$row,&$PA)	
+ *  848:     function getSingleField_typeInput($table,$field,$row,&$PA)
+ *  900:     function getSingleField_typeText($table,$field,$row,&$PA)
+ *  969:     function getSingleField_typeCheck($table,$field,$row,&$PA)
+ * 1028:     function getSingleField_typeRadio($table,$field,$row,&$PA)
+ * 1058:     function getSingleField_typeSelect($table,$field,$row,&$PA)
+ * 1217:     function getSingleField_typeGroup($table,$field,$row,&$PA)
+ * 1359:     function getSingleField_typeNone($table,$field,$row,&$PA)
+ * 1413:     function getSingleField_typeFlex($table,$field,$row,&$PA)
+ * 1514:     function getSingleField_typeFlex_langMenu($languages,$elName,$selectedLanguage,$multi=1)
+ * 1533:     function getSingleField_typeFlex_sheetMenu($sArr,$elName,$sheetKey)
+ * 1563:     function getSingleField_typeFlex_draw($dataStruct,$editData,$cmdData,$table,$field,$row,&$PA,$formPrefix='',$level=0,$tRows=array())
+ * 1712:     function getSingleField_typeUnknown($table,$field,$row,&$PA)
+ * 1727:     function getSingleField_typeUser($table,$field,$row,&$PA)
  *
  *              SECTION: "Configuration" fetching/processing functions
  * 1759:     function getRTypeNum($table,$row)	
@@ -75,7 +75,7 @@
  *              SECTION: Form element helper functions
  * 1990:     function dbFileIcons($fName,$mode,$allowed,$itemArray,$selector='',$params=array(),$onFocus='')	
  * 2099:     function renderWizards($itemKinds,$wizConf,$table,$row,$field,&$PA,$itemName,$specConf,$RTE=0)	
- * 2262:     function getIcon($icon)	
+ * 2262:     function getIcon($icon)
  * 2293:     function wrapOpenPalette($header,$table,$row,$palette,$retFunc=0)	
  * 2317:     function checkBoxParams($itemName,$thisValue,$c,$iCount,$addFunc='')	
  * 2331:     function elName($itemName)	
@@ -91,9 +91,9 @@
  * 2472:     function initItemArray($fieldValue)	
  * 2490:     function addItems($items,$iArray)	
  * 2512:     function procItems($items,$iArray,$config,$table,$row,$field)	
- * 2536:     function addSelectOptionsToItemArray($items,$fieldValue,$TSconfig,$field)	
- * 2614:     function addSelectOptionsToItemArray_makeModuleData($value)	
- * 2636:     function foreignTable($items,$fieldValue,$TSconfig,$field,$pFFlag=0)	
+ * 2536:     function addSelectOptionsToItemArray($items,$fieldValue,$TSconfig,$field)
+ * 2614:     function addSelectOptionsToItemArray_makeModuleData($value)
+ * 2636:     function foreignTable($items,$fieldValue,$TSconfig,$field,$pFFlag=0)
  *
  *              SECTION: Template functions
  * 2714:     function setFancyDesign()	
@@ -544,10 +544,9 @@ class t3lib_TCEforms	{
 
 		$out='';
 		$types_fieldConfig=t3lib_BEfunc::getTCAtypes($table,$row,1);
-		
+
 		$editFieldList=array_unique(t3lib_div::trimExplode(',',$list,1));
-		reset($editFieldList);
-		while(list(,$theFieldC)=each($editFieldList))	{
+		foreach($editFieldList as $theFieldC)	{
 			list($theField,$palFields) = split('\[|\]',$theFieldC);
 			$theField = trim($theField);
 			$palFields = trim($palFields);
@@ -668,7 +667,6 @@ class t3lib_TCEforms	{
 			// Get the TCA configuration for the current field:
 		$PA['fieldConf'] = $TCA[$table]['columns'][$field];
 
-		
 			// Now, check if this field is configured and editable (according to excludefields + other configuration)
 		if (	is_array($PA['fieldConf']) &&
 				(!$PA['fieldConf']['exclude'] || $BE_USER->check('non_exclude_fields',$table.':'.$field)) && 
@@ -721,7 +719,7 @@ class t3lib_TCEforms	{
 					$PA['fieldChangeFunc']=array();
 					$PA['fieldChangeFunc']['TBE_EDITOR_fieldChanged'] = "TBE_EDITOR_fieldChanged('".$table."','".$row['uid']."','".$field."','".$PA['itemFormElName']."');";
 					$PA['fieldChangeFunc']['alert']=$alertMsgOnChange;
-					
+
 						// Based on the type of the item, call a render function:
 					$item = $this->getSingleField_SW($table,$field,$row,$PA);
 
@@ -1074,15 +1072,14 @@ class t3lib_TCEforms	{
 
 			// Possibly remove some items:		
 		$removeItems=t3lib_div::trimExplode(',',$PA['fieldTSConfig']['removeItems'],1);
-		reset($selItems);
-		while(list($tk,$p)=each($selItems))	{
+		foreach($selItems as $tk => $p)	{
 			if (in_array($p[1],$removeItems))	{
 				unset($selItems[$tk]);
 			} else if (isset($PA['fieldTSConfig']['altLabels.'][$p[1]])) {
 				$selItems[$tk][0]=$this->sL($PA['fieldTSConfig']['altLabels.'][$p[1]]);
 			}
 		}
-		
+
 			// Creating the label for the "No Matching Value" entry.
 		$nMV_label = isset($PA['fieldTSConfig']['noMatchingValue_label']) ? $this->sL($PA['fieldTSConfig']['noMatchingValue_label']) : '[ '.sprintf($this->getLL('l_noMatchingValue'),$PA['itemFormElValue']).' ]';
 		
@@ -2544,7 +2541,7 @@ class t3lib_TCEforms	{
 	 */
 	function addSelectOptionsToItemArray($items,$fieldValue,$TSconfig,$field)	{
 		global $TCA;
-			
+
 			// Values from foreign tables:
 		if ($fieldValue['config']['foreign_table'])	{
 			$items = $this->foreignTable($items,$fieldValue,$TSconfig,$field);
@@ -2656,10 +2653,10 @@ class t3lib_TCEforms	{
 			// Perform lookup
 		$res = @mysql (TYPO3_db, $query);
 		if (mysql_error())	{ 
-			debug(array(mysql_error()."\n\nQuery:\n ".$query."\n\nThis may indicate a table defined in tables.php is not existing in the database!"));
-			exit;
+			echo(mysql_error()."\n\nQuery:\n ".$query."\n\nThis may indicate a table defined in tables.php is not existing in the database!");
+			return array();
 		}
-		
+
 			// Get label prefix.
 		$lPrefix = $this->sL($fieldValue['config'][$pF.'foreign_table_prefix']);
 
@@ -3890,4 +3887,4 @@ class t3lib_TCEforms_FE extends t3lib_TCEforms {
 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tceforms.php'])	{
 	include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tceforms.php']);
 }
-?>
\ No newline at end of file
+?>
diff --git a/t3lib/class.t3lib_tsparser_ext.php b/t3lib/class.t3lib_tsparser_ext.php
index abb45b0d45f3ca29876854e03f60f3fb6683130b..5ba0de1fb91d956361e4cfc678faf077d1545ae0 100755
--- a/t3lib/class.t3lib_tsparser_ext.php
+++ b/t3lib/class.t3lib_tsparser_ext.php
@@ -966,8 +966,8 @@ class t3lib_tsparser_ext extends t3lib_TStemplate	{
 										$p_field.='<input type="file" name="upload_'.$fN.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth().' onChange="uFormUrl('.$aname.')">';
 									}
 								break;
+								case 'small':
 								default:
-								case "small":
 									$fwidth= $typeDat["type"]=="small" ? 10 : 46;
 									$p_field='<input type="text" name="'.$fN.'" value="'.$fV.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth($fwidth).' onChange="uFormUrl('.$aname.')">';
 								break;