var numSelHot = 0;


//script date

    //start new script code
    // Checks if browser is Netscape 2.0x since the options array properties don't work with Netscape 2.0x
    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;
    }

    //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 {
                if( Dt.options.selectedIndex + 1 > numDays) {
                    Dt.options.selectedIndex=numDays - 1;
                }
                //check for leap year
                if( (Dt.options.selectedIndex + 1) == numDays ) {
                    return 1;
                } else {
                    return 4;
                }
            }
        }

        if( Dt.options.selectedIndex + 1 < numDays ) {
            value = 0;
        } else {
            if ( Dt.options.selectedIndex + 1 > numDays ) {
                Dt.options.selectedIndex--;
                value = 3;
            } else if ( Dt.options.selectedIndex + 1 == numDays ) {
                //index is 31 or 30
                value = 2;
            } else {
                value = 4;
            }
        }
        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 ( inM.options.selectedIndex == 11 ) {
                    outM.options.selectedIndex = 0
               } else if( res == 4 ) {
                    outM.options.selectedIndex=inM.options.selectedIndex + 1;
                    outD.options.selectedIndex = 0;
               } else {
                    outM.options.selectedIndex=inM.options.selectedIndex + 1;
                    outD.options.selectedIndex = 0;
               }
        } else {
            outM.options.selectedIndex = inM.options.selectedIndex;
            if (outD.options.selectedIndex <= inD.options.selectedIndex) {
                outD.options.selectedIndex = inD.options.selectedIndex + 1;
            }
        }
        return;
    }


    function dmddChange( outM, outD ) {
        if ( !isBrowserSupp() ) {
            return;
        }

        adjustDate( outM.options.selectedIndex, outD );
        return;
    }

//script date





function clickOther(doc)
{
	var totalChecked = 0;
	for (var i = 0; i < doc.form.elements.length; i++)
	{
		if (doc.form.elements[i].name == "facil")
		{
			if (doc.form.elements[i].checked)
			{
				totalChecked++;
			}
		}
	}
	if (totalChecked > 3)
	{
		doc.checked = false;
		alert("You cannot select more than three Facilities. Please uncheck a Facility before checking a different one.");
	}
	return;
}

function showNew(obj)
{
	if (obj.checked)
	{numSelHot++;}
	else
	{numSelHot = numSelHot - 1;}

if (numSelHot == 0)	
{
	document.all["numSelHot"].innerHTML = "";
	document.all["numSelHot"].innerText = "";
	document.getElementById('compareHotels').style.display = 'none';
	document.all["numSelHot1"].innerHTML = "";
	document.all["numSelHot1"].innerText = "";
	document.getElementById('compareHotels1').style.display = 'none';
}
else
{
	document.all["numSelHot"].innerHTML = "View & Compare " + numSelHot + " selected hotel(s)";
	document.all["numSelHot"].innerText = "View & Compare " + numSelHot + " selected hotel(s)";
	document.getElementById('compareHotels').style.display = 'block';
	document.all["numSelHot1"].innerHTML = "View & Compare " + numSelHot + " selected hotel(s)";
	document.all["numSelHot1"].innerText = "View & Compare " + numSelHot + " selected hotel(s)";
	document.getElementById('compareHotels1').style.display = 'block';
}

}


function citySelect(cCode, sCode, cName)

{

	frm1.countryCode.value = cCode;
	frm1.stateCode.value = sCode;
if (cName.length == 0)
	{
	}
else
	{
		frm1.city.value = cName;
	}
	
	//document.cityphoto.src = '';
	//document.cityphoto.alt = '';
	switch (cName)
	{
		case 'Paris':
			document.cityphoto.src = '/images/cities/paris.jpg';
			document.cityphoto.alt = 'Paris hotels';
			break;
		case 'London':
			document.cityphoto.src = '/images/cities/london.jpg';
			document.cityphoto.alt = 'London hotels';
			break;
		case 'Rome':
			document.cityphoto.src = '/images/cities/rome.jpg';
			document.cityphoto.alt = 'Rome hotels';
			break;
		case 'Barcelona':
			document.cityphoto.src = '/images/cities/barcelona.jpg';
			document.cityphoto.alt = 'Barcelona hotels';
			break;
		case 'Nice':
			document.cityphoto.src = '/images/cities/nice.jpg';
			document.cityphoto.alt = 'Nice hotels';
			break;
		case 'Venice':
			document.cityphoto.src = '/images/cities/venice.jpg';
			document.cityphoto.alt = 'Venice hotels';
			break;
		case 'Madrid':
			document.cityphoto.src = '/images/cities/madrid.jpg';
			document.cityphoto.alt = 'Madrid hotels';
			break;
		case 'Berlin':
			document.cityphoto.src = '/images/cities/berlin.jpg';
			document.cityphoto.alt = 'Berlin hotels';
			break;
		case 'Amsterdam':
			document.cityphoto.src = '/images/cities/amsterdam.jpg';
			document.cityphoto.alt = 'Amsterdam hotels';
			break;
		case 'Vienna':
			document.cityphoto.src = '/images/cities/vienna.jpg';
			document.cityphoto.alt = 'Vienna hotels';
			break;
		case 'Geneva':
			document.cityphoto.src = '/images/cities/geneva.jpg';
			document.cityphoto.alt = 'Geneva hotels';
			break;
		case 'Dublin':
			document.cityphoto.src = '/images/cities/dublin.jpg';
			document.cityphoto.alt = 'Dublin hotels';
			break;
		case 'New York':
			document.cityphoto.src = '/images/cities/new-york.jpg';
			document.cityphoto.alt = 'New York hotels';
			break;
		case 'Las Vegas':
			document.cityphoto.src = '/images/cities/las-vegas.jpg';
			document.cityphoto.alt = 'Las Vegas hotels';
			break;
		case 'Montreal':
			document.cityphoto.src = '/images/cities/montreal.jpg';
			document.cityphoto.alt = 'Montreal hotels';
			break;
		case '':
			document.cityphoto.src = '/images/cities/custom-city.jpg';
			document.cityphoto.alt = 'Enter a city';
			break;
	}

}

function fromSel(cityName, stateCode, countryCode)
{
	frm1.city.value = cityName;
	frm1.stateCode.value = stateCode;
	frm1.countryCode.value = countryCode;
}

function clearAmenity(count)
{
	for (i = 1; i <= count; i++)
		{
			frm1.amenities.item(i).checked = false;
		}
}

function show_hide()
{
	document.getElementById('layer1').style.visibility = 'hidden';
	document.getElementById('layer1').style.display = 'none';
	document.getElementById('layer2').style.display = 'block';
	document.getElementById('layer2').style.visibility = 'visible';
}


function setNameAirport(airName)
{
	frm1.airportName.value = airName;
}

function checkForm(count)
{
var flag;
	flag = true;
	for (i = 0; i <= count - 1; i++)
		{
			if (frm1.porcode.item(i).checked)
			{
				flag = false;
				frm1.submit();
				break;
			}
		}
	if (flag)
		{
			alert('Select airport!');
		}
}


function clearAmenityReadOnly(count)
{
	frm1.amenities.item(0).checked = true;
	for (i = 1; i <= count; i++)
		{
			frm1.amenities.item(i).checked = false;
		}
}


function warning()
{
	if (frm1.nearAirport.checked)
		{
			clearAmenityReadOnly(10);
			frm1.propName.value = '';
			frm1.propAdress.value = '';
			/*frm1.chains.item(0).selected = true;
			j = frm1.chains.length;
			for (i = 1; i < j; i++)
			{
				frm1.chains.item(i).selected = false;
			}*/
			alert('Note! When searching for hotels near an airport you will not be able to use the Optional Fields section.');
		}
}

function newCity(stateUrl)
{
	newCity = document.getElementById('newCitySelect').value;
	if (newCity != '')
	{
		if (stateUrl != '')
		{
			document.getElementById('newUrl').href = '../../' + newCity + '/city.html';
			document.getElementById('newUrl').click();
		}
		else
		{
			document.getElementById('newUrl').href = '../' + newCity + '/city.html';
			document.getElementById('newUrl').click();
		}
	}
}


function makeState(countryCode)
{
	cmpStr = frm1.city.value;
	j = frm1.city.length;
	for (i = 0; i < j; i++)
	{
		if (frm1.city.item(i).value == cmpStr)
		{
			pos = i;
		}
	}
	if (countryCode == 'US' || countryCode == 'CA' || countryCode == 'AU')
	{
		cmpStr = frm1.city.item(pos).text;
		frm1.stateCode.value = cmpStr.substr(cmpStr.length - 3, 2);
	}
	else
	{
		frm1.stateCode.value = '';
	}
}

function clickThis(nameObj)
{
	document.getElementById(nameObj).click();
}

