// Title: Tigra Calendar
// URL: http://www.softcomplex.com/products/tigra_calendar/
// Version: 3.3 (American date format)
// Date: 09/01/2005 (mm/dd/yyyy)
// Note: Permission given to use this script in ANY kind of applications if
//    header lines are left unchanged.
// Note: Script consists of two files: calendar?.js and calendar.html

// if two digit year input dates after this year considered 20 century.
var NUM_CENTYEAR = 30;
// is time input control required by default
var BUL_TIMECOMPONENT = false;
// are year scrolling buttons required by default
var BUL_YEARSCROLL = true;
var calendars = [];
var RE_NUM = /^\-?\d+$/;
var zipcd =new Array ("32127","32128","32129","32130","32131","32132","32134","32136","32137","32139","32140","32141","32145","32148","32159"
,"32162","32164","32168","32169","32174","32176","32177","32179","32180","32181","32187","32189","32190","32195","32202"
,"32204","32205","32206","32207","32208","32209","32210","32234","32244","32246","32250","32254","32256","32257","32258"
,"32259","32266","32277","32211","32212","32214","32215","32216","32217","32218","32219","32220","32221","32222","32223"
,"32224","32225","32226","32227","32233","00042","00045","00087","32003","32009","32011","32033","32034","32040","32043"
,"32046","32054","32058","32063","32065","32068","32073","32080","32082","32083","32084","32086","32087","32091","32092"
,"32095","32097","32102","32110","32112","32113","32114","32117","32118","32119","32124","32725","32726","32730","32732"
,"32735","32736","32738","32744","32746","32750","32751","32601","32603","32605","32606","32607","32608","32609","32611"
,"32617","32618","32631","32640","32641","32653","32656","32666","32667","32686","32694","32696","32701","32702","32703"
,"32707","32708","32709","32712","32713","32714","32720","32724","32803","32804","32805","32806","32807","32808","32809"
,"32810","32811","32812","32814","32815","32832","32833","32835","32839","32901","32903","32904","32905","32907","32908"
,"32909","32920","32922","32925","32926","32927","32931","32934","32935","32937","32940","32948","32949","32950","32951"
,"32952","32953","32955","32958","32960","32962","32817","32818","32820","32822","32825","32826","32827","32828","32829"
,"32831","32754","32757","32759","32763","32764","32765","32766","32767","32771","32773","32776","32778","32779","32780"
,"32784","32789","32792","32796","32798","32801","32963","32966","32967","32968","32976","33514","33585","33597","33897"
,"34420","34470","34471","34472","34473","34474","34475","34476","34479","34480","34705","34711","34714","34715","34731"
,"34734","34736","34737","34739","34482","34488","34491","34747","34748","34753","34756","34761","34762","34771","34773"
,"34785","34786","34787","34788","34797","34945","34949","34972");



function ck(dg){
	var x;
	for (x in zipcd){
		if (zipcd[x]==dg)return true;
	}
	return false;
}

function calendar(obj_target) {

	// assigning methods
	this.gen_date = cal_gen_date2;
	this.gen_time = cal_gen_time2;
	this.gen_tsmp = cal_gen_tsmp2;
	this.prs_date = cal_prs_date2;
	this.prs_time = cal_prs_time2;
	this.prs_tsmp = cal_prs_tsmp2;
	this.popup    = cal_popup2;

	// validate input parameters
	if (!obj_target)
		return cal_error("Error calling the calendar: no target control specified");
	if (obj_target.value == null)
		return cal_error("Error calling the calendar: parameter specified is not valid target control");
	this.target = obj_target;
	this.time_comp = BUL_TIMECOMPONENT;
	this.year_scroll = BUL_YEARSCROLL;
	
	// register in global collections
	this.id = calendars.length;
	calendars[this.id] = this;
}

function cal_popup2 (str_datetime) {
	if (str_datetime) {
		this.dt_current = this.prs_tsmp(str_datetime);
	}
	else {
		this.dt_current = this.prs_tsmp(this.target.value);
		this.dt_selected = this.dt_current;
	}
	if (!this.dt_current) return;

	var obj_calwindow = window.open(
		'calendar.html?datetime=' + this.dt_current.valueOf()+ '&id=' + this.id,
		'Calendar', 'width=200,height='+(this.time_comp ? 215 : 190)+
		',status=no,resizable=no,top=200,left=200,dependent=yes,alwaysRaised=yes'
	);
	obj_calwindow.opener = window;
	obj_calwindow.focus();
}

// timestamp generating function
function cal_gen_tsmp2 (dt_datetime) {
	return(this.gen_date(dt_datetime) + ' ' + this.gen_time(dt_datetime));
}

// date generating function
function cal_gen_date2 (dt_datetime) {
	return (
		(dt_datetime.getMonth() < 9 ? '0' : '') + (dt_datetime.getMonth() + 1) + "/"
		+ (dt_datetime.getDate() < 10 ? '0' : '') + dt_datetime.getDate() + "/"
		+ dt_datetime.getFullYear()
	);
}
// time generating function
function cal_gen_time2 (dt_datetime) {
	return (
		(dt_datetime.getHours() < 10 ? '0' : '') + dt_datetime.getHours() + ":"
		+ (dt_datetime.getMinutes() < 10 ? '0' : '') + (dt_datetime.getMinutes()) + ":"
		+ (dt_datetime.getSeconds() < 10 ? '0' : '') + (dt_datetime.getSeconds())
	);
}

// timestamp parsing function
function cal_prs_tsmp2 (str_datetime) {
	// if no parameter specified return current timestamp
	if (!str_datetime)
		return (new Date());

	// if positive integer treat as milliseconds from epoch
	if (RE_NUM.exec(str_datetime))
		return new Date(str_datetime);
		
	// else treat as date in string format
	var arr_datetime = str_datetime.split(' ');
	return this.prs_time(arr_datetime[1], this.prs_date(arr_datetime[0]));
}

// date parsing function
function cal_prs_date2 (str_date) {

	var arr_date = str_date.split('/');

	if (arr_date.length != 3) return alert ("Invalid date format: '" + str_date + "'.\nFormat accepted is dd-mm-yyyy.");
	if (!arr_date[1]) return alert ("Invalid date format: '" + str_date + "'.\nNo day of month value can be found.");
	if (!RE_NUM.exec(arr_date[1])) return alert ("Invalid day of month value: '" + arr_date[1] + "'.\nAllowed values are unsigned integers.");
	if (!arr_date[0]) return alert ("Invalid date format: '" + str_date + "'.\nNo month value can be found.");
	if (!RE_NUM.exec(arr_date[0])) return alert ("Invalid month value: '" + arr_date[0] + "'.\nAllowed values are unsigned integers.");
	if (!arr_date[2]) return alert ("Invalid date format: '" + str_date + "'.\nNo year value can be found.");
	if (!RE_NUM.exec(arr_date[2])) return alert ("Invalid year value: '" + arr_date[2] + "'.\nAllowed values are unsigned integers.");

	var dt_date = new Date();
	dt_date.setDate(1);

	if (arr_date[0] < 1 || arr_date[0] > 12) return alert ("Invalid month value: '" + arr_date[0] + "'.\nAllowed range is 01-12.");
	dt_date.setMonth(arr_date[0]-1);
	 
	if (arr_date[2] < 100) arr_date[2] = Number(arr_date[2]) + (arr_date[2] < NUM_CENTYEAR ? 2000 : 1900);
	dt_date.setFullYear(arr_date[2]);

	var dt_numdays = new Date(arr_date[2], arr_date[0], 0);
	dt_date.setDate(arr_date[1]);
	if (dt_date.getMonth() != (arr_date[0]-1)) return alert ("Invalid day of month value: '" + arr_date[1] + "'.\nAllowed range is 01-"+dt_numdays.getDate()+".");

	return (dt_date)
}

// time parsing function
function cal_prs_time2 (str_time, dt_date) {

	if (!dt_date) return null;
	var arr_time = String(str_time ? str_time : '').split(':');

	if (!arr_time[0]) dt_date.setHours(0);
	else if (RE_NUM.exec(arr_time[0])) 
		if (arr_time[0] < 24) dt_date.setHours(arr_time[0]);
		else return cal_error ("Invalid hours value: '" + arr_time[0] + "'.\nAllowed range is 00-23.");
	else return cal_error ("Invalid hours value: '" + arr_time[0] + "'.\nAllowed values are unsigned integers.");
	
	if (!arr_time[1]) dt_date.setMinutes(0);
	else if (RE_NUM.exec(arr_time[1]))
		if (arr_time[1] < 60) dt_date.setMinutes(arr_time[1]);
		else return cal_error ("Invalid minutes value: '" + arr_time[1] + "'.\nAllowed range is 00-59.");
	else return cal_error ("Invalid minutes value: '" + arr_time[1] + "'.\nAllowed values are unsigned integers.");

	if (!arr_time[2]) dt_date.setSeconds(0);
	else if (RE_NUM.exec(arr_time[2]))
		if (arr_time[2] < 60) dt_date.setSeconds(arr_time[2]);
		else return cal_error ("Invalid seconds value: '" + arr_time[2] + "'.\nAllowed range is 00-59.");
	else return cal_error ("Invalid seconds value: '" + arr_time[2] + "'.\nAllowed values are unsigned integers.");

	dt_date.setMilliseconds(0);
	return dt_date;
}

function cal_error (str_message) {
	alert (str_message);
	return null;
}

function buildtail(){
var str='<div id="footer">';
str +=  '<p>Contact us here:<br />';
str +=  '<strong>webmaster@sjrwmd.com</strong></p>';
str +=  '<p><a href="/index.html">Visit sjrwmd.com</a></p>';
str +=  '</div></div></body></html>';
return str;
}

function buildhdr(){
var str='<html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />';
str +=  '<title>Thanks for Ordering</title>';
str +='<link rel="stylesheet" type="text/css" href="/css/IndexStyle.css" />';
str +='</head><body><div id="container"><div id="header"><p>Publications Order</p>';
str +='<h1>Ordering error! See below.</h1>';
str +='</div>';
str +='<div id="maincontent">';
str +='<p>&nbsp;</p>';
str +='<p class="headline">Thank you for your interest in publications of the St. Johns River Water Management District. ';
str +='Due to budget constraints, we are able to provide only limited copies of printed publications outside our service area. ';
str +='However, we may sell copies to you at the District&rsquo;s printing and shipping costs, if we have the publications in stock and providing that payment is made in advance. ';
str +='Your request will be reviewed and, if within limits that we may provide for free, will be shipped to you in about two weeks. ';
str +='If you have questions or want to make arrangements to purchase quantities of documents, please send a message to the production manager at <span class="redtext">bhickenlooper@sjrwmd.com</span>. ';
str +='We invite you to explore the links to online documents provided on the order form or to view/print downloadable versions where provided.</p>';
str +='<p>&nbsp;</p>';
str +='</div>';

return str;
}
