<?xml version="1.0" encoding="UTF-8" ?>
<Module>
<ModulePrefs title="Countdown to Monthly Event" 
             directory_title="Countdown to Monthly Event"
             description="Count down how many more days until a monthly event, such as one that happens every third Friday, every first Sunday, every fifth Sunday, etc.  Number of days grows in size and turns more and more red each day as it gets closer!  Please submit comments so we will know what you like, what we can change, what new features you would like, what new gadgets you would like, and if you stop using this gadget, why. Thank you, and enjoy!"
             category="communication" 
             category2="lifestyle"
             scaling="false" scrolling="true" render_inline="never" singleton="false"
             height="180" width="280"
             thumbnail="http://hosting.gmodules.com/ig/gadgets/file/113198001483006027607/countdown_tn.png"
             title_url="http://mediawink.com"        
             author="MediaWink"
             author_email="mediawink+feedback@gmail.com"
             author_location="USA" 
             author_affiliation="MediaWink.com"
             author_photo="mediawink.png"
             author_aboutme="Provider of software for PC as well as cell phone."
             author_link="http://mediawink.com"
             author_quote="More fulfilling life through technology and education">
<Locale messages="http://mediawink.googlepages.com/msg_countdown_en.xml" /> 
</ModulePrefs>



<UserPref name="event" display_name="Edit Settings" required="true" default_value="The 3rd Friday"/> 
<UserPref name="ordinal" display_name="Ordinal (e.g. 3 for 3rd)" required="true" default_value="3" /> 
<UserPref name="eday" display_name="Day (0=Sun, 1=Mon, ...)" required="true" default_value="5" /> 
<Content type="html">

<![CDATA[
<style type=text/css>
#all {
font-family:arial,sans-serif;
text-align:center;
margin-top:6px;
}
#countdown_table {
font-family:arial,sans-serif;
font-size:smaller;
text-align:center;
}
#hoursTd {
font-size:smaller;
color:#777777;
}
</style>

<div id=all></div>

<script>

prefs=new _IG_Prefs(__MODULE_ID__);
fevent=prefs.getString("event");
emonth=eval(prefs.getString("month"));
edate=eval(prefs.getString("date"));
eday=eval(prefs.getString("eday"));
eyear=eval(prefs.getString("year"));
ordinal=eval(prefs.getString("ordinal"));


function updateEvent()
{
  // Set event date to Xth Yday
  today=new Date();
  eyear=today.getFullYear();
  emonth=today.getMonth()+1;

  xthYday = new Date();

  xthYday.setFullYear(eyear, emonth-1, 1);
  day = xthYday.getDay();
  edate = 8+eday-day + (ordinal-2)*7;
  if (edate <= (ordinal-1)*7) {
    edate += 7
  }
  if (today.getDate() > edate) {
    emonth++;
    if ( emonth == 13 )
    {
      eyear++;
      emonth=1;
    }
    xthYday.setFullYear(eyear, emonth-1, 1);
    day = xthYday.getDay();
    edate = 8+eday-day + (ordinal-2)*7;
    if (edate <= (ordinal-1)*7) {
      edate += 7
    }
  }

  edayspastnew=totdays[emonth-1]+edate
}

normal='<table width=100% id=countdown_table>' +
'<tr>' +
'<td id=1st_half align=right width=50%>' + getFirstMsgHalf("days_until") + '</td>' +
'<td id=days></td>' +
'<td id=2nd_half width=50% align=left>' + getSecondMsgHalf("days_until") + '</td>' +
'</tr>' +
'<tr>' +
'<td id=hoursTd colspan=3>' +
'<span id=hours></span>  :  <span id=minutes></span>  :  <span id=seconds></span>' +
'</td>' +
'</tr>' +
'</table>';
_gel("all").innerHTML=normal;
daysin=new Array(31,28,31,30,31,30,31,31,30,31,30,31)
totdays=new Array()
totdays[0]=0

updateEvent()

for (var i=1;i<12;i++){
  totdays[i]=totdays[i-1]+daysin[i-1]
}

function formattedMSG(id, param1, param2) {
  var msg = prefs.getMsg(id);
  msg = msg.replace(/\$1\%s/, param1);
  msg = msg.replace(/\$2\%ds/, param2);
  return msg;
}

function getFirstMsgHalf(id) {
  var msg = prefs.getMsg(id);
  var i = msg.indexOf("%1$s");
  msg = msg.slice(0, i);
  return msg.replace(/\%2\$d/, "<br><b>" + fevent + "</b><br>(" + eyear+"-"+emonth+"-"+edate + ")");
}

function getSecondMsgHalf(id) {
  var msg = prefs.getMsg(id);
  var i = msg.indexOf("%1$s");
  msg = msg.slice(i + 4, msg.length);
  return msg.replace(/\%2\$d/, "<br><b>" + fevent + "</b><br>(" + eyear+"-"+emonth+"-"+edate + ")");
}

function updatetimer(){
  updateEvent()
  today=new Date()
  happened=false
  dayspastnew=totdays[today.getMonth()]+today.getDate()
  daystill2=((eyear-today.getFullYear())*365+(edayspastnew-dayspastnew))
  if (daystill2<=0) {
    happened=true 
  }
  todayseconds=(60-today.getSeconds()).toString()
  if (happened==true) {
    todayseconds=today.getSeconds().toString()
  }
  if (todayseconds.length!=2) {
  todayseconds="0"+todayseconds
  }
  todayminutes=(60-today.getMinutes()).toString()
  if (happened==true) {
    todayminutes=today.getMinutes().toString()
  }
  if (todayminutes.length!=2) {
    todayminutes="0"+todayminutes
  }
  dayspastnew=totdays[today.getMonth()]+today.getDate()
  daystill=((eyear-today.getFullYear())*365+(edayspastnew-dayspastnew))
  todayhours=(-today.getHours()+daystill*24-1)
  if(happened==true){
    daystill = 0;
    todayhours= "00";
    todayminutes = "00";
    todayseconds = "00";
  }
  document.getElementById("seconds").innerHTML=todayseconds
  document.getElementById("minutes").innerHTML=todayminutes
  document.getElementById("hours").innerHTML=todayhours
  document.getElementById("days").innerHTML=daystill
  var num = 0xFF-daystill*0x8;
  if (num <= 17 )
  {
    num = 17;
  }
  document.getElementById("days").style.color="#"+num.toString(16)+"0000"
  num = 70 - daystill*2;
  document.getElementById("days").style.fontSize=num.toString(10)+ "pt"

  var msg_id="days_until";
  if (daystill==1){
    msg_id = "day_until";
  }
  document.getElementById("1st_half").innerHTML = getFirstMsgHalf(msg_id);
  document.getElementById("2nd_half").innerHTML = getSecondMsgHalf(msg_id);
  setTimeout("updatetimer()", 1000)
}
updatetimer()
</script>

<script type="text/javascript"><!--
google_ad_client = "pub-3939792523679113";
google_ad_width = 234;
google_ad_height = 60;
google_ad_format = "234x60_as";
google_ad_type = "text_image";
//2007-12-17: Phobia
google_ad_channel = "1410174289";
//google_ad_channel = "5475858339";
//google_ad_slot = "1410174289";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "0000FF";
google_color_text = "000000";
google_color_url = "008000";
//-->
</script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<br>
<script src="http://hosting.gmodules.com/ig/gadgets/file/113198001483006027607/try.js"></script>
]]>
</Content>
</Module> 

























