function checkCity()
{
	if (document.f.city.value == "" || document.f.city.value == "null")
	{
	  setCountryCode(valueOfCodeAutoComplete(_highlightedSuggestionDiv));
  	  setCityNameEn(valueOfCityEnAutoComplete(_highlightedSuggestionDiv));
	}
	if (document.f.city.value == "" || document.f.city.value == "null")
	{
		alert("Некорректное название города!")
		return false;
	}
	document.f.submit();
	return true;
}

    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 setCountryCode(valueCC)
{
	_inputFieldCC.value = valueCC;
}

function setCityNameEn(valueCN)
{
	_inputFieldCityNameEn.value = valueCN;
}

function setHomePage(obj) 
{
	if (document.all) 
	{
		obj.style.behavior='url(#default#homepage)';
		obj.setHomePage('http://www.hotels.su/');
		return false;
	} 
	else if (!document.layers) 
	{
		netscape.security.PrivilegeManager.enablePrivilege("UniversalPreferencesWrite");
		navigator.preference("browser.startup.homepage", "http://www.hotels.su/"); 
		return false;
	}
	return true;
}

function setTodayDate()
{
	var d = new Date();
	var dtIn = document.getElementById("dtIn");
	if (dtIn != null && typeof(dtIn) != 'undefined')
	{
		dtIn.options.selectedIndex = d.getDate();
		var mnIn = document.getElementById("mnIn");
		mnIn.options.selectedIndex = d.getMonth();
	}
	//var mnOut = document.getElementById("mnOut");
	//var dtOut = document.getElementById("dtOut");
	amadChange(mnIn, dtIn, document.frm1.mnOut, document.frm1.dtOut);
	//amadChange( inM, inD, outM, outD )
}

function fromSel(cityName, stateCode, countryCode)
{
	document.getElementById('city').value = cityName;
	document.getElementById('stateCode').value = stateCode;
	document.getElementById('countryCode').value = countryCode;
}

function clearInput() 
{
	var city = document.getElementById("cityN").value;
	if (city == "Введите город...")
		document.getElementById("cityN").value = "";
}

//changes departure month when arrival month is changed
       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;
    }
	
 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        
    //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 clearAmenity(count)
  {
	for (i = 1; i <= count; i++)
		{
			frm1.amenities.item(i).checked = false;
		}
  }*/
  function clickThis(nameObj)
{
	document.getElementById(nameObj).click();
}
 function Loading()
{
if (typeof window_width == 'undefined' || typeof window_height == 'undefined') {
var window_width;
var window_height;
if( typeof( window.innerWidth ) == 'number' ) {
window_width = window.innerWidth;
window_height = window.innerHeight;
} else if( document.documentElement &&
( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
window_width = document.documentElement.clientWidth;
window_height = document.documentElement.clientHeight;
} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
window_width = document.body.clientWidth;
window_height = document.body.clientHeight;
}
}
var left = Math.round((window_width - 200) / 2);
var top = Math.round(((window_height - 46) / 3) + 46);
document.getElementById('pageIsLoading').style.left = left+'px';
document.getElementById('pageIsLoading').style.top = top+'px';
}
function hideLoading() {
document.getElementById('pageIsLoading').style.display = 'none';
}
