';
for (var i in google_chrome) {
var text = tree[1][ google_chrome[i] ];
if (google_chrome[i] == 'All') {
text = '-- Select --';
}
str = str + '';
}
str = str + '';
return str;
}
function select_region(obj)
{
var level = obj.id.split('_');
//lastest = level;
var pre = parseInt(level[1]) -1 ;
var next = parseInt(level[1]) + 1;
if (obj.value != 'All') {
//set #edit-tid to current value
set_current(obj.value);
find_all_direct_children(obj.value);
//adding new element .
//before we adding new element we have to see if the element exist or not.
if (is_element_exist(next)) {
//if exist, delete it and all of them children.
delete_all_children(next);
}
var has_options = false;
if (next_level.length != 0) {
var str = '';
if (has_options == true)
$(wrapper_div_id).append(str);
}
} else {
//set current value to currently selected element's parent element.
if (level != 0) {
//find selected element
var tid = selected_element("#"+lvl_id+"_"+ pre);
set_current(tid);
}
delete_all_children(next);
}
}
function selected_element(id)
{
return $(id).val();
}
function set_current(value)
{
//before set, set currently selected element to not selected.
$(original_element_id + " option").each(function() {
if ($(this).attr('selected') == 'selected') {
$(this).attr('selected','');
return;
}
});
$(original_element_id + " option").each(function() {
if ($(this).val() == value) {
$(this).attr('selected','selected');
return;
}
});
}
function delete_all_children(level)
{
while ($('#'+lvl_id+'_'+level).length > 0) {
$('#'+lvl_id+'_'+ level).remove();
++level;
}
}
function is_element_exist(level)
{
if ($('#'+lvl_id+'_'+level).length > 0)
return true;
return false;
}
function find_all_direct_children(tid)
{
var text = '';
next_level = new Object();
//find corresponde element in #edit-term-node-tid-depth
$(original_element_id + " option").each(function() {
if ($(this).val() == tid) {
text = $(this).text();
return;
}
});
var n = count_hyphen(text);
//find all item with leading n hyphen and is child of tid
var in_position = false;
$(original_element_id + " option").each(function() {
if (in_position) {
if (count_hyphen($(this).text()) == n+1) {
next_level[$(this).val()] = $(this).text();
//
} else {
if (count_hyphen($(this).text()) == n) // at same level again
{
in_position = false;
return;
}
}
}
if ($(this).val() == tid) {
in_position = true;
}
});
}
function count_hyphen(text)
{
//this funciton only count hyphen which start from begining of an string.
var len = text.length;
var n=0;
//hyphen must start at zero position.
for (var i = 0; i < len ; i++) {
if (text.charAt(i) == '-') {
++n;
} else
break;
}
return n;
}
// ]]>
Personal Create your profile
Newsletters Receive the latest updates from destination-nz.com
Travel Planner
Save listings and events to your favourites
Share your favourites with others
Interactive
Share your travel experiences
Upload photos and write your own stories
Comment on our blogs
Get talking in our travel forum
Maps Regional maps
Itineraries National North Island South Island Themed
Distances Distance charts
Browse and book online Accommodation Activities Transport Services
my.destination-nz Share travel information Save listings and events to your favourites Share your favourites with others

The 2011 edition of our destination-nz.com Visitor Guide is here! Invaluable to New Zealand travellers, particularly if you are wanting to travel independently and make your own plans.
ORDER NOW!