IE = false;
NS = false;
if (document.all) IE = true;
if (document.layers) NS = true;
MONTH = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
DAY = new Array('S','M','T','W','T','F','S');
theTime = new Date(document.lastModified);
var	currentForm = null;
var	currentElem = null;
var	pulldown = false;

function overDay(d,withinMonth)
{
	if (withinMonth)
		d.style.backgroundColor='#9abcde';
	else
		d.style.backgroundColor='#abcdef';
	d.style.border = '1px white solid';
	d.style.color = '#ffffff';
}

function outDay(d,withinMonth)
{
	if (withinMonth)
	{
		d.style.backgroundColor='#DFDDD0';
		d.style.border = '1px #DFDDD0 solid';
	}
	else
	{
		d.style.backgroundColor='#EAE7D4';
		d.style.border = '1px #EAE7D4 solid';
	}

	d.style.color = '#000000';
}
function readTime()
{
	if (pulldown)
	{
		hElem = eval('document.forms[currentForm].elements["'+currentElem+'_hr"]');
		mElem = eval('document.forms[currentForm].elements["'+currentElem+'_min"]');
		sElem = eval('document.forms[currentForm].elements["'+currentElem+'_sec"]');
		var hr = hElem.options[hElem.selectedIndex].value;
		var min = mElem.options[mElem.selectedIndex].value;
		var sec = sElem.options[sElem.selectedIndex].value;
		theTime = new Date(2000,0,1,hr,min,sec);
	}
	else
	{
		var Time = (document.forms[currentForm].elements[currentElem].value).toString;
	}
}
function transferTime()
{
	var hr = theTime.getHours();
	var min = theTime.getMinutes();
	var sec = theTime.getSeconds();
	
	if (pulldown)
	{
		hElem = eval('document.forms[currentForm].elements["'+currentElem+'_hr"]');
		mElem = eval('document.forms[currentForm].elements["'+currentElem+'_min"]');
		sElem = eval('document.forms[currentForm].elements["'+currentElem+'_sec"]');

		var index=-1;
		for (var i=1; i<hElem.options.length && index==-1; i++)
			if (hElem.options[i].value > hr) index=i-1;
		if (index==-1) index=hElem.options.length;
		hElem.selectedIndex = index;

		var index=-1;
		for (var i=1; i<mElem.options.length && index==-1; i++)
			if (mElem.options[i].value > min) index=i-1;
		if (index==-1) index=mElem.options.length;
		mElem.selectedIndex = index;

		var index=-1;
		for (var i=1; i<sElem.options.length && index==-1; i++)
			if (sElem.options[i].value > sec) index=i-1;
		if (index==-1) index=sElem.options.length;
		sElem.selectedIndex = index;

		edited=true;
		hideWindow("ClockPopup");
	}
	else
	{
		document.forms[currentForm].elements[currentElem].value = month + '/'+day+'/'+year;
		edited=true;
		hideWindow("ClockPopup");
	}
}
function adjustTime(step,type)
{
	switch(type){
		case 'h': theTime.setHours(theTime.getHours()+step);break;
		case 'm': theTime.setMinutes(theTime.getMinutes()+step);break;
		case 's': theTime.setSeconds(theTime.getSeconds()+step);break;
		
	}
	displayTime();
}


function displayTime()
{
	var hr = theTime.getHours();
	var min = theTime.getMinutes();
	var sec = theTime.getSeconds();
	if (hr >= 12)
		{	
			if (hr>12) hr -=12;
			document.forms["clock"].elements["AMPM"].value = 'PM';
		}
	else document.forms["clock"].elements["AMPM"].value = 'AM';

	if (min < 10) min = '0'+min;
	if (sec < 10) sec = '0'+sec;
	document.forms["clock"].elements["Time"].value = hr+':'+min+':'+sec;
}
function swapAMPM()
{
	var hr = theTime.getHours()
	if (hr < 12) hr+=12;
	else hr-=12;
	theTime.setHours(hr);
	displayTime();
}
function setClock(e)
{
	x = e.offsetX-59;
	y = e.offsetY-59;
//	r = Math.sqrt(x*x+y*y);
	if (x==0)
	{
		if (y>0)
			rad = 180;
		else
			rad = 0;
	}
	else
	{
		rad = Math.atan(y/x)/Math.PI*2*90;
		rad+=90;
		if (x<0) rad+=180;
	}
	
	hr = Math.floor(rad/30);
	min = Math.floor(60*(rad-30*hr)/30.0);
	sec = 0;

	var oldHr = theTime.getHours()
	if (oldHr >= 12) hr+=12;

	theTime = new Date(2000,0,1,hr,min,sec);
	displayTime();
}

function setTime(value)
{
}
function buildClock()
{
	var cal = "<table style='border:2px menutext outset;'cellpadding=0 cellspacing=0 width=350><tr><td><form name='clock'>";
	cal += "<table width=350 height=150 bgcolor=menu style='background-Color:menu; color:menutext;'><tr>";
	cal += "<td rowspan=3><img src='/images/wysiwyg/clock.gif' onclick='setClock(window.event);'></td>";
	cal += "<td><b>Selected Time</b></td></tr>";
	cal += "<tr><td><table bgcolor=white>";
	cal += "<tr><td colspan=3><input name='Time' value='' size=9 maxlength=9 onchange='setTime(this.value);'><input name='AMPM' value='AM' size=3 maxlength=2 onclick='swapAMPM();this,blur();'></td></tr>";
	cal += "<tr><td>hr</td><td>min</td><td>sec</td></tr>";
	cal += "<tr>";
	cal += "<td><img onclick=\"adjustTime(1,'h');\" src='/images/wysiwyg/step_up.gif'><img onclick=\"adjustTime(6,'h');\" src='/images/wysiwyg/jump_up.gif'></td>";
	cal += "<td><img onclick=\"adjustTime(1,'m');\" src='/images/wysiwyg/step_up.gif'><img onclick=\"adjustTime(15,'m');\" src='/images/wysiwyg/jump_up.gif'></td>";
	cal += "<td><img onclick=\"adjustTime(1,'s');\" src='/images/wysiwyg/step_up.gif'><img onclick=\"adjustTime(15,'s');\" src='/images/wysiwyg/jump_up.gif'></td>";
	cal += "</tr><tr>";
	cal += "<td><img onclick=\"adjustTime(-1,'h');\" src='/images/wysiwyg/step_down.gif'><img onclick=\"adjustTime(-6,'h');\" src='/images/wysiwyg/jump_down.gif'></td>";
	cal += "<td><img onclick=\"adjustTime(-1,'m');\" src='/images/wysiwyg/step_down.gif'><img onclick=\"adjustTime(-15,'m');\" src='/images/wysiwyg/jump_down.gif'></td>";
	cal += "<td><img onclick=\"adjustTime(-1,'s');\" src='/images/wysiwyg/step_down.gif'><img onclick=\"adjustTime(-15,'s');\" src='/images/wysiwyg/jump_down.gif'></td>";
	cal += "</tr></table>";
	cal += "</td></tr><tr><td><input type='submit' value='ok' onclick='transferTime();return false;'</td></tr>";
	cal += "</form></td></tr></table>";
	innerHTML = cal;
	if (IE)	theClock.innerHTML = innerHTML;
	else	{theClock.document.open();theClock.document.write(innerHTML);theClock.document.close();}

	return cal;
}
var theClock = null;
var timer = null;
windowOffsetX = 25;
windowOffsetY = 15;
function overWindow()
{
	clearTimeout(timer);
}

function outWindow()
{
	closeWindow("ClockPopup");
}

function closeWindow(winName) {
	timer = setTimeout("hideWindow('"+winName+"');",500);
}

function hideWindow(winName) {
	if (IE)
	{
		win = document.all[winName];
		win.style.display = 'none';
	}
	else
	{
		win = document.layers[winName];
		win.visibility = 'hidden';
	}
}

function showClock(obj,form,elem,isPulldown)
{
	if (isPulldown) pulldown = true;

	currentForm = form;
	currentElem = elem;
	x = window.event.clientX;
	y = window.event.clientY;
//	x = obj.absX+25;
//	y = obj.absY+10;
	windowH = document.body.offsetHeight;
	windowW = document.body.offsetWidth;
	if (IE)
	{
		theClock = document.all["ClockPopup"];
		if (!theClock)
		{
			theClock = document.createElement('DIV');
			theClock.style.zIndex=1;
			theClock.style.position = 'absolute';
			theClock.id = "ClockPopup";
			theClock.onmouseover = overWindow;
			theClock.onmouseout = outWindow;
			theClock = document.body.appendChild(theClock);
//			if (Clock.absY2 > windowH) Clock.style.top = windowH-Clock.offsetHeight;
//			if (Clock.absX2 > windowW) Clock.style.left = windowW-Clock.offsetWidth-15;
		}
		theClock.style.display = 'block';
		theClock.style.left=x;
		theClock.style.top=y;
	}
	else
	{
		theClock = document.layers["ClockPopup"];
		if (!theClock)
		{
			theClock = new Layer('Clock',window);
			theClock.onmouseover = overWindow;
			theClock.onmouseout = outWindow;
			theClock.left=x;
			theClock.top=y;
			theClock.zIndex=1;
		}
		theClock.visibility = 'show';
		theClock.left=x;
		theClock.top=y;
	}
	theTime = new Date();
	if (elem) readTime();
	buildClock();
	displayTime();

//	df_hideElement("SELECT",Clock);
//	df_hideElement("OBJECT",Clock);
//	df_hideElement("IFRAME",Clock);
}
