//These are the variables we use.
working_data = new Array();
ez_array = new Array();
select_array = new Array("a0", "a1", "a2", "a3", "a4", "a5"); 
option_array5 = new Array("SFR", "Condo", "NoPref");
num = 0; i = 0; dup = 0; n = ""; n0 = "";  n1 = ""; bb = ","; picked = 0;
first_part = ""; checker = 0; prop = ""; switch_prop = 0; new_prop = "";
need_new_prop = 0; new_prop_switch = 0; ez_string = "";
//This function starts when the viewer checks/unchecks a box on this page
function add_item(prop) {
bnum = 0;
while(bnum <= 5) {
if(prop == select_array[bnum]) {
id_select_option();
first_part = document.forms[0]["anum_" + bnum].value
prop = first_part + picked; checker = 1; break;
} 
else{bnum++;}
}
n = parent.parent.parent.frames[0].document.forms[0].mls_list.value
if(n=="") { //Means that no item on any page has been checked (that's why
          //we get the data from the top frame)
checker = 0;
parent.parent.parent.frames[0].document.forms[0].mls_list.value = (prop);
}
else { //Means that one or more items have been checked before
i = 0; i0 = 0; dup = 0; n1 = ""; //Reinitialize some variables
working_data = ez_split(n, bb);
num = ez_counter; //This tells us how many boxes have been checked
                  //on all the pages.
//working_data = n.split(","); //Segment the old data by comma
//num = working_data.length; //How many boxes are checked?

//Now we start checking for duplicates and need for comma. We repeat this
//for each box that is checked (duplicate means that viewer has just
//unchecked a box).
while(i <num) {
if(checker == 1) {update_select_options(prop);}
if(switch_prop == 1) {prop = working_data[i]; switch_prop = 0;}
if(working_data[i] == "") {break;} //Processed the last item in the loop
if(working_data[i] != (prop)) { //Looking for duplicates
if(i != (num - (i0 - 1))) { //Guesses about whether we need a comma
n0 = working_data[i] +","; //We think we do so we add it here
}
else {
n0 = working_data[i]; //We don't so no comma
}
}
else { //Means we found a duplicate that we want to omit.
i++; i0--; dup = 1; continue;
}
//This item was not a duplicate so get ready to check the next.
n1 = n1 + n0; i++; i0--;
}
//Iterations finished. Now we can add the item just checked by the viewer
if(need_new_prop == 1) {prop = new_prop; dup = 0; need_new_prop = 0;}
if(dup == 0) { //ie the viewer checked rather than unchecked an item
n1 = n1 + (prop);
}
//A final check and corrective action for trailing commas.
num = n1.length; num--;
last_character = n1.charAt(num);
if(last_character == ",") {
n=n1.substring(0, num);
}
else {n = n1;}
//Now we print to the top frame.
parent.parent.parent.frames[0].document.forms[0].mls_list.value = n;
checker = 0; new_prop_switch = 0; need_new_prop = 0; zoo = 0;
}
} //Work finished here, so let's stop

function update_select_options(prop) {
aa = "-";
worked_select = new Array();
work_back = working_data[i];
work_back1 = working_data[i+1];
target_select = working_data[i];
if(new_prop_switch == 0) {new_prop = prop; new_prop_switch = 1;}
zz = target_select.indexOf(aa);
if(zz == -1) {return;}
worked_select = ez_split(target_select, aa);
target_select = worked_select[0] + aa;
if(target_select == first_part) {
working_data[i] = target_select + working_data[i+1];
switch_prop = 1; prop = working_data[i]; need_new_prop = 1;
working_data[i+1] = work_back1;
return(prop);
}
else {
working_data[i] = work_back;
working_data[i+1] = work_back1; return;
}
return(prop);
}

//-------------
function id_select_option() {
i = 0;
while(document.forms[0]["a_" + bnum].options[i].selected == false) {
i++;}
picked = document.forms[0]["a_" + bnum].options[i].value
}
//-------------

//Artificial split function needed because MSIE3 failed to include
//provisions for performing this common activity.

function ez_split(ez_string, ez_marker) {
ez_i = 0; ez_start = 0; ez_counter = 0; ez_num = 0; ez_remainder = "";
ez_length = ez_string.length;
while(ez_string != "") {
ez_num = ez_string.indexOf(ez_marker, ez_start);
if(ez_num == -1) {
ez_array[ez_i] = ez_string; ez_counter++;  return(ez_array);
}
ez_array[ez_i] = ez_string.substring(0, ez_num);
ez_i++; ez_num++;
ez_remainder= ez_string.substring(ez_num, ez_length);
ez_string = ez_remainder;
ez_counter++;
}
return(ez_array);
}

//This function replaces text box entry in top frame
function do_text_replace() {
parent.parent.parent.frames[0].document.forms[0].mls_community.value =
document.forms[0].a6.value;
}

function get_mls_next() {
  next_page = "mls_next.htm";
  self.location = next_page;
}

