function OpenWindow(mypage, myname, w, h, scroll)
{
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	
	winprops = 'height='+h+', width='+w+', top='+wint+', left='+winl+', scrollbars='+scroll+', resizable';
	win = window.open(mypage, myname, winprops);
	
	if (parseInt(navigator.appVersion) >= 4) 
	{ 
		win.window.focus();
	}
}


function jsClockTimeZone(offset, city)
{
	// Copyright 1999 - 2001 by Ray Stott
	// OK to use if this copyright is included
	// Script available at http://www.crays.com/jsc
	// http://www.javascriptmall.com/jsc/jsC4Uclocks.htm
	var TimezoneOffset = offset;  // adjust for time zone
	var localTime = new Date();
	var ms = localTime.getTime() 
		+ (localTime.getTimezoneOffset() * 60000)
		+ TimezoneOffset * 3600000;
	var time =  new Date(ms);
	var hour = time.getHours() ;
	var minute = time.getMinutes();
	var second = time.getSeconds();
	var temp = "" + ((hour > 12) ? hour - 12 : hour);
	if (hour==0) temp = "12";
	if (temp.length==1) temp = " " + temp;
	temp += ((minute < 10) ? ":0" : ":") + minute;
	temp += ((second < 10) ? ":0" : ":") + second;
	temp += (hour >= 12) ? " PM" : " AM";
	$('h3#' + city).html(temp);
	setTimeout("jsClockTimeZone(" + offset + ", '" + city +"')", 1000);
}


/*
Author: Robert Hashemian
http://www.hashemian.com/
*/
function calcage(secs, num1, num2) {
  s = ((Math.floor(secs/num1))%num2).toString();
  if (LeadingZero && s.length < 2)
    s = "0" + s;
  return s;
}

function CountBack(secs) 
{
 	if (secs < 0) 
	{
		// put the image in #compbox
		//$('#compbox').html();
    	return;
  	}

	DisplayStr = DisplayFormat.replace(/%%D%%/g, calcage(secs, 86400, 100000));
	DisplayStr = DisplayStr.replace(/%%H%%/g, calcage(secs, 3600, 24));
	DisplayStr = DisplayStr.replace(/%%M%%/g, calcage(secs, 60, 60));
	DisplayStr = DisplayStr.replace(/%%S%%/g, calcage(secs, 1, 60));

	$('p#when-it-happens').html(DisplayStr);

	if (CountActive) setTimeout("CountBack(" + (secs+CountStepper) + ")", SetTimeOutPeriod);
}

var TargetDate = "05/07/2009 11:00 AM UTC+0800";
//var TargetDate = "04/30/2009 08:44 PM UTC+0200";
var BackColor = "#191919";
var ForeColor = "white";
var CountActive = true;
var CountStepper = -1;
var LeadingZero = true;
var DisplayFormat = "%%D%%:%%H%%:%%M%%:%%S%%";
var FinishMessage = "It is finally here!";
var SetTimeOutPeriod = 0;

function when_it_happens()
{
	if (typeof(BackColor)=="undefined")
	  BackColor = "white";
	if (typeof(ForeColor)=="undefined")
	  ForeColor= "black";
	if (typeof(TargetDate)=="undefined")
	  TargetDate = "12/31/2020 5:00 AM";
	if (typeof(DisplayFormat)=="undefined")
	  DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
	if (typeof(CountActive)=="undefined")
	  CountActive = true;
	if (typeof(FinishMessage)=="undefined")
	  FinishMessage = "";
	if (typeof(CountStepper)!="number")
	  CountStepper = -1;
	if (typeof(LeadingZero)=="undefined")
	  LeadingZero = true;


	CountStepper = Math.ceil(CountStepper);
	if (CountStepper == 0)
	  CountActive = false;
	SetTimeOutPeriod = (Math.abs(CountStepper)-1)*1000 + 990;
	//putspan(BackColor, ForeColor);
	var dthen = new Date(TargetDate);
	var dnow = new Date();
	if(CountStepper>0)
	  ddiff = new Date(dnow-dthen);
	else
	  ddiff = new Date(dthen-dnow);
	gsecs = Math.floor(ddiff.valueOf()/1000);
	CountBack(gsecs);
}