smmerz / MMAF2

// ==UserScript==
// @name        MMAF2
// @namespace   MarchMadnessAutoFill
// @description test
// @include     https://www.google.com/?gws_rd=ssl
// @include     https://www.google.com/
// @include     http://*.collegehoops.upickem.net/collegebasketball/framed*
// @include     http://*.collegebasketball.upickem.net/collegebasketball/framed*
// @version     1.2.3
// @grant       none
// ==/UserScript==

var location=window.location.href;
var TournamentGames=124
var Round1= [124, 117, 104, 99, 80, 81, 76, 63, 61, 48, 43, 44, 25, 20, 7, 0]
var Quarter= [[1, 2, 21, 42], [1, 3, 13, 21], [1, 4, 32, 47], [1, 5, 30, 37], [1, 6, 6, 8], [1, 7, 4, 4], [1, 8, 51, 63], [1, 9, 56, 61], [1, 10, 4, 4], [1, 11, 3, 6], [1, 12, 19, 19], [1, 13, 4, 4], [1, 14, 0, 0], [1, 15, 0, 0], [1, 16, 0, 0], [2, 3, 23, 37], [2, 4, 2, 6], [2, 5, 0, 3], [2, 6, 23, 29], [2, 7, 53, 73], [2, 8, 2, 5], [2, 9, 0, 1], [2, 10, 26, 44], [2, 11, 12, 13], [2, 12, 1, 1], [2, 13, 0, 0], [2, 14, 0, 0], [2, 15, 0, 0], [2, 16, 0, 0], [3, 4, 2, 5], [3, 5, 2, 3], [3, 6, 38, 66], [3, 7, 7, 12], [3, 8, 1, 1], [3, 9, 1, 1], [3, 10, 9, 13], [3, 11, 25, 38], [3, 12, 0, 0], [3, 13, 0, 0], [3, 14, 0, 0], [3, 15, 1, 1], [3, 16, 0, 0], [4, 5, 36, 66], [4, 6, 2, 3], [4, 7, 2, 4], [4, 8, 3, 8], [4, 9, 2, 2], [4, 10, 2, 2], [4, 11, 0, 0], [4, 12, 21, 33], [4, 13, 0, 0], [4, 14, 0, 0], [4, 15, 0, 0], [4, 16, 0, 0], [5, 6, 1, 1], [5, 7, 0, 0], [5, 8, 0, 2], [5, 9, 1, 2], [5, 10, 1, 1], [5, 11, 0, 0], [5, 12, 0, 0], [5, 13, 11, 14], [5, 14, 0, 0], [5, 15, 0, 0], [5, 16, 0, 0], [6, 7, 3, 6], [6, 8, 0, 1], [6, 9, 0, 0], [6, 10, 4, 6], [6, 11, 0, 0], [6, 12, 0, 0], [6, 13, 0, 0], [6, 14, 13, 15], [6, 15, 0, 0], [6, 16, 0, 0], [7, 8, 0, 1], [7, 9, 0, 0], [7, 10, 0, 0], [7, 11, 0, 3], [7, 12, 0, 0], [7, 13, 0, 0], [7, 14, 1, 1], [7, 15, 2, 3], [7, 16, 0, 0], [8, 9, 0, 0], [8, 10, 0, 0], [8, 11, 0, 0], [8, 12, 0, 1], [8, 13, 1, 1], [8, 14, 0, 0], [8, 15, 0, 0], [8, 16, 0, 0], [9, 10, 0, 0], [9, 11, 0, 0], [9, 12, 0, 0], [9, 13, 1, 1], [9, 14, 0, 0], [9, 15, 0, 0], [9, 16, 0, 0], [10, 11, 0, 2], [10, 12, 0, 0], [10, 13, 0, 0], [10, 14, 1, 1], [10, 15, 4, 4], [10, 16, 0, 0], [11, 12, 0, 0], [11, 13, 0, 0], [11, 14, 5, 5], [11, 15, 0, 0], [11, 16, 0, 0], [12, 13, 8, 11], [12, 14, 0, 0], [12, 15, 0, 0], [12, 16, 0, 0], [13, 14, 0, 0], [13, 15, 0, 0], [13, 16, 0, 0], [14, 15, 0, 0], [14, 16, 0, 0], [15, 16, 0, 0]]
var FinalFour= [[1, 2, 12, 17], [1, 3, 3, 7], [1, 4, 7, 9], [1, 5, 4, 4], [1, 6, 1, 2], [1, 7, 1, 2], [1, 8, 1, 2], [1, 9, 1, 1], [1, 10, 0, 0], [1, 11, 0, 0], [1, 12, 0, 0], [1, 13, 0, 0], [1, 14, 0, 0], [1, 15, 0, 0], [1, 16, 0, 0], [2, 3, 6, 10], [2, 4, 1, 1], [2, 5, 0, 1], [2, 6, 1, 2], [2, 7, 0, 0], [2, 8, 0, 2], [2, 9, 0, 0], [2, 10, 0, 0], [2, 11, 1, 1], [2, 12, 0, 0], [2, 13, 0, 0], [2, 14, 0, 0], [2, 15, 0, 0], [2, 16, 0, 0], [3, 4, 2, 2], [3, 5, 0, 0], [3, 6, 0, 0], [3, 7, 0, 0], [3, 8, 1, 1], [3, 9, 0, 0], [3, 10, 0, 0], [3, 11, 1, 1], [3, 12, 0, 0], [3, 13, 0, 0], [3, 14, 0, 0], [3, 15, 0, 0], [3, 16, 0, 0], [4, 5, 1, 1], [4, 6, 0, 1], [4, 7, 0, 0], [4, 8, 0, 0], [4, 9, 0, 0], [4, 10, 0, 0], [4, 11, 0, 0], [4, 12, 0, 0], [4, 13, 0, 0], [4, 14, 0, 0], [4, 15, 0, 0], [4, 16, 0, 0], [5, 6, 0, 0], [5, 7, 0, 0], [5, 8, 1, 1], [5, 9, 0, 0], [5, 10, 0, 0], [5, 11, 0, 0], [5, 12, 0, 0], [5, 13, 0, 0], [5, 14, 0, 0], [5, 15, 0, 0], [5, 16, 0, 0], [6, 7, 0, 0], [6, 8, 0, 0], [6, 9, 0, 0], [6, 10, 0, 0], [6, 11, 0, 0], [6, 12, 0, 0], [6, 13, 0, 0], [6, 14, 0, 0], [6, 15, 0, 0], [6, 16, 0, 0], [7, 8, 1, 1], [7, 9, 0, 0], [7, 10, 0, 0], [7, 11, 0, 0], [7, 12, 0, 0], [7, 13, 0, 0], [7, 14, 0, 0], [7, 15, 0, 0], [7, 16, 0, 0], [8, 9, 0, 0], [8, 10, 0, 0], [8, 11, 1, 1], [8, 12, 0, 0], [8, 13, 0, 0], [8, 14, 0, 0], [8, 15, 0, 0], [8, 16, 0, 0], [9, 10, 0, 0], [9, 11, 0, 0], [9, 12, 0, 0], [9, 13, 0, 0], [9, 14, 0, 0], [9, 15, 0, 0], [9, 16, 0, 0], [10, 11, 0, 0], [10, 12, 0, 0], [10, 13, 0, 0], [10, 14, 0, 0], [10, 15, 0, 0], [10, 16, 0, 0], [11, 12, 0, 0], [11, 13, 0, 0], [11, 14, 0, 0], [11, 15, 0, 0], [11, 16, 0, 0], [12, 13, 0, 0], [12, 14, 0, 0], [12, 15, 0, 0], [12, 16, 0, 0], [13, 14, 0, 0], [13, 15, 0, 0], [13, 16, 0, 0], [14, 15, 0, 0], [14, 16, 0, 0], [15, 16, 0, 0]]
var ChampMean=71.4032258065;
var ChampSTD=9.49611071052;
var ChampDif=7.06451612903;
var WinnerSet=[];
var Printvar='';
var ifrm_height = '195px';
var ifrm_width = '450px';
var t1_1 = ''
var t1_2 = ''
var t1_3 = ''
var t1_4 = ''
var t1_5 = ''
var t1_6 = ''
var t1_7 = ''
var t1_8 = ''
var t1_9 = ''
var t1_10 = ''
var t1_11 = ''
var t1_12 = ''
var t1_13 = ''
var t1_14 = ''
var t1_15 = ''
var t1_16 = ''
var t2_1 = ''
var t2_2 = ''
var t2_3 = ''
var t2_4 = ''
var t2_5 = ''
var t2_6 = ''
var t2_7 = ''
var t2_8 = ''
var t2_9 = ''
var t2_10 = ''
var t2_11 = ''
var t2_12 = ''
var t2_13 = ''
var t2_14 = ''
var t2_15 = ''
var t2_16 = ''
var t3_1 = ''
var t3_2 = ''
var t3_3 = ''
var t3_4 = ''
var t3_5 = ''
var t3_6 = ''
var t3_7 = ''
var t3_8 = ''
var t3_9 = ''
var t3_10 = ''
var t3_11 = ''
var t3_12 = ''
var t3_13 = ''
var t3_14 = ''
var t3_15 = ''
var t3_16 = ''
var t4_1 = ''
var t4_2 = ''
var t4_3 = ''
var t4_4 = ''
var t4_5 = ''
var t4_6 = ''
var t4_7 = ''
var t4_8 = ''
var t4_9 = ''
var t4_10 = ''
var t4_11 = ''
var t4_12 = ''
var t4_13 = ''
var t4_14 = ''
var t4_15 = ''
var t4_16 = ''

function gen_id(section,seed)
{
    if (seed==1 && section==1){return t1_1};
    if (seed==2 && section==1){return t1_2};
    if (seed==3 && section==1){return t1_3};
    if (seed==4 && section==1){return t1_4};      
    if (seed==5 && section==1){return t1_5};
    if (seed==6 && section==1){return t1_6};      
    if (seed==7 && section==1){return t1_7};
    if (seed==8 && section==1){return t1_8};      
    if (seed==9 && section==1){return t1_9};
    if (seed==10 && section==1){return t1_10};      
    if (seed==11 && section==1){return t1_11};
    if (seed==12 && section==1){return t1_12};
    if (seed==13 && section==1){return t1_13};
    if (seed==14 && section==1){return t1_14};
    if (seed==15 && section==1){return t1_15};
    if (seed==16 && section==1){return t1_16};   
    if (seed==1 && section==2){return t2_1};
    if (seed==2 && section==2){return t2_2};
    if (seed==3 && section==2){return t2_3};
    if (seed==4 && section==2){return t2_4};      
    if (seed==5 && section==2){return t2_5};
    if (seed==6 && section==2){return t2_6};      
    if (seed==7 && section==2){return t2_7};
    if (seed==8 && section==2){return t2_8};      
    if (seed==9 && section==2){return t2_9};
    if (seed==10 && section==2){return t2_10};      
    if (seed==11 && section==2){return t2_11};
    if (seed==12 && section==2){return t2_12};
    if (seed==13 && section==2){return t2_13};
    if (seed==14 && section==2){return t2_14};
    if (seed==15 && section==2){return t2_15};
    if (seed==16 && section==2){return t2_16};        
    if (seed==1 && section==3){return t3_1};
    if (seed==2 && section==3){return t3_2};
    if (seed==3 && section==3){return t3_3};
    if (seed==4 && section==3){return t3_4};      
    if (seed==5 && section==3){return t3_5};
    if (seed==6 && section==3){return t3_6};      
    if (seed==7 && section==3){return t3_7};
    if (seed==8 && section==3){return t3_8};      
    if (seed==9 && section==3){return t3_9};
    if (seed==10 && section==3){return t3_10};      
    if (seed==11 && section==3){return t3_11};
    if (seed==12 && section==3){return t3_12};
    if (seed==13 && section==3){return t3_13};
    if (seed==14 && section==3){return t3_14};
    if (seed==15 && section==3){return t3_15};
    if (seed==16 && section==3){return t3_16};        
    if (seed==1 && section==4){return t4_1};
    if (seed==2 && section==4){return t4_2};
    if (seed==3 && section==4){return t4_3};
    if (seed==4 && section==4){return t4_4};      
    if (seed==5 && section==4){return t4_5};
    if (seed==6 && section==4){return t4_6};      
    if (seed==7 && section==4){return t4_7};
    if (seed==8 && section==4){return t4_8};      
    if (seed==9 && section==4){return t4_9};
    if (seed==10 && section==4){return t4_10};      
    if (seed==11 && section==4){return t4_11};
    if (seed==12 && section==4){return t4_12};
    if (seed==13 && section==4){return t4_13};
    if (seed==14 && section==4){return t4_14};
    if (seed==15 && section==4){return t4_15};
    if (seed==16 && section==4){return t4_16};        
};


function randomIntFromInterval(min,max)
{
    return Math.floor(Math.random()*(max-min+1)+min);
};

function championshipScore(){
  var dif=randomIntFromInterval(2,ChampDif*2)/2
  var base = ((Math.random() + Math.random() + Math.random() + Math.random() + Math.random() + Math.random()) - 3) * ChampSTD + ChampMean
  return [Math.floor( base + dif), Math.floor(base - dif)];
};

function round1PickWinner(wins,total,seed1,seed2,team1,team2,push_){
    if (randomIntFromInterval(1,total) <= wins){
        if (push_ == 'Y'){
            WinnerSet.push(seed1)}
        return [team1,seed1,'T',''];
        }
    if (push_ == 'Y'){
        WinnerSet.push(seed2)}
    return [team2,seed2,'B',''];
};

function pickWinner(seed1,seed2,team1,team2,round,push_){
    probSet=[];
    if (round == 'Q'){
        probSet=Quarter}
    else if (round == 'F'){
        probSet=FinalFour};   
    if (seed1 == seed2){
        var coinflip = randomIntFromInterval(1,2);
        if (push_ == 'Y'){
            if (coinflip == 1){
                WinnerSet.push(seed1+'(1)');
                return [team1,seed1,'T','(1)'];}
            else if (coinflip == 2){
                WinnerSet.push(seed2+'(2)');
                return [team2,seed2,'B','(2)'];}
            }
    }else if (seed1 > seed2){
        var seed3 = seed1;
        seed1 = seed2;
        seed2 = seed3;
        var stat;
        for (stat in probSet){
            if (seed1 == probSet[stat][0]){
                if (seed2 == probSet[stat][1]){
                    if (probSet[stat][3]!= 0){
                        if (probSet[stat][2]==0){
                            team_and_seed=round1PickWinner(1,(probSet[stat][3]+1),seed1,seed2,team2,team1,push_);
                            if (team_and_seed[1] == seed1){
//                                WinnerSet.push(seed1);
                                return [team_and_seed[0],team_and_seed[1],'B',''];
                            }else if(team_and_seed[1] == seed2){
//                                WinnerSet.push(seed2);
                                return [team_and_seed[0],team_and_seed[1],'T',''];
                            }    
                        }else if(probSet[stat][2] == probSet[stat][3]){
                            team_and_seed=round1PickWinner(probSet[stat][2],(probSet[stat][3]+1),seed1,seed2,team2,team1,push_);
                            if (team_and_seed[1] == seed1){
//                                WinnerSet.push(seed1);
                                return [team_and_seed[0],team_and_seed[1],'B',''];
                            }else if(team_and_seed[1] == seed2){
//                                WinnerSet.push(seed2);
                                return [team_and_seed[0],team_and_seed[1],'T',''];
                            }                       
                        }else if(probSet[stat][2] != probSet[stat][3]){
                            team_and_seed=round1PickWinner(probSet[stat][2],probSet[stat][3],seed1,seed2,team2,team1,push_);
                            if (team_and_seed[1] == seed1){
//                                WinnerSet.push(seed1);
                                return [team_and_seed[0],team_and_seed[1],'B',''];
                            }else if(team_and_seed[1] == seed2){
//                                WinnerSet.push(seed2);
                                return [team_and_seed[0],team_and_seed[1],'T',''];
                            }
                        }
                    }else{
                        team_and_seed=round1PickWinner(1,2,seed1,seed2,team2,team1,push_);
                        if (team_and_seed[1] == seed1){
//                            WinnerSet.push(seed1);
                            return [team_and_seed[0],team_and_seed[1],'B',''];
                        }else if(team_and_seed[1] == seed2){
//                            WinnerSet.push(seed2);
                            return [team_and_seed[0],team_and_seed[1],'T',''];       
                        }
                    }
                }
            }
        }
    }else{
//        console.log('else case')
        var stat;
        for (stat in probSet){
            if (seed1 == probSet[stat][0]){
                if (seed2 == probSet[stat][1]){
//                    console.log(probSet[stat]);
                    if (probSet[stat][3]!= 0){
//                        console.log('else case 2');
                        if (probSet[stat][2]==0){
                            team_and_seed=round1PickWinner(1,(probSet[stat][3]+1),seed1,seed2,team1,team2,push_);
                            if (team_and_seed[1] == seed1){
//                                WinnerSet.push(seed1);
                                return [team_and_seed[0],team_and_seed[1],'T',''];
                            }else if(team_and_seed[1] == seed2){
//                                WinnerSet.push(seed2);
                                return [team_and_seed[0],team_and_seed[1],'B',''];
                            }    
                        }else if(probSet[stat][2] == probSet[stat][3]){
                            team_and_seed=round1PickWinner(probSet[stat][2],(probSet[stat][3]+1),seed1,seed2,team1,team2,push_);
                            if (team_and_seed[1] == seed1){
//                                WinnerSet.push(seed1);
                                return [team_and_seed[0],team_and_seed[1],'T',''];
                            }else if(team_and_seed[1] == seed2){
//                                WinnerSet.push(seed2);
                                return [team_and_seed[0],team_and_seed[1],'B',''];
                            }                       
                        }else if(probSet[stat][2]!=probSet[stat][3]){
//                            console.log('step 3')
                            team_and_seed=round1PickWinner(probSet[stat][2],(probSet[stat][3]),seed1,seed2,team1,team2,push_);
                            if (team_and_seed[1] == seed1){
//                                WinnerSet.push(seed1);
                                return [team_and_seed[0],team_and_seed[1],'T',''];
                            }else if(team_and_seed[1] == seed2){
//                                WinnerSet.push(seed2);
                                return [team_and_seed[0],team_and_seed[1],'B',''];
                            }
                        }
                    }else{
//                        console.log('else case 2');
                        team_and_seed=round1PickWinner(1,2,seed1,seed2,team1,team2,push_);
//                        console.log(team_and_seed);
                        if (team_and_seed[1] == seed1){
//                            WinnerSet.push(seed1);
                            return [team_and_seed[0],team_and_seed[1],'T',''];
                        }else if(team_and_seed[1] == seed2){
//                            WinnerSet.push(seed2);
                            return [team_and_seed[0],team_and_seed[1],'B',''];
                        }
                    }
                }
            }
        }
    }
};

function setCookie(cname, cvalue, exdays) {
    var d = new Date();
    d.setTime(d.getTime() + (exdays*24*60*60*1000));
    var expires = 'expires='+d.toUTCString();
    document.cookie = cname + '=' + cvalue + '; ' + expires;
};



//setCookie("storedsim","",1)
//setCookie("round_number","R64",1)

function getCookie(cname) {
    var name = cname + "=";
    var ca = document.cookie.split(';');
    for(var i=0; i<ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1);
        if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
    }
    return "";
};

//setCookie("username", '')
setCookie('round_number','R4')
//setCookie('results_r2','')

function checkCookie() {
    var user = getCookie("username");
    if (user != "") {
        var impossible = 'nothing'
    } else {
        user = prompt("Please enter your name:", "");
        if (user != "" && user != null) {
            setCookie("username", user, 365);
        }
    }
};

if (location == 'https://www.google.com/?gws_rd=ssl' || location == 'https://www.google.com/'){
    checkCookie()
    var PickName = getCookie("username")}





function checkSim() {
    var sim = getCookie("storedsim");
    if (sim != "") {
        return sim;
    } else {
        var newsim = simulate()
        setCookie("storedsim",newsim,1)
        return newsim
    }
};


function simulate() {

    if (getCookie('round_number') == 'R64' || getCookie('round_number') == ''){
        R1 = 'Y'
        R2 = 'Y'
        R3 = 'Y'
        R4 = 'Y'
        R5 = 'Y'
        R6 = 'Y'

        var winner1_1 = round1PickWinner(Round1[0],TournamentGames,1,16,t1_1,t1_16,R1);
        var winner1_8 = round1PickWinner(Round1[7],TournamentGames,8,9, t1_8,t1_9,R1);
        var winner1_5 = round1PickWinner(Round1[4],TournamentGames,5,12,t1_5,t1_12,R1);
        var winner1_4 = round1PickWinner(Round1[3],TournamentGames,4,13,t1_4,t1_13,R1);
        var winner1_6 = round1PickWinner(Round1[5],TournamentGames,6,11,t1_6,t1_11,R1);
        var winner1_3 = round1PickWinner(Round1[2],TournamentGames,3,14,t1_3,t1_14,R1);
        var winner1_7 = round1PickWinner(Round1[6],TournamentGames,7,10,t1_7,t1_10,R1);
        var winner1_2 = round1PickWinner(Round1[1],TournamentGames,2,15,t1_2,t1_15,R1);

        var winner1_18 = pickWinner(winner1_1[1],winner1_8[1],winner1_1[0],winner1_8[0],'Q',R2);
        var winner1_54 = pickWinner(winner1_5[1],winner1_4[1],winner1_5[0],winner1_4[0],'Q',R2);
        var winner1_63 = pickWinner(winner1_6[1],winner1_3[1],winner1_6[0],winner1_3[0],'Q',R2);
        var winner1_72 = pickWinner(winner1_7[1],winner1_2[1],winner1_7[0],winner1_2[0],'Q',R2);

        var winner1_1854 = pickWinner(winner1_18[1],winner1_54[1],winner1_18[0],winner1_54[0],'Q',R3);
        var winner1_6372 = pickWinner(winner1_63[1],winner1_72[1],winner1_63[0],winner1_72[0],'Q',R3);

        var winner1 = pickWinner(winner1_1854[1],winner1_6372[1],winner1_1854[0],winner1_6372[0],'Q',R4);

        var winner2_1 = round1PickWinner(Round1[0],TournamentGames,1,16,t2_1,t2_16,R1);
        var winner2_8 = round1PickWinner(Round1[7],TournamentGames,8,9, t2_8,t2_9,R1);
        var winner2_5 = round1PickWinner(Round1[4],TournamentGames,5,12,t2_5,t2_12,R1);
        var winner2_4 = round1PickWinner(Round1[3],TournamentGames,4,13,t2_4,t2_13,R1);
        var winner2_6 = round1PickWinner(Round1[5],TournamentGames,6,11,t2_6,t2_11,R1);
        var winner2_3 = round1PickWinner(Round1[2],TournamentGames,3,14,t2_3,t2_14,R1);
        var winner2_7 = round1PickWinner(Round1[6],TournamentGames,7,10,t2_7,t2_10,R1);
        var winner2_2 = round1PickWinner(Round1[1],TournamentGames,2,15,t2_2,t2_15,R1);

        var winner2_18 = pickWinner(winner2_1[1],winner2_8[1],winner2_1[0],winner2_8[0],'Q',R2);
        var winner2_54 = pickWinner(winner2_5[1],winner2_4[1],winner2_5[0],winner2_4[0],'Q',R2);
        var winner2_63 = pickWinner(winner2_6[1],winner2_3[1],winner2_6[0],winner2_3[0],'Q',R2);
        var winner2_72 = pickWinner(winner2_7[1],winner2_2[1],winner2_7[0],winner2_2[0],'Q',R2);

        var winner2_1854 = pickWinner(winner2_18[1],winner2_54[1],winner2_18[0],winner2_54[0],'Q',R3);
        var winner2_6372 = pickWinner(winner2_63[1],winner2_72[1],winner2_63[0],winner2_72[0],'Q',R3);

        var winner2 = pickWinner(winner2_1854[1],winner2_6372[1],winner2_1854[0],winner2_6372[0],'Q',R4);

        var winner3_1 = round1PickWinner(Round1[0],TournamentGames,1,16,t3_1,t3_16,R1);
        var winner3_8 = round1PickWinner(Round1[7],TournamentGames,8,9, t3_8,t3_9,R1);
        var winner3_5 = round1PickWinner(Round1[4],TournamentGames,5,12,t3_5,t3_12,R1);
        var winner3_4 = round1PickWinner(Round1[3],TournamentGames,4,13,t3_4,t3_13,R1);
        var winner3_6 = round1PickWinner(Round1[5],TournamentGames,6,11,t3_6,t3_11,R1);
        var winner3_3 = round1PickWinner(Round1[2],TournamentGames,3,14,t3_3,t3_14,R1);
        var winner3_7 = round1PickWinner(Round1[6],TournamentGames,7,10,t3_7,t3_10,R1);
        var winner3_2 = round1PickWinner(Round1[1],TournamentGames,2,15,t3_2,t3_15,R1);

        var winner3_18 = pickWinner(winner3_1[1],winner3_8[1],winner3_1[0],winner3_8[0],'Q',R2);
        var winner3_54 = pickWinner(winner3_5[1],winner3_4[1],winner3_5[0],winner3_4[0],'Q',R2);
        var winner3_63 = pickWinner(winner3_6[1],winner3_3[1],winner3_6[0],winner3_3[0],'Q',R2);
        var winner3_72 = pickWinner(winner3_7[1],winner3_2[1],winner3_7[0],winner3_2[0],'Q',R2);

        var winner3_1854 = pickWinner(winner3_18[1],winner3_54[1],winner3_18[0],winner3_54[0],'Q',R3);
        var winner3_6372 = pickWinner(winner3_63[1],winner3_72[1],winner3_63[0],winner3_72[0],'Q',R3);

        var winner3 = pickWinner(winner3_1854[1],winner3_6372[1],winner3_1854[0],winner3_6372[0],'Q',R4);

        var winner4_1 = round1PickWinner(Round1[0],TournamentGames,1,16,t4_1,t4_16,R1);
        var winner4_8 = round1PickWinner(Round1[7],TournamentGames,8,9, t4_8,t4_9,R1);
        var winner4_5 = round1PickWinner(Round1[4],TournamentGames,5,12,t4_5,t4_12,R1);
        var winner4_4 = round1PickWinner(Round1[3],TournamentGames,4,13,t4_4,t4_13,R1);
        var winner4_6 = round1PickWinner(Round1[5],TournamentGames,6,11,t4_6,t4_11,R1);
        var winner4_3 = round1PickWinner(Round1[2],TournamentGames,3,14,t4_3,t4_14,R1);
        var winner4_7 = round1PickWinner(Round1[6],TournamentGames,7,10,t4_7,t4_10,R1);
        var winner4_2 = round1PickWinner(Round1[1],TournamentGames,2,15,t4_2,t4_15,R1);

        var winner4_18 = pickWinner(winner4_1[1],winner4_8[1],winner4_1[0],winner4_8[0],'Q',R2);
        var winner4_54 = pickWinner(winner4_5[1],winner4_4[1],winner4_5[0],winner4_4[0],'Q',R2);
        var winner4_63 = pickWinner(winner4_6[1],winner4_3[1],winner4_6[0],winner4_3[0],'Q',R2);
        var winner4_72 = pickWinner(winner4_7[1],winner4_2[1],winner4_7[0],winner4_2[0],'Q',R2);

        var winner4_1854 = pickWinner(winner4_18[1],winner4_54[1],winner4_18[0],winner4_54[0],'Q',R3);
        var winner4_6372 = pickWinner(winner4_63[1],winner4_72[1],winner4_63[0],winner4_72[0],'Q',R3);

        var winner4 = pickWinner(winner4_1854[1],winner4_6372[1],winner4_1854[0],winner4_6372[0],'Q',R4);

        var winner12 = pickWinner(winner1[1],winner2[1],winner1[0],winner2[0],'F',R5);
        var winner34 = pickWinner(winner3[1],winner4[1],winner3[0],winner4[0],'F',R5);
        var winner = pickWinner(winner12[1],winner34[1],winner12[0],winner34[0],'F',R6);

        champscore=championshipScore();

        setCookie("MarchMadnessWinnerSet",[winner1_1,winner1_8,winner1_5,winner1_4,winner1_6,winner1_3,winner1_7,winner1_2,winner1_18,winner1_54,winner1_63,winner1_72,winner1_1854,winner1_6372,winner1,winner2_1,winner2_8,winner2_5,winner2_4,winner2_6,winner2_3,winner2_7,winner2_2,winner2_18,winner2_54,winner2_63,winner2_72,winner2_1854,winner2_6372,winner2,winner3_1,winner3_8,winner3_5,winner3_4,winner3_6,winner3_3,winner3_7,winner3_2,winner3_18,winner3_54,winner3_63,winner3_72,winner3_1854,winner3_6372,winner3,winner4_1,winner4_8,winner4_5,winner4_4,winner4_6,winner4_3,winner4_7,winner4_2,winner4_18,winner4_54,winner4_63,winner4_72,winner4_1854,winner4_6372,winner4,winner12,winner34,winner],7);
        setCookie("MarchMadnessWinnerSpot",[winner1_1[2],winner1_8[2],winner1_5[2],winner1_4[2],winner1_6[2],winner1_3[2],winner1_7[2],winner1_2[2],winner1_18[2],winner1_54[2],winner1_63[2],winner1_72[2],winner1_1854[2],winner1_6372[2],winner1[2],winner2_1[2],winner2_8[2],winner2_5[2],winner2_4[2],winner2_6[2],winner2_3[2],winner2_7[2],winner2_2[2],winner2_18[2],winner2_54[2],winner2_63[2],winner2_72[2],winner2_1854[2],winner2_6372[2],winner2[2],winner3_1[2],winner3_8[2],winner3_5[2],winner3_4[2],winner3_6[2],winner3_3[2],winner3_7[2],winner3_2[2],winner3_18[2],winner3_54[2],winner3_63[2],winner3_72[2],winner3_1854[2],winner3_6372[2],winner3[2],winner4_1[2],winner4_8[2],winner4_5[2],winner4_4[2],winner4_6[2],winner4_3[2],winner4_7[2],winner4_2[2],winner4_18[2],winner4_54[2],winner4_63[2],winner4_72[2],winner4_1854[2],winner4_6372[2],winner4[2],winner12[2],winner34[2],winner[2]],7);            
        setCookie("MarchMadnessChampScore",champscore,7);

        var WinnerSet2=[winner1_1[1],winner1_8[1],winner1_5[1],winner1_4[1],winner1_6[1],winner1_3[1],winner1_7[1],winner1_2[1],winner2_1[1],winner2_8[1],winner2_5[1],winner2_4[1],winner2_6[1],winner2_3[1],winner2_7[1],winner2_2[1],winner3_1[1],winner3_8[1],winner3_5[1],winner3_4[1],winner3_6[1],winner3_3[1],winner3_7[1],winner3_2[1],winner4_1[1],winner4_8[1],winner4_5[1],winner4_4[1],winner4_6[1],winner4_3[1],winner4_7[1],winner4_2[1]]     
      
        var message='=SPLIT("'+PickName+','+WinnerSet+','+champscore+'",",")';
        var message2='=SPLIT("'+PickName+','+WinnerSet2+','+champscore+'",",")';
      
        
        if (getCookie('fill_style') == 'Upfront' || getCookie('fill_style') == ''){
        return "<table width=100%><tr><td><font size=2>"+'['+winner1_1[1]+','+winner1_8[1]+','+winner1_5[1]+','+winner1_4[1]+','+winner1_6[1]+','+winner1_3[1]+','+winner1_7[1]+','+winner1_2[1]+']'+'</td><td><font size=2>'+'['+winner2_1[1]+','+winner2_8[1]+','+winner2_5[1]+','+winner2_4[1]+','+winner2_6[1]+','+winner2_3[1]+','+winner2_7[1]+','+winner2_2[1]+']'+'</td><td><font size=2>'+'['+winner3_1[1]+','+winner3_8[1]+','+winner3_5[1]+','+winner3_4[1]+','+winner3_6[1]+','+winner3_3[1]+','+winner3_7[1]+','+winner3_2[1]+']'+'</td><td><font size=2>'+'['+winner4_1[1]+','+winner4_8[1]+','+winner4_5[1]+','+winner4_4[1]+','+winner4_6[1]+','+winner4_3[1]+','+winner4_7[1]+','+winner4_2[1]+']'+'</td></tr><tr><td><font size=2>'+'['+winner1_18[1]+','+winner1_54[1]+','+winner1_63[1]+','+winner1_72[1]+']'+'</td><td><font size=2>'+'['+winner2_18[1]+','+winner2_54[1]+','+winner2_63[1]+','+winner2_72[1]+']'+'</td><td><font size=2>'+'['+winner3_18[1]+','+winner3_54[1]+','+winner3_63[1]+','+winner3_72[1]+']'+'</td><td><font size=2>'+'['+winner4_18[1]+','+winner4_54[1]+','+winner4_63[1]+','+winner4_72[1]+']'+'</td></tr><tr><td><font size=2>'+'['+winner1_1854[1]+','+winner1_6372[1]+']'+'</td><td><font size=2>'+'['+winner2_1854[1]+','+winner2_6372[1]+']'+'</td><td><font size=2>'+'['+winner3_1854[1]+','+winner3_6372[1]+']'+'</td><td><font size=2>'+'['+winner4_1854[1]+','+winner4_6372[1]+']'+'</td></tr><tr><td><font size=2>'+'['+winner1[1]+']'+'</td><td><font size=2>'+'['+winner2[1]+']'+'</td><td><font size=2>'+'['+winner3[1]+']'+'</td><td><font size=2>'+'['+winner4[1]+']'+"</td></tr></font></table><p>"+'Championship Game:['+winner12[1]+winner12[3]+','+winner34[1]+winner34[3]+'] Winner:['+winner[1]+winner[3]+'] Score:['+champscore+']'+"</p><p id='message'>"+message+"</p>";
        }else if (getCookie('fill_style') == 'Round By Round'){
        ifrm_height = '145px'
        ifrm_width = '360px'

        return "<table width=100%><tr><td>"+'['+winner1_1[1]+','+winner1_8[1]+','+winner1_5[1]+','+winner1_4[1]+','+winner1_6[1]+','+winner1_3[1]+','+winner1_7[1]+','+winner1_2[1]+']'+'</td><td>'+'['+winner2_1[1]+','+winner2_8[1]+','+winner2_5[1]+','+winner2_4[1]+','+winner2_6[1]+','+winner2_3[1]+','+winner2_7[1]+','+winner2_2[1]+']'+'</td></tr><tr><td>'+'['+winner3_1[1]+','+winner3_8[1]+','+winner3_5[1]+','+winner3_4[1]+','+winner3_6[1]+','+winner3_3[1]+','+winner3_7[1]+','+winner3_2[1]+']'+'</td><td>'+'['+winner4_1[1]+','+winner4_8[1]+','+winner4_5[1]+','+winner4_4[1]+','+winner4_6[1]+','+winner4_3[1]+','+winner4_7[1]+','+winner4_2[1]+']'+'</td></tr></table><p>'+'Score:['+champscore+']'+"</p><p id='message'>"+message2+"</p>";            
        }
      
      
      
      
    }else if (getCookie('round_number') == 'R32'){
        R1 = 'Y'
        R2 = 'Y'
        R3 = 'Y'
        R4 = 'Y'
        R5 = 'Y'
        R6 = 'Y'

        if (getCookie('results_r1')[0] != '['){
            setCookie('results_r1', window.prompt('Please copy results of the first round from the March Madness Links Page. \n\nPress Enter/Return key if here by mistake:'),100);      
        }
        if (getCookie('results_r1')[0] == '['){      
            var winner1s1 = parseInt(getCookie('results_r1').split(',')[0].replace('[',''))
                if (winner1s1 == 1){
                    winner1_1 = [t1_1,winner1s1,'T','']
                } else if (winner1s1 == 16){
                    winner1_1 = [t1_16,winner1s1,'B','']
                }     
            var winner1s8 = parseInt(getCookie('results_r1').split(',')[1])
                if (winner1s8 == 8){
                    winner1_8 = [t1_8,winner1s8,'T','']
                } else if (winner1s8 == 9){
                    winner1_8 = [t1_9,winner1s8,'B','']
                }                    
            var winner1s5 = parseInt(getCookie('results_r1').split(',')[2])
                if (winner1s5 == 5){
                    winner1_5 = [t1_5,winner1s5,'T','']
                } else if (winner1s5 == 12){
                    winner1_5 = [t1_12,winner1s5,'B','']
                }                     
            var winner1s4 = parseInt(getCookie('results_r1').split(',')[3])
                if (winner1s4 == 4){
                    winner1_4 = [t1_4,winner1s4,'T','']
                } else if (winner1s4 == 13){
                    winner1_4 = [t1_13,winner1s4,'B','']
                }                      
            var winner1s6 = parseInt(getCookie('results_r1').split(',')[4])
                if (winner1s6 == 6){
                    winner1_6 = [t1_6,winner1s6,'T','']
                } else if (winner1s6 == 11){
                    winner1_6 = [t1_11,winner1s6,'B','']
                }                      
            var winner1s3 = parseInt(getCookie('results_r1').split(',')[5])
                if (winner1s3== 3){
                    winner1_3 = [t1_3,winner1s3,'T','']
                } else if (winner1s3 == 14){
                    winner1_3 = [t1_14,winner1s3,'B','']
                }  
            var winner1s7 = parseInt(getCookie('results_r1').split(',')[6])
                if (winner1s7== 7){
                    winner1_7 = [t1_7,winner1s7,'T','']
                } else if (winner1s7 == 10){
                    winner1_7 = [t1_10,winner1s7,'B','']
                }             
            var winner1s2 = parseInt(getCookie('results_r1').split(',')[7])
                if (winner1s2== 2){
                    winner1_2 = [t1_2,winner1s2,'T','']
                } else if (winner1s2 == 15){
                    winner1_2 = [t1_15,winner1s2,'B','']
                }



            var winner2s1 = parseInt(getCookie('results_r1').split(',')[8])
                if (winner2s1 == 1){
                    winner2_1 = [t2_1,winner2s1,'T','']
                } else if (winner2s1 == 16){
                    winner2_1 = [t2_16,winner2s1,'B','']
                }     
            var winner2s8 = parseInt(getCookie('results_r1').split(',')[9])
                if (winner2s8 == 8){
                    winner2_8 = [t2_8,winner2s8,'T','']
                } else if (winner2s8 == 9){
                    winner2_8 = [t2_9,winner2s8,'B','']
                }                    
            var winner2s5 = parseInt(getCookie('results_r1').split(',')[10])
                if (winner2s5 == 5){
                    winner2_5 = [t2_5,winner2s5,'T','']
                } else if (winner2s5 == 12){
                    winner2_5 = [t2_12,winner2s5,'B','']
                }                     
            var winner2s4 = parseInt(getCookie('results_r1').split(',')[11])
                if (winner2s4 == 4){
                    winner2_4 = [t2_4,winner2s4,'T','']
                } else if (winner2s4 == 13){
                    winner2_4 = [t2_13,winner2s4,'B','']
                }                      
            var winner2s6 = parseInt(getCookie('results_r1').split(',')[12])
                if (winner2s6 == 6){
                    winner2_6 = [t2_6,winner2s6,'T','']
                } else if (winner2s6 == 11){
                    winner2_6 = [t2_11,winner2s6,'B','']
                }                      
            var winner2s3 = parseInt(getCookie('results_r1').split(',')[13])
                if (winner2s3== 3){
                    winner2_3 = [t2_3,winner2s3,'T','']
                } else if (winner2s3 == 14){
                    winner2_3 = [t2_14,winner2s3,'B','']
                }  
            var winner2s7 = parseInt(getCookie('results_r1').split(',')[14])
                if (winner2s7== 7){
                    winner2_7 = [t2_7,winner2s7,'T','']
                } else if (winner2s7 == 10){
                    winner2_7 = [t2_10,winner2s7,'B','']
                }             
            var winner2s2 = parseInt(getCookie('results_r1').split(',')[15])
                if (winner2s2== 2){
                    winner2_2 = [t2_2,winner2s2,'T','']
                } else if (winner2s2 == 15){
                    winner2_2 = [t2_15,winner2s2,'B','']
                }             



            var winner3s1 = parseInt(getCookie('results_r1').split(',')[16])
                if (winner3s1 == 1){
                    winner3_1 = [t3_1,winner3s1,'T','']
                } else if (winner3s1 == 16){
                    winner3_1 = [t3_16,winner3s1,'B','']
                }     
            var winner3s8 = parseInt(getCookie('results_r1').split(',')[17])
                if (winner3s8 == 8){
                    winner3_8 = [t3_8,winner3s8,'T','']
                } else if (winner3s8 == 9){
                    winner3_8 = [t3_9,winner3s8,'B','']
                }                    
            var winner3s5 = parseInt(getCookie('results_r1').split(',')[18])
                if (winner3s5 == 5){
                    winner3_5 = [t3_5,winner3s5,'T','']
                } else if (winner3s5 == 12){
                    winner3_5 = [t3_12,winner3s5,'B','']
                }                     
            var winner3s4 = parseInt(getCookie('results_r1').split(',')[19])
                if (winner3s4 == 4){
                    winner3_4 = [t3_4,winner3s4,'T','']
                } else if (winner3s4 == 13){
                    winner3_4 = [t3_13,winner3s4,'B','']
                }                      
            var winner3s6 = parseInt(getCookie('results_r1').split(',')[20])
                if (winner3s6 == 6){
                    winner3_6 = [t3_6,winner3s6,'T','']
                } else if (winner3s6 == 11){
                    winner3_6 = [t3_11,winner3s6,'B','']
                }                      
            var winner3s3 = parseInt(getCookie('results_r1').split(',')[21])
                if (winner3s3== 3){
                    winner3_3 = [t3_3,winner3s3,'T','']
                } else if (winner3s3 == 14){
                    winner3_3 = [t3_14,winner3s3,'B','']
                }  
            var winner3s7 = parseInt(getCookie('results_r1').split(',')[22])
                if (winner3s7== 7){
                    winner3_7 = [t3_7,winner3s7,'T','']
                } else if (winner3s7 == 10){
                    winner3_7 = [t3_10,winner3s7,'B','']
                }             
            var winner3s2 = parseInt(getCookie('results_r1').split(',')[23])
                if (winner3s2== 2){
                    winner3_2 = [t3_2,winner3s2,'T','']
                } else if (winner3s2 == 15){
                    winner3_2 = [t3_15,winner3s2,'B','']
                }                        



            var winner4s1 = parseInt(getCookie('results_r1').split(',')[24])
                if (winner4s1 == 1){
                    winner4_1 = [t4_1,winner4s1,'T','']
                } else if (winner4s1 == 16){
                    winner4_1 = [t4_16,winner4s1,'B','']
                }     
            var winner4s8 = parseInt(getCookie('results_r1').split(',')[25])
                if (winner4s8 == 8){
                    winner4_8 = [t4_8,winner4s8,'T','']
                } else if (winner4s8 == 9){
                    winner4_8 = [t4_9,winner4s8,'B','']
                }                    
            var winner4s5 = parseInt(getCookie('results_r1').split(',')[26])
                if (winner4s5 == 5){
                    winner4_5 = [t4_5,winner4s5,'T','']
                } else if (winner4s5 == 12){
                    winner4_5 = [t4_12,winner4s5,'B','']
                }                     
            var winner4s4 = parseInt(getCookie('results_r1').split(',')[27])
                if (winner4s4 == 4){
                    winner4_4 = [t4_4,winner4s4,'T','']
                } else if (winner4s4 == 13){
                    winner4_4 = [t4_13,winner4s4,'B','']
                }                      
            var winner4s6 = parseInt(getCookie('results_r1').split(',')[28])
                if (winner4s6 == 6){
                    winner4_6 = [t4_6,winner4s6,'T','']
                } else if (winner4s6 == 11){
                    winner4_6 = [t4_11,winner4s6,'B','']
                }                      
            var winner4s3 = parseInt(getCookie('results_r1').split(',')[29])
                if (winner4s3== 3){
                    winner4_3 = [t4_3,winner4s3,'T','']
                } else if (winner4s3 == 14){
                    winner4_3 = [t4_14,winner4s3,'B','']
                }  
            var winner4s7 = parseInt(getCookie('results_r1').split(',')[30])
                if (winner4s7== 7){
                    winner4_7 = [t4_7,winner4s7,'T','']
                } else if (winner4s7 == 10){
                    winner4_7 = [t4_10,winner4s7,'B','']
                }             
            var winner4s2 = parseInt(getCookie('results_r1').split(',')[31].replace(']',''))
                if (winner4s2== 2){
                    winner4_2 = [t4_2,winner4s2,'T','']
                } else if (winner4s2 == 15){
                    winner4_2 = [t4_15,winner4s2,'B','']
                }                         

            var winner1_18 = pickWinner(winner1_1[1],winner1_8[1],winner1_1[0],winner1_8[0],'Q',R2);
            var winner1_54 = pickWinner(winner1_5[1],winner1_4[1],winner1_5[0],winner1_4[0],'Q',R2);
            var winner1_63 = pickWinner(winner1_6[1],winner1_3[1],winner1_6[0],winner1_3[0],'Q',R2);
            var winner1_72 = pickWinner(winner1_7[1],winner1_2[1],winner1_7[0],winner1_2[0],'Q',R2);

            var winner1_1854 = pickWinner(winner1_18[1],winner1_54[1],winner1_18[0],winner1_54[0],'Q',R3);
            var winner1_6372 = pickWinner(winner1_63[1],winner1_72[1],winner1_63[0],winner1_72[0],'Q',R3);

            var winner1 = pickWinner(winner1_1854[1],winner1_6372[1],winner1_1854[0],winner1_6372[0],'Q',R4);

            var winner2_18 = pickWinner(winner2_1[1],winner2_8[1],winner2_1[0],winner2_8[0],'Q',R2);
            var winner2_54 = pickWinner(winner2_5[1],winner2_4[1],winner2_5[0],winner2_4[0],'Q',R2);
            var winner2_63 = pickWinner(winner2_6[1],winner2_3[1],winner2_6[0],winner2_3[0],'Q',R2);
            var winner2_72 = pickWinner(winner2_7[1],winner2_2[1],winner2_7[0],winner2_2[0],'Q',R2);

            var winner2_1854 = pickWinner(winner2_18[1],winner2_54[1],winner2_18[0],winner2_54[0],'Q',R3);
            var winner2_6372 = pickWinner(winner2_63[1],winner2_72[1],winner2_63[0],winner2_72[0],'Q',R3);

            var winner2 = pickWinner(winner2_1854[1],winner2_6372[1],winner2_1854[0],winner2_6372[0],'Q',R4);

            var winner3_18 = pickWinner(winner3_1[1],winner3_8[1],winner3_1[0],winner3_8[0],'Q',R2);
            var winner3_54 = pickWinner(winner3_5[1],winner3_4[1],winner3_5[0],winner3_4[0],'Q',R2);
            var winner3_63 = pickWinner(winner3_6[1],winner3_3[1],winner3_6[0],winner3_3[0],'Q',R2);
            var winner3_72 = pickWinner(winner3_7[1],winner3_2[1],winner3_7[0],winner3_2[0],'Q',R2);

            var winner3_1854 = pickWinner(winner3_18[1],winner3_54[1],winner3_18[0],winner3_54[0],'Q',R3);
            var winner3_6372 = pickWinner(winner3_63[1],winner3_72[1],winner3_63[0],winner3_72[0],'Q',R3);

            var winner3 = pickWinner(winner3_1854[1],winner3_6372[1],winner3_1854[0],winner3_6372[0],'Q',R4);

            var winner4_18 = pickWinner(winner4_1[1],winner4_8[1],winner4_1[0],winner4_8[0],'Q',R2);
            var winner4_54 = pickWinner(winner4_5[1],winner4_4[1],winner4_5[0],winner4_4[0],'Q',R2);
            var winner4_63 = pickWinner(winner4_6[1],winner4_3[1],winner4_6[0],winner4_3[0],'Q',R2);
            var winner4_72 = pickWinner(winner4_7[1],winner4_2[1],winner4_7[0],winner4_2[0],'Q',R2);

            var winner4_1854 = pickWinner(winner4_18[1],winner4_54[1],winner4_18[0],winner4_54[0],'Q',R3);
            var winner4_6372 = pickWinner(winner4_63[1],winner4_72[1],winner4_63[0],winner4_72[0],'Q',R3);

            var winner4 = pickWinner(winner4_1854[1],winner4_6372[1],winner4_1854[0],winner4_6372[0],'Q',R4);

            var winner12 = pickWinner(winner1[1],winner2[1],winner1[0],winner2[0],'F',R5);
            var winner34 = pickWinner(winner3[1],winner4[1],winner3[0],winner4[0],'F',R5);
            var winner = pickWinner(winner12[1],winner34[1],winner12[0],winner34[0],'F',R6);

            champscore=championshipScore();

            setCookie("MarchMadnessWinnerSet",[winner1_1,winner1_8,winner1_5,winner1_4,winner1_6,winner1_3,winner1_7,winner1_2,winner1_18,winner1_54,winner1_63,winner1_72,winner1_1854,winner1_6372,winner1,winner2_1,winner2_8,winner2_5,winner2_4,winner2_6,winner2_3,winner2_7,winner2_2,winner2_18,winner2_54,winner2_63,winner2_72,winner2_1854,winner2_6372,winner2,winner3_1,winner3_8,winner3_5,winner3_4,winner3_6,winner3_3,winner3_7,winner3_2,winner3_18,winner3_54,winner3_63,winner3_72,winner3_1854,winner3_6372,winner3,winner4_1,winner4_8,winner4_5,winner4_4,winner4_6,winner4_3,winner4_7,winner4_2,winner4_18,winner4_54,winner4_63,winner4_72,winner4_1854,winner4_6372,winner4,winner12,winner34,winner],7);
            //setCookie("MarchMadnessWinnerSpot",[winner1_1[2],winner1_8[2],winner1_5[2],winner1_4[2],winner1_6[2],winner1_3[2],winner1_7[2],winner1_2[2],winner1_18[2],winner1_54[2],winner1_63[2],winner1_72[2],winner1_1854[2],winner1_6372[2],winner1[2],winner2_1[2],winner2_8[2],winner2_5[2],winner2_4[2],winner2_6[2],winner2_3[2],winner2_7[2],winner2_2[2],winner2_18[2],winner2_54[2],winner2_63[2],winner2_72[2],winner2_1854[2],winner2_6372[2],winner2[2],winner3_1[2],winner3_8[2],winner3_5[2],winner3_4[2],winner3_6[2],winner3_3[2],winner3_7[2],winner3_2[2],winner3_18[2],winner3_54[2],winner3_63[2],winner3_72[2],winner3_1854[2],winner3_6372[2],winner3[2],winner4_1[2],winner4_8[2],winner4_5[2],winner4_4[2],winner4_6[2],winner4_3[2],winner4_7[2],winner4_2[2],winner4_18[2],winner4_54[2],winner4_63[2],winner4_72[2],winner4_1854[2],winner4_6372[2],winner4[2],winner12[2],winner34[2],winner[2]],7);            
            setCookie("MarchMadnessChampScore",champscore,7);

            var WinnerSet2=[winner1_18[1],winner1_54[1],winner1_63[1],winner1_72[1],winner2_18[1],winner2_54[1],winner2_63[1],winner2_72[1],winner3_18[1],winner3_54[1],winner3_63[1],winner3_72[1],winner4_18[1],winner4_54[1],winner4_63[1],winner4_72[1]]     
      
            var message='=SPLIT("'+PickName+','+WinnerSet+','+champscore+'",",")';
            var message2='=SPLIT("'+PickName+','+WinnerSet2+','+champscore+'",",")';
      
            if (getCookie('fill_style') == 'Upfront' || getCookie('fill_style') == ''){
                ifrm_height = '170px'
                ifrm_width = '370px'           
                return "<table width=100%><tr><td>"+'['+winner1_18[1]+','+winner1_54[1]+','+winner1_63[1]+','+winner1_72[1]+']'+'</td><td>'+'['+winner2_18[1]+','+winner2_54[1]+','+winner2_63[1]+','+winner2_72[1]+']'+'</td><td>'+'['+winner3_18[1]+','+winner3_54[1]+','+winner3_63[1]+','+winner3_72[1]+']'+'</td><td>'+'['+winner4_18[1]+','+winner4_54[1]+','+winner4_63[1]+','+winner4_72[1]+']'+'</td></tr><tr><td>'+'['+winner1_1854[1]+','+winner1_6372[1]+']'+'</td><td>'+'['+winner2_1854[1]+','+winner2_6372[1]+']'+'</td><td>'+'['+winner3_1854[1]+','+winner3_6372[1]+']'+'</td><td>'+'['+winner4_1854[1]+','+winner4_6372[1]+']'+'</td></tr><tr><td>'+'['+winner1[1]+']'+'</td><td>'+'['+winner2[1]+']'+'</td><td>'+'['+winner3[1]+']'+'</td><td>'+'['+winner4[1]+']'+"</td></tr></font></table><p>"+'Championship:['+winner12[1]+winner12[3]+','+winner34[1]+winner34[3]+'] Winner:['+winner[1]+winner[3]+'] Score:['+champscore+']'+"</p><p id='message'>"+message+"</p>";
            }else if (getCookie('fill_style') == 'Round By Round'){
                ifrm_height = '120px'
                ifrm_width = '360px'
                return "<table width=100%><tr><td>"+'['+winner1_18[1]+','+winner1_54[1]+','+winner1_63[1]+','+winner1_72[1]+']'+'</td><td>'+'['+winner2_18[1]+','+winner2_54[1]+','+winner2_63[1]+','+winner2_72[1]+']'+'</td><td>'+'['+winner3_18[1]+','+winner3_54[1]+','+winner3_63[1]+','+winner3_72[1]+']'+'</td><td>'+'['+winner4_18[1]+','+winner4_54[1]+','+winner4_63[1]+','+winner4_72[1]+']'+'</td></tr></font></table><p>Score:['+champscore+']'+"</p><p id='message'>"+message2+"</p>";
            }          
        }
      
      
      
    }else if (getCookie('round_number') == 'R16'){
        R1 = 'Y'
        R2 = 'Y'
        R3 = 'Y'
        R4 = 'Y'
        R5 = 'Y'
        R6 = 'Y'
        
        setCookie('results_r2','[1,5,3,2,1,4,3,2,1,5,6,7,1,4,11,10]');

        if (getCookie('results_r2')[0] != '['){
            setCookie('results_r2', window.prompt('Please copy results of the second round from the March Madness Links Page. \n\nPress Enter/Return key if here by mistake:'),100)
        }

        if (getCookie('results_r2')[0] == '['){      
            var winner1s18 = parseInt(getCookie('results_r2').split(',')[0].replace('[',''))
                if (winner1s18 == 1 || winner1s18 == 16 ){
                    winner1_18 = [gen_id(1,winner1s18),winner1s18,'T','']
                } else if (winner1s18 == 8 || winner1s18 == 9){
                    winner1_18 = [gen_id(1,winner1s18),winner1s18,'B','']
                }     
            var winner1s54 = parseInt(getCookie('results_r2').split(',')[1])
                if (winner1s54 == 5 || winner1s54 == 12){
                    winner1_54 = [gen_id(1,winner1s54),winner1s54,'T','']
                } else if (winner1s54 == 4 || winner1s54 == 13){
                    winner1_54 = [gen_id(1,winner1s54),winner1s54,'B','']
                }                    
            var winner1s63 = parseInt(getCookie('results_r2').split(',')[2])
                if (winner1s63 == 6 || winner1s63 == 11){
                    winner1_63 = [gen_id(1,winner1s63),winner1s63,'T','']
                } else if (winner1s63 == 3 || winner1s63 == 14){
                    winner1_63 = [gen_id(1,winner1s63),winner1s63,'B','']
                }                     
            var winner1s72 = parseInt(getCookie('results_r2').split(',')[3])
                if (winner1s72 == 7 || winner1s72 == 10){
                    winner1_72 = [gen_id(1,winner1s72),winner1s72,'T','']
                } else if (winner1s72 == 2 || winner1s72 == 15){
                    winner1_72 = [gen_id(1,winner1s72),winner1s72,'B','']
                }    
            var winner2s18 = parseInt(getCookie('results_r2').split(',')[4])
                if (winner2s18 == 1 || winner2s18 == 16 ){
                    winner2_18 = [gen_id(2,winner2s18),winner2s18,'T','']
                } else if (winner2s18 == 8 || winner2s18 == 9){
                    winner2_18 = [gen_id(2,winner2s18),winner2s18,'B','']
                }     
            var winner2s54 = parseInt(getCookie('results_r2').split(',')[5])
                if (winner2s54 == 5 || winner2s54 == 12){
                    winner2_54 = [gen_id(2,winner2s54),winner2s54,'T','']
                } else if (winner2s54 == 4 || winner2s54 == 13){
                    winner2_54 = [gen_id(2,winner2s54),winner2s54,'B','']
                }                    
            var winner2s63 = parseInt(getCookie('results_r2').split(',')[6])
                if (winner2s63 == 6 || winner2s63 == 11){
                    winner2_63 = [gen_id(2,winner2s63),winner2s63,'T','']
                } else if (winner2s63 == 3 || winner2s63 == 14){
                    winner2_63 = [gen_id(2,winner2s63),winner2s63,'B','']
                }                     
            var winner2s72 = parseInt(getCookie('results_r2').split(',')[7])
                if (winner2s72 == 7 || winner2s72 == 10){
                    winner2_72 = [gen_id(2,winner2s72),winner2s72,'T','']
                } else if (winner2s72 == 2 || winner2s72 == 15){
                    winner2_72 = [gen_id(2,winner2s72),winner2s72,'B','']
                }            
            var winner3s18 = parseInt(getCookie('results_r2').split(',')[8])
                if (winner3s18 == 1 || winner3s18 == 16 ){
                    winner3_18 = [gen_id(3,winner3s18),winner3s18,'T','']
                } else if (winner3s18 == 8 || winner3s18 == 9){
                    winner3_18 = [gen_id(3,winner3s18),winner3s18,'B','']
                }     
            var winner3s54 = parseInt(getCookie('results_r2').split(',')[9])
                if (winner3s54 == 5 || winner3s54 == 12){
                    winner3_54 = [gen_id(3,winner3s54),winner3s54,'T','']
                } else if (winner3s54 == 4 || winner3s54 == 13){
                    winner3_54 = [gen_id(3,winner3s54),winner3s54,'B','']
                }                    
            var winner3s63 = parseInt(getCookie('results_r2').split(',')[10])
                if (winner3s63 == 6 || winner3s63 == 11){
                    winner3_63 = [gen_id(3,winner3s63),winner3s63,'T','']
                } else if (winner3s63 == 3 || winner3s63 == 14){
                    winner3_63 = [gen_id(3,winner3s63),winner3s63,'B','']
                }                     
            var winner3s72 = parseInt(getCookie('results_r2').split(',')[11])
                if (winner3s72 == 7 || winner3s72 == 10){
                    winner3_72 = [gen_id(3,winner3s72),winner3s72,'T','']
                } else if (winner3s72 == 2 || winner3s72 == 15){
                    winner3_72 = [gen_id(3,winner3s72),winner3s72,'B','']
                }             
            var winner4s18 = parseInt(getCookie('results_r2').split(',')[12])
                if (winner4s18 == 1 || winner4s18 == 16 ){
                    winner4_18 = [gen_id(4,winner4s18),winner4s18,'T','']
                } else if (winner4s18 == 8 || winner4s18 == 9){
                    winner4_18 = [gen_id(4,winner4s18),winner4s18,'B','']
                }     
            var winner4s54 = parseInt(getCookie('results_r2').split(',')[13])
                if (winner4s54 == 5 || winner4s54 == 12){
                    winner4_54 = [gen_id(4,winner4s54),winner4s54,'T','']
                } else if (winner4s54 == 4 || winner4s54 == 13){
                    winner4_54 = [gen_id(4,winner4s54),winner4s54,'B','']
                }                    
            var winner4s63 = parseInt(getCookie('results_r2').split(',')[14])
                if (winner4s63 == 6 || winner4s63 == 11){
                    winner4_63 = [gen_id(4,winner4s63),winner4s63,'T','']
                } else if (winner4s63 == 3 || winner4s63 == 14){
                    winner4_63 = [gen_id(4,winner4s63),winner4s63,'B','']
                }                     
            var winner4s72 = parseInt(getCookie('results_r2').split(',')[15])
                if (winner4s72 == 7 || winner4s72 == 10){
                    winner4_72 = [gen_id(4,winner4s72),winner4s72,'T','']
                } else if (winner4s72 == 2 || winner4s72 == 15){
                    winner4_72 = [gen_id(4,winner4s72),winner4s72,'B','']
                }                      
        

            var winner1_1854 = pickWinner(winner1_18[1],winner1_54[1],winner1_18[0],winner1_54[0],'Q',R3);
            var winner1_6372 = pickWinner(winner1_63[1],winner1_72[1],winner1_63[0],winner1_72[0],'Q',R3);

            var winner1 = pickWinner(winner1_1854[1],winner1_6372[1],winner1_1854[0],winner1_6372[0],'Q',R4);

            var winner2_1854 = pickWinner(winner2_18[1],winner2_54[1],winner2_18[0],winner2_54[0],'Q',R3);
            var winner2_6372 = pickWinner(winner2_63[1],winner2_72[1],winner2_63[0],winner2_72[0],'Q',R3);

            var winner2 = pickWinner(winner2_1854[1],winner2_6372[1],winner2_1854[0],winner2_6372[0],'Q',R4);

            var winner3_1854 = pickWinner(winner3_18[1],winner3_54[1],winner3_18[0],winner3_54[0],'Q',R3);
            var winner3_6372 = pickWinner(winner3_63[1],winner3_72[1],winner3_63[0],winner3_72[0],'Q',R3);

            var winner3 = pickWinner(winner3_1854[1],winner3_6372[1],winner3_1854[0],winner3_6372[0],'Q',R4);

            var winner4_1854 = pickWinner(winner4_18[1],winner4_54[1],winner4_18[0],winner4_54[0],'Q',R3);
            var winner4_6372 = pickWinner(winner4_63[1],winner4_72[1],winner4_63[0],winner4_72[0],'Q',R3);

            var winner4 = pickWinner(winner4_1854[1],winner4_6372[1],winner4_1854[0],winner4_6372[0],'Q',R4);

            var winner12 = pickWinner(winner1[1],winner2[1],winner1[0],winner2[0],'F',R5);
            var winner34 = pickWinner(winner3[1],winner4[1],winner3[0],winner4[0],'F',R5);
            var winner = pickWinner(winner12[1],winner34[1],winner12[0],winner34[0],'F',R6);

            champscore=championshipScore();

            setCookie("MarchMadnessWinnerSet",[winner1_1,winner1_8,winner1_5,winner1_4,winner1_6,winner1_3,winner1_7,winner1_2,winner1_18,winner1_54,winner1_63,winner1_72,winner1_1854,winner1_6372,winner1,winner2_1,winner2_8,winner2_5,winner2_4,winner2_6,winner2_3,winner2_7,winner2_2,winner2_18,winner2_54,winner2_63,winner2_72,winner2_1854,winner2_6372,winner2,winner3_1,winner3_8,winner3_5,winner3_4,winner3_6,winner3_3,winner3_7,winner3_2,winner3_18,winner3_54,winner3_63,winner3_72,winner3_1854,winner3_6372,winner3,winner4_1,winner4_8,winner4_5,winner4_4,winner4_6,winner4_3,winner4_7,winner4_2,winner4_18,winner4_54,winner4_63,winner4_72,winner4_1854,winner4_6372,winner4,winner12,winner34,winner],7);
            setCookie("MarchMadnessWinnerSpot",[winner1_1854[2],winner1_6372[2],winner1[2],winner2_1854[2],winner2_6372[2],winner2[2],winner3_1854[2],winner3_6372[2],winner3[2],winner4_1854[2],winner4_6372[2],winner4[2],winner12[2],winner34[2],winner[2],],7);            
            setCookie("MarchMadnessChampScore",champscore,7);
      
            var WinnerSet2=[winner1_1854[1],winner1_6372[1],winner2_1854[1],winner2_6372[1],winner3_1854[1],winner3_6372[1],winner4_1854[1],winner4_6372[1]]     
      
            var message='=SPLIT("'+PickName+','+WinnerSet+','+champscore+'",",")';
            var message2='=SPLIT("'+PickName+','+WinnerSet2+','+champscore+'",",")';
      
      
            if (getCookie('fill_style') == 'Upfront' || getCookie('fill_style') == ''){
                ifrm_height = '145px'
                ifrm_width = '370px'      
                return "<table width=100%><tr><td>"+'['+winner1_1854[1]+','+winner1_6372[1]+']'+'</td><td>'+'['+winner2_1854[1]+','+winner2_6372[1]+']'+'</td><td>'+'['+winner3_1854[1]+','+winner3_6372[1]+']'+'</td><td>'+'['+winner4_1854[1]+','+winner4_6372[1]+']'+'</td></tr><tr><td>'+'['+winner1[1]+']'+'</td><td>'+'['+winner2[1]+']'+'</td><td>'+'['+winner3[1]+']'+'</td><td>'+'['+winner4[1]+']'+"</td></tr></font></table><p>"+'Championship:['+winner12[1]+winner12[3]+','+winner34[1]+winner34[3]+'] Winner:['+winner[1]+winner[3]+'] Score:['+champscore+']'+"</p><p id='message'>"+message+"</p>";
                
            }else if (getCookie('fill_style') == 'Round By Round'){
                ifrm_height = '120px'
                ifrm_width = '360px'
                return "<table width=100%><tr><td>"+'['+winner1_1854[1]+','+winner1_6372[1]+']'+'</td><td>'+'['+winner2_1854[1]+','+winner2_6372[1]+']'+'</td><td>'+'['+winner3_1854[1]+','+winner3_6372[1]+']'+'</td><td>'+'['+winner4_1854[1]+','+winner4_6372[1]+']'+'</td></tr></font></table><p>Score:['+champscore+']'+"</p><p id='message'>"+message2+"</p>";
                
            }                  
        }        

      
    }else if (getCookie('round_number') == 'R8'){
        R1 = 'Y'
        R2 = 'Y'
        R3 = 'Y'
        R4 = 'Y'
        R5 = 'Y'
        R6 = 'Y'

        if (getCookie('results_r3')[0] != '['){
            setCookie('results_r3', window.prompt('Please copy results of the third round from the March Madness Links Page. \n\nPress Enter/Return key if here by mistake:'),100)
        }

        if (getCookie('results_r3')[0] == '['){      
            var winner1s1854 = parseInt(getCookie('results_r3').split(',')[0].replace('[',''))
                if (winner1s1854 == 1 || winner1s1854 == 16 || winner1s1854 == 8 || winner1s1854 == 9){
                    winner1_1854 = [gen_id(1,winner1s1854),winner1s1854,'T','']
                } else if (winner1s1854 == 5 || winner1s1854 == 12 || winner1s1854 == 4 || winner1s1854 == 13){
                    winner1_1854 = [gen_id(1,winner1s1854),winner1s1854,'B','']
                }     
            var winner1s6372 = parseInt(getCookie('results_r3').split(',')[1])
                if (winner1s6372 == 6 || winner1s6372 == 11 || winner1s6372 == 3 || winner1s6372 == 14){
                    winner1_6372 = [gen_id(1,winner1s6372),winner1s6372,'T','']
                } else if (winner1s6372 == 7 || winner1s6372 == 10 || winner1s6372 == 2 || winner1s6372 == 15){
                    winner1_6372 = [gen_id(1,winner1s6372),winner1s6372,'B','']
                }
            var winner2s1854 = parseInt(getCookie('results_r3').split(',')[2].replace('[',''))
                if (winner2s1854 == 1 || winner2s1854 == 16 || winner2s1854 == 8 || winner2s1854 == 9){
                    winner2_1854 = [gen_id(2,winner2s1854),winner2s1854,'T','']
                } else if (winner2s1854 == 5 || winner2s1854 == 12 || winner2s1854 == 4 || winner2s1854 == 13){
                    winner2_1854 = [gen_id(2,winner2s1854),winner2s1854,'B','']
                }     
            var winner2s6372 = parseInt(getCookie('results_r3').split(',')[3])
                if (winner2s6372 == 6 || winner2s6372 == 11 || winner2s6372 == 3 || winner2s6372 == 14){
                    winner2_6372 = [gen_id(2,winner2s6372),winner2s6372,'T','']
                } else if (winner2s6372 == 7 || winner2s6372 == 10 || winner2s6372 == 2 || winner2s6372 == 15){
                    winner2_6372 = [gen_id(2,winner2s6372),winner2s6372,'B','']
                }            
            var winner3s1854 = parseInt(getCookie('results_r3').split(',')[4].replace('[',''))
                if (winner3s1854 == 1 || winner3s1854 == 16 || winner3s1854 == 8 || winner3s1854 == 9){
                    winner3_1854 = [gen_id(3,winner3s1854),winner3s1854,'T','']
                } else if (winner3s1854 == 5 || winner3s1854 == 12 || winner3s1854 == 4 || winner3s1854 == 13){
                    winner3_1854 = [gen_id(3,winner3s1854),winner3s1854,'B','']
                }     
            var winner3s6372 = parseInt(getCookie('results_r3').split(',')[5])
                if (winner3s6372 == 6 || winner3s6372 == 11 || winner3s6372 == 3 || winner3s6372 == 14){
                    winner3_6372 = [gen_id(3,winner3s6372),winner3s6372,'T','']
                } else if (winner3s6372 == 7 || winner3s6372 == 10 || winner3s6372 == 2 || winner3s6372 == 15){
                    winner3_6372 = [gen_id(3,winner3s6372),winner3s6372,'B','']
                }            
            var winner4s1854 = parseInt(getCookie('results_r3').split(',')[6].replace('[',''))
                if (winner4s1854 == 1 || winner4s1854 == 16 || winner4s1854 == 8 || winner4s1854 == 9){
                    winner4_1854 = [gen_id(4,winner4s1854),winner4s1854,'T','']
                } else if (winner4s1854 == 5 || winner4s1854 == 12 || winner4s1854 == 4 || winner4s1854 == 13){
                    winner4_1854 = [gen_id(4,winner4s1854),winner4s1854,'B','']
                }     
            var winner4s6372 = parseInt(getCookie('results_r3').split(',')[7].replace(']',''))
                if (winner4s6372 == 6 || winner4s6372 == 11 || winner4s6372 == 3 || winner4s6372 == 14){
                    winner4_6372 = [gen_id(4,winner4s6372),winner4s6372,'T','']
                } else if (winner4s6372 == 7 || winner4s6372 == 10 || winner4s6372 == 2 || winner4s6372 == 15){
                    winner4_6372 = [gen_id(4,winner4s6372),winner4s6372,'B','']
                }            
        

            var winner1 = pickWinner(winner1_1854[1],winner1_6372[1],winner1_1854[0],winner1_6372[0],'Q',R4);
            var winner2 = pickWinner(winner2_1854[1],winner2_6372[1],winner2_1854[0],winner2_6372[0],'Q',R4);
            var winner3 = pickWinner(winner3_1854[1],winner3_6372[1],winner3_1854[0],winner3_6372[0],'Q',R4);
            var winner4 = pickWinner(winner4_1854[1],winner4_6372[1],winner4_1854[0],winner4_6372[0],'Q',R4);

            var winner12 = pickWinner(winner1[1],winner2[1],winner1[0],winner2[0],'F',R5);
            var winner34 = pickWinner(winner3[1],winner4[1],winner3[0],winner4[0],'F',R5);
            var winner = pickWinner(winner12[1],winner34[1],winner12[0],winner34[0],'F',R6);

            champscore=championshipScore();

            
            setCookie("MarchMadnessWinnerSet",[winner1_1,winner1_8,winner1_5,winner1_4,winner1_6,winner1_3,winner1_7,winner1_2,winner1_18,winner1_54,winner1_63,winner1_72,winner1_1854,winner1_6372,winner1,winner2_1,winner2_8,winner2_5,winner2_4,winner2_6,winner2_3,winner2_7,winner2_2,winner2_18,winner2_54,winner2_63,winner2_72,winner2_1854,winner2_6372,winner2,winner3_1,winner3_8,winner3_5,winner3_4,winner3_6,winner3_3,winner3_7,winner3_2,winner3_18,winner3_54,winner3_63,winner3_72,winner3_1854,winner3_6372,winner3,winner4_1,winner4_8,winner4_5,winner4_4,winner4_6,winner4_3,winner4_7,winner4_2,winner4_18,winner4_54,winner4_63,winner4_72,winner4_1854,winner4_6372,winner4,winner12,winner34,winner],7);
            //setCookie("MarchMadnessWinnerSpot",[winner1_1[2],winner1_8[2],winner1_5[2],winner1_4[2],winner1_6[2],winner1_3[2],winner1_7[2],winner1_2[2],winner1_18[2],winner1_54[2],winner1_63[2],winner1_72[2],winner1_1854[2],winner1_6372[2],winner1[2],winner2_1[2],winner2_8[2],winner2_5[2],winner2_4[2],winner2_6[2],winner2_3[2],winner2_7[2],winner2_2[2],winner2_18[2],winner2_54[2],winner2_63[2],winner2_72[2],winner2_1854[2],winner2_6372[2],winner2[2],winner3_1[2],winner3_8[2],winner3_5[2],winner3_4[2],winner3_6[2],winner3_3[2],winner3_7[2],winner3_2[2],winner3_18[2],winner3_54[2],winner3_63[2],winner3_72[2],winner3_1854[2],winner3_6372[2],winner3[2],winner4_1[2],winner4_8[2],winner4_5[2],winner4_4[2],winner4_6[2],winner4_3[2],winner4_7[2],winner4_2[2],winner4_18[2],winner4_54[2],winner4_63[2],winner4_72[2],winner4_1854[2],winner4_6372[2],winner4[2],winner12[2],winner34[2],winner[2]],7);                        
            setCookie("MarchMadnessChampScore",champscore,7);
          
            var WinnerSet2=[winner1[1],winner2[1],winner3[1],winner4[1]]     
      
            var message='=SPLIT("'+PickName+','+WinnerSet+','+champscore+'",",")';
            var message2='=SPLIT("'+PickName+','+WinnerSet2+','+champscore+'",",")';
      
      
            if (getCookie('fill_style') == 'Upfront' || getCookie('fill_style') == ''){
                ifrm_height = '120px'
                ifrm_width = '370px'   
                return "<table width=100%><tr><td>"+'['+winner1[1]+']'+'</td><td>'+'['+winner2[1]+']'+'</td><td>'+'['+winner3[1]+']'+'</td><td>'+'['+winner4[1]+']'+"</td></tr></font></table><p>"+'Championship:['+winner12[1]+winner12[3]+','+winner34[1]+winner34[3]+'] Winner:['+winner[1]+winner[3]+'] Score:['+champscore+']'+"</p><p id='message'>"+message+"</p>";
                
            }else if (getCookie('fill_style') == 'Round By Round'){
                ifrm_height = '120px'
                ifrm_width = '360px'
                return "<table width=100%><tr><td>"+'['+winner1[1]+']'+'</td><td>'+'['+winner2[1]+']'+'</td><td>'+'['+winner3[1]+']'+'</td><td>'+'['+winner4[1]+']'+'</td></tr></font></table><p>Score:['+champscore+']'+"</p><p id='message'>"+message2+"</p>";
                
            }                  
        }                    
    }else if (getCookie('round_number') == 'R4'){
        R1 = 'Y'
        R2 = 'Y'
        R3 = 'Y'
        R4 = 'Y'
        R5 = 'Y'
        R6 = 'Y'
        
        setCookie('results_r4','[2,2,1,10]');        

        if (getCookie('results_r4') == ''){
            setCookie('results_r4', window.prompt('Please copy results of the fourth round from the March Madness Links Page. \n\nPress Enter/Return key if here by mistake:'),100)
        }

        if (getCookie('results_r4')[0] == '['){      
            var winner1s = parseInt(getCookie('results_r4').split(',')[0].replace('[',''))
                if (winner1s == 1 || winner1s == 16 || winner1s == 8 || winner1s == 9 || winner1s == 5 || winner1s == 12 || winner1s == 4 || winner1s == 13){
                    winner1 = [gen_id(1,winner1s),winner1s,'T','']
                } else if (winner1s == 6 || winner1s == 11 || winner1s == 3 || winner1s == 14 || winner1s == 7 || winner1s == 10 || winner1s == 2 || winner1s == 15){
                    winner1 = [gen_id(1,winner1s),winner1s,'B','']
                }     
            var winner2s = parseInt(getCookie('results_r4').split(',')[1])
                if (winner2s == 1 || winner2s == 16 || winner2s == 8 || winner2s == 9 || winner2s == 5 || winner2s == 12 || winner2s == 4 || winner2s == 13){
                    winner2 = [gen_id(2,winner2s),winner2s,'T','']
                } else if (winner2s == 6 || winner2s == 11 || winner2s == 3 || winner2s == 14 || winner2s == 7 || winner2s == 10 || winner2s == 2 || winner2s == 15){
                    winner2 = [gen_id(2,winner2s),winner2s,'B','']
                }  
            var winner3s = parseInt(getCookie('results_r4').split(',')[2])
                if (winner3s == 1 || winner3s == 16 || winner3s == 8 || winner3s == 9 || winner3s == 5 || winner3s == 12 || winner3s == 4 || winner3s == 13){
                    winner3 = [gen_id(3,winner3s),winner3s,'T','']
                } else if (winner3s == 6 || winner3s == 11 || winner3s == 3 || winner3s == 14 || winner3s == 7 || winner3s == 10 || winner3s == 2 || winner3s == 15){
                    winner3 = [gen_id(3,winner3s),winner3s,'B','']
                }              
            var winner4s = parseInt(getCookie('results_r4').split(',')[3].replace(']',''))
                if (winner4s == 1 || winner4s == 16 || winner4s == 8 || winner4s == 9 || winner4s == 5 || winner4s == 12 || winner4s == 4 || winner4s == 13){
                    winner4 = [gen_id(4,winner4s),winner4s,'T','']
                } else if (winner4s == 6 || winner4s == 11 || winner4s == 3 || winner4s == 14 || winner4s == 7 || winner4s == 10 || winner4s == 2 || winner4s == 15){
                    winner4 = [gen_id(4,winner4s),winner4s,'B','']
                }                      
        
            var winner12 = pickWinner(winner1[1],winner2[1],winner1[0],winner2[0],'F',R5);
            var winner34 = pickWinner(winner3[1],winner4[1],winner3[0],winner4[0],'F',R5);
            var winner = pickWinner(winner12[1],winner34[1],winner12[0],winner34[0],'F',R6);

            champscore=championshipScore();

            setCookie("MarchMadnessWinnerSet",[winner1_1,winner1_8,winner1_5,winner1_4,winner1_6,winner1_3,winner1_7,winner1_2,winner1_18,winner1_54,winner1_63,winner1_72,winner1_1854,winner1_6372,winner1,winner2_1,winner2_8,winner2_5,winner2_4,winner2_6,winner2_3,winner2_7,winner2_2,winner2_18,winner2_54,winner2_63,winner2_72,winner2_1854,winner2_6372,winner2,winner3_1,winner3_8,winner3_5,winner3_4,winner3_6,winner3_3,winner3_7,winner3_2,winner3_18,winner3_54,winner3_63,winner3_72,winner3_1854,winner3_6372,winner3,winner4_1,winner4_8,winner4_5,winner4_4,winner4_6,winner4_3,winner4_7,winner4_2,winner4_18,winner4_54,winner4_63,winner4_72,winner4_1854,winner4_6372,winner4,winner12,winner34,winner],7);
            setCookie("MarchMadnessWinnerSpot",[winner12[2],winner34[2],winner[2]],7);            
            setCookie("MarchMadnessChampScore",champscore,7);
        
            var WinnerSet2=[winner12[1]+winner12[3],winner34[1]+winner34[3]]     
      
            var message='=SPLIT("'+PickName+','+WinnerSet+','+champscore+'",",")';
            var message2='=SPLIT("'+PickName+','+WinnerSet2+','+champscore+'",",")';
      
      
            if (getCookie('fill_style') == 'Upfront' || getCookie('fill_style') == ''){
                ifrm_height = '95px'
                ifrm_width = '370px'
                return "<p>"+'Championship:['+winner12[1]+winner12[3]+','+winner34[1]+winner34[3]+'] Winner:['+winner[1]+winner[3]+'] Score:['+champscore+']'+"</p><p id='message'>"+message+"</p>";
                
            }else if (getCookie('fill_style') == 'Round By Round'){
                ifrm_height = '100px'
                ifrm_width = '360px'
                return "<p>"+'Championship:['+winner12[1]+winner12[3]+','+winner34[1]+winner34[3]+'] Score:['+champscore+']'+"</p><p id='message'>"+message+"</p>";
                
            }                  
        }               
    }else if (getCookie('round_number') == 'R2'){
        R1 = 'Y'
        R2 = 'Y'
        R3 = 'Y'
        R4 = 'Y'
        R5 = 'Y'
        R6 = 'Y'

        if (getCookie('results_r5') == ''){
            setCookie('results_r5', window.prompt('Please copy results of the fifth round from the March Madness Links Page. \n\nPress Enter/Return key if here by mistake:'),100)
        }

        if (getCookie('results_r5')[0] == '['){      
            var winners = getCookie('results_r5').split(',')
            var winner12 = [winners[2],parseInt(winners[0].replace('[','')),'T','']
            var winner34 = [winners[3].replace(']',''),parseInt(winners[1]),'B','']         

            var winner = pickWinner(winner12[1],winner34[1],winner12[0],winner34[0],'F',R6);

            champscore=championshipScore();

            setCookie("MarchMadnessWinnerSet",[winner1_1,winner1_8,winner1_5,winner1_4,winner1_6,winner1_3,winner1_7,winner1_2,winner1_18,winner1_54,winner1_63,winner1_72,winner1_1854,winner1_6372,winner1,winner2_1,winner2_8,winner2_5,winner2_4,winner2_6,winner2_3,winner2_7,winner2_2,winner2_18,winner2_54,winner2_63,winner2_72,winner2_1854,winner2_6372,winner2,winner3_1,winner3_8,winner3_5,winner3_4,winner3_6,winner3_3,winner3_7,winner3_2,winner3_18,winner3_54,winner3_63,winner3_72,winner3_1854,winner3_6372,winner3,winner4_1,winner4_8,winner4_5,winner4_4,winner4_6,winner4_3,winner4_7,winner4_2,winner4_18,winner4_54,winner4_63,winner4_72,winner4_1854,winner4_6372,winner4,winner12,winner34,winner],7);
            //setCookie("MarchMadnessWinnerSpot",[winner1_1[2],winner1_8[2],winner1_5[2],winner1_4[2],winner1_6[2],winner1_3[2],winner1_7[2],winner1_2[2],winner1_18[2],winner1_54[2],winner1_63[2],winner1_72[2],winner1_1854[2],winner1_6372[2],winner1[2],winner2_1[2],winner2_8[2],winner2_5[2],winner2_4[2],winner2_6[2],winner2_3[2],winner2_7[2],winner2_2[2],winner2_18[2],winner2_54[2],winner2_63[2],winner2_72[2],winner2_1854[2],winner2_6372[2],winner2[2],winner3_1[2],winner3_8[2],winner3_5[2],winner3_4[2],winner3_6[2],winner3_3[2],winner3_7[2],winner3_2[2],winner3_18[2],winner3_54[2],winner3_63[2],winner3_72[2],winner3_1854[2],winner3_6372[2],winner3[2],winner4_1[2],winner4_8[2],winner4_5[2],winner4_4[2],winner4_6[2],winner4_3[2],winner4_7[2],winner4_2[2],winner4_18[2],winner4_54[2],winner4_63[2],winner4_72[2],winner4_1854[2],winner4_6372[2],winner4[2],winner12[2],winner34[2],winner[2]],7);            
            setCookie("MarchMadnessChampScore",champscore,7);

            var message='=SPLIT("'+PickName+','+WinnerSet+','+champscore+'",",")';

            ifrm_height = '95px'
            ifrm_width = '370px'

            return "<p>"+'Winner:['+winner[1]+winner[3]+'] Score:['+champscore+']'+"</p><p id='message'>"+message+"</p>";
        }
    }
}


write_sim = checkSim()
//console.log(write_sim)
//console.log("write_sim")



//document.getElementById(winner1_1[0]).click();
//document.getElementById(winner1_2[0]).click();
//document.getElementById(winner1_3[0]).click();
//document.getElementById(winner1_4[0]).click();
//document.getElementById(winner1_5[0]).click();
//document.getElementById(winner1_6[0]).click();
//document.getElementById(winner1_7[0]).click();
//document.getElementById(winner1_8[0]).click();
//document.getElementById("txtTopScore").value=27;
//document.getElementById("txtBottomScore").value=17;

var newDiv2 = document.createElement("script");
newDiv2.setAttribute('Id', 'AFT');
var newContent2 = document.createTextNode("function autoFill(){document.getElementById('AutoFillReady').innerHTML='Yes'}"); 
newDiv2.appendChild(newContent2); //add the text node to the newly created div. 
// add the newly created element and its content into the DOM 
var currentDiv = document.getElementById("div1"); 
document.body.insertBefore(newDiv2, currentDiv); 

var newDiv2 = document.createElement("P");
newDiv2.setAttribute('Id', 'AutoFillReady');
var newContent2 = document.createTextNode('No'); 
newDiv2.appendChild(newContent2); //add the text node to the newly created div. 
// add the newly created element and its content into the DOM 
var currentDiv = document.getElementById("div1"); 
document.body.insertBefore(newDiv2, currentDiv); 

var newDiv2 = document.createElement("P");
newDiv2.setAttribute('Id', 'MarchMadnessWinnerSpot');
var newContent2 = document.createTextNode(getCookie("MarchMadnessWinnerSpot")); 
newDiv2.appendChild(newContent2); //add the text node to the newly created div. 
// add the newly created element and its content into the DOM 
var currentDiv = document.getElementById("div1"); 
document.body.insertBefore(newDiv2, currentDiv); 










var ifrm = document.createElement('iframe');
ifrm.setAttribute('id', 'ifrm'); // assign an id
ifrm.width = ifrm_width ;
ifrm.height = ifrm_height ;
ifrm.style.position = "fixed";
ifrm.style.top = "30px";
ifrm.style.left = "30px";
ifrm.style.border = "solid 1px green";
ifrm.scrolling = 'no';

document.body.appendChild(ifrm);
var doc = document.getElementById('ifrm').contentWindow.document;
doc.open();

//var message='=SPLIT("'+location+','+WinnerSet+','+champscore+'",",")';

var fill_style_a = '';
var fill_style_b = '';
if (getCookie('fill_style') == 'Upfront'){
    fill_style_a = ' selected'
}else if (getCookie('fill_style') == 'Round By Round'){
    fill_style_b = ' selected'};

var round_a = '';
var round_b = '';
var round_c = '';
var round_d = '';
var round_e = '';
var round_f = '';
if (getCookie('round_number') == 'R64'){
    round_a = ' selected'
}else if (getCookie('round_number') == 'R32'){
    round_b = ' selected'
}else if (getCookie('round_number') == 'R16'){
    round_c = ' selected'
}else if (getCookie('round_number') == 'R8'){
    round_d = ' selected'
}else if (getCookie('round_number') == 'R4'){
    round_e = ' selected'
}else if (getCookie('round_number') == 'R2'){
    round_f = ' selected'};  

var setCookie_code = "<script>function setCookie(cname, cvalue, exdays) {var d = new Date(); d.setTime(d.getTime() + (exdays*24*60*60*1000)); var expires = 'expires='+d.toUTCString(); document.cookie = cname + '=' + cvalue + '; ' + expires;};</script>";
var copyButton_code = "<script>function copyToClipboard(text) {window.prompt('Copy it, Hit Enter then Paste into Google Spreadsheets:', document.getElementById('message').innerHTML)}</script>"
var newsimbutton = "<button onclick=setCookie('storedsim','',100)>New Simulation</button>";
var refreshbutton = "<button onclick=window.top.location.reload()>Refresh</button>";
var copybutton = '<button onclick=copyToClipboard()>Copy</button>';
var autofillbutton = "<button onClick=parent.autoFill()>Auto Fill</button> "
var roundSelect = '<select id="round_number" onchange="changed_round()"><option'+round_a+' value="R64">Round of 64</option><option'+round_b+' value="R32">Round of 32</option><option'+round_c+' value="R16">Sweet 16</option><option'+round_d+' value="R8">Elite 8</option><option'+round_e+' value="R4">Final 4</option><option'+round_f+' value="R2">Championship</option></select>'
var fillStyleSelect = '<select id="fill_style" onchange="changed_fill_style()"><option'+fill_style_a+' value="Upfront">Upfront</option><option'+fill_style_b+' value="Round By Round">Round By Round</option></select>'
var changed_fill_style_code = "<script>function changed_fill_style(){var x = document.getElementById('fill_style').value; setCookie('fill_style',x,100)}</script>";
var changed_round_code = "<script>function changed_round(){var x = document.getElementById('round_number').value; setCookie('round_number',x,100)}</script>";
var clearcookiesbutton = "<button onclick=clearCookies()>Clear Cookies</button>";
var clearCookies_code = '<script>function clearCookies(){setCookie("storedsim","",100);setCookie("results_r1","",100);setCookie("results_r2","",100);setCookie("results_r3","",100);setCookie("results_r4","",100);setCookie("results_r5","",100);setCookie("txtFirstName","",100);setCookie("txtLastName","",100);setCookie("txtUserNameReg","",100);setCookie("txtEmailAddress","",100);setCookie("txtConfirmEmail","",100);setCookie("txtPhone","",100);setCookie("txtCity","",100);setCookie("txtPostalCode","",100);setCookie("txtExtraField","",100);setCookie("txtPasswordReg","",100);setCookie("txtConfirmPasswordReg","",100);}</script>';




var AutoFillScript = "<!DOCTYPE html><html><body>"+setCookie_code+copyButton_code+changed_fill_style_code+changed_round_code+clearCookies_code+roundSelect+fillStyleSelect+clearcookiesbutton+"<br>"+newsimbutton+refreshbutton+copybutton+autofillbutton+write_sim+"</body></html>";

doc.write(AutoFillScript);




doc.body.style.background= "white";
doc.close();

/*
window.onload = function(){
    Spots=getCookie("MarchMadnessWinnerSpot")
    console.log(Spots)
    AdjSpots=Spots.split(",")
    var inputs = document.getElementsByTagName('input');
    for(var i = 0; i < inputs.length; i++) {
        if(inputs[i].type.toLowerCase() == 'checkbox') {
            if(inputs[i].name == "chkGame1"){
                if(inputs[i].value == "0"){
                    if(AdjSpots[0] == "T"){
                        inputs[i].click()
                    }
                }
                if(inputs[i].value == "1"){
                    if(AdjSpots[0] == "B"){
                        inputs[i].click()
                    }
                }
            }
            if(inputs[i].name == "chkGame2"){
                if(inputs[i].value == "0"){
                    if(AdjSpots[1] == "T"){
                        inputs[i].click()
                    }
                }
                if(inputs[i].value == "1"){
                    if(AdjSpots[1] == "B"){
                        inputs[i].click()
                    }
                }
            }          
            if(inputs[i].name == "chkGame3"){
                if(inputs[i].value == "0"){
                    if(AdjSpots[2] == "T"){
                        inputs[i].click()
                    }
                }
                if(inputs[i].value == "1"){
                    if(AdjSpots[2] == "B"){
                        inputs[i].click()
                    }
                }
            }          
            if(inputs[i].name == "chkGame4"){
                if(inputs[i].value == "0"){
                    if(AdjSpots[3] == "T"){
                        inputs[i].click()
                    }
                }
                if(inputs[i].value == "1"){
                    if(AdjSpots[3] == "B"){
                        inputs[i].click()
                    }
                }
            }          
          
          
          
          
        }
    }
}

*/