Sourced wnframework-modules from Google Code as erpnext
diff --git a/setup/page/__init__.py b/setup/page/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/setup/page/__init__.py
diff --git a/setup/page/import_data/__init__.py b/setup/page/import_data/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/setup/page/import_data/__init__.py
diff --git a/setup/page/import_data/import_data.html b/setup/page/import_data/import_data.html
new file mode 100644
index 0000000..a4b30f4
--- /dev/null
+++ b/setup/page/import_data/import_data.html
@@ -0,0 +1,55 @@
+<div class="layout_wrapper">
+<div id="di_header"></div>
+<div style="margin: 8px">
+<table style="border-collapse: collapse;" border="0">
+<tbody>
+<tr>
+<td style="border: 1px solid #aaaaaa; padding: 4px; width: 60%;">
+	
+<form action="index.cgi" enctype="multipart/form-data" method="POST" target="ImportIFrame"> <input name="cmd" type="hidden" value="import_csv" /> 
+<h3 style="background-color: #EEF; padding: 2px;">Step 1. Download Template</h3>
+<select id="import_template" style="margin: 10px;"> <option>Select Master...</option> </select>
+
+<div style="margin: 10px; margin-top: 0px;"><input name="overwrite" type="checkbox"/> Over-write records with same name?</div>
+<div id="child_tab_lst"></div>
+<h3 style="background-color: #EEF; padding: 2px;">Step 2. Upload and Import</h3>
+<table style="width: 480px;" border="0" cellspacing="10px">
+<tbody>
+<tr>
+<td width="200px">Select CSV File to be imported</td>
+<td><input name="csv_file" type="file" /></td>
+</tr>
+<tr>
+<td width="200px">Date format in source CSV</td>
+<td><select name="dateformat"> <option value="yyyy-mm-dd">yyyy-mm-dd</option> <option value="mm/dd/yyyy">mm/dd/yyyy</option> <option value="mm/dd/yy">mm/dd/yy</option> <option value="dd-mm-yyyy">dd-mm-yyyy</option> <option value="dd/mm/yyyy">dd/mm/yyyy</option> </select></td>
+</tr>
+<tr>
+<td>&nbsp;</td>
+<td>
+<div id="import_btn"><input type="submit" value="Import" /></div>
+</td>
+</tr>
+</tbody>
+</table>
+</form>
+<div style="background-color: #FFE; padding: 10px; margin: 10px;">
+<h3>Data Import Guide</h3>
+<ol>
+<li>Get the template of the DocType for which you want to import in CSV (Comma seperated values) format.</li>
+<li>Fill in the data in the template. You can remove columns that are not relevant</li>
+<li>Save the template in CSV format</li>
+<li>Select the saved CSV file, identify the date format if any</li>
+<li>Click on "Import"</li>
+</ol></div>
+</td>
+<td style="border: 1px solid #AAA; padding: 4px;">
+<h3>Import Log:</h3>
+<div id="import_result_area">
+<iframe src="blank1.html" name="ImportIFrame" style="border: 0px; height: 500px; width: 100%"></iframe>
+</div>
+</td>
+</tr>
+</tbody>
+</table>
+</div>
+</div>
\ No newline at end of file
diff --git a/setup/page/import_data/import_data.js b/setup/page/import_data/import_data.js
new file mode 100644
index 0000000..aa0bdbd
--- /dev/null
+++ b/setup/page/import_data/import_data.js
@@ -0,0 +1,45 @@
+pscript['onload_Import Data'] = function() {
+  
+  //alert(profile.can_get_report);
+
+  callback = function(r,rt) {
+    var h = new PageHeader('di_header','Import Data','Tool to download template and upload data');
+    var sel = $i('import_template');
+    if(r.message){
+      add_sel_options(sel, r.message);
+      sel.onchange=function(){
+        $i('child_tab_lst').innerHTML ='';
+        if(sel.value != 'Select Master...'){
+          $c_obj('Import Data Control','get_child_lst',sel.value,
+            function(r,rt){
+              var me = this;
+              $y($i('child_tab_lst'),{backgroundColor:'#EEEEEE'})
+              var desc = $a($i('child_tab_lst'), 'div', '', {padding:'8px'});
+              
+              desc.innerHTML = "<h4>Please click on following link(s) to download template.</h4>";
+ 
+              
+              var parent = $a($i('child_tab_lst'), 'div');
+              var tab = make_table(parent,r.message.length,1,'100%',[],{padding:'8px',fontSize:'15px',borderCollapse: 'collapse'});
+              
+              for(var i=0;i<r.message.length;i++){
+                var dt= $a($td(tab,i,0), 'span', 'link_type');
+                dt.innerHTML = r.message[i];
+                dt.nm = r.message[i];
+                
+
+                dt.onclick = function(){ 
+					var ovr = $('input[name="overwrite"]:checked').length;
+                    window.location = outUrl + '?cmd=get_template&dt=' + this.nm + (ovr ? '&overwrite=1' : '');
+                }
+              }
+            }  
+          );
+        }
+      }
+    }
+  }
+  $c_obj('Import Data Control','get_master_lst','',callback);
+  
+
+}
diff --git a/setup/page/import_data/import_data.txt b/setup/page/import_data/import_data.txt
new file mode 100644
index 0000000..b422f12
--- /dev/null
+++ b/setup/page/import_data/import_data.txt
@@ -0,0 +1,106 @@
+[
+	{
+		'author': None,
+		'category': 'Standard',
+		'content': None,
+		'creation': '2010-12-14 10:33:09',
+		'docstatus': 0,
+		'doctype': 'Page',
+		'file_list': None,
+		'icon': None,
+		'idx': None,
+		'keywords': None,
+		'menu_index': None,
+		'modified': '2011-05-02 16:28:00',
+		'modified_by': 'Administrator',
+		'module': 'Setup',
+		'name': 'Import Data',
+		'owner': 'Administrator',
+		'page_name': 'Import Data',
+		'page_title': None,
+		'parent': None,
+		'parent_node': None,
+		'parentfield': None,
+		'parenttype': None,
+		'publish': None,
+		'script': None,
+		'show_in_menu': 0,
+		'site_description': None,
+		'standard': 'Yes',
+		'static_content': None,
+		'style': None,
+		'stylesheet': None,
+		'template': None,
+		'write_content': None
+	},
+	{
+		'creation': '2010-12-14 10:33:09',
+		'docstatus': 0,
+		'doctype': 'Page Role',
+		'idx': 1,
+		'modified': '2011-05-02 16:28:00',
+		'modified_by': 'Administrator',
+		'name': 'PR000224',
+		'owner': 'Administrator',
+		'parent': 'Import Data',
+		'parentfield': 'roles',
+		'parenttype': 'Page',
+		'role': 'Administrator'
+	},
+	{
+		'creation': '2010-12-14 10:33:09',
+		'docstatus': 0,
+		'doctype': 'Page Role',
+		'idx': 2,
+		'modified': '2011-05-02 16:28:00',
+		'modified_by': 'Administrator',
+		'name': 'PR000225',
+		'owner': 'harshada@webnotestech.com',
+		'parent': 'Import Data',
+		'parentfield': 'roles',
+		'parenttype': 'Page',
+		'role': 'System Manager'
+	},
+	{
+		'creation': '2010-12-14 10:33:09',
+		'docstatus': 0,
+		'doctype': 'Page Role',
+		'idx': 3,
+		'modified': '2011-05-02 16:28:00',
+		'modified_by': 'Administrator',
+		'name': 'PR000226',
+		'owner': 'harshada@webnotestech.com',
+		'parent': 'Import Data',
+		'parentfield': 'roles',
+		'parenttype': 'Page',
+		'role': 'Sales Master Manager'
+	},
+	{
+		'creation': '2010-12-14 10:33:09',
+		'docstatus': 0,
+		'doctype': 'Page Role',
+		'idx': 4,
+		'modified': '2011-05-02 16:28:00',
+		'modified_by': 'Administrator',
+		'name': 'PR000227',
+		'owner': 'harshada@webnotestech.com',
+		'parent': 'Import Data',
+		'parentfield': 'roles',
+		'parenttype': 'Page',
+		'role': 'Purchase Master Manager'
+	},
+	{
+		'creation': '2010-12-14 10:33:09',
+		'docstatus': 0,
+		'doctype': 'Page Role',
+		'idx': 5,
+		'modified': '2011-05-02 16:28:00',
+		'modified_by': 'Administrator',
+		'name': 'PR000228',
+		'owner': 'harshada@webnotestech.com',
+		'parent': 'Import Data',
+		'parentfield': 'roles',
+		'parenttype': 'Page',
+		'role': 'Material Master Manager'
+	}
+]
\ No newline at end of file
diff --git a/setup/page/people/__init__.py b/setup/page/people/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/setup/page/people/__init__.py
diff --git a/setup/page/people/people.comp.js b/setup/page/people/people.comp.js
new file mode 100644
index 0000000..8938b6a
--- /dev/null
+++ b/setup/page/people/people.comp.js
@@ -0,0 +1,50 @@
+
+pscript.onload_people=function(){make_customer_tab($i('crm_home'));}
+function make_customer_tab(parent){new DocColumnView('Customers',parent,['Customer Group','Customer','Contact'],{'Customer Group':{show_fields:['name'],create_fields:['name'],search_fields:['name'],next_col:'Customer'},'Customer':{show_fields:['name','customer_name'],create_fields:['name','customer_name'],search_fields:['customer_name'],filter_by:['Customer Group','customer_group'],next_col:'Contact'},'Contact':{show_fields:['name','first_name','last_name'],create_fields:['name','first_name','last_name'],search_fields:['first_name','last_name'],conditions:['is_customer=1'],filter_by:['Customer','customer']},})}
+function DocColumnView(title,parent,items,opts){this.columns={};this.items=items;this.page_head=new PageHeader(parent,title);this.make_columns(items.length,parent);for(var i=0;i<items.length;i++){var c=opts[items[i]];this.columns[items[i]]=new List2(this,$td(this.tab,0,i),items[i],c);}
+this.columns[items[0]].run();}
+DocColumnView.prototype.make_columns=function(n,parent){var cl=[];for(var i=0;i<n;i++){cl.push(cint(100/n)+'%')}
+this.tab=make_table(parent,1,n,'100%',cl)
+this.tab.className='dcv-tab';}
+DocColumnView.prototype.refresh=function(){this.columns[this.items[0]].run();}
+function List2(dcv,parent,doctype,opts){this.dcv=dcv;this.doctype=doctype;this.opts=opts;this.dtl=get_doctype_label(doctype);this.make_body(parent);this.selected_item=null;}
+List2.prototype.make_body=function(parent){this.make_toolbar(parent);this.make_search(parent);this.make_message(parent);this.make_list(parent);this.clear();}
+List2.prototype.make_toolbar=function(parent){var me=this;this.head=$a(parent,'div','list2-head');$gr(this.head,'#EEE','#CCC');var t=make_table(this.head,1,2,'100%',['60%','40%'],{verticalAlign:'middle'});var span=$a($td(t,0,0),'span','',{cssFloat:'left'},this.dtl);var refresh_icon=$a($td(t,0,0),'div','wn-icon ic-playback_reload',{marginLeft:'7px',cssFloat:'left'});refresh_icon.onclick=function(){me.run();}
+this.btn=$btn($td(t,0,1),'+ New',function(){me.make_new();},{fontWeight:'bold',cssFloat:'right'},'green');}
+List2.prototype.make_search=function(parent){var me=this;this.searchbar=$a(parent,'div','list2-search');this.search_inp=$a_input(this.searchbar,'text');this.search_btn=$a(this.searchbar,'img','',{cursor:'pointer',marginLeft:'8px',marginBottom:'-3px'});this.search_btn.src='images/icons/magnifier.png';this.search_btn.onclick=function(){me.run();}}
+List2.prototype.make_message=function(parent){this.clear_message=$a(parent,'div','help_box',{margin:'4px',display:'none'},(this.opts.filter_by?('Select '+get_doctype_label(this.opts.filter_by[0])+' to see list'):''));this.no_result_message=$a(parent,'div','help_box',{margin:'4px',display:'none'},'No '+this.dtl+' created yet!');}
+List2.prototype.make_new=function(){var me=this;newdoc(this.doctype,function(dn){if(me.opts.filter_by){var val=me.dcv.columns[me.opts.filter_by[0]].get_selected();if(val)
+locals[me.doctype][dn][me.opts.filter_by[1]]=val;}});}
+List2.prototype.clear=function(){$dh(this.lst_area);$ds(this.clear_message)
+$dh(this.no_result_message);this.clear_next();}
+List2.prototype.show_list=function(){$ds(this.lst_area);$dh(this.clear_message)
+$dh(this.no_result_message);}
+List2.prototype.show_no_result=function(){if(!this.search_inp.value){$dh(this.lst_area);$dh(this.clear_message);$ds(this.no_result_message);}}
+List2.prototype.clear_next=function(){if(this.opts.next_col&&this.dcv.columns[this.opts.next_col])this.dcv.columns[this.opts.next_col].clear();}
+List2.prototype.make_list=function(parent){var me=this;this.lst_area=$a(parent,'div','list2-list-area');this.lst=new Listing('Profiles',1);this.lst.opts.hide_refresh=1;this.lst.opts.cell_style={padding:'0px'};this.lst.colwidths=['100%'];this.lst.get_query=function(){var q=me.build_query();this.query=q[0];this.query_max=q[1];}
+this.lst.make(this.lst_area);this.lst.show_cell=function(cell,ri,ci,d){new List2Item(cell,d[ri],me);}
+this.lst.onrun=function(){me.show_list();me.clear_next();if(!me.lst.has_data())me.show_no_result();}}
+List2.prototype.run=function(){$dh(this.lst.results);this.lst.run();}
+List2.prototype.build_query=function(){var args={fields:this.opts.show_fields.join(', '),doctype:this.doctype,cond:''}
+var cl=this.build_search_conditions();cl=this.add_filter_condition(cl);if(cl.length)args.cond=' AND '+cl.join(' AND ');var query=repl('SELECT %(fields)s FROM `tab%(doctype)s` WHERE docstatus < 2 %(cond)s',args)
+var query_max=repl('SELECT COUNT(*) FROM `tab%(doctype)s` WHERE docstatus < 2 %(cond)s',args)
+return[query,query_max]}
+List2.prototype.build_search_conditions=function(){var cl=new Array();if(this.opts.conditions){for(var i=0;i<this.opts.conditions.length;i++)cl.push(this.opts.conditions);}
+if(this.search_inp.value&&this.search_inp.value!='Search'){for(var i=0;i<this.opts.search_fields.length;i++){cl.push(repl('`%(field)s` LIKE "%(txt)s"',{field:this.opts.search_fields[i],txt:'%'+this.search_inp.value+'%'}));}}
+return cl;}
+List2.prototype.add_filter_condition=function(cl){if(this.opts.filter_by){cl.push(repl('`%(filter)s` = "%(val)s"',{filter:this.opts.filter_by[1],val:this.dcv.columns[this.opts.filter_by[0]].get_selected()}));}
+return cl;}
+List2.prototype.get_selected=function(){if(this.selected_item)return this.selected_item.det[0];else return'';}
+List2Item=function(cell,det,list2){this.det=det;this.list2=list2;this.make_body(cell);this.show_text();this.show_more_info();}
+List2Item.prototype.make_body=function(cell){var me=this;this.body=$a(cell,'div','list2-item-div')
+if(me.list2.opts.next_col){this.make_with_icon();}else{this.content=this.body;}
+this.body.onclick=function(){me.select();if(me.list2.opts.next_col)me.list2.dcv.columns[me.list2.opts.next_col].run();}}
+List2Item.prototype.make_with_icon=function(){var t=make_table(this.body,1,2,'100%',['','18px'])
+$y($td(t,0,1),{verticalAlign:'middle'})
+var img=$a($td(t,0,1),'img');img.src='images/icons/control_play.png';this.content=$td(t,0,0);}
+List2Item.prototype.show_text=function(){var me=this;this.label=$a(this.content,'div','list2-item-title','',this.det[0]);var span=$a(this.label,'span','link_type list2-edit-link','','[Edit]');span.onclick=function(){loaddoc(me.list2.doctype,me.det[0]);}}
+List2Item.prototype.show_more_info=function(){var det=this.det;if(det.length>1){var l=[];for(var i=1;i<det.length;i++){if(det[i]&&det[i]!=det[0])l.push(det[i]);}
+if(l.length)
+this.more_info=$a(this.content,'div','list2-item-more-info','',l.join(', '))}}
+List2Item.prototype.select=function(){if(this.list2.selected_item)this.list2.selected_item.deselect();this.body.className='list2-item-div list2-item-selected';this.list2.selected_item=this;}
+List2Item.prototype.deselect=function(){this.body.className='list2-item-div';}
\ No newline at end of file
diff --git a/setup/page/people/people.html b/setup/page/people/people.html
new file mode 100644
index 0000000..ad31e38
--- /dev/null
+++ b/setup/page/people/people.html
@@ -0,0 +1 @@
+<div id="crm_home"></div>
\ No newline at end of file
diff --git a/setup/page/people/people.js b/setup/page/people/people.js
new file mode 100644
index 0000000..fd316bf
--- /dev/null
+++ b/setup/page/people/people.js
@@ -0,0 +1,32 @@
+//make tabs
+
+pscript.onload_people = function() {
+	make_customer_tab($i('crm_home'));
+}
+
+function make_customer_tab(parent) {	
+	new wn.widgets.DocColumnView('Customers', parent, ['Customer Group', 'Customer', 'Contact'], {
+		'Customer Group': { 
+			show_fields : ['name'],
+			create_fields : ['name'],
+			search_fields : ['name'],
+			next_col: 'Customer'
+		},
+		'Customer': { 
+			show_fields : ['name', 'customer_name'],
+			create_fields : ['name', 'customer_name'],
+			search_fields : ['customer_name'],
+			filter_by : ['Customer Group', 'customer_group'],
+			next_col: 'Contact'
+		},
+		'Contact': { 
+			show_fields : ['name', 'first_name', 'last_name'],
+			create_fields : ['name','first_name', 'last_name'],
+			search_fields : ['first_name', 'last_name'],
+			conditions: ['is_customer=1'],
+			filter_by : ['Customer', 'customer']
+		},
+	})
+}
+
+
diff --git a/setup/page/people/people.txt b/setup/page/people/people.txt
new file mode 100644
index 0000000..3e7bba2
--- /dev/null
+++ b/setup/page/people/people.txt
@@ -0,0 +1,26 @@
+[
+	{
+		'content': None,
+		'creation': '2011-03-21 12:12:32',
+		'docstatus': 0,
+		'doctype': 'Page',
+		'icon': None,
+		'idx': None,
+		'menu_index': None,
+		'modified': '2011-03-21 12:13:39',
+		'modified_by': 'Administrator',
+		'module': 'Setup',
+		'name': 'people',
+		'owner': 'Administrator',
+		'page_name': 'People',
+		'parent': None,
+		'parent_node': None,
+		'parentfield': None,
+		'parenttype': None,
+		'script': None,
+		'show_in_menu': None,
+		'standard': 'Yes',
+		'static_content': None,
+		'style': None
+	}
+]
\ No newline at end of file
diff --git a/setup/page/permission_engine/__init__.py b/setup/page/permission_engine/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/setup/page/permission_engine/__init__.py
diff --git a/setup/page/permission_engine/permission_engine.comp.js b/setup/page/permission_engine/permission_engine.comp.js
new file mode 100644
index 0000000..f0c9b1c
--- /dev/null
+++ b/setup/page/permission_engine/permission_engine.comp.js
@@ -0,0 +1,75 @@
+
+pscript['onload_Permission Engine']=function(){var h=new PageHeader('pe_header','Permissions Manager','Set specific permissions for Roles')
+if(!pscript.perm_engine)pscript.perm_engine=new pscript.PermEngine();}
+pscript.PermEngine=function(){this.wrapper=$i('perm_engine_div');this.head=$a(this.wrapper,'div');this.body=$a(this.wrapper,'div');this.footer=$a(this.wrapper,'div');var lab=$a(this.body,'div','',{backgroundColor:'#FFD',padding:'8px',margin:'16px 0px'});lab.innerHTML='Please select the item for which you want to set permissions';this.make_head();this.load_options();}
+pscript.PermEngine.prototype.make_head=function(){var me=this;var make_select=function(label){var w=$a(me.head,'div','',{margin:'8px 0px'});var t=make_table(w,1,2,'300px',['50%','50%']);$td(t,0,0).innerHTML=label;var s=$a($td(t,0,1),'select','',{width:'140px'});s.wrapper=w;return s;}
+var make_button=function(label,parent,green){return $btn(parent,label,null,{margin:'8px 0px',display:'none'},(green?'green':null));}
+this.type_select=make_select('Set Permissions For');this.type_select.onchange=function(){me.get_permissions();}
+this.add_button=make_button('+ Add A New Rule',this.head,0);this.add_button.onclick=function(){me.add_permission();}
+this.update_button=make_button('Update',this.footer,1);this.update_button.onclick=function(){me.update_permissions();}}
+pscript.PermEngine.prototype.add_permission=function(){var me=this;if(!this.add_permission_dialog){var d=new Dialog(400,400,'Add Permission');d.make_body([['Select','Role'],['Select','Level'],['Button','Add']])
+add_sel_options(d.widgets['Role'],this.roles,'');add_sel_options(d.widgets['Level'],[0,1,2,3,4,5,6,7,8,9],0);d.widgets['Add'].onclick=function(){if(!sel_val(d.widgets['Role'])){msgprint('Please select Role');return;}
+var callback=function(r,rt){me.get_permissions();d.hide();}
+$c_obj('Permission Control','add_permission',JSON.stringify([sel_val(me.type_select),sel_val(d.widgets['Role']),sel_val(d.widgets['Level'])]),callback);}
+this.add_permission_dialog=d;}
+this.add_permission_dialog.show();}
+pscript.PermEngine.prototype.hide_fields=function(){$dh(this.role_select.wrapper);this.type_select.disabled=false;this.body.innerHTML='';}
+pscript.PermEngine.prototype.load_options=function(){var me=this;$dh(me.update_button);$dh(me.add_button);$c_obj('Permission Control','get_doctype_list','',function(r,rt){me.roles=r.message.roles;empty_select(me.type_select);add_sel_options(me.type_select,add_lists([''],r.message.doctypes));});}
+pscript.PermEngine.prototype.get_permissions=function(){var me=this;if(!sel_val(me.type_select)){msgprint('Please select a type first!');return;}
+$c_obj('Permission Control','get_permissions',sel_val(me.type_select),function(r,rt){if(r.message.perms.length)me.get_results(r.message);else me.body.innerHTML='<div style = "color : red; margin:8px 0px;">No Records Found</div>'});}
+pscript.PermEngine.prototype.get_results=function(r){var perms=r.perms;var me=this;var doctype=sel_val(me.type_select);$ds(me.update_button);$ds(me.add_button);this.body.innerHTML=''
+pscript.all_checkboxes=[];pscript.all_matches=[];var head=$a(this.body,'h3');head.innerHTML='Rules for '+doctype;var permt=make_table(me.body,perms.length+1,9,'80%',[],{border:'1px solid #AAA',padding:'3px',verticalAlign:'middle',height:'30px'});var col_labels=['Role','Level','Read','Write','Create','Submit','Cancel','Amend','Restrict By']
+for(var n=0;n<col_labels.length;n++){$y($td(permt,0,n),{backgroundColor:'#DDD',width:(n==0?'30%':(n==8?'21%':'7%'))})
+$td(permt,0,n).innerHTML=col_labels[n];$td(permt,0,n).fieldname=col_labels[n].toLowerCase();}
+for(var j=0;j<perms.length;j++){var plevel=$a($td(permt,j+1,1),'span','link_type');plevel.innerHTML=perms[j].permlevel;plevel.doctype=doctype;plevel.value=perms[j].permlevel;plevel.onclick=function(){me.get_fields(this.doctype,this.value)}
+$td(permt,j+1,0).innerHTML=perms[j].role;}
+for(var l=0;l<perms.length;l++){for(var m=0;m<6;m++){var chk=$a_input($td(permt,l+1,m+2),'checkbox');var val=perms[l][$td(permt,0,m+2).fieldname];if(val==1)chk.checked=1;else chk.checked=0;chk.doctype=doctype;chk.permlevel=perms[l].permlevel;chk.perm_type=col_labels[m+2].toLowerCase();chk.role=perms[l].role;pscript.all_checkboxes.push(chk);}}
+me.add_match_select(r,perms,permt,doctype);}
+pscript.PermEngine.prototype.add_match_select=function(r,perms,permt,doctype){var me=this;for(var i=0;i<perms.length;i++){if(perms[i].permlevel==0){var sel=$a($td(permt,i+1,8),'select','',{width:'100%'});add_sel_options(sel,r.fields);sel.details=perms[i];sel.details.parent=doctype;sel.onchange=function(){if(sel_val(this)&&sel_val(this)!='owner')$ds(this.div);else $dh(this.div);}
+var div=$a($td(permt,i+1,8),'div','link_type',{marginTop:'2px',fontSize:'10px',display:'none'});div.onclick=function(){this.details.match=sel_val(this.sel);me.show_match_dialog(this.details);}
+div.innerHTML='Set Users / Roles';div.details=perms[i];sel.div=div;div.sel=sel;if(perms[i].match){sel.value=perms[i].match;$ds(div);}
+pscript.all_matches.push(sel);}}}
+pscript.PermEngine.prototype.show_match_dialog=function(details){if(!this.match_defaults_dialog){var d=new Dialog(750,500,'Permission Applies To');d.make_body([['HTML','Body']]);var w=d.widgets['Body'];$y(w,{height:'350px',overflow:'auto'});this.match_defaults_dialog=d;}
+this.match_defaults_dialog.show();var me=this;var callback=function(r,rt){me.render_match_dialog(r,details);}
+$c_obj('Permission Control','get_defaults',details.match+'~~~'+(this.profiles?'No':'Yes'),callback);}
+pscript.PermEngine.prototype.render_match_dialog=function(r,details){var d=this.match_defaults_dialog;var w=d.widgets['Body'];w.innerHTML='<div style="background-color:#FFD; padding: 4px; color: #440; margin-bottom:16px">Please Note: Any action will also affect other permissions with similar rules!</div>'
+var t=make_table($a(w,'div','',{borderBottom:'1px solid #AAA'}),1,3,'90%',['40%','40%','20%'],{fontWeight:'bold',padding:'3px',fontSize:'14px'});$td(t,0,0).innerHTML='Who?';$td(t,0,1).innerHTML='Is allowed if '+details.match+' equals';var dl=r.message.dl;this.options=r.message.ol;if(!this.profiles){this.profiles=r.message.pl;}
+for(var i=0;i<dl.length;i++){new MatchDefaultValue(this,w,dl[i],details.match);}
+this.add_new_match_row(details.match);}
+pscript.PermEngine.prototype.add_new_match_row=function(fieldname){new MatchDefaultValue(this,this.match_defaults_dialog.widgets['Body'],null,fieldname,1);}
+MatchDefaultValue=function(pe,parent,details,fieldname,editable){this.pe=pe;this.wrapper=$a(parent,'div','',{margin:'4px'});this.clear();this.details=details;this.fieldname=fieldname;this.render(editable);}
+MatchDefaultValue.prototype.clear=function(){this.wrapper.innerHTML='';this.tab=make_table(this.wrapper,1,3,'90%',['40%','40%','20%'],{verticalAlign:'middle',padding:'3px'});}
+MatchDefaultValue.prototype.render=function(editable){if(editable){this.render_editable();}else{this.render_static();}}
+MatchDefaultValue.prototype.render_editable=function(){var me=this;this.profile_or_role=$a($td(this.tab,0,0),'select','',{width:'60px',marginRight:'8px'});add_sel_options(this.profile_or_role,['Profile','Role'],'Profile');this.profile_or_role.onchange=function(){if(sel_val(this)=='Profile'){$di(me.profile_sel);$dh(me.role_sel);}
+else{$dh(me.profile_sel);$di(me.role_sel);}}
+this.role_sel=$a($td(this.tab,0,0),'select','',{width:'100px',display:'none'});add_sel_options(this.role_sel,this.pe.roles);this.profile_sel=$a($td(this.tab,0,0),'select','',{width:'100px'});add_sel_options(this.profile_sel,this.pe.profiles);this.options_sel=$a($td(this.tab,0,1),'select','',{width:'120px'});add_sel_options(this.options_sel,this.pe.options);var span=$a($td(this.tab,0,2),'span','link_type',{marginLeft:'8px'});span.innerHTML='Add'
+span.onclick=function(){me.save();}}
+MatchDefaultValue.prototype.render_static=function(){var me=this;$td(this.tab,0,0).innerHTML=this.details.parenttype;$td(this.tab,0,0).innerHTML+='&nbsp;'+this.details.parent;$td(this.tab,0,1).innerHTML=this.details.defvalue;var span=$a($td(this.tab,0,2),'span','link_type',{marginLeft:'8px'});span.innerHTML='Cancel'
+span.onclick=function(){me.delete_def();}}
+MatchDefaultValue.prototype.delete_def=function(){var me=this;this.wrapper.innerHTML='<div style="color: #888; padding: 3px;">Deleting...</div>';var callback=function(r,rt){$dh(me.wrapper);if(r.exc)msgprint('There were errors!')}
+$c_obj('Permission Control','delete_default',[this.details.parent,this.fieldname,this.details.defvalue].join('~~~'),callback)}
+MatchDefaultValue.prototype.save=function(){var me=this;var callback=function(r,rt){me.details=r.message;me.clear();me.render();me.pe.add_new_match_row(me.fieldname);}
+if(sel_val(this.profile_or_role)=='Profile'){var parent=sel_val(this.profile_sel);var parenttype='Profile';}
+else{var parent=sel_val(this.role_sel);var parenttype='Role';}
+if(!sel_val(this.options_sel)||!parent){msgprint("Please select all values");return;}
+$c_obj('Permission Control','add_default',[parent,parenttype,this.fieldname,sel_val(this.options_sel)].join('~~~'),callback);this.wrapper.innerHTML='<div style="color: #888; padding: 3px;">Adding...</div>';}
+pscript.PermEngine.prototype.make_fields_dialog=function(){if(!pscript.get_field_dialog){pscript.get_field_dialog=new Dialog(750,500,'Fields');pscript.get_field_dialog.make_body([['HTML','Fields','<div id="perm_engine_get_fields"></div>'],['Button','OK']]);}
+else $i('perm_engine_get_fields').innerHTML='';}
+pscript.PermEngine.prototype.get_fields=function(dt,permlevel){var me=this;var callback=function(r,rt){var parent_fields_dict=r.message.parent_fields_dict;var table_fields_dict=r.message.table_fields_dict;me.make_fields_dialog();me.make_fields_table(dt,parent_fields_dict,table_fields_dict,permlevel);pscript.get_field_dialog.show();pscript.get_field_dialog.widgets['OK'].onclick=function(){pscript.get_field_dialog.hide();}}
+var args="{'dt':'"+dt+"','permlevel':"+permlevel+"}"
+$c_obj('Permission Control','get_fields',args,callback);}
+pscript.PermEngine.prototype.make_fields_table=function(dt,parent_fields_dict,table_fields_dict,permlevel){var make_grid=function(table,fields_dict){var col_labels=['Label','Fieldtype','Fieldname','Options'];for(var n=0;n<col_labels.length;n++){$a_input(($td(table,0,n)),'data');$td(table,0,n).innerHTML='<b>'+col_labels[n]+'</b>';$td(table,0,n).fieldname=col_labels[n].toLowerCase();}
+for(var i=0;i<keys(fields_dict).length;i++){for(var j=0;j<4;j++){$a_input(($td(table,i+1,j)),'data');$td(table,i+1,j).innerHTML=cstr(fields_dict[i][$td(table,0,j).fieldname])}}}
+$i('perm_engine_get_fields').innerHTML='<b>'+dt+' Fields at Level '+permlevel+':</b><br><br>';var parent_field_table=make_table('perm_engine_get_fields',keys(parent_fields_dict).length+1,4,'100%',['25%','25%','25%','25%'],{border:'1px solid #AAA',padding:'2px'});make_grid(parent_field_table,parent_fields_dict);child_tables=keys(table_fields_dict)
+if(child_tables.length>0){for(var k=0;k<child_tables.length;k++){var tab_fields_det=table_fields_dict[child_tables[k]];if(keys(tab_fields_det).length>0){$i('perm_engine_get_fields').innerHTML+='<br><b>'+child_tables[k]+' Fields at Level '+permlevel+':</b><br><br>'
+var child_field_table=make_table('perm_engine_get_fields',keys(tab_fields_det).length+1,4,'100%',['25%','25%','25%','25%'],{border:'1px solid #AAA',padding:'2px'});make_grid(child_field_table,tab_fields_det);}}}}
+pscript.PermEngine.prototype.update_permissions=function(){var me=this;var out={};var add_to_out=function(doctype,permlevel,role,key,value){if(!out[doctype])out[doctype]={};if(!out[doctype][permlevel])out[doctype][permlevel]={};if(!out[doctype][permlevel][role])out[doctype][permlevel][role]={};out[doctype][permlevel][role][key]=value;}
+for(i in pscript.all_checkboxes){c=pscript.all_checkboxes[i];add_to_out(c.doctype,c.permlevel,c.role,c.perm_type,c.checked?1:0);}
+for(var i=0;i<pscript.all_matches.length;i++){var s=pscript.all_matches[i];if(sel_val(s))
+add_to_out(s.details.parent,s.details.permlevel,s.details.role,'match',sel_val(s));}
+var args="{'perm_dict': "+JSON.stringify(out)+"}"
+$c_obj('Permission Control','update_permissions',args,function(r,rt){});}
+pscript.PermEngine.prototype.update_page_roles=function(){var me=this;var out={};for(i in pscript.all_pg_checkboxes){c=pscript.all_pg_checkboxes[i];out[c.page_name]=c.checked?1:0}
+var args="{'page_role_dict': "+JSON.stringify(out)+", 'role': '"+sel_val(me.role_select)+"'}"
+$c_obj('Permission Control','update_page_role',args,function(r,rt){});}
+pscript.PermEngine.prototype.reset_perm_engine=function(){this.type_select.selectedIndex=0;this.load_options();}
\ No newline at end of file
diff --git a/setup/page/permission_engine/permission_engine.html b/setup/page/permission_engine/permission_engine.html
new file mode 100644
index 0000000..1b9cab2
--- /dev/null
+++ b/setup/page/permission_engine/permission_engine.html
@@ -0,0 +1,4 @@
+<div class="layout_wrapper">
+<div id="pe_header"></div>
+<div id="perm_engine_div" style="margin: 16px;"></div>
+</div>
\ No newline at end of file
diff --git a/setup/page/permission_engine/permission_engine.js b/setup/page/permission_engine/permission_engine.js
new file mode 100644
index 0000000..378ad0c
--- /dev/null
+++ b/setup/page/permission_engine/permission_engine.js
@@ -0,0 +1,525 @@
+pscript['onload_Permission Engine'] = function() {
+  // header and toolbar
+  var h = new PageHeader('pe_header','Permissions Manager','Set specific permissions for Roles')
+  
+  if(!pscript.perm_engine) pscript.perm_engine = new pscript.PermEngine();
+}
+
+
+pscript.PermEngine = function() {
+  // create UI elements
+  this.wrapper = $i('perm_engine_div');
+  
+  this.head = $a(this.wrapper, 'div');
+  this.body = $a(this.wrapper, 'div');
+  this.footer = $a(this.wrapper, 'div');
+
+  var lab = $a(this.body,'div', '', {backgroundColor:'#FFD', padding:'8px', margin:'16px 0px'});
+  lab.innerHTML = 'Please select the item for which you want to set permissions';
+  
+  this.make_head();
+  this.load_options();
+}
+
+
+// Make Head
+// -------------
+pscript.PermEngine.prototype.make_head = function() {
+  var me = this;
+  
+  var make_select = function(label) {
+    var w = $a(me.head, 'div', '', {margin:'8px 0px'});
+    var t = make_table(w,1,2,'300px',['50%','50%']);
+    $td(t,0,0).innerHTML = label;
+    var s = $a($td(t,0,1),'select','',{width:'140px'});
+    s.wrapper = w;
+    return s;
+  }
+  
+  var make_button = function(label, parent, green) {
+  	return $btn(parent, label, null, {margin:'8px 0px', display:'none'}, (green ? 'green' : null));
+  }
+  
+  
+  // Set Permissions for
+  this.type_select = make_select('Set Permissions For');
+  this.type_select.onchange = function() {
+  	me.get_permissions();
+  }
+    
+  // Update Button
+  this.add_button = make_button('+ Add A New Rule', this.head, 0);
+  this.add_button.onclick = function() {
+    me.add_permission();
+  }
+
+  // Update Button
+  this.update_button = make_button('Update', this.footer, 1);
+  this.update_button.onclick = function() {
+    me.update_permissions();
+  }
+}
+
+// Add Permissions
+// -----------------
+pscript.PermEngine.prototype.add_permission = function() {
+  var me = this;
+  if(!this.add_permission_dialog) {
+  	
+  	// dialog
+    var d = new Dialog(400,400,'Add Permission');
+    d.make_body([['Select','Role'],['Select','Level'],['Button','Add']])
+
+    add_sel_options(d.widgets['Role'], this.roles, '');
+    add_sel_options(d.widgets['Level'], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0);
+
+    // add
+    d.widgets['Add'].onclick = function() {
+      if(!sel_val(d.widgets['Role'])) {
+        msgprint('Please select Role'); return;
+      }
+      var callback = function(r, rt) {
+      	// reload
+        me.get_permissions();
+        d.hide();
+      }
+      $c_obj('Permission Control','add_permission',JSON.stringify([sel_val(me.type_select), sel_val(d.widgets['Role']), sel_val(d.widgets['Level'])]), callback);
+    }
+
+    this.add_permission_dialog = d;
+  }
+  this.add_permission_dialog.show();
+}
+
+
+// Hide Fields
+// -----------------
+pscript.PermEngine.prototype.hide_fields = function() {
+  $dh(this.role_select.wrapper);
+  this.type_select.disabled = false;
+  this.body.innerHTML = '';
+}
+
+
+// Load Roles And Modules
+// -----------------------
+pscript.PermEngine.prototype.load_options = function() {
+  var me = this;
+  $dh(me.update_button);
+  $dh(me.add_button);
+
+  $c_obj('Permission Control','get_doctype_list','', function(r,rt) {    
+    me.roles = r.message.roles;
+    
+    // Type
+    empty_select(me.type_select);
+    add_sel_options(me.type_select,add_lists([''], r.message.doctypes));
+    
+  });
+}
+
+
+// Get DocType and Permissions related to module
+// --------------------------------------------------
+pscript.PermEngine.prototype.get_permissions = function() {
+  var me = this;
+  
+  if(!sel_val(me.type_select)) {
+  	msgprint('Please select a type first!'); return;
+  }
+  
+  $c_obj('Permission Control','get_permissions',sel_val(me.type_select), function(r,rt) {    
+     // Get permissions
+    if(r.message.perms.length)me.get_results(r.message);
+    else me.body.innerHTML = '<div style = "color : red; margin:8px 0px;">No Records Found</div>'
+  });
+}
+
+// Get Results
+// ------------------
+pscript.PermEngine.prototype.get_results = function(r){
+  var perms = r.perms;
+  var me = this;
+  var doctype = sel_val(me.type_select);
+  
+  // show update button
+  $ds(me.update_button);
+  $ds(me.add_button);
+
+  this.body.innerHTML = ''
+  pscript.all_checkboxes = [];
+  pscript.all_matches = [];
+  
+  var head = $a(this.body, 'h3'); head.innerHTML = 'Rules for ' + doctype;        
+  var permt = make_table(me.body, perms.length+1,9,'80%',[],{border:'1px solid #AAA', padding:'3px', verticalAlign:'middle', height:'30px'});
+    
+  // Create Grid for particular DocType
+  // ------------------------------------
+    
+  // Columns
+  var col_labels = ['Role','Level','Read','Write','Create','Submit','Cancel','Amend','Restrict By']
+  for(var n = 0; n < col_labels.length; n++){
+  	$y($td(permt,0,n), {backgroundColor:'#DDD', width:(n==0?'30%':(n==8?'21%':'7%'))})
+    $td(permt,0,n).innerHTML = col_labels[n];
+    $td(permt,0,n).fieldname = col_labels[n].toLowerCase();
+  }
+    
+  // Rows for Column Level / Role
+  for(var j = 0; j < perms.length; j++){
+    var plevel = $a($td(permt,j+1,1), 'span', 'link_type');
+    plevel.innerHTML = perms[j].permlevel;
+    plevel.doctype = doctype;
+    plevel.value = perms[j].permlevel;
+    plevel.onclick = function() {me.get_fields(this.doctype, this.value)}
+
+    // role
+    $td(permt,j+1,0).innerHTML = perms[j].role;
+
+  }  
+    
+  // Get values
+  for(var l = 0; l < perms.length; l++){
+    for(var m = 0; m < 6; m++){                             // (read,write,create,submit,cancel,amend) 
+      var chk = $a_input($td(permt,l+1,m+2), 'checkbox');
+      var val = perms[l][$td(permt,0,m+2).fieldname];
+      if(val == 1) chk.checked = 1;
+      else chk.checked = 0;
+      chk.doctype = doctype;
+      chk.permlevel = perms[l].permlevel; chk.perm_type = col_labels[m+2].toLowerCase(); chk.role = perms[l].role;
+      pscript.all_checkboxes.push(chk);
+    }
+  }
+  
+  // add selects for match
+  me.add_match_select(r, perms, permt, doctype);
+}
+
+// render selects for match
+// --------------------------------------------
+
+pscript.PermEngine.prototype.add_match_select = function(r, perms, permt, doctype) {
+  var me = this;
+  
+  // add select for match
+  for(var i=0; i<perms.length; i++) {
+    if(perms[i].permlevel==0) {
+      // select
+      var sel = $a($td(permt,i+1,8),'select','',{width:'100%'});
+      add_sel_options(sel, r.fields);
+      sel.details = perms[i]; sel.details.parent = doctype;
+      sel.onchange = function() { 
+      	if(sel_val(this) && sel_val(this)!='owner') $ds(this.div); 
+      	else $dh(this.div); }
+      
+      // link
+      var div = $a($td(permt,i+1,8),'div','link_type',{marginTop: '2px', fontSize:'10px', display:'none'});
+      div.onclick = function() { this.details.match = sel_val(this.sel); me.show_match_dialog(this.details); }
+      div.innerHTML = 'Set Users / Roles';
+      div.details = perms[i];
+      sel.div = div; div.sel = sel;
+
+      // set the value
+      if(perms[i].match) { sel.value = perms[i].match; $ds(div); }
+      
+      pscript.all_matches.push(sel);
+    }
+  }
+}
+
+// match users Dialog
+// =======================================================
+
+pscript.PermEngine.prototype.show_match_dialog=function(details) {
+  if(!this.match_defaults_dialog) {
+    var d = new Dialog(750, 500, 'Permission Applies To');
+    d.make_body([['HTML','Body']]);
+    var w = d.widgets['Body'];
+    $y(w,{height:'350px', overflow:'auto'});
+    this.match_defaults_dialog = d;
+  }
+  
+  // dialog
+  this.match_defaults_dialog.show();
+  
+  // render the rules
+  var me = this;
+  var callback = function(r,rt) {
+  	me.render_match_dialog(r, details);
+  }
+  // load the rules
+  $c_obj('Permission Control','get_defaults', details.match + '~~~' + (this.profiles ? 'No' : 'Yes'), callback); 
+}
+
+// --------------------------------------------
+
+pscript.PermEngine.prototype.render_match_dialog=function(r, details) {
+  var d = this.match_defaults_dialog;
+  var w = d.widgets['Body'];
+  w.innerHTML = '<div style="background-color:#FFD; padding: 4px; color: #440; margin-bottom:16px">Please Note: Any action will also affect other permissions with similar rules!</div>'
+  
+  // header
+  var t=make_table($a(w,'div','',{borderBottom:'1px solid #AAA'}),1,3,'90%',['40%','40%','20%'],{fontWeight:'bold', padding:'3px', fontSize:'14px'});
+  $td(t,0,0).innerHTML = 'Who?'; $td(t,0,1).innerHTML = 'Is allowed if '+details.match+' equals';
+  
+  // existing defaults
+  var dl = r.message.dl; this.options = r.message.ol;
+  if(!this.profiles) {
+    this.profiles = r.message.pl;
+  }
+  
+  for(var i=0; i<dl.length; i++) {
+    new MatchDefaultValue(this, w, dl[i], details.match);
+  }
+  
+  this.add_new_match_row(details.match);
+}
+
+pscript.PermEngine.prototype.add_new_match_row = function(fieldname) {
+  // add new default
+  new MatchDefaultValue(this, this.match_defaults_dialog.widgets['Body'], null, fieldname, 1);
+}  
+  
+// --------------------------------------------
+
+MatchDefaultValue = function(pe, parent, details, fieldname, editable) {
+  this.pe = pe;
+  this.wrapper = $a(parent, 'div', '', {margin:'4px'});
+  this.clear();
+  this.details = details;
+  this.fieldname = fieldname;
+  this.render(editable);
+}
+
+
+// --------------------------------------------
+
+MatchDefaultValue.prototype.clear = function() {
+  this.wrapper.innerHTML = '';
+  this.tab = make_table(this.wrapper, 1, 3, '90%', ['40%','40%','20%'], {verticalAlign:'middle', padding:'3px'});
+}
+
+// --------------------------------------------
+
+MatchDefaultValue.prototype.render = function(editable) {
+
+  if(editable) {
+  	this.render_editable();
+  } else {
+    this.render_static();
+  }
+}
+
+// --------------------------------------------
+
+MatchDefaultValue.prototype.render_editable = function() {
+  var me = this;
+
+  // profile or role
+  this.profile_or_role = $a($td(this.tab,0,0), 'select', '', {width:'60px', marginRight:'8px'});
+  add_sel_options(this.profile_or_role,['Profile', 'Role'], 'Profile');
+  this.profile_or_role.onchange = function() {
+    if(sel_val(this)=='Profile') { $di(me.profile_sel); $dh(me.role_sel); }
+    else { $dh(me.profile_sel); $di(me.role_sel); }
+  }
+
+  // role sel
+  this.role_sel = $a($td(this.tab,0,0), 'select', '', {width:'100px',display:'none'});
+  add_sel_options(this.role_sel,this.pe.roles);
+  
+  // profile sel
+  this.profile_sel = $a($td(this.tab,0,0), 'select', '', {width:'100px'});
+  add_sel_options(this.profile_sel,this.pe.profiles);
+
+  // options sel
+  this.options_sel = $a($td(this.tab,0,1), 'select', '', {width:'120px'});
+  add_sel_options(this.options_sel,this.pe.options);
+
+   // add
+  var span = $a($td(this.tab,0,2),'span','link_type',{marginLeft:'8px'});
+  span.innerHTML = 'Add'
+  span.onclick = function() { me.save(); }
+}
+
+// --------------------------------------------
+
+MatchDefaultValue.prototype.render_static = function() {
+  var me = this;
+  
+  $td(this.tab,0,0).innerHTML = this.details.parenttype;
+  $td(this.tab,0,0).innerHTML += '&nbsp;' + this.details.parent;
+  $td(this.tab,0,1).innerHTML = this.details.defvalue;
+
+   // delete
+  var span = $a($td(this.tab,0,2),'span','link_type',{marginLeft:'8px'});
+  span.innerHTML = 'Cancel'
+  span.onclick = function() { me.delete_def(); }
+}
+
+// --------------------------------------------
+
+MatchDefaultValue.prototype.delete_def = function() {	
+  var me = this;
+  this.wrapper.innerHTML = '<div style="color: #888; padding: 3px;">Deleting...</div>';
+  var callback = function(r,rt) {
+  	$dh(me.wrapper);
+    if(r.exc) msgprint('There were errors!')
+  }
+  $c_obj('Permission Control','delete_default'
+    ,[this.details.parent, this.fieldname, this.details.defvalue].join('~~~')
+    ,callback)
+}
+
+// --------------------------------------------
+
+MatchDefaultValue.prototype.save = function() {
+  var me= this;
+  
+  var callback = function(r,rt) {
+    me.details = r.message;
+    me.clear();
+    me.render();
+    me.pe.add_new_match_row(me.fieldname);
+  }
+  	
+  // values
+  if(sel_val(this.profile_or_role)=='Profile') { var parent = sel_val(this.profile_sel); var parenttype = 'Profile'; }
+  else { var parent = sel_val(this.role_sel); var parenttype = 'Role'; }
+
+  if(!sel_val(this.options_sel) || !parent) { msgprint("Please select all values"); return; }
+  	
+  $c_obj('Permission Control','add_default'
+    ,[parent, parenttype, this.fieldname, sel_val(this.options_sel)].join('~~~')
+    ,callback);
+      
+  this.wrapper.innerHTML = '<div style="color: #888; padding: 3px;">Adding...</div>';
+}
+
+
+// Make Dialog Box To Get Fields fro PermLevel
+// =======================================================
+
+pscript.PermEngine.prototype.make_fields_dialog=function(){
+  if(!pscript.get_field_dialog) {
+    pscript.get_field_dialog = new Dialog(750,500,'Fields');
+    pscript.get_field_dialog.make_body([['HTML','Fields','<div id="perm_engine_get_fields"></div>'],['Button','OK']]);
+  }
+  else $i('perm_engine_get_fields').innerHTML = '';
+}
+
+// Get Fields
+// --------------------
+pscript.PermEngine.prototype.get_fields = function(dt, permlevel) {
+  var me = this;
+  var callback = function(r,rt){
+    // Get Parent DocType Fields
+    var parent_fields_dict = r.message.parent_fields_dict;
+    
+    // Get Child Table Fields if any
+    var table_fields_dict = r.message.table_fields_dict;
+    
+    // Make Fields Dialog Box
+    me.make_fields_dialog();
+    
+    me.make_fields_table(dt, parent_fields_dict, table_fields_dict, permlevel);
+    
+    pscript.get_field_dialog.show();
+    pscript.get_field_dialog.widgets['OK'].onclick=function(){
+      pscript.get_field_dialog.hide();
+    }
+  }
+  var args = "{'dt':'"+dt+"','permlevel':"+permlevel+"}"
+  $c_obj('Permission Control','get_fields', args, callback);
+}
+
+
+
+// Make Table of Fields for Dialog Box
+// --------------------------------------
+pscript.PermEngine.prototype.make_fields_table = function(dt, parent_fields_dict, table_fields_dict, permlevel) {
+  
+  var make_grid = function(table, fields_dict) {
+    var col_labels = ['Label','Fieldtype','Fieldname','Options'];
+    for(var n = 0; n < col_labels.length; n++){
+      $a_input(($td(table,0,n)), 'data');
+      $td(table,0,n).innerHTML = '<b>'+col_labels[n]+'</b>';
+      $td(table,0,n).fieldname = col_labels[n].toLowerCase();
+    }
+    
+    // Add values
+    for(var i = 0; i < keys(fields_dict).length; i++){
+      for(var j = 0; j < 4; j++){
+        $a_input(($td(table,i+1,j)), 'data');
+        $td(table,i+1,j).innerHTML = cstr(fields_dict[i][$td(table,0,j).fieldname])
+      }
+    }
+  }
+
+  
+  $i('perm_engine_get_fields').innerHTML = '<b>'+ dt + ' Fields at Level '+ permlevel +':</b><br><br>';
+  var parent_field_table = make_table('perm_engine_get_fields',keys(parent_fields_dict).length+1, 4,'100%',['25%','25%','25%','25%'],{border:'1px solid #AAA',padding:'2px'});
+  make_grid(parent_field_table, parent_fields_dict);
+  
+  child_tables = keys(table_fields_dict)
+  if(child_tables.length > 0){
+    for(var k = 0; k < child_tables.length; k++){
+      var tab_fields_det = table_fields_dict[child_tables[k]];
+      if(keys(tab_fields_det).length > 0){
+        $i('perm_engine_get_fields').innerHTML += '<br><b>'+ child_tables[k] + ' Fields at Level '+ permlevel +':</b><br><br>'
+        var child_field_table = make_table('perm_engine_get_fields',keys(tab_fields_det).length+1, 4,'100%',['25%','25%','25%','25%'],{border:'1px solid #AAA',padding:'2px'});
+        make_grid(child_field_table, tab_fields_det);
+      }
+    }
+  }
+}
+
+
+// Update Permissions
+// -----------------------
+pscript.PermEngine.prototype.update_permissions = function() {
+  var me = this;
+  var out = {};
+
+  var add_to_out = function(doctype, permlevel, role, key, value) {
+    if(!out[doctype]) out[doctype] = {};
+    if(!out[doctype][permlevel]) out[doctype][permlevel] = {};
+    if(!out[doctype][permlevel][role]) out[doctype][permlevel][role] = {};
+    out[doctype][permlevel][role][key] = value; 
+  }
+
+  // check boxes
+  for(i in pscript.all_checkboxes) {
+    c = pscript.all_checkboxes[i];
+    add_to_out(c.doctype, c.permlevel, c.role, c.perm_type, c.checked ? 1 : 0);
+  }
+
+  // matches
+  for(var i=0; i<pscript.all_matches.length; i++) {
+  	var s = pscript.all_matches[i];
+    if(sel_val(s))
+      add_to_out(s.details.parent, s.details.permlevel, s.details.role, 'match', sel_val(s));
+  }
+  
+  var args = "{'perm_dict': "+JSON.stringify(out)+"}"
+  $c_obj('Permission Control','update_permissions', args, function(r,rt) {});
+}
+
+
+// Update Page Roles
+// ----------------------
+pscript.PermEngine.prototype.update_page_roles = function() {
+  var me = this;
+  var out = {};
+  for(i in pscript.all_pg_checkboxes) {
+    c = pscript.all_pg_checkboxes[i];
+    out[c.page_name] = c.checked ? 1 : 0
+  }
+  var args = "{'page_role_dict': "+JSON.stringify(out)+", 'role': '"+sel_val(me.role_select)+"'}"
+  $c_obj('Permission Control','update_page_role', args, function(r,rt) {});
+}
+
+// Reset Permission Engine
+// -------------------------
+pscript.PermEngine.prototype.reset_perm_engine = function(){
+  this.type_select.selectedIndex = 0;
+  this.load_options();
+}
diff --git a/setup/page/permission_engine/permission_engine.txt b/setup/page/permission_engine/permission_engine.txt
new file mode 100644
index 0000000..72ef01c
--- /dev/null
+++ b/setup/page/permission_engine/permission_engine.txt
@@ -0,0 +1 @@
+[{'creation': '2010-01-07 10:44:43', 'module': 'Setup', 'doctype': 'Page', 'owner': 'saumil@webnotestech.com', 'style': None, 'modified_by': 'Administrator', 'script': None, 'show_in_menu': 1, 'content': None, 'page_name': 'Permission Engine', 'menu_index': None, 'docstatus': 0, 'parent': None, 'standard': 'Yes', 'icon': None, 'name': 'Permission Engine', 'idx': None, 'static_content': None, 'modified': '2010-11-18 20:24:21', 'parenttype': None, 'parent_node': None, 'parentfield': None}, {'modified_by': 'Administrator', 'name': 'PR000107', 'parent': 'Permission Engine', 'creation': '2010-01-07 11:10:21', 'modified': '2010-11-18 20:24:21', 'doctype': 'Page Role', 'idx': 1, 'parenttype': 'Page', 'role': 'System Manager', 'owner': 'saumil@webnotestech.com', 'docstatus': 0, 'parentfield': 'roles'}]
\ No newline at end of file
diff --git a/setup/page/setup/__init__.py b/setup/page/setup/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/setup/page/setup/__init__.py
diff --git a/setup/page/setup/setup.comp.js b/setup/page/setup/setup.comp.js
new file mode 100644
index 0000000..59d31b4
--- /dev/null
+++ b/setup/page/setup/setup.comp.js
@@ -0,0 +1,32 @@
+
+pscript.onload_Setup=function(){var parent=$i('setup_div');add_space_holder(parent);var callback=function(r,rt){parent.page_head=new PageHeader(parent,'Setup');var setup_data=new SetupData(r.message);pscript.setup_make_sections(setup_data);remove_space_holder();}
+$c_obj('Setup Wizard Control','get_country','',callback);}
+pscript.setup_set_height=function(){var parent=$i('setup_div');$y(parent.tray.body,{height:get_window_height()-parent.page_head.wrapper.offsetHeight+'px',overflow:'auto'})}
+pscript.setup_make_sections=function(setup_data){var parent=$i('setup_div');parent.tray=new TrayPage(parent)
+var lst=[setup_data.system,setup_data.general,setup_data.accounts,setup_data.selling,setup_data.buying,setup_data.stock,setup_data.hr,setup_data.maintenance,setup_data.production];for(var s=0;s<lst.length;s++){var lbl=keys(lst[s])[0];var ti=parent.tray.add_item(lbl,null,null,1)
+new SetupItem(ti.body,lbl,lst[s][lbl]);if(s==0)ti.expand();}
+setTimeout(pscript.setup_set_height,100);resize_observers.push(pscript.setup_set_height);}
+SetupItem=function(parent,lbl,link_list){this.icons={'System':'back_img Setup','General':'back_img Home','Accounts':'back_img Accounts','Selling':'back_img Selling','Stock':'back_img Stock','Buying':'back_img Buying','Maintenance':'back_img Maintenance','Production':'back_img Production','HR':'back_img HR'};this.make_item_body(parent,lbl,link_list);}
+SetupItem.prototype.make_item_body=function(parent,lbl,link_list){this.link_area=parent;this.render_item_body(lbl,link_list);}
+SetupItem.prototype.render_item_body=function(lbl,link_list){var me=this;link_list.sort(function(a,b){return a[0]>b[0];});for(var i=0;i<link_list.length;i++){var wrapper=$a(this.link_area,'div','',{marginBottom:'4px',padding:'2px'});$(wrapper).hover(function(){$y(this,{backgroundColor:'#EEF'})},function(){$y(this,{backgroundColor:''})})
+var tab=make_table($a(wrapper,'div'),1,2,'100%',[200/7+'%',500/7+'%'])
+var dt=$a($td(tab,0,0),'span','link_type');dt.innerHTML=link_list[i][0];dt.label=link_list[i][0];dt.arg=link_list[i][1];dt.nm=link_list[i][2];if(dt.arg==1)dt.cn=link_list[i][3];else if(dt.arg==2)dt.cb=link_list[i][3];dt.onclick=function(){me.link_action(this)}
+$y($td(tab,0,1),{color:'#777'});$td(tab,0,1).innerHTML=link_list[i][4];}}
+SetupItem.prototype.link_action=function(obj){var me=this;var obj=obj;if(obj.arg==1){if(in_list(profile.can_read,obj.nm)){if(obj.cn!='')
+loaddocbrowser(obj.nm,obj.nm,obj.cn);else
+loaddocbrowser(obj.nm);}
+else
+msgprint('No read permission',1);}
+else if(obj.arg==2){me.show_page(obj);}
+else if(obj.arg==3){newdoc(obj.nm);}}
+SetupItem.prototype.show_page=function(obj){var me=obj;var callback=function(r,rt)
+{if(r.message){if(me.cb=='')
+loadpage(me.nm);else
+show_chart_browser(me.nm,me.cb);}
+else
+msgprint('No read permission',1);}
+$c_obj('Setup Wizard Control','get_page_lst',me.nm,callback);}
+SetupData=function(cnty){this.system={'System':[['Global Defaults',3,'Manage Account','','Set global default values'],['Manage Series',3,'Naming Series','','Manage numbering series for transactions'],['Custom Field',1,'Custom Field','dt'+NEWLINE+'label'+NEWLINE+'fieldtype'+NEWLINE+'options','Add and manage custom fields on forms'],['Email Settings',3,'Email Settings','','Outgoing email server and address'],['Notification Settings',3,'Notification Control','','Automatic emails set at selected events'],['Company',1,'Company','id'+NEWLINE+'is_active'+NEWLINE+'email','Manage list of companies'],['Fiscal Year',1,'Fiscal Year','id'+NEWLINE+'company'+NEWLINE+'is_active'+NEWLINE+'year','Manage list of fiscal years'],['Personalize',3,'Personalize','','Set your banner'],['Manage Trash',2,'Trash','','Restore trashed items'],['Import Data',2,'Import Data','','Import data from CSV files'],['Manage Users',2,'My Company','','Add / remove users and manage their roles'],['Web Forms',2,'Webforms','','Code to embed forms in yor website'],['Permissions Manager',2,'Permission Engine','','Manage all permissions from one tool (beta)'],['Property Setter',1,'Property Setter','','Customize properties of a Form (DocType) or Field'],['Letter Head',1,'Letter Head','','Manage different letter heads for Prints'],['SMS Settings',3,'SMS Settings','','Integrate your personalized SMS gateway which support http web service'],['SMS Center',3,'SMS Center','','Send mass sms to your leads, contacts and partners']]};this.general={'General':[['Authorization Rule',1,'Authorization Rule','','Set rules based on amounts'],['Print Heading',1,'Print Heading','','Manage headings for printing transactions'],['Term',1,'Term','','Manage template of standard Terms for order / invoices etc'],['Currency',1,'Currency','','Manage list of currencies'],['Country',1,'Country','','Country master'],['State',1,'State','','State master'],['Activty Type',1,'Activity Type','','Types of activities that you can select in your Timesheet'],['City',1,'City','','City master']]};this.selling={'Selling':[['Customer Group',2,'Sales Browser','Customer Group','Manage customer categories'],['Territory',2,'Sales Browser','Territory','Manage sales territories'],['Customer',1,'Customer','customer_group'+NEWLINE+'country','Customer master'],['Sales Person',2,'Sales Browser','Sales Person','Manage sales persons'],['Sales Partner',1,'Sales Partner','','Manage sales partners'],['Campaign',1,'Campaign','id'+NEWLINE+'campaign_name'+NEWLINE+'description','Manage sales / marketing campaigns'],['Sales BOM',1,'Sales BOM','id'+NEWLINE+'is_active'+NEWLINE+'new_item_name'+NEWLINE+'description'+NEWLINE+'item_group','Manage Sales Bill of Material (Main item + accessories)'],['Price List',1,'Price List','','Price list master']]};this.accounts={'Accounts':[['Chart of Accounts',2,'Accounts Browser','Account','Manage chart of accounts'],['Chart of Cost Centers',2,'Accounts Browser','Cost Center','Manage chart of cost centers'],['POS Setting',1,'POS Setting','','Manage Point of Sales default Settings.']]};if(cnty=='India'){var lst1=[['TDS Rate Chart',1,'TDS Rate Chart','','TDS rate master'],['TDS Category',1,'TDS Category','id'+NEWLINE+'module','TDS categories']];for(var i=0;i<lst1.length;i++)
+this.accounts['Accounts'].push(lst1[i]);}
+var lst=[['Monthly Distribution',1,'Budget Distribution','id'+NEWLINE+'fiscal_year'+NEWLINE+'distribution_id','Manage budget distributions (seasonalities)'],['Sales Other Charges',1,'Other Charges','','Manage your charge structures (taxes + charges) for sales'],['Purchase Other Charges',1,'Purchase Other Charges','','Manage your charge structures (taxes + charges) for purchase'],['Mode of Payment',1,'Mode of Payment','','Mode of payment master']];for(var i=0;i<lst.length;i++)
+this.accounts['Accounts'].push(lst[i]);this.stock={'Stock':[['Item Group',2,'Sales Browser','Item Group','Manage item classifications'],['Item',1,'Item','name'+NEWLINE+'item_group'+NEWLINE+'description','Item master'],['Brand',1,'Brand','id'+NEWLINE+'description','Brand master'],['Batch',1,'Batch','name'+NEWLINE+'start_date'+NEWLINE+'item'+NEWLINE+'expiry_date','Manage batches'],['Price List',1,'Price List','','Price list master'],['UOM',1,'UOM','','Unit of measure (UOM) master'],['Warehouse Type',1,'Warehouse Type','','Warehouse classifications'],['Warehouse',1,'Warehouse','','Warehouse master']]};this.buying={'Buying':[['Supplier Type',1,'Supplier Type','','Manage supplier classifications'],['Supplier',1,'Supplier','id'+NEWLINE+'supplier_type'+NEWLINE+'supplier_status'+NEWLINE+'company','Supplier master']]};this.maintenance={'Maintenance':[['Serial No',1,'Serial No','item_code'+NEWLINE+'status'+NEWLINE+'pr_no'+NEWLINE+'delivery_note_no'+NEWLINE+'customer_name','Manage unique serial numbers for items'],['Purpose of Service',1,'Purpose of Service','','Purpose of service master']]};this.production={'Production':[['Bill of Materials',1,'Bill Of Materials','id'+NEWLINE+'item'+NEWLINE+'description'+NEWLINE+'operating_cost'+NEWLINE+'maintained_by','Muti-level bill of materials and operations'],['Workstation',1,'Workstation','id'+NEWLINE+'workstation_name'+NEWLINE+'warehouse'+NEWLINE+'description','Workstation master']]};this.hr={'HR':[['Department',1,'Department','','Company department master'],['Designation',1,'Designation','','Company designation master'],['Branch',1,'Branch','','Manage branches for your company'],['Grade',1,'Grade','','Manage employee grades'],['Employment Type',1,'Employment Type','','Manage types of employment'],['Employee',1,'Employee','employee_name'+NEWLINE+'employment_type'+NEWLINE+'status'+NEWLINE+'branch'+NEWLINE+'designation'+NEWLINE+'department'+NEWLINE+'grade'+NEWLINE+'reports_to','Employee master'],['Earning Type',1,'Earning Type','taxable'+NEWLINE+'exemption_limit','Types of salary earning master'],['Deduction Type',1,'Deduction Type','','Types of salary deduction master'],['Expense Type',1,'Expense Type','','Types of expense master'],['Salary Structure',1,'Salary Structure','employee'+NEWLINE+'is_active'+NEWLINE+'fiscal_year'+NEWLINE+'from_date'+NEWLINE+'ctc'+NEWLINE+'total_earning'+NEWLINE+'total_deduction'+NEWLINE+'total','Salary structure template'],['Holiday List',1,'Holiday List','fiscal_year','List of holidays'],['Leave Type',1,'Leave Type','max_days_allowed'+NEWLINE+'is_carry_forward'+NEWLINE+'is_encash','Leave type master'],['KRA Template',1,'KRA Template','','Template of Key Result Areas (KRAs)']]};}
\ No newline at end of file
diff --git a/setup/page/setup/setup.html b/setup/page/setup/setup.html
new file mode 100644
index 0000000..e60d00b
--- /dev/null
+++ b/setup/page/setup/setup.html
@@ -0,0 +1 @@
+<div id="setup_div" class="layout_wrapper"></div>
\ No newline at end of file
diff --git a/setup/page/setup/setup.js b/setup/page/setup/setup.js
new file mode 100644
index 0000000..645fbd1
--- /dev/null
+++ b/setup/page/setup/setup.js
@@ -0,0 +1,253 @@
+pscript.onload_Setup = function() {
+  var parent = $i('setup_div');
+  add_space_holder(parent);
+
+  var callback = function(r,rt){
+
+    // header
+    parent.page_head = new PageHeader(parent,'Setup');
+    
+    // sections
+    var setup_data = new SetupData(r.message);
+    pscript.setup_make_sections(setup_data);
+    
+    remove_space_holder();
+  }
+  $c_obj('Setup Wizard Control','get_country','',callback);  
+}
+
+pscript.setup_set_height = function() {
+  var parent = $i('setup_div');
+  $y(parent.tray.body, {height: get_window_height() - parent.page_head.wrapper.offsetHeight + 'px', overflow:'auto'})
+}
+
+// Make sections
+// ===================================================
+
+pscript.setup_make_sections = function(setup_data) {
+  var parent = $i('setup_div');
+  parent.tray = new TrayPage(parent)
+
+  // list of setup data
+  var lst = [setup_data.system, setup_data.general, setup_data.accounts, setup_data.selling, setup_data.buying, setup_data.stock, setup_data.hr, setup_data.maintenance, setup_data.production];
+
+  for(var s=0; s<lst.length; s++){
+    var lbl = keys(lst[s])[0];
+
+    var ti = parent.tray.add_item(lbl, null, null, 1)
+    new SetupItem(ti.body, lbl, lst[s][lbl]);
+
+    if(s==0) ti.expand();
+  }
+  
+  setTimeout(pscript.setup_set_height, 100);
+  resize_observers.push(pscript.setup_set_height);
+}
+
+// Setup Item
+// ===================================================
+SetupItem = function(parent, lbl, link_list) {
+  this.icons = {'System':'back_img Setup', 'General':'back_img Home', 'Accounts':'back_img Accounts', 'Selling':'back_img Selling', 'Stock':'back_img Stock', 'Buying':'back_img Buying', 'Maintenance':'back_img Maintenance', 'Production':'back_img Production', 'HR':'back_img HR'};
+  this.make_item_body(parent, lbl, link_list);
+}
+
+
+// Make body for item in setup wizard
+// ===================================================
+SetupItem.prototype.make_item_body = function(parent, lbl, link_list){
+  // item link area
+  this.link_area = parent;
+  this.render_item_body(lbl, link_list);
+}
+
+
+// Render item body
+// ===================================================
+SetupItem.prototype.render_item_body = function(lbl, link_list) {
+  var me = this;
+  // set item header
+
+  link_list.sort(function(a, b) { return a[0] > b[0]; });
+
+  // show links for item
+  for(var i=0; i<link_list.length; i++){
+    var wrapper = $a(this.link_area, 'div','',{marginBottom:'4px', padding:'2px'});
+    $(wrapper).hover(
+      function() { $y(this,{backgroundColor:'#EEF'}) }
+      ,function() { $y(this,{backgroundColor:''}) }
+    )
+    var tab = make_table($a(wrapper,'div'), 1, 2, '100%', [200/7+'%', 500/7+'%'])
+
+    var dt= $a($td(tab,0,0), 'span', 'link_type');
+    dt.innerHTML = link_list[i][0]; 
+    dt.label = link_list[i][0];
+    dt.arg = link_list[i][1]; 
+    dt.nm = link_list[i][2];
+    
+    if(dt.arg == 1) dt.cn = link_list[i][3]; 
+    else if(dt.arg == 2) dt.cb=link_list[i][3];
+ 
+    // execute when link is clicked
+    dt.onclick = function(){
+      me.link_action(this)
+    }
+    
+    // description
+    $y($td(tab,0,1), {color:'#777'});
+    $td(tab,0,1).innerHTML = link_list[i][4];
+  }
+}
+
+
+// Execute when link is clicked
+// ----------------------------
+SetupItem.prototype.link_action = function(obj) {
+  var me = this;
+  var obj = obj;
+  
+  // if object links to a doc browser
+  if(obj.arg == 1){
+    if(in_list(profile.can_read, obj.nm)){
+      if(obj.cn !='')
+        loaddocbrowser(obj.nm, obj.nm, obj.cn);
+      else
+        loaddocbrowser(obj.nm);
+    }
+    else
+      msgprint('No read permission',1);
+  }
+  
+  // if obj links to a page
+  else if(obj.arg == 2){
+    me.show_page(obj);
+  }
+  
+  // if object links to a single doctype
+  else if(obj.arg == 3){
+    newdoc(obj.nm);
+  }
+}
+
+
+// Show page for corresponding link
+// --------------------------------
+SetupItem.prototype.show_page = function(obj) {
+  var me = obj;
+  var callback = function(r,rt)
+  {
+    if(r.message){
+      if(me.cb == '')
+        loadpage(me.nm);
+      else
+        show_chart_browser(me.nm,me.cb);    
+    }
+    else
+      msgprint('No read permission',1);
+  }
+  $c_obj('Setup Wizard Control','get_page_lst',me.nm,callback);  
+}
+
+
+// Setup Data
+// ======================================================================================================================================================= 
+SetupData = function(cnty){
+
+  // arg : 1 - Docbrowser, 2 - Page, 3 - DocType
+  
+  //[label, arg, name, callback/col_name, description]
+
+  this.system = {'System':[['Global Defaults',3,'Manage Account','','Set global default values'],
+    ['Manage Series',3,'Naming Series','','Manage numbering series for transactions'],
+    ['Custom Field',1,'Custom Field','dt'+NEWLINE+'label'+NEWLINE+'fieldtype'+NEWLINE+'options','Add and manage custom fields on forms'],
+    ['Email Settings',3,'Email Settings','','Outgoing email server and address'],
+    ['Notification Settings',3,'Notification Control','','Automatic emails set at selected events'],
+    ['Company',1,'Company','id'+NEWLINE+'is_active'+NEWLINE+'email','Manage list of companies'],
+    ['Fiscal Year',1,'Fiscal Year','id'+NEWLINE+'company'+NEWLINE+'is_active'+NEWLINE+'year','Manage list of fiscal years'],
+    ['Personalize',3,'Personalize','','Set your banner'],
+    ['Manage Trash',2,'Trash','','Restore trashed items'],
+    ['Import Data',2,'Import Data','','Import data from CSV files'],
+    ['Manage Users',2,'My Company','','Add / remove users and manage their roles'],
+    ['Web Forms',2,'Webforms','', 'Code to embed forms in yor website'],
+    ['Permissions Manager',2,'Permission Engine','', 'Manage all permissions from one tool (beta)'],
+    ['Property Setter',1,'Property Setter','', 'Customize properties of a Form (DocType) or Field'],
+    //['Badge Settings',3,'Badge Settings','','Define rules for assigning badges to users'],
+    //['Social Badge',1,'Social Badge','id'+NEWLINE+'badge_image'+NEWLINE+'badge_description'+NEWLINE+'badge_points','Social badge master'],
+    ['Letter Head',1,'Letter Head','','Manage different letter heads for Prints'],
+    ['SMS Settings',3,'SMS Settings','','Integrate your personalized SMS gateway which support http web service'],
+    ['SMS Center',3,'SMS Center','','Send mass sms to your leads, contacts and partners']
+  ]};
+
+  
+  this.general = {'General':[['Authorization Rule',1,'Authorization Rule','','Set rules based on amounts'],
+    ['Print Heading',1,'Print Heading','','Manage headings for printing transactions'],
+    ['Term',1,'Term','','Manage template of standard Terms for order / invoices etc'],
+    ['Currency',1,'Currency','','Manage list of currencies'],
+    ['Country',1,'Country','','Country master'],
+    ['State',1,'State','','State master'],
+    ['Activty Type',1,'Activity Type','','Types of activities that you can select in your Timesheet'],
+    ['City',1,'City','','City master']]};
+  
+  this.selling = {'Selling':[['Customer Group',2,'Sales Browser','Customer Group','Manage customer categories'],
+    ['Territory',2,'Sales Browser','Territory','Manage sales territories'],
+    ['Customer',1,'Customer','customer_group'+NEWLINE+'country','Customer master'],
+    ['Sales Person',2,'Sales Browser','Sales Person','Manage sales persons'],
+    ['Sales Partner',1,'Sales Partner','', 'Manage sales partners'],
+    ['Campaign',1,'Campaign','id'+NEWLINE+'campaign_name'+NEWLINE+'description','Manage sales / marketing campaigns'],
+    ['Sales BOM',1,'Sales BOM','id'+NEWLINE+'is_active'+NEWLINE+'new_item_name'+NEWLINE+'description'+NEWLINE+'item_group','Manage Sales Bill of Material (Main item + accessories)'],
+    ['Price List',1,'Price List','','Price list master']]};
+
+  this.accounts = {'Accounts':[['Chart of Accounts',2,'Accounts Browser','Account','Manage chart of accounts'],
+    ['Chart of Cost Centers',2,'Accounts Browser','Cost Center','Manage chart of cost centers'],
+    ['POS Setting',1,'POS Setting','','Manage Point of Sales default Settings.']]};
+    
+  // if country = india; show india related doctypes
+  //-------------------------------------------------
+    
+  if(cnty == 'India'){  
+    var lst1 = [['TDS Rate Chart',1,'TDS Rate Chart','', 'TDS rate master'],['TDS Category',1,'TDS Category','id'+NEWLINE+'module','TDS categories']];
+    for(var i =0; i<lst1.length;i++)      
+      this.accounts['Accounts'].push(lst1[i]);
+  }
+  //--------------------------------------------------    
+  
+  var lst = [['Monthly Distribution',1,'Budget Distribution','id'+NEWLINE+'fiscal_year'+NEWLINE+'distribution_id','Manage budget distributions (seasonalities)'],
+    ['Sales Other Charges',1,'Other Charges','','Manage your charge structures (taxes + charges) for sales'],
+    ['Purchase Other Charges',1,'Purchase Other Charges','','Manage your charge structures (taxes + charges) for purchase'],
+    ['Mode of Payment',1,'Mode of Payment','','Mode of payment master']];
+             
+  for(var i =0; i<lst.length;i++)
+      this.accounts['Accounts'].push(lst[i]);
+  
+  this.stock = {'Stock':[['Item Group',2,'Sales Browser','Item Group','Manage item classifications'],
+    ['Item',1,'Item','name'+NEWLINE+'item_group'+NEWLINE+'description','Item master'],
+    ['Brand',1,'Brand','id'+NEWLINE+'description','Brand master'],
+    ['Batch',1,'Batch','name'+NEWLINE+'start_date'+NEWLINE+'item'+NEWLINE+'expiry_date','Manage batches'],
+    ['Price List',1,'Price List','','Price list master'],
+    ['UOM',1,'UOM','','Unit of measure (UOM) master'],
+    ['Warehouse Type',1,'Warehouse Type','','Warehouse classifications'],
+    ['Warehouse',1,'Warehouse','','Warehouse master']]};
+  
+  this.buying = {'Buying':[['Supplier Type',1,'Supplier Type','','Manage supplier classifications'],
+    ['Supplier',1,'Supplier','id'+NEWLINE+'supplier_type'+NEWLINE+'supplier_status'+NEWLINE+'company','Supplier master']]};
+  
+  this.maintenance = {'Maintenance':[['Serial No',1,'Serial No','item_code'+NEWLINE+'status'+NEWLINE+'pr_no'+NEWLINE+'delivery_note_no'+NEWLINE+'customer_name','Manage unique serial numbers for items'],
+    ['Purpose of Service',1,'Purpose of Service','','Purpose of service master']]};
+  
+  this.production = {'Production':[['Bill of Materials',1,'Bill Of Materials','id'+NEWLINE+'item'+NEWLINE+'description'+NEWLINE+'operating_cost'+NEWLINE+'maintained_by','Muti-level bill of materials and operations'],
+    ['Workstation',1,'Workstation','id'+NEWLINE+'workstation_name'+NEWLINE+'warehouse'+NEWLINE+'description','Workstation master']]};
+  
+  this.hr = {'HR':[['Department',1,'Department','','Company department master'],
+    ['Designation',1,'Designation','','Company designation master'],
+    ['Branch',1,'Branch','','Manage branches for your company'],
+    ['Grade',1,'Grade','','Manage employee grades'],
+    ['Employment Type',1,'Employment Type','','Manage types of employment'],
+    ['Employee',1,'Employee','employee_name'+NEWLINE+'employment_type'+NEWLINE+'status'+NEWLINE+'branch'+NEWLINE+'designation'+NEWLINE+'department'+NEWLINE+'grade'+NEWLINE+'reports_to','Employee master'],
+    ['Earning Type',1,'Earning Type','taxable'+NEWLINE+'exemption_limit','Types of salary earning master'],
+    ['Deduction Type',1,'Deduction Type','','Types of salary deduction master'],
+    ['Expense Type',1,'Expense Type','', 'Types of expense master'],
+      
+    ['Salary Structure',1,'Salary Structure','employee'+NEWLINE+'is_active'+NEWLINE+'fiscal_year'+NEWLINE+'from_date'+NEWLINE+'ctc'+NEWLINE+'total_earning'+NEWLINE+'total_deduction'+NEWLINE+'total','Salary structure template'],
+    ['Holiday List',1,'Holiday List','fiscal_year','List of holidays'],
+    ['Leave Type',1,'Leave Type','max_days_allowed'+NEWLINE+'is_carry_forward'+NEWLINE+'is_encash','Leave type master'],
+    ['KRA Template',1,'KRA Template','','Template of Key Result Areas (KRAs)']]};
+}
diff --git a/setup/page/setup/setup.txt b/setup/page/setup/setup.txt
new file mode 100644
index 0000000..f2a7a70
--- /dev/null
+++ b/setup/page/setup/setup.txt
@@ -0,0 +1 @@
+[{'creation': '2010-07-13 13:42:28', 'module': 'Setup', 'doctype': 'Page', 'owner': 'Administrator', 'style': None, 'modified_by': 'harshada@webnotestech.com', 'script': None, 'show_in_menu': None, 'content': None, 'page_name': 'Setup', 'menu_index': None, 'docstatus': 0, 'parent': None, 'standard': 'Yes', 'icon': None, 'name': 'Setup', 'idx': None, 'static_content': None, 'modified': '2010-11-24 16:25:07', 'parenttype': None, 'parent_node': None, 'parentfield': None}]
\ No newline at end of file
diff --git a/setup/page/setup/setup_static.html b/setup/page/setup/setup_static.html
new file mode 100644
index 0000000..54fee71
--- /dev/null
+++ b/setup/page/setup/setup_static.html
@@ -0,0 +1 @@
+Setup
\ No newline at end of file
diff --git a/setup/page/setup_wizard/__init__.py b/setup/page/setup_wizard/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/setup/page/setup_wizard/__init__.py
diff --git a/setup/page/setup_wizard/setup_wizard.html b/setup/page/setup_wizard/setup_wizard.html
new file mode 100644
index 0000000..1f5547e
--- /dev/null
+++ b/setup/page/setup_wizard/setup_wizard.html
@@ -0,0 +1 @@
+<div id="setup_wizard_wrapper" class="layout_wrapper"></div>
\ No newline at end of file
diff --git a/setup/page/setup_wizard/setup_wizard.js b/setup/page/setup_wizard/setup_wizard.js
new file mode 100644
index 0000000..59308f1
--- /dev/null
+++ b/setup/page/setup_wizard/setup_wizard.js
@@ -0,0 +1,167 @@
+pscript['onload_Setup Wizard'] = function()
+{   
+
+  // header and toolbar
+  var h = new PageHeader('setup_wizard_wrapper','Setup Wizard','All important setup items in one place');
+
+  pscript.setup_wizard_callback();
+}
+
+// ==================================================================================================
+
+pscript.setup_wizard_callback = function(){
+    var items = {};
+    items['Customer'] = new pscript.Setup_Wizard_Obj('Customer', 'customer_name', 0, '', 'Customer', 'Manage your customers',1);
+    items['Supplier'] = new pscript.Setup_Wizard_Obj('Supplier', 'supplier_name', 0, '', 'Supplier', 'Manage your supplier',1);
+    items['Item'] = new pscript.Setup_Wizard_Obj('Item', 'item_name', 0, '', 'Item', 'Create your items',1);
+    //items['Customer Group'] = new pscript.Setup_Wizard_Obj('Customer Group', 'group_name', 0, '', 'Customer Group', 'Organizes your customers for better analysis');
+    items['Price List'] = new pscript.Setup_Wizard_Obj('Price List', 'price_list_name', 0, '', 'Price List', 'Helps you maintain different prices for different customers, currencies etc.');
+    items['Supplier Type'] = new pscript.Setup_Wizard_Obj('Supplier Type', 'supplier_type', 0, '', 'Supplier Type', 'Organizes your suppliers for better analysis');
+    //items['Item Group'] = new pscript.Setup_Wizard_Obj('Item Group', 'group_name', 0, '', 'Item Group', 'Organizes your items for better analysis');
+    items['UoM'] = new pscript.Setup_Wizard_Obj('UOM', 'uom_name', 0, '', 'UOM', 'Maintain multiple Units of Measure (UOM)');
+    items['Warehouse Type'] = new pscript.Setup_Wizard_Obj('Warehouse Type', 'warehouse_type', 0, '', 'Warehouse Type', 'Define types of warehouses');
+    items['Warehouse'] = new pscript.Setup_Wizard_Obj('Warehouse', 'warehouse_name', 'warehouse_type', 'Warehouse Type', 'Warehouse', 'Manage stock across different warehouses');
+    items['Print Heading'] = new pscript.Setup_Wizard_Obj('Print Heading', 'print_heading', 'transaction', 'Transaction', 'Print Heading', 'Define print heading for various transaction.');
+    items['Warehouse Type'].onmake = function(){
+       items['Warehouse'].refresh_select('warehouse_type', 'Warehouse Type', 'Warehouse');
+    }
+    items['Print Heading'].onmake = function(){
+       items['Print Heading'].refresh_select('transaction', 'Transaction', 'Print Heading');
+    }
+}
+
+// ==================================================================================================
+pscript.Setup_Wizard_Obj = function(lbl, name_field, opt_fieldname, opt_field_tbl, dt, desc, important) 
+{
+    this.lbl = lbl;
+    this.make_body(lbl, important);
+    if(lbl != 'Item')
+      this.make_input(name_field);
+    if(opt_fieldname){
+      this.make_select(opt_fieldname, opt_field_tbl, dt);
+    }
+   
+    this.show_description(desc);
+    this.make_button();
+    this.create_doc_link(dt);
+
+}
+
+pscript.Setup_Wizard_Obj.prototype.make_body = function(lbl, important) {
+    var wrapper = $a($i('setup_wizard_wrapper'), 'div', '', {padding:'8px', borderBottom: '1px solid #AAA'});
+    if(important)$y(wrapper, {backgroundColor:'#FFD'});
+    this.tab = make_table(wrapper,1,3,'90%',['20%','50%','30%'], {padding:'2px 0px', verticalAlign:'middle'});
+    this.desc_area = $a(wrapper,'div','comment');
+    
+    $td(this.tab,0,0).innerHTML = lbl.bold();
+}
+
+pscript.Setup_Wizard_Obj.prototype.make_input = function(name_field){
+    this.input = $a_input($td(this.tab,0,1), 'text');
+    this.name_field = name_field;
+}
+
+pscript.Setup_Wizard_Obj.prototype.make_select = function(fn, ft, dt){
+    this.select = $a($td(this.tab,0,1), 'select', '', {width:'120px', marginLeft:'8px'});
+    this.opt_field = fn;
+    this.sel_field = 'Select ' + ft + '...';
+    this.refresh_select(fn, ft, dt);
+}                
+
+pscript.Setup_Wizard_Obj.prototype.refresh_select = function(fn, ft, dt){
+  var me = this;
+  if(ft == 'Transaction'){
+    empty_select(me.select);
+    add_sel_options(me.select, ['Select Transaction ...','Purchase Order','Sales Order','Service Order','Purchase Receipt','Delivery Note','Receivable Voucher','Payable Voucher','Journal Voucher']);
+  }
+  else{
+    $c_obj('Setup Wizard Control', 'get_master_lists','', function(r,rt){
+      var ft_lst = [];
+      if(r.message) ft_lst = r.message;
+      ft_lst.push('Select Warehouse Type ...');
+      empty_select(me.select);
+      add_sel_options(me.select, ft_lst.reverse(), 'Warehouse Type');
+    });
+  }
+}  
+ 
+pscript.Setup_Wizard_Obj.prototype.make_button = function(){   
+    var me = this;
+
+    var create = $a($td(this.tab,0,1), 'button', '', {marginLeft:'8px'});
+    create.innerHTML = 'Create';
+    
+    create.onclick = function(){
+        me.create_record(this);
+    }
+}
+
+// show description
+pscript.Setup_Wizard_Obj.prototype.show_description=function(desc){ 
+    this.desc_area.innerHTML = desc;
+}
+
+// create link to show listing of all records
+pscript.Setup_Wizard_Obj.prototype.create_doc_link = function(doc_link){  
+    this.obj_link = $a($td(this.tab,0,2), 'span', 'link_type',{marginLeft:'8px'});
+    this.obj_link.innerHTML = 'View ' + doc_link + ' list';
+    this.dt = doc_link;
+
+    this.obj_link.onclick = function(){
+      if(doc_link == 'Customer') doc_lst = 'customer_group'+NEWLINE+'country';
+      else if(doc_link == 'Supplier') doc_lst = 'supplier_type'+NEWLINE+'supplier_status'+NEWLINE+'company';
+      else if(doc_link == 'Item') doc_lst = 'item_group'+NEWLINE+'description';
+        
+      if(doc_link == 'Customer' || doc_link == 'Supplier' || doc_link == 'Item')
+        loaddocbrowser(doc_link,doc_link, doc_lst);
+      else
+        loaddocbrowser(doc_link);
+    }
+}    
+pscript.Setup_Wizard_Obj.prototype.create_record = function(cur_obj)
+{   
+    var me = this;
+    if(me.lbl == 'Item'){ me.create_master_rec(); }
+    else{
+      if(this.input.value) { //check for input value
+        
+        if (this.select && (this.sel_field == this.select.value)){ //check for value is selected or not
+          alert('Please select '+this.select.value);  
+          this.input.value = '';
+        }
+        else{
+          args = {};
+          args['Doctype'] = this.dt;
+          if(strip(this.input.value) == ''){ alert("Please enter proper name."); me.input.value = '';}
+          else{
+            if(me.lbl == 'Customer' || me.lbl == 'Supplier'){ this.create_master_rec(); }
+            else{
+              args[this.name_field] = this.input.value;
+              args[this.opt_field] = this.opt_field ? this.select.value : '';
+              
+              $c_obj('Setup Wizard Control', 'create_record', JSON.stringify(args), function(r,rt){        
+                alert(r.message);
+                me.input.value = '';
+                if(me.onmake) me.onmake();  
+              });
+            }
+          }
+        }
+      }
+      else
+        alert("Please enter " +this.dt);
+    }
+}
+
+pscript.Setup_Wizard_Obj.prototype.create_master_rec = function(){
+  var me = this;
+  var fn = function(new_docname) {
+    var new_doc = locals[me.lbl][new_docname];
+    if(me.lbl == 'Customer')
+      new_doc.customer_name = me.input.value;
+    else if(me.lbl == 'Supplier')
+      new_doc.supplier_name = me.input.value;
+  }
+  new_doc(me.lbl, fn);
+  
+}
\ No newline at end of file
diff --git a/setup/page/setup_wizard/setup_wizard.txt b/setup/page/setup_wizard/setup_wizard.txt
new file mode 100644
index 0000000..e79cc54
--- /dev/null
+++ b/setup/page/setup_wizard/setup_wizard.txt
@@ -0,0 +1 @@
+[{'creation': '2010-04-26 11:03:08', 'module': 'Setup', 'doctype': 'Page', 'owner': 'Administrator', 'style': None, 'modified_by': 'Administrator', 'script': None, 'show_in_menu': 0, 'content': None, 'page_name': 'Setup Wizard', 'menu_index': None, 'docstatus': 0, 'parent': None, 'standard': 'Yes', 'icon': None, 'name': 'Setup Wizard', 'idx': None, 'static_content': None, 'modified': '2010-09-25 00:00:00', 'parenttype': None, 'parent_node': None, 'parentfield': None}, {'modified_by': 'Administrator', 'name': 'PR000127', 'parent': 'Setup Wizard', 'creation': '2010-04-26 13:35:08', 'modified': '2010-07-13 13:36:23', 'doctype': 'Page Role', 'idx': 1, 'parenttype': 'Page', 'role': 'System Manager', 'owner': 'Administrator', 'docstatus': 0, 'parentfield': 'roles'}]
\ No newline at end of file
diff --git a/setup/page/setup_wizard/setup_wizard_static.html b/setup/page/setup_wizard/setup_wizard_static.html
new file mode 100644
index 0000000..281c686
--- /dev/null
+++ b/setup/page/setup_wizard/setup_wizard_static.html
@@ -0,0 +1 @@
+<div></div>
\ No newline at end of file
diff --git a/setup/page/webforms/__init__.py b/setup/page/webforms/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/setup/page/webforms/__init__.py
diff --git a/setup/page/webforms/webforms.html b/setup/page/webforms/webforms.html
new file mode 100644
index 0000000..e1717dc
--- /dev/null
+++ b/setup/page/webforms/webforms.html
@@ -0,0 +1,13 @@
+<div class="layout_wrapper">
+<div id="webform_div"></div>
+<p><strong>Note : </strong>Copy and paste code provided below in your website wherever you want to show the form to capture details</p>
+<p>&nbsp;</p>
+<p><span style="font-size: medium;"><strong>Lead</strong></span></p>
+<div id="lead_div"></div>
+<p><span style="font-size: medium;"><strong>Customer Issue</strong></span></p>
+<div id="cust_issue_div"></div>
+<p><span style="font-size: medium;"><strong>Job Application</strong></span></p>
+<div id="job_div"></div>
+<p><span style="font-size: medium;"><strong>Ticket</strong></span></p>
+<div id="ticket_div"></div>
+</div>
\ No newline at end of file
diff --git a/setup/page/webforms/webforms.js b/setup/page/webforms/webforms.js
new file mode 100644
index 0000000..d429ce0
--- /dev/null
+++ b/setup/page/webforms/webforms.js
@@ -0,0 +1,26 @@
+pscript.onload_Webforms = function(){
+
+  $c_obj('Home Control','get_acc_id','', function(r,rt) {
+    if(r.message) {
+      var acc_id = r.message; 
+  var parent = $i('webform_div');
+  new PageHeader(parent,'Web Forms','');
+      
+      var lead_dv = $a('lead_div','div', '', {border:'1px solid #AAA', padding:'8px', width:'90%'});
+      var cust_issue_dv = $a('cust_issue_div','div', '', {border:'1px solid #AAA', padding:'8px', width:'95%'});
+      var job_dv = $a('job_div','div', '', {border:'1px solid #AAA', padding:'8px', width:'95%'});
+      var ticket_dv = $a('ticket_div','div', '', {border:'1px solid #AAA', padding:'8px', width:'95%'});
+
+      // url
+      if(window.location.href.indexOf('?')!=-1)
+        var url = window.location.href.split('?')[0];
+      else
+        var url = window.location.href.split('#')[0];
+
+      lead_dv.innerHTML = '&lt;iframe src ="'+url+'?ac_name='+acc_id+'&embed=Lead" width ="400" height="800" frameborder="0"&gt;&lt;/iframe&gt;';
+      cust_issue_dv.innerHTML = '&lt;iframe src ="'+url+'?ac_name='+acc_id+'&embed=Customer Issue" width ="400" height="500" frameborder="0"&gt;&lt;/iframe&gt;';
+      job_dv.innerHTML = '&lt;iframe src ="'+url+'?ac_name='+acc_id+'&embed=Job Application"  width ="400" height="800" frameborder="0""&gt;&lt;/iframe&gt;';
+      ticket_dv.innerHTML = '&lt;iframe src ="'+url+'?ac_name='+acc_id+'&embed=Support Ticket"  width ="400" height="800" frameborder="0""&gt;&lt;/iframe&gt;';
+    }
+  }); 
+}
diff --git a/setup/page/webforms/webforms.txt b/setup/page/webforms/webforms.txt
new file mode 100644
index 0000000..63a8289
--- /dev/null
+++ b/setup/page/webforms/webforms.txt
@@ -0,0 +1 @@
+[{'creation': '2010-12-18 17:10:03', 'module': 'Setup', 'doctype': 'Page', 'owner': 'Administrator', 'style': None, 'modified_by': 'Administrator', 'script': None, 'show_in_menu': None, 'content': None, 'page_name': 'Webforms', 'menu_index': None, 'docstatus': 0, 'parent': None, 'standard': 'Yes', 'icon': None, 'name': 'Webforms', 'idx': None, 'static_content': None, 'modified': '2010-12-18 17:14:25', 'parenttype': None, 'parent_node': None, 'parentfield': None}, {'modified_by': 'Administrator', 'name': 'PR000075', 'parent': 'Webforms', 'creation': '2010-12-18 17:11:12', 'modified': '2010-12-18 17:14:25', 'doctype': 'Page Role', 'idx': 1, 'parenttype': 'Page', 'role': 'All', 'owner': 'Administrator', 'docstatus': 0, 'parentfield': 'roles'}]
\ No newline at end of file
diff --git a/setup/page/webforms/webforms_static.html b/setup/page/webforms/webforms_static.html
new file mode 100644
index 0000000..3488a17
--- /dev/null
+++ b/setup/page/webforms/webforms_static.html
@@ -0,0 +1 @@
+webforms
\ No newline at end of file