

var testWindow;
var formType;
var fName;
var indexselect;

if(indexSelect[0].checked){indexSelect[0].click();}else if(indexSelect[1].checked){indexSelect[1].click();}else if(indexSelect[2].checked){indexSelect[2].click();}
else if(indexSelect[3].checked){indexSelect[3].click();}
if (indexSelect[1].checked) {
if(document.hotForm && document.hotForm.cityText) {
document.hotForm.cityText.focus();
}
}

/* state = 1 - show element
   state = 0 - hide element
*/
function toggleDiv(divID, state){
    if(document.layers){ //netscape 4+

       document.layers[divID].visibility = state ? "show" : "hide";
       document.layers[divID].display = state ? "block" : "none";

    } else if(document.getElementById) { //netscape 6 internetExplorer 5+

        document.getElementById(divID).style.visibility = state ? "visible" : "hidden";
        document.getElementById(divID).style.display = state ? "block" : "none";

    } else {    //Internet Explorer 4

        document.all[divID].style.visibility = state ? "visible" : "hidden";
        document.all[divID].style.display = state ? "block" : "none";

    }
}

    function isBrowserSupp() {
        // Get the version of the browser
        version =  parseFloat( navigator.appVersion );

        if ( ( version >= 2.0 ) && ( version < 2.1 ) && ( navigator.appName.indexOf( "Netscape" ) != -1 ) ) {
            return false;
        } else {
            return true;
        }

        return true;
    }

    function isLeapYear( yrStr ) {
        var leapYear = false;
        var year = parseInt( yrStr, 10 );
        // every fourth year is a leap year
        if ( year % 4 == 0 ) {
            leapYear = true;
            // unless it's a multiple of 100
            if( year % 100 == 0 ) {
                leapYear = false;
                // unless it's a multiple of 400
                if( year % 400 == 0 ) {
                    leapYear=true;
                }
            }
        }
        return leapYear;
    }

    function getDaysInMonth( mthIdx, YrStr ) {
        // all the rest have 31
        var maxDays = 31
        // expect Feb. (of course)
        if( mthIdx == 1 ) {
            if( isLeapYear( YrStr ) ) {
                maxDays=29;
            } else {
                maxDays=28;
            }
        }

        // thirty days hath...
        if( mthIdx == 3 || mthIdx == 5 || mthIdx == 8 || mthIdx == 10 ) {
            maxDays=30;
        }
        return maxDays;
    }

    function displayHotel(){
        toggleDiv('hotelTable', 1);
        document.getElementById('hotel').checked=true;
       	}

    //the function which does some magic to the date fields
    // return non-zero if it is the last day of the month
    function adjustDate( mthIdx, Dt ) {
        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 );

        if( mthIdx == 1 ) {
            if( Dt.options.selectedIndex + 1 < numDays ) {
                return 0;
            } else {
                Dt.options.selectedIndex=numDays - 1;
                //check for leap year
                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 {
                //index is 31 or 30
                value = 2;
            }
        }
        return value;
    }

    //changes departure month when arrival month is changed
    function amadChange( inM, inD, outM, outD ) {
        if ( !isBrowserSupp() ) {
            return;
        }

        var res = adjustDate( inM.options.selectedIndex, inD );
        if( res != 0 ) {
               outD.options.selectedIndex = 0;
               if ( outM.options.selectedIndex == 11 ) {
                    outM.options.selectedIndex = 0
               } else {
                    outM.options.selectedIndex=inM.options.selectedIndex + 1;
                    outD.options.selectedIndex = 1;
               }
        } else {
            outM.options.selectedIndex = inM.options.selectedIndex;
            if (outD.options.selectedIndex <= inD.options.selectedIndex) {
                outD.options.selectedIndex = inD.options.selectedIndex + 2;
            }
        }
        return;
    }


    function dmddChange( outM, outD ) {
        if ( !isBrowserSupp() ) {
            return;
        }

        adjustDate( outM.options.selectedIndex, outD );
        return;
    }



 function OpenWindow(file, name, width, height) {
        OpenWindow(file, name, width, height, false);
    }

    function OpenWindow(file, name, width, height, showLeftTopScrollbar) {
        var attr = "";
        if(showLeftTopScrollbar) {
            attr += "top=10,left=5,scrollbars=1,";
        }
        attr += "width=" + width + ",height=" + height + ",resizeable=0";
        window.open(file, name, attr);
    }

   function loadDefaultDates() {
        var hotelArrival = new Date();
        var hotelDeparture = new Date();

        var hotelAdvanceArrival = 21;
        var hotelAdvanceDeparture = 23;

        hotelArrival.setDate( hotelArrival.getDate() + hotelAdvanceArrival );
        hotelDeparture.setDate( hotelDeparture.getDate() + hotelAdvanceDeparture );

        document.forms['hotForm'].arrivalMonth.value = hotelArrival.getMonth();
        document.forms['hotForm'].departureMonth.value = hotelDeparture.getMonth();
        document.forms['hotForm'].arrivalDay.value = hotelArrival.getDate();
        document.forms['hotForm'].departureDay.value = hotelDeparture.getDate();

    }

    function validateDepWindow(formName) {
        if (document.forms[formName].tempDepTime[document.forms[formName].tempDepTime.selectedIndex].value==('M')) {
            window.document.forms[formName].tripWindow.value='5';
            window.document.forms[formName].departureTime.value='7AM';
        } else if (document.forms[formName].tempDepTime[document.forms[formName].tempDepTime.selectedIndex].value==('A')) {
            window.document.forms[formName].tripWindow.value='5';
            window.document.forms[formName].departureTime.value='3PM';
        } else if (document.forms[formName].tempDepTime[document.forms[formName].tempDepTime.selectedIndex].value==('E')) {
            window.document.forms[formName].tripWindow.value='5';
            window.document.forms[formName].departureTime.value='8PM';
        } else if(document.forms[formName].tempDepTime[document.forms[formName].tempDepTime.selectedIndex].value==('ANT')) {
            window.document.forms[formName].tripWindow.value='9';
            window.document.forms[formName].departureTime.value='12PM';
        } else {
            window.document.forms[formName].tripWindow.value='5';
            window.document.forms[formName].departureTime.value=document.forms[formName].tempDepTime.value;
        }
    }

    function validateRetWindow(formName) {
        if (document.forms[formName].tempRetTime[document.forms[formName].tempRetTime.selectedIndex].value==('M')) {
            window.document.forms[formName].returnTime.value='7AM';
        } else if (document.forms[formName].tempRetTime[document.forms[formName].tempRetTime.selectedIndex].value==('A')) {
            window.document.forms[formName].returnTime.value='3PM';
        } else if (document.forms[formName].tempRetTime[document.forms[formName].tempRetTime.selectedIndex].value==('E')) {
            window.document.forms[formName].returnTime.value='8PM';
        } else if(document.forms[formName].tempRetTime[document.forms[formName].tempRetTime.selectedIndex].value==('ANT')) {
            window.document.forms[formName].returnTime.value='12PM';
        } else {
            window.document.forms[formName].returnTime.value=window.document.forms[formName].tempRetTime.value;
        }
	   }


function update(themonth,theday){
    document.forms[fName].elements[formType+'Day'].options[theday - 1].selected = true;
    document.forms[fName].elements[formType+'Month'].options[themonth].selected = true;

    testWindow.close();
}


function loadCalendar(viewMonth) {


	testWindow.document.close();
	testWindow.document.open();


	var day_of_week = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
	var month_of_year = new Array("January","February","March","April","May","June","July","August","September","October","November","December");

	var dateObj = new Date();
	var year = dateObj.getYear();	 // Returns year
	var month = dateObj.getMonth();  // Returns month (0-11)
	var today = dateObj.getDate();   // Returns day (1-31)
	var weekday = dateObj.getDay();  // Returns day (1-31)

	var DAYS_OF_WEEK = 7;   // "constant" for number of days in a week
	var DAYS_OF_MONTH = 31; // "constant" for number of days in a month
	var cal;                // Used for printing

	if (viewMonth < month) {
		year = year + 1;
	}

	if(year < 1900){
		year += 1900; //done to solve the problem of netscape and mozilla returning year in form 10X for years > 2000
	}

	month = viewMonth;
	dateObj.setDate(1);      // Start the calendar day at '1'
	dateObj.setMonth(month); // Start the calendar month at now
	dateObj.setYear((year));

	// VARIABLES FOR FORMATTING
	var TR_start = '<TR>';
	var TR_end = '</TR>';
	var highlight_start = '<TD WIDTH="14%"><TABLE CELLSPACING=0 BORDER=2 BGCOLOR=D4E9FD BORDERCOLOR=0606FC><TR><TD WIDTH=14%><B><CENTER>';
	var highlight_end   = '</CENTER></TD></TR></TABLE></B>';
	var TD_start = '<TD WIDTH="14%"><CENTER>';
	var TD_end = '</CENTER></TD>';
	var prevM = month - 1;
	var nextM = month + 1;

	if (nextM == 12) {
		nextM = 0;
	}

	if (prevM == -1) {
		prevM = 11;
	}

	// BEGIN CODE FOR CALENDAR
	cal =  '<html><head><title>Calendar</title></head><body>';
	cal += "<style>a:link{cursor: hand}a:active{cursor: hand}a:hover{cursor: hand}a:visited{cursor: hand}body{cursor: default}</style>";

    // NOTE:
    // Update the calendar.js reference below to reference where you
    // put the calendar.js file.

    cal += '<SCRIPT SRC="calendar.js"></SCRIPT>';

    cal += '<TABLE BORDER="2" CELLSPACING="0" CELLPADDING="0" BORDERCOLOR="#0606FC" width="100%" height="200"><TR><TD>';
	cal += '<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0" width="100%">' + TR_start;
	cal += '<TD COLSPAN="' + DAYS_OF_WEEK + '" BGCOLOR="#D4E9FD"><CENTER><B>';
	cal += month_of_year[month]  + '   ' + year + '</B>' + TD_end + TR_end;
	cal += TR_start;

    ///////////////////////////////////
    // DO NOT EDIT BELOW THIS POINT  //
    ///////////////////////////////////

	// LOOPS FOR EACH DAY OF WEEK
	for(index=0; index < DAYS_OF_WEEK; index++) {
        // PRINTS DAY
        cal += TD_start + day_of_week[index] + TD_end;
	}

	cal += TD_end + TR_end;
	cal += TR_start;

	// FILL IN BLANK GAPS UNTIL TODAY'S DAY
	for(index=0; index < dateObj.getDay(); index++) {
	    cal += TD_start + '  ' + TD_end;
    }

	// LOOPS FOR EACH DAY IN CALENDAR
    for(index=0; index < DAYS_OF_MONTH; index++) {
        if( dateObj.getDate() > index ) {
            // RETURNS THE NEXT DAY TO PRINT
            week_day =dateObj.getDay();

            // START NEW ROW FOR FIRST DAY OF WEEK
            if(week_day == 0) {
                cal += TR_start;
            }

            if(week_day != DAYS_OF_WEEK) {
                // SET VARIABLE INSIDE LOOP FOR INCREMENTING PURPOSES
                var day  = dateObj.getDate();

                // PRINTS DAY
                cal += TD_start + "<span onclick='window.opener.update(" + month + "," + day + ")' style='cursor:hand;font-weight:bold;background:#D4E9FD;width:22px;'>" + day + "</span>" + TD_end;
            }

            // END ROW FOR LAST DAY OF WEEK
            if(week_day == DAYS_OF_WEEK) {
                cal += TR_end;
            }
        }

        // INCREMENTS UNTIL END OF THE MONTH
        dateObj.setDate(dateObj.getDate()+1);

    }// end for loop

	cal += '</td></TR></TABLE></TABLE>';
    cal += '<div align="center"><a href="javascript:" onClick="window.opener.loadCalendar(' + prevM + ');">&lt;&lt;</a>&nbsp;&nbsp;&nbsp;&nbsp;';
	cal += '<a href="javascript:" onClick="window.opener.loadCalendar(' + nextM + ');">&gt;&gt;</a><br></div>';
	cal += '<div align="center"><a href="javascript:window.close();">close</a></div>';
	cal += '</body></html>';

	//  PRINT CALENDAR
	testWindow.document.write(cal);
}


function openCalendar(formName,type) {
	formType=type;
	fName=formName;
	testWindow = window.open('','dates','width=450,height=250,resizable=1,status=1,menubar=0,location=0');
	loadCalendar(document.forms[fName].elements[formType+'Month'].selectedIndex);
}

function groups(form) {
    if (form.numberOfRooms.selectedIndex == 8) {
        window.location="http://travel.ian.com/index.jsp?pageName=groups&cid=158859";
        return false;
    }
    return submitGuestInfoForm(form);
}


	function clearTextBox(_textbox) {
		_textbox.value = "";
	}

	function go(loc) {
		window.location.href = loc;
	}

	function setCSC(city,state,country) {
		if (city != "") {
			document.hotForm.cityRadio2.checked=false;
			document.hotForm.cityText.value='';
			document.hotForm.city.value=city;
			document.hotForm.stateProvince.value=state;
			document.hotForm.country.value=country;
		}
	}

    function showLayer(layername)
    {
    if (isNav)
        { document.layers[layername].visibility = 'visible';}
        else //Must be IE
        { document.all[layername].style.visibility = 'visible';	}
    }

    function hideLayer(layername)
    {
        if (isNav)
        { document.layers[layername].visibility = 'hidden';	}
        else //Must be IE
        {document.all[layername].style.visibility = 'hidden';}
    }

    function subpop(s) {//DH added this for new popcal
        addWindow = window.open(s,"myform","width=270,height=150,resizable=1,status=1,menubar=0,scrollbars=0,fullscreen=0");
        addWindow.focus();
    }
	
    function checkDoubleSubmit(frm) {
        if (frm.frmsubmit.value == "Y" || frm.frmsubmit.value == "TWICE") {
            frm.frmsubmit.value = "TWICE";
            alert("You have already submitted this reservation once.  Please click 'OK' to continue. ");
            return(false);
        }
        frm.frmsubmit.value = "Y";
        return(true);
    }

    function editReservePage(fieldToJumpTo) {
        setCookie('reserveField',fieldToJumpTo)
        history.back();
    }

    function goToAnchor(reserveField) {
        window.location.hash=reserveField;
    }

    var isNav, isIE
    if (parseInt(navigator.appVersion) >= 4)
    { if (navigator.appName == "Netscape")
       { isNav = true }
       else
       { isIE = true }
    }

    function showLayer(layername)
    {
    if (isNav)
        { document.layers[layername].visibility = 'visible';}
        else //Must be IE
        { document.all[layername].style.visibility = 'visible';	}
    }

    function hideLayer(layername)
    {
        if (isNav)
        { document.layers[layername].visibility = 'hidden';	}
        else //Must be IE
        {document.all[layername].style.visibility = 'hidden';}
    }

    function loadPromo(file) {
       thor2 = window.open(file,'thor2','top=50,left=50,width=620,height=600,resizable=1,status=1,scrollbars=1');
       thor2.blur();
    }

    function showPromo(file) {
        if (thor2 == undefined){
            var thor2;
            thor2 = window.open(file,'thor2','top=50,left=50,resizable=1,status=1,scrollbars=1');
        }else{
            if (thor2.closed) {
                thor2 = window.open(file,'thor2','top=50,left=50,resizable=1,status=1,scrollbars=1');
            } else {
                thor2.focus();
            }
        }
    }

    //check the system date and set the time in advance if is equal to the same day as booking
    function checkTime(M,D,Y,obj)
    {
        var calendar = new Date();
        var date = calendar.getDate();
        var month = calendar.getMonth();
        var year = calendar.getYear();
        var hour = calendar.getHours();
        var date2 = D.value;
        var month2 = M.value;
        var year2 = Y.value;
        var newTime;

        if (obj == document.forms['aForm'].dropOffTime)
        {
            hour += 3;
        }else{
            hour += 2;
        }

        if (month2 == month && date2 == date && year2 == year){
            if (hour == 0){
                newTime = '12AM';
            }else if (hour == 11){
                newTime = '12PM';
            }else if(hour < 11){
                newTime = hour + 'AM';
            }else if(hour > 11){
                hour -= 11;
                newTime = hour + 'PM';
            }
            obj.value=newTime;
        }else{
            obj.value='9AM';
        }
    }

    function goToAnchor(reserveField) {
        window.location.hash=reserveField;
    }

    function toggleDiv(divID, state){
        if(document.layers){ //netscape 4+

           document.layers[divID].visibility = state ? "show" : "hide";
           document.layers[divID].display = state ? "block" : "none";

        } else if(document.getElementById) { //netscape 6 internetExplorer 5+

            document.getElementById(divID).style.visibility = state ? "visible" : "hidden";
            document.getElementById(divID).style.display = state ? "block" : "none";

        } else {    //Internet Explorer 4

            document.all[divID].style.visibility = state ? "visible" : "hidden";
            document.all[divID].style.display = state ? "block" : "none";

        }
    }

	function setChildPTC(numChildren) {
		if (numChildren == 0) {
			for(j=0; j < 6; j++){
				eval("document.forms['airForm'].childPTC["+j+"].value=''");
				}
				} else {
				for(j=1; j <= numChildren; j++){
				var ptc=j-1;
				eval("document.forms['airForm'].childPTC["+ptc+"].value=5");
			}
		}
	}

	function handleError() {
	return true;
	}
	window.onerror = handleError;

    function displayHotel(){
        toggleDiv('hotelTable', 1);

        document.getElementById('hotel').checked=true;
	}

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) { //v3.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); 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];}
}

function newWin(path) {  
 window.open(path, 'new', 'toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no,copyhistory=no,width=600,height=475');
}
function getPage(path) {  
 window.open(path, 'new', 'toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no,copyhistory=no,width=600,height=475');
}

function setVisibleAH(select) {
if (select.value != 0) {
childrenOptionsAH.style.visibility="visible";
childrenOptionsAH.style.display="block";
message1AH.style.visibility="visible";
message1AH.style.display="block";
message2AH.style.visibility="visible";
message2AH.style.display="block";
if (select.value <= 5) {
for(a = 1; a <= select.value; ++a) {
eval("cAH" +a+".style.visibility=\"visible\"");
eval("cAH" +a+".style.display=\"block\"");
}
for(a = 5; a > select.value; --a) {
eval("cAH" +a+".style.visibility=\"hidden\"");
eval("cAH" +a+".style.display=\"none\"");
}
}
//cAH1.style.visibility="visible";
//cAH1.style.display="block";
}else{
childrenOptionsAH.style.visibility="hidden";
childrenOptionsAH.style.display="none";
message1AH.style.visibility="hidden";
message1AH.style.display="none";
message2AH.style.visibility="hidden";
message2AH.style.display="none";
cAH1.style.visibility="hidden";
cAH1.style.display="none";
cAH2.style.visibility="hidden";
cAH2.style.display="none";
cAH3.style.visibility="hidden";
cAH3.style.display="none";
cAH4.style.visibility="hidden";
cAH4.style.display="none";
cAH5.style.visibility="hidden";
cAH5.style.display="none";
}
resetForm(select);
}
function resetForm(select) {
//document.frmPackages.numbChild.selectedIndex = 1;
for(a = 5; a > select.value; --a) {
eval("document.frmPackages.Child"+a+"Age.selectedIndex=0");
}
//document.frmPackages.Child1Age.selectedIndex=0;
}

	function setVisible(select) {
		if (select.value != 0) {
			childrenOptions.style.visibility="visible";
			childrenOptions.style.display="block";
			message1.style.visibility="visible";
			message1.style.display="block";
			message2.style.visibility="visible";
			message2.style.display="block";
				if (select.value <= 5) {
				for(a = 1; a <= select.value; ++a) {
				eval("c" +a+".style.visibility=\"visible\"");
				eval("c" +a+".style.display=\"block\"");
				}
				for(a = 5; a > select.value; --a) {
				eval("c" +a+".style.visibility=\"hidden\"");
				eval("c" +a+".style.display=\"none\"");
				}
				}
				//c1.style.visibility="visible";
				//c1.style.display="block";
				}else{
				childrenOptions.style.visibility="hidden";
				childrenOptions.style.display="none";
				message1.style.visibility="hidden";
				message1.style.display="none";
				message2.style.visibility="hidden";
				message2.style.display="none";
				c1.style.visibility="hidden";
				c1.style.display="none";
				c2.style.visibility="hidden";
				c2.style.display="none";
				c3.style.visibility="hidden";
				c3.style.display="none";
				c4.style.visibility="hidden";
				c4.style.display="none";
				c5.style.visibility="hidden";
				c5.style.display="none";
			}
		resetForm(select);
	}

	function resetForm(select) {
		//document.frmPackages.numbChild.selectedIndex = 1;
		for(a = 5; a > select.value; --a) {
		eval("document.frmPackages.Child"+a+"Age.selectedIndex=0");
		}
		//document.frmPackages.Child1Age.selectedIndex=0;
	}

function selectdate() {
window.open('http://www.vacationcondos.com/affil/condorentals/searchset.asp?dest=','testwindow','height=360,width=360,status=no,toolbar=yes,menubar=no,location=no,scrollbars=yes,resizable=yes,');
}

