window.addEvent("domready", SetPicker);

function SetPicker()
{

    var oDate = new Date();
    oDate = new Date(oDate.getTime() + 86400000/2);
    
    var oForm = $("OWievDateForm");
    var oList = oForm.getElementsByTagName("input");
    
    if (oList.length<0)
        return false;
    
    var oOptions = 
    {
        format: "d.m.Y", 
        allowEmpty: false, 
        pickerClass: "datepicker_dashboard",
        inputOutputFormat: "Y-m-d",
        onSelect: function (oDate) 
        {
            var cNewLocation = "";
            
            cNewLocation = window.location.toString();
            
            if (cNewLocation.charAt(cNewLocation.length-1)!="/")
                cNewLocation += "/";
            
            if (cNewLocation.match("[0-9]{4}/[0-9]{2}/[0-9]{2}/$"))
                cNewLocation = cNewLocation.substr(0, cNewLocation.length-11);
            
            cNewLocation += oDate.getFullYear() + "/";
            cNewLocation += (oDate.getMonth()<9 ? "0" : "") + (oDate.getMonth()+1) + "/";
            cNewLocation += (oDate.getDate()<10 ? "0" : "") + oDate.getDate();
            
            window.location = cNewLocation;
            //alert();
        },
        toggleElements: "#OWievDateForm img",
        maxDate: oDate,
        minDate: new Date("1970-01-01")
    };
    
    new DatePicker(oList.item(0), oOptions);

    return true;
}
