var issues = new Array(
    '12/06/09',         '11/13/09',
    '12/06/09 - T',     '10/27/09',
    '12/13/09',         '11/20/09',
    '12/20/09',         '11/27/09',
    '12/27/09',         '12/06/09',
    '01/03/10',         '12/11/09',
    '01/10/10',         '12/18/09',
    '01/17/10',         '12/26/09',
    '01/24/10',         '01/01/10',
    '01/31/10',         '01/08/10',
    '02/07/10',         '01/15/10',
    '02/14/10',         '01/22/10',
    '02/21/10',         '01/29/10',
    '02/28/10',         '02/05/10',
    '02/28/10 - T',     '01/19/10',
    '03/07/10',         '02/12/10',
    '03/14/10',         '02/19/10',
    '03/14/10 - T',     '02/02/10',
    '03/21/10',         '02/26/10',
    '03/28/10',         '03/05/10',
    '03/28/10 - T',     '02/16/10',
    '04/04/10',         '03/12/10',
    '04/11/10',         '03/19/10',
    '04/11/10 - T',     '03/02/10',
    '04/18/10',         '03/26/10',
    '04/25/10',         '04/02/10',
    '04/25/10 - T',     '03/16/10',
    '05/02/10',         '04/09/10',
    '05/02/10 - T',     '03/23/10',
    '05/09/10',         '04/16/10',
    '05/16/10',         '04/23/10',
    '05/23/10',         '04/30/10',
    '05/23/10 - T',     '04/13/10',
    '05/30/10',         '05/07/10',
    '06/06/10',         '05/14/10',
    '06/13/10',         '05/21/10',
    '06/20/10',         '05/28/10',
    '06/27/10',         '06/04/10',
    '07/04/10',         '06/11/10',
    '07/11/10',         '06/18/10',
    '07/18/10',         '06/25/10',
    '07/25/10',         '07/02/10',
    '08/01/10',         '07/09/10',
    '08/08/10',         '07/16/10',
    '08/15/10',         '07/23/10',
    '08/22/10',         '07/30/10',
    '08/22/10 - T',     '07/13/10',
    '08/29/10',         '08/06/10',
    '09/05/10',         '08/13/10',
    '09/12/10',         '08/20/10',
    '09/12/10 - T',     '08/03/10',
    '09/19/10',         '08/27/10',
    '09/26/10',         '09/03/10',
    '09/26/10 - T',     '08/17/10',
    '10/03/10',         '09/10/10',
    '10/03/10 - T',     '08/24/10',
    '10/10/10',         '09/17/10',
    '10/17/10',         '09/24/10',
    '10/17/10 - T',     '09/07/10',
    '10/24/10',         '10/01/10',
    '10/31/10',         '10/08/10',
    '11/07/10',         '10/15/10',
    '11/07/10 - T',     '09/28/10',
    '11/14/10',         '10/22/10',
    '11/21/10',         '10/29/10',
    '11/21/10 - T',     '10/12/10',
    '11/28/10',         '11/05/10',
    '12/05/10',         '11/12/10',
    '12/05/10 - T',     '10/26/10',
    '12/12/10',         '11/19/10',
    '12/19/10',         '11/26/10',
    '12/26/10',         '12/03/10'
);



function buildIssue() {
    var issue, opts, now, date, future, arg, l, check, month, day, year;

    issue = document.getElementById('issue');
    if (!issue) { return; }
    opts = issue.options;
    if (!opts) { return; }

    issue.selectedIndex = 0;
    opts.length = 1;

    now = new Date();
    date = new Date();
    future = new Date();
    future.setTime(now.getTime() + 3600000 * 24 * 30 * 3); // 3 months in future
    now.setTime(now.getTime() - 3600000 * 24 * 12); // 12 days in past

    arg = buildIssue.arguments[1];
    if (!arg || !arg.length) { arg = ''; }

    l = issues.length;
    for (i = 0 ; i < l ; i = i + 2) {
        check = issues[i+1];
        if (check.length != 8) { continue; }

        month = check.substring(0, 2);
        day = check.substring(3, 5);
        year = "20" + check.substring(6, 8);
        
        date.setMonth(parseInt(month, 10) - 1);
        date.setDate(parseInt(day, 10));
        date.setYear(parseInt(year));
        
        if ((date >= now) && (date < future)) {
            sel = ((arg == issues[i]) ? true : false);
    
            opts[opts.length] = new Option(issues[i], issues[i], sel, sel);
        }
    }
}


function verifyReplacement() {
    if (confirm('Only select “Yes” if you are submitting files which should replace files already submitted for this issue.')) { return; }
    
    document.uploadform.replacement[0].checked = false;
    document.uploadform.replacement[1].checked = true;
}


function validate() {
    var obj;
    
    if (!verifyEmail()) { return false; }
    
    obj = document.getElementById('reservation_number');
    if (!obj) { return false; }
    
//  if (obj.value.match('^[0-9]{10}_[0-9]{1,2}$')) { return true; }
//  if (obj.value.match('^[0-9]{10}-[0-9]{3}-[0-9]{3}$')) { return true; }
    if (obj.value.match('^[0-9]{10}.*')) { return true; }

    alert('Please enter a 12 digit PPI number or 18 digit SAP number.');
    return false;
}


function anotherClicked() {
    document.anotherform.submit();
}