Jump to content

[SOLVED] Please code analyze


AV

Recommended Posts

// global variables
var gtdiff;         // diff between server and local time
var counttime=120;    // number of minutes to count down
//var counttime=2;    // number of minutes to count down
var onesec=1000; // milliseconds
var oneminute=60*onesec;
var gservertime = co_get_servertime();
var gfuturetime;

var countdownwidth='156px';
var countdownheight='30px';
var countdownbgcolor='lightgreen';
var opentags='<font face="Verdana" size="1">';
var closetags='</font>';

var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
var crosscount='';

// general function
function co_pad ( num ) { return ( ( num > 9 ) ? num : "0" + num ); }

var debugCounter = 0;
function co_debugMsg(msg) {
  // un rem the next line when you go live to prevent debug messages from showing
  return;
  debugCounter++;
  var t = document.createTextNode("\n" + co_pad(debugCounter) + ": " + msg);
  var br = document.createElement("br");
  var debug = document.getElementById("debug");
  debug.appendChild(t);
  debug.appendChild(br);
}

function co_get_servertime() {
  var stime = "October 12, 1988 23:59:55"; // Date format
  stime = "October 26, 2007 11:02:43"; // get date from server
  return new Date(stime);
}

function co_setfuturetimestamp(idate,tnum) {
  var tyy, tmm, tdd, thh, tmi=0;
  var rdate, rsec;
  var ttime = idate.getTime()+(tnum*oneminute);
  rdate = new Date(ttime);
//  tyy = rdate.getYear();
  tyy = rdate.getFullYear();
  tmm = rdate.getMonth();
  tdd = rdate.getDate();
  thh = rdate.getHours();
  if (thh%2 != 0) { thh = thh-1;} // Not even adj to even hrs count down
  if (tnum < 60) { tmi = rdate.getMinutes(); }
  return new Date(tyy,tmm,tdd,thh,tmi,0); // set new time w/ 0 sec
}

function co_redirect_refresh_page() {
  window.location="http://www.mywebsite.com/index.html";
}

function co_refresh_alert() {
  alert("Demo is refreshing, please wait...");
}

function co_get_futuretime(tnum) {
  var curtime = new Date();
  gtdiff=Date.parse(gservertime)-Date.parse(curtime);
  return co_setfuturetimestamp(gservertime,tnum);
}

function co_seconds_elapsed (istarttime) {
  curtime = new Date();
  var time_diff=Date.parse(istarttime)-(Date.parse(curtime)+gtdiff); // adj to get server time
  return Math.floor ( (time_diff) / onesec ); // sec elapsed
}
// general function

function co_dmsg(ehour,emin,esec) {
//  var msg1 = opentags + "Demos refresh in " + co_pad(ehour) + ":" + co_pad(emin) + ":" + co_pad(esec);
  var msg1 = opentags + "Count Down: " + co_pad(ehour) + ":" + co_pad(emin) + ":" + co_pad(esec);
  if(ehour<=0 && emin<=0 && esec<=1){
//    window.location.reload();  this is like DOS and put high load on server, BAD!!!
    gservertime=gfuturetime;
    gfuturetime=co_get_futuretime(counttime);
    co_debugMsg("server "+gservertime);
    co_debugMsg("future "+gfuturetime);
//    co_redirect_refresh_page();
    co_refresh_alert();
  }
  else{
    if (document.layers){
      co_debugMsg("else "+gservertime);
      document.countdownnsmain.document.countdownnssub.document.write(msg1);
      document.countdownnsmain.document.countdownnssub.document.close();
    }
    else if (document.all||document.getElementById){
      crosscount.innerHTML = msg1;
    }
  }
}

// THIS FUNCTION TAKES THE SECONDS ELAPSED AND CONVERTS THEM FOR OUTPUT
function co_countdown(){
  setTimeout("co_countdown()",onesec); // set timer delay
  var secs = co_seconds_elapsed (gfuturetime);   // TAKE THE SECONDS ELAPSED
  var mins = Math.floor ( secs / 60 );   // CONVERT SECONDS TO MINUTES AND SECONDS
  secs = secs - (mins * 60);
  var hour = Math.floor ( mins / 60 );   // CONVERT MINUTES TO HOURS AND MINUTES
  mins = mins - (hour * 60);
  co_dmsg(hour,mins,secs);
}

function co_start_countdown(){
  if (document.layers) document.countdownnsmain.visibility="show";
  else if (document.all||document.getElementById)
    crosscount = document.getElementById&&!document.all ? document.getElementById("countdownie") : countdownie;
  co_countdown();
}

<!-- main -->
if (document.all||document.getElementById)
  document.write('<span id="countdownie" style="width:'+countdownwidth+'; background-color:'+countdownbgcolor+'"></span>');

gfuturetime=co_get_futuretime(counttime);
window.onload=co_start_countdown;

 

Hi, I have found this code at opensourcecms.com.

I wish to know what happends after time reaches 0.

 

Regards

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.