﻿function RemoveText(odj) {
    odj.value = "";
}
//this function is being called when clicking the sort button 
function removeBreadcrumb(url)
{
	window.location.href = url;
}
function goSort(ddlSortName)
{
  var value=document.getElementById(prefixvar+ddlSortName).value;	  
	var baseURL = document.getElementById(prefixvar+'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;
          }
        }
      }
      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;
    }
}

//this function is called when clicking on the
//Go button in the free search area
function goFreeTextSearch(ctl) {
    var isValid = true;

    if (typeof (Page_ClientValidate) == "function") {
        isValid = Page_ClientValidate('FreeSearch');
    }

    var freeTextValue = ctl.value;
    if (freeTextValue == '')
        isValid = false;

    if (isValid) {
        freeTextValue = encodeURIComponent(freeTextValue);

        var dt = new Date();

        //if new free search, take the basic url and the free text to it
        window.location.href = searchBaseUrl + '&free_text=' + freeTextValue + "&attribute_value_string|Store_ID=" + siteName;
    }

    return false;
}

/*Setting the collapse\expand state of the filters.
The function is called from each filter object but appears once in the search page*/
function SwitchStyle(imgObj) {
    if (imgObj.title == 'Expand') {
        //img.td.tr.tbody.table.siblingTable = children table
        imgObj.parentElement.parentElement.parentElement.parentElement.nextSibling.style.display = '';
        imgObj.title = 'Collapse';
        imgObj.src = './Images/Search/arrow_up.gif';
    }
    else {
        //img.td.tr.tbody.table.siblingTable = children table
        imgObj.parentElement.parentElement.parentElement.parentElement.nextSibling.style.display = 'none';
        imgObj.title = 'Expand';
        imgObj.src = './Images/Search/arrow_down.gif';
    }
}
//This function is being used as the A tag URL,
//to include the CMC regExp indentification - when redirection is not relevant
function ignore(cmc_param) { }
//This function is being used as the A tag URL, 
//to include the CMC regExp indentification - when redirection is relevent
function loadURL(url, cmc_param, newWindow) {
    if (newWindow)
        window.open(url, "_blank");
    else
        window.location.href = url;
}
