﻿// ProductFilter

function SubmitFilter() {

    $.query = $.query.load(location.href);
    var display = $.query.get('display');

    window.location.hash = $('form').serialize() + '&display=' + display;
}

function ChangeCategory(cat) {
	if (window.location.href.indexOf('https://') >= 0){
		//cart url: https://deurklinkshop-nl.intrastores.com/default.asp?action=ShowCart
		var loc = '' + window.location;
		window.location = loc.replace(/https:\/\/(\w+)-(\w+)(.+)/, 'http://www.$1.$2/?action=ProductSelector#ProductGroupID=' + cat);
	}		
    else if (window.location.href.indexOf('ProductSelector') > 0) {
        window.location.hash = 'ProductGroupID=' + cat;
    }
    else {
        $.query = $.query.load(location.href);
        var x = $.query.set('action', 'ProductSelector').toString();
        window.location = x + '#ProductGroupID=' + cat;
    }
}

function GlobalSearch(keyword) {
    if (window.location.href.indexOf('https://') >= 0) {
        //cart url: https://deurklinkshop-nl.intrastores.com/default.asp?action=ShowCart
        var loc = '' + window.location;
        window.location = loc.replace(/https:\/\/(\w+)-(\w+)(.+)/, 'http://www.$1.$2/?action=ProductSelector#ProductGroupID=0&SearchText=' + keyword);
    }
    else if (window.location.href.indexOf('ProductSelector') > 0) {
        window.location.hash = 'ProductGroupID=0&SearchText=' + keyword;
    }
    else {
        $.query = $.query.load(location.href);
        var x = $.query.set('action', 'ProductSelector').toString();
        window.location = x + '#ProductGroupID=0&SearchText=' + keyword;
    }
}

/////  FilterResult

function getPage(page) {
    $.query = $.query.load(location.href);
    var x = $.query.set('page', page).toString();
    window.location.hash = x.replace('?', '');
}
function changeSorting(col, asc) {
    $.query = $.query.load(location.href);
    var x = $.query.set('sortAscending', asc.toString()).set('sortColumn', col).toString();
    window.location.hash = x.replace('?', '');
}
function changeDisplay(display) {
    $.query = $.query.load(location.href);
    var x = $.query.set('display', display).toString();
    window.location.hash = x.replace('?', '');
}
function changePageSize(size) {
    $.query = $.query.load(location.href);
    var x = $.query.set('pageSize', size).toString();
    window.location.hash = x.replace('?', '');
}
