﻿
function insertParam(key, value, redirect) {
    key = escape(key); value = escape(value);
    var kvp = document.location.search.substr(1).split('&');
    var i = kvp.length;
    var x;
    //updates if it exists
    while (i--) {
        x = kvp[i].split('=');

        if (x[0] == key) {
            x[1] = value;
            kvp[i] = x.join('=');
            break;
        }
    }
    //if it didn't exist
    if (i < 0) {
        if (kvp[0] == '')
            kvp[0] = [key, value].join('=');
        else
            kvp[kvp.length] = [key, value].join('=');
    }
    var newurl;
    //this will reload the page, it's likely better to store this until finished
    if (kvp.length == 1) {
        newurl = kvp[0];
    } else {
     newurl = kvp.join('&');
    }
    if (redirect)
        document.location.search = newurl;
    else {
        return (document.location + '').replace("#","") + '?' + newurl;
    }
}
function scrollWin(towhere, time) {
    $('html, body').animate({
        scrollTop: $(towhere).offset().top
    }, time);
}
