[IMP]: Change also in source file
[odoo/odoo.git] / addons / thunderbird / plugin / openerp_plugin / chrome / openerp_plugin / content / tiny_xmlrpc.js
1 /************************************************************
2 *    OpenERP, Open Source Management Solution
3 *    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
4 *
5 *    This program is free software: you can redistribute it and/or modify
6 *    it under the terms of the GNU Affero General Public License as
7 *    published by the Free Software Foundation, either version 3 of the
8 *    License, or (at your option) any later version.
9 *
10 *    This program is distributed in the hope that it will be useful,
11 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
12 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 *    GNU Affero General Public License for more details.
14 *
15 *    You should have received a copy of the GNU Affero General Public License
16 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 ***************************************************************/
18
19 var xmlRpcClient;
20
21 //Service name on server like /common,/db etc...
22 var strServerService;
23
24 //temporary variables
25 var strobject;
26
27 //Array
28 var arrDbList = new Array();
29 var arrPartnerList = new Array();
30 var arrFinalList = new Array();
31
32
33 var contentType = new Array();
34 var uri = new Array();
35 var url = new Array();
36 var name = new Array();
37 var attach_eml ="no";
38 var popup_display = "yes"
39 var rpc= {
40     servers: {},
41     addserver: function(name,ip,port,path) {
42         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
43         this.servers[name]= {
44             ip: ip,
45             port: port,
46             path: path,
47             avaible: true,
48             sock: Components.classes['@mozilla.org/xml-rpc/client;1'].createInstance(Components.interfaces.nsIXmlRpcClient)};
49     },
50     getany: function(rpcval,n) {
51         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
52         var t = ['PRUint8','PRUint16','PRInt16','PRInt32','PRBool','Char','CString','Float','Double','PRTime','InputStream','Array','Dictionary'];
53         for (var i=0; i<t.length; i++)
54             try { return [t[i],this.Iget(rpcval,Components.interfaces[((i==10 || i==12)? 'nsI': 'nsISupports')+t[i]],n)]; } catch(e) {}
55         return [false,'error getany','Undefined type'];
56     },
57     onfault: function(t) {
58         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
59         return (t.constructor==Array && t.length==3 && !t[0] && (t[1].substr(0,5)=='error' || t[1].substr(0,5)=='fault'))?
60             true : false;
61     },
62     getall: function(rpcval,n) {
63         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
64         var t = this.getany(rpcval,n);
65         if (this.onfault(t)) return t;
66         if (t[0]=='PRBool') return (t[1]=='true');
67         if (t[0]=='PRInt32') return parseInt(t[1]+'');
68         if (t[0]=='PRTime') {
69             dte= new Date("January 1, 1970, 00:00:00");
70             dte.setUTCMilliseconds(t[1]+'');
71             return dte; }
72         if (t[0]=='Double' || t[0]=='Float') return parseFloat(t[1]+'');
73         if (t[0]=='Char' || t[0]=='CString') return (t[1]+'').replace(/¬/g,'€');
74         if (t[0]=='Array') {
75             var a=[];
76             for (var i=0; i<t[1].Count(); i++) a[i]= this.getall(t[1],i);
77         } else if (t[0]=='Dictionary') {
78             var a={};
79             var keys = t[1].getKeys({});
80             for (var k = 0; k < keys.length; k++)
81                 a[keys[k]]= this.getall(t[1],keys[k]);
82         } else return t[1];
83         return a;
84     },
85     Iget: function(rpcval,itype,n) {
86         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
87         if (n == undefined) return rpcval.QueryInterface(itype);
88         else if (n==parseInt(n)) return rpcval.QueryElementAt(n,itype);
89         else return rpcval.getValue(n).QueryInterface(itype);
90     },
91     checktype: function(val) {
92         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
93         if (val != undefined) {
94             switch (val.constructor) {
95                 case Number: return (val==parseInt(val))? 1:4;
96                 case Boolean: return 2;
97                 case String: return 3;
98                 case Date: return 5;
99                 case Object: return 7;
100                 case Array: return 6;
101
102             }
103         }
104         return 7;
105
106     },
107     set: function(rpcobj,param) {
108         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
109         if (param==undefined) return [false,'error set','Undefined parameter'];
110         var itype= this.checktype(param);
111         if (this.onfault(itype)) return itype;
112         var p = this.servers[rpcobj].sock.createType(itype,{});
113         if (itype==6) {
114             if (param.length>0)
115                 for (var i=0; i<param.length; i++) p.AppendElement( this.set(rpcobj,param[i]) );
116         } else if (itype==7) {
117             for (var i in param) p.setValue( i, this.set(rpcobj,param[i]) );
118         } else if (itype==4) {
119             p.data=(''+param).replace(',','.');
120         } else p.data=param;
121         return p;
122     },
123     ask: function(rpcobj,method,params,func_out) {
124         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
125         var a=this.disableNset(rpcobj) ;
126         if (this.onfault(a)) return a;
127         var handler = {
128             onResult: function(client, async, result) {
129                 rpc.servers[rpcobj].avaible= true;
130                 func_out(rpc.getall(result)); },
131             onFault: function (client, async, faute) {alert("in ask infault"+result)
132                  rpc.servers[rpcobj].avaible= true; func_out([false,'fault',faute]); },
133             onError: function (client, async, status, msg) {
134                 rpc.servers[rpcobj].avaible= true;
135                 if (status=='2147500037') {
136                     status= "no network or no server";
137                     msg= "1. Check your network connection.";
138                     msg+= "\n2. Check your server connection parameters:";
139                     msg+= "\n\t"+rpc.servers[rpcobj].ip+":"+rpc.servers[rpcobj].port+"=>"+params[0];
140                     msg+= "\n3. Your server may not be launched or connected to the network.";
141                 }
142                 func_out([false,'error '+status,msg]);
143                 } };
144         var p = [];
145         for (var i=0; i<params.length; i++)
146             p[i]= this.set(rpcobj,params[i]);
147         try { this.servers[rpcobj].sock.asyncCall(handler, null, method, p, p.length);
148         } catch(e) {
149             this.servers[rpcobj].avaible= true;
150             this.servers[rpcobj].sock= Components.classes['@mozilla.org/xml-rpc/client;1'].createInstance(Components.interfaces.nsIXmlRpcClient) ;
151             func_out([false,'error catch',e]); }
152         return true;
153     },
154     disableNset: function(rpcobj) {
155         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
156         if (this.servers[rpcobj]) {
157             this.servers[rpcobj].avaible= false;//alert('http://'+this.servers[rpcobj].ip+':'+this.servers[rpcobj].port+this.servers[rpcobj].path);
158             server_path=this.servers[rpcobj].ip+':'+this.servers[rpcobj].port+this.servers[rpcobj].path
159             this.servers[rpcobj].sock.init(server_path);
160             
161             return true; }
162         return [false,'error disableNset','Server vars not set'];
163     }
164 }
165 function handler_function( result ) {
166     if ( rpc.onfault( result ) ) { alert( result[0] + "\n" + result[1] ); return; }
167     else{
168         alert("got result"+result)  
169     }
170 }
171
172 //Sets the preference service
173 function getPref(){
174     var prefService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
175     var branchobj = prefService.getBranch("extensions.tiny.");
176     branchobj.QueryInterface(Components.interfaces.nsIPrefBranch2);
177     return branchobj
178 }
179
180 function setFileName(fname){
181     getPref().setCharPref('fname',fname);
182 }
183
184 //set attachment file save or not
185 function setAttachment(argAttac){
186     getPref().setCharPref('attachment',argAttac);
187 }
188
189 //set preference value for server url
190 function setServer(argServer){
191     getPref().setCharPref('serverurl',argServer);
192 }
193
194 //set preference value for server port
195 function setPort(argPort){
196     getPref().setCharPref('serverport',argPort)
197 }
198
199 //set preference value of database name for data searching and selection
200 function setDbName(argDbName){
201     getPref().setCharPref('serverdbname',argDbName);
202 }
203
204 //set webserver url
205 function setWebServerURL(argWebServerURL){
206     getPref().setCharPref('webserverurl',argWebServerURL);
207 }
208 //set preference value of username for login
209 function setUsername(argUsername){
210     getPref().setCharPref('username',argUsername);
211 }
212
213 //set preference value of password for login
214 function setPassword(argPassword){
215     getPref().setCharPref('password',argPassword);
216 }
217
218 //set preference value for storing partner id
219 function setPartnerId(argPartnerId){
220     getPref().setCharPref('partnerid',argPartnerId)
221 }
222
223 //set preference value for Resource Id
224 function setResourceId(argResourceId){
225     getPref().setCharPref('res_id',argResourceId)
226 }
227 //set server service
228 function setServerService(argServerService){
229     strServerService = argServerService;
230 }
231
232 //set preference value for sender email
233 function setSenderEmail(argSenderEmail){
234     getPref().setCharPref('senderemail',argSenderEmail)
235 }
236
237 //set preference value for receiver email
238 function setReceiverEmail(argReceiverEmail){
239     getPref().setCharPref('receiveremail',argReceiverEmail)
240 }
241
242 //set preference value for sender name
243 function setSenderName(argSenderName){
244     getPref().setCharPref('sendername',argSenderName)
245 }
246
247 //set preference value for email subject
248 function setSubject(argSubject){
249     getPref().setCharPref('subject',argSubject)
250 }
251
252 //set preference value for email received date
253 function setReceivedDate(argReceivedDate){
254     getPref().setCharPref('receiveddate',argReceivedDate)
255 }
256
257 //set preference value for storing contact id which is used while storing mail contents after creating a new partner contact
258 function setContactId(argContactId){
259     getPref().setCharPref('contactid',argContactId)
260 }
261
262 //set preference value for storing attachment option in config
263 function setAttachValue(argAttachValue){
264     getPref().setCharPref('attachvalue',argAttachValue)
265 }
266
267 //set preference value for email cclist
268 function setCCList(argCCList){
269     getPref().setCharPref('cclist',argCCList)
270 }
271
272 //set preference value for email message body
273 function setMessageBody(argMessageBody){
274     getPref().setCharPref('messagebody',argMessageBody)
275 }
276
277 //set preference value for Partner Name
278 function setPartnerName(argPartnerName){
279     getPref().setCharPref('partnername',argPartnerName)
280 }
281
282 //set preference value for Contact Name
283 function setContactName(argContactName){
284     getPref().setCharPref('contactname',argContactName)
285 }
286
287 //set preference value for street
288 function setStreet(argStreet){
289     getPref().setCharPref('street',argStreet)
290 }
291
292 //set preference value for street2
293 function setStreet2(argStreet2){
294     getPref().setCharPref('street2',argStreet2)
295 }
296
297 //set preference value for zipcode
298 function setZipCode(argZipcode){
299     getPref().setCharPref('zipcode',argZipcode)
300 }
301
302 //set preference value for Office Number
303 function setOfficenumber(argOfficenumber){
304     getPref().setCharPref('officeno',argOfficenumber)
305 }
306
307 //set preference value for Phone Number
308 function setMobilenumber(argMobilenumber){
309     getPref().setCharPref('phoneno',argMobilenumber)
310 }
311
312 //set preference value for Fax
313 function setFax(argFax){
314     getPref().setCharPref('fax',argFax)
315 }
316
317 //set preference value for city
318 function setCity(argCity){
319     getPref().setCharPref('city',argCity)
320 }
321
322 //set preference value for country
323 function setCountry(argCountry){
324     getPref().setCharPref('country',argCountry)
325 }
326
327 //set preference value for state
328 function setState(argState){
329     getPref().setCharPref('state',argState)
330 }
331
332
333 //set the value for the whole server url
334 function setServerUrl(argServerUrl)
335 {
336     var seperateUrl = argServerUrl.split(':');
337     setServer(seperateUrl.slice(0,seperateUrl.length-1).join(":"));
338     setPort(seperateUrl[seperateUrl.length-1]);
339 }
340
341 //set preference value for storing user id
342 function setUserId(argUserId){
343     getPref().setIntPref('userid',argUserId);
344 }
345
346 //set database list is displaye or not
347 function setDBList(argDBList){
348     getPref().setCharPref('db_list',argDBList)
349 }
350
351 //set server connect or not
352 function setconnect_server(argconnect_server){
353     getPref().setCharPref('connect_server',argconnect_server)
354 }
355
356 //set module install or not
357 function setmodule_install(argconnect_module){
358     getPref().setCharPref('module_install',argconnect_module)
359 }
360
361 //get module install or not
362 function getmodule_install(){
363     return getPref().getCharPref('module_install');
364 }
365
366
367 //get server connect or not
368 function getconnect_server(){
369     return getPref().getCharPref('connect_server');
370 }
371
372
373 //get partner id
374 function getPartnerId(){
375     return getPref().getCharPref('partnerid');
376 }
377 //get database list is displaye or not
378 function getDBList(){
379     return getPref().getCharPref('db_list');
380 }
381
382 function getFileName(){
383     return getPref().getCharPref('fname');
384 }
385
386 //get attachment save or not
387 function getAttachment(){
388     return getPref().getCharPref('attachment');
389 }
390
391 //get serverurl
392 function getServer(){
393     return getPref().getCharPref('serverurl');
394 }
395
396 //get server port
397 function getPort(){
398     return getPref().getCharPref('serverport');
399 }
400
401 //get database name
402 function getDbName(){
403     return getPref().getCharPref('serverdbname');
404 }
405
406 //get webserver url
407 function getWebServerURL(){
408     return getPref().getCharPref('webserverurl');
409 }
410
411 //get webserver port
412 function getwebPort(){
413     return getPref().getCharPref('webserverport');
414 }
415
416 //get username from config settings
417 function getUsername(){
418     return getPref().getCharPref('username');
419 }
420
421 //get password from config settings
422 function getPassword(){
423     return getPref().getCharPref('password');
424 }
425
426 //get serverservice
427 function getServerService(){
428     return strServerService;
429
430 }
431
432 //get sender email
433 function getSenderEmail(){
434     return getPref().getCharPref('senderemail');
435 }
436
437 //get receiver email
438 function getReceiverEmail(){
439     return getPref().getCharPref('receiveremail');
440 }
441
442 //get resource id
443 function getResourceId(){
444     return getPref().getCharPref('res_id');
445 }
446
447
448 //get sender name
449 function getSenderName(){
450         str = getPref().getCharPref('sendername');
451         if(!str.toString().match(/=?utf-8?q?/))
452         {
453             return str;
454         }
455         else
456         {
457
458             string = str.replace(/[\'Š',\'Ž',\'š',\'ž',\'Ÿ',\'À',\'Á',\'Â',\'Ã',\'Ä',\'Å',\'Ç',\'È',\'É',\'Ê',\'Ë',\'Ì',\'Í',\'Î',\'Ï',\'Ñ',\'Ò',\'Ó',\'Ô',\'Õ',\'Ö',\'Ø',\'Ù',\'Ú',\'Û',\'Ü',\'Ý',\'à',\'á',\'â',\'ã',\'ä',\'å',\'ç',\'è',\'é',\'ê',\'ë',\'ì',\'í',\'î',\'ï',\'ñ',\'ò',\'ó',\'ô',\'õ',\'ö',\'ø',\'ù',\'ú',\'û',\'ü',\'ý',\'ÿ',\'Þ',\'þ',\'Ð',\'ð',\'ß',\'Œ',\'œ',\'Æ',\'æ',\'µ']/g,'"',"'",'“','”',"\n","\r",'_/',"'S','Z','s','z','Y','A','A','A','A','A','A','C','E','E','E','E','I','I','I','I','N','O','O','O','O','O','O','U','U','U','U','Y','a','a','a','a','a','a','c','e','e','e','e','i','i','i','i','n','o','o','o','o','o','o','u','u','u','u','y','y','TH','th','DH','dh','ss','OE','oe','AE','ae','u','','','','','','','-'");
459
460             var utftext = "";
461             var encoded_string = "";
462             var convertedString = "";
463             for (var n = 0; n < string.length; n++)
464             {
465                 var c = string.charCodeAt(n);
466                 if (c < 128) {
467                     utftext += String.fromCharCode(c);
468                 }
469             }
470
471             encoded_string = encode64(utftext);
472            return encoded_string;
473         }
474 }
475
476
477 //get partner name
478 function getPartnerName(){
479     return getPref().getCharPref('partnername');
480 }
481
482 //get contact name
483 function getContactName(){
484     return getPref().getCharPref('contactname');
485 }
486
487
488 //get street name
489 function getStreet(){
490     return getPref().getCharPref('street');
491 }
492
493 //get street2 name
494 function getStreet2(){
495     return getPref().getCharPref('street2');
496 }
497
498 //get zip code
499 function getZipCode(){
500     return getPref().getCharPref('zipcode');
501 }
502
503 //get city name
504 function getCity(){
505     return getPref().getCharPref('city');
506 }
507
508 //get country name
509 function getCountry(){
510     return getPref().getCharPref('country');
511 }
512
513 //get state name
514 function getState(){
515     return getPref().getCharPref('state');
516 }
517
518 //get office no
519 function getOfficenumber(){
520     return getPref().getCharPref('officeno');
521 }
522
523 //get mobile no
524 function getMobilenumber(){
525     return getPref().getCharPref('phoneno');
526 }
527
528 //get fax no
529 function getFax(){
530     return getPref().getCharPref('fax');
531 }
532
533
534 //get email subject
535 function getSubject(){
536     return getPref().getCharPref('subject');
537 }
538
539 //get email received date
540 function getReceivedDate(){
541     return getPref().getCharPref('receiveddate');
542 }
543
544 //get contact id which is used while storing mail contents after creating a new partner contact
545 function getContactId(){
546     return getPref().getCharPref('contactid');
547 }
548
549 //get attachment option information from the configuration settings
550 function getAttachValue(){
551     return getPref().getCharPref('attachvalue');
552 }
553
554 //get email cclist information
555 function getCCList(){
556     return getPref().getCharPref('cclist');
557 }
558
559 //get email message body
560 function getMessageBody(){
561     return getPref().getCharPref('messagebody');
562 }
563
564 //get the whole server path
565 function getServerUrl(){
566     return getServer()+":"+getPort()+"/"+getServerService();
567 }
568
569 //get user id for the xmlrpc request
570 function getUserId(){
571     return getPref().getIntPref('userid');
572 }
573
574 //Creates and returns and instance of the XML-RPC client
575 function getClient() {
576     // Enable correct security
577     netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
578     return Components.classes['@mozilla.org/xml-rpc/client;1'].createInstance(Components.interfaces.nsIXmlRpcClient);
579 }
580
581 //returns the xmlrpc client instance
582 function getXmlRpc() {
583     if (!xmlRpcClient) {
584         xmlRpcClient = getClient();
585     }
586
587     // Initialize the client with the URL
588     xmlRpcClient.init(getServerUrl());
589     return xmlRpcClient;
590 }
591
592 // function to get all basic parameters
593 function getBasicList(){
594     var branchobj = getPref();
595     arrBasicList = [];
596     arrBasicList[0] = branchobj.getCharPref("serverdbname");
597     arrBasicList[1] = branchobj.getIntPref('userid');
598     arrBasicList[2] = branchobj.getCharPref("password");
599     arrBasicList[3] = getServer()
600     arrBasicList[4] = getPort()
601     return arrBasicList
602 }
603
604 function createMenuItem_db(aLabel) {
605     const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
606     var item = document.createElementNS(XUL_NS, "menuitem"); // create a new XUL menuitem
607     item.setAttribute("label", aLabel);
608     item.setAttribute("value", aLabel);
609     return item;
610 }
611
612 //xmlrpc request handler for getting the list of database
613 var listDbHandler = {
614     onResult: function(client, context, result) {
615         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
616         var arrMethodList = result.QueryInterface(Components.interfaces.nsISupportsArray);
617                 // Set the number of results
618         var count = arrMethodList.Count();
619         // Loop through the results, adding items to the list
620         for (i = 0; i < count; i++) {
621             var strlDbName = arrMethodList.QueryElementAt(i, Components.interfaces.nsISupportsCString);
622                         arrDbList[i] = strlDbName.data;
623         }
624         var database = ""
625         if (count > 0)
626         {
627             setDBList("true");
628             var label = document.getElementById("database_option");
629             var vbox = document.createElement("vbox");
630             var hbox = document.createElement("hbox");
631             var label1 = document.createElement("label");
632             label1.setAttribute("width","80");
633             label1.setAttribute("value","Database:");
634             label1.setAttribute("id","label111");
635             var menu1 = document.createElement("menulist");
636             var menupopup1 = document.createElement("menupopup");
637             menu1.setAttribute("id","DBlist");
638             menu1.setAttribute("width","300");
639             var menuitem1 = document.createElement("menuitem");
640             database = arrDbList[0]
641             menuitem1.setAttribute("label", arrDbList[0]);
642             menuitem1.setAttribute("value", arrDbList[0]);
643             menupopup1.appendChild(menuitem1);
644             menu1.appendChild(menupopup1)
645             hbox.appendChild(label1);
646             hbox.appendChild(menu1);
647             vbox.appendChild(hbox);
648             label.appendChild(vbox);
649
650             var d = document.getElementById("first"); 
651             var d_nested = document.getElementById("lbldb_list1"); 
652             var throwawayNode = d.removeChild(d_nested);
653             var d_nested = document.getElementById("DBlist_text"); 
654             var throwawayNode = d.removeChild(d_nested);
655
656
657         }
658         else
659         {
660             setDBList("false");
661         }
662         // Loop through the results, adding items to the list
663         if (count)
664         {
665             const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
666             var popup = document.getElementById("DBlist"); // a <menupopup> element
667             var arrsec=new Array()
668             for (var i=0;i<popup.menupopup.childNodes.length;i++) {
669                 arrsec.push(popup.menupopup.childNodes[i].label)
670             }
671             for (i=0;i<arrDbList.length;i++){
672                 
673                 if (arrsec.indexOf(arrDbList[i])==-1) {
674                     if (arrDbList[i] != database){
675                         popup.menupopup.appendChild(createMenuItem_db(arrDbList[i]));
676                     }
677                 }
678             }
679         }
680     },
681
682
683     onFault: function (client, ctxt, fault) {
684         setDBList("false");
685     },
686
687     onError: function (client, ctxt, status, errorMsg) {
688         setDBList("false");       
689     }
690 };
691 //function to get the database list
692 function getDbList(argControl)
693 {
694     setDBList("false");
695     setconnect_server("true");
696     // Enable correct security
697     netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
698     // Get the instance of the XML-RPC client
699     var xmlRpcClient = getXmlRpc();
700     arrDbList = [];
701     var cmbDbList = document.getElementById(argControl);
702
703     xmlRpcClient.asyncCall(listDbHandler,cmbDbList,'list',[],0);
704     return arrDbList;
705 }
706
707 function createMenuItem_partner(aLabel, aValue) {
708     const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
709     var item = document.createElementNS(XUL_NS, "menuitem"); // create a new XUL menuitem
710     item.setAttribute("label", aLabel);
711     item.setAttribute("value", aValue);
712     return item;
713 }
714
715 //xmlrpc request handler for getting the list of All objects
716 var listAllDocumentHandler = {
717
718     onResult: function(client, context, result) {
719         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
720         var arrIdList = result.QueryInterface(Components.interfaces.nsISupportsArray);
721                 // Set the number of results
722         var count = arrIdList.Count();
723
724         // Loop through the results, adding items to the list
725         for (i = 0; i < count; i++) {
726             var strlResult = arrIdList.QueryElementAt(i, Components.interfaces.nsISupportsArray);
727             var resultcount = strlResult.Count();
728             var arrDataPair = new Array();
729             arrDataPair[0] = strlResult.QueryElementAt(0, Components.interfaces.nsISupportsCString);
730             arrDataPair[1] = strlResult.QueryElementAt(1, Components.interfaces.nsISupportsCString);
731             arrPartnerList[i] = arrDataPair;
732         }
733         if (context)
734         {
735             const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
736             var popup = document.getElementById("section"); // a <menupopup> element
737             for (i=0;i<arrPartnerList.length;i++){
738                 popup.menupopup.appendChild(createMenuItem_partner(arrPartnerList[i][1],arrPartnerList[i][0]));
739             }
740         }
741         popup_display = "no"
742         searchCheckbox()
743     },
744     onFault: function (client, ctxt, fault) {
745
746     },
747
748     onError: function (client, ctxt, status, errorMsg) {
749
750     }
751 }
752
753 var listAllCountryHandler = {
754
755     onResult: function(client, context, result) {
756         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
757         var arrIdList = result.QueryInterface(Components.interfaces.nsISupportsArray);
758         var count = arrIdList.Count();
759         // Loop through the results, adding items to the list
760         for (i = 0; i < count; i++) {
761             var strlResult = arrIdList.QueryElementAt(i, Components.interfaces.nsISupportsArray);
762             var resultcount = strlResult.Count();
763             var arrDataPair = new Array();
764             arrDataPair[0] = strlResult.QueryElementAt(0, Components.interfaces.nsISupportsPRInt32);
765           
766             arrDataPair[1] = strlResult.QueryElementAt(1, Components.interfaces.nsISupportsCString);
767             arrPartnerList[i] = arrDataPair;
768         }
769         if (!context)
770         {
771             const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
772             var popup = document.getElementById("country"); // a <menupopup> element
773             for (i=0;i<arrPartnerList.length;i++){
774                 popup.menupopup.appendChild(createMenuItem_partner(arrPartnerList[i][1],arrPartnerList[i][0]));
775             }
776         }
777            
778     },
779     onFault: function (client, ctxt, fault) {
780         
781     },
782
783     onError: function (client, ctxt, status, errorMsg) {
784         
785     }
786 }
787
788 var listAllStateHandler = {
789
790     onResult: function(client, context, result) {
791         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
792         var arrIdList = result.QueryInterface(Components.interfaces.nsISupportsArray);
793                 // Set the number of results
794         var count = arrIdList.Count();
795         
796         // Loop through the results, adding items to the list
797         for (i = 0; i < count; i++) {
798             var strlResult = arrIdList.QueryElementAt(i, Components.interfaces.nsISupportsArray);
799             var resultcount = strlResult.Count();
800             var arrDataPair = new Array();
801             arrDataPair[0] = strlResult.QueryElementAt(0, Components.interfaces.nsISupportsPRInt32);
802             arrDataPair[1] = strlResult.QueryElementAt(1, Components.interfaces.nsISupportsCString);
803             arrPartnerList1[i] = arrDataPair;
804
805           
806         }
807         if (!context)
808         {
809             const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
810
811             var popup = document.getElementById("state"); 
812             // a <menupopup> element
813             for (i=0;i<arrPartnerList1.length;i++){
814                 popup.menupopup.appendChild(createMenuItem_partner(arrPartnerList1[i][1],arrPartnerList1[i][0]));
815
816             }
817           //  popup.menupopup.selectedItem = popup.menupopup.firstChild;
818         }
819     
820     },
821     onFault: function (client, ctxt, fault) {
822
823     },
824
825     onError: function (client, ctxt, status, errorMsg) {
826
827     }
828 }
829
830
831 //function to get the list of All object
832 function getAllDocument(){
833     var branchobj = getPref();
834     setServerService('xmlrpc/object');
835     var xmlRpcClient = getXmlRpc();
836     arrPartnerList = [];
837     var end = document.getElementById("section")
838     length = end.itemCount
839     for (i = 0; i < length; i++) {
840         end.removeItemAt(0)
841     }
842     var cmdObjectList = document.getElementById("section");
843     var strDbName = xmlRpcClient.createType(xmlRpcClient.STRING,{});
844     strDbName.data = branchobj.getCharPref("serverdbname");
845     var struid = xmlRpcClient.createType(xmlRpcClient.INT,{});
846     struid.data = branchobj.getIntPref('userid');
847     var strpass = xmlRpcClient.createType(xmlRpcClient.STRING,{});
848     strpass.data = branchobj.getCharPref("password");
849     var strmethod = xmlRpcClient.createType(xmlRpcClient.STRING,{});
850     strmethod.data = 'list_alldocument';
851     var strobj = xmlRpcClient.createType(xmlRpcClient.STRING,{});
852     strobj.data = 'thunderbird.partner';
853     var strvalue = xmlRpcClient.createType(xmlRpcClient.STRING,{});
854     strvalue.data = ""
855     xmlRpcClient.asyncCall(listAllDocumentHandler,cmdObjectList,'execute',[ strDbName,struid,strpass,strobj,strmethod,strvalue ],6);
856 }
857
858 function getAllCountry(){
859     var branchobj = getPref();
860     setServerService('xmlrpc/object');
861     var xmlRpcClient = getXmlRpc();
862     arrPartnerList = [];
863     var strDbName = xmlRpcClient.createType(xmlRpcClient.STRING,{});
864     strDbName.data = branchobj.getCharPref("serverdbname");
865     var struid = xmlRpcClient.createType(xmlRpcClient.INT,{});
866     struid.data = branchobj.getIntPref('userid');
867     var strpass = xmlRpcClient.createType(xmlRpcClient.STRING,{});
868     strpass.data = branchobj.getCharPref("password");
869     var strmethod = xmlRpcClient.createType(xmlRpcClient.STRING,{});
870     strmethod.data = 'list_allcountry';
871     var strobj = xmlRpcClient.createType(xmlRpcClient.STRING,{});
872     strobj.data = 'thunderbird.partner';
873     var strvalue = xmlRpcClient.createType(xmlRpcClient.STRING,{});
874     strvalue.data = document.getElementById("country").value;
875     xmlRpcClient.asyncCall(listAllCountryHandler,null,'execute',[ strDbName,struid,strpass,strobj,strmethod,strvalue ],6);
876 }
877
878 function getAllState(){
879     var branchobj = getPref();
880     setServerService('xmlrpc/object');
881     var xmlRpcClient = getXmlRpc();
882     arrPartnerList1 = [];
883     var state = document.getElementById('state').menupopup;
884     while (state.firstChild) 
885      {
886         //The list is LIVE so it will re-index each call
887         state.removeChild(state.firstChild);
888     };
889
890
891     var strDbName = xmlRpcClient.createType(xmlRpcClient.STRING,{});
892     strDbName.data = branchobj.getCharPref("serverdbname");
893     var struid = xmlRpcClient.createType(xmlRpcClient.INT,{});
894     struid.data = branchobj.getIntPref('userid');
895     var strpass = xmlRpcClient.createType(xmlRpcClient.STRING,{});
896     strpass.data = branchobj.getCharPref("password");
897     var strmethod = xmlRpcClient.createType(xmlRpcClient.STRING,{});
898     strmethod.data = 'list_allstate';
899     var strobj = xmlRpcClient.createType(xmlRpcClient.STRING,{});
900     strobj.data = 'thunderbird.partner';
901     var strvalue = xmlRpcClient.createType(xmlRpcClient.STRING,{});
902     strvalue.data = document.getElementById("country").value;
903     xmlRpcClient.asyncCall(listAllStateHandler,null,'execute',[ strDbName,struid,strpass,strobj,strmethod,strvalue ],6);
904 }
905
906
907 //function to create array object to pass as an parameter for xmlrpc request
908 function dictcreation(value,checkboxobj){
909     var temp = xmlRpcClient.createType(xmlRpcClient.ARRAY,{});
910     var test = xmlRpcClient.createType(xmlRpcClient.ARRAY,{});
911     var strkey = xmlRpcClient.createType(xmlRpcClient.STRING,{});
912     strkey.data = value;
913     test.AppendElement(strkey);
914     temp.AppendElement(test);
915     var test1 = xmlRpcClient.createType(xmlRpcClient.ARRAY,{});
916     for(i=0;i<checkboxobj.length;i++){
917         var strvalue = xmlRpcClient.createType(xmlRpcClient.STRING,{});
918         strvalue.data = checkboxobj[i];
919         test1.AppendElement(strvalue);
920     }
921     if(checkboxobj.length>0){
922         temp.AppendElement(test1);
923     }
924     return temp;
925 }
926
927 //function to search and fillup section selection box
928 function createMenuItem(aLabel) {
929   const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
930   var item = document.createElementNS(XUL_NS, "menuitem"); // create a new XUL menuitem
931   item.setAttribute("label", aLabel[1]);
932   item.setAttribute("value", aLabel[0]);
933   return item;
934 }
935
936
937 var listinstallmodulehandler = {
938     onResult: function(client, context, result) {
939         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
940         var arrIdList = result.QueryInterface(Components.interfaces.nsISupportsArray);
941         var count = arrIdList.Count();
942         if (count > 0) 
943         { 
944             setmodule_install('yes')
945         }
946     
947     },
948     onFault: function (client, ctxt, fault) {
949         setmodule_install('no')
950     },
951
952     onError: function (client, ctxt, status, errorMsg) {
953         setmodule_install('no')
954     }
955 }
956
957 function module_install()
958 {
959     setmodule_install("no")
960     var branchobj = getPref();
961     setServerService('xmlrpc/object');
962     netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
963     var xmlRpcClient = getXmlRpc();
964     var strDbName = xmlRpcClient.createType(xmlRpcClient.STRING,{});
965     strDbName.data = branchobj.getCharPref("serverdbname");
966     var struid = xmlRpcClient.createType(xmlRpcClient.INT,{});
967     struid.data = branchobj.getIntPref('userid');
968     var strpass = xmlRpcClient.createType(xmlRpcClient.STRING,{});
969     strpass.data = branchobj.getCharPref("password");
970     var strmethod = xmlRpcClient.createType(xmlRpcClient.STRING,{});
971     strmethod.data = 'name_search';
972     var strobj = xmlRpcClient.createType(xmlRpcClient.STRING,{});
973     strobj.data = 'ir.model';
974     var strvalue = xmlRpcClient.createType(xmlRpcClient.STRING,{});
975     strvalue.data = 'thunderbird.partner';
976     xmlRpcClient.asyncCall(listinstallmodulehandler,null,'execute',[ strDbName,struid,strpass,strobj,strmethod, strvalue],6);
977 }
978
979
980
981 var listSearchContactHandler = {
982     onResult: function(client, context, result) {
983         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
984         var sendername = getSenderEmail();
985         var arrIdList = result.QueryInterface(Components.interfaces.nsISupportsArray);
986         var count = arrIdList.Count();
987         for (i = 0; i < count; i++) {
988             var strlResult = arrIdList.QueryElementAt(i, Components.interfaces.nsISupportsArray);
989             var strlSearchResult = strlResult.QueryElementAt(0, Components.interfaces.nsISupportsCString);
990             var strlSearchResultValue = strlResult.QueryElementAt(1, Components.interfaces.nsISupportsCString);
991             if(strlSearchResult=="partner_name"){
992                  setPartnerName(strlSearchResultValue);
993                  var t = getPartnerName();}
994
995             if(strlSearchResult=="contactname"){
996                  setSenderName(strlSearchResultValue);
997                  var t = getSenderName();}
998             
999             if(strlSearchResult=="street"){
1000                  setStreet(strlSearchResultValue);
1001                  var t = getStreet();}
1002             
1003             if(strlSearchResult=="street2"){
1004                  setStreet2(strlSearchResultValue);
1005                  var t = getStreet2();}
1006             
1007             if(strlSearchResult=="zip"){
1008                  setZipCode(strlSearchResultValue);
1009                  var t = getZipCode();}
1010
1011             if(strlSearchResult=="city"){
1012                  setCity(strlSearchResultValue);
1013                  var t = getCity();}
1014         
1015             if(strlSearchResult=="phone"){
1016                  setOfficenumber(strlSearchResultValue);
1017                  var t = getOfficenumber();}
1018         
1019             if(strlSearchResult=="fax"){
1020                  setFax(strlSearchResultValue);
1021                  var t = getFax();}
1022             
1023             if(strlSearchResult=="mobile"){
1024                  setMobilenumber(strlSearchResultValue);
1025                  var t = getMobilenumber();}
1026
1027            if(strlSearchResult=="email" && strlSearchResultValue!=''){
1028                  setSenderEmail(strlSearchResultValue);
1029                  var t = getSenderEmail();
1030                  window.open("chrome://openerp_plugin/content/address.xul", "", "chrome, resizable=yes");} 
1031     
1032             if(strlSearchResult=="email" && strlSearchResultValue==''){
1033                 alert("Contact is not available.");
1034             } 
1035
1036             if(strlSearchResult=="res_id"){
1037                  setResourceId(strlSearchResultValue);
1038                  var t = getResourceId();}
1039         }
1040     },
1041     onFault: function (client, ctxt, fault) {
1042
1043     },
1044
1045     onError: function (client, ctxt, status, errorMsg) {
1046
1047     }
1048
1049 }
1050
1051 var listSearchContactdetailHandler = {
1052     onResult: function(client, context, result) {
1053         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
1054      //  var sendername = getSenderEmail();
1055         var sendername = document.getElementById("txtemail").value
1056         var arrIdList = result.QueryInterface(Components.interfaces.nsISupportsArray);
1057         var count = arrIdList.Count();
1058         for (i = 0; i < count; i++) {
1059             var strlResult = arrIdList.QueryElementAt(i, Components.interfaces.nsISupportsArray);
1060             var strlSearchResult = strlResult.QueryElementAt(0, Components.interfaces.nsISupportsCString);
1061             var strlSearchResultValue = strlResult.QueryElementAt(1, Components.interfaces.nsISupportsCString);
1062             if(strlSearchResult=="email" && strlSearchResultValue=='')
1063             {
1064                 alert("Contact is not Available.")
1065                 document.getElementById("txtemail").value = sendername;
1066             } 
1067             if(strlSearchResult=="partner_name"){
1068                  document.getElementById("txtselectpartner").value =strlSearchResultValue;}
1069
1070             if(strlSearchResult=="contactname"){
1071                  document.getElementById("txtcontactname").value =strlSearchResultValue;}
1072             
1073             if(strlSearchResult=="street"){
1074                 document.getElementById("txtstreet").value =strlSearchResultValue;}
1075             
1076             if(strlSearchResult=="street2"){
1077                  document.getElementById("txtstreet2").value =strlSearchResultValue;}
1078             if(strlSearchResult=="zip"){
1079                  document.getElementById("txtzip").value =strlSearchResultValue;}
1080
1081             if(strlSearchResult=="city"){
1082                 document.getElementById("txtcity").value =strlSearchResultValue;}
1083             if(strlSearchResult=="phone"){
1084                  document.getElementById("txtoffice").value =strlSearchResultValue;}
1085         
1086             if(strlSearchResult=="fax"){
1087                  document.getElementById("txtfax").value =strlSearchResultValue;}
1088             
1089             if(strlSearchResult=="mobile"){
1090                  document.getElementById("txtmobile").value =strlSearchResultValue;}
1091
1092             if(strlSearchResult=="email"&& strlSearchResultValue!=''){
1093                  alert("Contact is Available.")
1094                  document.getElementById("txtemail").value =strlSearchResultValue;}
1095
1096             if(strlSearchResult=="res_id"){
1097                  setResourceId(strlSearchResultValue);
1098                  var t = getResourceId();}
1099
1100         }
1101     },
1102     onFault: function (client, ctxt, fault) {
1103
1104     },
1105
1106     onError: function (client, ctxt, status, errorMsg) {
1107
1108     }
1109
1110 }
1111
1112 function searchContactdetail()
1113 {
1114     var branchobj = getPref();
1115     setServerService('xmlrpc/object');
1116     netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
1117     arrFinalList = [];
1118     var xmlRpcClient = getXmlRpc();
1119     var cmbSearchList = document.getElementById('listSearchBox');
1120     var strDbName = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1121     strDbName.data = branchobj.getCharPref("serverdbname");
1122     var struid = xmlRpcClient.createType(xmlRpcClient.INT,{});
1123     struid.data = branchobj.getIntPref('userid');
1124     var strpass = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1125     strpass.data = branchobj.getCharPref("password");
1126     var strobj = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1127     strobj.data = 'thunderbird.partner';
1128     var strmethod = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1129     strmethod.data = 'search_contact';
1130     var strname = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1131     strname.data = document.getElementById("txtemail").value;
1132     xmlRpcClient.asyncCall(listSearchContactdetailHandler,cmbSearchList,'execute',[ strDbName,struid,strpass,strobj,strmethod,strname ],6);
1133 }
1134
1135 //xmlrpc request handler for getting the search results for the particular selected check box object
1136 var listSearchCheckboxHandler = {
1137     onResult: function(client, context, result) {
1138         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
1139         var arrMethodList = result.QueryInterface(Components.interfaces.nsISupportsArray);
1140                 // Set the number of results
1141         var count = arrMethodList.Count();
1142         var close=0;
1143         if(count == 0  && popup_display != "no"){
1144             alert("No Records Found");
1145             return false;
1146         }
1147         else if(count ==2 )
1148         {
1149             if (arrMethodList.QueryElementAt(0, Components.interfaces.nsISupportsCString)=="error")
1150             {
1151                 close =1;
1152             }
1153         }
1154         popup_display = "yes"
1155         // Loop through the results, adding items to the list
1156         var arr1 = new Array();
1157         var arr2 = new Array();
1158         var flag1 = 0;
1159         var flag2 = 0;
1160         var er ="";
1161         var er_val =new Array();
1162         for (i = 0; i < count; i++) 
1163         {
1164             if(i%2==0){
1165                 if (arrMethodList.QueryElementAt(i, Components.interfaces.nsISupportsCString)=="error")
1166                 {
1167                     er = arrMethodList.QueryElementAt(i, Components.interfaces.nsISupportsCString);
1168                     er_val[0] =arrMethodList.QueryElementAt(i+1, Components.interfaces.nsISupportsArray);
1169                     i +=1;
1170                     continue;
1171                 }
1172                 arr1[flag1] = arrMethodList.QueryElementAt(i, Components.interfaces.nsISupportsCString);
1173                 flag1++;
1174             }
1175             else{
1176                 arr2[flag2] = arrMethodList.QueryElementAt(i, Components.interfaces.nsISupportsArray);
1177                 flag2++;
1178             }
1179         }
1180         if (er)
1181         {
1182             var arrSearchList1 = new Array();
1183             for(j=0;j<er_val[0].Count();j++)
1184             {
1185                 var arrDataPair = new Array();
1186                 arrDataPair[0] = er_val[0].QueryElementAt(j, Components.interfaces.nsISupportsCString)
1187                 arrSearchList1[j]=arrDataPair;
1188             }
1189             alert( arrSearchList1 + "  Model not exists")
1190             if (close == 1)
1191             {
1192                 alert("No Records Found");
1193                 return false;
1194             }
1195         }
1196         for (i = 0; i < arr2.length; i++) {
1197             var arrSearchList1 = new Array();
1198             for(j=0;j<arr2[i].Count();j++){
1199                 var strlSearchResult = arr2[i].QueryElementAt(j, Components.interfaces.nsISupportsArray);
1200                 var resultcount = strlSearchResult.Count();
1201                 var arrDataPair = new Array();
1202                 arrDataPair[0] = strlSearchResult.QueryElementAt(0, Components.interfaces.nsISupportsPRInt32);
1203                 arrDataPair[1] = strlSearchResult.QueryElementAt(1, Components.interfaces.nsISupportsCString);
1204                 arrDataPair[2] = arr1[i];
1205                 arrSearchList1[j] = arrDataPair;
1206             }
1207             arrFinalList[i]=arrSearchList1;
1208         }
1209         if (context)
1210         {
1211
1212             var row_count = context.getRowCount();
1213             var cmbSearchList = document.getElementById('listSearchBox');
1214             for (i=0;i<row_count;i++)
1215             {
1216                 context.removeItemAt(0);
1217             }
1218             for (i=0;i<arrFinalList.length;i++)
1219             {
1220                 for(j=0;j<arrFinalList[i].length;j++){
1221                 //creates the dynamic listbox which shows the searched records for the selected object in checkbox
1222                     var listcell = document.createElement("listcell");
1223                     var listItem = document.createElement("listitem");
1224
1225                     var objectcharpref = getPref().getCharPref("object").split(',');
1226                     var imagecharpref = getPref().getCharPref("imagename").split(',');
1227                     var imagename = ''
1228                     for(k=0;k<objectcharpref.length;k++){
1229                         if(arr1[i] == objectcharpref[k]){
1230                             imagename = imagecharpref[k]
1231                         }
1232                     }
1233
1234                     listcell.setAttribute("image",imagename); // stores the image of the object
1235                     listcell.setAttribute("class","listcell-iconic");
1236                     listcell.setAttribute("width",12);
1237                     listcell.setAttribute("height",12);
1238                     listcell.setAttribute("label",arrFinalList[i][j][1]); //stores the name ofthe record
1239                     listItem.appendChild(listcell);
1240                     listItem.value = arrFinalList[i][j][0]; //stores the id of the record
1241                     listItem.label = arr1[i]; // stores the value of the object   
1242                     cmbSearchList.appendChild(listItem);
1243                 }
1244             }
1245         }
1246     },
1247
1248     onFault: function (client, ctxt, fault) {
1249
1250     },
1251
1252     onError: function (client, ctxt, status, errorMsg) {
1253
1254     }
1255 };
1256
1257 //function to search the records of selected checkbox object
1258 function searchCheckbox()
1259 {
1260     var checkboxlist = getnamesearch();
1261     if(checkboxlist.length == 0){
1262         alert("Please Select One or More Document");
1263         return false;
1264     }
1265     var branchobj = getPref();
1266     setServerService('xmlrpc/object');
1267     netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
1268     arrFinalList = [];
1269     var xmlRpcClient = getXmlRpc();
1270     var end = document.getElementById('listSearchBox').getRowCount();
1271     for(i=0; i< end; i++){
1272         document.getElementById('listSearchBox').removeItemAt(0);
1273     }
1274     var cmbSearchList = document.getElementById('listSearchBox');
1275     var strDbName = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1276     strDbName.data = branchobj.getCharPref("serverdbname");
1277     var struid = xmlRpcClient.createType(xmlRpcClient.INT,{});
1278     struid.data = branchobj.getIntPref('userid');
1279     var strpass = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1280     strpass.data = branchobj.getCharPref("password");
1281     var strmethod = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1282     strmethod.data = 'search_checkbox';
1283     var strname = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1284     strname.data = document.getElementById('txtvalueobj').value;
1285     var strobj = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1286     strobj.data = 'thunderbird.partner';
1287     var arrofarr = dictcreation(strname,checkboxlist);
1288     xmlRpcClient.asyncCall(listSearchCheckboxHandler,cmbSearchList,'execute',[ strDbName,struid,strpass,strobj,strmethod,arrofarr ],6);
1289 }
1290
1291 function searchContact()
1292 {
1293     var branchobj = getPref();
1294     setServerService('xmlrpc/object');
1295     netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
1296     arrFinalList = [];
1297     var xmlRpcClient = getXmlRpc();
1298     var cmbSearchList = document.getElementById('listSearchBox');
1299     var strDbName = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1300     strDbName.data = branchobj.getCharPref("serverdbname");
1301     var struid = xmlRpcClient.createType(xmlRpcClient.INT,{});
1302     struid.data = branchobj.getIntPref('userid');
1303     var strpass = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1304     strpass.data = branchobj.getCharPref("password");
1305     var strobj = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1306     strobj.data = 'thunderbird.partner';
1307     var strmethod = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1308     strmethod.data = 'search_contact';
1309     var strname = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1310     strname.data = getSenderEmail();
1311     
1312     xmlRpcClient.asyncCall(listSearchContactHandler,cmbSearchList,'execute',[ strDbName,struid,strpass,strobj,strmethod,strname ],6);
1313 }
1314
1315 //xmlrpc request handler for getting the list of partners
1316 var listPartnerHandler = {
1317
1318     onResult: function(client, context, result) {
1319         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
1320         var arrIdList = result.QueryInterface(Components.interfaces.nsISupportsArray);
1321                 // Set the number of results
1322         var count = arrIdList.Count();
1323         // Loop through the results, adding items to the list
1324         for (i = 0; i < count; i++) {
1325             var strlResult = arrIdList.QueryElementAt(i, Components.interfaces.nsISupportsArray);
1326             var resultcount = strlResult.Count();
1327             var arrDataPair = new Array();
1328             arrDataPair[0] = strlResult.QueryElementAt(0, Components.interfaces.nsISupportsPRInt32);
1329             arrDataPair[1] = strlResult.QueryElementAt(1, Components.interfaces.nsISupportsCString);
1330             arrPartnerList[i] = arrDataPair;
1331         }
1332         if (context)
1333         {
1334             var row_count = context.getRowCount();
1335             var cmdPartnerList = document.getElementById('listPartnerBox');
1336             for (i=0;i<row_count;i++)
1337             {
1338                 context.removeItemAt(0);
1339             }
1340             for (i=0;i<arrPartnerList.length;i++)
1341             {
1342                 var listcell = document.createElement("listcell");
1343                 var listItem = document.createElement("listitem");
1344                 listcell.setAttribute("label",arrPartnerList[i][1]);
1345                 listItem.appendChild(listcell);
1346                 listItem.value = arrPartnerList[i][0];
1347                 cmdPartnerList.appendChild(listItem);
1348             }
1349         }
1350     },
1351     onFault: function (client, ctxt, fault) {
1352
1353     },
1354
1355     onError: function (client, ctxt, status, errorMsg) {
1356
1357     }
1358 }
1359
1360 //function to get the list of partners
1361 function getPartnerList(){
1362     var branchobj = getPref();
1363     window.opener.document.getElementById('txtselectpartner').setAttribute('value','');
1364     setServerService('xmlrpc/object');
1365     var xmlRpcClient = getXmlRpc();
1366     arrPartnerList = [];
1367     var end = document.getElementById('listPartnerBox').getRowCount();
1368     for(i=0; i< end; i++){
1369         document.getElementById('listPartnerBox').removeItemAt(0);
1370     }
1371     var cmdPartnerList = document.getElementById('listPartnerBox');
1372     var strDbName = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1373     strDbName.data = branchobj.getCharPref("serverdbname");
1374     var struid = xmlRpcClient.createType(xmlRpcClient.INT,{});
1375     struid.data = branchobj.getIntPref('userid');
1376     var strpass = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1377     strpass.data = branchobj.getCharPref("password");
1378     var strmethod = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1379     strmethod.data = 'name_search';
1380     var strobj = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1381     strobj.data = 'res.partner';
1382     var strvalue = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1383     strvalue.data = document.getElementById('txtselectpartner').value;
1384     xmlRpcClient.asyncCall(listPartnerHandler,cmdPartnerList,'execute',[ strDbName,struid,strpass,strobj,strmethod,strvalue ],6);
1385 }
1386
1387 //function to create the xmlrpc supported variables for xmlrpc request
1388 function dictcontact(a,b){
1389     var temp = xmlRpcClient.createType(xmlRpcClient.ARRAY,{});
1390     for(i=0;i<a.length;i++){
1391         var strkey = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1392         strkey.data = a[i]
1393         var strvalue = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1394         strvalue.data = b[i]
1395         var test = xmlRpcClient.createType(xmlRpcClient.ARRAY,{});
1396         test.AppendElement(strkey);
1397         test.AppendElement(strvalue);
1398         temp.AppendElement(test);
1399     }
1400     return temp;
1401 }
1402
1403 //xmlrpc request handler for creating the record of mail
1404 var listArchiveHandler = {
1405     onResult: function(client, context, result) {
1406         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
1407         list_documents = document.getElementById('listSearchBox')
1408         var createId = result.QueryInterface(Components.interfaces.nsISupportsPRInt32);
1409         createId = parseInt(createId);
1410         if(createId==0)
1411         {
1412             alert("Mail is Already Pushed.");
1413         }
1414         else if (createId<0)
1415         {
1416             alert("sorry Mail is not Pushed.");
1417         
1418         }
1419     
1420     else if (createId>=1)
1421         {
1422             alert("Mail is Successfully Pushed.");
1423         }
1424     window.close();
1425
1426     },
1427     onFault: function (client, ctxt, fault) {
1428
1429     },
1430
1431     onError: function (client, ctxt, status, errorMsg) {
1432
1433     }
1434 }
1435
1436 //function to archive the mail content through xmlrpc request
1437 function upload_archivemail()
1438 {
1439     list_documents = document.getElementById('listSearchBox')
1440     var context = []
1441     var cnt = list_documents.selectedCount
1442     var ref_ids = "";
1443     var branchobj = getPref();
1444     setServerService('xmlrpc/object');
1445     netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
1446     var xmlRpcClient = getXmlRpc();
1447     var strDbName = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1448     strDbName.data = branchobj.getCharPref("serverdbname");
1449     var struids = xmlRpcClient.createType(xmlRpcClient.INT,{});
1450     struids.data = branchobj.getIntPref('userid');
1451     var strpass = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1452     strpass.data = branchobj.getCharPref("password");
1453     var strmethod = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1454     strmethod.data = 'history_message';
1455     var strobj = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1456     strobj.data = 'thunderbird.partner';
1457     var resobj = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1458
1459     for(i=0;i<cnt;i++)
1460     {   
1461         var object = list_documents.getSelectedItem(i);
1462         var eml_string = parse_eml();
1463         ref_ids += object.label;
1464         ref_ids += ",";
1465         ref_ids += object.value;
1466         if (i < cnt-1){ref_ids += ";";}
1467         
1468     }
1469     var a = ['ref_ids','message'];
1470     var b = [ref_ids, eml_string];
1471     var arrofarr = dictcontact(a,b);
1472
1473     xmlRpcClient.asyncCall(listArchiveHandler,null,'execute',[strDbName,struids,strpass,strobj,strmethod,arrofarr],6);
1474      
1475 }
1476
1477 var listArchiveDocumentHandler = {
1478     onResult: function(client, context, result) {
1479         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
1480         var createId = result.QueryInterface(Components.interfaces.nsISupportsPRInt32);
1481         var popup = document.getElementById("section").selectedItem; 
1482         alert("Document Created Successfully For " +" " + ":" + " "+ popup.label);
1483         window.close();
1484
1485     },
1486     onFault: function (client, ctxt, fault) {
1487
1488     },
1489
1490     onError: function (client, ctxt, status, errorMsg) {
1491
1492     }
1493 }
1494
1495 function create_archivemail(){
1496     var popup = document.getElementById("section").selectedItem; 
1497     // a <menupopup> element
1498
1499     if (String(popup) != "null"){
1500         object=popup.value;
1501         if (object == undefined) { alert("select At Least one Document !")}
1502         else{
1503         var branchobj = getPref();
1504         setServerService('xmlrpc/object');
1505         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
1506         var xmlRpcClient = getXmlRpc();
1507         var strDbName = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1508         strDbName.data = branchobj.getCharPref("serverdbname");
1509         var struids = xmlRpcClient.createType(xmlRpcClient.INT,{});
1510         struids.data = branchobj.getIntPref('userid');
1511         var strpass = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1512         strpass.data = branchobj.getCharPref("password");
1513         var strmethod = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1514         strmethod.data = 'process_email';
1515         var strobj = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1516         strobj.data = 'thunderbird.partner';
1517         var eml_string = parse_eml()
1518         var a = ['model', 'message'];
1519         var b = [object, eml_string];
1520         var arrofarr = dictcontact(a,b);
1521         xmlRpcClient.asyncCall(listArchiveDocumentHandler,null,'execute',[strDbName,struids,strpass,strobj,strmethod,arrofarr],6);
1522         //alert("Document Created Successfully For " +" " + ":" + " "+ popup.label);
1523         }
1524         //window.close();
1525     }
1526     else
1527     {
1528         alert(" select At Least one Document !")
1529     }
1530 }
1531
1532
1533 //xmlrpc request handler for creating a new contact
1534 var listCreateContactHandler = {
1535     onResult: function(client, context, result) {
1536         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
1537         var createId = result.QueryInterface(Components.interfaces.nsISupportsPRInt32);
1538         setContactId(createId);
1539         alert("Contact Created Successfully."); 
1540         window.close();
1541     },
1542     onFault: function (client, ctxt, fault) {
1543
1544     },
1545
1546     onError: function (client, ctxt, status, errorMsg) {
1547
1548     }
1549 }
1550
1551 var listUpdateContactHandler = {
1552     onResult: function(client, context, result) {
1553         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
1554         alert("Contact Update Successfully.");
1555         window.close();
1556         var partnerId = result.QueryInterface(Components.interfaces.nsISupportsPRInt32);
1557         setResourceId(partnerId);
1558         window.close();
1559     },
1560     onFault: function (client, ctxt, fault) {
1561
1562     },
1563
1564     onError: function (client, ctxt, status, errorMsg) {
1565
1566     }
1567 }
1568
1569 //function to create a new contact
1570 function createContact(){
1571     var branchobj = getPref();
1572     setServerService('xmlrpc/object');
1573     netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
1574     var xmlRpcClient = getXmlRpc();
1575     var strDbName = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1576     strDbName.data = branchobj.getCharPref("serverdbname");
1577     var struids = xmlRpcClient.createType(xmlRpcClient.INT,{});
1578     struids.data = branchobj.getIntPref('userid');
1579     var strpass = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1580     strpass.data = branchobj.getCharPref("password");
1581     var strmethod = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1582     strmethod.data = 'create_contact';
1583     var strobj = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1584     strobj.data = 'thunderbird.partner';
1585     var a = ['partner_id','name','street','street2','zip','city','country_id','state_id','phone','fax','mobile','email'];
1586     var b = [getPartnerId(),document.getElementById("txtname").value,document.getElementById("txtstreet").value,document.getElementById("txtstreet2").value,document.getElementById("txtzip").value, document.getElementById("txtcity").value,document.getElementById("country").value,document.getElementById("state").value,document.getElementById("txtoffice").value,document.getElementById("txtfax").value,document.getElementById("txtmobile").value,document.getElementById("txtemail").value];
1587     var arrofarr = dictcontact(a,b);
1588     xmlRpcClient.asyncCall(listCreateContactHandler,null,'execute',[strDbName,struids,strpass,strobj,strmethod,arrofarr],6);
1589 }
1590
1591 function UpdateContact(){
1592     var branchobj = getPref();
1593     setServerService('xmlrpc/object');
1594     netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
1595     var xmlRpcClient = getXmlRpc();
1596     var strDbName = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1597     strDbName.data = branchobj.getCharPref("serverdbname");
1598     var struids = xmlRpcClient.createType(xmlRpcClient.INT,{});
1599     struids.data = branchobj.getIntPref('userid');
1600     var strpass = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1601     strpass.data = branchobj.getCharPref("password");
1602     var strmethod = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1603     strmethod.data = 'update_contact';
1604     var strobj = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1605     strobj.data = 'thunderbird.partner';
1606     var a = ['res_id','partner_id','name','street','street2','zip','city','country_id','state_id','phone','fax','mobile','email'];
1607     var b = [getResourceId(),document.getElementById("txtselectpartner").value,document.getElementById("txtcontactname").value,document.getElementById("txtstreet").value,document.getElementById("txtstreet2").value,document.getElementById("txtzip").value, document.getElementById("txtcity").value,document.getElementById("country").value,document.getElementById("state").value,document.getElementById("txtoffice").value,document.getElementById("txtfax").value,document.getElementById("txtmobile").value,document.getElementById("txtemail").value];
1608     var arrofarr = dictcontact(a,b);
1609     xmlRpcClient.asyncCall(listUpdateContactHandler,null,'execute',[strDbName,struids,strpass,strobj,strmethod,arrofarr],6);
1610 }
1611
1612 //xmlrpc request handler for creating a attachment record
1613 var listAttachHandler = {
1614     onResult: function(client, context, result) {
1615         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
1616         var createId = result.QueryInterface(Components.interfaces.nsISupportsPRInt32);
1617
1618     },
1619     onFault: function (client, ctxt, fault) {
1620
1621     },
1622
1623     onError: function (client, ctxt, status, errorMsg) {
1624
1625     }
1626 }
1627
1628
1629 //function to encode the string into base64
1630 var base64chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split("");
1631 function base64_encode (s)
1632  {
1633    // the result/encrypted string, the padding string, and the pad count
1634    var r = ""; var p = ""; var c = s.length % 3;
1635
1636    // add a right zero pad to make this string a multiple of 3 characters
1637    if (c > 0) { for (; c < 3; c++) { p += '='; s += "\0"; } }
1638
1639    // increment over the length of the string, three characters at a time
1640    for (c = 0; c < s.length; c += 3) {
1641
1642      // we add newlines after every 76 output characters, according to the MIME specs
1643      if (c > 0 && (c / 3 * 4) % 76 == 0) { r += "\r\n"; }
1644
1645      // these three 8-bit (ASCII) characters become one 24-bit number
1646      var n = (s.charCodeAt(c) << 16) + (s.charCodeAt(c+1) << 8) + s.charCodeAt(c+2);
1647
1648      // this 24-bit number gets separated into four 6-bit numbers
1649      n = [(n >>> 18) & 63, (n >>> 12) & 63, (n >>> 6) & 63, n & 63];
1650
1651      // those four 6-bit numbers are used as indices into the base64 character list
1652      r += base64chars[n[0]] + base64chars[n[1]] + base64chars[n[2]] + base64chars[n[3]];
1653
1654      // add the actual padding string, after removing the zero pad
1655    } return r.substring(0, r.length - p.length) + p;
1656  }
1657
1658 //function to encode the string into base64
1659 var keyStr = "ABCDEFGHIJKLMNOP" +
1660                 "QRSTUVWXYZabcdef" +
1661                 "ghijklmnopqrstuv" +
1662                 "wxyz0123456789+/" +
1663                 "="+"-_.!~*'()";
1664
1665 function encode64(input) {
1666 var output = "";
1667 var chr1, chr2, chr3 = "";
1668 var enc1, enc2, enc3, enc4 = "";
1669 var i = 0;
1670
1671 do {
1672  chr1 = input.charCodeAt(i++);
1673  chr2 = input.charCodeAt(i++);
1674  chr3 = input.charCodeAt(i++);
1675
1676  enc1 = chr1 >> 2;
1677  enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
1678  enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
1679  enc4 = chr3 & 63;
1680
1681  if (isNaN(chr2)) {
1682     enc3 = enc4 = 64;
1683  } else if (isNaN(chr3)) {
1684     enc4 = 64;
1685  }
1686
1687  output = output +
1688     keyStr.charAt(enc1) +
1689     keyStr.charAt(enc2) +
1690     keyStr.charAt(enc3) +
1691     keyStr.charAt(enc4);
1692  chr1 = chr2 = chr3 = "";
1693  enc1 = enc2 = enc3 = enc4 = "";
1694 } while (i < input.length);
1695
1696 return output;
1697 }
1698
1699
1700 //function to read the contents of the attachment files from the temp folder
1701 function createInstance(name,test){
1702     var encoded_string = '';
1703     var file_name = ''
1704
1705     for(i=0;i<test.length;i++){
1706         var stream = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream);
1707         stream.init(test[i], 0x01, 00004, 0);
1708         var bstream = Components.classes["@mozilla.org/binaryinputstream;1"].createInstance(Components.interfaces.nsIBinaryInputStream);
1709         bstream.setInputStream(stream);
1710         var r = new Array();
1711             var fileContents = bstream.readByteArray(bstream.available(),r);
1712         bstream.close();
1713         var printstring = '';
1714         for(j=0;j<fileContents.length;j++)
1715         {
1716             printstring += String.fromCharCode(fileContents[j]);
1717         }
1718         encoded_string += encode64(printstring)+',';
1719         file_name += name[i]+',';
1720         test[i].remove(true);
1721     }
1722     encoded_string = encoded_string.substring(0,encoded_string.length-1);
1723     file_name = file_name.substring(0,file_name.length-1);
1724     getPref().setCharPref('displayName',file_name);
1725     getPref().setCharPref('attachmentdata',encoded_string);
1726
1727
1728 }
1729
1730 //xmlrpc request handler for handling the login information
1731 function check_module_install(count){
1732     if (getmodule_install() == "no")
1733     {
1734         if (count <= 0){ return false; }
1735         count = count - 1;
1736         return check_module_install(count)
1737     }
1738     return true
1739 }
1740     
1741 var listLoginHandler = {
1742     onResult: function(client, context, result) {
1743         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
1744         var login = result.QueryInterface(Components.interfaces.nsISupportsPrimitive)
1745         if(login.type == 12){
1746             login = result.QueryInterface(Components.interfaces.nsISupportsPRInt32)
1747             setUserId(login.data);
1748             module_install();
1749             alert('Successfully Login To OpenERP.');
1750             window.close();
1751         }
1752         else{
1753             alert("Login Failed");
1754         }
1755     },
1756     onFault: function (client, ctxt, fault) {
1757
1758     },
1759
1760     onError: function (client, ctxt, status, errorMsg) {
1761         alert("Database does not Exist!\n\n Please specify proper database name.");
1762     }
1763 }
1764
1765
1766 //function to check the login information
1767 function testConnection(){
1768     if (getconnect_server() == "false")
1769     {
1770         alert("Server is Not Running...Please check it!!"+" "+getServer())
1771         return false;
1772     }
1773     if (getDBList()=="false")
1774     {
1775         if (document.getElementById('DBlist_text').value =='')
1776         {
1777             alert("You Must Enter Database Name.");
1778             return false;
1779         }
1780         setDbName(document.getElementById('DBlist_text').value);
1781     }
1782     else
1783     {
1784         if (document.getElementById('DBlist').value == 0 || document.getElementById('DBlist').value =="--select--")
1785         {
1786             alert("You Must Select Database Name.");
1787             return false;
1788         }
1789         setDbName(document.getElementById('DBlist').value);
1790     }
1791     var branchobj = getPref();
1792     setServer(document.getElementById('txturl').value);
1793         var s = document.getElementById('txturl').value;
1794     var a =s.split(':');
1795     setPort(a[a.length-1]);
1796     setUsername(document.getElementById('txtusername').value);
1797     setPassword(document.getElementById('txtpassword').value);
1798     setServerService('xmlrpc/common');
1799     netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
1800     var xmlRpcClient = getXmlRpc();
1801     var strDbName = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1802     strDbName.data = getPref().getCharPref('serverdbname');
1803     var strusername = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1804     strusername.data = getPref().getCharPref('username');
1805     var strpass = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1806     strpass.data = getPref().getCharPref('password');
1807     xmlRpcClient.asyncCall(listLoginHandler,null,'login',[strDbName,strusername,strpass],3);
1808     
1809 }
1810
1811 function testConnection_web(){
1812     var branchobj = getPref();
1813     weburl = getWebServerURL();
1814     var messenger = Components.classes["@mozilla.org/messenger;1"].createInstance();
1815     messenger = messenger.QueryInterface(Components.interfaces.nsIMessenger);
1816     messenger.launchExternalURL(weburl);
1817     
1818 }
1819
1820 //xmlrpc request handler for handling the login information
1821 var listcreateLoginHandler = {
1822     onResult: function(client, context, result) {
1823         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
1824         var login = result.QueryInterface(Components.interfaces.nsISupportsPrimitive)
1825         setconnect_server("true")       
1826         if(login.type == 12){
1827             login = result.QueryInterface(Components.interfaces.nsISupportsPRInt32)
1828             setUserId(login.data);
1829         }
1830         else{
1831             alert("Login Failed.");
1832         }
1833     },
1834     onFault: function (client, ctxt, fault) {
1835         
1836     },
1837
1838     onError: function (client, ctxt, status, errorMsg) {
1839         setconnect_server("false")
1840     }
1841 }
1842
1843 //function to check the login information
1844 function createConnection(){
1845     setconnect_server("true");
1846     var branchobj = getPref();
1847     setServerService('xmlrpc/common');
1848     netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
1849     var xmlRpcClient = getXmlRpc();
1850     var strDbName = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1851     strDbName.data = getPref().getCharPref('serverdbname');
1852     var strusername = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1853     strusername.data = getPref().getCharPref('username');
1854     var strpass = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1855     strpass.data = getPref().getCharPref('password');
1856     xmlRpcClient.asyncCall(listcreateLoginHandler,null,'login',[strDbName,strusername,strpass],3);
1857 }
1858
1859 //xmlrpc request handler for handling the partner information
1860 var listCreatePartnerHandler = {
1861     onResult: function(client, context, result) {
1862         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
1863         var createId = result.QueryInterface(Components.interfaces.nsISupportsPRInt32);
1864         setPartnerId(createId);
1865         txtselectpartner = document.getElementById('txtselectpartner')
1866         if(typeof(createId.data) == 'number' && createId!=0){
1867          window.opener.document.getElementById('txtselectpartner').setAttribute('value',txtselectpartner.value);
1868             window.close();
1869         }
1870         if(createId == 0){
1871             alert("Partner Already Exist.");
1872         }
1873     },
1874     onFault: function (client, ctxt, fault) {
1875
1876     },
1877
1878     onError: function (client, ctxt, status, errorMsg) {
1879
1880     }
1881 }
1882 //function to create the tiny partner object
1883 function createPartner(){
1884     var branchobj = getPref();
1885     txtselectpartner = document.getElementById('txtselectpartner')
1886     setServerService('xmlrpc/object');
1887     netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
1888     var xmlRpcClient = getXmlRpc();
1889     var strDbName = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1890     strDbName.data = branchobj.getCharPref("serverdbname");
1891     var struids = xmlRpcClient.createType(xmlRpcClient.INT,{});
1892     struids.data = branchobj.getIntPref('userid');
1893     var strpass = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1894     strpass.data = branchobj.getCharPref("password");
1895     var strmethod = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1896     strmethod.data = 'create_partner';
1897     var strobj = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1898     strobj.data = 'thunderbird.partner';
1899     if(document.getElementById('txtselectpartner').value ==''){
1900         alert("You Must Enter Partner Name.");
1901         return false;
1902     }
1903     setPartnerId(txtselectpartner.value)
1904     var a = ['partner_id','name'];
1905     var b = [getPartnerId(),txtselectpartner.value];
1906     var arrofarr = dictcontact(a,b);
1907     xmlRpcClient.asyncCall(listCreatePartnerHandler,null,'execute',[strDbName,struids,strpass,strobj,strmethod,arrofarr],6);
1908 }
1909 //xmlrpc request handler for handling the object information
1910 var listSearchDocumentHandler = {
1911     onResult: function(client, context, result) {
1912         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
1913         var searchResult = result.QueryInterface(Components.interfaces.nsISupportsPRInt32);
1914         if(searchResult.data == 0){
1915             alert("Document Does Not Exist.");
1916             return false;
1917         }
1918         var objvalue = getPref().getCharPref("listobject");
1919         var objectvalue = getPref().getCharPref("object");
1920         var imagevalue = getPref().getCharPref("imagename");
1921
1922         var objcharpref = getPref().getCharPref("listobject").split(',');
1923         var objectcharpref = getPref().getCharPref("object").split(',');
1924         var imagecharpref = getPref().getCharPref("imagename").split(',');
1925
1926
1927         if(objectcharpref.indexOf(document.getElementById("txtobject").value) != -1){
1928             alert("Document already in List.");
1929         }
1930         else{
1931             var listItem = document.createElement("listitem");
1932             var listcell1 = document.createElement("listcell");
1933             var listcell2 = document.createElement("listcell");
1934             var listcell3 = document.createElement("listcell");
1935             listcell1.setAttribute("label",document.getElementById("txtobj").value);
1936             listcell2.setAttribute("label",document.getElementById("txtobject").value);
1937             listcell3.setAttribute("image",'file://'+document.getElementById("txtimagename").value);
1938             listcell3.setAttribute("class","listcell-iconic")
1939             listcell3.setAttribute("width",16)
1940             listcell3.setAttribute("height",16)
1941             listItem.appendChild(listcell1);
1942             listItem.appendChild(listcell2);
1943             listItem.appendChild(listcell3);
1944             document.getElementById("listObjectListBox").appendChild(listItem)
1945             if(getPref().getCharPref("object")!=''){
1946                 getPref().setCharPref("listobject",objvalue+','+document.getElementById("txtobj").value);
1947                 getPref().setCharPref("object",objectvalue+','+document.getElementById("txtobject").value);
1948                 getPref().setCharPref("imagename",imagevalue+','+"file://"+document.getElementById("txtimagename").value);
1949             }
1950             else{
1951                 getPref().setCharPref("listobject",document.getElementById("txtobj").value);
1952                 getPref().setCharPref("object",document.getElementById("txtobject").value);
1953                 getPref().setCharPref("imagename","file://"+document.getElementById("txtimagename").value);
1954             }
1955         }
1956     },
1957     onFault: function (client, ctxt, fault) {
1958
1959     },
1960
1961     onError: function (client, ctxt, status, errorMsg) {
1962
1963     }
1964 }
1965
1966 //function to search the tiny objects for configuration settings
1967 function searchDocument(){
1968     var branchobj = getPref();
1969     setServerService('xmlrpc/object');
1970     netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
1971     var xmlRpcClient = getXmlRpc();
1972     var strDbName = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1973     strDbName.data = branchobj.getCharPref("serverdbname");
1974     var struids = xmlRpcClient.createType(xmlRpcClient.INT,{});
1975     struids.data = branchobj.getIntPref('userid');
1976     var strpass = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1977     strpass.data = branchobj.getCharPref("password");
1978     var strmethod = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1979     strmethod.data = 'search_document';
1980     var strobj = xmlRpcClient.createType(xmlRpcClient.STRING,{});
1981     strobj.data = 'thunderbird.partner';
1982     if(document.getElementById('txtobj').value =='' ){
1983         alert("You Must Enter Document.");
1984         return false;
1985     }
1986     if(document.getElementById('txtobject').value =='' ){
1987         alert("You Must Enter Document Name.");
1988         return false;
1989     }
1990     var a = ['model'];
1991     var b = [document.getElementById('txtobject').value];
1992     var arrofarr = dictcontact(a,b);
1993     xmlRpcClient.asyncCall(listSearchDocumentHandler,null,'execute',[strDbName,struids,strpass,strobj,strmethod,arrofarr],6);
1994 }
1995
1996 //xmlrpc request handler for list of search object exist in database or not.
1997 var listsearchAttachmentHandler = {
1998     onResult: function(client, context, result) {
1999         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
2000         var objectlist = result.QueryInterface(Components.interfaces.nsISupportsCString);
2001         getPref().setCharPref('tempobject',objectlist)
2002         //document.getElementById("txtvalueobj").value= getSenderEmail();
2003         var checkbox = document.getElementById("checkbox-dynamic");
2004         
2005         var object = preferenceBranch.getCharPref("listobject").split(',');
2006         var obj = preferenceBranch.getCharPref("tempobject").split(',');
2007         var imagelist = preferenceBranch.getCharPref("imagename").split(',');
2008
2009         count = 0
2010         if (object[0]!=''){
2011             for(var i=0; i<object.length; i++){
2012                 if (obj[i] == "null")
2013                 {
2014                     continue
2015                 }
2016
2017                 if(count%3==0){
2018                     var vbox = document.createElement("hbox");
2019                 }
2020                 count += 1
2021                 var hbox = document.createElement("vbox");
2022                 var checkbox1 = document.createElement("checkbox");
2023             
2024                 checkbox1.setAttribute("label",object[i]);
2025                 checkbox1.setAttribute("id","cbx"+(i+1));
2026                 checkbox1.setAttribute("width",150)
2027                 if (obj[i] =="res.partner.address")
2028                 {
2029                     checkbox1.setAttribute("checked",true);
2030                 }
2031                 if(i==0){
2032                     checkbox1.setAttribute("checked",true);
2033                 }
2034
2035                 var image1 = document.createElement("image");
2036                 image1.setAttribute("src",imagelist[i]);
2037                 image1.setAttribute("width",16)
2038                 image1.setAttribute("height",16)
2039
2040                 vbox.appendChild(image1);
2041                 hbox.appendChild(checkbox1);
2042                 vbox.appendChild(hbox);
2043                 checkbox.appendChild(vbox);
2044             }
2045         }
2046         setTimeout("getAllDocument()", 0)
2047         exis_grp = document.getElementById("existsobjectgroup")
2048         new_grp = document.getElementById("newobjectgroup")
2049
2050         new_grp.height = parseInt(parseInt(new_grp.height) + parseInt((count /3) * 23.5))
2051         win = document.getElementById("pluginwindows").setAttribute("height",1000)
2052
2053     },
2054     onFault: function (client, ctxt, fault) {
2055
2056     },
2057
2058     onError: function (client, ctxt, status, errorMsg) {
2059
2060     }
2061 }
2062
2063 //function to create a new attachment record
2064 function listSearchDocumentAttachment(){
2065     var branchobj = getPref();
2066     setServerService('xmlrpc/object');
2067     netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
2068     var xmlRpcClient = getXmlRpc();
2069     var strDbName = xmlRpcClient.createType(xmlRpcClient.STRING,{});
2070     strDbName.data = branchobj.getCharPref("serverdbname");
2071     var struids = xmlRpcClient.createType(xmlRpcClient.INT,{});
2072     struids.data = branchobj.getIntPref('userid');
2073     var strpass = xmlRpcClient.createType(xmlRpcClient.STRING,{});
2074     strpass.data = branchobj.getCharPref("password");
2075     var strmethod = xmlRpcClient.createType(xmlRpcClient.STRING,{});
2076     strmethod.data = 'search_document_attachment';
2077     var strobj = xmlRpcClient.createType(xmlRpcClient.STRING,{});
2078     strobj.data = 'thunderbird.partner';
2079     var resobj = xmlRpcClient.createType(xmlRpcClient.STRING,{});
2080     var popup = document.getElementById("section").selectedItem; // a <menupopup> element
2081     object=popup.value;
2082     resobj.data = object;
2083     var a = ['object'];
2084     var b = [getPref().getCharPref("object")];
2085     var arrofarr = dictcontact(a,b);
2086     xmlRpcClient.asyncCall(listsearchAttachmentHandler,null,'execute',[strDbName,struids,strpass,strobj,strmethod,arrofarr],6);
2087 }
2088
2089
2090 //function to create a new attachment record
2091
2092 function win_close()
2093 {
2094     var fpath =""
2095     if(navigator.userAgent.indexOf('Linux')!= -1){
2096         fpath ="/tmp/"
2097     }
2098     else if(navigator.userAgent.indexOf('Win')!= -1){
2099         fpath ="C:\\"
2100     }
2101     else if(navigator.userAgent.indexOf('Mac OS X')!= -1){ 
2102         fpath ="/tmp/"
2103     } 
2104     try
2105       {
2106         name = fpath + getFileName() +".eml"
2107
2108         var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
2109         file.initWithPath( name );
2110         file.remove(true);
2111         window.close();
2112       }
2113     catch(err)
2114       {
2115         window.close();
2116       }
2117 }
2118
2119 function attachmentWidnowOpen(msg)
2120 {
2121
2122         if (msg=="create")
2123         {
2124             var popup = document.getElementById("section").selectedItem; // a <menupopup> element
2125             if (String(popup) != "null"){
2126                 object=popup.value;
2127                 if (object=="" || object == undefined) { alert("select at least one document !")}
2128                 else{
2129                     create_archivemail()
2130                 }
2131             }
2132             else
2133             {
2134                 alert("select at least one Document !")
2135             }
2136         }
2137         else if (msg=="upload")
2138         {   
2139             if(document.getElementById('listSearchBox').selectedItem)
2140             {   
2141                 upload_archivemail()
2142             }
2143             else{
2144                 alert("Please select at least one record");
2145             }
2146         }
2147 }