
function quickQuote(formName) {
	this.formName = formName;
	this.childrenFieldName = "children";
    // WARNING!. DEPENDANCY ON GLOBALS FROM CALLER
	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");
		}
	}
};

quickQuote.prototype.showWarning = function( timeoutSeconds )
{
    try {
        // hide selects
        var form = document.forms["quickQuote"];
        form.className = (form.className||"").replace(/ *hideselect */gi," ") + " hideselect";
        form = null;

        // bind listeners
        var nodeWarn = document.getElementById( "qqWarning" );//"qqWarningClose");
        if ( nodeWarn.addEventListener ) {
            nodeWarn.addEventListener("click",quickQuote.closeWarning,false);
            nodeWarn.addEventListener("keydown",quickQuote.closeWarning,false);
        } else if ( nodeWarn.attachEvent ) {
            nodeWarn.attachEvent("onclick",quickQuote.closeWarning);
            nodeWarn.attachEvent("onkeydown",quickQuote.closeWarning);
        }
        nodeWarn = null;

        // set autoclose (10sec)
        if ( quickQuote.timer ) {
            window.clearTimeout(quickQuote.timer);
            quickQuote.timer = null;
        }
        if ( !isNaN(timeoutSeconds) ) {
            quickQuote.timer = window.setTimeout( quickQuote.closeWarning, timeoutSeconds*1000);
        }

        // show it
        document.getElementById( "qqWarning" ).style.display = 'block';

        // set focus
        setTimeout(function()
        {
            try { document.getElementById( 'qqWarningClose' ).focus(); }
            catch(e) { alert("qqWarningClose.focus catch : " + e.message); e = null; }
        },1);

    } catch(e) {
        alert("quickQuote.showWarning catch : " + e.message);
        e = null;
    }
};

quickQuote.closeWarning = function()
{
    try {
        // cancel autoclose
        if ( quickQuote.timer ) {
            window.clearTimeout(quickQuote.timer);
            quickQuote.timer = null;
        }

        // hide warning
        document.getElementById( "qqWarning" ).style.display = 'none';

        // show selects
        var form = document.forms["quickQuote"];
        form.className = (form.className||"").replace(/ *hideselect */gi," ");
        form = null;

        // unbind listeners
        var nodeWarn = document.getElementById( "qqWarning" );//"qqWarningClose");
        if ( nodeWarn.removeEventListener ) {
            nodeWarn.removeEventListener("click",quickQuote.closeWarning,false);
            nodeWarn.removeEventListener("keydown",quickQuote.closeWarning,false);
        } else if ( nodeWarn.detachEvent ) {
            nodeWarn.detachEvent("onclick",quickQuote.closeWarning);
            nodeWarn.detachEvent("onkeydown",quickQuote.closeWarning);
        }

    } catch(e) {
        alert("quickQuote.closeWarning catch : " + e.message);
        e = null;
    }
};

// this was quickly borrowed from WDPRO 2.0
// is not intended to be long term solution (using syndicated qq is)
quickQuote.prototype.displaySubmitError = function( strMessage ) {
    
    this.displayMessage( strMessage, "Warning", "Ok" );
    return false;
};

quickQuote.prototype.displayMessage = function( strMessage, strTitle, strClose, bHideInnerBox )
{
    var nodeQQ   = document.getElementById( "qqContainer" );
    var nodeWarn = document.getElementById( "qqWarning" );
    var nodeBg, nodeContainer, nodeBox, nodeText;

    if ( !nodeWarn ) {
        nodeWarn = document.createElement( 'div' );
        nodeWarn.id = 'qqWarning';
        nodeWarn.style.display = 'block';

        nodeBg = nodeWarn.appendChild( document.createElement( 'div' ) );
        nodeBg.className = 'qqWarningBackground';
        nodeBg.id = 'qqWarningBackground';
        nodeBg = undefined;

        nodeContainer = nodeWarn.appendChild( document.createElement( 'div' ) );
        nodeContainer.className = 'qqWarningContainer';
        nodeContainer.id = 'qqWarningContainer';

        nodeBox = nodeContainer.appendChild( document.createElement( 'div' ) );
        nodeBox.className = 'qqWarningBox';
        nodeContainer = undefined;

        nodeText = nodeBox.appendChild( document.createElement( 'div' ) );
        nodeText.id = 'qqWarningTitle';
        nodeText.innerHTML = '&nbsp;';
        nodeText = undefined;

        nodeText = nodeBox.appendChild( document.createElement( 'div' ) );
        nodeText.id = 'qqWarningMessage';
        nodeText.innerHTML = '&nbsp;';
        nodeText = undefined;

        nodeText = nodeBox.appendChild( document.createElement( 'div' ) );
        nodeText.id = 'qqWarningClose';
        nodeText.innerHTML = 'Close';

        nodeText = undefined;
        nodeBox = undefined;
        nodeQQ.appendChild( nodeWarn );
    }

    document.getElementById( 'qqWarningContainer' ).style.visibility = bHideInnerBox ? 'hidden' : 'visible';
    document.getElementById( 'qqWarningTitle' ).innerHTML   = strTitle;
    document.getElementById( 'qqWarningMessage' ).innerHTML = strMessage;
    document.getElementById( 'qqWarningClose' ).innerHTML   = strClose;

    this.showWarning(5);

    nodeWarn = document.getElementById("qqWarning");
    nodeWarn.style.height = nodeQQ.offsetHeight + 'px';
    nodeContainer = document.getElementById("qqWarningContainer");
    nodeContainer.style.top = ( Math.floor(nodeWarn.offsetHeight/2) - Math.floor(nodeContainer.offsetHeight/2))+'px';
    nodeContainer.style.left = ( Math.floor(nodeWarn.offsetWidth/2) - Math.floor(nodeContainer.offsetWidth/2))+'px';
    nodeBg = document.getElementById("qqWarningBackground");
    nodeBg.style.height = nodeQQ.offsetHeight + 'px';
    nodeBg.style.width  = nodeQQ.offsetWidth  + 'px';

    nodeBg = nodeContainer = nodeBox = nodeText = nodeWarn = nodeQQ = null;

};