/* site specific scripts */

var month = '09';     //  months (* = next month, 0 = this month, 1-12 = specific month)
var day = '12';      //  day of month
var hour = '0';        //  hours of the day (0 - 23)
var tz = '+1';         //  timezone
var display = 'dispClock'; //dispClock is the id of the div
var nMonth = '9';     //  new month date for end of kyn week
var nDay = '18';      //  new day date
var nHour = '23';       //  new hour time
var hasChanged=true;   // variable to determin if the countdown has changed to the new date or not.


function siteInit(){
  // Called with the body onload event.
  // Customise according to site requirements.
  //displayTZCountDown(setTZCountDown(month,day,hour,tz),display);
 //  displayTZCountDown(0,display);
}

function unCheck(){
    email = document.getElementById('email');
    telephone = document.getElementById('telephone');
    if(email){
        email.checked = '';
    }
    if(telephone){
        telephone.checked = '';
    }
}

function unCheckNoContact(){
    nocontact = document.getElementById('no_contact');
    if(nocontact){
        nocontact.checked = '';
    }
}


function setTZCountDown(month,day,hour,tz)
{
   var toDate = new Date();

   if (month == '*')
      toDate.setMonth(toDate.getMonth() + 1);
   else if (month > 0)
   {
      if (month <= toDate.getMonth())
         toDate.setYear(toDate.getYear() + 1);
      toDate.setMonth(month-1);
   }

   if (day.substr(0,1) == '+')
   {
      var day1 = parseInt(day.substr(1));
      toDate.setDate(toDate.getDate()+day1);
   }
   else
   {
      toDate.setDate(day);
   }

   toDate.setHours(hour);
   toDate.setMinutes(0-(tz*60));
   toDate.setSeconds(0);
   var fromDate = new Date();
   fromDate.setMinutes(fromDate.getMinutes() + fromDate.getTimezoneOffset());
   var diffDate = new Date(0);
   diffDate.setMilliseconds(toDate - fromDate);
   return Math.floor(diffDate.valueOf()/1000);
}

function change()
{
   month = nMonth;
   day = nDay;
   hour = nHour;
   hasChanged=true;
   document.getElementById('dispTitle').innerHTML='Know your Numbers! week time left ...';
   displayTZCountDown(setTZCountDown(month,day,hour,tz),display);

}

function displayTZCountDown(countdown,dispClock)
{
   if (countdown < 0 && hasChanged==false) {
      change();
   }
   else if (countdown <0 && hasChanged==true){
      document.getElementById('dispTitle').innerHTML='KYN Week - Thanks to all who took part!';
   }
   else
   {
      var secs = countdown % 60;
      if (secs < 10)
         secs = '0'+secs;
      var countdown1 = (countdown - secs) / 60;
      var mins = countdown1 % 60;
      if (mins < 10)
         mins = '0'+mins;
      countdown1 = (countdown1 - mins) / 60;
      var hours = countdown1 % 24;
      var days = (countdown1 - hours) / 24;
      document.getElementById(dispClock).innerHTML ='<table><tr><td>'+days+'</td><th>Days</th><td>'+hours+'</td><th>Hours</th><td>'+mins+'</td><th>Minutes</th><td>'+secs+'</td><th>Seconds</th></tr></table>';
      setTimeout('displayTZCountDown('+(countdown-1)+',\''+dispClock+'\');',999);
   }
}

function MM_swapImgRestore() { //restores the color of the image when the user no longer hovers.
  var i,x,a=document.MM_sr;
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++)
   x.src=x.oSrc;
}

function MM_findObj(n, d)  //used for changinG the image
{
  var p,i,x;
  if(!d) d=document;
  if((p=n.indexOf("?"))>0&&parent.frames.length)
  {
   d=parent.frames[n.substring(p+1)].document;
   n=n.substring(0,p);
  }
  if(!(x=d[n])&&d.all) x=d.all[n];
  for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() //changes the color of the image on the hover. Calls the function above.
{
  var i,j=0,x,a=MM_swapImage.arguments;
  document.MM_sr=new Array;
  for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null)
   {
      document.MM_sr[j++]=x;
      if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];
   }
}

function hoverRegionName(x)
{
   document.getElementById("current1").style.display="none";
   document.getElementById("current2").style.display="none";

   document.getElementById("current"+x).style.display="inline";
}

function hoverOffRegionName()
{
   document.getElementById("current1").style.display="none";
   document.getElementById("current2").style.display="none";
}
function printPageComponent() {
  html  = '<div id="print-page">';
  html += '  <a \n';
  html += '         onclick="window.print();" \n';
  html += '         title="Print the current page"> \n';
  html += '         Print this page';
  html += '  <a />';
  html += '</div>';
  return html;
}



