<!--

/**
 * Common Form Library
 * Comprised of the latest version
 * of Validation Routines and some
 * new stuff
 * Serguei Mokhov, 13/09/2000
 * Updated: $Header: /cvsroot/travelsearcheng/travel-search-engine/js/common_form_lib.js,v 1.6 2002/12/02 20:15:22 mokhov Exp $
 * mokhov@cs.concordia.ca
 */

/**
 * 12/03/2001
 * - Added support for English and French languages
 *   for the dateInputBlock();
 * - made HTML code XHTML 1.0 compliant;
 * - Added timeInputBlock() and its support for the the English and French languages;
 */

var g_aMonthsEn = new Array
(
	"January",
	"February",
	"March",
	"April",
	"May",
	"June",
	"July",
	"August",
	"September",
	"October",
	"November",
	"December"
);

var g_aMonthsFr = new Array
(
	"Janvier",
	"F&eacute;vrier",
	"Mars",
	"Avril",
	"Mai",
	"Juin",
	"Juillet",
	"Aout",
	"Septembre",
	"Octobre",
	"Novembre",
	"D&eacute;cembre"
);

var g_aMonthsFrEn = new Array();

for(var i = 0; i < g_aMonthsFr.length; i++)
{
	g_aMonthsFrEn[i] = g_aMonthsEn[i] + " / " + g_aMonthsFr[i];
}

var g_aMonthsRu = new Array
(
	"ßíâàðü",
	"Ôåâðàëü",
	"Ìàðò",
	"Àïðåëü",
	"Ìàé",
	"Èþíü",
	"Èþëü",
	"Àâãóñò",
	"Ñåíòÿáðü",
	"Îêòÿáðü",
	"Íîÿáðü",
	"Äåêàáðü"
);

var g_aCaptionsEn = new Array
(
	"Day",
	"Month",
	"Year",
	"Hour",
	"Minute",
	"Second"
);

var g_aCaptionsFr = new Array
(
	"Jour",
	"Mois",
	"Ann&eacute;e",
	"Heure",
	"Minute",
	"Second"
);

var g_aCaptionsRu = new Array
(
	"×èñëî",
	"Ìåñÿö",
	"Ãîä",
	"HOUR",
	"MINUTE",
	"SECOND"
);

var DAY = 0;
var MONTH = 1;
var YEAR = 2;
var HOUR = 3;
var MINUTE = 4;
var SECOND = 5;


function timeInputBlock
(
	p_strBlockName,
	p_strLanguage,
	p_iMinuteInterval,
	p_iSecondInterval,
	p_bSecondsNeeded,
	p_bTipCaptionNeeded,
	p_strHeader,
	p_oDocument,
	p_iInitHour,
	p_iInitMinute,
	p_iInitSecond,
	p_strStyle
)
{
	var l_iMinuteInterval = p_iMinuteInterval ? p_iMinuteInterval : 15;
	var l_iSecondInterval = p_iSecondInterval ? p_iSecondInterval : 15;

	var l_aCaptions;

	if(p_strLanguage == "fr")
	{
		l_aCaptions = g_aCaptionsFr;
	}
	else if(p_strLanguage == "ru")
	{
		l_aCaptions = g_aCaptionsRu;
	}
	else
	{
		l_aCaptions = g_aCaptionsEn;
	}

	var l_strHTML = "";

	l_strHTML += '<table cellpadding="0" cellspacing="0" border="0">';

	if(p_bTipCaptionNeeded)
	{
		l_strHTML +=
			'<tr><td colspan="2"><span style="font: normal 10px/10px Arial">' + l_aCaptions[HOUR] + '</span></td>' +
			'<td colspan="2"><span style="font: normal 10px/10px Arial">' + l_aCaptions[MINUTE] + '</span></td>';

		if(p_bSecondsNeeded)
		{
			l_strHTML += '<td><span style="font: normal 10px/10px Arial">' + l_aCaptions[SECOND] + '</span></td></tr>';
		}
	}

	l_strHTML += '<tr><td><select style="font: normal 10px/10px Verdana" name="' + p_strBlockName + 'Hour" id="' + p_strBlockName + 'Hour">';

	var l_iHourSelected = p_iInitHour ? p_iInitHour : 0;

	for(var i = 0; i < 24; i++)
	{
		l_strHTML += "<option value=\"" + ( (i < 10) ? "0" : "" ) + i + "\"" + (l_iHourSelected == i ? " selected" : "")  + ">" + ( (i < 10) ? "0" : "" ) + i + "</option>";
	}

	l_strHTML +=
		'</select></td><td><b>:</b></td>' +
		'<td><select style="font: normal 10px/10px Verdana" name="' + p_strBlockName + 'Minute" id="' + p_strBlockName + 'Minute">';

	var l_iMinuteSelected = p_iInitMinute ? p_iInitMinute : 0;

	for(i = 0; i < 60; i += p_iMinuteInterval)
	{
		l_strHTML += "<option value=\"" + ( (i < 10) ? "0" : "" ) + i + "\"" + (l_iMinuteSelected == i ? " selected" : "")  + ">" + ( (i < 10) ? "0" : "" ) + i + "</option>";
	}

	l_strHTML +=
		'</select></td>';

	if(p_bSecondsNeeded)
	{
		var l_iSecondSelected = p_iInitSecond ? p_iInitSecond : 0;

		for(i = 0; i < 60; i += p_iSecondInterval)
		{
			l_strHTML += "<option value=\"" + ( (i < 10) ? "0" : "" ) + i + "\"" + (l_iSecondSelected == i ? " selected" : "")  + ">" + ( (i < 10) ? "0" : "" ) + i + "</option>";
		}

		l_strHTML +=
			'<td><b>:</b></td>' +
			'<td><select style="font: normal 10px/10px Verdana" name="' + p_strBlockName + 'Second" id="' + p_strBlockName + 'Second">'+
			'</select></td>';
	}

	if(p_bTipCaptionNeeded && p_strLanguage == "franglais")
	{
		l_strHTML +=
			'<tr><td colspan="2"><span style="font: normal 10px/10px Arial">' + g_aCaptionsFr[HOUR] + '</span></td>' +
			'<td colspan="2"><span style="font: normal 10px/10px Arial">' + g_aCaptionsFr[MINUTE] + '</span></td>';

		if(p_bSecondsNeeded)
		{
			l_strHTML += '<td><span style="font: normal 10px/10px Arial">' + g_aCaptionsFr[SECOND] + '</span></td></tr>';
		}
	}

	l_strHTML +=
		'</tr>' +
		'</table>';

	if(p_oDocument)
	{
		p_oDocument.write(l_strHTML);
	}
	else
	{
		return l_strHTML;
	}
}


function dateInputBlock
(
	p_strBlockName,      // for the form
	p_strLanguage,       // languages supported: en, fr, franglais, ru
	p_bTipCaptionNeeded, // Include field caption into the block if true
	p_strHeader,
	p_oDocument,         // if not null, will write to it, else return HTML string
	p_iInitDay,          // starting day
	p_iInitMonth,        // ="= month
	p_iInitYear,         // ="= year
	p_iYearRange, // if specified and non-zero, will be a drop down of years [p_iInitYear ... p_iInitYear + p_iYearRange]
	p_strCaptionPlacement, // default - top, non-default - inside dropdowns, matters when p_bTipCaptionNeeded is true	
	p_strStyle
)
{	var l_aMonths;
	var l_aCaptions;

	if(!p_iYearRange)
		p_iYearRange = 0;

	if(!p_strCaptionPlacement)
		p_strCaptionPlacement = "top";

	if(p_strLanguage == "fr")
	{
		l_aMonths = g_aMonthsFr;
		l_aCaptions = g_aCaptionsFr;
	}
	else if(p_strLanguage == "ru")
	{
		l_aMonths = g_aMonthsRu;
		l_aCaptions = g_aCaptionsRu;
	}
	else if(p_strLanguage == "franglais")
	{
		l_aMonths = g_aMonthsFrEn;
		l_aCaptions = g_aCaptionsEn;
	}
	else
	{
		l_aMonths = g_aMonthsEn;
		l_aCaptions = g_aCaptionsEn;
	}

	var l_strHTML = "";

	l_strHTML += '<table cellpadding="0" cellspacing="0" border="0">';

	if(p_bTipCaptionNeeded)
	{
		if(p_strCaptionPlacement == "top")
			l_strHTML +=
				'<tr><td><span '+ p_strStyle +'>' +
				l_aCaptions[DAY] +
				'</span></td><td><span '+ p_strStyle +'>' +
				l_aCaptions[MONTH] +
				'</span></td><td><span '+ p_strStyle +'>' +
				l_aCaptions[YEAR] + '</span></td></tr>';
	}

	l_strHTML += '<tr><td><select '+ p_strStyle +' name="' + p_strBlockName + 'Day" id="' + p_strBlockName + 'Day">';

	var l_iDaySelected = p_iInitDay ? p_iInitDay : 1;

	if(p_strCaptionPlacement == "inside")
		l_strHTML += '<option value="">Day</option>';

	for(var i = 1; i <= 31; i++)
	{
		l_strHTML +=
			"<option value=\"" + i + "\"" + (l_iDaySelected == i ? " selected" : "")  + ">" +
			( (i < 10) ? "0" : "" ) + i + "</option>";
	}

	l_strHTML +=
		'</select></td>' +
		'<td><select '+ p_strStyle +' name="' + p_strBlockName + 'Month" id="' + p_strBlockName + 'Month">';

	var l_aSelectedMonth = new Array();
	var l_iSelectedMonth = p_iInitMonth ? p_iInitMonth : 1;

	if(p_strCaptionPlacement == "inside")
		l_strHTML += '<option '+ p_strStyle +' value="">Month</option>';

	for(i = 0; i < 12; i++)
	{
		l_aSelectedMonth[i] = new String( ((l_iSelectedMonth == i + 1) ? " selected" : "") );
		l_strHTML += "<option value='"+ (i+1) + "' " + l_aSelectedMonth[i] + ">" + l_aMonths[i] + "</option>";
	}

	if(p_iInitYear > 0)
	{
		var l_iSelectedYear = p_iInitYear ? p_iInitYear : "200";

		l_strHTML += '</select></td>';

		if(!p_iYearRange)
		{
			l_strHTML +=
				'<td><input type="text" '+ p_strStyle +' name="' + p_strBlockName + 'Year" id="' + p_strBlockName +
				'Year" size="4" maxsize="4" value="' + l_iSelectedYear + '"></td>';
		}
		else
		{
			l_strHTML +=
				'<td>' +
				'<select '+ p_strStyle +' name="' + p_strBlockName + 'Year" id="' + p_strBlockName + 'Year">';

			//if(p_strCaptionPlacement == "inside")
			//l_strHTML += '<option value="">Year</option>';

			for(i = 0; i < p_iYearRange; i++)
				l_strHTML += '<option value="'+(p_iInitYear + i)+'">'+(p_iInitYear + i)+'</option>';

			l_strHTML +=
				'</select></td>';
		}
	}

	if(p_bTipCaptionNeeded && p_strLanguage == "franglais")
	{
		l_strHTML +=
			'<tr><td><span style="font: normal 10px/10px Arial">' +
			g_aCaptionsFr[DAY] +
			'</span></td><td><span style="font: normal 10px/10px Arial">' +
			g_aCaptionsFr[MONTH] +
			'</span></td><td><span style="font: normal 10px/10px Arial">' +
			g_aCaptionsFr[YEAR] + '</span></td></tr>';
	}

	l_strHTML +=
		'</tr>' +
		'</table>';

	if(p_oDocument)
	{
		p_oDocument.write(l_strHTML);
	}
	else
	{
		return l_strHTML;
	}
}


/***************** Validation Routines *****************/

//Checks if the user typed just white spaces in the
//TEXT element (white spaces are space, return, and tab)
// Input: string object
//Output: 'true'  if only white spaces in th entered text
//        'false' otherwise
function OnlyWhiteSpaces(txt)
{
	for(var i = 0; i < txt.length; i++)
	{
		if
		(
			txt.substring(i, i + 1) != " " &&
			txt.substring(i, i + 1) != "" &&
			txt.substring(i, i + 1) != "\n"
		)
		return false;
	}

	return true;
}

//Check whether the input is numeric or not
//in the TEXT element
// Input: string element object
//Output: 'true'  if string contain only numbers
//        'false' otherwise
function isDigit(field)
{
	for(var i = 0; i < field.length; i++)
		if(field.substring(i, i + 1) < "0" || field.substring(i, i + 1) > "9")
			return false;

	return true;
}

//Check is there radio button checked or not
//in the same group of radio buttons
// Input: Array of Radio buttons
//        Number radio buttons in te array
//Output: 'true'  if checked radio button found
//        'false' otherwise
function isRadioSetChecked(paRadioSet, pnRadios)
{
  for(var i = 0; i < pnRadios; i++)
    if(paRadioSet[i].checked) return true;
  return false;
}

//-->
