
// Browser Detection
isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
NS4 = (document.layers) ? true : false;
IEmac = ((document.all)&&(isMac)) ? true : false;
IE4plus = (document.all) ? true : false;
IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
IE5 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.")!=-1)) ? true : false;
ver4 = (NS4 || IE4plus) ? true : false;
NS6 = (!document.layers) && (navigator.userAgent.indexOf('Netscape')!=-1)?true:false;

// Body onload utility (supports multiple onload functions)
var gSafeOnload = new Array();
function SafeAddOnload(f)
{
	if (IEmac && IE4)  // IE 4.5 blows out on testing window.onload
	{
		window.onload = SafeOnload;
		gSafeOnload[gSafeOnload.length] = f;
	}
	else if  (window.onload)
	{
		if (window.onload != SafeOnload)
		{
			gSafeOnload[0] = window.onload;
			window.onload = SafeOnload;
		}		
		gSafeOnload[gSafeOnload.length] = f;
	}
	else
		window.onload = f;
}
function SafeOnload()
{
	try {
		for (var i=0;i<gSafeOnload.length;i++)
			gSafeOnload[i]();
	} catch (e) {}
}

function OpenWindowCentered(url, key, w, h, useParentForMetrics, settings)
{
	if( useParentForMetrics )
	{
		sLeft = parseInt(isNaN(window.parent.screenX)?window.parent.screenLeft:window.parent.screenX);
		sTop = parseInt(isNaN(window.parent.screenY)?window.parent.screenTop:window.parent.screenY);
		myWidth = 0
		myHeight = 0;
	if( typeof( window.parent.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.parent.innerWidth;
		myHeight = window.parent.innerHeight;
	} else if( document.documentElement &&
		( parent.document.documentElement.clientWidth || parent.document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = parent.document.documentElement.clientWidth;
		myHeight = parent.document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = parent.document.body.clientWidth;
		myHeight = parent.document.body.clientHeight;
	}
	} else {
		sLeft = parseInt(isNaN(window.screenX)?window.screenLeft:window.screenX);
		sTop = parseInt(isNaN(window.screenY)?window.screenTop:window.screenY);
		myWidth = 0
		myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement &&
		( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	}
		LeftPosition = (myWidth) ? (myWidth-w)/2 + sLeft : 0;
		TopPosition = (myHeight) ? (myHeight-h)/2 - 32 + sTop : 0;
		if( settings == '' || settings == null ) settings = 'menubar=no,scrollbars=no,statusbar=no';
		settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',' + settings;
		newwin = window.open( url, key, settings );
		if( LeftPosition < 0 || TopPosition < 0 ) newwin.moveTo(LeftPosition, TopPosition);
		return newwin;
}

function dateFormat(format,dateel){

if( dateel == null ) return '';
if( dateel.value == '' ) return '';
origvalue = dateel.value.replace('-', '/').replace('-', '/'); //"05062003";
if( origvalue.indexOf('/') < 0 && origvalue.indexOf('-') < 0 ) origvalue = origvalue.substring(0, 2) + '/' + origvalue.substring(2, 4) + '/' + origvalue.substring(4, 999);
s = origvalue.replace(/^(\d\d)(\d\d)(\d{4})$/,"$1$2$3");
sa = s.split('/');
tmpmonth = sa[0];
tmpday = sa[1];
tmpyear = sa[2];
if( tmpyear == null ) tmpyear = (new Date()).getFullYear();
dateobj = new Date(tmpyear, tmpmonth, tmpday);
if( tmpyear + '' == 'NaN' ) dateobj = new Date(origvalue);

months = new Array(
"January","February","March","April",
"May","June","July","August","September",
"October","November","December");
mons = new Array(
"Jan","Feb","Mar","Apr","May","Jun","Jul",
"Aug", "Sep","Oct","Nov","Dec");
days = new Array(
"Sunday","Monday","Tuesday","Wednesday",
"Thursday","Friday","Saturday");
dys = new Array(
"Sun","Mon","Tues","Wed","Thurs","Fri","Sat");

// Build vars
//if(dateobj.getFullYear() > 1900)
m = dateobj.getMonth();
d = dateobj.getDate();
yy = dateobj.getFullYear() % 100;
if(tmpyear.toString().length <= 2) {
	if(yy > 50)
	  yyyy = dateobj.getFullYear();
	else
	  yyyy = 100 + dateobj.getFullYear();
}
else
  yyyy = dateobj.getFullYear();
Day = days[dateobj.getDay()];
Dy = dys[dateobj.getDay()];
Month = months[m-1];
Mon = mons[m-1];
if( (Month + '') == "undefined" )
{
	Month = "December";
	Mon = "Dec";
	m = 12;
	yyyy = yyyy - 1;
}
if(m.toString().length < 2)
  mm = "0" + m + "";
else
  mm = m;

if(d.toString().length < 2)
  dd = "0" + d + "";
else
  dd = d;

codes = new Array("Month","Mon","mm","m","Day","Dy","dd","d","yyyy","yy");
lastmstring = format;
replaceOld("!Month",Month);
replaceOld("!Mon",Mon);
replaceOld("!mm",mm);
replaceOld("!m",m);
replaceOld("!Day",Day);
replaceOld("!Dy",Dy);
replaceOld("!dd",dd);
replaceOld("!d",d);
replaceOld("!yyyy",yyyy);
replaceOld("!yy",yy);

if( lastmstring.indexOf('NaN') >= 0 )
	return '';
else
	return lastmstring;
}

function replaceOld(before,after){
indexOfIt = lastmstring.indexOf(before);
if(indexOfIt >= 0)
  {
  beforeIt = lastmstring.substring(0, indexOfIt);
  afterIt = lastmstring.substring(indexOfIt + before.length, lastmstring.length);
  lastmstring = beforeIt + after + afterIt;
  replaceOld(before,after);
  return true;
  }
return false;
}


