1.4.0 version changes
diff --git a/PhoneGapStarter.zip b/PhoneGapStarter.zip
index c472d58..a21ad87 100644
--- a/PhoneGapStarter.zip
+++ b/PhoneGapStarter.zip
Binary files differ
diff --git a/VERSION b/VERSION
index 589268e..e21e727 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-1.3.0
\ No newline at end of file
+1.4.0
\ No newline at end of file
diff --git a/framework/PhoneGap/Commands/Compass.cs b/framework/PhoneGap/Commands/Compass.cs
index 2ff915d..d8d8848 100644
--- a/framework/PhoneGap/Commands/Compass.cs
+++ b/framework/PhoneGap/Commands/Compass.cs
@@ -104,48 +104,20 @@
         }
         #endregion
 
-        //#region CompassHeading
-        ///// <summary>
-        ///// 
-        ///// </summary>
-        //[DataContract]
-        //public class CompassHeading
-        //{
-        //    /// <summary>
-        //    /// The heading in degrees from 0 - 359.99 at a single moment in time. 
-        //    /// </summary>
-        //    [DataMember(IsRequired = false, Name = "magneticHeading")]
-        //    public double MagneticHeading { get; set; }
-
-        //    /// <summary>
-        //    ///  The heading relative to the geographic North Pole in degrees 0 - 359.99 at a single moment in time. 
-        //    ///  A negative value indicates that the true heading could not be determined.
-        //    /// </summary>
-        //    [DataMember(IsRequired = false, Name = "trueHeading")]
-        //    public double TrueHeading { get; set; }
-
-        //    /// <summary>
-        //    /// The deviation in degrees between the reported heading and the true heading.
-        //    /// </summary>
-        //    [DataMember(IsRequired = false, Name = "headingAccuracy")]
-        //    public double HeadingAccuracy { get; set; }
-        //}
-
-        //#endregion
 
         /// <summary>
         /// Time the value was last changed
         /// </summary>
-        private DateTime lastValueChangedTime;
+        //private DateTime lastValueChangedTime;
 
         /// <summary>
         /// Accelerometer options
         /// </summary>
         private CompassOptions compassOptions;
 
-        bool isDataValid;
+        //bool isDataValid;
 
-        bool calibrating = false;
+        //bool calibrating = false;
 
         public Compass()
         {
@@ -344,16 +316,12 @@
             if (compass.IsDataValid)
             {
                 // trueHeading :: The heading in degrees from 0 - 359.99 at a single moment in time.
-
                 //  magneticHeading:: The heading relative to the geographic North Pole in degrees 0 - 359.99 at a single moment in time. 
                 //  A negative value indicates that the true heading could not be determined.
-                
                 // headingAccuracy :: The deviation in degrees between the reported heading and the true heading.
-
                 //rawMagnetometerReading = e.SensorReading.MagnetometerReading;
 
-                //compass.Stop();
-                Debug.WriteLine("Compass Result :: " + GetHeadingFormatted(e.SensorReading));
+                //Debug.WriteLine("Compass Result :: " + GetHeadingFormatted(e.SensorReading));
 
                 PluginResult result = new PluginResult(PluginResult.Status.OK,GetHeadingFormatted(e.SensorReading));
                 result.KeepCallback = true;
diff --git a/framework/PhoneGap/Commands/Device.cs b/framework/PhoneGap/Commands/Device.cs
index acf67b3..1d2348d 100644
--- a/framework/PhoneGap/Commands/Device.cs
+++ b/framework/PhoneGap/Commands/Device.cs
@@ -61,7 +61,7 @@
             get

             {

                 // TODO: should be able to dynamically read the PhoneGap version from somewhere...

-                return "1.3.0";

+                return "1.4.0";

             }

         }

 

diff --git a/framework/Properties/AssemblyInfo.cs b/framework/Properties/AssemblyInfo.cs
index 74b218d..e95cdc1 100644
--- a/framework/Properties/AssemblyInfo.cs
+++ b/framework/Properties/AssemblyInfo.cs
@@ -31,5 +31,5 @@
 //
 // You can specify all the values or you can default the Revision and Build Numbers 
 // by using the '*' as shown below:
-[assembly: AssemblyVersion("1.3.0.0")]
-[assembly: AssemblyFileVersion("1.3.0")]
+[assembly: AssemblyVersion("1.4.0")]
+[assembly: AssemblyFileVersion("1.4.0")]
diff --git a/framework/js/accelerometer.js b/framework/js/accelerometer.js
index f560d22..4f13e7d 100644
--- a/framework/js/accelerometer.js
+++ b/framework/js/accelerometer.js
@@ -93,7 +93,7 @@
  */
 Accelerometer.prototype.watchAcceleration = function(successCallback, errorCallback, options) 
 {
-
+	var self = this;
     // successCallback required
     if (typeof successCallback !== "function") {
         console.log("Accelerometer Error: successCallback is not a function");
diff --git a/framework/js/battery.js b/framework/js/battery.js
new file mode 100644
index 0000000..a606f4e
--- /dev/null
+++ b/framework/js/battery.js
@@ -0,0 +1,81 @@
+/*  
+	Licensed under the Apache License, Version 2.0 (the "License");
+	you may not use this file except in compliance with the License.
+	You may obtain a copy of the License at
+	
+	http://www.apache.org/licenses/LICENSE-2.0
+	
+	Unless required by applicable law or agreed to in writing, software
+	distributed under the License is distributed on an "AS IS" BASIS,
+	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+	See the License for the specific language governing permissions and
+	limitations under the License.
+*/
+
+if (!PhoneGap.hasResource("battery")) {
+
+PhoneGap.addResource("battery");
+
+PhoneGap.onPhoneGapInit.subscribeOnce(function() {
+
+	navigator.battery = navigator.battery || 
+	{
+
+
+		_events:{},
+		_isAttached:false,
+
+		_onBatteryStatusChanged:function(eventName,result)
+		{
+
+		},
+
+		addEventListener: function(eventName, funk)
+		{
+			this._events[eventName] = this._events[eventName] || [];
+			this._events[eventName].push(funk);
+			if(!this._isAttached)
+			{
+				// exec start
+			}
+		},
+
+		removeEventListener: function(eventName, funk)
+		{
+			if( eventName in this._events === false  )	
+				return;
+
+			this._events[eventName].splice(this._events[eventName].indexOf(funk), 1);
+			if(this._isAttached)
+			{
+				var hasListeners = false;
+				for(var v in this._events)
+				{
+					if(this._events[v].length)
+					{
+						hasListeners = true;
+						break;
+					}
+				}
+				if(!hasListeners)
+				{
+					// exec stop
+				}
+			}
+		},
+
+		dispatchEvent: function(eventName /* , args... */)
+		{
+			if( eventName in this._events === false  )	
+				return;
+			for(var i = 0; i < this._events[event].length; i++)
+			{
+				this._events[eventName][i].apply(this, Array.prototype.slice.call(arguments, 1))
+			}
+		}
+
+	};
+
+});
+
+}
\ No newline at end of file
diff --git a/framework/js/phonegap-1.4.0.js b/framework/js/phonegap-1.4.0.js
index 9a997bb..b1e3f62 100644
--- a/framework/js/phonegap-1.4.0.js
+++ b/framework/js/phonegap-1.4.0.js
@@ -751,7 +751,7 @@
  */
 Accelerometer.prototype.watchAcceleration = function(successCallback, errorCallback, options) 
 {
-
+	var self = this;
     // successCallback required
     if (typeof successCallback !== "function") {
         console.log("Accelerometer Error: successCallback is not a function");
@@ -1194,7 +1194,11 @@
 	this.isCompassSupported = true; // default assumption
 };
 
-Compass.ERROR_MSG = ["Not running", "Starting", "", "Failed to start", "Not Supported"];
+// Capture error codes
+CompassError = {
+	COMPASS_INTERNAL_ERR:0,
+	COMPASS_NOT_SUPPORTED:20
+}
 
 /**
  * Asynchronously aquires the current heading.
@@ -1224,15 +1228,15 @@
 		var self = this;
 		var onSuccess = function(result)
 		{
-			//var compassResult = JSON.parse(result);
-			console.log("compassResult = " + result);
-			self.lastHeading = result;
+			var compassResult = JSON.parse(result);
+			//console.log("compassResult = " + result);
+			self.lastHeading = compassResult;
 			successCallback(self.lastHeading);
 		}
 		
 		var onError = function(err)
 		{
-			if(err == 4)
+			if(err == CompassError.COMPASS_NOT_SUPPORTED)
 			{
 				self.isCompassSupported = false;	
 			}
@@ -1246,9 +1250,9 @@
 	{
 		var funk = function()
 		{
-			errorCallback(4);
+			errorCallback(CompassError.COMPASS_NOT_SUPPORTED);
 		};
-		window.setTimeout(funk,0);
+		window.setTimeout(funk,0); // async
 	}
 };
 
@@ -1263,7 +1267,8 @@
 Compass.prototype.watchHeading= function(successCallback, errorCallback, options) {
 
     // Default interval (100 msec)
-    var frequency = (options !== undefined) ? options.frequency : 100;
+    
+	var self = this;
 
     // successCallback required
     if (typeof successCallback !== "function") {
@@ -1279,22 +1284,36 @@
 	
 	if(this.isCompassSupported)
 	{	
-		var self = this;
-		var onInterval = function()
-		{
-			self.getCurrentHeading(successCallback,errorCallback,options);
+		var onSuccess = function (result) {
+			var compassResult = JSON.parse(result);
+			self.lastHeading = compassResult;
+			successCallback(self.lastHeading);
 		}
-		return window.setInterval(onInterval,frequency);
+	
+		var onError = function (err) {
+			errorCallback(err);
+		}
+	
+		var id = PhoneGap.createUUID();
+	
+		var params = {id:id,
+					  frequency:((options && options.frequency) ? options.frequency : 100)};
+	
+	
+		PhoneGap.exec(onSuccess, onError, "Compass", "startWatch", params);
+	
+		return id; 
 	}
 	else
 	{
 		var funk = function()
 		{
-			errorCallback(4);
+			errorCallback(CompassError.COMPASS_NOT_SUPPORTED);
 		};
-		window.setTimeout(funk,0);
+		window.setTimeout(funk,0); // async
 		return -1;
 	}
+
 };
 
 
@@ -1305,8 +1324,7 @@
  */
 Compass.prototype.clearWatch = function(id) {
 
-    // Stop javascript timer
-	clearInterval(id);
+	PhoneGap.exec(null, null, "Compass", "stopWatch", { id: id });
 
 };
 
diff --git a/templates/full/GapAppProj.csproj b/templates/full/GapAppProj.csproj
index fbb8c3a..6f17c02 100644
--- a/templates/full/GapAppProj.csproj
+++ b/templates/full/GapAppProj.csproj
@@ -56,7 +56,7 @@
     <Reference Include="System.Core" />
     <Reference Include="System.Net" />
     <Reference Include="System.Xml" />
-    <Reference Include="WP7GapClassLib, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL" />
+    <Reference Include="WP7GapClassLib, Version=1.4.0.0, Culture=neutral, processorArchitecture=MSIL" />
   </ItemGroup>
   <ItemGroup>
     <Compile Include="App.xaml.cs">
@@ -80,12 +80,12 @@
   <ItemGroup>
     <Content Include="GapLib\WP7GapClassLib.dll" />
     <Content Include="GapSourceDictionary.xml" />
+    <Content Include="www\phonegap-1.4.0.js" />
     <None Include="ManifestProcessor.js" />
     <Content Include="www\index.html">
       <SubType>Designer</SubType>
     </Content>
     <Content Include="www\master.css" />
-    <Content Include="www\phonegap-1.3.0.js" />
     <None Include="Properties\AppManifest.xml">
       <SubType>Designer</SubType>
     </None>
diff --git a/templates/full/GapLib/WP7GapClassLib.dll b/templates/full/GapLib/WP7GapClassLib.dll
index 1849fdc..ea609cc 100644
--- a/templates/full/GapLib/WP7GapClassLib.dll
+++ b/templates/full/GapLib/WP7GapClassLib.dll
Binary files differ
diff --git a/templates/full/www/index.html b/templates/full/www/index.html
index aaa07f4..1b7e8d7 100644
--- a/templates/full/www/index.html
+++ b/templates/full/www/index.html
@@ -8,7 +8,7 @@
     
 	  <link rel="stylesheet" href="master.css" type="text/css" media="screen" title="no title" charset="utf-8"/>
             
-      <script type="text/javascript" charset="utf-8" src="phonegap-1.3.0.js"></script>
+      <script type="text/javascript" charset="utf-8" src="phonegap-1.4.0.js"></script>
        
       <script type="text/javascript">
 
diff --git a/templates/full/www/phonegap-1.3.0.js b/templates/full/www/phonegap-1.4.0.js
similarity index 90%
rename from templates/full/www/phonegap-1.3.0.js
rename to templates/full/www/phonegap-1.4.0.js
index 70876df..b1e3f62 100644
--- a/templates/full/www/phonegap-1.3.0.js
+++ b/templates/full/www/phonegap-1.4.0.js
@@ -656,14 +656,19 @@
 }
 	
 
-/*
- * PhoneGap is available under *either* the terms of the modified BSD license *or* the
- * MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
- *
- * Copyright (c) 2005-2011, Nitobi Software Inc.
- * Copyright (c) 2010-2011, IBM Corporation
- * Copyright (c) 2011, Microsoft Corporation
- */
+/*  
+	Licensed under the Apache License, Version 2.0 (the "License");
+	you may not use this file except in compliance with the License.
+	You may obtain a copy of the License at
+	
+	http://www.apache.org/licenses/LICENSE-2.0
+	
+	Unless required by applicable law or agreed to in writing, software
+	distributed under the License is distributed on an "AS IS" BASIS,
+	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+	See the License for the specific language governing permissions and
+	limitations under the License.
+*/
 
 if (!PhoneGap.hasResource("accelerometer")) 
 {
@@ -746,7 +751,7 @@
  */
 Accelerometer.prototype.watchAcceleration = function(successCallback, errorCallback, options) 
 {
-
+	var self = this;
     // successCallback required
     if (typeof successCallback !== "function") {
         console.log("Accelerometer Error: successCallback is not a function");
@@ -801,14 +806,19 @@
 });
 }
 
-/*
- * PhoneGap is available under *either* the terms of the modified BSD license *or* the
- * MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
- *
- * Copyright (c) 2005-2010, Nitobi Software Inc.
- * Copyright (c) 2010-2011, IBM Corporation
- * Copyright (c) 2011, Microsoft Corporation
- */
+/*  
+	Licensed under the Apache License, Version 2.0 (the "License");
+	you may not use this file except in compliance with the License.
+	You may obtain a copy of the License at
+	
+	http://www.apache.org/licenses/LICENSE-2.0
+	
+	Unless required by applicable law or agreed to in writing, software
+	distributed under the License is distributed on an "AS IS" BASIS,
+	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+	See the License for the specific language governing permissions and
+	limitations under the License.
+*/
 
 if (!PhoneGap.hasResource("camera")) {
 PhoneGap.addResource("camera");
@@ -948,14 +958,19 @@
 });
 }
 
-/*
- * PhoneGap is available under *either* the terms of the modified BSD license *or* the
- * MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
- *
- * Copyright (c) 2005-2010, Nitobi Software Inc.
- * Copyright (c) 2010-2011, IBM Corporation
- * Copyright (c) 2011, Microsoft Corporation
- */
+/*  
+	Licensed under the Apache License, Version 2.0 (the "License");
+	you may not use this file except in compliance with the License.
+	You may obtain a copy of the License at
+	
+	http://www.apache.org/licenses/LICENSE-2.0
+	
+	Unless required by applicable law or agreed to in writing, software
+	distributed under the License is distributed on an "AS IS" BASIS,
+	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+	See the License for the specific language governing permissions and
+	limitations under the License.
+*/
 
 if (!PhoneGap.hasResource("capture")) {
 PhoneGap.addResource("capture");
@@ -1150,14 +1165,19 @@
 });
 }
 
-/*
- * PhoneGap is available under *either* the terms of the modified BSD license *or* the
- * MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
- *
- * Copyright (c) 2005-2010, Nitobi Software Inc.
- * Copyright (c) 2010-2011, IBM Corporation
- * Copyright (c) 2011, Microsoft Corporation
- */
+/*  
+	Licensed under the Apache License, Version 2.0 (the "License");
+	you may not use this file except in compliance with the License.
+	You may obtain a copy of the License at
+	
+	http://www.apache.org/licenses/LICENSE-2.0
+	
+	Unless required by applicable law or agreed to in writing, software
+	distributed under the License is distributed on an "AS IS" BASIS,
+	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+	See the License for the specific language governing permissions and
+	limitations under the License.
+*/
 
 if (!PhoneGap.hasResource("compass")) {
 PhoneGap.addResource("compass");
@@ -1174,7 +1194,11 @@
 	this.isCompassSupported = true; // default assumption
 };
 
-Compass.ERROR_MSG = ["Not running", "Starting", "", "Failed to start", "Not Supported"];
+// Capture error codes
+CompassError = {
+	COMPASS_INTERNAL_ERR:0,
+	COMPASS_NOT_SUPPORTED:20
+}
 
 /**
  * Asynchronously aquires the current heading.
@@ -1204,15 +1228,15 @@
 		var self = this;
 		var onSuccess = function(result)
 		{
-			//var compassResult = JSON.parse(result);
-			console.log("compassResult = " + result);
-			self.lastHeading = result;
+			var compassResult = JSON.parse(result);
+			//console.log("compassResult = " + result);
+			self.lastHeading = compassResult;
 			successCallback(self.lastHeading);
 		}
 		
 		var onError = function(err)
 		{
-			if(err == 4)
+			if(err == CompassError.COMPASS_NOT_SUPPORTED)
 			{
 				self.isCompassSupported = false;	
 			}
@@ -1226,9 +1250,9 @@
 	{
 		var funk = function()
 		{
-			errorCallback(4);
+			errorCallback(CompassError.COMPASS_NOT_SUPPORTED);
 		};
-		window.setTimeout(funk,0);
+		window.setTimeout(funk,0); // async
 	}
 };
 
@@ -1243,7 +1267,8 @@
 Compass.prototype.watchHeading= function(successCallback, errorCallback, options) {
 
     // Default interval (100 msec)
-    var frequency = (options !== undefined) ? options.frequency : 100;
+    
+	var self = this;
 
     // successCallback required
     if (typeof successCallback !== "function") {
@@ -1259,22 +1284,36 @@
 	
 	if(this.isCompassSupported)
 	{	
-		var self = this;
-		var onInterval = function()
-		{
-			self.getCurrentHeading(successCallback,errorCallback,options);
+		var onSuccess = function (result) {
+			var compassResult = JSON.parse(result);
+			self.lastHeading = compassResult;
+			successCallback(self.lastHeading);
 		}
-		return window.setInterval(onInterval,frequency);
+	
+		var onError = function (err) {
+			errorCallback(err);
+		}
+	
+		var id = PhoneGap.createUUID();
+	
+		var params = {id:id,
+					  frequency:((options && options.frequency) ? options.frequency : 100)};
+	
+	
+		PhoneGap.exec(onSuccess, onError, "Compass", "startWatch", params);
+	
+		return id; 
 	}
 	else
 	{
 		var funk = function()
 		{
-			errorCallback(4);
+			errorCallback(CompassError.COMPASS_NOT_SUPPORTED);
 		};
-		window.setTimeout(funk,0);
+		window.setTimeout(funk,0); // async
 		return -1;
 	}
+
 };
 
 
@@ -1285,8 +1324,7 @@
  */
 Compass.prototype.clearWatch = function(id) {
 
-    // Stop javascript timer
-	clearInterval(id);
+	PhoneGap.exec(null, null, "Compass", "stopWatch", { id: id });
 
 };
 
@@ -1300,14 +1338,19 @@
 });
 }
 
-/*
- * PhoneGap is available under *either* the terms of the modified BSD license *or* the
- * MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
- *
- * Copyright (c) 2005-2010, Nitobi Software Inc.
- * Copyright (c) 2010-2011, IBM Corporation
- * Copyright (c) 2011, Microsoft Corporation
- */
+/*  
+	Licensed under the Apache License, Version 2.0 (the "License");
+	you may not use this file except in compliance with the License.
+	You may obtain a copy of the License at
+	
+	http://www.apache.org/licenses/LICENSE-2.0
+	
+	Unless required by applicable law or agreed to in writing, software
+	distributed under the License is distributed on an "AS IS" BASIS,
+	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+	See the License for the specific language governing permissions and
+	limitations under the License.
+*/
 
 if (!PhoneGap.hasResource("contact")) {
 PhoneGap.addResource("contact");
@@ -1675,14 +1718,19 @@
 
 }
 
-/*
- * PhoneGap is available under *either* the terms of the modified BSD license *or* the
- * MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
- *
- * Copyright (c) 2005-2010, Nitobi Software Inc.
- * Copyright (c) 2010-2011, IBM Corporation
- * Copyright (c) 2011, Microsoft Corporation
- */
+/*  
+	Licensed under the Apache License, Version 2.0 (the "License");
+	you may not use this file except in compliance with the License.
+	You may obtain a copy of the License at
+	
+	http://www.apache.org/licenses/LICENSE-2.0
+	
+	Unless required by applicable law or agreed to in writing, software
+	distributed under the License is distributed on an "AS IS" BASIS,
+	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+	See the License for the specific language governing permissions and
+	limitations under the License.
+*/
 
 if (!PhoneGap.hasResource("device")) {
 PhoneGap.addResource("device");
@@ -1751,7 +1799,20 @@
     });
 }
 
-
+/*  
+	Licensed under the Apache License, Version 2.0 (the "License");
+	you may not use this file except in compliance with the License.
+	You may obtain a copy of the License at
+	
+	http://www.apache.org/licenses/LICENSE-2.0
+	
+	Unless required by applicable law or agreed to in writing, software
+	distributed under the License is distributed on an "AS IS" BASIS,
+	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+	See the License for the specific language governing permissions and
+	limitations under the License.
+*/
+
 // this is a WP7 Only implementation of the Storage API for use in webpages loaded from the local file system
 // inside phonegap application.
 // there is a native implementation which is backing this and providing the persistance of values.
@@ -1959,14 +2020,19 @@
 })();};
 
 
-/*
- * PhoneGap is available under *either* the terms of the modified BSD license *or* the
- * MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
- *
- * Copyright (c) 2005-2010, Nitobi Software Inc.
- * Copyright (c) 2010-2011, IBM Corporation
- * Copyright (c) 2011, Microsoft Corporation
- */
+/*  
+	Licensed under the Apache License, Version 2.0 (the "License");
+	you may not use this file except in compliance with the License.
+	You may obtain a copy of the License at
+	
+	http://www.apache.org/licenses/LICENSE-2.0
+	
+	Unless required by applicable law or agreed to in writing, software
+	distributed under the License is distributed on an "AS IS" BASIS,
+	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+	See the License for the specific language governing permissions and
+	limitations under the License.
+*/
 
 if (!PhoneGap.hasResource("file")) {
 PhoneGap.addResource("file");
@@ -3001,14 +3067,19 @@
 });
 }
 
-/*
- * PhoneGap is available under *either* the terms of the modified BSD license *or* the
- * MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
- *
- * Copyright (c) 2005-2010, Nitobi Software Inc.
- * Copyright (c) 2010-2011, IBM Corporation
- * Copyright (c) 2011, Microsoft Corporation
- */
+/*  
+	Licensed under the Apache License, Version 2.0 (the "License");
+	you may not use this file except in compliance with the License.
+	You may obtain a copy of the License at
+	
+	http://www.apache.org/licenses/LICENSE-2.0
+	
+	Unless required by applicable law or agreed to in writing, software
+	distributed under the License is distributed on an "AS IS" BASIS,
+	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+	See the License for the specific language governing permissions and
+	limitations under the License.
+*/
 
 if (!PhoneGap.hasResource("filetransfer")) {
 PhoneGap.addResource("filetransfer");
@@ -3098,14 +3169,19 @@
 };
 }
 
-/*
- * PhoneGap is available under *either* the terms of the modified BSD license *or* the
- * MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
- *
- * Copyright (c) 2005-2010, Nitobi Software Inc.
- * Copyright (c) 2010-2011, IBM Corporation
- * Copyright (c) 2011, Microsoft Corporation
- */
+/*  
+	Licensed under the Apache License, Version 2.0 (the "License");
+	you may not use this file except in compliance with the License.
+	You may obtain a copy of the License at
+	
+	http://www.apache.org/licenses/LICENSE-2.0
+	
+	Unless required by applicable law or agreed to in writing, software
+	distributed under the License is distributed on an "AS IS" BASIS,
+	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+	See the License for the specific language governing permissions and
+	limitations under the License.
+*/
 
 if (!PhoneGap.hasResource("media")) {
 PhoneGap.addResource("media");
@@ -3326,14 +3402,19 @@
 
 }
 
-/*
- * PhoneGap is available under *either* the terms of the modified BSD license *or* the
- * MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
- *
- * Copyright (c) 2005-2010, Nitobi Software Inc.
- * Copyright (c) 2010-2011, IBM Corporation
- * Copyright (c) 2011, Microsoft Corporation
- */
+/*  
+	Licensed under the Apache License, Version 2.0 (the "License");
+	you may not use this file except in compliance with the License.
+	You may obtain a copy of the License at
+	
+	http://www.apache.org/licenses/LICENSE-2.0
+	
+	Unless required by applicable law or agreed to in writing, software
+	distributed under the License is distributed on an "AS IS" BASIS,
+	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+	See the License for the specific language governing permissions and
+	limitations under the License.
+*/
 
 if (!PhoneGap.hasResource("network")) {
 PhoneGap.addResource("network");
@@ -3393,6 +3474,7 @@
 Connection.CELL_3G = "3g";
 Connection.CELL_4G = "4g";
 Connection.NONE = "none";
+Connection.CELL = "cellular";
 
 /**
  * Get connection info
@@ -3415,14 +3497,19 @@
 });
 }
 
-/*
- * PhoneGap is available under *either* the terms of the modified BSD license *or* the
- * MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
- *
- * Copyright (c) 2005-2011, Nitobi Software Inc.
- * Copyright (c) 2010-2011, IBM Corporation
- * Copyright (c) 2011, Microsoft Corporation
- */
+/*  
+	Licensed under the Apache License, Version 2.0 (the "License");
+	you may not use this file except in compliance with the License.
+	You may obtain a copy of the License at
+	
+	http://www.apache.org/licenses/LICENSE-2.0
+	
+	Unless required by applicable law or agreed to in writing, software
+	distributed under the License is distributed on an "AS IS" BASIS,
+	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+	See the License for the specific language governing permissions and
+	limitations under the License.
+*/
 
 if (!PhoneGap.hasResource("notification")) {
 PhoneGap.addResource("notification");
@@ -3544,12 +3631,27 @@
 });
 }
 
-/**
+/*  
+	Licensed under the Apache License, Version 2.0 (the "License");
+	you may not use this file except in compliance with the License.
+	You may obtain a copy of the License at
+	
+	http://www.apache.org/licenses/LICENSE-2.0
+	
+	Unless required by applicable law or agreed to in writing, software
+	distributed under the License is distributed on an "AS IS" BASIS,
+	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+	See the License for the specific language governing permissions and
+	limitations under the License.
+*/
+                          
+/**
  * @author purplecabbage
  */
                           
 (function(win,doc){
 
+
     doc.addEventListener("DOMContentLoaded",function()
     {
     	var docDomain = null;
@@ -3569,26 +3671,34 @@
 		
 			win.XMLHttpRequest = function(){};
 		
-			var UNSENT = 0;
-			var OPENED = 1;
-			var HEADERS_RECEIVED = 2;
-			var LOADING = 3;
-			var DONE = 4;
+			win.XMLHttpRequest.UNSENT = 0;
+			win.XMLHttpRequest.OPENED = 1;
+			win.XMLHttpRequest.HEADERS_RECEIVED = 2;
+			win.XMLHttpRequest.LOADING = 3;
+			win.XMLHttpRequest.DONE = 4;
 	          
 			win.XMLHttpRequest.prototype =
 			{
+                UNSENT:0,
+                OPENED:1,
+                HEADERS_RECEIVED:2,
+                LOADING:3,
+                DONE:4,
+
 				isAsync:false,
 				onreadystatechange:null,
-				readyState:UNSENT,
+				readyState:0,
+                _url:"",
 				open:function(reqType,uri,isAsync,user,password)
 				{
-					//console.log("XMLHttpRequest.open " + uri);
+					console.log("XMLHttpRequest.open " + uri);
 					if(uri && uri.indexOf("http") == 0)
 					{
 						if(!this.wrappedXHR)
 						{
-							//console.log("using wrapped XHR");
 							this.wrappedXHR = new aliasXHR();
+                            var self = this;
+
 							Object.defineProperty( this, "status", { get: function() {
 								return this.wrappedXHR.status;										
 							}});
@@ -3598,32 +3708,40 @@
 							Object.defineProperty( this, "statusText", { get: function() {
 								return this.wrappedXHR.statusText;										
 							}});
-							Object.defineProperty( this, "responseXML", { get: function() {
+
+                            Object.defineProperty( this, "responseXML", { get: function() {
 								return this.wrappedXHR.responseXML;										
-							}});
-							
-							this.getResponseHeader = function() {
-								return this.wrappedXHR.getResponseHeader.apply(this.wrappedXHR,arguments);
+							}});    
+                        
+							this.getResponseHeader = function(header) {
+								return this.wrappedXHR.getResponseHeader(header);
 							};
 							this.getAllResponseHeaders = function() {
-								return this.wrappedXHR.getAllResponseHeaders.apply(this.wrappedXHR,arguments);
+								return this.wrappedXHR.getAllResponseHeaders();
 							};
 							
-							this.wrappedXHR.onreadystatechange = this.onreadystatechange;
+							this.wrappedXHR.onreadystatechange = function()
+                            {
+                                self.changeReadyState(self.wrappedXHR.readyState);
+                            };
 						}
 						return this.wrappedXHR.open(reqType,uri,isAsync,user,password);
 					}
 					else
 					{
+                        // x-wmapp1://app/www/page2.html
                         // need to work some magic on the actual url/filepath
-		                var lastFileSlash = uri.lastIndexOf("\\");
-		                var newUrl =  "app/" + uri.substr(lastFileSlash + 1);
+		                var newUrl =  uri;
+                        if(newUrl.indexOf(":/") > -1)
+                        {
+                            newUrl = newUrl.split(":/")[1];
+                        }
+
 		                if(newUrl.lastIndexOf("/") === newUrl.length - 1)
 		                {
-		                    newUrl += "index.html"; // default page is index.html, when call is to a dir/
+		                    newUrl += "index.html"; // default page is index.html, when call is to a dir/ ( why not ...? )
 		                }
-						navigator.fileMgr.readAsText(newUrl,"UTF-8",this.onResult.bind(this),this.onError.bind(this));
-		                this.changeReadyState(OPENED);
+                        this._url = newUrl;
 					}
 				},
 				statusText:"",
@@ -3635,41 +3753,55 @@
 						this.onreadystatechange();	
 					}
 				},
-				getResponseHeader:function()
+				getResponseHeader:function(header)
 				{
-					return "";
+                    return this.wrappedXHR ?  this.wrappedXHR.getResponseHeader(header) : "";
 				},
 				getAllResponseHeaders:function()
 				{
-					return "";
+					return this.wrappedXHR ?  this.wrappedXHR.getAllResponseHeaders() : "";
 				},
 				responseText:"",
-				responseXML:function()
-				{
-					return new Document(this.responseText);
-				},
+				responseXML:"",
 				onResult:function(res)
 				{
 					this.status = 200;
 					this.responseText = res;
-					this.changeReadyState(DONE);
+
+                    Object.defineProperty( this, "responseXML", { get: function() {
+                        var parser = new DOMParser();
+						return parser.parseFromString(this.responseText,"text/xml");										
+					}}); 
+					this.changeReadyState(this.DONE);
 				},
 				onError:function(err)
 				{
-					//console.log("Received Error from FileAPI :: " + err);
+					console.log("Wrapped XHR received Error from FileAPI :: " + err);
 					this.status = 404;
-					this.changeReadyState(DONE);
+					this.changeReadyState(this.DONE);
 				},
+
+                abort:function()
+                {
+					if(this.wrappedXHR)
+					{
+						return this.wrappedXHR.abort();
+					}
+                },
 				
 				send:function(data)
 				{
 					if(this.wrappedXHR)
 					{
-						return this.wrappedXHR.send.apply(this.wrappedXHR,arguments);
+						return this.wrappedXHR.send(data);
 					}
+                    else
+                    {
+                        this.changeReadyState(this.OPENED);
+                        navigator.fileMgr.readAsText(this._url,"UTF-8",this.onResult.bind(this),this.onError.bind(this));
+                    }
 				},
-				status:404,
-				responseText:"empty"
+				status:404
 			};		  
 	    } // if doc domain 
 
@@ -3678,5 +3810,3 @@
 		  
 })(window,document);
 
-          
-