webglade

JavaScript library to dynamically create XUL GUI from Glade XML files
git clone https://logand.com/git/webglade.git/
Log | Files | Refs | README | LICENSE

mab.js (25088B)


      1 /**
      2 *
      3 *
      4 * @FileName: mab.js
      5 * @$LastChangedDate: 2004-07-16 17:49:47 +0200 (Fri, 16 Jul 2004) $
      6 * @Author: Fabio Serra AKA Faser - faser@faser.net
      7 * @Copyright: Fabio Serra
      8 * @Licenze: MPL 1.1
      9 *
     10 */
     11 
     12 
     13 //Main
     14 function main() {
     15 	//Initialize global Search ToolBar that have to mantain the consistence between
     16 	//the various menuitem in the search toolbar
     17 	myProductLineController = new ProductLineController();
     18 	myProductLineController.update();
     19 
     20 	//Initialize global Display Controller. Display Controller visualize the
     21 	//XML Mab Document (XMDManager) in the tree and in the left panels
     22 	myDisplayController = new DisplayController();
     23 
     24 	//This  global objetc mantain the list of all opened document
     25 	//and display them in the windows menubar item.
     26 	myDocOpened = new DocOpenManager();
     27 
     28 	//Save searches made in this session
     29 	mySearchHistory = new SearchHistory();
     30 
     31 	//Main ProgressMeter. I have to put the reference here in a global var because
     32 	//in some circumstance when ProgressBar class is called lost the reference to the progressmeter element
     33 	//To investigate.
     34 	guiMeter = document.getElementById("meter");
     35 
     36 	//Focus on Search textbox
     37 	window.focus();
     38 	document.getElementById('find-text').focus();
     39 
     40 	//If MAB is running from remote disable some buttons
     41 	if(MAB_RUN == "remote") {
     42 		var broadcaster = document.getElementById("isMabRemote");
     43 		broadcaster.setAttribute("disabled","true");
     44 	}
     45 
     46 
     47 }
     48 
     49 //Start a new search
     50 function newSearch() {
     51 	var searchType = myDisplayController.getSearchPreference();
     52 	var requestedRecord = myDisplayController.getRecordPreference();
     53 	var recordForPage = 10;
     54 	var requestPage = requestedRecord/recordForPage;
     55 
     56 	//Object to get the first query string
     57 	var myQueryStringBuilder = new QueryStringBuilder(myProductLineController);
     58 	var qString = myQueryStringBuilder.createQueryString(1,searchType);
     59 
     60 	if(!qString) {
     61 		return false;
     62 	} else {
     63 		var mabRequestType = "default";
     64 		var mySearchController = new SearchController(mabRequestType,requestPage);
     65 		var nrThread = 0;
     66 		mySearchController.search(qString,nrThread);
     67 		return true;
     68 	}
     69 }
     70 
     71 //Get more products using the last search criteria
     72 function nextRecord() {
     73 	var pagesAvailable = mySearchHistory.getPagesAvailable();
     74 	if( pagesAvailable < 1) {
     75 		alert("No more products available");
     76 		return false;
     77 	}
     78 
     79 	var searchType = myDisplayController.getSearchPreference();
     80 	var requestedRecord = myDisplayController.getRecordPreference();
     81 	var recordForPage = 10;
     82 	var requestPage = requestedRecord/recordForPage;
     83 
     84 	if(pagesAvailable < requestPage) {requestPage = pagesAvailable;}
     85 
     86 
     87 	var mabRequestType = "default";
     88 	var mySearchController = new SearchController(mabRequestType,requestPage);
     89 	var qString = mySearchHistory.lastURL;
     90 	var pageToStart = mySearchHistory.lastPage + 1;
     91 	var newQString = mySearchController.setCurrentPage(qString,pageToStart)
     92 
     93 	//Check if searchType has been modified respect the previous search
     94 	var oldSearchType = mySearchController.getQueryParam(newQString,"type");
     95 	if(searchType != oldSearchType) {
     96 		newQString = mySearchController.setQueryParam(newQString,"type",searchType);
     97 	}
     98 	var nrThread = 0;
     99 	mySearchController.search(newQString,nrThread);
    100 	return true;
    101 }
    102 
    103 //Retrieve and/or refresh all info about the selected products
    104 function getComment(){
    105 	var myXMDManager = myDocOpened.getCurrentDocument();
    106 	var rows = myDisplayController.getAllSelectedRowIndex();
    107 
    108 	if(rows.length == 0) {
    109 		alert("No rows selected.");
    110 		return false;
    111 	}
    112 
    113 	//Create asin list grouped by locale
    114 	var asinList = {};
    115 	var pk,node, locale,amazAsin;
    116 	for(var i=0; i< rows.length; i++) {
    117 		pk = myDisplayController.getRowPrimaryKey(rows[i]);
    118 		if(pk) {
    119 			node = myXMDManager.getNodeDetail(pk);
    120 			if(node) {
    121 				locale =  myXMDManager.getSingleElement(node,"MABLocale");
    122 				amazAsin = myXMDManager.getSingleElement(node,"Asin");
    123 
    124 				if(!locale || !amazAsin) {continue;}
    125 
    126 				if(typeof asinList[locale] == "undefined") {
    127 					asinList[locale] = new Array();
    128 				}
    129 
    130 				asinList[locale].push(amazAsin);
    131 			}
    132 		}
    133 	}
    134 
    135 	//ok, now call asinSearch
    136 	var res = asinSearch(asinList);
    137 	return res;
    138 }
    139 
    140 function asinSearch(asinList) {
    141 
    142 	var query = "";
    143 	var list = "";
    144 	var qString = "";
    145 	var countItem = 0;
    146 	var nrThread = 0;
    147 	var done = false;
    148 	var mySearchController;
    149 	var mabRequestType = "asin";
    150 	for(var loc in asinList) {
    151 		qString = AWSURL[loc]+'?t='+ASSID[loc]+'&dev-t='+DEVT+'&type=heavy&f=xml&locale='+loc+'&AsinSearch=';
    152 		countItem = 1;
    153 
    154 		for(var i=0; i < asinList[loc].length;i++) {
    155 			list += asinList[loc][i];
    156 			if(countItem % 10 == 0 || countItem == asinList[loc].length) {
    157 				query = qString + list;
    158 				//Short term fix for japanese site
    159 				if(loc == "jp") {query += '&__mk_ja_JP=%E3%82%AB%E3%82%BF%E3%82%AB%E3%83%8A';}
    160 				mySearchController = new SearchController(mabRequestType,1);
    161 				mySearchController.search(query,nrThread);
    162 				list = "";
    163 				query = "";
    164 				done = true;
    165 			} else {
    166 				list += ","
    167 			}
    168 
    169 			countItem++;
    170 		}
    171 	}
    172 	//Asin List is empty and no asinSearch has been made?
    173 	return done;
    174 }
    175 
    176 //Reload all info about the selected products
    177 function reload() {
    178 	getComment();
    179 }
    180 
    181 
    182 //Reload all expired products
    183 function reloadExpired() {
    184 	var myXMDManager = myDocOpened.getCurrentDocument();
    185 	if(!myXMDManager) {return false;}
    186 	var asinList = myXMDManager.getAllExpiredProducts(EXPIRED_SHORT);
    187 	var expired = false
    188 	for(var p in asinList) {
    189 		if(asinList[p].length > 0) {
    190 			expired = true;
    191 			break;
    192 		}
    193 	}
    194 
    195 	if(!expired) {
    196 		alert("There are not expired products to reload");
    197 		return false;
    198 	} else {
    199 		return asinSearch(asinList);
    200 	}
    201 
    202 }
    203 
    204 
    205 //Get Similar Products
    206 function getSimilarProducts() {
    207 	var myXMDManager = myDocOpened.getCurrentDocument();
    208 	var rows = myDisplayController.getAllSelectedRowIndex();
    209 
    210 	if(rows.length == 0) {
    211 		alert("No rows selected.");
    212 		return false;
    213 	}
    214 
    215 	//Create asin list of similar products grouped by locale
    216 	var asinList = {};
    217 	var tmpList = {};
    218 	var item, result;
    219 	var retry = 0;
    220 	var pk, node, locale, amazAsin, testReviews;
    221 	var i, j = 0;
    222 	for(i=0; i< rows.length; i++) {
    223 		pk = myDisplayController.getRowPrimaryKey(rows[i]);
    224 
    225 		if(pk) {
    226 			node = myXMDManager.getNodeDetail(pk);
    227 			if(node) {
    228 
    229 				locale =  myXMDManager.getSingleElement(node,"MABLocale");
    230 				amazAsin = myXMDManager.getArrayElement(node,"Product");
    231 
    232 				if(!locale) {continue;}
    233 				//Maybe we can't find the similar products because we don't have loaded
    234 				//an heavy XML
    235 				if(amazAsin.length == 0) {
    236 					item = myXMDManager.getSingleElement(node,"Asin");
    237 					testReviews = myXMDManager.getSingleElement(node,"Reviews");
    238 					//Load all xml
    239 					if(!testReviews) {
    240 						tmpList[locale] = new Array();
    241 						tmpList[locale][0] = item;
    242 						result = asinSearch(tmpList);
    243 					} else {
    244 						continue;
    245 					}
    246 				} else {
    247 					if(typeof asinList[locale] == "undefined") {
    248 						asinList[locale] = new Array();
    249 					}
    250 
    251 					for(j=0;j<amazAsin.length;j++) {
    252 						asinList[locale].push(amazAsin[j]);
    253 					}
    254 				}
    255 			}
    256 		}
    257 	}
    258 
    259 	var res = asinSearch(asinList);
    260 	return res;
    261 }
    262 
    263 //Create a new document
    264 function newDoc() {
    265 	var myXMDManager = new XMDManager();
    266 
    267 	//Add new doc to windows list
    268 	myDocOpened.addDoc(myXMDManager);
    269 	myDisplayController.clearAll();
    270 	return myXMDManager;
    271 }
    272 
    273 //Load a previuos opened or created document that is listed in the windows menu bar
    274 function loadDoc(docCounter) {
    275 	var myXMDManager = myDocOpened.getDocument(docCounter);
    276 	if(myXMDManager) {
    277 		myDocOpened.checkDoc(docCounter);
    278 		myDisplayController.clearAll();
    279 		myDisplayController.buildTree(myXMDManager);
    280 		return true;
    281 	}else{
    282 		alert("An error has occured loading the document");
    283 		return false;
    284 	}
    285 }
    286 
    287 //Open a previous saved document. MAB Remote can only open memory saved doc
    288 //local MAB can open files
    289 function openDoc(mode) {
    290 	//Docs are listed in the windows menu item
    291 	if(MAB_RUN == "remote") {return false;}
    292 
    293 	//Local
    294 	var myXMDManager;
    295 	var myFileManager = new FileManager();
    296 	var f = myFileManager.readFile();
    297 
    298 	if(f == false) {return false;}
    299 
    300 	try {
    301 	var mabXML = new DOMParser().parseFromString(f,'text/xml');
    302 	}catch(e) {
    303 		alert(e);
    304 	}
    305 
    306 	//Merge Mode
    307 	if(mode == "merge") {
    308 		myXMDManager = myDocOpened.getCurrentDocument();
    309 		if(!myXMDManager) {myXMDManager = newDoc();}
    310 		var res = myXMDManager.isValidMABDoc(mabXML);
    311 		if(!res) {
    312 			alert("The document is not a valid MAB file");
    313 			return false;
    314 		} else{
    315 			myXMDManager.merge(mabXML);
    316 			myXMDManager.wasSaved = false;
    317 			myDisplayController.buildTree(myXMDManager,true);
    318 		}
    319 
    320 	}else if(mode == "open") {
    321 		//Single Open Mode
    322 		myXMDManager = new XMDManager();
    323 		if(!myXMDManager.isValidMABDoc(mabXML)) {
    324 			alert("The document is not a valid MAB file");
    325 			return false;
    326 		} else {
    327 			myXMDManager.merge(mabXML);
    328 			//Get full path and file name without the extension
    329 			myXMDManager.fullPath = myFileManager.path;
    330 			var fileName = myFileManager.leafName;
    331 			fileName = fileName.substr(0,fileName.lastIndexOf("."));
    332 			myXMDManager.name =  fileName;
    333 			myXMDManager.wasSaved = true;
    334 			//Build HasTable
    335 			myXMDManager.buildHashTable();
    336 			//Add the current document to windows menu-item and to the array list
    337 			myDocOpened.addDoc(myXMDManager);
    338 			//Display result
    339 			myDisplayController.clearAll();
    340 			myDisplayController.buildTree(myXMDManager);
    341 		}
    342 	}
    343 
    344 	return true;
    345 }
    346 
    347 function saveAsDoc() {
    348 	if(MAB_RUN == "remote") {return false;}
    349 
    350 	var doc = myDocOpened.getCurrentDocument();
    351 	if(!doc) {
    352 		alert("The document is empty. Can not be saved.");
    353 		return false;
    354 	}
    355 
    356 	var fm = new FileManager();
    357 	//Loaded from disk or previously saved
    358 	var path = fm.saveAs();
    359 	var res = fm.saveFile(doc.xmlDoc,path);
    360 	if(res == true) {
    361 		doc.wasSaved = true;
    362 		doc.fullPath = fm.path;
    363 		doc.name = fm.leafName;
    364 		//Pay attention to the file extension
    365 		myDocOpened.renameCurrentDoc(doc.name);
    366 		return true;
    367 	}else{
    368 		return false;
    369 	}
    370 
    371 }
    372 
    373 function saveDoc() {
    374 	if(MAB_RUN == "remote") {return false;}
    375 
    376 	var doc = myDocOpened.getCurrentDocument();
    377 	if(!doc) {
    378 		alert("The document is empty. Can not be saved.");
    379 		return false;
    380 	}
    381 
    382 	var path = doc.fullPath;
    383 	var res;
    384 	if(path == "") {
    385 		res = saveAsDoc();
    386 	}else{
    387 		var fm = new FileManager();
    388 		res = fm.saveFile(doc.xmlDoc,path);
    389 	}
    390 
    391 	return res;
    392 }
    393 
    394 //Close the current open document
    395 function closeDoc() {
    396 	if(MAB_RUN == "remote") {
    397 		var result = closeDocRemote();
    398 		return result;
    399 	}
    400 
    401 	try {
    402 		netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
    403 	} catch (e) {
    404 		alert("Permission denied:" + e);
    405 	}
    406 
    407 	var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
    408                     .getService(Components.interfaces.nsIPromptService);
    409 
    410 
    411 	var flags=promptService.BUTTON_TITLE_SAVE * promptService.BUTTON_POS_0 +
    412           promptService.BUTTON_TITLE_DONT_SAVE * promptService.BUTTON_POS_1 +
    413           promptService.BUTTON_TITLE_CANCEL * promptService.BUTTON_POS_2;
    414 
    415 	var doc = myDocOpened.getCurrentDocument();
    416 	if(!doc) {
    417 		myDisplayController.clearAll();
    418 		return false;
    419 	}
    420 
    421 	var path = doc.fullPath;
    422 	var proceed = false;
    423 
    424 	if(path == "") {
    425 		proceed = promptService.confirmEx(window,"Save file?","Save changes to this new document, " + myDocOpened.getCurrentDocumentName() + "?",flags, null, null, null, null, {});
    426 		//Save
    427 		if(proceed == 0) {
    428 			var res = saveAsDoc();
    429 		//Cancel
    430 		}else if(proceed == 2) {
    431 			return false;
    432 		}
    433 
    434 	}else if(!doc.wasSaved) {
    435 		proceed = confirm("Save changes to " + path + '?');
    436 		if(proceed) {saveDoc();}
    437 	}
    438 
    439 	//Clear memory reference to this document and remove from list
    440 	myDocOpened.removeDoc(myDocOpened.getCurrentDocCounter());
    441 	myDisplayController.clearAll();
    442 	return true;
    443 }
    444 
    445 function closeDocRemote() {
    446 	myDocOpened.removeDoc(myDocOpened.getCurrentDocCounter());
    447 	myDisplayController.clearAll();
    448 }
    449 
    450 
    451 function clearAll() {
    452 	//Clear from GUI
    453 	myDisplayController.clearAll();
    454 	//Remove records from model
    455 	var myXMDManager = myDocOpened.getCurrentDocument();
    456 	if(myXMDManager) {
    457 		myXMDManager.removeAllDetails();
    458 	}
    459 }
    460 
    461 function showDetails() {
    462 	var myXMDManager = myDocOpened.getCurrentDocument();
    463 	myDisplayController.showDetails(myXMDManager);
    464 	//Change status to read
    465 	changeStatus("read");
    466 }
    467 
    468 
    469 //Go to the Amazon
    470 function goAmazon() {
    471 	var myXMDManager = myDocOpened.getCurrentDocument();
    472 	var res = myDisplayController.getProductAmazonUrl(myXMDManager);
    473 	if(!res) {
    474 		var proceed = confirm("No rows selected. Go to Amazon HomePage?");
    475 		if(proceed) {
    476 			var locale = myProductLineController.getLocale();
    477 			window.open(AMAZONURL[locale],"Amazon");
    478 		}
    479 	}else{
    480 		window.open(res,"Amazon");
    481 	}
    482 }
    483 
    484 //Search on Google by ProductName
    485 function goGoogle() {
    486 	var myXMDManager = myDocOpened.getCurrentDocument();
    487 	var idx = myDisplayController.getSelectedRowIndex();
    488 	if(idx < 0) {
    489 		var proceed = confirm("No rows selected. Go to Google HomePage?");
    490 		if(proceed) window.open(GOOGLEURL[locale],"Google");
    491 	} else {
    492 		var primaryKey = myDisplayController.getRowPrimaryKey(idx);
    493 		var nodeDetail = myXMDManager.getNodeDetail(primaryKey);
    494 		var searchString = myXMDManager.getSingleElement(nodeDetail,"ProductName");
    495 		var locale = myXMDManager.getSingleElement(nodeDetail,"MABLocale");
    496 		if(searchString) {
    497 			var words = searchString.split(" ");
    498 			//Google limit to 10 words
    499 			if(words.length > 10) {
    500 				searchString = "";
    501 				for(var i=0;i<10;i++){
    502 					searchString +=words[i]+' ';
    503 				}
    504 			}
    505 			searchString = encodeURI('"'+searchString+'"');
    506 			var googleUrl = GOOGLEURL[locale] + '/search?q=' + searchString + ' -site:'+ AMAZONURL[locale];
    507 			void(window.open(googleUrl,"Google"));
    508 		}
    509 	}
    510 }
    511 
    512 //Add the selected item to the Amazon Shopping Card
    513 function addCart() {
    514 	var myXMDManager = myDocOpened.getCurrentDocument();
    515 	var rows = myDisplayController.getAllSelectedRowIndex();
    516 
    517 	if(rows.length == 0) {
    518 		alert("No row selected.");
    519 		return false;
    520 	}
    521 
    522 	var pk, nodeDetail, temp;
    523 	var Asin = new Array();
    524 	var checkLocale = new Array;
    525 	for(var i=0; i< rows.length; i++) {
    526 		pk = myDisplayController.getRowPrimaryKey(rows[i]);
    527 		if(!pk) {continue;}
    528 		nodeDetail = myXMDManager.getNodeDetail(pk);
    529 		temp = myXMDManager.getSingleElement(nodeDetail,"Asin");
    530 		Asin.push(temp);
    531 		checkLocale[i] = myXMDManager.getSingleElement(nodeDetail,"MABLocale");
    532 		if(i == 0) {continue;}
    533 		if(checkLocale[i] != checkLocale[i-1]) {
    534 			alert("You can add item to only one shopping cart at time\nYou have selected products from differents Amazon shop");
    535 			return false;
    536 		}
    537 	}
    538 	if(Asin.length == 0) {return false;}
    539 	var locale = checkLocale[0];
    540 	var params = "";
    541 	for(i=0;i< Asin.length; i++) {
    542 		params += "asin." + Asin[i] +"=1&";
    543 	}
    544 	params += "tag-value="+ ASSID[locale] + "&";
    545 	params += "tag_value=" + ASSID[locale] + "&";
    546 	params += "dev-tag-value=" + DEVT;
    547 
    548 	var me = this;
    549 	var baseHREF = AMAZONURL[locale];
    550 
    551 	var callback = function(res) {
    552 		me.myProgressBar.stop();
    553 		var strBaseHREF = "<base href=" + baseHREF + ">";
    554 		if(res.status > 0) {
    555 			alert(res.message);
    556 			return false;
    557 		}else{
    558 			ow = window.open("","Amazon");
    559 			ow.document.open('text/html');
    560 			ow.document.write(strBaseHREF + res.content);
    561 			ow.document.close();
    562 			ow.focus();
    563 			return true;
    564 		}
    565 	}
    566 
    567 	var targetURL = AMAZONCARD[locale];
    568 	targetURL += Asin;
    569 
    570 	this.myProgressBar = new ProgressBar(guiMeter,true);
    571 	this.myProgressBar.start();
    572 	try {
    573 		var blPermission = false;
    574 		if(MAB_RUN == "local") {blPermission = true;}
    575 		var myConnection = new Connection(targetURL,blPermission);
    576 		myConnection.setCallback(callback);
    577 		myConnection.setErrorCallback(callback);
    578 		myConnection.send(params,"POST","txt");
    579 	}catch(e){
    580 		alert("An error as occured \n" + e);
    581 		this.myProgressBar.stop()
    582 		return false;
    583 	}
    584 
    585 	return true;
    586 }
    587 
    588 
    589 //Delete seleted rows from the tree and from the xml document
    590 function deleteRow() {
    591 	var myXMDManager = myDocOpened.getCurrentDocument();
    592 	var rows = myDisplayController.getAllSelectedRowIndex();
    593 	if(rows.length == 0) {
    594 		alert("No rows selected");
    595 		return false;
    596 	}
    597 
    598 	var pk;
    599 	var isRowDeleted = false;
    600 	var len = rows.length-1;
    601 	//Reverse loop to prevent mess with row index that are live
    602 	for(var i=len; i >= 0; i--) {
    603 		pk = myDisplayController.getRowPrimaryKey(rows[i]);
    604 		if(pk) {
    605 			myDisplayController.removeRow(pk);
    606 			isRowDeleted = myXMDManager.removeDetail(pk);
    607 		}
    608 	}
    609 
    610 	//Set Focus on the last -1 element
    611 	if(isRowDeleted) {
    612 		var indexRow = rows[0]-1;
    613 		myDisplayController.setFocusOnRow(indexRow);
    614 	}
    615 
    616 	return isRowDeleted;
    617 }
    618 
    619 //Sort result in the tree based on the column clicked. The XML Document is
    620 // sort too.
    621 function sortResult(el,tagName,columnPosition) {
    622 	var myXMDManager = myDocOpened.getCurrentDocument();
    623 	if(!myXMDManager) {return false;}
    624 
    625 	// If virtualSort is false the under hood xml document is not sorted
    626 	// in this case when products list is saved the items are not sorted, same
    627 	// thing when the user switch between documets loaded or in exportxml and exporthtml function
    628 
    629 	var virtualSort = false;
    630 	myDisplayController.sort(myXMDManager,el,tagName,virtualSort);
    631 	return true;
    632 }
    633 
    634 
    635 
    636 //Export Doc in XML - open a news browser window.
    637 //I can't find a way to display the document in source mode or to open the new window with text/xml type
    638 function exportXMLDoc() {
    639 	var myXMDManager = myDocOpened.getCurrentDocument();
    640 	if(!myXMDManager){return false;}
    641 	var strTitle = myXMDManager.name;
    642 	var str = serializeXML(myXMDManager.xmlDoc);
    643 	var param = "toolbar=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,location=no,directories=no";
    644 	var ow = window.open("html/exportXML.html","Export",param);
    645 
    646 	//It seems that with Mozilla 1.7 and Firefox 0.9 onload doesn't work anymore in the installed version.
    647 	//why it doesn't work ? setTimeout is an orrible solution!
    648 
    649 	//ow.onload = insertXML;
    650 	setTimeout(insertXML,500);
    651 	function insertXML() {
    652 		ow.document.title = strTitle.toUpperCase();
    653 		ow.document.getElementById('result').appendChild(ow.document.createTextNode(str));
    654 		ow.focus();
    655 		return true;
    656 	}
    657 
    658 	return true;
    659 }
    660 
    661 //Export HTML Doc opening a new browser window
    662 function exportHTMLDoc() {
    663 	var myXMDManager = myDocOpened.getCurrentDocument();
    664 	if(!myXMDManager) {return false;}
    665 	var strTitle = myXMDManager.name;
    666 	var strHTML = "";
    667 	var imgSrc = "";
    668 	var info = "";
    669 	var nodeList = myXMDManager.xmlDoc.getElementsByTagName("Details");
    670 
    671 	var param = "toolbar=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,location=no,directories=no";
    672 	var ow = window.open("html/exportHTML.html","Export",param);
    673 
    674 
    675 	for(var i=0;i< nodeList.length;i++) {
    676 		imgSrc = myXMDManager.getSingleElement(nodeList[i],"ImageUrlMedium");
    677 		info = myDisplayController.getFormattedInfo(myXMDManager,nodeList[i],"base");
    678 		strHTML += '<tr><td valign="top" class="img"><img src="'+ imgSrc +'" border="0"></td>';
    679 		strHTML += '<td valign="top" class="product">' + info + '</td></tr>';
    680 	}
    681 
    682 	//ow.onload = insertHTML; //why this? see exportXML :-(
    683 	setTimeout(insertHTML,500);
    684 	function insertHTML() {
    685 		ow.document.title = strTitle.toUpperCase();
    686 		ow.document.getElementById("page-title").innerHTML = strTitle.toUpperCase();
    687 		ow.document.getElementById("export-content").innerHTML = strHTML;
    688 		ow.focus();
    689 	}
    690 
    691 	return true;
    692 }
    693 
    694 //Export in txt a information summary about the selected rows.
    695 function exportTXTDoc() {
    696 	var myXMDManager = myDocOpened.getCurrentDocument();
    697 	var rows = myDisplayController.getAllSelectedRowIndex();
    698 	var len = rows.length;
    699 	if(len == 0) {
    700 		alert("No rows selected");
    701 		return false;
    702 	}
    703 
    704 	var txt = "";
    705 	var pk,node,amazAsin,locale,theUrl;
    706 
    707 	for(var i=0; i < len; i++) {
    708 		pk = myDisplayController.getRowPrimaryKey(rows[i]);
    709 		if(pk) {
    710 			node = myXMDManager.getNodeDetail(pk);
    711 			txt += myDisplayController.getFormattedInfo(myXMDManager,node,"base");
    712 			amazAsin = myXMDManager.getSingleElement(node,"Asin");
    713 			locale = myXMDManager.getSingleElement(node,"MABLocale");
    714 			theUrl = AMAZONURL[locale] + "/exec/obidos/ASIN/" + amazAsin + "/" + ASSID[locale] + "/";
    715 			txt += "Amazon page: " + theUrl + "\n\n";
    716 		}
    717 	}
    718 
    719 	//Remove HTML Info
    720 	txt = stripHTML(txt);
    721 	txt = "<pre>" + txt + "</pre>";
    722 
    723 	var param = "toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes,location=no,directories=no";
    724 	var ow = window.open("","Export",param);
    725 	ow.document.open("text/html", "");
    726     ow.document.writeln(txt);
    727     ow.document.close();
    728 	ow.focus();
    729 	return true;
    730 }
    731 
    732 /**
    733  * Open a new window to display a fake CD cover
    734  * @return true if the selected item is a music products
    735  * @type bool
    736 */
    737 function openCoverWin() {
    738 
    739 	//Check the selected items is in music catalog
    740 	var XMDManager = myDocOpened.getCurrentDocument();
    741 	var index = myDisplayController.getSelectedRowIndex();
    742 	var primaryKey = myDisplayController.getRowPrimaryKey(index);
    743 
    744 	var node = XMDManager.getNodeDetail(primaryKey);
    745 	if(node) {
    746 		var catalog = XMDManager.getSingleElement(node,"Catalog");
    747 		if(catalog != "Music") {
    748 			alert('You need to select a music CD');
    749 			return false;
    750 		}
    751 	} else {
    752 		return false;
    753 	}
    754 
    755 	var param = "toolbar=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,location=no,directories=no";
    756 	var ow = window.open("html/cover.html","Cover",param);
    757 	ow.focus();
    758 	return true;
    759 }
    760 
    761 //Get the bigger product image
    762 function getImageLarge() {
    763 	var myXMDManager = myDocOpened.getCurrentDocument();
    764 	var index = myDisplayController.getSelectedRowIndex();
    765 	var pk = myDisplayController.getRowPrimaryKey(index);
    766 	var node = myXMDManager.getNodeDetail(pk);
    767 	//get large image URL
    768 	var imgLarge = myXMDManager.getSingleElement(node,'ImageUrlLarge');
    769 	//Open Win for large image
    770 	var openWindow = function() {
    771 		void(window.open(this.src,'','centerscreen,resizable,width=' + this.width + ',height=' + this.height + ''));
    772 	}
    773 
    774 	if(imgLarge) {
    775 		 var img = new Image();
    776 		 img.src = imgLarge;
    777 		 img.onload = openWindow;
    778 		 return true;
    779 	}else{
    780 		return false;
    781 	}
    782 }
    783 
    784 //Set a background color on selected rows
    785 function setLabel(color) {
    786 
    787 	var myXMDManager = myDocOpened.getCurrentDocument();
    788 	var rows = myDisplayController.getAllSelectedRowIndex();
    789 	if(rows.length == 0) {
    790 		alert("No rows selected");
    791 		return false;
    792 	}
    793 	var done = false;
    794 	var pk, node, treeRow;
    795 	var len = rows.length;
    796 	for(var i=0; i < len; i++) {
    797 		pk = myDisplayController.getRowPrimaryKey(rows[i]);
    798 		if(pk) {
    799 			node = myXMDManager.getNodeDetail(pk);
    800 			treeRow = document.getElementById(pk);
    801 			myXMDManager.setNodeValue(node,"MABLabel",color)
    802 			myDisplayController.updateRow(treeRow,node,myXMDManager);
    803 			done = true;
    804 		}
    805 	}
    806 
    807 	return done;
    808 }
    809 
    810 function changeStatus(MABStatus) {
    811 	var myXMDManager = myDocOpened.getCurrentDocument();
    812 	var idx = myDisplayController.getSelectedRowIndex();
    813 	if(idx >= 0) {
    814 		var pk = myDisplayController.getRowPrimaryKey(idx);
    815 		var node = myXMDManager.getNodeDetail(pk);
    816 		if(!node) {return false;}
    817 		var treeRow = document.getElementById(pk);
    818 		myXMDManager.setNodeValue(node,"MABStatus",MABStatus)
    819 		myDisplayController.updateRow(treeRow,node,myXMDManager);
    820 		return true;
    821 	}else{
    822 		return false;
    823 	}
    824 }
    825 
    826 //Add the selected items to bookmark (sidebar)
    827 function addBookmark() {
    828 
    829 	var myXMDManager = myDocOpened.getCurrentDocument();
    830 	var idx = myDisplayController.getSelectedRowIndex();
    831 	if(idx < 0) { return false;}
    832 	var primaryKey = myDisplayController.getRowPrimaryKey(idx);
    833 	var nodeDetail = myXMDManager.getNodeDetail(primaryKey);
    834 	var title = myXMDManager.getSingleElement(nodeDetail,"ProductName");
    835 	var urlLink = myDisplayController.getProductAmazonUrl(myXMDManager,"directLink",nodeDetail);
    836 
    837 	//Require Privilege for remote version
    838 	try {
    839 		//Mozilla - Problem with Firefox 1.0 RC - So pass directly to sidebar
    840 		if(navigator.vendor == "Firefox"){throw("e");}
    841 
    842 		netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect")
    843 		var b = Components.classes["@mozilla.org/browser/bookmarks-service;1"].getService();
    844     	b = b.QueryInterface(Components.interfaces.nsIBookmarksService);
    845 		b.addBookmarkImmediately(urlLink,title,0,null);
    846 		return true;
    847 	}catch(e) {
    848 		try{
    849 			if(typeof(window.sidebar)!="undefined" && typeof(window.sidebar.addPanel)!="undefined") {
    850          		window.sidebar.addPanel (title,urlLink,"");
    851 				return true;
    852 			}else{
    853 				return false;
    854 			}
    855 		}catch(e){
    856 			alert("This function is not supported by your browser");
    857 			var el = document.getElementById("mabAddBookmark");
    858 			el.setAttribute("disabled","true");
    859 			return false;
    860 		}
    861 
    862 	}
    863 }
    864