var Tabs = ['prices','details','editions','notes','preview'];


function jump_results(starting, pattern, sortorder) {
        window.location = 'http://' + location.hostname + '/' + pattern + '::' + starting + sortorder; 
}

function validate_create_acct(form_name) {

	if (form_name.pass1.value != form_name.pass2.value) {
		alert ("Your password couldn\'t be verified; please make sure you enter it identically in both password fields.");
		form_name.pass1.value = '';
		form_name.pass2.value = '';
		form_name.pass1.focus();
		return false;
	} else {
		return true;
	}

}

function fave_action(form_name, action, f_id) { 
	$(form_name).type.value = action;
	if (f_id > 0) { 
		$(form_name).f_id.value = f_id;
	}
	var reaction;
	if (action.match(/delete/)) {
		if (!(confirm("Are you sure you want to remove that?"))) { 
			return false;
		}
	}
	$(form_name).submit();
	return false;
}

function f_delete(action, f_id, f_field_id) {
	if (!(confirm("Are you sure you want to remove that?"))) { return false; }

	var url = '/ajax/';
	if (action == 'delete_fl') {
		url = url + 'flist_delete?flist_id=' + f_id;
	} else if (action == 'delete_fv') {
		url = url + 'fave_delete?fave_id=' + f_id;
	} else {
		alert ("No action associated with " + action + ":" + f_id);
		return false;
	}
	var field = f_field_id + '_' + f_id;

	new Ajax.Request(url, {
		method: 'post',
		onSuccess: function(transport) {
			var success = transport.responseText.match(/deleted/);
			if (success) {
				$(field).style.display = 'none';
			} else {
				alert ('Sorry. This action failed to be performed.');
			}
		},
		onFailure: function() {
		}
	});
	return false;
}

function f_add(action, f_token, f_type, f_field_id, flist_id) {
	var url = '/ajax/';
	if (action == 'create_fl') {
		url = url + 'flist_create';
	} else if (action == 'create_fv') {
		url = url + 'fave_create?f_token=' + f_token + '&f_type=' + f_type + '&flist_id=' + flist_id;
	} else {
		url = url + 'foobar';
	}
	 // alert ("Fave add: " + f_type + ", " + f_field_id + ", " + flist_id);
	// alert (action);
	var f_type_text = f_type;
	if (f_type_text == 'isbn' || f_type_text == 'ean') { 
		f_type_text = 'book';
	}

	new Ajax.Request(url, {
		method: 'post',
		onSuccess: function(transport) {
			var success = transport.responseText.match(/created/);
			if (success) {
				$(f_field_id).innerHTML = 'This ' + f_type_text + ' has been added to your favorites list.';
				// alert ('Added successfully');
			} else {
				$(f_field_id).innerHTML = 'We\'re sorry, but this item was unable to be added at this time';
				// alert ('Unable to add this item');
			}
		},
		onFailure: function() {
			$(f_field_id).innerHTML = 'We\'re sorry, but this item was unable to be added at this time';
			// alert ('Unable to add this item');
		}
	});
	return false;
}

function f_move(type, direction, f_id) {
	var url = '/ajax/f_move?type=' + type + '&direction=' + direction + '&f_id=' + f_id;

	new Ajax.Request(url, {
		method: 'post',
		onSuccess: function(transport) {
			var success = transport.responseText.match(/success/);
			if (success) {
				var ids = new Array;
				ids = transport.responseText.split(":");
				var swap_prefix;
				if (type == 'flist') {
					swap_prefix = 'favorites_hunk';
				} else {
					swap_prefix = 'fave_item';
				}
				var swap1 = swap_prefix + '_' + ids[1];
				var swap2 = swap_prefix + '_' + ids[2];
				var swapx_text = $(swap1).innerHTML;
				$(swap1).innerHTML = $(swap2).innerHTML;
				$(swap2).innerHTML = swapx_text;
				var swap1tag = $(swap1).getElementsByTagName('div');
				var swap2tag = $(swap2).getElementsByTagName('div');
				swap1tag[0].parentNode.id = swap2;
				swap2tag[0].parentNode.id = swap1;
				// window.location="/favorites.html";
			} else {
				// handle login timeout
				if (transport.responseText.match(/invalid user/)) {
					alert ("Your session has timed out. Please log in again to modify bookmarks.");
					process_logout();
				}
				// alert (transport.responseText);
			}
		},
		onFailure: function() {
			// alert ("Uknown error");
		}
	});
	return false;
}

function fill_preferences() {
	var url = '/ajax/load_prefs';
	new Ajax.Request(url, {
		method: 'post',
		onSuccess: function(transport) {
			var elements = transport.responseText.split("\n");
			var currency = elements[1].split("\t");
			var methods = elements[2].split("\t");
			var countries = elements[3].split("\t");
			var states = elements[4].split("\t");
			fill_popup(currency, 'pref_currency');
			fill_popup(methods, 'pref_methods');
			fill_popup(countries, 'pref_countries');
			fill_popup(states, 'pref_states');
		},
		onFailure: function() {

		}
	});
}

function fill_popup(values, selector) {
	$(selector).options.length = 0;
	$(selector).options[0]=new Option('-', '-', 1, 1);

	for (var i = 0; i < values.length; i++) {
		var keyvalue = values[i].split("|");
		$(selector).options[i]=new Option(keyvalue[1], keyvalue[2], 0, 0);
	}
	$(selector).selectedIndex = 1;
}

function prefs_change(type, value) {
	var url = '/ajax/prefs_change?type=' + type + "&value=" + value;
	new Ajax.Request(url, {
		method: 'post',
		onSuccess: function(transport) {
			window.location.reload();
		},
		onFailure: function() {
			window.location.reload();
		}
	});
}

function process_login(form, box) {
	var url = '/ajax/process_login?&email_addr=' + encodeURIComponent(form.email_addr.value) + '&password=' + encodeURIComponent(form.password.value);
	var f_field_id = 'message_' + box;
	//var f_field_id = 'message_block';

	new Ajax.Request(url, {
		method: 'post',
		onSuccess: function(transport) {
			$(f_field_id).style.display = '';
			var success = transport.responseText.match(/success/);
			if (success != '') {
				var ra = transport.responseText.split("\n");
				var login = ra[0].match(/success\: (.+)/);
				var cook = ra[1].match(/cookie\: (.+)/);
				document.cookie = cook[1];
				close_stuff();
				swap_login_status();
				// $(f_field_id).innerHTML = 'Successful login';
				// alert ('success');
			} else {
				$(f_field_id).innerHTML = 'Login failed. Please try again.';
			}
		},
		onFailure: function() {
			$(f_field_id).style.display = '';
			$(f_field_id).innerHTML = 'Login failed. Please try again.';
		}
	});
	return false;
}

function process_logout() {
	var token = document.cookie.match(/token\=([^;]+)/);
	
	var url = '/ajax/process_logout?token=' + token[1];

	new Ajax.Request(url, {
		method: 'post',
		onSuccess: function(transport) {
			var success = transport.responseText.match(/logout/);
			if (success) {
			} else {
				// alert ('Your logout failed for unknown reasons. Please quit your browser and restart it to ensure a logout. ' + transport.responseText);
			}
		},
		onFailure: function() {
		}
	});
	
	document.cookie = 'token=1; path=/; domain=.isbn.nu; expires=Thu, 01-Jan-70 00:00:01 GMT;';
	window.location="/?logout=1";
	swap_login_status();
}

function swap_menu_color(base, overout) {
	var id = 'm_' + base;
	var pop = 'pop_' + base;
	if ($(pop) && ($(pop).style.display === '' || $(pop).style.display == 'block')) { return; }
	if (overout == 'over') {
		$(id).style.background = '#314A6B';
	} else { 
		$(id).style.background = '#121b27';
	}
}


function swap_tabs(id, isbn) {
	var hide_details = 0;
	var display_choice = document.cookie.match(/display_one\=([^;]+)/);
	if (display_choice && display_choice[1] == 1) { hide_details = 1; }

	for (var i=0; i<Tabs.length; i++) {
		if (Tabs[i] == id) {
			$('tab_body_' + id).style.display = 'block';
			$('tab_head_' + id).style.backgroundColor = "#000";
			if (Tabs[i] == 'preview' && $('google_preview_already').value == '') {
				var viewer = new google.books.DefaultViewer($('google_viewerCanvas'));
				viewer.load('ISBN:' + isbn, google_no_preview);
				viewer.resize();
				$('google_preview_already').value = 1;
			}

		} else if ($('tab_body_' + Tabs[i])) {
			if (Tabs[i] == 'details' && hide_details && id == 'prices') { 
				continue;
			}
			$('tab_body_' + Tabs[i]).style.display = 'none';
			$('tab_head_' + Tabs[i]).style.backgroundColor = "#6171e4";
		}
	}
	if (id == 'prices' && hide_details) { 
		$('tab_body_details').style.display = 'block';
	}
}
function google_no_preview() {
	$('google_no_preview').innerHTML = "I'm sorry, there's no preview for this title available at this time."; 
}

function check_google_preview(isbn) {

	var url = '/ajax/check_google_preview?isbn=' + encodeURI(isbn);

	new Ajax.Request(url, {
		method: 'post',
		onSuccess: function(transport) {
			var success = transport.responseText.match(/embeddable/);
			if (success) {
				$('tab_head_preview').style.display = '';
			} 
		},
		onFailure: function() {
		}
	});
	return false;
}


function toggle_display_tab() {
	var display_choice = document.cookie.match(/display_one\=([^;]+)/);
	var toggle = 0;
	if (display_choice) { toggle = display_choice[1]; }
	toggle = (toggle == 1 ? 0 : 1);
	show_display_css(toggle);
	$('toggle_display').innerHTML = (toggle ? "Click to show details in a separate tab from prices" : "Click to show details on same page as prices");
	document.cookie = 'display_one=' + toggle + '; path=/; domain=.isbn.nu; expires=Thu, 01-Jan-2032 00:00:01 GMT;';
	swap_tabs('prices');
	return false;
}

function show_display_css(one_page) {
	$('tab_head_details').style.display = (one_page ? 'none' : '');
	$('tab_body_details').style.display = (one_page ? 'block' : 'none');
	$('tab_body_details').style.styleFloat = (one_page ? 'left' : 'none');
	$('tab_body_details').style.position = (one_page ? 'relative' : 'absolute');
	$('tab_body_prices').style.position = (one_page ? 'static' : 'absolute');
	$('toggle_display').innerHTML = (one_page ? "Click to show details in a separate tab from prices" : "Click to show details on same page as prices");
}

function set_display_tab() {
	var display_choice = document.cookie.match(/display_one\=([^;]+)/);
	if (!display_choice || display_choice[1] == 0) { return false; }
	show_display_css(1);
}

function load_correct_tab() {
	var loc = location.href;
	var tab = loc.match(/\#(.*)$/);
	if (tab === null) { 
		for (var i=0; i<Tabs.length; i++) {
			if ($('tab_head_' + Tabs[i]) && $('tab_head_' + Tabs[i]).style.backgroundColor == '#000') { 
				return false;
			}
		}
		swap_tabs('prices'); return; 
	}
	var match = Tabs.indexOf(tab[1]);
	if (match > 0) { swap_tabs(tab[1]); }
	else { 
		if (tab && tab[1] == 'amazondesc') { 
			swap_tabs('details');
		} else { 
			swap_tabs('editions'); 
		}
	}
}

// uses "this" to avoid base reference
function rollout_close(item) {
	item.style.color = "#fff";
	item.style.backgroundColor = "#6171e4";
}

function rollover_close(item) {
	item.style.color = "#000";
	item.style.backgroundColor = "#fff";
}

function set_home_focus(field) {
	setTimeout('$(\'' + field + '\').focus()', 50);
	return false;
}

function form_appear(base) {
	var menu_item = 'm_' + base;
	var form_field = 'pop_' + base;
	var form_name = base + "_field";
	$(menu_item).style.backgroundColor = "#314A6B";
	$(form_field).style.top = ($(menu_item).offsetTop - 17) + 'px';
	$(form_field).style.left = ($(menu_item).offsetLeft + 160) + 'px';
	if (base == 'preferences') {
		$(form_field).style.top = ($(menu_item).offsetTop - 160) + 'px';
	}
	close_stuff('no');
	Effect.Appear(form_field, { duration: 1.0 });
	// hack allows focus after fadein
	if ($(form_name)) { 
		setTimeout('$(\'' + form_name + '\').focus()', 1050);
	}
	var opac = $('l_center').style.opacity;
	if (opac === '' || opac == 1) { 
		new Effect.Opacity('l_center', { from: 1.0, to: 0.3, duration: 1.0 });
	}
	if (base == 'preferences') { 
		// fill_preferences();
	}
}


function close_box(base, dont) {
	var item = 'pop_' + base;
	var roll = 'm_' + base;
	if ($(item).style.display != 'none') {
		Effect.Fade(item, { duration: 1.0 });
	}
	$(roll).style.background = '#121b27';

	var opac = $('l_center').style.opacity;
	if (opac === '' || opac == 1 || dont == 'no') { return; }
	new Effect.Opacity('l_center', { from: 0.3, to: 1.0, duration: 1.0 });
}

function close_stuff(dont) {
	close_box('isbn', dont);
	close_box('title', dont);
	close_box('author', dont);
	close_box('login', dont);
	close_box('logout', dont);
	close_box('preferences', dont);
}

function swap_login_status(in_out) {
		
	var navels = new Array("m_login","m_create","m_fave","m_acctm","m_logout");
	for (i = 0; i < navels.length; i++) {
		if ($(navels[i]).style.display == 'none') {
			$(navels[i]).style.display = '';
		} else {
			$(navels[i]).style.display = 'none';
		}
	}
}

function prefetch(isbnlist, stores) {
	var isbns = isbnlist.split("|");
	var prestores = stores.split("|");
	for (var i = 0; i < isbns.length; i++) {
		ajax_load('1', isbns[i], prestores)
	}
}


function ajax_load(prefetch, preisbn, prestores) {
	var stores = (prefetch ? prestores : find_stores('none'));
	var isbn = (prefetch ? preisbn : $('isbn_13').innerHTML);

	var url_path = '/api/api?method=nu.isbn.ean.getStoreInfo&ean=' + isbn + '&suppress_biblio=1&' + (prefetch ? 'prefetch=1&' : '') + 'store=';

	if (stores.length > 3 && prefetch != 1) {
		var divs = $('priceblock').getElementsByTagName('div');
		var total_stores = 0;
		for (var i = 0; i < divs.length; i++) {
			if (divs[i].id.match(/^row_slot_/)) { total_stores++; }
		}
		$('price_load_text_completed').innerHTML = (total_stores - stores.length);
		$('price_load_text_total').innerHTML = total_stores;
		var bar_start_width = Math.round((total_stores - stores.length) / total_stores * 372);
		$('price_load_progress_bar').style.width = bar_start_width + 'px';
 		Effect.Appear('price_load_progress_container', { duration: 0.5 });
	}

	for (var i = 0; i < stores.length; i++) {

		// spawn jobs
		var this_path = url_path + stores[i];
		new Ajax.Request(this_path, {
			method: 'post',
			onSuccess: function(transport) {
				if (this_path.match(/prefetch\=1/)) { return; }

				var store;
				var price;
				var timeToShip;
				var timeToArrive;
				var totalMin;
				var totalMax;
				var currency;
				var url;
				
				var lines = transport.responseText.split("\n");
				for (var i = 0; i < lines.length; i++) {
					if (lines[i].match(/<key>ID/)) { 
						store = match_string(lines[i+1]);
					} else if (lines[i].match(/<key>Price/)) {
						price = match_string(lines[i+1]);
					} else if (lines[i].match(/<key>TimeToShip/)) {
						timeToShip = match_string(lines[i+1]);
					} else if (lines[i].match(/<key>TimeToArrive/)) {
						timeToArrive = match_string(lines[i+1]);
					} else if (lines[i].match(/<key>TotalTimeMin/)) {
						totalMin = match_string(lines[i+1]);
					} else if (lines[i].match(/<key>TotalTimeMax/)) {
						totalMax = match_string(lines[i+1]);
					} else if (lines[i].match(/<key>URL/)) {
						var t_url = match_string(lines[i+1]);
						t_url = t_url.replace(/&amp;amp;/g, '&amp;');
						url = t_url.replace(/&amp;/g, '&');
						url = url.replace(/&amp;/g, '&');
					} else if (lines[i].match(/<key>CurrencyFormat/)) {
						currency = match_string(lines[i+1]);
						currency = currency.substr(0,1);
					}
				}
				if (url == 'Limit exceeded') { 
					$('amazon_oct_note').style.display = '';
				}
				if (store && price > 0) {
					if ($('price_load_progress_container').style.display != 'none') {
						var s_com = $('price_load_text_completed').innerHTML || 0;
						s_com++;
						if (s_com > total_stores) { s_com = total_stores; }
						$('price_load_text_completed').innerHTML = s_com;
						var bar_start_width = Math.round(s_com / total_stores * 372);
						$('price_load_progress_bar').style.width = bar_start_width + 'px';
					}

					$('row_slot_' + store).style.display = '';
					$('price_insert_' + store).innerHTML = currency + price;
					var dayOrWeek = 'days';
					if (totalMin > 7) { 
						dayOrWeek = 'weeks'; 
						totalMin = Math.round(totalMin / 7);
						totalMax = Math.round(totalMax / 7);
					}
					$('pr_totaltime_cell_' + store).innerHTML = totalMin + "&ndash;" + totalMax + " " + dayOrWeek;
					$('pr_pack_cell_' + store).innerHTML = timeToShip;
					$('pr_ship_cell_' + store).innerHTML = timeToArrive;
					if (url) {
						$('price_insert_' + store).href = url;
					}
					// update all the shipping information
					
					//$('show_status_ajax').style.display = '';
					
					var still_sorting = 1;
					while (still_sorting) {
						var stores = find_stores('');

						still_sorting = 0;
						for (var j = 0; j < (stores.length - 1); j++) {
							if (!(j % 2)) {
								$('row_slot_' + stores[j]).style.backgroundColor = "#d8ddff";
								$('row_slot_' + stores[j+1]).style.backgroundColor = "#fff";
							} else {
								$('row_slot_' + stores[j]).style.backgroundColor = "#fff";
							}
							
							var current = $('price_insert_' + stores[j]).innerHTML;
							if (current.match(/^[^\d]{1,1}/)) { 
								current = current.substr(1);
							}
							
							var next = $('price_insert_' + stores[j+1]).innerHTML;
							if (next.match(/^[^\d]{1,1}/)) { 
								next = next.substr(1);
							}

							if (parseFloat(next) < parseFloat(current)) { 
								still_sorting = 1;
								var swap1 = 'row_slot_' + stores[j];
								var swap2 = 'row_slot_' + stores[j+1];
								var swapx_text = $(swap1).innerHTML;
								$(swap1).innerHTML = $(swap2).innerHTML;
								$(swap2).innerHTML = swapx_text;
								var swap1tag = $(swap1).getElementsByTagName('div');
								var swap2tag = $(swap2).getElementsByTagName('div');
								swap1tag[0].parentNode.id = swap2;
								swap2tag[0].parentNode.id = swap1;
							}
						}
					}

					
				} else {
				 	// delete store related row
					// $('price_insert_' + store[1]).innerHTML = 'none';
				}
			},
			onFailure: function() {
			}
		});
	}

	if (prefetch) { return false; }
	
	var end_url = '/ajax/price_complete?isbn=' + escape($('isbn_13').innerHTML);

	new Ajax.Request(end_url, {
		method: 'post',
		onSuccess: function(transport) {
			var success = transport.responseText.match(/completed/);
			if (success) {
				if ($('price_load_progress_container').style.display != 'none') {
					$('price_load_text_completed').innerHTML = total_stores;
					$('price_load_progress_bar').style.width = '100%';
					Effect.Fade('price_load_progress_container', { duration: 1.5 });
				}
				var stores = find_stores('');
				if (stores.length == 0 || stores.length === null) {
					$('price_table_header').style.display = 'none';
					$('price_row_click_info').style.display = 'none';
					$('alternate_results').style.display = '';
				}			
			}
		},
		onFailure: function() {
			if ($('price_load_progress_container').style.display != 'none') {
				Effect.BlindUp('price_load_progress_container', { duration: 1.5 });
			}
		}
	});
	
	if ($('bookmooch') && $('bookmooch').style.display == 'none') {
		var mooch_url = '/ajax/bookmooch_lookup?isbn=' + escape($('isbn_10').innerHTML);
		new Ajax.Request(mooch_url, {
			method: 'post',
			onSuccess: function(transport) {
				var success = transport.responseText.match(/\d+/);
				if (success) {
					$('bookmooch').style.display = '';
				}
			}
		});
	}

	if ($('abebooks_signed') && $('abebooks_signed').style.display == 'none') {
		var abe_url = '/ajax/abebooks_signed?isbn=' + escape($('isbn_10').innerHTML);
		new Ajax.Request(abe_url, {
			method: 'post',
			onSuccess: function(transport) {
				var price = transport.responseText.match(/^(\$[\d\.]+)/);
				if (price) {
					$('abebooks_signed').style.display = '';
					$('abebooks_signed_price').innerHTML = price[0];
				}
			}
		});

	}
	
	return false;
}


function sort_prices_by(type) {
	// ship_time
	// prices
	// show_ship

	if (type == 'show_ship') {
		var ss = $('show_shipping').innerHTML;
		var s_stores = find_stores('');
		for (var j = 0; j < s_stores.length; j++) {
			var pi = $('price_insert_' + s_stores[j]).innerHTML;
			var start = Number(pi.substr(1));
			var new_total = 0;
			if (ss == '0') {
				new_total = start + Number($('pr_shipping_cost_' + s_stores[j]).value);
			} else {
				new_total = start - Number($('pr_shipping_cost_' + s_stores[j]).value);
			}
			new_total = Math.round(new_total * 100) / 100;
			var new_string = pi.substr(0,1) + new_total;
			if (!new_string.match(/\./)) {
				new_string += ".00";
			} else if (new_string.match(/\.\d{1,1}$/)) {
				new_string += "0";
			}
			$('price_insert_' + s_stores[j]).innerHTML = new_string;
			// $('price_row_click_info').innerHTML += new_total + ", ";
		}
		$('show_shipping').innerHTML = (ss == 0 ? '1' : '0');
	}

	var still_sorting = 1;
	var bgcol = ['#d8ddff','#fff'];
	
	while (still_sorting) {
		var stores = find_stores('');

		still_sorting = 0;
		for (var j = 0; j < (stores.length - 1); j++) {

			var current = 0;
			var next = 0;
			if (type == "ship_time") {
				current = calc_ship_time($('pr_totaltime_cell_' + stores[j]).innerHTML);
				next = calc_ship_time($('pr_totaltime_cell_' + stores[j+1]).innerHTML);
			} else {
				current = $('price_insert_' + stores[j]).innerHTML;
				if (current.match(/^[^\d]{1,1}/)) { 
					current = current.substr(1);
				}
				next = $('price_insert_' + stores[j+1]).innerHTML;
				if (next.match(/^[^\d]{1,1}/)) { 
					next = next.substr(1);
				}
			}
			

			if (Number(next) < Number(current)) { 
				still_sorting = 1;
				var swap1 = 'row_slot_' + stores[j];
				var swap2 = 'row_slot_' + stores[j+1];
				var swapx_text = $(swap1).innerHTML;
				$(swap1).innerHTML = $(swap2).innerHTML;
				$(swap2).innerHTML = swapx_text;
				var swap1tag = $(swap1).getElementsByTagName('div');
				var swap2tag = $(swap2).getElementsByTagName('div');
				swap1tag[0].parentNode.id = swap2;
				swap2tag[0].parentNode.id = swap1;
			}
			$('row_slot_' + stores[j]).style.backgroundColor = bgcol[j % 2];
			$('row_slot_' + stores[j+1]).style.backgroundColor = bgcol[j % 2 + 1];
		}
	}

}

function calc_ship_time(sh_time) {
	var days = sh_time.match(/^(\d+)(?:\s|\&|\-|\–|\%).*(day|week)/);
	//alert(escape(sh_time) + ", " + days);
	if (!days) { return 0; };
	var ret_time = days[1] * (days[2] == 'week' ? 7 : 1);
	return ret_time;
}


function find_stores(none_flag) {
	var divs = $('priceblock').getElementsByTagName('div');
	var prices = new Array;
	var j = 0;
	for (var i = 0; i < divs.length; i++) {
		if (divs[i].id.match(/^row_slot_/) && divs[i].style.display == none_flag) {
			j++;
			prices.push(divs[i]);
		}
	}
	var stores = new Array;
	for (var i = 0; i < prices.length; i++) {
		var name = prices[i].id.match(/row_slot_(.+)/);
		if (name && name[1] && !($('price_insert_' + name[1]).innerHTML.match(/\-1\.00/)) ) {
			stores.push(name[1]);
		}
	}

	return stores;
}

function match_string(text) {
	var a = new Array;
	a = text.match(/string>([^<]+)/);
	return a[1];
}


