var dayName = new Array ("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
// form a  new array containing days of the week to be referenced by variable dayName

var now = new Date;
// create a date variable named now referencing the current date and time
var dn = now.getDate(); // set dn to the date in the month
if ( dn <10) {dn="0"+dn}// if day number is less than 10 insert a 0 before the day number
var mth = (now.getMonth()+1) // set mth to the month number plus 1 to compensate for javascript counting from 0
if(mth <10) {mth="0"+mth}// if moth number is less than 10 insert a 0 before the month number
var yr = (now.getFullYear().toString()).substr(2); // set yr to the year, convert the year to a string and extract the last two digits

//***********************************************************************************************************

//text resize function

function setMinHeight(size)
{
var txtVal = parseInt(size);
document.getElementById('main').style.fontSize = txtVal +'%';
document.cookie ='elemSize='+ txtVal;

}

//***************************************************************************************************************
// getcookie function from w3c schools website
function getCookie(c_name)
{
if (document.cookie.length>0)
  {
var c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
var c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
}
//===============================================================================



//text size cookie set and read function

function setTxtCookie()
{
 var cookVal = getCookie("elemSize");
if(cookVal == "")
{cookVal = 105;}

setMinHeight(cookVal)

}

//===============================================================================
//pop up window function for index page

function newWin() {
   OpenWindow=window.open("", "newwin", "height=630, width=450,toolbar=no,scrollbars=yes,menubar=no");
OpenWindow.document.write('<html>\n<head>\n<title>Wales Autumn Internationals<\/title>\n<\/head>\n')
OpenWindow.document.write('<body>\n<img src="images/golf2010.jpg" height="600" width="400" alt="Golf Day at the quins">\n')
OpenWindow.document.write('<p align="right">\n<a href="javascript:window.close()">Close<\/a>\n<\/p>\n')
OpenWindow.document.write('<\/BODY>\n')
OpenWindow.document.write('<\/HTML>\n')
OpenWindow.focus()
OpenWindow.document.close()

   }

//===============================================================================
//countdown script adapted from http://scripts.franciscocharrua.com/countdown-clock.php
function countdown_clock(year, month, day, hour, minute, format)
         {
         //I chose a div as the container for the timer, but
         //it can be an input tag inside a form, or anything
         //who's displayed content can be changed through
         //client-side scripting.
         html_code = '<div id="countdown">Only</div>';

         
         document.write(html_code);
         
         countdown(year, month, day, hour, minute, format);                
         }
         
function countdown(year, month, day, hour, minute, format)
         {
         Today = new Date();
         Todays_Year = Today.getFullYear() - 2000;
         Todays_Month = Today.getMonth();                  
         
         //Convert both today's date and the target date into miliseconds.                           
         Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(), 
                                 Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime();                                 
         Target_Date = (new Date(year, month - 1, day, hour, minute, 00)).getTime();                  
         
         //Find their difference, and convert that into seconds.                  
         Time_Left = Math.round((Target_Date - Todays_Date) / 1000);
         
         if(Time_Left < 0)
            Time_Left = 0;
         
         switch(format)
               {
               case 0:
                    //The simplest way to display the time left.
                    document.all.countdown.innerHTML = Time_Left + ' seconds';
                    break;
               case 1:
                    //More datailed.
                    days = Math.floor(Time_Left / (60 * 60 * 24));
                    Time_Left %= (60 * 60 * 24);
                    hours = Math.floor(Time_Left / (60 * 60));
                    Time_Left %= (60 * 60);
                    minutes = Math.floor(Time_Left / 60);
                    Time_Left %= 60;
                    seconds = Time_Left;
                    
                    dps = 's'; hps = 's'; mps = 's'; sps = 's';
                    //ps is short for plural suffix.
                    if(days == 1) dps ='';
                    if(hours == 1) hps ='';
                    if(minutes == 1) mps ='';
                    if(seconds == 1) sps ='';
                    
	  document.getElementById('countdown').innerHTML= 'Only ';
	  document.getElementById('countdown').innerHTML += days + ' day' + dps + ' ';
                    document.getElementById('countdown').innerHTML += hours + ' hour' + hps + ' ';
                    document.getElementById('countdown').innerHTML += minutes + ' minute' + mps + ' and ';
                    document.getElementById('countdown').innerHTML += seconds + ' second' + sps;
	  document.getElementById('countdown').innerHTML +=' before the Spar / Maesteg Quins 2010 Golf Challenge begins.'
	
                    break;
               default: 
                    document.all.countdown.innerHTML = Time_Left + ' seconds';
               }
               
         //Recursive call, keeps the clock ticking.
         setTimeout('countdown(' + year + ',' + month + ',' + day + ',' + hour + ',' + minute + ',' + format + ');', 1000);
         }
//=================================================================================
