[fix] added country and time zone to global defaults
diff --git a/patches/october_2013/p06_update_control_panel_and_global_defaults.py b/patches/october_2013/p06_update_control_panel_and_global_defaults.py
new file mode 100644
index 0000000..dd5a1c1
--- /dev/null
+++ b/patches/october_2013/p06_update_control_panel_and_global_defaults.py
@@ -0,0 +1,22 @@
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import webnotes
+
+def execute():
+	webnotes.reload_doc("setup", "doctype", "global_defaults")
+
+	country = webnotes.conn.sql("""select value from `tabSingles` where 
+		field ='country' and doctype='Control Panel'""")
+	time_zone = webnotes.conn.sql("""select value from `tabSingles` where 
+		field ='timezone' and doctype='Control Panel'""")
+
+	cp_bean = webnotes.bean("Control Panel")
+	cp_bean.time_zone = time_zone
+	cp_bean.save()
+
+	gb_bean = webnotes.bean("Global Defaults")
+	gb_bean.country = country
+	gb_bean.time_zone = time_zone
+	gb_bean.save()
\ No newline at end of file
diff --git a/public/js/complete_setup.js b/public/js/complete_setup.js
index e565621..7448c7b 100644
--- a/public/js/complete_setup.js
+++ b/public/js/complete_setup.js
@@ -28,7 +28,7 @@
 					options: "", fieldtype: 'Select'},
 				{fieldname:'currency', label: 'Default Currency', reqd:1,
 					options: "", fieldtype: 'Select'},
-				{fieldname:'timezone', label: 'Time Zone', reqd:1,
+				{fieldname:'time_zone', label: 'Time Zone', reqd:1,
 					options: "", fieldtype: 'Select'},
 				{fieldname:'industry', label: 'Industry', reqd:1,
 					options: erpnext.complete_setup.domains.join('\n'), fieldtype: 'Select'},
@@ -51,10 +51,10 @@
 				d.get_input("currency").empty()
 					.add_options(wn.utils.unique([""].concat($.map(erpnext.country_info, 
 						function(opts, country) { return opts.currency; }))).sort());
-				d.get_input("timezone").empty()
+				d.get_input("time_zone").empty()
 					.add_options([""].concat(erpnext.all_timezones));
 			}
-		})
+		});
 		
 		// on clicking update
 		d.fields_dict.update.input.onclick = function() {
@@ -84,7 +84,7 @@
 
 		d.fields_dict.country.input.onchange = function() {
 			var country = d.fields_dict.country.input.value;
-			var $timezone = $(d.fields_dict.timezone.input);
+			var $timezone = $(d.fields_dict.time_zone.input);
 			$timezone.empty();
 			// add country specific timezones first
 			if(country){
diff --git a/setup/doctype/global_defaults/global_defaults.js b/setup/doctype/global_defaults/global_defaults.js
index 3999979..a4bdb48 100644
--- a/setup/doctype/global_defaults/global_defaults.js
+++ b/setup/doctype/global_defaults/global_defaults.js
@@ -1,9 +1,44 @@
 // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
 // License: GNU General Public License v3. See license.txt
 
-// Validate
-cur_frm.cscript.validate = function(doc, cdt, cdn) {
-	return $c_obj(make_doclist(cdt, cdn), 'get_defaults', '', function(r, rt){
-		sys_defaults = r.message;
-	});
-}
\ No newline at end of file
+$.extend(cur_frm.cscript, {
+	validate: function(doc, cdt, cdn) {
+		return $c_obj(make_doclist(cdt, cdn), 'get_defaults', '', function(r, rt){
+			sys_defaults = r.message;
+		});
+	},
+
+	refresh: function() {
+		var me = this;
+		wn.call({
+			method:"webnotes.country_info.get_country_timezone_info",
+			callback: function(data) {
+				erpnext.country_info = data.message.country_info;
+				erpnext.all_timezones = data.message.all_timezones;
+				// me.set_timezone_options();
+			}
+		});
+	},
+
+	country: function() {
+		var me = this;
+		var timezones = [];
+
+		if (this.frm.doc.country) {
+			var timezones = (erpnext.country_info[this.frm.doc.country].timezones || []).sort();
+		}
+
+		this.frm.set_value("time_zone", timezones[0]);
+		this.set_timezone_options(timezones);
+	},
+
+	set_timezone_options: function(filtered_options) {
+		if(!filtered_options) filtered_options = [];
+		var remaining_timezones = $.map(erpnext.all_timezones, function(v) 
+			{ return filtered_options.indexOf(v)===-1 ? v : null; });
+
+		this.frm.fields_dict.time_zone.df.options = 
+			(filtered_options.concat([""]).concat(remaining_timezones)).join("\n");
+		refresh_field("time_zone");
+	}
+});
\ No newline at end of file
diff --git a/setup/doctype/global_defaults/global_defaults.py b/setup/doctype/global_defaults/global_defaults.py
index 1b1d50c..4a3791b 100644
--- a/setup/doctype/global_defaults/global_defaults.py
+++ b/setup/doctype/global_defaults/global_defaults.py
@@ -29,6 +29,7 @@
 	def on_update(self):
 		"""update defaults"""
 		self.validate_session_expiry()
+		self.update_control_panel()
 		
 		for key in keydict:
 			webnotes.conn.set_default(key, self.doc.fields.get(keydict[key], ''))
@@ -57,7 +58,12 @@
 			if len(parts)!=2 or not (cint(parts[0]) or cint(parts[1])):
 				webnotes.msgprint("""Session Expiry must be in format hh:mm""",
 					raise_exception=1)
-				
-	
+
+	def update_control_panel(self):
+		cp_bean = webnotes.bean("Control Panel")
+		cp_bean.country = self.doc.country
+		cp_bean.time_zone = self.doc.time_zone
+		cp_bean.save()
+		
 	def get_defaults(self):
 		return webnotes.defaults.get_defaults()
diff --git a/setup/doctype/global_defaults/global_defaults.txt b/setup/doctype/global_defaults/global_defaults.txt
index a8a80b1..da40a19 100644
--- a/setup/doctype/global_defaults/global_defaults.txt
+++ b/setup/doctype/global_defaults/global_defaults.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-05-02 17:53:24", 
   "docstatus": 0, 
-  "modified": "2013-10-23 10:22:44", 
+  "modified": "2013-10-23 18:06:04", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -155,6 +155,13 @@
  }, 
  {
   "doctype": "DocField", 
+  "fieldname": "country", 
+  "fieldtype": "Select", 
+  "label": "Country", 
+  "options": "link:Country"
+ }, 
+ {
+  "doctype": "DocField", 
   "fieldname": "sms_sender_name", 
   "fieldtype": "Data", 
   "label": "SMS Sender Name", 
@@ -176,6 +183,12 @@
   "read_only": 0
  }, 
  {
+  "doctype": "DocField", 
+  "fieldname": "time_zone", 
+  "fieldtype": "Select", 
+  "label": "Time Zone"
+ }, 
+ {
   "doctype": "DocPerm"
  }
 ]
\ No newline at end of file
diff --git a/setup/doctype/setup_control/setup_control.py b/setup/doctype/setup_control/setup_control.py
index b78bfcc..818e310 100644
--- a/setup/doctype/setup_control/setup_control.py
+++ b/setup/doctype/setup_control/setup_control.py
@@ -141,7 +141,7 @@
 
 		# control panel
 		cp = webnotes.doc("Control Panel", "Control Panel")
-		for k in ['country', 'timezone', 'company_name']:
+		for k in ['country', 'time_zone', 'company_name']:
 			cp.fields[k] = args[k]
 			
 		cp.save()