DQM_cancel_onload = true;
var flag = 0;
var today = new Date();
var day   = today.getDate();
var month = today.getMonth();
var month1= month;
var year  = today.getFullYear();
var text_field1 = "";
var text_field2 = "";
var text_field3 = "";
var defaultDates = "";
var departDay = "";
var returnDay = "";
var departMonth = "";
var returnMonth = "";
var departTime = "";
var returnTime = "";

function getParams() {
	var idx = document.URL.indexOf('?');
	var params = new Array();
	if (idx != -1) {
		var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
		for (var i=0; i<pairs.length; i++) {
			nameVal = pairs[i].split('=');
			params[nameVal[0]] = nameVal[1];
		}
      if (params["adinfonitumCode"]) {
         return "false";
      }
      else {
   		return params;
      }
	}
	else{ 
		return "false";
	}
}


function padout(number) { return (number < 10) ? '0' + number : number; }
function restart() {
	text_field1.selectedIndex = day-1;
	text_field2.selectedIndex = month - month1 + (12 * (month < month1));
	if (text_field3 != null)
		text_field3.selectedIndex = text_field2.selectedIndex;
	mywindow.close();
}
 
function changeReturn() {
	if (flag == 0){
		document.orbot.returnMonth.selectedIndex = document.orbot.departMonth.selectedIndex;
		flag = 1;
	}
}
 
function moreOptions() {
	document.orbot.moreOptions.value=true;
	document.orbot.multiflight.value=false;
	document.orbot.submit();
}
 
function multiFlight() {
        document.orbot.typeRoundTrip.value="multicity";
        document.orbot.multiflight.value=true;
        document.orbot.moreOptions.value=true;
        document.orbot.submit();
}


function lessOptions() {
	document.orbot.moreOptions.value=false;
	document.orbot.multiflight.value=false;
	document.orbot.submit();
}
 
function newWindow(fieldname1,fieldname2,fieldname3,evnt) {
	c_today = new Date();
	day = c_today.getDate();
	month = c_today.getMonth();
	year = c_today.getFullYear();
	text_field1 = fieldname1;
	text_field2 = fieldname2;
	text_field3 = fieldname3;
	var properties = "left=" + (evnt.screenX + 20);
	properties += ",top=" + (evnt.screenY + 1);
	properties += ",titlebar=0,resizable=no,width=205,height=195";
	mywindow=open('/cal.html','myname',properties);
	mywindow.location.href = '/cal.html';
	if (mywindow.opener == null) mywindow.opener = self;
	mywindow.focus();
}
 
function futureDate(daysOut){
   var today = new Date();
   var todayInMS = today.getTime(); // today in MilliSeconds
   var nextDate = todayInMS + (60 * 60 * 24 * daysOut * 1000);
   return new Date(nextDate);
}

function dropMonths(dropType, dateObj){
   months = new Array();
   monthsNumerical = new Array();
   monthsNumerical.push("1","2","3","4","5","6","7","8","9","10","11","12");
   months.push("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
   var today = new Date();
   var nextYear = today.getFullYear() + 1;
   if (dropType == "depart") output = '<font style="font-family: Arial, Helvetica, sans-serif;font-size:   12px;color:       #333333;"> Depart</font><br> <select NAME="departMonth" onChange="changeReturn();">';
   else output = '<font style="font-family: Arial, Helvetica, sans-serif;font-size:   12px;color:       #333333;">Return</font><br><select NAME="returnMonth">';
 	for (var i=today.getMonth() ; i<12; i++) {
      if ((i == dateObj.getMonth()) && (today.getFullYear() == dateObj.getFullYear())) {
			output += '<option value="'+monthsNumerical[i]+'" selected>'+ months[i] + '<\/option>';
		}
      else {
			output += '<option value="' + monthsNumerical[i] + '">' + months[i] + '<\/option>';
		}
   }
   // Modify drop boxes to account for next year
   for (var i=0; i<today.getMonth(); i++) {
      if ((i == dateObj.getMonth()) && (today.getFullYear() != dateObj.getFullYear())) {
			output += '<option value="'+months[i] + ' ' + nextYear + '" selected>'+ months[i] + ' ' + nextYear + '<\/option>';
		}
		else{
			output += '<option value="' + months[i] + ' ' + nextYear + '">' + months[i] + ' ' + nextYear +'<\/option>';
		}
   }
   output += '</select>';
   return output;
}

function dropDays(dropType, dateObj){
   if (dropType == "depart") output = '<select NAME="departDay">';
   else output = '<select NAME="returnDay">';
   for (var i=1; i<32; i++) {
      if (i == dateObj.getDate()) output += '<option value="' + i + '" selected>' + i + '<\/option>';
      else output += '<option value="' + i + '">' + i + '<\/option>';
   }
   output += '</select>';
   return output;
}

function setDefaultDates(){
	// we have Default Date we need to dispaly for this promo.
		document.orbot.departMonth.value	= departMonth;
		document.orbot.departDay.value 	= departDay;
		document.orbot.returnDay.value	= returnDay;
		document.orbot.returnMonth.value	= returnMonth;
		//document.orbot.returnMonth.value	= months[returnMonth;]
	}
function setPassedInVals(){
		
	//param list was passed in to this page, so override the defaults
	if ( params != "false" ){
		var t_origin 		= unescape(params["origin"]);
		var t_destination	= unescape(params["destination"]);
		var t_searchType 	= unescape(params["searchType"]);
		var t_departDay	= unescape(params["departDay"]);
		var t_returnMonth	= unescape(params["returnMonth"]);
		var t_departMonth	= unescape(params["departMonth"]);
		var t_returnDay	= unescape(params["returnDay"]);
		var t_departTime	= unescape(params["departTime"]);
		var t_returnTime	= unescape(params["returnTime"]);
		var t_searchMethod= unescape(params["searchMethod"]);
		var t_adults 		= unescape(params["adults"]);
	
  	 	if (t_origin == "undefined"){ origin = ""; }
		else{ document.orbot.origin.value = t_origin; }
	
		if (t_destination == "undefined"){ destination = ""; }
		else{ document.orbot.destination.value = t_destination; }


		if (t_departMonth == "undefined"){ document.orbot.departMonth.value = departMonth; }
		else{ document.orbot.departMonth.value = t_departMonth; }

		if (t_departDay == "undefined"){ document.orbot.departDay.value = departDay; }
		else{ document.orbot.departDay.value = t_departDay; }

		if (t_returnMonth == "undefined"){ document.orbot.returnMonth.value = returnMonth; }
		else{ document.orbot.returnMonth.value = t_returnMonth; }

		if (t_returnDay == "undefined"){ document.orbot.returnDay.value = returnDay; }
	 	else{ document.orbot.returnDay.value = t_returnDay; }

		if (t_departTime == "undefined"){ document.orbot.departTime.value = departTime; }
	 	else{ document.orbot.departTime.value = t_departTime; }

		if (t_returnTime == "undefined"){ document.orbot.returnTime.value = returnTime; }
	 	else{ document.orbot.returnTime.value = t_returnTime; }

		if (t_searchType == "oneway"){ document.orbot.searchType.value = "oneway"; }
	 	else{ document.orbot.searchType.value = "roundtrip"; }

		//if ( t_searchMethod == "scheduleSearch"){ document.orbot.searchMethod[1].checked = true; }
	 	//else if ( t_searchMethod == "awardTravelSearch"){ document.orbot.searchMethod[0].checked = true; }
	 	//else{ document.orbot.searchMethod[0].checked = true; }

		if (t_searchType == "undefined"){ searchType = "roundtrip"; }
		}//if passed in params
	else {
		predefinedDates();
	}

}
function predefinedDates(){
 document.orbot.departTime.value = departTime;

}


