
function quickQuote(formName) {
	this.formName = formName;
	this.childrenFieldName = "children";
	this.childFieldName = childFieldName;
	this.childDivId = childDivId;
	this.arrivalMonth = arrivalMonth;
	this.arrivalDay = arrivalDay;
	this.arrivalYear = arrivalYear;
	this.departureMonth = departureMonth;
	this.departureDay = departureDay;
	this.departureYear = departureYear;
	this.minLengthOfStay = minLengthOfStay;
	this.maxLengthOfStay = maxLengthOfStay;
}

quickQuote.prototype.getElements = function (itemId)  {
	if (document.layers && document.layers[itemName] != null) {
	    objValue = document.layers[itemId];
	}
	else if (document.all) {
	    objValue = document.all[itemId];
	}
	else if (document.getElementById) {
	    objValue = document.getElementById([itemId]);
	}
	return objValue;
}

quickQuote.prototype.countItems = function(item) {
	count = 0;
	for (i=1; i<20; i++) {
		if (this.getElements(item + i)) {
			count = count + 1
		}
	}
	return count;
}

quickQuote.prototype.displayOff = function (id) {
	objValue = this.getElements(id);
	objValue.style.display = "none";
}

quickQuote.prototype.displayOn = function (id) {
	objValue = this.getElements(id);
	objValue.style.display = "inline";
}

quickQuote.prototype.moveTo = function (id, x, y) {
	objValue = this.getElements(id);
	alert(id);
	if (DOMtype == 'isDOM') {
		objValue.style.left = x;
		objValue.style.top = y;
	} else if (DOMtype == 'isIE') {
		objValue.style.pixelLeft = x;
		objValue.style.pixelTop = y;
	}
}

quickQuote.prototype.displayChildren = function (value) {
	intValue = parseInt(value);
	childInt = this.countItems(this.childFieldName);
	this.displayOff("quickQuoteChildAges");
	for ( i=0; i<childInt; i++ ) {
		document.forms[this.formName].elements[this.childFieldName + (i+1)].value = "";
	}
	if ( intValue > 0) {
		this.displayOn("quickQuoteChildAges");
		for ( i=0; i<childInt; i++ ) {
			if (i < intValue) {
				this.displayOn(this.childDivId + (i+1));
				this.displayOn(this.childFieldName + (i+1));
			} else {
				this.displayOff(this.childDivId + (i+1));
				this.displayOff(this.childFieldName + (i+1));
			}
		}
	}
}

quickQuote.prototype.checkDate = function (whichLeg, completeDate) {
	formObj = document.forms[this.formName];
	reqMonth = completeDate.getMonth()+1;
	reqDate = completeDate.getDate();
	reqYear = completeDate.getYear();
	Date.isLeapYear = function(year){ if (year%4==0 && ((year%100!=0) || (year%400==0))) return true; else return false; }
	daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	if (whichLeg == 1) {
		// set this leg as arrival, and set the other as departure
		otherLeg = 0;
		var thisMonth = formObj.elements[this.arrivalMonth];
		var thisDate = formObj.elements[this.arrivalDay];
		var thisYear = formObj.elements[this.arrivalYear];
		var aMonth = thisMonth;
		var aDate = thisDate;
		var aYear = thisYear;
		var dMonth = formObj.elements[this.departureMonth];
		var dDate = formObj.elements[this.departureDay];
		var dYear = formObj.elements[this.departureYear];
	} else {
		// set this leg as departure, and set the other as arrival
		otherLeg = 1;
		var thisMonth = formObj.elements[this.departureMonth];
		var thisDate = formObj.elements[this.departureDay];
		var thisYear = formObj.elements[this.departureYear];
		var dMonth = thisMonth;
		var dDate = thisDate;
		var dYear = thisYear;
		var aMonth = formObj.elements[this.arrivalMonth];
		var aDate = formObj.elements[this.arrivalDay];
		var aYear = formObj.elements[this.arrivalYear];
	}
	dateArrival = new Date(aYear.value, aMonth.value, aDate.value);
	dateDeparture = new Date(dYear.value, dMonth.value, dDate.value);
	daysDifferent = (dateDeparture - dateArrival)/(1000*60*60*24);
	
	//alert("Your arrival date is: " + aMonth.value + "-" + aDate.value + "-" + aYear.value + " and your departure date is: " + dMonth.value + "-" + dDate.value + "-" + dYear.value);
	
	// check and make sure that the user has at least the required date
	if (thisYear.value <= reqYear) {
		thisYear.value = reqYear;
		if (thisMonth.value <= parseInt(reqMonth)) {
			thisMonth.value = reqMonth;
			if (thisDate.value < reqDate) {
				thisDate.value = reqDate;
				updateCal(otherLeg);
			}
		}
	}
	
	// check and make sure that the user a greater departure date than arrival, and if not, adjust the dates
	depDate = null;
	if (daysDifferent < this.minLengthOfStay) {
		depDate = new Date(aYear.value, aMonth.value - 1, parseInt(aDate.value) + this.minLengthOfStay);
	}
	if (daysDifferent > this.maxLengthOfStay) {
		depDate = new Date(aYear.value, aMonth.value - 1, parseInt(aDate.value) + this.maxLengthOfStay);
	}
	if (depDate) {
		newDepYear = depDate.getYear();
		if (newDepYear > reqYear+1) {
			dYear.options.length = 0;
			yearLength = newDepYear-reqYear;
			for (i=0; i<yearLength+1; i++) {
				dYear.options[i] = new Option(reqYear+i,reqYear+i);
				if (reqYear+i == newDepYear) {
					dYear.options[i].selected = true;
				}
			}
		}
		dYear.value = newDepYear;
		dMonth.value = parseInt(depDate.getMonth()) + 1;
		dDate.value = depDate.getDate();
	}
	
	// reformat the form based on the month, and total days in that month
	if (Date.isLeapYear(thisYear.value)) {
		daysInMonth[1] = 29;
	}

	selectedMonth = thisMonth.selectedIndex;
	selectedDate = thisDate.selectedIndex;
	thisDate.options.length = 0;
		
	for ( i=1; i<daysInMonth[selectedMonth]+1; i++ ) {
		myDay = i;
		if (myDay < 10) {
			myDay = "0" + i;
		}
		thisDate.options[i-1] = new Option(myDay,i);
		if (i-1 == selectedDate) {
			thisDate.options[i-1].selected = true;
		}
	}
}

quickQuote.prototype.toggleSelect = function (thisValue, elementName, idToToggle, desiredValue) {
	document.forms[this.formName].elements[elementName].selectedIndex = 0;
	if (thisValue == desiredValue) {
		this.displayOn(idToToggle);
	} else {
		this.displayOff(idToToggle);
	}
}
quickQuote.prototype.toggleTickets = function (thisValue) {
	if (thisValue == "tickets") {
		this.displayOn("quickQuoteChildren10Up");
		this.displayOn("quickQuoteChildren3To9");
		this.displayOn("quickQuoteCountry");
		this.displayOn("numOfDays");
		this.displayOff("quickQuoteDates");
		this.displayOff("quickQuoteAdults");
		this.displayOff("quickQuoteChildAges");
	} else {
		this.displayOff("quickQuoteChildren10Up");
		this.displayOff("quickQuoteChildren3To9");
		this.displayOff("quickQuoteCountry");
		this.displayOff("quickQuoteState");
		this.displayOff("numOfDays");
		this.displayOn("quickQuoteDates");
		this.displayOn("quickQuoteAdults");
		if (document.forms[this.formName].elements[this.childrenFieldName].selectedIndex >= 1) {
			this.displayOn("quickQuoteChildAges");
		}
	}
}