fixed order by for common queries, should be ordered based on startswith match and then alphabetical order for fuzzy match
diff --git a/public/js/utils.js b/public/js/utils.js
index 6cd2c19..185baa6 100644
--- a/public/js/utils.js
+++ b/public/js/utils.js
@@ -22,7 +22,11 @@
 		from `tabProfile` where ifnull(enabled, 0)=1 and docstatus < 2 and \
 		name not in ('Administrator', 'Guest') and (%(key)s like \"%s\" or \
 		concat_ws(' ', first_name, middle_name, last_name) like \"%%%s\") \
-		order by name asc limit 50";
+		order by \
+		case when name like \"%s%%\" then 0 else 1 end, \
+		case when concat_ws(' ', first_name, middle_name, last_name) like \"%s%%\" \
+			then 0 else 1 end, \
+		name asc limit 50";
 };
 
 // searches for active employees
@@ -30,7 +34,10 @@
 	return "select name, employee_name from `tabEmployee` \
 		where status = 'Active' and docstatus < 2 and \
 		(%(key)s like \"%s\" or employee_name like \"%%%s\") \
-		order by name asc limit 50";
+		order by \
+		case when name like \"%s%%\" then 0 else 1 end, \
+		case when employee_name like \"%s%%\" then 0 else 1 end, \
+		name limit 50";
 };
 
 // searches for leads which are not converted
@@ -38,5 +45,9 @@
 	return "select name, lead_name, company_name from `tabLead` \
 		where docstatus < 2 and ifnull(status, '') != 'Converted' and \
 		(%(key)s like \"%s\" or lead_name like \"%%%s\" or company_name like \"%%%s\") \
-		order by lead_name asc limit 50";
+		order by \
+		case when name like \"%s%%\" then 0 else 1 end, \
+		case when lead_name like \"%s%%\" then 0 else 1 end, \
+		case when company_name like \"%s%%\" then 0 else 1 end, \
+		lead_name asc limit 50";
 };
diff --git a/selling/doctype/lead/lead.txt b/selling/doctype/lead/lead.txt
index b41fc51..666d702 100644
--- a/selling/doctype/lead/lead.txt
+++ b/selling/doctype/lead/lead.txt
@@ -3,9 +3,9 @@
 
 	# These values are common in all dictionaries
 	{
-		u'creation': '2012-08-08 10:41:31',
+		u'creation': '2012-11-19 12:06:56',
 		u'docstatus': 0,
-		u'modified': '2012-11-16 12:26:14',
+		u'modified': '2012-11-21 17:12:54',
 		u'modified_by': u'Administrator',
 		u'owner': u'Administrator'
 	},
@@ -40,12 +40,14 @@
 
 	# These values are common for all DocPerm
 	{
+		'amend': 0,
 		u'doctype': u'DocPerm',
 		u'name': u'__common__',
 		'parent': u'Lead',
 		'parentfield': u'permissions',
 		'parenttype': u'DocType',
-		'read': 1
+		'read': 1,
+		'submit': 0
 	},
 
 	# DocType, Lead
@@ -146,7 +148,7 @@
 	{
 		'colour': u'White:FFF',
 		'depends_on': u"eval:doc.source == 'Existing Customer'",
-		'description': u'Source of th',
+		'description': u'Source of the Lead',
 		u'doctype': u'DocField',
 		'fieldname': u'customer',
 		'fieldtype': u'Link',
@@ -626,77 +628,81 @@
 
 	# DocPerm
 	{
+		'cancel': 0,
+		'create': 0,
+		u'doctype': u'DocPerm',
+		'permlevel': 1,
+		'role': u'All',
+		'write': 0
+	},
+
+	# DocPerm
+	{
+		'cancel': 0,
 		'create': 1,
 		u'doctype': u'DocPerm',
 		'permlevel': 0,
-		'role': u'Guest',
+		'role': u'Sales User',
 		'write': 1
 	},
 
 	# DocPerm
 	{
-		'amend': 0,
-		'cancel': 0,
-		'create': 0,
-		u'doctype': u'DocPerm',
-		'permlevel': 1,
-		'role': u'Sales User',
-		'submit': 0,
-		'write': 0
-	},
-
-	# DocPerm
-	{
-		'amend': 0,
-		'cancel': 0,
-		'create': 0,
-		u'doctype': u'DocPerm',
-		'permlevel': 1,
-		'role': u'Sales Manager',
-		'submit': 0,
-		'write': 0
-	},
-
-	# DocPerm
-	{
-		'amend': 0,
 		'cancel': 1,
 		'create': 1,
 		u'doctype': u'DocPerm',
 		'permlevel': 0,
 		'role': u'Sales Manager',
-		'submit': 0,
 		'write': 1
 	},
 
 	# DocPerm
 	{
-		'amend': 0,
-		'cancel': 0,
-		'create': 1,
-		u'doctype': u'DocPerm',
-		'permlevel': 0,
-		'role': u'Sales User',
-		'submit': 0,
-		'write': 1
-	},
-
-	# DocPerm
-	{
-		u'doctype': u'DocPerm',
-		'permlevel': 1,
-		'role': u'All'
-	},
-
-	# DocPerm
-	{
-		'amend': 0,
 		'cancel': 0,
 		'create': 1,
 		u'doctype': u'DocPerm',
 		'permlevel': 0,
 		'role': u'System Manager',
-		'submit': 0,
+		'write': 1
+	},
+
+	# DocPerm
+	{
+		'cancel': 0,
+		'create': 0,
+		u'doctype': u'DocPerm',
+		'permlevel': 1,
+		'role': u'Sales Manager',
+		'write': 0
+	},
+
+	# DocPerm
+	{
+		'cancel': 0,
+		'create': 0,
+		u'doctype': u'DocPerm',
+		'permlevel': 1,
+		'role': u'Sales User',
+		'write': 0
+	},
+
+	# DocPerm
+	{
+		'cancel': 0,
+		'create': 1,
+		u'doctype': u'DocPerm',
+		'permlevel': 0,
+		'role': u'System Manager',
+		'write': 1
+	},
+
+	# DocPerm
+	{
+		'cancel': 0,
+		'create': 1,
+		u'doctype': u'DocPerm',
+		'permlevel': 0,
+		'role': u'Guest',
 		'write': 1
 	}
 ]
\ No newline at end of file
diff --git a/utilities/doctype/address/address.js b/utilities/doctype/address/address.js
index c4631f8..3b27ba8 100644
--- a/utilities/doctype/address/address.js
+++ b/utilities/doctype/address/address.js
@@ -15,8 +15,8 @@
 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 cur_frm.cscript.onload = function(doc, cdt, cdn) {
-	if(doc.customer) cur_frm.add_fetch('customer', 'customer_name', 'customer_name');
-	if(doc.supplier) cur_frm.add_fetch('supplier', 'supplier_name', 'supplier_name');
+	cur_frm.add_fetch('customer', 'customer_name', 'customer_name');
+	cur_frm.add_fetch('supplier', 'supplier_name', 'supplier_name');
 	
 	var route = wn.get_route();
 	if(route[1]=='Supplier') {