﻿//this function is being called when clicking the sort button
function goSort()
{
  var value=document.getElementById('_ctl0_defaultContentPlaceHolder_MercadoSearchControl1_cmbSortOptions').value;
	var baseURL = document.getElementById('_ctl0_defaultContentPlaceHolder_MercadoSearchControl1_baseURLWithoutSort').value; 
	var url = baseURL + '&sort_option=' + value;
	window.location.href = url;
}
//this function is being called when clicking the compare button
function goCompare()
{
    //get all INPUT tags
    var compareChecks=document.getElementsByTagName ("input");
    if (compareChecks != null)
    {
      var selected_ids ="";
      for (var i=0; i< compareChecks.length; i++)
      { 
      
        //if it's a Checkbox and the ID contains the chkCompare string 
        // meaning it's a compare checkbox
        if (compareChecks[i].type =="checkbox") 
        {
          if (compareChecks[i].id.indexOf("chkProductCompare") != -1)
          {
            //if it's chekced, get the ID, from an attribute set on the server side and add it to the selected IDs list
            if (compareChecks[i].checked) 
                selected_ids += ((selected_ids.length==0)? "" : "|") + compareChecks[i].attributes["prod_id"].value;
          }
        }
      }
      //commenting out as product compare page isn't implemented at this point
     // if (selected_ids.length == 0)
      //  alert ("Please select products to compare");
    //  else //redirect to the compare page with the relevent url params
        //  window.location.href = "ProductCompare.aspx?selected_prod_ids=" + selected_ids;
    }
}