/*
 * Used to display the selected criteria  ***NO LONGER USED***
 */
function listCriteria() {
  var pd_submit = document.getElementById ('content:partnersearch:partner_dir_submit_flg');
  var pd_submit_val = document.getElementById ('content:partnersearch:partner_dir_submit_value');

  if (pd_submit.value == "true") {

      var txt_found_for = document.getElementById ('content:dummypartnersearch:dummy_found_for');
      var p_isv = document.getElementById ('content:partnersearch:partner_isv');
      var p_reseller = document.getElementById ('content:partnersearch:partner_reseller');
      var p_keyword = document.getElementById ('content:partnersearch:criteria_item_b000');
      var p_country = document.getElementById ('content:partnersearch:country');
      var p_zip = document.getElementById ('content:partnersearch:zipcode');
      var p_dist = document.getElementById ('content:partnersearch:distance');
      var p_special = document.getElementById ('content:partnersearch:special_programs');
      var p_level = document.getElementById ('content:partnersearch:partner_level');
      var p_industry = document.getElementById ('content:partnersearch:industry');
      var mycriteria = new Array();

      if (p_isv != undefined && p_isv.checked == true) {
        mycriteria[mycriteria.length] = document.getElementById("content:dummypartnersearch:dummy_p_isv").value;
      }
      if (p_reseller != undefined && p_reseller.checked == true) {
        mycriteria[mycriteria.length] = document.getElementById("content:dummypartnersearch:dummy_p_reseller").value;
      }
      if (p_keyword.value != '') {
        mycriteria[mycriteria.length] = p_keyword.value;
      }
      if (p_country != undefined && p_country.value != '') {
        for (jj = 0; jj < p_country.options.length; jj++) {
          if (p_country.options[jj].selected == true) {
            mycriteria[mycriteria.length] = p_country.options[jj].text;
          }
        }
      }
      if (p_zip != undefined && p_zip.value != '') {
        mycriteria[mycriteria.length] = p_zip.value;
        if (p_dist != undefined && p_dist.value != '') {
          mycriteria[mycriteria.length] = p_dist.options[p_dist.selectedIndex].text;
        }
      }
      if (p_special != undefined && p_special.value != '') {
        for (jj = 0; jj < p_special.options.length; jj++) {
          if (p_special.options[jj].selected == true) {
            mycriteria[mycriteria.length] = p_special.options[jj].text;
          }
        }
      }
      if (p_level != undefined && p_level.value != '') {
        mycriteria[mycriteria.length] = p_level.options[p_level.selectedIndex].text;;
      }
      if (p_industry != undefined && p_industry.value != '') {
        for (jj = 0; jj < p_industry.options.length; jj++) {
          if (p_industry.options[jj].selected == true) {
            mycriteria[mycriteria.length] = p_industry.options[jj].text;
          }
        }
      }

      // create the criteria & save
      var criteria_val = "";
      if (mycriteria.length > 0) {
        criteria_val = criteria_val + txt_found_for.value + " ";
      }
      for (ii = 0; ii < mycriteria.length; ii++) {
        criteria_val = criteria_val + "<b>" + mycriteria[ii] + "</b>";
        if (ii < mycriteria.length - 1) criteria_val = criteria_val + ", ";
        if (ii == mycriteria.length - 2) criteria_val = criteria_val + "and ";
      }

      pd_submit_val.value = criteria_val;
      
      // reset the submit flg now
      pd_submit.value = "false";
      
  } // if (pd_submit.value == "true")
  
  document.write(pd_submit_val.value);
}


/*
 * Set values for a javascript search page submit of the pagesize change
 */
function pagesize_submit() {
  var form1 = document.getElementById ('content:paging_size');
  var sub2 = document.getElementById ('content:paging_size:pagesize_change');
  var sub3 = document.getElementById ('content:paging_size:pd_page');

  sub2.value = 'yes';
  sub3.value = 'yes';
  form1.submit();
}


/*
 * Set values for a javascript search page submit of the sortby change
 */
function sortby_submit() {
  var form1 = document.getElementById ('content:sort_by');
  var sub2 = document.getElementById ('content:sort_by:sortby_change');

  sub2.value = 'yes';
  form1.submit();
}


/*
 * Update the list of vendor_id's held for comparison in a js array
 */
function updateList(me1) {

    var me2 = me1.parentNode;
      
    if (me2.elements[1].checked == true) {
        var vid = me2.elements[0].value;
        if (inArray(compareArray, vid) !== false) {
            //alert("already inArray");
        }
        else {
            if (compareArray.length >= 5) {
                alert("Only up to 5 companies can be compared. You have already reached this limit.");
                me2.elements[1].checked = false;
            }
            else {
                compareArray[compareArray.length] = me2.elements[0].value;
            }
        }
    }
    else {
        var foundIndex = inArray(compareArray, me2.elements[0].value);
        if (foundIndex !== false) {
            compareArray.splice(foundIndex, 1);
            //removeIndex(compareArray, foundIndex);
        }
    }
    //alert("compareArray=" + compareArray + "#");

    document.getElementById("content:comp_button1:pd_comp_vid").value = compareArray.toString();
    document.getElementById("content:paging_size:pd_comp_vid2").value = compareArray.toString();
    document.getElementById("content:sort_by:pd_comp_vid1").value = compareArray.toString();

    var vid3 = document.getElementById("content:paging_top:pd_comp_vid3");
    if (vid3 != undefined) { vid3.value = compareArray.toString(); }
 
    // update the compare link to add vendor id's
    var url_ids = "";
    for (var jj = 0; jj < compareArray.length && jj < 5; jj++) {
      url_ids = url_ids + "vendor_id" + jj + "=" + compareArray[jj] + "&";
    }

    document.getElementById("content:comp_button1:pd_comp_link").href = "/catalog/search/PartnerCompare.jsf?" + url_ids;
}


/*
 * returns the index if in the array; else returns false
 */
function inArray(array1, myValue) {
    for (var ii = 0; ii < array1.length; ii++) {
        if (myValue == array1[ii]) {
            return ii;
            break;
        }
    }
    return false;
}


/*
 * removes the given index from the array
 */
function removeIndex(array1, myIndex) {
    array1[myIndex] = array1[array1.length - 1];
    array1.length = array1.length -1;
}


// create the vendor_id comparison array
var compareArray=new Array();


/*
 * Initialize the compare vendor js array & checkboxes
 */
function compare_init() {
    var vids = document.getElementById("content:comp_button1:pd_comp_vid");
    //alert(vids);
    if (vids != undefined) {
        if (vids.value == "") {
            compareArray = new Array;
        }
        else {
            compareArray = vids.value.split(",");
        }
        //alert("compareArray=" + compareArray + "#");
    }

    var inputs = document.getElementsByTagName("input");
    for (var ii = 0; ii < inputs.length; ii++) {
      if (inputs[ii].type == "checkbox" && inputs[ii].name == "vid_cb") {
        var me2 = inputs[ii].parentNode;
        var vid = me2.elements[0].value;
        if (inArray(compareArray, vid) !== false) {
            inputs[ii].checked = true;
        }
        else {
            inputs[ii].checked = false;
        }
      }
    }

    // update the compare link to add vendor id's
    var url_ids = "";
    for (var jj = 0; jj < compareArray.length && jj < 5; jj++) {
      url_ids = url_ids + "vendor_id" + jj + "=" + compareArray[jj] + "&";
    }

    var comp_link = document.getElementById("content:comp_button1:pd_comp_link");
    if (vids != comp_link) {
        comp_link.href = "/catalog/search/PartnerCompare.jsf?" + url_ids;
    }

}

/*
 * Toggle the display of the optional filters
 */
function toggle_opts() {
  var opts = document.getElementById("content:partnersearch:pd_hidden_opts");
  var sub6a = document.getElementById("content:partnersearch:comp_0140_id_20sub6a");
  var sub6 = document.getElementById("content:partnersearch:comp_0140_id_20sub6");
  var sub7 = document.getElementById("content:partnersearch:comp_0140_id_20sub7");
  var css = YAHOO.otorg.DomCollapse.css;

  if(YAHOO.util.Dom.hasClass(opts,css.hideClass)){
  	YAHOO.util.Dom.removeClass(opts,css.hideClass);
  	YAHOO.util.Dom.removeClass(sub6,css.hideClass);
  	YAHOO.util.Dom.addClass(sub7,css.hideClass);
        sub6a.src="/catalog/im/ic_show_plus.gif"
  } else {
  	YAHOO.util.Dom.addClass(opts,css.hideClass);
  	YAHOO.util.Dom.addClass(sub6,css.hideClass);
  	YAHOO.util.Dom.removeClass(sub7,css.hideClass);
        sub6a.src="/catalog/im/ic_hide_minus.gif"
  };
}

