// lsmonitor_full.js: write normal full style live scoring monitor

function change_style(sno)
{
   document.F_OPTIONS.SB_LSSTYLE.selectedIndex = sno;
   process_options();
}

function write_top_sponsors()
{
   var dhtml = "";
   document.write(dhtml);
}

function write_bottom_sponsors()
{
   write_top_sponsors();
}

function write_data_table()
{
   var j=0;
   for (var i=0; i<players.length; i++)
   {
       p=players[i].split("/~");
       if (p[2] == "Y")
       {
           sel_players[j] = p[0];
           j++;
       }
   }

   document.write ("<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 ALIGN=CENTER WIDTH='90%' id='t_head'>");
   document.write ("<TR>");
   
   if (options.showphotos)
   {
       document.write ("<TD CLASS=TD0C width=" + photo_div_width + ">" +
                       "<DIV id=LEADER_PHOTO_DIV " +
                       "style='width:" + photo_div_width + "px;height:" + photo_div_height + "px;" +
                       "filter:revealTrans(transition=" + transition_type + ",duration=2);" +
                       "text-align:center;vertical-align:middle;'>" +
                       "</DIV>" +
                       "</TD>");
   }

   document.write ("<TD CLASS=TD0C>");
   document.write ("<TABLE BORDER=0 CELLSPACING=2 CELLPADDING=0 width=100% ALIGN=CENTER>");
   document.write ("<TR><TD align=center>" +
                   "<DIV ID=D_LAST_UPDATED CLASS=TD0C></DIV>" +
                   "</TD></TR>");
   document.write ("<TR><TD align=center>" +
                   "<DIV ID=D_LS_STATUS CLASS=HEAD2></DIV>" +
                   "</TD></TR>");
   document.write ("<TR><TD align=center>" +
                   "<INPUT TYPE=BUTTON ID=B_REFRESH NAME=B_REFRESH CLASS=BUTT VALUE=''" +
                   " onclick='process_refresh_button()'>" +
                   "</TD></TR>");
   document.write ("<TR><TD align=center>" +
                   "<DIV CLASS=FOOT1>" +
                   "<a href='#options'>Options & Preferences</a>" +
                   "<BR>" +
                   "<a href='#reports'>Tournament Reports & Statistics</a>" +
                   "</DIV>" +
                   "</TD></TR>");
   document.write ("<TR><TD align=center>" +
                   "<DIV ID=LS_MESS></DIV>" +
                   "<DIV ID=LS_CUT></DIV>" +
                   "</TD></TR>");
   document.write ("</TABLE>");
   if (typeof write_top_sponsors != "undefined")
       write_top_sponsors();
   document.write ("</TD>");

   if (options.showphotos)
   {
       document.write ("<TD CLASS=TD0C width=" + photo_div_width + ">" +
                       "<DIV id=LOWRND_PHOTO_DIV " +
                       "style='width:" + photo_div_width + "px;height:" + photo_div_height + "px;" +
                       "filter:revealTrans(transition=" + transition_type + ",duration=2);" +
                       "text-align:center;vertical-align:middle;'>" +
                       "</DIV>" +
                       "</TD>");
   }

   document.write ("</TR></TABLE>");

   document.write ("<TABLE BORDER=0 CELLSPACING=10 CELLPADDING=0 ALIGN=CENTER>");
   document.write ("<TR>");
   document.write ("<TD STYLE='text-align:center;vertical-align:top;'>");
   document.write ("<DIV ID='DIV_F1'></DIV>");
   document.write ("</TD>");
   var f_req = true;
   if (options.leaderboardonly)
       f_req = false;
   if (tourn.curr_round < 2)
       f_req = false;
   if (f_req)
   {
       document.write ("<TD STYLE='text-align:center;vertical-align:top;'>");
       document.write ("<DIV ID='DIV_F2'></DIV>");
       document.write ("</TD>");
   }
   document.write ("</TR>");
   document.write ("<TR>");
   document.write ("<TD STYLE='text-align:center;vertical-align:top;'>");
   document.write ("<P>&nbsp;</P>");
   document.write ("<DIV ID='DIV_F3'></DIV>");
   document.write ("</TD>");
   if (f_req)
   {
       document.write ("<TD STYLE='text-align:center;vertical-align:top;'>");
       document.write ("<P>&nbsp;</P>");
       var last_round = tourn.curr_round - 1;
       document.write ("<DIV ID='DIV_F4'></DIV>");
       document.write ("</TD>");
   }
   document.write ("</TR>");
   document.write ("</TABLE>");
}

function write_report_links()
{
   document.write ("<A name='#reports'>" +
                   "<DIV class=TD0C style='padding-top:10px;' id='d_report_links'>" +
                   "<TABLE border=0 cellspacing=5 cellpadding=0 ALIGN=CENTER>" +
                   "<TR>" +
                   "<TD style='margin:auto;text-align:center;' colspan=2>" +
                   "<DIV class=HEAD2>Tournament Reports & Statistics</DIV>" +
                   "</TD>" +
                   "</TR>" +
                   "<TR>" +
                   "<TD class=TD0C style='vertical-align:top;font-size:100%;'>" +
                   "<DIV class=FOOT1 style='text-align:justify; width:300px;'>" +
                   "There are a number of reports available for this tournament " +
                   "that provide instant access to draws, scores and " +
                   "statistics. Any report selected from the list " +
                   "will be opened in a new window and will not affect the " +
                   "live scoring monitor." +
                   "<P>" +
                   "Please visit the <A href='javascript:load_tic()'>Tour Information Centre</A> " +
                   "if you require reports on any other tournaments, " +
                   "orders of merit, cumulative statistics or previous seasons." +
                   "</DIV>" +
                   "</TD>");
   document.write ("<TD class=TD0L style='vertical-align:top;' nowrap>" +
                   "<UL>");
   for (var i=0; i<reports.length; i++)
   {
       var r=reports[i].split("/~");
       document.write ("<LI><A href='javascript:load_report(" + i + ")'>" + r[0] + "</A></LI>");
   }
   document.write ("</UL></TD></TR></TABLE></DIV>");
   if (typeof write_bottom_sponsors != "undefined")
       write_bottom_sponsors();
}

function write_options_form()
{
   document.write ("<A name='#options'>" +
                   "<DIV id='d_options_form'>");
   document.write ("<FORM NAME=F_OPTIONS style='margin:0px;'>");
   document.write ("<TABLE BORDER=0 CELLSPACING=4 CELLPADDING=4 ALIGN=CENTER>");
   document.write ("<TR>");
   document.write ("<TD STYLE='text-align:center;border-width:0px;vertical-align:top;' COLSPAN=2>");
   document.write ("<P CLASS=HEAD1>Options</P>");
   document.write ("</TD>");
   document.write ("</TR>");
   document.write ("<TR>");
   if (!tourn.matchplay)
   {
       document.write ("<TD style='text-align:center;vertical-align:top;'>" +
                       "<FIELDSET>" +
                       "<LEGEND class=HEAD2>Select Players to Follow</LEGEND>" +
                       "<DIV CLASS=FOOT1>Note - hold down the Ctrl key when clicking<BR>" +
                       "to select multiple players</DIV>");
       document.write ("<SELECT MULTIPLE NAME=SB_PLAYERS CLASS=SELECT SIZE=8>");
       for (var i=0; i<players.length; i++)
       {
           p=players[i].split("/~");
           document.write ("<OPTION");
           if (p[2] == "Y")
               document.write (" SELECTED");
           document.write (">" + p[1] + "</OPTION>");
       }
       document.write ("</SELECT>");
       document.write ("</FIELDSET></TD>");
   }
   document.write ("<TD style='text-align:center;vertical-align:top;'>" +
                   "<FIELDSET>" +
                   "<LEGEND class=HEAD2>General Options</LEGEND>");
   document.write ("<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=1 ALIGN=CENTER>");
   if (!tourn.matchplay)
   {
       document.write ("<TR>" +
                       "<TD CLASS=TD0L>Live Scoring Monitor Style</TD>" +
                       "<TD>" +
                       "<SELECT NAME=SB_LSSTYLE CLASS=SELECT>" +
                       "<OPTION VALUE='F'>Full Page</OPTION>" +
//                     "<OPTION VALUE='O'>Compact</OPTION>" +
                       "<OPTION VALUE='M'>Mini</OPTION>" +
                       "</SELECT></TD></TR>");
       document.write ("<TR>" +
                       "<TD CLASS=TD0L>Scoreboard Positions to Show</TD>" +
                       "<TD>" +
                       "<SELECT NAME=TB_SBLIMIT CLASS=SELECT>");
       for (var i=5; i<161; i+=5)
           document.write ("<OPTION value='" + i + "'>Top " + i + "</OPTION>");
       document.write ("</SELECT></TD></TR>");
       document.write ("<TR>" +
                       "<TD CLASS=TD0L>Show Full-Card Leaderboard Only</TD>" +
                       "<TD><INPUT TYPE=CHECKBOX NAME=CB_LBONLY CLASS=SELECT></TD>" +
                       "</TR>");
       document.write ("<TR>" +
                       "<TD CLASS=TD0L>Show Player Photos</TD>" +
                       "<TD><INPUT TYPE=CHECKBOX NAME=CB_PHOTOS CLASS=SELECT></TD>" +
                       "</TR>");
   }
   document.write ("<TR>" +
                   "<TD CLASS=TD0L>Player Nationalities</TD>" +
                   "<TD>" +
                   "<SELECT NAME=TB_NATS CLASS=SELECT>" +
                   "<OPTION value='O'>Omit nationalities</OPTION>" +
                   "<OPTION value='C'>Show as codes</OPTION>");
   if (tic_params.flags_base != '')
       document.write ("<OPTION value='F'>Show as flags</OPTION>");
   document.write ("</SELECT></TD></TR>");
   if (!tourn.matchplay)
       document.write ("<TR>" +
                       "<TD CLASS=TD0L>Group Together Tied Positions</TD>" +
                       "<TD><INPUT TYPE=CHECKBOX NAME=CB_GRPTIES CLASS=SELECT></TD>" +
                       "</TR>");
   document.write ("<TR>" +
                   "<TD CLASS=TD0L>Automatic Refresh Period</TD>" +
                   "<TD>" +
                   "<SELECT NAME=TB_REFPER CLASS=SELECT>" +
//                 "<OPTION value='0.1'>6 seconds</OPTION>" +
//                 "<OPTION value='0.2'>12 seconds</OPTION>" +
//                 "<OPTION value='0.5'>30 seconds</OPTION>" +
                   "<OPTION value='1'>1 minute</OPTION>" +
                   "<OPTION value='2'>2 minutes</OPTION>" +
                   "<OPTION value='3'>3 minutes</OPTION>" +
                   "<OPTION value='4'>4 minutes</OPTION>" +
                   "<OPTION value='5'>5 minutes</OPTION>" +
                   "<OPTION value='10'>10 minutes</OPTION>" +
                   "<OPTION value='15'>15 minutes</OPTION>" +
                   "<OPTION value='20'>20 minutes</OPTION>" +
                   "<OPTION value='30'>30 minutes</OPTION>" +
                   "</SELECT></TD></TR>");
   document.write ("</TABLE></FIELDSET>");
   document.write ("</TD>");
   document.write ("</TR>");
   document.write ("<TR>" +
                   "<TD align=center COLSPAN=2>" +
                   "<INPUT TYPE=BUTTON NAME=B_SUBMIT CLASS=BUTT VALUE='Save &amp; Apply Options*' onclick='process_options(true)'>" +
                   "<SPAN style='width:60px;'>&nbsp;</SPAN>" +
                   "<INPUT TYPE=BUTTON NAME=B_SUBMIT CLASS=BUTT VALUE='Apply Options Only' onclick='process_options(false)'>" +
                   "<DIV class=FOOT1 style='padding-top:4px;'>*Options will be saved in a local \"cookie\" on your system if allowed</DIV>" +
                   "</TD>" +
                   "</TR>");
   document.write ("</TABLE>");
   document.write ("</FORM></DIV>");
   document.write ("<DIV class='TD0C'>" +
                   "<DIV id='d_countdown_area'  style='margin:auto;display:none;width:300px;height:16px;border:1px solid black;padding:1px;background-color:#e0e0e0;position:relative;'>" +
                   "<DIV id='d_countdown_inner' style='height:100%;font-size:8pt;text-align:left;color:black;background-color:#c0c0c0;position:absolute;top:0px;left:0px;'></DIV>" +
                   "<DIV id='d_countdown_text'  style='height:100%;vertical-align:middle;font-size:8pt;text-align:center;color:black;position:absolute;top:0px;left:0px;width:100%;'>&nbsp;</DIV>" +
                   "</DIV>" +
                   "</DIV>");
   if (!tourn.matchplay)
   {
       for (var i=0; i<document.F_OPTIONS.SB_LSSTYLE.options.length; i++)
           if (document.F_OPTIONS.SB_LSSTYLE.options[i].value == options.mon_style)
               document.F_OPTIONS.SB_LSSTYLE.options[i].selected = true;
       document.F_OPTIONS.TB_SBLIMIT.value=options.sb_limit;
       document.F_OPTIONS.CB_LBONLY.checked=options.leaderboardonly;
       document.F_OPTIONS.CB_PHOTOS.checked=options.showphotos;
   }
   if ((options.shownats != "C") && (options.shownats != "F") && (options.shownats != "O"))
       options.shownats = "C";
   document.F_OPTIONS.TB_NATS.value=options.shownats;
   if (!tourn.matchplay)
       document.F_OPTIONS.CB_GRPTIES.checked=options.groupties;
   document.F_OPTIONS.TB_REFPER.value=options.auto_mins;
}

function write_wap_mess()
{
   document.write ("<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=4 WIDTH='80%' ALIGN=CENTER>");
   document.write ("<TR>");
   document.write ("<TD CLASS=FOOT1>");
   document.write ("<B>Mobile Internet Service</B>" +
                   "<DIV ALIGN=LEFT>" +
                   "If you have an Internet-enabled mobile WAP phone you can " +
                   "keep in touch at all times with the latest live scores and other statistics " +
                   "from the " + tic_params.tour_name + ". " +
                   "<A href='javascript:wap_information();'>" +
                   "Click here for more information." +
                   "</A>");
   document.write ("</TD>");
   document.write ("</TR>");
   document.write ("</TABLE>");
}

function check_cookie()
{
   if (options.reloading)
       return(false);
   var allcookies = this.document.cookie;
   var cookies = allcookies.split(";");
   var thiscookie = "";
   for (var i=0; i<cookies.length; i++)
   {
       var ss = cookies[i].indexOf("LSMONOPTS=");
       if (ss > -1)
       {
           ss += 10;
           var thiscookie = cookies[i].substring(ss, cookies[i].length);
       }
   }
   if (thiscookie == "")
       return(false);
   var params = thiscookie.split("||");
   for (var i=0; i<params.length; i++)
   {
       var c = params[i].split("~");
       if (c[0] == "style")  options.mon_style       = c[1];
       if (c[0] == "limit")  options.sb_limit        = c[1];
       if (c[0] == "lbonly") options.leaderboardonly = (c[1] == "Y");
       if (c[0] == "photos") options.showphotos      = (c[1] == "Y");
       if (c[0] == "nats")   options.shownats        =  c[1];
       if (c[0] == "gties")  options.groupties       = (c[1] == "Y");
       if (c[0] == "amins")  options.auto_mins       = c[1];
   }
}

function generate_main_body()
{
   if (browser_ok("full"))
   {
       check_cookie();
       write_data_table();
       write_report_links();
       write_options_form();
       if (tic_params.wapurl != '')
           write_wap_mess();
       if ((tic_params.noheadings == "Y") && (tic_params.nomessages == "Y") && (!options.showphotos))
       {
           document.getElementById("t_head").style.display = "none";
           document.getElementById("d_report_links").style.display = "none";
           document.getElementById("d_options_form").style.display = "none";
           if (document.getElementById("DIV_F3") != null)
               document.getElementById("DIV_F3").style.display = "none";
       }
   }
}
