bFirstLoad = true;

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

var sSelecteddestinationCode = '';
var sSelectedresortCode ='';
var sSelectedhotelCode ='';

var SeasonCode = "S2004";
var SeasonPos = "";
var SeasonPMI = "";
var localFB;
var i;

var wCalendar;

if ( SeasonCode == 'S2005' ) {
	SeasonPMI = 'PT01-S2005-1'
}
else 
	if ( SeasonCode == 'W2004' ) {
		SeasonPMI = 'PT02-W2004-1'
	}
	else {
		SeasonPMI = 'PT01-S2004-3'
	}

function SetDropdown( aContents, sName ) {

var iSelectedIndex ='';
var sDispName = '';
var objDropdown=eval("document.searchForm." + sName );
var objsSelectedCode=''; 

	if ( sName == "destination" ) {
		objsSelectedCode = sSelecteddestinationCode;
		sDispName = 'Destination';
	}
	if ( sName == "resort" ) {
		objsSelectedCode = sSelectedresortCode;
		sDispName = 'Resort';
	}
	if ( sName == "hotel" ) {
		objsSelectedCode = sSelectedhotelCode;
		sDispName = 'Hotel';
	}

	objDropdown.options.length=2
	objDropdown.options[0]=new Option('Any ' + sDispName,'0',false,false);
	objDropdown.options[1]=new Option('- - - - - - - - - - - - -','0',false,false);
	for (i=0; i<( aContents.length ); i++) {
		if ( objsSelectedCode == aContents[i][0] )
				iSelectedIndex = i+2
		objDropdown.options[i+2]=new Option(aContents[i][1],aContents[i][0],false,false);
	}
	
	objDropdown.options.selectedIndex=iSelectedIndex;
	document.close();
}

function PopulateDestinationList() {

	if ( bFirstLoad )
		sSelecteddestinationCode = '';
	document.searchForm.destination.options[0]=new Option("Loading...","LO",false,false);
	document.searchForm.destination.options[1]=new Option("- - - - - - - - - - - - ");
	document.searchForm.destination.options.selectedIndex=0;
	parent.parent.SQLApplet.GetDestinationList(SeasonPMI);
}

function PopulateResortList() {

	if ( bFirstLoad )
		sSelectedresortCode = '';
	document.searchForm.resort.options[0]=new Option("Loading...","LO",false,false);
	document.searchForm.resort.options[1]=new Option("- - - - - - - - - - - - ");
	document.searchForm.resort.options.selectedIndex=0;
	if ( document.searchForm.destination[document.searchForm.destination.selectedIndex].value == 'LO' )
		parent.parent.SQLApplet2.GetResortList(SeasonPMI, sSelecteddestinationCode );
	else
		parent.parent.SQLApplet2.GetResortList(SeasonPMI, document.searchForm.destination[document.searchForm.destination.selectedIndex].value);
}

function PopulateHotelList() {

	if ( bFirstLoad )
		sSelectedhotelCode = '';
	document.searchForm.hotel.options[0]=new Option("Loading...","LO",false,false);
	document.searchForm.hotel.options[1]=new Option("- - - - - - - - - - - - ");
	document.searchForm.hotel.options.selectedIndex=0;
	if ( document.searchForm.resort[document.searchForm.resort.selectedIndex].value == 'LO' )
		parent.parent.SQLApplet3.GetHotelList(SeasonPMI, sSelectedresortCode );
	else
		parent.parent.SQLApplet3.GetHotelList(SeasonPMI, document.searchForm.resort[document.searchForm.resort.selectedIndex].value);
}

function PopulateHotelByMainResortList() {
	if ( bFirstLoad )
		sSelectedhotelCode = '';
	document.searchForm.hotel.options[0]=new Option("Loading...","LO",false,false);
	document.searchForm.hotel.options[1]=new Option("- - - - - - - - - - - - ");
	document.searchForm.hotel.options.selectedIndex=0;
	if ( document.searchForm.destination[document.searchForm.destination.selectedIndex].value == 'LO' )
		parent.parent.SQLApplet4.GetHotelByMainResortList(SeasonPMI, sSelecteddestinationCode );
	else
		parent.parent.SQLApplet4.GetHotelByMainResortList(SeasonPMI, document.searchForm.destination[document.searchForm.destination.selectedIndex].value);
}

function ShowCal() {

	var sURL='calendar.asp?M=' + document.searchForm.month[document.searchForm.month.selectedIndex].value;
	sURL += '&Y=' + document.searchForm.year.value;
	sURL += '&MN=' + document.searchForm.month[0].value;
	sURL += '&MX=' + document.searchForm.month[document.searchForm.month.options.length-1].value;
	sURL += '&MNY=' + document.searchForm.year.value;
	sURL += '&MXY=' + document.searchForm.year.value;
	wCalendar=window.open(sURL,'calender','width=500,height=300');
}

function changeSeason(sType, sPeriod, bValidDate) {
	
	if ( sType + sPeriod == 'S2005' ) {
		SeasonPMI = 'PT01-S2005-1'
	}
		else 
			if ( sType + sPeriod == 'W2004' ) {
				SeasonPMI = 'PT02-W2004-1'
		}
		else {
			SeasonPMI = 'PT01-S2004-3'
		}
	
	 document.imgSeasonPeriod.src="images/"+sPeriod+".gif";
	 document.imgSeasonType.src="images/"+sType+".gif";

	for (var i=0;i<=document.searchForm.year.length-1; i++) {
		if ( sPeriod == document.searchForm.year[i].value )
			document.searchForm.year.selectedIndex = i
	}

	//get MR data
	PopulateDestinationList();

	sSelectedresortCode = document.searchForm.resort[document.searchForm.resort.selectedIndex].value

	//get LR data	
	PopulateResortList();
	
	sSelectedhotelCode = document.searchForm.hotel[document.searchForm.hotel.selectedIndex].value

	// get Hotel data
	PopulateHotelList();
}

function ChangeDropdowns(MRCode, LRCode, ACCode) {
	

	if ( MRCode != document.searchForm.destination[document.searchForm.destination.selectedIndex].value ) {
	
		//get MR data	
		sSelecteddestinationCode = MRCode;
		PopulateDestinationList();
	}
	
	if ( LRCode != document.searchForm.resort[document.searchForm.resort.selectedIndex].value ) {
	
		//get LR data	
		sSelectedresortCode = LRCode;	
		PopulateResortList();
	}

	if ( ACCode != document.searchForm.hotel[document.searchForm.hotel.selectedIndex].value ) {
	
		// get Hotel data
		sSelectedhotelCode = ACCode;
		PopulateHotelList();
	}
}

function Flexibreaks(MR, LR, AC, HotelName, MonthIndex) {

	
	if (MonthIndex > "") {
		document.searchForm.month.selectedIndex = 3;
	}
	else {
		document.searchForm.month.selectedIndex = 9;
	}		
	
	ChangeDropdowns(MR, LR, AC);
	if (HotelName > "") {
		k = document.searchForm.hotel.options.length
		document.searchForm.hotel.options[k]=new Option(HotelName,AC,false,false);
		document.searchForm.hotel.selectedIndex = k;
		SetOtherCombos(true);
	}
	document.searchForm.FlexiBreak.value = true;
	localFB = true;
	// if we've set these up already, don't do it again as selection is lost.
	if ( document.searchForm.Duration.options.length < 10 ) {
		document.searchForm.Duration.options[2]=new Option("3 to 6","3",false,false);
		document.searchForm.Duration.options[3]=new Option("7","7",false,false);
		document.searchForm.Duration.options[4]=new Option("8 to 13","8",false,false);
		document.searchForm.Duration.options[5]=new Option("14","14",false,false);
		document.searchForm.Duration.options[6]=new Option("15 to 20","15",false,false);
		document.searchForm.Duration.options[7]=new Option("21","21",false,false);
		document.searchForm.Duration.options[8]=new Option("22 to 27","22",false,false);
		document.searchForm.Duration.options[9]=new Option("28","28",false,false);
		document.searchForm.Duration.options[0].selected=true;
	}
}
function ChangeDuration(){
	if (localFB == true || document.searchForm.FlexiBreak.value == true ) {
			// if we've set these up already, don't do it again as selection is lost.
			if ( document.searchForm.Duration.options.length < 10 ) {
				document.searchForm.Duration.options[2]=new Option("3 to 6","3",false,false);
				document.searchForm.Duration.options[3]=new Option("7","7",false,false);
				document.searchForm.Duration.options[4]=new Option("8 to 13","8",false,false);
				document.searchForm.Duration.options[5]=new Option("14","14",false,false);
				document.searchForm.Duration.options[6]=new Option("15 to 20","15",false,false);
				document.searchForm.Duration.options[7]=new Option("21","21",false,false);
				document.searchForm.Duration.options[8]=new Option("22 to 27","22",false,false);
				document.searchForm.Duration.options[9]=new Option("28","28",false,false);
				document.searchForm.Duration.options[0].selected=true;
			}
		}
	else
		{
			if ( document.searchForm.Duration.options.length < 5 ) {
			}
		}
}

function ChangeSearch() {
	var sType=document.searchForm.AVType.options[document.searchForm.AVType.selectedIndex].value;
	if (sType!="") {
		// change the page
		var sTemp=document.location.href;
		var sURL="";
		iAVPos=sTemp.indexOf("&AV");
		if (iAVPos==-1) {
			iAVPos=sTemp.length;
		}
		sURL=sTemp.substr(0,iAVPos);
		sURL+="&AV="+sType;
		sURL+sTemp.substr(iAVPos+6)
		sTemp="";
		
	}

	if (sType!="BR") {
		document.searchForm.resort.options.length=2;
		document.searchForm.resort.options[0].selected=true;
		document.searchForm.hotel.options.length=2;
		document.searchForm.hotel.options[0].selected=true;
		document.searchForm.board.options[0]=new Option("Any Board Type","",false,false);
		document.searchForm.board.options[1]=new Option("- - - - - - - - - - - - -","",false,false);
		document.searchForm.board.options[2]=new Option("Half board","HB",false,false);
		document.searchForm.board.options[3]=new Option("Full board","FB",false,false);
		document.searchForm.board.options[4]=new Option("Self Catering","SC",false,false);
		document.searchForm.board.options[5]=new Option("Bed & Breakfast","BB",false,false);
		document.searchForm.board.options[6]=new Option("All Inclusive","AI",false,false);
		document.searchForm.board.options[0].selected=true;		
	}
	else{
		MRChosen();
	}
	
	if(sType!=''){
		showHidePricebreakers();
	}	
}

function showHidePricebreakers(){


var sCode = document.searchForm.AVType.options[document.searchForm.AVType.selectedIndex].value;

	if(sCode==''){
		//nothing
	}
	else{
		if(sCode=='PB'){
			clearLR();
			clearHotel();
			MM_showHideLayers('divCalendarPopupObj4','','hide');
			MM_showHideLayers('divCalendarPopupObj4','','hide');
			MM_showHideLayers('divCalendarPopupObj5','','hide');
			MM_showHideLayers('divCalendarPopupObj5','','hide');
		}
		else{
			MM_showHideLayers('divCalendarPopupObj4','','show');
			MM_showHideLayers('divCalendarPopupObj4','','show');
			MM_showHideLayers('divCalendarPopupObj5','','show');
			MM_showHideLayers('divCalendarPopupObj5','','show');
		}
	}
}	//showHidePricebreakers

function SetOtherCombos(bResetPrice) {
	
	if (bResetPrice) document.searchForm.price.selectedIndex = 0;
	if (document.searchForm.hotel.selectedIndex>1)
	{
		document.searchForm.board.options.length=0;
		document.searchForm.board.options[0]=new Option("Board Type of Hotel","",false,false);
		document.searchForm.board.options[0].selected=true;
	}
	else
	{
		if (document.searchForm.board.selectedIndex>0){
		}
		else{
			document.searchForm.board.options.length=6;
			document.searchForm.board.options[0]=new Option("Any Board Type","",false,false);
			document.searchForm.board.options[1]=new Option("- - - - - - - - - - - - -","",false,false);
			document.searchForm.board.options[2]=new Option("Half board","HB",false,false);
			document.searchForm.board.options[3]=new Option("Full board","FB",false,false);
			document.searchForm.board.options[4]=new Option("Self Catering","SC",false,false);
			document.searchForm.board.options[5]=new Option("Bed & Breakfast","BB",false,false);
			document.searchForm.board.options[6]=new Option("All Inclusive","AI",false,false);
			document.searchForm.board.options[0].selected=true;
		}
	}
}

// 2 strings, used in the following 2 functions:
var sVal="";
var sText="";

// function to populate the sub resort and hotel combos
function MRChosen(LRCode) {
	// get the MR Code from the dropdown
	var x = document.searchForm.destination.selectedIndex;
	if (x>1)
	{
		PopulateResortList()
		document.searchForm.resort.options[0].selected=true;
		document.searchForm.hotel.options[0].selected=true;
		PopulateHotelByMainResortList()
		clearLR();
		//clearHotel();
		SetOtherCombos(false);
	}
	else {
		clearLR();
		clearHotel();
	}
}

// function to populate the hotel combo.
function LRChosen(ACCode) {
	var x = document.searchForm.resort.selectedIndex;
	if (x>1)
	{
		PopulateHotelList()
		SetOtherCombos(false);
	}
	else {
		PopulateHotelByMainResortList();
		SetOtherCombos(false);
	}
}


// check to see if the number of pax has invalidated anything.
function passengersChanged() {
	if (document.searchForm.passengers[document.searchForm.passengers.selectedIndex].value < 3 ||
	document.searchForm.passengers[document.searchForm.passengers.selectedIndex].value == "Any") {
		if (document.searchForm.freechild.checked == true) {
			document.searchForm.freechild.checked = false;
		}
	}
}

// check against the number of pax to see if the selection is valid.
function freechildChanged() {
	if (document.searchForm.freechild.checked == true) {
		// if price breakersor late deals, warn and uncheck
		if (document.searchForm.AVType.options[document.searchForm.AVType.selectedIndex].value!="BR") {
			alert('Unfortunately free children are not available \non Price Breakers and Late Deals');
			document.searchForm.freechild.checked = false;
		}
		else {
			// if the number of pax is less than 3, warn and uncheck
			if (document.searchForm.passengers[document.searchForm.passengers.selectedIndex].value < 3 ||
			document.searchForm.passengers[document.searchForm.passengers.selectedIndex].value == "Any") {
				alert('You must have a party size of 3 or more \nfor free children to become available');
				document.searchForm.freechild.checked = false;
			}
		}
	}
}



function showIt()
{
	var bOk = true;

	if ((parseInt(document.searchForm.year.value) == 2004 && 
		 (document.searchForm.month[document.searchForm.month.selectedIndex].value) < 5) ||
		(parseInt(document.searchForm.year.value) == 2004 && 
		 (document.searchForm.month[document.searchForm.month.selectedIndex].value) == 5 && 
		 (document.searchForm.day[document.searchForm.day.selectedIndex].value) < 8))
	{
		var strDays = 1 + " day";
		if (1 > 1) strDays += "s"

		if (bOk == true) alert("Departure dates must be at least " + strDays + " in the future.");
		bOk = false;
	}
		
	if (parseInt(document.searchForm.year.value) == 2005 && 
		 document.searchForm.month.selectedIndex+1 > 10)
	{
		if (bOk) alert("Unfortunately Winter 2005 " + 
			" holidays are not yet available to search \non the web. Departure dates must be before " + 
			" November 2005. " );
		bOk = false;
	}
	
	var SelectedDate = new Date(document.searchForm.year.value, document.searchForm.month[document.searchForm.month.selectedIndex].value-1, document.searchForm.day[document.searchForm.day.selectedIndex].value) 
	var LastLateDealDate = new Date('2004','6','30')
	if (document.searchForm.AVType.options[document.searchForm.AVType.selectedIndex].value == "LD")
	{
		if (SelectedDate > LastLateDealDate)
		{
			if (bOk) alert("Late Deals are only available for holidays departing in the next 12 weeks");
			bOk = false;
		}
	}
	if (document.searchForm.AVType.options[document.searchForm.AVType.selectedIndex].value == "PB")
	{
		//if (bOk) if ((document.imgSeasonType.src).indexOf("images/S.gif")>0 && (document.imgSeasonPeriod.src).indexOf("images/2004.gif")>0)
		//{
		//	alert ("Pricebreakers are currently not available for Summer 2004");		
		//	bOk = false;
		//}
		if (bOk) if ((document.imgSeasonType.src).indexOf("images/W.gif")>0 && (document.imgSeasonPeriod.src).indexOf("images/2004.gif")>0)
		{
			alert ("Pricebreakers are currently not available for Winter 2004");
			bOk = false;
		}
	}

	if (document.searchForm.Airport.selectedIndex == 0 || document.searchForm.Airport.selectedIndex == 1)
	{
		if (bOk) alert("Please select a departure airport.");
		bOk = false;
	}

	if (document.searchForm.passengers.selectedIndex == 0 || document.searchForm.passengers.selectedIndex == 1)
	{
		if (bOk == true) alert("Please select the number of passengers in your party.");
		bOk = false;
	}

	//don't let them go over to the prefs screen until the drop downs have loaded, else js error occurs.
	if ( document.searchForm.destination[document.searchForm.destination.selectedIndex].value == 'LO' ||
			document.searchForm.resort[document.searchForm.resort.selectedIndex].value == 'LO'  ||
				document.searchForm.hotel[document.searchForm.hotel.selectedIndex].value == 'LO' )
			bOk = false;

	if (bOk) 
	{
			document.location.href=BuildPrefsLink();
	}		
}

function clearHotel()
{
	// clear the accom unit field.
	document.searchForm.hotel.options.length=1;
	document.searchForm.hotel.options[1]=new Option("- - - - - - - - - - - - -","Any",false,false);
	document.searchForm.hotel.options[0].selected=true;
	SetOtherCombos(false);
}

function clearLR()
{
	// clear the accom unit field.
	document.searchForm.resort.options.length=1;
	document.searchForm.resort.options[1]=new Option("- - - - - - - - - - - - -","Any",false,false);
	document.searchForm.resort.options[0].selected=true;
}


function BuildPrefsLink() {
	var strDestinationText
	var strResortText
	var strHotelText
	var strDestinationItem
	var strHotelItem
	var strLOCN_CODE_PAR
	var strLOCN_CODE_PAR2
	var strLOCN_CODE_PAR3
	var iPrefCount = 0;
	var strDay = document.searchForm.day[document.searchForm.day.selectedIndex].value;
	var strMonth = document.searchForm.month[document.searchForm.month.selectedIndex].value;
	var strYear = document.searchForm.year.value;
	var strAirportCode;
	
	if (strMonth>4) document.searchForm.SeasonPeriod.value = strYear;
	else document.searchForm.SeasonPeriod.value = strYear-1;
	if (strMonth>4&&strMonth<11){
		document.searchForm.SeasonTypeCode.value = "S";
		document.searchForm.Brochure.value = "PSS";
	}
	else
	{
		document.searchForm.SeasonTypeCode.value = "W";
		document.searchForm.Brochure.value = "PWS";
	}	

	strDestinationItem = document.searchForm.destination.selectedIndex;
	strDestinationText = document.searchForm.destination.options[strDestinationItem].text;
	strDestinationText = escape(strDestinationText);

	strResortItem = document.searchForm.resort.selectedIndex;
	strResortText = document.searchForm.resort.options[strResortItem].text;
	strResortText = escape(strResortText);
										
	strHotelItem = document.searchForm.hotel.selectedIndex;
	strHotelText = document.searchForm.hotel.options[strHotelItem].text;
	strHotelText = escape(strHotelText);
								
	if ( document.searchForm.Airport[document.searchForm.Airport.selectedIndex].value == 'XXX' )
		strAirportCode = 'LGW';
	else
		strAirportCode = document.searchForm.Airport[document.searchForm.Airport.selectedIndex].value;
  					     
	strURL = 'AvailSearchPrefs.asp' +
	'?DD=' + strDay +
	'&MM=' + strMonth +
	'&YY=' + strYear +
	'&PX=' + document.searchForm.passengers[document.searchForm.passengers.selectedIndex].value +
	'&DU=' + document.searchForm.Duration[document.searchForm.Duration.selectedIndex].value +
	'&FT=' + document.searchForm.flight[document.searchForm.flight.selectedIndex].value +
	'&AP=' + strAirportCode +
	'&MC=' + document.searchForm.destination[document.searchForm.destination.selectedIndex].value +
	'&MR=' + strDestinationText +
	'&LC=' + document.searchForm.resort[document.searchForm.resort.selectedIndex].value +
	'&LR=' + strResortText +
	'&AC=' + document.searchForm.hotel[document.searchForm.hotel.selectedIndex].value +
	'&HN=' + strHotelText +
	'&PC=' + document.searchForm.price[document.searchForm.price.selectedIndex].value +
	'&BD=' + document.searchForm.board[document.searchForm.board.selectedIndex].value +
	'&TK=' + // Trating
	'&FC=' + document.searchForm.freechild.checked +
	'&NR=' + document.searchForm.rooms[document.searchForm.rooms.selectedIndex].value +
	'&PB=' + "1" +
	'&BC=' + document.searchForm.Brochure.value +
	'&SubProduct=' + document.searchForm.SubProduct.value +
	'&SI=' + document.searchForm.Site.value +
	'&ST=' + document.searchForm.SeasonTypeCode.value +
	'&SP=' + document.searchForm.SeasonPeriod.value +
	'&FB=' + document.searchForm.FlexiBreak.value +
	'&AV=' + document.searchForm.AVType.options[document.searchForm.AVType.selectedIndex].value;

	// 
	var strQafURL = "AvailSearch.asp" +
	"?DD=" + document.searchForm.day[document.searchForm.day.selectedIndex].value +
	"&MM=" + document.searchForm.month[document.searchForm.month.selectedIndex].value +
	"&YY=" + document.searchForm.year.value +
	"&PX=" + document.searchForm.passengers[document.searchForm.passengers.selectedIndex].value +
	"&DU=" + document.searchForm.Duration[document.searchForm.Duration.selectedIndex].value +
	"&FT=" + document.searchForm.flight[document.searchForm.flight.selectedIndex].value +
	"&AP=" + document.searchForm.Airport[document.searchForm.Airport.selectedIndex].value +
	"&MC=" + document.searchForm.destination[document.searchForm.destination.selectedIndex].value +
	"&LC=" + document.searchForm.resort[document.searchForm.resort.selectedIndex].value +
	"&AC=" + document.searchForm.hotel[document.searchForm.hotel.selectedIndex].value +
	"&PC=" + document.searchForm.price[document.searchForm.price.selectedIndex].value +
	"&BD=" + document.searchForm.board[document.searchForm.board.selectedIndex].value +
	"&TK=" + // Trating
	"&FC=" + document.searchForm.freechild.checked +
	"&NR=" + document.searchForm.rooms[document.searchForm.rooms.selectedIndex].value +
	"&PB=" + document.searchForm.price[document.searchForm.price.selectedIndex].value +
	"&BC=" + document.searchForm.Brochure.value +
	"&SC=" + document.searchForm.SubProduct.value +
	"&SI=" + document.searchForm.Site.value +
	"&ST=" + document.searchForm.SeasonTypeCode.value +
	"&SP=" + document.searchForm.SeasonPeriod.value +
	"&FB=" + document.searchForm.FlexiBreak.value +
	"&AV=" + document.searchForm.AVType[document.searchForm.AVType.selectedIndex].value +
	"&HN=" + strHotelText;
	
	parent.parent.variables.document.frmGeneric.QafURL.value = strQafURL;

	return strURL;
}

var defaultEmptyOK = false;
function isEmpty(s){ return ((s == null) || (s.length == 0)) }
function isDigit(c){ return ((c >= '0') && (c <= '9')) }
function isInteger(s){
	if (isEmpty(s))
		if (isInteger.arguments.length == 1) return defaultEmptyOK;
		else return (isInteger.arguments[1] == true);
	for (i = 0; i < s.length; i++){   
		var c = s.charAt(i);
		if (!isDigit(c)) return false; }
	return true; }

function isSignedInteger(s){
	if (isEmpty(s)) {
		if (isSignedInteger.arguments.length == 1) return defaultEmptyOK;
		else return (isSignedInteger.arguments[1] == true);
	}
	else {
		var startPos = 0;
		var secondArg = defaultEmptyOK;
		if (isSignedInteger.arguments.length > 1) secondArg = isSignedInteger.arguments[1];
		if ((s.charAt(0) == '-') || (s.charAt(0) == '+')) startPos = 1;    
	return (isInteger(s.substring(startPos, s.length), secondArg)) } }

function isNonnegativeInteger(s){
	var secondArg = defaultEmptyOK;
	if (isNonnegativeInteger.arguments.length > 1) secondArg = isNonnegativeInteger.arguments[1];
	return (isSignedInteger(s, secondArg) && ((isEmpty(s) && secondArg) || (parseInt (s) >= 0))); }

function isYear(s){
	if (!isNonnegativeInteger(s)) return false;
    return ((s.length == 2) || (s.length == 4)); }

function daysInFebruary(year){ 

return(((year % 4 == 0)&&((!(year % 100 == 0))||(year % 400 == 0)))?29:28); }

function daysInMonth(month,year){
	//No arrays to conform to Netscape 2.0
	
	if      (month == '01'||month == '1'||month == 'January'  ||month == 'Jan') return 31
	else if (month == '02'||month == '2'||month == 'February' ||month == 'Feb'){

		if (isYear('' + year + ''))                                         return daysInFebruary('' + year + '')
		else { var thisYear = new Date();                                   return daysInFebruary(thisYear.getYear()) } }
	else if (month == '03'||month == '3'||month == 'March'    ||month == 'Mar') return 31
	else if (month == '04'||month == '4'||month == 'April'    ||month == 'Apr') return 30
	else if (month == '05'||month == '5'                      ||month == 'May') return 31
	else if (month == '06'||month == '6'||month == 'June'     ||month == 'Jun') return 30
	else if (month == '07'||month == '7'||month == 'July'     ||month == 'Jul') return 31
	else if (month == '08'||month == '8'||month == 'August'   ||month == 'Aug') return 31
	else if (month == '09'||month == '9'||month == 'September'||month == 'Sep') return 30
	else if (month == '10'              ||month == 'October'  ||month == 'Oct') return 31
	else if (month == '11'              ||month == 'November' ||month == 'Nov') return 30
	else if (month == '12'              ||month == 'December' ||month == 'Dec') return 31
	else return false }

function getDayName(m,d,y,f){
	//No arrays to conform to Netscape 2.0
	var thisDate  = new Date(y, (m - 1), d);
	if (f == 'd') return thisDate.getDate();
	else {
		if (thisDate.getDate() < 10) return '0' + thisDate.getDate();
		else                         return thisDate.getDate(); } }

function DayConstructor(d,l,a,v,t,m,y){  
	for (i = d.length - a; i < l; i++){
		var VoptionValue = getDayName(m, i, y, v) + 1;
		var ToptionValue = getDayName(m, i, y, t) + 1;
		var newOpt = new Option (ToptionValue, VoptionValue);
		d.options[d.length] = newOpt; } }

function DayDestructor(d,l,a){
	if (!(d.options.selectedIndex <= l + a)) d.options.selectedIndex = l + a;
	//Older browsers may need refreshed to reflect the deletion.
	//To edit this script, copy and insert it into your .cfm page and set the following variable: js_script_Done = true
	for (i = d.length - a; i > l; i--){  d.options[i + a] = null; } }

var sSeasonType = 'S';
var sSeasonPeriod = 2004;

function SetDays(m,y,d,a,v,t){
	if (daysInMonth(m,y)){
		if      ((d.length - a) > daysInMonth(m, y) - 1) DayDestructor (d, daysInMonth(m,y) - 1, a)
		else if ((d.length - a) < daysInMonth(m, y))     DayConstructor(d, daysInMonth(m,y),     a, v, t, m, y); } 
	var sOldSeasonType;
	var sOldSeasonPeriod;
	sOldSeasonType = sSeasonType;
	sOldSeasonPeriod = sSeasonPeriod;

	if (m != 10) ChangeDuration();

	var sDay = d.options[d.options.selectedIndex].value;
	if (m > 4)
	{
		if (m < 10) sSeasonType = "S";
		else
		{
			if (m==10 && sDay>31) sSeasonType = "W";
			else
			{
				if (m > 10)  sSeasonType = "W";
				else sSeasonType = "S";
			}
		}
	}
	else
	{
		if (m==4 && sDay>30) sSeasonType = "S";
		else sSeasonType = "W";
	}	
	sSeasonPeriod = y;
	
	
    
	if (m < 5 && sSeasonType == "W") sSeasonPeriod--
	
	if (sOldSeasonType != sSeasonType || sOldSeasonPeriod != sSeasonPeriod)
		changeSeason(sSeasonType, sSeasonPeriod, true);
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

