// Title: Tigra Calendar PRO
// URL: http://www.softcomplex.com/products/tigra_calendar_pro/
// Version: 1.3 (pop-up mode)
// Date: 02-26-2003 (mm-dd-yyyy)
// Technical Support: support@softcomplex.com (specify product title and order ID)
// Notes: This Script is shareware. Please visit url above for registration details.

var calendars = [];

// Constructor
function calendar (str_date, obj_control, str_min_date, str_max_date) {

	this.popup = cal_popup;
	this.UA=U_A=new _UserAgent();

	this.id = calendars.length;
	calendars[this.id] = this;

	if (!obj_control)
		return alert("Form element specified can't be found in the document.");
	this.control_obj = obj_control;
	
	var dt_params = (str_date ? cal_parse_date(str_date) : cal_date_only());
	
	var re_num = /^\-?\d+$/;
	if (str_min_date != null)
		this.min_date = (re_num.exec(str_min_date)
			? new Date (dt_params.valueOf() - new Number(str_min_date * 864e5))
			: cal_parse_date(str_min_date)
		).valueOf();
	if (str_max_date != null)
		this.max_date = (re_num.exec(str_max_date)
			? new Date (dt_params.valueOf() + new Number(str_max_date * 864e5))
			: cal_parse_date(str_max_date)
		).valueOf();

	this.dt_current = dt_params;
}

// Constructor - CUSTOMIZED VERSION #1
function startdatecal (str_date, obj_control, str_min_date, str_max_date) {

	this.popup = cal_popup;
	this.UA=U_A=new _UserAgent();

	this.id = calendars.length;
	calendars[this.id] = this;

	if (!obj_control)
		return alert("Form element specified can't be found in the document.");
	this.control_obj = obj_control;
	
	var dt_params = (str_date ? cal_parse_date(str_date) : cal_date_only());
	
	var re_num = /^\-?\d+$/;
	if (str_min_date != null)
		this.min_date = (re_num.exec(str_min_date)
			? new Date (dt_params.valueOf() - new Number(str_min_date * 864e5))
			: cal_parse_date(str_min_date)
		).valueOf();
	if (str_max_date != null)
		this.max_date = (re_num.exec(str_max_date)
			? new Date (dt_params.valueOf() + new Number(str_max_date * 864e5))
			: cal_parse_date(str_max_date)
		).valueOf();

	this.dt_current = dt_params;
}

// Constructor - CUSTOMIZED VERSION #2
function enddatecal (str_date, obj_control, str_min_date, str_max_date) {

	this.popup = cal_popup;
	this.UA=U_A=new _UserAgent();

	this.id = calendars.length;
	calendars[this.id] = this;

	if (!obj_control)
		return alert("Form element specified can't be found in the document.");
	this.control_obj = obj_control;
	
	var dt_params = (str_date ? cal_parse_date(str_date) : cal_date_only());
	
	var re_num = /^\-?\d+$/;
	if (str_min_date != null)
		this.min_date = (re_num.exec(str_min_date)
			? new Date (dt_params.valueOf() - new Number(str_min_date * 864e5))
			: cal_parse_date(str_min_date)
		).valueOf();
	if (str_max_date != null)
		this.max_date = (re_num.exec(str_max_date)
			? new Date (dt_params.valueOf() + new Number(str_max_date * 864e5))
			: cal_parse_date(str_max_date)
		).valueOf();

	this.dt_current = dt_params;
}

function cal_popup (num_datetime, b_end) {

	if (num_datetime)
		this.dt_current = new Date(num_datetime);
	else if (this.control_obj.value)
		this.dt_current = cal_parse_date(this.control_obj.value);
	
	this.control_obj.value = cal_generate_date(this.dt_current);
	if (b_end) return;
		
	var n_left = 200, n_top = 200, w = 200, h = 185;
	
	if(this.UA.mac && this.UA.ns4) w=260;
		
	if (screen) {
		n_left = (screen.width - w) >> 1;
		n_top = (screen.height - h) >> 1;
	}
	var obj_calwindow = window.open(
		'calendar.html?datetime='
		+ this.dt_current.valueOf()
		+ '&id=' + this.id, 'Calendar',
		'width='+ w +',height='+ h +',status=no,resizable=no,top=' + n_top + ','
		+'left=' + n_left + ',dependent=yes,alwaysRaised=yes'
	);
	obj_calwindow.opener = window;
	obj_calwindow.focus();
}

function cal_date_only (dt_datetime) {
	if (!dt_datetime)
		dt_datetime = new Date();
	dt_datetime.setHours(0);
	dt_datetime.setMinutes(0);
	dt_datetime.setSeconds(0);
	dt_datetime.setMilliseconds(0);
	return dt_datetime;
}

function _UserAgent() {
	var b = navigator.appName;
	var v = this.version = navigator.appVersion;
	var ua=this.uas = navigator.userAgent.toLowerCase();
	this.v = parseInt(v);
	this.mozilla=false;
	this.ns = (b=="Netscape");
	this.ie = (b=="Microsoft Internet Explorer");
	this.opera = ua.indexOf("opera")>0;
	if(ua.indexOf("netscape") < 0 && ua.indexOf("msie") < 0  && ua.indexOf("opera") < 0 && this.v>=5) {
		this.mozilla=true;
		this.ns=false;
	}
	if (this.ns) {
		this.v = parseInt(v);
		this.ns4 = (this.v==4);
		this.ns6 = (this.v>=5);
	}
	else if (this.ie) {
		this.ie4 = this.ie5 = this.ie55 = this.ie6 = false;
		if (v.indexOf('MSIE 4')>0) {this.ie4 = true; this.v = 4;}
		else if (v.indexOf('MSIE 5')>0) {this.ie5 = true; this.v = 5;}
		else if (v.indexOf('MSIE 5.5')>0) {this.ie55 = true; this.v = 5.5;}
		else if (v.indexOf('MSIE 6')>0) {this.ie6 = true; this.v = 6;}
	}
	else if (this.opera || this.mozilla) {
		this.v = parseInt(v);
	}
	this.win32 = ua.indexOf("win")>-1;
	this.mac = ua.indexOf("mac")>-1;
	this.other = (!this.win32 && !this.mac);
}
