
function currencyWindow(popurl)
	{
	currWindow = window.open(popurl, 'CurrencyConverter', 'width=460,height=380');
	currWindow.focus;
	}

function changeForm(id)
{ 
	var f; 
	f=document.search;
	//alert(id);
	turn_off_all_boxes();
	 if(id == 3)
	 {
		lastmindealsbox.style.display='block';
		clickstay('id5');

	 }
	 else if(id == 4)
	 {
		 carbox.style.display='block';
		 clickstay('id4');
		 //alert(document.hotsrchbox.dod_dd.selectedIndex);
		 if(hotsrchbox){
			 document.CarSearch.pudate_mo.options.selectedIndex = document.hotsrchbox.doa_mm.options.selectedIndex;
			 document.CarSearch.pudate_dy.options.selectedIndex = document.hotsrchbox.doa_dd.options.selectedIndex;
			 document.CarSearch.dodate_mo.options.selectedIndex = document.hotsrchbox.dod_mm.options.selectedIndex;
			 document.CarSearch.dodate_dy.options.selectedIndex = document.hotsrchbox.dod_dd.options.selectedIndex;
		 }
	 }
	 else if(id == 6)
	 {
		 hotelairbox.style.display='block';
		 clickstay('id3');
	 }
	 else 
	 {
		hotelbox.style.display='block';
		clickstay('id1');
	 }
}

function turn_off_all_boxes(){
	if(hotelbox){
		hotelbox.style.display='none';
	}
	if(lastmindealsbox){
		lastmindealsbox.style.display='none';
	}
	if(carbox){
		carbox.style.display='none';
	}
	if(hotelairbox){
		hotelairbox.style.display='none';
	}
}

function IsLeapYear(yrStr)
{
 var leapYear = false;
 var year = parseInt(yrStr, 10);
 if (year%4 == 0) 
  { 
	leapYear = true;
	if (year%100 == 0)
	 {
	  leapYear = false;
	  if (year%400 == 0)
	   {
	    leapYear = true;
		}
	  }
   }
  return leapYear;
 }


function getDaysInMonth(mthIdx, yrStr) 
{
 var maxDays = 31;
 if (mthIdx == 1)
	{
	 if (IsLeapYear(yrStr))
	   { 
	    maxDays = 29;
	   }
	 else
		{
		  maxDays = 28;
		}
     }
 if (mthIdx == 3 || mthIdx == 5 || mthIdx == 8 || mthIdx == 10)
	{
	 maxDays = 30;
	 }
 return maxDays;
}

function adjustDate(mthIdx, Dt, initDate)
{
var value = 0;

var today = new Date();
var theYear = parseInt(today.getYear(),10);

if (mthIdx < today.getMonth()) {
	theYear = (parseInt(today.getYear(),10) + 1);
}

if (theYear < 100) {
	theYear = "19" + theYear;
	}
else {
	if ((theYear - 100) < 10) {
		theYear = "0" + (theYear - 100);
		}
	else 
		{
		theYear = (theYear - 100) + "";
		}
	theYear = "20" + theYear
}

var numDays = getDaysInMonth(mthIdx, theYear);

 
// checks whether to initialize date or not.
if (initDate == 1) 
	{
	  if ((numDays - Dt)==7)
		{

		//checks if month is December
		if (mthIdx==11) {
			document.hotsrchbox.doa_mm.options.selectedIndex = mthIdx;
			document.hotsrchbox.dod_mm.options.selectedIndex = 0;
			document.hotsrchbox.dod_yy.options.selectedIndex =+1;

			document.CarSearch.pudate_mo.options.selectedIndex = mthIdx;
			document.CarSearch.dodate_mo.options.selectedIndex = 0;
		} else {
			document.hotsrchbox.doa_mm.options.selectedIndex = mthIdx;
			document.hotsrchbox.dod_mm.options.selectedIndex = mthIdx+1;

			document.CarSearch.pudate_mo.options.selectedIndex = mthIdx;
			document.CarSearch.dodate_mo.options.selectedIndex = mthIdx+1;
		}

		//hotel search box
	    document.hotsrchbox.doa_dd.options.selectedIndex = numDays - 1;
	    document.hotsrchbox.dod_dd.options.selectedIndex =  7 - (numDays - Dt);

		//car search box
		document.CarSearch.pudate_dy.options.selectedIndex = numDays - 1;
		document.CarSearch.dodate_dy.options.selectedIndex = 7 - (numDays - Dt);

		}
		else if ((numDays-Dt)<7)
				{

				if (mthIdx==11) {
					document.hotsrchbox.doa_mm.options.selectedIndex = 0;
					document.hotsrchbox.dod_mm.options.selectedIndex = 
					document.hotsrchbox.doa_mm.options.selectedIndex;
					document.hotsrchbox.doa_yy.options.selectedIndex =+1;
					document.hotsrchbox.dod_yy.options.selectedIndex =+1;

					document.CarSearch.pudate_mo.options.selectedIndex = 0;
					document.CarSearch.dodate_mo.options.selectedIndex = 
					document.CarSearch.pudate_mo.options.selectedIndex;
				} else {
					document.hotsrchbox.doa_mm.options.selectedIndex = mthIdx + 1;
					document.hotsrchbox.dod_mm.options.selectedIndex = document.hotsrchbox.doa_mm.options.selectedIndex;	

					document.CarSearch.pudate_mo.options.selectedIndex = mthIdx + 1;
					document.CarSearch.dodate_mo.options.selectedIndex = document.CarSearch.pudate_mo.options.selectedIndex;
				}					

				//hotel search box
				document.hotsrchbox.doa_dd.options.selectedIndex = 6 - (numDays - Dt);
				document.hotsrchbox.dod_dd.options.selectedIndex = 7 - (numDays - Dt);	

				//car search box
				document.CarSearch.pudate_dy.options.selectedIndex = 6 - (numDays - Dt);
				document.CarSearch.dodate_dy.options.selectedIndex = 7 - (numDays - Dt);

				}
		else
			{ 
			//hotel search box
			document.hotsrchbox.doa_mm.options.selectedIndex = mthIdx;
			document.hotsrchbox.doa_dd.options.selectedIndex = (Dt - 1) + 7;
			document.hotsrchbox.dod_mm.options.selectedIndex = document.hotsrchbox.doa_mm.options.selectedIndex;
			document.hotsrchbox.dod_dd.options.selectedIndex = (Dt - 1) + 8;

			//car search box
			document.CarSearch.pudate_mo.options.selectedIndex = mthIdx;
			document.CarSearch.pudate_dy.options.selectedIndex = (Dt - 1) + 7;
			document.CarSearch.dodate_mo.options.selectedIndex = document.CarSearch.pudate_mo.options.selectedIndex;
			document.CarSearch.dodate_dy.options.selectedIndex = (Dt - 1) + 8;
			}
		}
else
	{		
	if (mthIdx == 1)
		{
		if (Dt.options.selectedIndex + 1 < numDays) 
			{
			return 0;
			}
		else
			{
			Dt.options.selectedIndex=numDays - 1;
			if (numDays == 29)
				{
				return 99;
				}
			else
				{
				return 1;
				}
			}
		}
	 if (Dt.options.selectedIndex + 1 < numDays)
		{
		value = 0;
		}
	 else
		{
		if (Dt.options.selectedIndex + 1 > numDays)
			{
			Dt.options.selectedIndex--;
			value = 3;
			}
		else
			{
			value = 2;
			}
		}
	 return value;
	}
}


function amadChange(inM, inD, outM, outD)
{
 var res = adjustDate(inM.options.selectedIndex, inD, 0);
 if (res != 0 )
	{
		outD.options.selectedIndex = 0;
		if (outM.options.selectedIndex == 11) {
			outM.options.selectedIndex = 0;
			}
		else {
			outM.options.selectedIndex = inM.options.selectedIndex + 1;
			}
		}
 else
	{
	outM.options.selectedIndex = inM.options.selectedIndex;
	outD.options.selectedIndex = inD.options.selectedIndex + 1;
	}
return;
}

function initDate()
{
	var today = new Date();
	var currMth = today.getMonth();
	var currDate = today.getDate();

	var mth = document.hotsrchbox.doa_dd.options.selectedIndex = currMth;
	var Dt = document.hotsrchbox.doa_dd.options.selectedIndex = currDate;
	adjustDate(mth, Dt, 1);
}
	
function waitBox()
{
  var popup = window.open('http://www.res99.com/wait.html','wait','height=125 ,width=330,left=330,top=330');
}

function showCal(url)
	{
	calWindow = window.open(url, 'Calendar', 'scrollbars=YES, width=550,height=225');
	calWindow.focus;
	}

function disclaimerWin(tnc)
	{
	tncWindow = window.open(tnc, 'TermsAndConditions', 'width=325,height=500');
	tncWindow.focus;
	}

function airportCodes(url)
	{
	arptWindow = window.open(url, 'AirportCodes', 'width=450,height=350');
	arptWindow.focus;
	}

var anyopen = "id1";
function clickstay(tdid) {
	document.all[anyopen].className = "tabOff";
	document.all[tdid].className = "tabOn";
	anyopen=tdid;
	}

function add_options_to_month_select(){
	document.write('<option value="01" >January');
	document.write('<option value="02" >February');
	document.write('<option value="03" >March');
	document.write('<option value="04" >April');
	document.write('<option value="05" >May');
	document.write('<option value="06" >June');
	document.write('<option value="07" >July');
	document.write('<option value="08" >August');
	document.write('<option value="09" >September');
	document.write('<option value="10" >October');
	document.write('<option value="11" >November');
	document.write('<option value="12" >December');
}

function add_options_to_car_time() {
	document.write('<option value="12A">12:00am</option>');
	document.write('<option value="1A">1:00am</option>');
	document.write('<option value="2A">2:00am</option>');
	document.write('<option value="3A">3:00am</option>');
	document.write('<option value="4A">4:00am</option>');
	document.write('<option value="5A">5:00am</option>');
	document.write('<option value="6A">6:00am</option>');
	document.write('<option value="7A">7:00am</option>');
	document.write('<option value="8A">8:00am</option>');
	document.write('<option value="9A">9:00am</option>');
	document.write('<option value="10A">10:00am</option>');
	document.write('<option value="11A">11:00am</option>');
	document.write('<option value="12P" selected>12:00pm</option>');
	document.write('<option value="1P">1:00pm</option>');
	document.write('<option value="2P">2:00pm</option>');
	document.write('<option value="3P">3:00pm</option>');
	document.write('<option value="4P">4:00pm</option>');
	document.write('<option value="5P">5:00pm</option>');
	document.write('<option value="6P">6:00pm</option>');
	document.write('<option value="7P">7:00pm</option>');
	document.write('<option value="8P">8:00pm</option>');
	document.write('<option value="9P">9:00pm</option>');
	document.write('<option value="10P">10:00pm</option>');
	document.write('<option value="11P">11:00pm</option>');
}

function add_options_to_car_type_select(){
		document.write('<option value="">No Preference');
		document.write('<option value="B-EC" selected>Economy Car');
		document.write('<option value="C-CC" >Compact Car');
		document.write('<option value="D-SC" >Standard Car');
		document.write('<option value="E-IC" >Intermediate Car');
		document.write('<option value="F-FC" >Full Size Car');
		document.write('<option value="G-PC" >Premium Car');
		document.write('<option value="H-LC" >Luxury Car');
		document.write('<option value="I-ASPT" >Sports Car');
		document.write('<option value="J-ACNV" >Convertible');
		document.write('<option value="K-MV" >Mini Van');
		document.write('<option value="L-FV" >Full Size Van');
		document.write('<option value="M-APUP" >Pick-up Truck ');
		document.write('<option value="N-AFWD" >Sport Utility (SUV)');
		document.write('<option value="O-ATRV" >All Terrain');
		document.write('<option value="P-AWGN" >Station Wagon');
		document.write('<option value="Q-ASPC" >Special Car');
}

function add_options_to_ct_time_select(){
		document.write('<option value="12:00am">12:00am</option>');
		document.write(' <option value="1:00am">1:00am</option>');
		document.write(' <option value="2:00am">2:00am</option>');
		document.write(' <option value="3:00am">3:00am</option>');
		document.write(' <option value="4:00am">4:00am</option>');
		document.write(' <option value="5:00am">5:00am</option>');
		document.write(' <option value="6:00am">6:00am</option>');
		document.write(' <option value="7:00am">7:00am</option>');
		document.write(' <option value="8:00am">8:00am</option>');
		document.write(' <option value="9:00am">9:00am</option>');
		document.write(' <option value="10:00am">10:00am</option>');
		document.write(' <option value="11:00am">11:00am</option>');
		document.write(' <option value="12:00pm">12:00pm</option>');
		document.write(' <option value="1:00pm">1:00pm</option>');
		document.write(' <option value="2:00pm">2:00pm</option>');
		document.write(' <option value="3:00pm">3:00pm</option>');
		document.write(' <option value="4:00pm">4:00pm</option>');
		document.write(' <option value="5:00pm">5:00pm</option>');
		document.write(' <option value="6:00pm">6:00pm</option>');
		document.write(' <option value="7:00pm">7:00pm</option>');
		document.write(' <option value="8:00pm">8:00pm</option>');
		document.write(' <option value="9:00pm">9:00pm</option>');
		document.write(' <option value="10:00pm">10:00pm</option>');
		document.write(' <option value="11:00pm">11:00pm</option>');
		document.write(' <option value="Morning">Morning</option>');
		document.write(' <option value="Noon">Noon</option>');
		document.write(' <option value="Evening">Evening</option>');
		document.write(' <option value=" " selected="selected">Anytime</option>');
}

function add_options_to_day_select(){
	var newnumber;
	for(var  ivar = 1;ivar < 32; ivar++){
		if(ivar < 10){
			newnumber = "0" + ivar;
		}else{
			newnumber = "" +  ivar;
		}
		document.write('<option value="' + newnumber + '">' + newnumber);
	}
}
