

function make_wb_url(action, args){
    var url = "" + window.location.protocol + "//" + window.location.hostname + window.location.pathname + "?";
    var arg_value = "";
    var url_args = get_dayhistory_args();

    if (args.pg == undefined ) {
        url_args.pg = "1";
    } 
    else {
        url_args.pg = args.pg;        
    }

    for (var a in args) {
        switch (action) {
            case 'set':
                url_args[a] = args[a];
                break;
            case 'add':
                if (url_args[a] != "") {
                    url_args[a] += ",";    
                }
                url_args[a] += args[a];

                break;
            case 'remove':

                if ((args[a] == null) || (args[a] == "")) {
                    arg_value = ""; // remove parameter
                }
                else {
                    arg_value = url_args[a].replace(args[a], "");
                    arg_value = arg_value.replace(/^,|,$/, "");
                    arg_value = arg_value.replace(/,,/, ",");
                }
                
                
                url_args[a] = arg_value;
                break;
            default:
                break;
        }
    }
    
    var url = "" + window.location.protocol + "//" + window.location.hostname + window.location.pathname + "?";
    for (var p in url_args) {
        
        if ((url_args[p] != null) && (url_args[p] != "")) {
            url += "&" + p + "=" + url_args[p];
        }
        
        
    }
    return encodeURI(url);

} // end make_wb_url



function make_day_str (day, format) {
    var arg_day = day;
    var d = new Date();
    var yr = parseInt(d.getFullYear());
    var is_year = false;
    if (arg_day && (arg_day != "")) {
        arg_day = $.trim(decodeURIComponent(arg_day).replace(/\//g,"-")); //normalize the string
//deb("cleaned:"+arg_day+":");        
        var day_parts = arg_day.split("-");
        if (day_parts.length > 2) {       // the year is specified
            is_year = true;
            // the following is because getFullYear prepends 20 for years before 70
            yr = parseInt(day_parts[2]); // for now assume year is the third part
            if ((yr > 10) && (yr < 100)) { 
                yr = 1900 + yr;
            }
            arg_day = day_parts[0] + "-" + day_parts[1] + "-" + yr;
//deb(":"+arg_day+":");        
            d = new Date.parseString(arg_day);                            
        }
        else { 
            // if no year is specified use a leap year to parse the day
            // otherwise Date may fail if day is 2-29
            d = new Date.parseString(arg_day+ "-"+"2000");    
        }
    }
    
//deb("format:"+format) ;   
    if (!format) {
        return d;
    }
    else if (format == "yyyy") {
        return ""+yr;
    }
    else {
        return d.format(format);
    }
}

