﻿//this function is being called when clicking the sort button
//function set_cookie(name, value, exp_y, exp_m, exp_d, path, domain) {
//    var cookie_string = name + "=" + escape(value);

//    if (exp_y) {
//        var expires = new Date(exp_y, exp_m, exp_d);
//        cookie_string += "; expires=" + expires.toGMTString();
//    }

//    if (path)
//        cookie_string += "; path=" + escape(path);

//    if (domain)
//        cookie_string += "; domain=" + escape(domain);

//    document.cookie = cookie_string;
//}

function goSort() {
    var value = document.getElementById('cmbSortOptions').value;
    var baseURL = document.getElementById('baseURLWithoutSort').value;
    var value2 = document.getElementById('cmbItemsPerPage').value;
    var url = baseURL + '&page_items=' + value2 + '&sort_option=' + value;

//    set_cookie("page_items", value2, 2050, 01, 15, "", ".onlynaturalpet.com");
//    set_cookie("sort_option", value, 2050, 01, 15, "", ".onlynaturalpet.com");

    window.location.href = url;
}

function goSort3() {
    var value = document.getElementById('cmbSortOptions2').value;
    var baseURL = document.getElementById('baseURLWithoutSort').value;
    var value2 = document.getElementById('cmbItemsPerPage2').value;
    var url = baseURL + '&page_items=' + value2 + '&sort_option=' + value;

//    set_cookie("page_items", value2, 2050, 01, 15, "", ".onlynaturalpet.com");
//    set_cookie("sort_option", value, 2050, 01, 15, "", ".onlynaturalpet.com");

    window.location.href = url;
}

function goSort2(url) {

    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;
    }
}